File indexing completed on 2025-08-05 08:15:35
0001 #ifndef ONCAL_ONCALSERVER_H
0002 #define ONCAL_ONCALSERVER_H
0003
0004 #include <fun4all/Fun4AllServer.h>
0005 #include <phool/PHTimeStamp.h>
0006
0007 #include <time.h> // for time_t
0008 #include <map>
0009 #include <set>
0010 #include <string>
0011 #include <vector>
0012
0013 class OnCal;
0014 class SubsysReco;
0015 class TH1;
0016
0017 namespace fetchrun
0018 {
0019 enum
0020 {
0021 CLOSEST,
0022 PREVIOUS
0023 };
0024 };
0025
0026 class OnCalServer : public Fun4AllServer
0027 {
0028 public:
0029 static OnCalServer *instance();
0030 ~OnCalServer() override;
0031 using Fun4AllServer::registerHisto;
0032 void registerHisto(TH1 *h1d, OnCal *Calibrator, const int replace = 0);
0033 void unregisterHisto(const std::string &calibratorname);
0034 void Print(const std::string &what = "ALL") const override;
0035
0036 void dumpHistos();
0037 int process_event() override;
0038 int BeginRun(const int runno) override;
0039 int EndRun(const int ) override { return 0; }
0040 int End() override;
0041
0042 PHTimeStamp *GetEndValidityTS();
0043
0044 PHTimeStamp *GetBeginValidityTS();
0045 void printStamps();
0046 PHTimeStamp *GetLastGoodRunTS(OnCal *calibrator, const int irun);
0047
0048 void recordDataBase(const bool bookkeep = false);
0049
0050
0051
0052
0053
0054
0055
0056
0057 void RunNumber(const int runnum);
0058 int RunNumber() const { return runNum; }
0059
0060 void BeginTimeStamp(const PHTimeStamp &TimeStp);
0061 void EndTimeStamp(const PHTimeStamp &TimeStp);
0062
0063 int SyncCalibTimeStampsToOnCal(const OnCal *calibrator, const std::string &table, const int commit = 0);
0064 int SyncCalibTimeStampsToOnCal(const OnCal *calibrator, const int commit = 0);
0065 int SyncOncalTimeStampsToRunDB(const int commit = 0);
0066 int ClosestGoodRun(OnCal *calibrator, const int irun, const int previous = fetchrun::CLOSEST);
0067 static int CopyTables(const OnCal *calibrator, const int FromRun, const int ToRun, const int commit = 0);
0068 static int OverwriteCalibration(OnCal *calibrator, const int runno, const int commit = 0, const int fromrun = -1);
0069 int FixMissingCalibration(OnCal *calibrator, const int runno, const int commit = 0, const int fromrun = -1);
0070
0071 int SetBorTime(const int runno);
0072 int SetEorTime(const int runno);
0073 int requiredCalibration(SubsysReco *reco, const std::string &calibratorname);
0074 int FindClosestCalibratedRun(const int irun);
0075 int FillRunListFromFileList();
0076 int AdjustRichTimeStampForMultipleRuns();
0077 int CreateCalibration(OnCal *calibrator, const int myrunnumber, const std::string &what, const int commit = 0);
0078 int GetCalibStatus(const std::string &calibname, const int runno);
0079 static int DisconnectDB();
0080 void TestMode(const int i = 1);
0081
0082 bool updateDBRunRange(const std::string &table, const std::string &column, const int entry, const int firstrun, const int lastrun);
0083 void EventCheckFrequency(const unsigned int i) { eventcheckfrequency = i; }
0084
0085 protected:
0086
0087
0088
0089
0090
0091
0092 bool connectDB();
0093
0094
0095
0096
0097
0098 bool insertRunNumInDB(const std::string &DBtable, const int runno);
0099
0100 bool findRunNumInDB(const std::string &DBtable, const int runno);
0101
0102
0103
0104
0105 bool updateDB(const std::string &table, const std::string &column, int entry);
0106 bool updateDB(const std::string &table, const std::string &column, bool entry);
0107 bool updateDB(const std::string &table, const std::string &column, const std::string &entry,
0108 const int runno, const bool append = false);
0109 int updateDB(const std::string &table, const std::string &column, const time_t ticks);
0110
0111 int check_create_subsystable(const std::string &tablename);
0112 int check_create_successtable(const std::string &tablename);
0113 int add_calibrator_to_statustable(const std::string &calibratorname);
0114 int check_calibrator_in_statustable(const std::string &calibratorname);
0115 static int GetRunTimeTicks(const int runno, time_t &borticks, time_t &eorticks);
0116 void CreateCalibrationUpdateStatus(OnCal *calibrator, const std::string &table, const std::string &tablecomment, const int dbcode);
0117 OnCalServer(const std::string &name = "OnCalServer");
0118 PHTimeStamp beginTimeStamp;
0119 PHTimeStamp endTimeStamp;
0120 int testmode{0};
0121 bool recordDB{false};
0122 TH1 *OnCalServerVars{nullptr};
0123 std::map<std::string, TH1 *> Histo;
0124 std::map<std::string, std::set<std::string> > calibratorhistomap;
0125 bool SetEndTimeStampByHand{false};
0126 bool SetBeginTimeStampByHand{false};
0127
0128 std::string successTable;
0129 unsigned int runNum{0};
0130 unsigned int nEvents{0};
0131 unsigned int eventcheckfrequency{1000};
0132 std::string database{"calBookKeep"};
0133
0134 std::map<std::string, std::set<SubsysReco *> > requiredCalibrators;
0135 std::vector<int> analysed_runs;
0136 std::vector<std::string> inputfilelist;
0137 std::set<int> runlist;
0138 };
0139
0140 #endif