RunHistoryDUNE.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // RunHistoryDUNE
4 //
5 // jpaley@fnal.gov
6 //
7 ////////////////////////////////////////////////////////////////////////
8 // Framework includes
9 
10 // C++ language includes
11 #include <iostream>
12 
13 // LArSoft includes
14 #include "RunHistoryDUNE.h"
15 
16 // Framework includes
18 #include "cetlib_except/exception.h"
19 
20 #include "nuevdb/IFDatabase/Util.h"
21 #include <boost/tokenizer.hpp>
22 #include <ctime>
23 
24 namespace dune {
25  //-----------------------------------------------
27  {
28  if (detid > 0 && detid < kNDUNEDetectors && run > 0) {
29  fDetId = detid;
30  fRun=run;
31  switch(fDetId) {
32  case(k35t):
33  fDetName = "dune35t";
34  break;
35  case(kProtoDUNE):
36  fDetName = "protoDUNE";
37  break;
38  case(kFarDet):
39  fDetName = "FarDet";
40  break;
41  case(kNearDet):
42  fDetName = "NearDet";
43  break;
44  default:
45  fDetName = "";
46  break;
47  }
48  }
49  else
50  abort();
51 
52  if (!Update(run)) abort();
53  fSCChanMap.clear();
54  fSCInvChanMap.clear();
55  fSCDataTable.reset();
56  }
57 
58  //------------------------------------------------
60  {
61  }
62 
63  //------------------------------------------------
65  {
66  if (!fSCChanMap.empty()) return true;
67 
69 
70  if (fDetName.empty()) {
71  std::cout << __PRETTY_FUNCTION__ << ": Error in line " << __LINE__ << ". Detector name is undefined." << std::endl;
72  return false; //std::abort();
73  }
74 
76  t.SetTableName("daq_sc_chanmap");
79 
80  int chanNameIdx = t.AddCol("chan_name","text");
81 
82  t.SetMinTSVld(1);
83  t.SetMaxTSVld(1);
84 
85  t.SetVerbosity(100);
86  if (! t.Load()) {
87  std::cout << "Error in " << __PRETTY_FUNCTION__ << ", line " << __LINE__ << ". Load from database failed." << std::endl;
88  return false; //std::abort();
89  }
90 
91  if (t.NRow() == 0) {
92  std::cout << "Error in " << __PRETTY_FUNCTION__ << ", line " << __LINE__ << ". Number of rows in table is 0. This should never be the case!" << std::endl;
93  return false;
94  }
95 
97  std::string chanName;
98  uint64_t chan;
99  for (int i=0; i<t.NRow(); ++i) {
100  row = t.GetRow(i);
101  chan = row->Channel();
102  row->Col(chanNameIdx).Get(chanName);
103  fSCChanMap[chanName] = chan;
104  fSCInvChanMap[chan] = chanName;
105  }
106 
107  return true;
108  }
109 
110  //------------------------------------------------
112  {
113  LoadSCData();
114  LoadSCChanMap();
115 
116  fSCDataTable->FillChanRowMap();
117  int rvIdx = fSCDataTable->GetColIndex("rvalue");
118  float rv;
119 
120  std::vector<uint64_t> chanList = fSCDataTable->VldChannels();
121 
122  for (size_t ichan=0; ichan<chanList.size(); ++ichan) {
123  std::vector<nutools::dbi::Row*> vldRow = fSCDataTable->GetVldRows(chanList[ichan]);
124  std::cout << fSCInvChanMap[chanList[ichan]];
125 
126  for (size_t irow=0; irow<vldRow.size(); ++irow) {
127  vldRow[irow]->Col(rvIdx).Get(rv);
128  std::cout << ", (" << rv << "," << vldRow[irow]->VldTime()-fTStart << ")";
129  }
130  std::cout << std::endl;
131  }
132  }
133 
134  //------------------------------------------------
136  {
138 
139  for (auto i : fASICSettingsMap) {
140  int chan = i.first%100000;
141  int asic = i.first/100000;
142  std::cout << "ASIC " << asic << ", " << chan << ": " << i.second.gain << " mV/fC, " << i.second.shape << " us, " << i.second.base << " mV" << std::endl;
143  }
144  }
145 
146  //------------------------------------------------
148  {
149  if (fASICSettingsTable.get() != nullptr) return true;
150 
152  fASICSettingsTable->SetDetector(fDetName);
153 
154  fASICSettingsTable->SetTableName("asic_settings_by_run");
157 
158  int gainIdx = fASICSettingsTable->AddCol("gain","float");
159  int shapeIdx = fASICSettingsTable->AddCol("shape","float");
160  int baseIdx = fASICSettingsTable->AddCol("base","int");
161 
162  fASICSettingsTable->SetMinTSVld(fRun);
163  fASICSettingsTable->SetMaxTSVld(fRun);
164 
165  fASICSettingsTable->SetVerbosity(100);
166  if (! fASICSettingsTable->Load()) {
167  std::cout << "Error in " << __PRETTY_FUNCTION__ << ", line " << __LINE__ << ". Load from database failed." << std::endl;
168  return false;
169  }
170 
171  if (!fASICSettingsTable->NRow()) {
172  std::cout << "WARNING! " << __PRETTY_FUNCTION__ << ", no ASIC settings found for this run." << std::endl;
173  return false;
174  }
175 
176  fASICSettingsMap.clear();
177  float g=0.;
178  float s=0.;
179  int b=0;
180  for (int irow=0; irow<fASICSettingsTable->NRow(); ++irow) {
181  nutools::dbi::Row* r = fASICSettingsTable->GetRow(irow);
182  int chan = r->Channel();
183  r->Col(gainIdx).Get(g);
184  r->Col(shapeIdx).Get(s);
185  r->Col(baseIdx).Get(b);
186  fASICSettingsMap[chan] = ASICSetting(g,s,b);
187  }
188  return true;
189  }
190 
191  //------------------------------------------------
193  {
194  if (fSCDataTable.get() != nullptr) return true;
195 
197  fSCDataTable->SetDetector(fDetName);
198 
199  fSCDataTable->SetTableName("daq_slowcontrols");
201  fSCDataTable->SetDataTypeMask(nutools::dbi::kNone);
202 
203  fSCDataTable->AddCol("rvalue","float");
204 
205  fSCDataTable->SetMinTSVld(fTStart);
206  fSCDataTable->SetMaxTSVld(fTStop);
207 
208  fSCDataTable->SetVerbosity(100);
209  if (! fSCDataTable->Load()) {
210  std::cout << "Error in " << __PRETTY_FUNCTION__ << ", line " << __LINE__ << ". Load from database failed." << std::endl;
211  return false; //std::abort();
212  }
213 
214  std::cout << "Read in " << fSCDataTable->NRow() << " rows of slow control data for run " << fRun << std::endl;
215 
216  return true;
217  }
218 
219  //------------------------------------------------
221  {
222  if (run == 0) return false;
223 
224  fSCDataTable.reset();
225  fASICSettingsTable.reset();
226 
227  std::string tableName = "run_summary";
229 
231  t.SetTableName(tableName);
233 
234  int runIdx = t.AddCol("run", "integer");
235  int cfgLabelIdx = t.AddCol("configuration_label", "integer");
236  int runTypeIdx = t.AddCol("run_type", "text");
237  int compListIdx = t.AddCol("component_list", "text");
238  int startIdx = t.AddCol("start", "timestamp");
239  int stopIdx = t.AddCol("stop", "timestamp");
240 
241  t.SetValidityRange("run",run);
242 
243  // t.SetVerbosity(100);
244  t.SetTimeQueries(false);
245  t.SetTimeParsing(false);
246  t.Load();
247 
248  if (t.NRow() != 1)
249  abort();
250 
251  std::string runTypeStr, compList;
252  int runNum=0;
253 
254  nutools::dbi::Row* row = t.GetRow(0);
255  row->Col(runIdx).Get(runNum);
256  row->Col(cfgLabelIdx).Get(fCfgLabel);
257  row->Col(compListIdx).Get(compList);
258  row->Col(runTypeIdx).Get(runTypeStr);
259  row->Col(startIdx).Get(fTStartStr);
260  row->Col(stopIdx).Get(fTStopStr);
261 
262  if (runNum != int(run)) abort();
263 
264  boost::tokenizer< boost::escaped_list_separator<char> > tok(compList);
265  fComponents.assign(tok.begin(),tok.end());
266 
267  fTStart = fTStop = 0;
268  time_t tval;
270  fTStart = tval;
271  if (fTStopStr != "" && fTStopStr != "None") {
273  fTStop = tval;
274  }
275 
276  return true;
277 
278  }
279 
280  //------------------------------------------------
282  {
283  switch(fRunType) {
285  return std::string("Production");
287  return std::string("Commissioning");
288  case(detinfo::kTestRun):
289  return std::string("Test");
290  case(detinfo::kPedestalRun):
291  return std::string("Pedestal");
293  return std::string("Calibration");
295  default:
296  return std::string("Uknown");
297  }
298  }
299 }
Pedestal provider class for DUNE.
virtual bool Update(uint64_t ts=0) override
void SetTimeQueries(bool f)
Definition: Table.h:305
std::unordered_map< int, std::string > fSCInvChanMap
std::string string
Definition: nybbler.cc:12
void SetMaxTSVld(float t)
Definition: Table.h:272
std::unique_ptr< nutools::dbi::Table > fASICSettingsTable
uint64_t Channel()
Definition: Row.h:55
static const double g
Definition: Units.h:145
bool Get(T &val) const
Definition: Column.h:72
void SetTimeParsing(bool f)
Definition: Table.h:306
bool SetValidityRange(std::string cname, T start, T end)
Definition: Table.h:218
std::unordered_map< std::string, int > fSCChanMap
RunHistoryDUNE(int detid, int runnum)
std::unique_ptr< nutools::dbi::Table > fSCDataTable
bool SetDetector(std::string det)
Definition: Table.cpp:493
void SetTableName(std::string tname)
Definition: Table.cpp:517
unsigned __int64 uint64_t
Definition: stdint.h:136
static bool TimeAsStringToTime_t(std::string ts, time_t &t)
Definition: Util.cpp:81
int AddCol(std::string cname, std::string ctype)
Definition: Table.cpp:326
virtual std::string RunTypeAsString() const override
std::unordered_map< int, ASICSetting > fASICSettingsMap
nutools::dbi::Row *const GetRow(int i)
Definition: Table.cpp:406
static bool * b
Definition: config.cpp:1043
void SetMinTSVld(float t)
Definition: Table.h:271
std::vector< std::string > fComponents
void SetVerbosity(int i)
Definition: Table.h:100
bool SetTableType(int t)
Definition: Table.cpp:451
Column & Col(int i)
Definition: Row.h:53
static QCString * s
Definition: config.cpp:1042
QTextStream & endl(QTextStream &s)
void SetDataTypeMask(int mask)
Definition: Table.h:76
unsigned int run
std::string tableName