RunHistory.cpp
Go to the documentation of this file.
1 #include <DatabaseUtils/RunHistory/RunHistory.h>
2 #include <DatabaseUtils/DAQConfig/PixelEnableMasks.h>
3 #include <DatabaseUtils/DCS/APDSettings.h>
4 #include <NovaDAQConventions/DAQConventions.h>
5 #include <cstdlib>
6 
7 namespace daqcfg = dbutils::daqconfig;
8 using namespace std;
9 
10 namespace dbutils {
11 
12  //**********************************************************************
13 
14  RunHistory::RunHistory(int run, std::string det) :
15  _runNumber(run), _nsubrun(0), _nTotTrig(0),
16  _nActiveChannels(0), _nTotalChannels(0),
17  _nTotalFEBs(0), _nMaskedOffFEBs(0),
18  _tStart("2010-01-01 00:00:00"), _tEnd(""),
19  _dcmList(0), _bnevbList(0)
20  {
21  runsTable.reset(new db::Table("NovaDatabase/tables/RunHistory/Runs.xml"));
22  resTable.reset(new db::Table("NovaDatabase/tables/RunHistory/DAQResourcesByRun.xml"));
24  _detector = det;
25  runsTable->SetDetector(det);
26  resTable->SetDetector(det);
27  char daqEnv[128];
28  sprintf(daqEnv,"NOVADAQ_ENVIRONMENT=%s",det.c_str());
29  putenv(daqEnv);
30  }
31  else {
32  std::string errStr = "RunHistory::RunHistory: invalid detector name!";
33  throw std::runtime_error(errStr);
34  }
35 
36  hwposTable.reset(new db::Table("NovaDatabase/tables/Hardware/HardwarePosition.xml"));
37  hwposTable->SetDBInfo("nova_hardware","ifdbprod.fnal.gov",
38  "5432","nova_reader");
39  hwposTable->SetIgnoreEnvVar(true);
40 
41  Load();
42  }
43  //**********************************************************************
44 
46  _runNumber(run), _nsubrun(0), _nTotTrig(0),
49  _tStart("2010-01-01 00:00:00"), _tEnd(""),
50  _dcmList(0), _bnevbList(0)
51  {
52  runsTable.reset(new db::Table("NovaDatabase/tables/RunHistory/Runs.xml"));
53  resTable.reset(new db::Table("NovaDatabase/tables/RunHistory/DAQResourcesByRun.xml"));
56  runsTable->SetDetector(det);
57  resTable->SetDetector(det);
58  char daqEnv[128];
59  sprintf(daqEnv,"NOVADAQ_ENVIRONMENT=%s",_detector.c_str());
60  putenv(daqEnv);
61  }
62  else {
63  std::string errStr = "RunHistory::RunHistory: invalid detector id!";
64  throw std::runtime_error(errStr);
65  }
66 
67  hwposTable.reset(new db::Table("NovaDatabase/tables/Hardware/HardwarePosition.xml"));
68  hwposTable->SetDBInfo("nova_hardware","ifdbprod.fnal.gov",
69  "5432","nova_reader");
70  hwposTable->SetIgnoreEnvVar(true);
71 
72  Load();
73  }
74 
75  //**********************************************************************
76 
78  {
79  }
80 
81  //**********************************************************************
82 
85  {
86  if (dbname!="") {
87  runsTable->SetDBName(dbname);
88  runsTable->SetIgnoreEnvVar(true);
89  resTable->SetDBName(dbname);
90  resTable->SetIgnoreEnvVar(true);
91  }
92  if (dbhost!="") {
93  runsTable->SetDBHost(dbhost);
94  runsTable->SetIgnoreEnvVar(true);
95  resTable->SetDBHost(dbhost);
96  resTable->SetIgnoreEnvVar(true);
97  }
98  if (user!="") {
99  runsTable->SetUser(user);
100  runsTable->SetIgnoreEnvVar(true);
101  resTable->SetUser(user);
102  resTable->SetIgnoreEnvVar(true);
103  }
104  if (dbport!="") {
105  runsTable->SetDBPort(dbport);
106  runsTable->SetIgnoreEnvVar(true);
107  resTable->SetDBPort(dbport);
108  resTable->SetIgnoreEnvVar(true);
109  }
110 
111  }
112 
113  //**********************************************************************
114 
116  {
117  runsTable->Clear();
118  resTable->Clear();
119  hwposTable->Clear();
120 
121  runsTable->SetValidityRange("run",_runNumber);
122  runsTable->LoadFromDB();
123  db::Row* row = runsTable->GetRow(0);
124  if (row) {
125  string timeStr;
126  if (row->Col("tstart")->Get(timeStr)) _tStart = timeStr;
127  if (row->Col("tstop")->Get(timeStr)) _tEnd = timeStr;
128  row->Col("nevents")->Get(_nTotTrig);
129  row->Col("configid")->Get(_gCfgId);
130  row->Col("nsubruns")->Get(_nsubrun);
131  }
132 
133  std::vector<std::string> tmpDCMList;
134  resTable->SetValidityRange("run",_runNumber);
135  resTable->LoadFromDB();
136  int nResources = resTable->NRow();
137  for (int i=0; i<nResources; ++i) {
138  row = resTable->GetRow(i);
139  string rtype;
140  string appname;
141  if (row->Col("resource_type")->Get(rtype)) {
142  if (rtype == "bnevb") {
143  BNEVB b;
144  row->Col("appname")->Get(appname);
145  b.appname = appname;
146  _bnevbList.push_back(b);
147  }
148  else if (rtype == "dcm") {
149  DCM d;
150  row->Col("appname")->Get(appname);
151  d.appname = appname;
152  _dcmList.push_back(d);
153  tmpDCMList.push_back(appname);
154  }
155  }
156  }
157 
158  daqcfg::PixelEnableMasks pixelEnableMasks(_gCfgId, tmpDCMList);
159  dcs::APDSettings apdSettings(_gCfgId, tmpDCMList);
160  for (uint32_t iDCM = 0; iDCM < _dcmList.size(); ++iDCM) {
161  int64_t febMask = 0;
162  pixelEnableMasks.getFEBEnableMask(_dcmList[iDCM].appname,
163  febMask);
164  _dcmList[iDCM].febMask = febMask;
165  for (int iFEB = 0; iFEB < 64; ++iFEB) {
166  bool countIt = true;
167  if ( (_dcmList[iDCM].appname == "dcm-3-01-03" ||
168  _dcmList[iDCM].appname == "dcm-3-02-03") &&
169  ((iFEB >= 16 && iFEB <= 31) || (iFEB >= 47)) )
170  countIt = false;
171  if ( (_dcmList[iDCM].appname == "dcm-3-01-01" ||
172  _dcmList[iDCM].appname == "dcm-3-02-01" ||
173  _dcmList[iDCM].appname == "dcm-3-01-02" ||
174  _dcmList[iDCM].appname == "dcm-3-02-02") &&
175  (iFEB == 47 || iFEB == 63))
176  countIt = false;
177  if (( _dcmList[iDCM].appname == "dcm-3-03-02") &&
178  ((iFEB >= 62)||(iFEB >= 46 && iFEB <= 47)))
179  countIt = false;
180  if (( _dcmList[iDCM].appname == "dcm-3-03-03") &&
181  ((iFEB >= 16 && iFEB <= 31)||(iFEB >= 46)))
182  countIt = false;
183  if ( _dcmList[iDCM].appname == "dcm-3-04-01")
184  if ((iFEB >= 6 && iFEB <= 15) || iFEB >= 22)
185  countIt = false;
186  if ( _dcmList[iDCM].appname == "dcm-3-04-02")
187  if ((iFEB >= 7 && iFEB <= 15) || (iFEB >= 23 && iFEB <= 31) ||
188  iFEB >= 39)
189  countIt = false;
190 
191  if (countIt) {
192  FEB f;
193  f.dcmid = _dcmList[iDCM].appname;
194  f.loc = iFEB;
195  _nTotalChannels += 32;
196  ++_nTotalFEBs;
197  f.isEnabled = false;
198  if (pixelEnableMasks.febIsEnabled(_dcmList[iDCM].appname, iFEB)) {
199  f.isEnabled = true;
200  int32_t pixelMask = 0;
201  pixelEnableMasks.getPixelEnableMask(_dcmList[iDCM].appname,
202  iFEB, pixelMask);
203  f.pixelMask = pixelMask;
204  f.nActivePix = pixelEnableMasks.
205  getEnabledPixelCountForFEB(_dcmList[iDCM].appname, iFEB);
207  f.apdV = 0;
208  f.isCooled = false;
209  f.tempEnabled = false;
210  f.temperature = -100;
211  if (apdSettings.hasValidData()) {
212  apdSettings.getTemperatureEnable(f.dcmid,f.loc,f.tempEnabled);
213  double temp;
214  apdSettings.getTemperature(f.dcmid,f.loc,temp);
215  f.temperature = temp;
216  }
217  }
218  if (! f.isEnabled) _nMaskedOffFEBs++;
219  _dcmList[iDCM].feb[iFEB] = f;
220  }
221  }
222 
223  }
224 
225 
226  std::string cmd = "detector='" + _detector + "' and hw_type='APD' and install_date < '" + _tStart + "' and (remove_date is NULL or remove_date > '" + _tStart + "')";
227  hwposTable->SetValiditySQL(cmd);
228  hwposTable->LoadFromDB();
229  for (int i=0; i<hwposTable->NRow(); ++i) {
230  row = hwposTable->GetRow(i);
231  if (row) {
232  int block; row->Col("block")->Get(block);
233  int plane; row->Col("plane")->Get(plane);
234  int module_position; row->Col("module_position")->Get(module_position);
235  }
236  }
237 
238  }
239 
240  //**********************************************************************
241 
242  time_t RunHistory::TStart() const {
243  time_t t;
245  return t;
246  else
247  return 0;
248  }
249 
250  //**********************************************************************
251 
252  time_t RunHistory::TStop() const {
253  time_t t;
254  string tEnd = _tEnd;
255  if (_tEnd == "")
256  tEnd = "2000-01-01 00:00:00";
258  return t;
259  else
260  return 0;
261  }
262 
263  //**********************************************************************
264 
266  cout << "****************************************" << endl;
267  cout << "Dump of run " << _runNumber << endl;
268  cout << "****************************************\n" << endl;
269  cout << "Num Subruns : " << _nsubrun << endl;
270  cout << "Start time : " << TStartAsString() << endl;
271  cout << "End time : " << TStopAsString() << endl;
272  cout << "Trig Tot : " << _nTotTrig << endl;
273  cout << "Num Active Channels: " << _nActiveChannels << endl;
274  cout << "Num DCMs : " << _dcmList.size() << endl;
275  for (unsigned int i=0; i<_dcmList.size(); ++i)
276  cout << "\t" << _dcmList[i].appname << endl;
277  cout << "Num BNEVBs : " << _bnevbList.size() << endl;
278  for (unsigned int i=0; i<_bnevbList.size(); ++i)
279  cout << "\t" << _bnevbList[i].appname << endl;
280 
281  }
282 
283  //**********************************************************************
284 
285  bool RunHistory::FEBEnableMask(const std::string& dcmName,int64_t& febMask) {
286  if (_pixMaskPtr.get() == 0) {
287  std::vector<std::string> dcmNameList;
288  for (unsigned int i=0; i<_dcmList.size(); ++i) {
289  dcmNameList.push_back(_dcmList[i].appname);
290  }
291  daqcfg::PixelEnableMasks blah(_gCfgId, dcmNameList);
292  _pixMaskPtr.reset(new daqcfg::PixelEnableMasks(_gCfgId, dcmNameList));
293  }
294 
295  if (! _pixMaskPtr->hasValidData()) {return false;}
296  return _pixMaskPtr->getFEBEnableMask(dcmName, febMask);
297  }
298 
299  //**********************************************************************
300 
302  const int& febId, int32_t& pixelMask) {
303  if (_pixMaskPtr.get() == 0) {
304  std::vector<std::string> dcmNameList;
305  for (unsigned int i=0; i<_dcmList.size(); ++i) {
306  dcmNameList.push_back(_dcmList[i].appname);
307  }
308  _pixMaskPtr.reset(new daqcfg::PixelEnableMasks(_gCfgId, dcmNameList));
309  }
310 
311  if (! _pixMaskPtr->hasValidData()) {return false;}
312  return _pixMaskPtr->getPixelEnableMask(dcmName, febId, pixelMask);
313  }
314 
315  //**********************************************************************
316 
318  const int& febId,
319  std::vector<int16_t>& thresholdList) {
320  if (_pixThreshPtr.get() == 0) {
321  std::vector<std::string> dcmNameList;
322  for (unsigned int i=0; i<_dcmList.size(); ++i) {
323  dcmNameList.push_back(_dcmList[i].appname);
324  }
325  _pixThreshPtr.reset(new daqcfg::PixelThresholds(_gCfgId, dcmNameList));
326  }
327 
328  if (! _pixThreshPtr->hasValidData()) {return false;}
329  return _pixThreshPtr->getThresholdsForFEB(dcmName, febId, thresholdList);
330  }
331 
332 } // end of namespace dbutils
static std::string GetName(int id)
std::string TStartAsString() const
Definition: RunHistory.h:87
std::string TStopAsString() const
Definition: RunHistory.h:88
Column & Col(int i)
Find index of column with name. Suitable for passing to Col.
Definition: Row.h:63
std::unique_ptr< db::Table > hwposTable
Definition: RunHistory.h:136
bool getFEBEnableMask(const std::string &dcmName, int64_t &febMask)
std::string _tStart
Definition: RunHistory.h:126
std::unique_ptr< daqcfg::PixelThresholds > _pixThreshPtr
Definition: RunHistory.h:138
static bool TimeAsStringToTime_t(std::string ts, time_t &t)
bool getTemperatureEnable(const std::string &dcmName, const int &febId, bool &enableFlag)
std::unique_ptr< db::Table > resTable
Definition: RunHistory.h:135
time_t TStop() const
Definition: RunHistory.cpp:252
bool Get(T &val) const
Definition: Column.h:85
bool getPixelEnableMask(const std::string &dcmName, const int &febId, int32_t &pixelMask)
time_t TStart() const
Definition: RunHistory.cpp:242
string cmd
Definition: run_hadd.py:52
block
print "ROW IS " print row
Definition: elec2geo.py:31
virtual bool hasValidData() const
Definition: APDSettings.h:51
std::vector< BNEVB > _bnevbList
Definition: RunHistory.h:130
static bool DetIdOk(int id)
Float_t d
Definition: plot.C:236
std::unique_ptr< db::Table > runsTable
Definition: RunHistory.h:134
void SetDBInfo(std::string dbname="", std::string dbhost="", std::string user="", std::string port="")
Definition: RunHistory.cpp:83
bool febIsEnabled(const std::string &dcmName, const int &febId)
bool getTemperature(const std::string &dcmName, const int &febId, int &temperature)
Definition: run.py:1
OStream cout
Definition: OStream.cxx:6
std::vector< DCM > _dcmList
Definition: RunHistory.h:129
std::string _tEnd
Definition: RunHistory.h:127
RunHistory(int run, std::string det)
Definition: RunHistory.cpp:14
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
std::unique_ptr< daqcfg::PixelEnableMasks > _pixMaskPtr
Definition: RunHistory.h:137
const hit & b
Definition: hits.cxx:21
bool PixelEnableMask(const std::string &dcmName, const int &febId, int32_t &pixelMask)
Definition: RunHistory.cpp:301
bool PixelThresholdsForFEB(const std::string &dcmName, const int &febId, std::vector< int16_t > &thresholdList)
Definition: RunHistory.cpp:317
static bool DetNameOk(std::string name)
bool FEBEnableMask(const std::string &dcmName, int64_t &febMask)
Definition: RunHistory.cpp:285
std::string _detector
Definition: RunHistory.h:125