RdTransformAds_bLogFile.cc
Go to the documentation of this file.
2 #include "AirplaneUtil.h"
3 #include "Ads_bDataBase.h"
4 #include "Airplane.h"
5 #include "Flight.h"
6 
7 #include <limits> // setprecision
8 #include <iomanip> // setprecision
9 
10 using namespace evt;
11 using namespace revt;
12 using namespace std;
13 using namespace utl;
14 using namespace fwk;
15 using namespace RdAirplane;
16 using namespace boost;
17 namespace fs = filesystem;
18 
19 RdTransformAds_bLogFile::RdTransformAds_bLogFile() :
20  _outputFile_(),
21  _ads_bDataBase_(NULL) {}
22 
24 
26 
27  _globalCoordinateSystem_ = det::Detector::GetInstance().GetReferenceCoordinateSystem();
28  string outputDirectory;
29 
30  CentralConfig* centralConfig = CentralConfig::GetInstance();
31  Branch timingTopBranch = centralConfig->GetTopBranch("RdTransformAds_bLogFile");
32  timingTopBranch.GetChild("OutputDirectoy").GetData(outputDirectory);
33 
34  //reading the ads-b data that is grouped by airplane and by flight over the AERA field
36  INFO("Assuming a time shift of the capture time of the ADS-B signal and the real position measurement on the airplane of " + lexical_cast<string>(_ads_bDataBase_->getTimeShift().GetInterval()/ms) + "ms.");
37 
38  _outputFile_ = fs::path(outputDirectory);
39  if(!fs::exists(_outputFile_)) {
40  ERROR("The output directory does not exist: " + _outputFile_.string());
41  return eFailure;
42  }
43  _outputFile_+="/adsbData.dat";
44 
46  ERROR("The output file already exists: " + _outputFile_.string());
47  return eFailure;
48  }
49  INFO("Data conversion started.");
50 
51  ofstream outputFileHandle;
52  try {
53  outputFileHandle.open(_outputFile_.c_str());
54  if(!outputFileHandle.is_open()) {
55  ERROR("Could not write data.");
56  return eFailure;
57  }
58  outputFileHandle
59  << "Flight Id| "
60  << "Time (Unix-Timestamp)| "
61  << "Latitude (UTM) (degree)| "
62  << "Longitude (UTM) (degree)| "
63  << "Pressure Altitude (UTM) (m)| "
64  << "Corrected Pressure Altitude (m)| "
65  << "GPS Altitude (m)| "
66  << endl
67  << setprecision(numeric_limits<long double>::digits10 + 1);
69  //iterate over all airplanes
70  for(Ads_bDataBase::AirplaneMap::const_iterator airplaneIter = airplanes.begin();
71  airplaneIter != airplanes.end();
72  ++airplaneIter) {
73  const Airplane* airplane = airplaneIter->second;
74  const Airplane::FlightList& flights = airplane->getFlights();
75  for(Airplane::FlightList::const_iterator flightIter = flights.begin();
76  flightIter != flights.end();
77  ++flightIter) {
78  const Flight* flight = *flightIter;
79  const Flight::Ads_bEventSet& ads_bEvents = flight->getAdsbEvents();
80  // iterate over all fly-overs
81  for(Flight::Ads_bEventSet::iterator ads_bEventIter = ads_bEvents.begin();
82  ads_bEventIter != ads_bEvents.end();
83  ++ads_bEventIter) {
84  const Ads_bEvent* ads_bEvent = *ads_bEventIter;
85  Ads_bEvent::AltitudeType altitudeType = ads_bEvent->getAltitudeType();
86  double pressureAltitude = altitudeType == Ads_bEvent::eGPSAltitude ? -1 : ads_bEvent->getAltitude(Ads_bEvent::ePressureAltitude);
87  double correctedPressureAltitude = altitudeType == Ads_bEvent::eGDASCorrectedPressureAltitude ? ads_bEvent->getAltitude(Ads_bEvent::eGDASCorrectedPressureAltitude) : -1;
88  double gpsAltitude = altitudeType == Ads_bEvent::eGPSAltitude ? ads_bEvent->getAltitude(Ads_bEvent::eGPSAltitude) : -1;
89  const UTMPoint& utmCoordinates = ads_bEvent->getCoordinates();
90  tuple<double, double, double> geodeticCoordinates = utmCoordinates.GetGeodeticCoordinates();
91  double latitude = geodeticCoordinates.get<0>();
92  double longitude = geodeticCoordinates.get<1>();
93 
94  outputFileHandle
95  << flight->getId() << " "
96  << UTCDateTime(ads_bEvent->getCaptureTime()).GetUnixSecond() << " "
97  << latitude/degree << " "
98  << longitude/degree << " "
99  << pressureAltitude/m << " "
100  << correctedPressureAltitude/m << " "
101  << gpsAltitude/m
102  << endl;
103 
104  }
105  }
106  }
107  } catch(...) {
108  outputFileHandle.close();
109  throw;
110  }
111  outputFileHandle.close();
112  INFO("Data conversion finished. (Aaaaand Offline might have killed itself. If so hit Ctr+C)");
113  return eSuccess;
114 }
115 
117  event.HasREvent(); // suppress unused variable warning
118  return eSuccess;
119 }
120 
121 
123  return eSuccess;
124 }
125 
126 
const double degree
utl::CoordinateSystemPtr _globalCoordinateSystem_
fwk::VModule::ResultFlag Run(evt::Event &event)
Run: invoked once per event.
Report success to RunController.
Definition: VModule.h:62
Class to hold and convert a point in geodetic coordinates.
Definition: UTMPoint.h:40
fwk::VModule::ResultFlag Init()
Initialize: invoked at beginning of run (NOT beginning of event)
const utl::TimeInterval & getTimeShift() const
Definition: Ads_bDataBase.h:68
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
const Ads_bEventSet & getAdsbEvents(Ads_bEvent::AltitudeType pAltitudeType) const
Definition: Flight.cc:121
constexpr double ms
Definition: AugerUnits.h:164
char * exists
Definition: XbArray.cc:12
Class representing a document branch.
Definition: Branch.h:107
const utl::UTMPoint & getCoordinates() const
Definition: Ads_bEvent.cc:83
AltitudeType getAltitudeType() const
Definition: Ads_bEvent.h:61
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
double GetInterval() const
Get the time interval as a double (in Auger base units)
Definition: TimeInterval.h:69
std::map< std::string, Airplane * > AirplaneMap
Definition: Ads_bDataBase.h:35
fwk::VModule::ResultFlag Finish()
Finish: invoked at end of the run (NOT end of the event)
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
const utl::TimeStamp & getCaptureTime() const
Definition: Ads_bEvent.h:39
double getAltitude(AltitudeType pAltitudeType) const
Definition: Ads_bEvent.cc:102
const AirplaneMap & getAirplanes()
Definition: Ads_bDataBase.h:50
static Ads_bDataBase * getSharedDataBase()
Report failure to RunController, causing RunController to terminate execution.
Definition: VModule.h:64
const FlightList & getFlights() const
Definition: Airplane.h:46
std::set< Ads_bEvent *, Ads_bEventComparator > Ads_bEventSet
Definition: Flight.h:31
Main configuration utility.
Definition: CentralConfig.h:51
std::list< Flight * > FlightList
Definition: Airplane.h:22
const std::string & getId() const
Definition: Flight.h:46
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
constexpr double m
Definition: AugerUnits.h:121
boost::tuple< double, double, double > GetGeodeticCoordinates() const
Get geodetic latitude, longitude, height.
Definition: UTMPoint.cc:67
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)

, generated on Tue Sep 26 2023.