Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OnCalServer.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file OnCalServer.h
1 #ifndef ONCAL_ONCALSERVER_H
2 #define ONCAL_ONCALSERVER_H
3 
5 #include <phool/PHTimeStamp.h>
6 
7 #include <map>
8 #include <set>
9 #include <string>
10 #include <vector>
11 
12 class Event;
13 class OnCal;
14 class PHCompositeNode;
15 class TH1;
16 
17 namespace fetchrun
18 {
19  enum
20  {
23  };
24 };
25 
26 class OnCalServer : public Fun4AllServer
27 {
28  public:
29  static OnCalServer *instance();
30  virtual ~OnCalServer();
32  void registerHisto(TH1 *h1d, OnCal *Calibrator, const int replace = 0);
33  void unregisterHisto(const std::string &calibname);
34  void Print(const std::string &what = "ALL") const;
35 
36  void dumpHistos();
37  int process_event();
38  int BeginRun(const int runno);
39  int EndRun(const int /*runno*/) { return 0; } // do not execute EndRun
40  int End();
41 
43 
45  void printStamps();
46  PHTimeStamp *GetLastGoodRunTS(OnCal *calibrator, const int irun);
47 
48  void recordDataBase(const bool bookkeep = false);
49 
50  // RunNumber() tells the server which run is being analyzed.
51  // and if recordDB is true, this will insert the run number in
52  // calprocess_stat table in calBookKeep database.
53  // All updates are made to the row in the database containing this runNum.
54  // Note that the run number is the primary key in the tables.
55  // If calBookKeep database is not to be updated, this function
56  // should not be called.
57  void RunNumber(const int runnum);
58  int RunNumber() const { return runNum; }
59 
60  void BeginTimeStamp(const PHTimeStamp &TimeStp);
61  void EndTimeStamp(const PHTimeStamp &TimeStp);
62 
63  int SyncCalibTimeStampsToOnCal(const OnCal *calibrator, const std::string &table, const int commit = 0);
64  int SyncCalibTimeStampsToOnCal(const OnCal *calibrator, const int commit = 0);
65  int SyncOncalTimeStampsToRunDB(const int commit = 0);
66  int ClosestGoodRun(OnCal *calibrator, const int runno, const int previous = fetchrun::CLOSEST);
67  int CopyTables(const OnCal *calibrator, const int FromRun, const int ToRun, const int commit = 0) const;
68  int CopySnglTable(const std::string &pdbclass, const std::string &tablename, const int bankid, const int FromRun, const int ToRun, const int commit);
69  int CopySnglTableNewBankId(const std::string &pdbclass, const std::string &tablename, const int bankid, const int Tobankid, const int FromRun, const int ToRun, const int commit);
70  int OverwriteCalibration(OnCal *calibrator, const int runno, const int commit = 0, const int fromrun = -1);
71  int FixMissingCalibration(OnCal *calibrator, const int runno, const int commit = 0, const int fromrun = -1);
72 
73  int SetBorTime(const int runno);
74  int SetEorTime(const int runno);
75  int requiredCalibration(SubsysReco *reco, const std::string &calibratorname);
76  int FindClosestCalibratedRun(const int irun);
79  int CreateCalibration(OnCal *calibrator, const int myrunnumber, const std::string &what, const int commit = 0);
80  int GetCalibStatus(const std::string &calibname, const int runno);
81  int DisconnectDB();
82  void TestMode(const int i = 1);
83  // need to be able to call this from the outside
84  bool updateDBRunRange(const char *table, const char *column, const int value, const int firstrun, const int lastrun);
85  void EventCheckFrequency(const unsigned int i) { eventcheckfrequency = i; }
86 
87  protected:
88  //-------------------------------------
89  // following functions access DB using odbc++ library
90  // these are designed to insert status in calBookKeep (or success) database.
91  // setDB() sets the name of the database to connect to. e.g., calibration
92  // this database should exist in the odbc.ini file.
93  // void setDB(const char* DBname){database = DBname;}
94  bool connectDB();
95 
96  // insertRunNumInDB enters the run number in the calBookKeep database.
97  // All other updates are made to rows in the database containing the runNum.
98  // This function should be called before any updates are made.
99  // Returns true on successful DB insert.
100  bool insertRunNumInDB(const std::string &tableName, const int runno);
101 
102  bool findRunNumInDB(const std::string &tableName, const int runno);
103 
104  // these functions update different columns in the success database tables.
105  // Ony the row with the run number set by setRunNum() is updated.
106 
107  bool updateDB(const char *table, const char *column, int value);
108  bool updateDB(const char *table, const char *column, bool value);
109  bool updateDB(const std::string &table, const std::string &column, const std::string &value,
110  const int runno, const bool append = false);
111  int updateDB(const std::string &table, const std::string &column, const time_t ticks);
112 
113  int check_create_subsystable(const std::string &DBTable);
114  int check_create_successtable(const std::string &DBTable);
115  int add_calibrator_to_statustable(const std::string &calibname);
116  int check_calibrator_in_statustable(const std::string &calibname);
117  int GetRunTimeTicks(const int runno, time_t &borticks, time_t &eorticks);
118  void CreateCalibrationUpdateStatus(OnCal *calibrator, const std::string &table, const std::string &tablecomment, const int dbcode);
119  OnCalServer(const std::string &name = "OnCalServer");
120  PHTimeStamp beginTimeStamp; // begin run timestamp of run analysing
121  PHTimeStamp endTimeStamp; // end run timestamp of run analysing
122  int testmode;
123  bool recordDB;
125  std::map<std::string, TH1 *> Histo;
126  std::map<std::string, std::set<std::string> > calibratorhistomap;
129 
131  unsigned int runNum;
132  unsigned int nEvents;
133  unsigned int eventcheckfrequency;
134  std::string database; // this holds the name of the database
135  // should be set to calibrations for normal running
136  std::map<std::string, std::set<SubsysReco *> > requiredCalibrators;
137  std::vector<int> analysed_runs;
138  std::vector<std::string> inputfilelist;
139  std::set<int> runlist;
140 };
141 
142 #endif /* __ONCALSERVER_H */