StationListCreatorModule.cc
Go to the documentation of this file.
1 #include <fstream>
2 #include <boost/format.hpp>
3 #include <evt/Event.h>
4 #include <utl/ErrorLogger.h>
5 #include <utl/UTMPoint.h>
6 #include <utl/ReferenceEllipsoid.h>
7 #include <det/Detector.h>
8 #include <sdet/SDetector.h>
9 #include <sdet/Station.h>
10 #include <sdet/SStationListSQLManager.h>
11 #include <sdet/SStationListXMLManager.h>
12 
14 
15 using namespace det;
16 using namespace sdet;
17 using namespace std;
18 using namespace evt;
19 using namespace fwk;
20 using namespace utl;
21 using namespace StationListCreatorModuleNS;
22 
23 
24 namespace StationListCreatorModuleNS {
25 
26 string
27 StringToXMLString(const string& str)
28 {
29  ostringstream res;
30 
31  for (string::const_iterator it = str.begin(); it != str.end(); ++it)
32  switch (*it) {
33  // replace '&' with "&amp;"
34  case '&':
35  res << "and";
36  break;
37  default:
38  res << *it;
39  }
40 
41  return res.str();
42 }
43 
44 }
45 
46 
49 {
50  return eSuccess;
51 }
52 
53 
55 StationListCreatorModule::Run(evt::Event& event)
56 {
57  const TimeStamp currentTime = GetCurrentSystemTime();
58  Detector::GetInstance().Update(currentTime);
59  const SDetector& sdetector = Detector::GetInstance().GetSDetector();
60 
61  sdetector.GetFullStationList();
62 
63  return eSuccess;
64 }
65 
66 
68 StationListCreatorModule::Finish()
69 {
70  ofstream output("SStationList.xml.in");
71 
72  output
73  << "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"
74  "\n"
75  "<!DOCTYPE stationList [\n"
76  " <!ENTITY UTMdata SYSTEM\n"
77  " \"<ellipsoid> WGS84 </ellipsoid> <zone> 19 </zone> <band> H </band>\">\n"
78  "]>\n"
79  "\n"
80  "<!-- created by StationListCreatorModule on "
81  << Detector::GetInstance().GetTime() << "\n"
82  " revision $""Id""$ -->\n"
83  "\n"
84  "<stationList\n"
85  " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
86  " xsi:noNamespaceSchemaLocation='@XMLSCHEMALOCATION@/SStationList.xsd'>\n"
87  "\n";
88 
89  const Detector& det = Detector::GetInstance();
90 
91  const int method = 3;
92 
93  switch (method) {
94  case 1:
95  {
96  ManagerRegister& sManagerRegister = det.GetSManagerRegister();
97  const SStationListSQLManager& sqlManager =
98  dynamic_cast<
100  >(sManagerRegister.GetManager("SStationListSQLManager"));
101  sqlManager.GetStationListManager().DumpXML(output, " ");
102  break;
103  }
104  case 2:
105  {
106  ManagerRegister& sManagerRegister = det.GetSManagerRegister();
107  const SStationListXMLManager& xmlManager =
108  dynamic_cast<
110  >(sManagerRegister.GetManager("SStationListXMLManager"));
111  xmlManager.GetStationListManager().DumpXML(output, " ");
112  break;
113  }
114  case 3:
115  {
116  const string commonFmt =
117  "%1%<station id=\"%2%\">\n"
118  "%1% <northing unit=\"meter\"> %|3$.2f| </northing>\n"
119  "%1% <easting unit=\"meter\"> %|4$.2f| </easting>\n"
120  "%1% <altitude unit=\"meter\"> %|5$.2f| </altitude>\n"
121  "%1% <name> %6% </name>\n"
122  "%1% <commission> %7% </commission>\n"
123  "%1% <decommission> %8% </decommission>\n"
124  "%1% <inGrid> %9% </inGrid>\n"
125  "%1% <groupId> %10% </groupId>\n"
126  "%1% <axes> %11% %12% </axes>\n";
127  const string fullUTMFmt =
128  "%1% <ellipsoid> %13% </ellipsoid>\n"
129  "%1% <zone> %14% </zone>\n"
130  "%1% <band> %15% </band>\n";
131  const string shortUTMFmt =
132  "%1% &UTMdata;\n";
133  const string endFmt =
134  "%1%</station>\n";
135  boost::format stationFmt(commonFmt + fullUTMFmt + endFmt);
136  boost::format stationShortFmt(commonFmt + shortUTMFmt + endFmt);
137  const SDetector& sDet = det.GetSDetector();
139  sIt != sDet.AllStationsEnd(); ++sIt) {
140  const UTMPoint utm(sIt->GetPosition(), ReferenceEllipsoid::GetWGS84());
141  const bool shortFmt = (utm.GetZone() == 19 && utm.GetBand() == 'H');
142  (shortFmt ? stationShortFmt : stationFmt)
143  % " "
144  % sIt->GetId()
145  % utm.GetNorthing()
146  % utm.GetEasting()
147  % utm.GetHeight()
148  % StringToXMLString(sIt->GetName())
149  % sIt->GetCommissionTime()
150  % sIt->GetDecommissionTime()
151  % sIt->IsInGrid()
152  % sIt->GetGroupId()
153  % sIt->GetAxes().at(0)
154  % sIt->GetAxes().at(1);
155  if (!shortFmt)
156  stationFmt % "WGS84" % utm.GetZone() % utm.GetBand();
157  output << (shortFmt ? stationShortFmt : stationFmt) << '\n';
158  }
159  break;
160  }
161  }
162 
163  output << "</stationList>\n";
164  output.close();
165 
166  return eSuccess;
167 }
const std::vector< int > & GetFullStationList() const
Get list of ID&#39;s for all stations available in the database or configuration file.
Definition: SDetector.cc:110
StationIterator AllStationsEnd() const
End of the collection of pointers to all stations in the history of the array.
Definition: SDetector.h:126
Class to hold and convert a point in geodetic coordinates.
Definition: UTMPoint.h:40
const SStationListManager & GetStationListManager() const
Manager for SD description in SQL station lists.
void Init()
Initialise the registry.
double GetNorthing() const
Get the northing.
Definition: UTMPoint.h:206
Manager for SD description in XML station lists.
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
StationIterator AllStationsBegin() const
Beginning of the collection of pointers to all stations in the history of the array.
Definition: SDetector.h:121
Top of the hierarchy of the detector description interface.
Definition: Detector.h:81
const sdet::SDetector & GetSDetector() const
Definition: Detector.cc:119
const VManager & GetManager(const std::string &managerName) const
Get a specific manager by name.
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
ManagerRegister & GetSManagerRegister() const
Definition: Detector.h:87
Register for detector description managers.
bool DumpXML(std::ostream &output, const std::string &indent="") const
Detector description interface for SDetector-related data.
Definition: SDetector.h:42
TimeStamp GetCurrentSystemTime()
get current time as reported by system
Definition: TimeStamp.cc:46
const SStationListManager & GetStationListManager() const
string StringToXMLString(const string &str)

, generated on Tue Sep 26 2023.