//////////////////////////////////////////////////////////////////// /// \class RAT::EventTime /// /// \brief Acts on the universal time of events /// /// \author Gabriel D. Orebi Gann -- contact person /// /// REVISION HISTORY:\n /// 09 Apr 2010 : Gabriel Orebi Gann - Add functions to GetDate /// in yyyy/mm/dd format\n /// 12 May 2010 : Gabriel Orebi Gann - Remove long double fns\n /// 14 Jun 2011 : Andy Mastbaum - Use static members and a flag to load /// DB values only once and cache them.\n /// 07-09-2012 : Nuno Barros - Modified the class to no longer load the database in the constructor, /// but rather the first time it is accessed. This way, the DATE database field /// can be modified in the macro file. It adds a performance penalty /// on first "use", but then the performance penalty on consecutive calls is negligible. /// 14 Feb 2016: F. Descamps - Changed the place the start if the run is /// retrieved from. It will now be taken from RUN.ratdb. /// 01 Jan 2016: F. Descamps - Changed the start-time format. /// 2017-09-17: Anthony LaTorre - change GetIntDate() and GetIntTime() to /// return uint32_t instead of ints. /// /// \details This class holds the start date of the run /// (input from RUN.ratdb) in `universal time': /// time since 01 Jan 2010, in days+secs+nsecs. /// Member functions of this class can return /// the UT of a single event (given the deltaT /// since the start of the run), or compare two /// UT stamps, or return the true date /// //////////////////////////////////////////////////////////////////// #ifndef __RAT_EventTime__ #define __RAT_EventTime__ #include #include #include "dprintf.hpp" #include "fileio.hpp" #include "multiio.hpp" #include #include #include #include #include namespace RAT { class EventTime { public: EventTime(); virtual ~EventTime() {}; // What might we want to do? // Get start time (controlled by ratdb) // Get current time // Increment time // Compare times // Get date (yr, month, day) // Get time / date in single objects (str/int) // Set time of this object to the UT at the start of the MC run void SetStart(); void Init(); void LoadDB(); // Set times to chosen values void SetUniversalTime( const DS::UniversalTime& ut ) { fDays = ut.GetDays(); fSecs = ut.GetSeconds(); fNsecs = ut.GetNanoSeconds(); } DS::UniversalTime GetUniversalTime() { return DS::UniversalTime(fDays, fSecs, fNsecs); } void SetUTDays(int day) {fDays = day;}; void SetUTSecs(int sec) {fSecs = sec;}; void SetUTNsecs(double nsec) {fNsecs = nsec;}; void SetUT(int day, int sec, double nsec) {fDays = day;fSecs=sec;fNsecs=nsec;}; // Set time of this object to values from the EV or MC branches void SetTimeEV(RAT::DS::EV *ev); void SetTimeMC(RAT::DS::MC *mc); // Get times int GetStartUTDays() {return fTimeOffsetDays;}; int GetStartUTSecs() {return fTimeOffsetSecs;}; double GetStartUTNsecs() {return fTimeOffsetNsecs;}; int GetUTDays() {return fDays;}; int GetUTSecs() {return fSecs;}; double GetUTNsecs() {return fNsecs;}; int GetCalYear() {return fYear;}; int GetCalMonth() {return fMonth;}; int GetCalDay() {return fDay;}; void IncrementUT(double deltaT); void IncrementUT(EventTime evT); EventTime CompareUT(EventTime evT1, EventTime evT2); EventTime CompareUT(EventTime evT2); EventTime CompareUT(EventTime *evT1, EventTime *evT2); EventTime CompareUT(EventTime *evT2); double GetFullUTNsecs(); uint32_t GetIntTime(); std::string GetStrTime(); uint32_t GetIntDate(); std::string GetStrDate(); // Account for roll-over in times void RollOver(); // Which one comes first? bool TimeOrder(EventTime ev2); bool TimeOrder(EventTime *ev2); int GetUTDay(int year, int month, int day, int secs, double nsecs, int &UTdays, int &UTsecs, double &UTnsecs); protected: // Set calendar date to match current UT void SetDate(); // Different versions of JD code (used for testing: they all agree) void GetDateSNO(int UTdays, int UTsecs, double UTnsecs); int GetUTDaySNO(int year, int month, int day, int secs, double nsecs, int &UTdays, int &UTsecs, double &UTnsecs); int GetUTDayNAVY(int year, int month, int day, int secs, double nsecs, int &UTdays, int &UTsecs, double &UTnsecs); int fTimeOffsetDays; int fTimeOffsetSecs; double fTimeOffsetNsecs; // cache copies of the database fields static DBLinkPtr fDateBank; static bool fDBLoaded; static int fTimeOffsetDaysDB; static int fTimeOffsetSecsDB; static double fTimeOffsetNsecsDB; double fJDOffset; int fDays; int fSecs; double fNsecs; int fYear; int fMonth; int fDay; }; } // namespace RAT #endif // __RAT_EventTime__