CMS 3D CMS Logo

TRGScalers2DB.cc
Go to the documentation of this file.
1 #ifndef RecoLuminosity_LumiProducer_TRGScalers2DB_h
2 #define RecoLuminosity_LumiProducer_TRGScalers2DB_h
3 #include "CoralBase/AttributeList.h"
4 #include "CoralBase/Attribute.h"
5 #include "CoralBase/AttributeSpecification.h"
6 #include "CoralBase/Blob.h"
7 #include "CoralBase/Exception.h"
8 #include "RelationalAccess/ConnectionService.h"
9 #include "RelationalAccess/ISessionProxy.h"
10 #include "RelationalAccess/ITransaction.h"
11 #include "RelationalAccess/ITypeConverter.h"
12 #include "RelationalAccess/IQuery.h"
13 #include "RelationalAccess/ICursor.h"
14 #include "RelationalAccess/ISchema.h"
15 #include "RelationalAccess/IView.h"
16 #include "RelationalAccess/ITable.h"
17 #include "RelationalAccess/ITableDataEditor.h"
18 #include "RelationalAccess/IBulkOperation.h"
26 #include <cstring>
27 #include <cstdlib>
28 #include <iostream>
29 #include <sstream>
30 #include <stdexcept>
31 #include <map>
32 namespace lumi {
33  class TRGScalers2DB : public DataPipe {
34  public:
35  const static unsigned int COMMITLSINTERVAL = 150; //commit interval in LS, totalrow=nsl*192
36  const static unsigned int COMMITLSTRGINTERVAL = 550; //commit interval in LS of schema2
37  explicit TRGScalers2DB(const std::string& dest);
38  unsigned long long retrieveData(unsigned int runnumber) override;
39  const std::string dataType() const override;
40  const std::string sourceType() const override;
41  ~TRGScalers2DB() override;
42 
43  //per run information
44  typedef std::vector<std::string> TriggerNameResult_Algo;
45  typedef std::vector<std::string> TriggerNameResult_Tech;
46  //per lumisection information
47  typedef unsigned long long DEADCOUNT;
48  typedef float DEADFRAC;
49  typedef std::vector<DEADCOUNT> TriggerDeadCountResult;
50  typedef std::vector<DEADFRAC> TriggerDeadFracResult;
51  typedef std::vector<unsigned int> BITCOUNT;
52  typedef std::vector<BITCOUNT> TriggerCountResult_Algo;
53  typedef std::vector<BITCOUNT> TriggerCountResult_Tech;
54  typedef std::map<unsigned int, std::vector<unsigned int> > PrescaleResult_Algo;
55  typedef std::map<unsigned int, std::vector<unsigned int> > PrescaleResult_Tech;
56 
57  std::string int2str(unsigned int t, unsigned int width);
58  unsigned int str2int(const std::string& s);
59  void writeTrgData(coral::ISessionProxy* session,
60  unsigned int runnumber,
61  const std::string& source,
62  TriggerDeadCountResult::iterator deadtimesBeg,
63  TriggerDeadCountResult::iterator deadtimesEnd,
65  TriggerNameResult_Algo& algonames,
66  TriggerNameResult_Tech& technames,
67  TriggerCountResult_Algo& algocounts,
68  TriggerCountResult_Tech& techcounts,
69  PrescaleResult_Algo& prescalealgo,
70  PrescaleResult_Tech& prescaletech,
71  unsigned int commitintv);
72  unsigned long long writeTrgDataToSchema2(coral::ISessionProxy* session,
73  unsigned int runnumber,
74  const std::string& source,
75  TriggerDeadCountResult::iterator deadtimesBeg,
76  TriggerDeadCountResult::iterator deadtimesEnd,
78  TriggerNameResult_Algo& algonames,
79  TriggerNameResult_Tech& technames,
80  TriggerCountResult_Algo& algocounts,
81  TriggerCountResult_Tech& techcounts,
82  PrescaleResult_Algo& prescalealgo,
83  PrescaleResult_Tech& prescaletech,
84  unsigned int commitintv);
85  }; //cl TRGScalers2DB
86  //
87  //implementation
88  //
89  //deadtime fraction query
90  //
91  //select fraction,lumi_section,count_bx from cms_gt_mon.v_scalers_tcs_deadtime where run_number=:runnum and scaler_name='DeadtimeBeamActive'
92  //
93  //select count_bx,lumi_section,scaler_index from cms_gt_mon.v_scalers_fdl_algo where run_number=:runnum order by scaler_index;
94  //
95  //
96  //select count_bx,lumi_section,scaler_index from cms_gt_mon.v_scalers_fdl_tech where run_number=:runnum order by scaler_index;
97  //
98  //select algo_index,alias from cms_gt.gt_run_algo_view where runnumber=:runnumber //order by algo_index;
99  //
100  //select techtrig_index,name from cms_gt.gt_run_tech_view where runnumber=:runnumber //order by techtrig_index;
101  //
102  //select distinct(prescale_index) from cms_gt_mon.lumi_sections where run_number=:runnumber;
103  //
104  //select lumi_section,prescale_index from cms_gt_mon.lumi_sections where run_number=:runnumber;
105  //
106  //select prescale_factor_algo_000,prescale_factor_algo_001..._127 from cms_gt.gt_run_presc_algo_view where runr=:runnumber and prescale_index=:prescale_index;
107  // {prescale_index:[pres]}
108  //
109  //select prescale_factor_tt_000,prescale_factor_tt_001..._63 from cms_gt.gt_run_presc_tech_view where runr=:runnumber and prescale_index=0;
110  //
112  unsigned long long TRGScalers2DB::retrieveData(unsigned int runnumber) {
113  std::string runnumberstr = int2str(runnumber, 6);
114  //query source GT database
115  coral::ConnectionService* svc = new coral::ConnectionService;
116  lumi::DBConfig dbconf(*svc);
117  if (!m_authpath.empty()) {
119  }
120  //std::cout<<"m_source "<<m_source<<std::endl;
121  coral::ISessionProxy* trgsession = svc->connect(m_source, coral::ReadOnly);
122  coral::ITypeConverter& tpc = trgsession->typeConverter();
123  tpc.setCppTypeForSqlType("unsigned int", "NUMBER(7)");
124  tpc.setCppTypeForSqlType("unsigned int", "NUMBER(10)");
125  tpc.setCppTypeForSqlType("unsigned long long", "NUMBER(20)");
126  std::string gtmonschema("CMS_GT_MON");
127  std::string algoviewname("V_SCALERS_FDL_ALGO");
128  std::string techviewname("V_SCALERS_FDL_TECH");
129  std::string deadviewname("V_SCALERS_TCS_DEADTIME");
130  std::string lstablename("LUMI_SECTIONS");
131 
132  std::string gtschema("CMS_GT");
133  std::string runtechviewname("GT_RUN_TECH_VIEW");
134  std::string runalgoviewname("GT_RUN_ALGO_VIEW");
135  std::string runprescalgoviewname("GT_RUN_PRESC_ALGO_VIEW");
136  std::string runpresctechviewname("GT_RUN_PRESC_TECH_VIEW");
137 
138  //data exchange format
141  lumi::TRGScalers2DB::BITCOUNT mybitcount_algo;
142  mybitcount_algo.reserve(lumi::N_TRGALGOBIT);
143  lumi::TRGScalers2DB::BITCOUNT mybitcount_tech;
144  mybitcount_tech.reserve(lumi::N_TRGTECHBIT);
146  algonames.reserve(lumi::N_TRGALGOBIT);
148  technames.reserve(lumi::N_TRGTECHBIT);
150  //algocount.reserve(400);
152  //techcount.reserve(400);
154  deadfracresult.reserve(500);
156  deadtimeresult.reserve(500);
157  coral::ITransaction& transaction = trgsession->transaction();
158  transaction.start(true);
163  coral::ISchema& gtmonschemaHandle = trgsession->schema(gtmonschema);
164  if (!gtmonschemaHandle.existsView(algoviewname)) {
165  throw lumi::Exception(std::string("non-existing view ") + algoviewname, "retrieveData", "TRGScalers2DB");
166  }
167  if (!gtmonschemaHandle.existsView(techviewname)) {
168  throw lumi::Exception(std::string("non-existing view ") + techviewname, "retrieveData", "TRGScalers2DB");
169  }
170  if (!gtmonschemaHandle.existsView(deadviewname)) {
171  throw lumi::Exception(std::string("non-existing view ") + deadviewname, "retrieveData", "TRGScalers2DB");
172  }
173 
174  //
175  //select count_bx,lumi_section,scaler_index from cms_gt_mon.v_scalers_fdl_algo where run_number=:runnum order by lumi_section,scaler_index;
176  //note: scaler_index 0-127
177  //note: lumi_section count from 1
178  //
179  coral::AttributeList bindVariableList;
180  bindVariableList.extend("runnumber", typeid(unsigned int));
181  bindVariableList["runnumber"].data<unsigned int>() = runnumber;
182 
183  coral::IQuery* Queryalgoview = gtmonschemaHandle.newQuery();
184  Queryalgoview->addToTableList(algoviewname);
185  coral::AttributeList qalgoOutput;
186  qalgoOutput.extend("COUNT_BX", typeid(unsigned int));
187  qalgoOutput.extend("LUMI_SECTION", typeid(unsigned int));
188  qalgoOutput.extend("SCALER_INDEX", typeid(unsigned int));
189  Queryalgoview->addToOutputList("COUNT_BX");
190  Queryalgoview->addToOutputList("LUMI_SECTION");
191  Queryalgoview->addToOutputList("SCALER_INDEX");
192  Queryalgoview->setCondition("RUN_NUMBER=:runnumber", bindVariableList);
193  Queryalgoview->addToOrderList("LUMI_SECTION");
194  Queryalgoview->addToOrderList("SCALER_INDEX");
195  Queryalgoview->defineOutput(qalgoOutput);
196  coral::ICursor& c = Queryalgoview->execute();
197 
198  unsigned int s = 0;
199  while (c.next()) {
200  const coral::AttributeList& row = c.currentRow();
201  //row.toOutputStream( std::cout ) << std::endl;
202  unsigned int lsnr = row["LUMI_SECTION"].data<unsigned int>();
203  unsigned int count = row["COUNT_BX"].data<unsigned int>();
204  unsigned int algobit = row["SCALER_INDEX"].data<unsigned int>();
205  mybitcount_algo.push_back(count);
206  if (algobit == (lumi::N_TRGALGOBIT - 1)) {
207  ++s;
208  while (s != lsnr) {
209  std::cout << "ALGO COUNT alert: found hole in LS range " << s << std::endl;
210  std::cout << " fill all algocount 0 for LS " << s << std::endl;
211  std::vector<unsigned int> tmpzero(lumi::N_TRGALGOBIT, 0);
212  algocount.push_back(tmpzero);
213  ++s;
214  }
215  algocount.push_back(mybitcount_algo);
216  mybitcount_algo.clear();
217  }
218  }
219  if (s == 0) {
220  c.close();
221  delete Queryalgoview;
222  transaction.commit();
223  throw lumi::Exception(std::string("requested run ") + runnumberstr + std::string(" doesn't exist for algocounts"),
224  "retrieveData",
225  "TRGScalers2DB");
226  }
227  delete Queryalgoview;
228  //
229  //select count_bx,lumi_section,scaler_index from cms_gt_mon.v_scalers_fdl_tech where run_number=:runnum order by lumi_section,scaler_index;
230  //
231  //note: techobit 0-63
232  //note: lsnr count from 1
233  //
234  coral::IQuery* Querytechview = gtmonschemaHandle.newQuery();
235  Querytechview->addToTableList(techviewname);
236  coral::AttributeList qtechOutput;
237  qtechOutput.extend("COUNT_BX", typeid(unsigned int));
238  qtechOutput.extend("LUMI_SECTION", typeid(unsigned int));
239  qtechOutput.extend("SCALER_INDEX", typeid(unsigned int));
240  Querytechview->addToOutputList("COUNT_BX");
241  Querytechview->addToOutputList("LUMI_SECTION");
242  Querytechview->addToOutputList("SCALER_INDEX");
243  Querytechview->setCondition("RUN_NUMBER=:runnumber", bindVariableList);
244  Querytechview->addToOrderList("LUMI_SECTION");
245  Querytechview->addToOrderList("SCALER_INDEX");
246  Querytechview->defineOutput(qtechOutput);
247  coral::ICursor& techcursor = Querytechview->execute();
248  s = 0;
249  while (techcursor.next()) {
250  const coral::AttributeList& row = techcursor.currentRow();
251  //row.toOutputStream( std::cout #include <stdexcept>) << std::endl;
252  unsigned int lsnr = row["LUMI_SECTION"].data<unsigned int>();
253  unsigned int count = row["COUNT_BX"].data<unsigned int>();
254  unsigned int techbit = row["SCALER_INDEX"].data<unsigned int>();
255  mybitcount_tech.push_back(count);
256  if (techbit == (lumi::N_TRGTECHBIT - 1)) {
257  ++s;
258  while (s != lsnr) {
259  std::cout << "TECH COUNT alert: found hole in LS range " << s << std::endl;
260  std::cout << " fill all techcount with 0 for LS " << s << std::endl;
261  std::vector<unsigned int> tmpzero(lumi::N_TRGTECHBIT, 0);
262  techcount.push_back(tmpzero);
263  ++s;
264  }
265  techcount.push_back(mybitcount_tech);
266  mybitcount_tech.clear();
267  }
268  }
269  if (s == 0) {
270  techcursor.close();
271  delete Querytechview;
272  transaction.commit();
273  throw lumi::Exception(std::string("requested run ") + runnumberstr + std::string(" doesn't exist for techcounts"),
274  "retrieveData",
275  "TRGScalers2DB");
276  }
277  delete Querytechview;
278 
279  //
280  //select fraction,lumi_section,count_bx from cms_gt_mon.v_scalers_tcs_deadtime where run_number=:runnum and scaler_name='DeadtimeBeamActive' order by lumi_section'
281  //
282  //note: lsnr count from 1
283  //
284  coral::IQuery* Querydeadview = gtmonschemaHandle.newQuery();
285  Querydeadview->addToTableList(deadviewname);
286  coral::AttributeList qdeadOutput;
287  qdeadOutput.extend("FRACTION", typeid(float));
288  qdeadOutput.extend("LUMI_SECTION", typeid(unsigned int));
289  qdeadOutput.extend("COUNT_BX", typeid(unsigned int));
290  Querydeadview->addToOutputList("FRACTION");
291  Querydeadview->addToOutputList("LUMI_SECTION");
292  Querydeadview->addToOutputList("COUNT_BX");
293  coral::AttributeList bindVariablesDead;
294  bindVariablesDead.extend("runnumber", typeid(int));
295  bindVariablesDead.extend("scalername", typeid(std::string));
296  bindVariablesDead["runnumber"].data<int>() = runnumber;
297  bindVariablesDead["scalername"].data<std::string>() = std::string("DeadtimeBeamActive");
298  Querydeadview->setCondition("RUN_NUMBER=:runnumber AND SCALER_NAME=:scalername", bindVariablesDead);
299  Querydeadview->addToOrderList("LUMI_SECTION");
300  Querydeadview->defineOutput(qdeadOutput);
301  coral::ICursor& deadcursor = Querydeadview->execute();
302  s = 0;
303  while (deadcursor.next()) {
304  const coral::AttributeList& row = deadcursor.currentRow();
305  //row.toOutputStream( std::cout ) << std::endl;
306  ++s;
307  unsigned int lsnr = row["LUMI_SECTION"].data<unsigned int>();
308  float dfrac = 1.0;
309  unsigned int count = 0;
310  while (s != lsnr) {
311  std::cout << "DEADTIME alert: found hole in LS range" << s << std::endl;
312  std::cout << " fill deadtimefraction 0%, deadtimebeamactive 0 for LS " << s << std::endl;
313  deadfracresult.push_back(dfrac);
314  deadtimeresult.push_back(count);
315  ++s;
316  }
317  if (!row["FRACTION"].isNull()) {
318  dfrac = row["FRACTION"].data<float>(); //deadfraction is null from trigger means "undefined", but insert 1.0...
319  } else {
320  std::cout << "DEADTIME fraction alert: undefined fraction , assume 100% , LS " << lsnr << std::endl;
321  }
322  if (dfrac > 1.0) {
323  std::cout << "DEADTIME fraction alert: overflow dead fraction , force to 100% , LS " << lsnr << std::endl;
324  dfrac = 1.0;
325  }
326  deadfracresult.push_back(dfrac);
327  count = row["COUNT_BX"].data<unsigned int>();
328  deadtimeresult.push_back(count);
329  }
330  if (s == 0) {
331  deadcursor.close();
332  delete Querydeadview;
333  transaction.commit();
334  throw lumi::Exception(std::string("requested run ") + runnumberstr + std::string(" doesn't exist for deadcounts"),
335  "retrieveData",
336  "TRGScalers2DB");
337  return 0;
338  }
339  delete Querydeadview;
340 
341  //
342  //select distinct(prescale_index) from cms_gt_mon.lumi_sections where run_number=:runnumber;
343  //
344  std::vector<int> prescidx;
345  coral::IQuery* allpsidxQuery = gtmonschemaHandle.newQuery();
346  allpsidxQuery->addToTableList(lstablename);
347  coral::AttributeList allpsidxOutput;
348  allpsidxOutput.extend("psidx", typeid(int));
349  allpsidxQuery->addToOutputList("distinct(PRESCALE_INDEX)", "psidx");
350  coral::AttributeList bindVariablesAllpsidx;
351  bindVariablesAllpsidx.extend("runnumber", typeid(int));
352  bindVariablesAllpsidx["runnumber"].data<int>() = runnumber;
353  allpsidxQuery->setCondition("RUN_NUMBER =:runnumber", bindVariablesAllpsidx);
354  allpsidxQuery->defineOutput(allpsidxOutput);
355  coral::ICursor& allpsidxCursor = allpsidxQuery->execute();
356  while (allpsidxCursor.next()) {
357  const coral::AttributeList& row = allpsidxCursor.currentRow();
358  int psidx = row["psidx"].data<int>();
359  prescidx.push_back(psidx);
360  }
361  delete allpsidxQuery;
362  std::map<int, std::vector<unsigned int> > algoprescMap;
363  std::map<int, std::vector<unsigned int> > techprescMap;
364  std::vector<int>::iterator prescidxIt;
365  std::vector<int>::iterator prescidxItBeg = prescidx.begin();
366  std::vector<int>::iterator prescidxItEnd = prescidx.end();
367  for (prescidxIt = prescidxItBeg; prescidxIt != prescidxItEnd; ++prescidxIt) {
368  std::vector<unsigned int> algopres;
369  algopres.reserve(lumi::N_TRGALGOBIT);
370  std::vector<unsigned int> techpres;
371  techpres.reserve(lumi::N_TRGTECHBIT);
372  algoprescMap.insert(std::make_pair(*prescidxIt, algopres));
373  techprescMap.insert(std::make_pair(*prescidxIt, techpres));
374  }
375  //
376  //select lumi_section,prescale_index from cms_gt_mon.lumi_sections where run_number=:runnumber
377  // {ls:prescale_index}
378  //
379  std::map<unsigned int, int> lsprescmap;
380  coral::IQuery* lstoprescQuery = gtmonschemaHandle.newQuery();
381  lstoprescQuery->addToTableList(lstablename);
382  coral::AttributeList lstoprescOutput;
383  lstoprescOutput.extend("lumisection", typeid(unsigned int));
384  lstoprescOutput.extend("psidx", typeid(int));
385  lstoprescQuery->addToOutputList("LUMI_SECTION", "lumisection");
386  lstoprescQuery->addToOutputList("PRESCALE_INDEX", "psidx");
387  coral::AttributeList bindVariablesLstopresc;
388  bindVariablesLstopresc.extend("runnumber", typeid(int));
389  bindVariablesLstopresc["runnumber"].data<int>() = runnumber;
390  lstoprescQuery->setCondition("RUN_NUMBER =:runnumber", bindVariablesLstopresc);
391  lstoprescQuery->defineOutput(lstoprescOutput);
392  unsigned int lsprescount = 0;
393  unsigned int lastpresc = 0;
394  coral::ICursor& lstoprescCursor = lstoprescQuery->execute();
395  while (lstoprescCursor.next()) {
396  ++lsprescount;
397  const coral::AttributeList& row = lstoprescCursor.currentRow();
398  unsigned int lumisection = row["lumisection"].data<unsigned int>();
399  while (lsprescount != lumisection) {
400  std::cout << "PRESCALE_INDEX COUNT alert: found hole in LS range " << lsprescount << std::endl;
401  std::cout << " fill this prescale from last availabl prescale " << lastpresc << std::endl;
402  unsigned int guesspsidx = lastpresc;
403  lsprescmap.insert(std::make_pair(lsprescount, guesspsidx));
404  ++lsprescount;
405  }
406  int psidx = row["psidx"].data<int>();
407  lsprescmap.insert(std::make_pair(lumisection, psidx));
408  lastpresc = psidx;
409  }
410  if (lsprescount == 0) {
411  lstoprescCursor.close();
412  delete lstoprescQuery;
413  transaction.commit();
414  throw lumi::Exception(
415  std::string("requested run ") + runnumberstr + std::string(" doesn't exist for prescale_index"),
416  "retrieveData",
417  "TRG2DB");
418  }
419  delete lstoprescQuery;
420 
421  for (prescidxIt = prescidxItBeg; prescidxIt != prescidxItEnd; ++prescidxIt) {
422  std::vector<unsigned int> algopres;
423  algopres.reserve(lumi::N_TRGALGOBIT);
424  std::vector<unsigned int> techpres;
425  techpres.reserve(lumi::N_TRGTECHBIT);
426  algoprescMap.insert(std::make_pair(*prescidxIt, algopres));
427  techprescMap.insert(std::make_pair(*prescidxIt, techpres));
428  }
429  //prefill lsprescmap
430  //transaction.commit();
435  coral::ISchema& gtschemaHandle = trgsession->schema(gtschema);
436  if (!gtschemaHandle.existsView(runtechviewname)) {
437  throw lumi::Exception(std::string("non-existing view ") + runtechviewname, "str2int", "TRG2DB");
438  }
439  if (!gtschemaHandle.existsView(runalgoviewname)) {
440  throw lumi::Exception(std::string("non-existing view ") + runalgoviewname, "str2int", "TRG2DB");
441  }
442  if (!gtschemaHandle.existsView(runprescalgoviewname)) {
443  throw lumi::Exception(std::string("non-existing view ") + runprescalgoviewname, "str2int", "TRG2DB");
444  }
445  if (!gtschemaHandle.existsView(runpresctechviewname)) {
446  throw lumi::Exception(std::string("non-existing view ") + runpresctechviewname, "str2int", "TRG2DB");
447  }
448  //
449  //select algo_index,alias from cms_gt.gt_run_algo_view where runnumber=:runnumber //order by algo_index;
450  //
451  std::map<unsigned int, std::string> triggernamemap;
452  coral::IQuery* QueryName = gtschemaHandle.newQuery();
453  QueryName->addToTableList(runalgoviewname);
454  coral::AttributeList qAlgoNameOutput;
455  qAlgoNameOutput.extend("ALGO_INDEX", typeid(unsigned int));
456  qAlgoNameOutput.extend("ALIAS", typeid(std::string));
457  QueryName->addToOutputList("ALGO_INDEX");
458  QueryName->addToOutputList("ALIAS");
459  QueryName->setCondition("RUNNUMBER=:runnumber", bindVariableList);
460  //QueryName->addToOrderList("algo_index");
461  QueryName->defineOutput(qAlgoNameOutput);
462  coral::ICursor& algonamecursor = QueryName->execute();
463  while (algonamecursor.next()) {
464  const coral::AttributeList& row = algonamecursor.currentRow();
465  //row.toOutputStream( std::cout ) << std::endl;
466  unsigned int algo_index = row["ALGO_INDEX"].data<unsigned int>();
467  std::string algo_name = row["ALIAS"].data<std::string>();
468  triggernamemap.insert(std::make_pair(algo_index, algo_name));
469  }
470  delete QueryName;
471 
472  //
473  //select techtrig_index,name from cms_gt.gt_run_tech_view where runnumber=:runnumber //order by techtrig_index;
474  //
475  std::map<unsigned int, std::string> techtriggernamemap;
476  coral::IQuery* QueryTechName = gtschemaHandle.newQuery();
477  QueryTechName->addToTableList(runtechviewname);
478  coral::AttributeList qTechNameOutput;
479  qTechNameOutput.extend("TECHTRIG_INDEX", typeid(unsigned int));
480  qTechNameOutput.extend("NAME", typeid(std::string));
481  QueryTechName->addToOutputList("TECHTRIG_INDEX");
482  QueryTechName->addToOutputList("NAME");
483  QueryTechName->setCondition("RUNNUMBER=:runnumber", bindVariableList);
484  //QueryTechName->addToOrderList("techtrig_index");
485  QueryTechName->defineOutput(qTechNameOutput);
486  coral::ICursor& technamecursor = QueryTechName->execute();
487  while (technamecursor.next()) {
488  const coral::AttributeList& row = technamecursor.currentRow();
489  //row.toOutputStream( std::cout ) << std::endl;
490  unsigned int tech_index = row["TECHTRIG_INDEX"].data<unsigned int>();
491  std::string tech_name = row["NAME"].data<std::string>();
492  techtriggernamemap.insert(std::make_pair(tech_index, tech_name));
493  }
494  delete QueryTechName;
495  //
496  //loop over all prescale_index
497  //
498  //select prescale_factor_algo_000,prescale_factor_algo_001..._127 from cms_gt.gt_run_presc_algo_view where runr=:runnumber and prescale_index=:prescale_index;
499  // {prescale_index:[pres]}
500  //
501  std::vector<int>::iterator presIt;
502  std::vector<int>::iterator presItBeg = prescidx.begin();
503  std::vector<int>::iterator presItEnd = prescidx.end();
504  for (presIt = presItBeg; presIt != presItEnd; ++presIt) {
505  coral::IQuery* QueryAlgoPresc = gtschemaHandle.newQuery();
506  QueryAlgoPresc->addToTableList(runprescalgoviewname);
507  coral::AttributeList qAlgoPrescOutput;
508  std::string algoprescBase("PRESCALE_FACTOR_ALGO_");
509  for (unsigned int bitidx = 0; bitidx < lumi::N_TRGALGOBIT; ++bitidx) {
510  std::string algopresc = algoprescBase + int2str(bitidx, 3);
511  qAlgoPrescOutput.extend(algopresc, typeid(unsigned int));
512  }
513  for (unsigned int bitidx = 0; bitidx < lumi::N_TRGALGOBIT; ++bitidx) {
514  std::string algopresc = algoprescBase + int2str(bitidx, 3);
515  QueryAlgoPresc->addToOutputList(algopresc);
516  }
517  coral::AttributeList PrescbindVariable;
518  PrescbindVariable.extend("runnumber", typeid(int));
519  PrescbindVariable.extend("prescaleindex", typeid(int));
520  PrescbindVariable["runnumber"].data<int>() = runnumber;
521  PrescbindVariable["prescaleindex"].data<int>() = *presIt;
522  QueryAlgoPresc->setCondition("RUNNR=:runnumber AND PRESCALE_INDEX=:prescaleindex", PrescbindVariable);
523  QueryAlgoPresc->defineOutput(qAlgoPrescOutput);
524  coral::ICursor& algopresccursor = QueryAlgoPresc->execute();
525  while (algopresccursor.next()) {
526  const coral::AttributeList& row = algopresccursor.currentRow();
527  for (unsigned int bitidx = 0; bitidx < lumi::N_TRGALGOBIT; ++bitidx) {
528  std::string algopresc = algoprescBase + int2str(bitidx, 3);
529  algoprescMap[*presIt].push_back(row[algopresc].data<unsigned int>());
530  }
531  }
532  delete QueryAlgoPresc;
533  }
534  //
535  //select prescale_factor_tt_000,prescale_factor_tt_001..._63 from cms_gt.gt_run_presc_tech_view where runr=:runnumber and prescale_index=0;
536  //
537  for (presIt = presItBeg; presIt != presItEnd; ++presIt) {
538  coral::IQuery* QueryTechPresc = gtschemaHandle.newQuery();
539  QueryTechPresc->addToTableList(runpresctechviewname);
540  coral::AttributeList qTechPrescOutput;
541  std::string techprescBase("PRESCALE_FACTOR_TT_");
542  for (unsigned int bitidx = 0; bitidx < lumi::N_TRGTECHBIT; ++bitidx) {
543  std::string techpresc = techprescBase + this->int2str(bitidx, 3);
544  qTechPrescOutput.extend(techpresc, typeid(unsigned int));
545  }
546  for (unsigned int bitidx = 0; bitidx < lumi::N_TRGTECHBIT; ++bitidx) {
547  std::string techpresc = techprescBase + int2str(bitidx, 3);
548  QueryTechPresc->addToOutputList(techpresc);
549  }
550  coral::AttributeList TechPrescbindVariable;
551  TechPrescbindVariable.extend("runnumber", typeid(int));
552  TechPrescbindVariable.extend("prescaleindex", typeid(int));
553  TechPrescbindVariable["runnumber"].data<int>() = runnumber;
554  TechPrescbindVariable["prescaleindex"].data<int>() = *presIt;
555  QueryTechPresc->setCondition("RUNNR=:runnumber AND PRESCALE_INDEX=:prescaleindex", TechPrescbindVariable);
556  QueryTechPresc->defineOutput(qTechPrescOutput);
557  coral::ICursor& techpresccursor = QueryTechPresc->execute();
558  while (techpresccursor.next()) {
559  const coral::AttributeList& row = techpresccursor.currentRow();
560  //row.toOutputStream( std::cout ) << std::endl;
561  for (unsigned int bitidx = 0; bitidx < lumi::N_TRGTECHBIT; ++bitidx) {
562  std::string techpresc = techprescBase + int2str(bitidx, 3);
563  techprescMap[*presIt].push_back(row[techpresc].data<unsigned int>());
564  }
565  }
566  delete QueryTechPresc;
567  }
568  transaction.commit();
569  delete trgsession;
570 
571  std::map<unsigned int, int>::iterator lsprescmapIt;
572  std::map<unsigned int, int>::iterator lsprescmapItBeg = lsprescmap.begin();
573  std::map<unsigned int, int>::iterator lsprescmapItEnd = lsprescmap.end();
574  for (lsprescmapIt = lsprescmapItBeg; lsprescmapIt != lsprescmapItEnd; ++lsprescmapIt) {
575  unsigned int ls = lsprescmapIt->first;
576  int preidx = lsprescmapIt->second;
577  algoprescale.insert(std::make_pair(ls, algoprescMap[preidx]));
578  techprescale.insert(std::make_pair(ls, techprescMap[preidx]));
579  }
580  algoprescMap.clear();
581  techprescMap.clear();
582  //
583  //reprocess Algo name result filling unallocated trigger bit with string "False"
584  //
585  for (size_t algoidx = 0; algoidx < lumi::N_TRGALGOBIT; ++algoidx) {
586  std::map<unsigned int, std::string>::iterator pos = triggernamemap.find(algoidx);
587  if (pos != triggernamemap.end()) {
588  algonames.push_back(pos->second);
589  } else {
590  algonames.push_back("False");
591  }
592  }
593  //
594  //reprocess Tech name result filling unallocated trigger bit with string "False"
595  //
596  std::stringstream ss;
597  for (size_t techidx = 0; techidx < lumi::N_TRGTECHBIT; ++techidx) {
598  ss << techidx;
599  technames.push_back(ss.str());
600  ss.str(""); //clear the string buffer after usage
601  }
602  //
603  //cross check result size
604  //
605  if (algonames.size() != lumi::N_TRGALGOBIT || technames.size() != lumi::N_TRGTECHBIT) {
606  throw lumi::Exception("wrong number of bits", "retrieveData", "TRG2DB");
607  }
608  //if(algoprescale.size()!=lumi::N_TRGALGOBIT || techprescale.size()!=lumi::N_TRGTECHBIT){
609  // throw lumi::Exception("wrong number of prescale","retrieveData","TRG2DB");
610  //}
611  if (deadtimeresult.size() != deadfracresult.size() || deadtimeresult.size() != algocount.size() ||
612  deadtimeresult.size() != techcount.size() || deadtimeresult.size() != algoprescale.size() ||
613  deadtimeresult.size() != techprescale.size()) {
614  //throw lumi::Exception("inconsistent number of LS","retrieveData","TRG2DB");
615  std::cout
616  << "[WARNING] inconsistent number of LS of deadtimecounter,deadfrac,algo,tech,prescalealgo,prescaletech "
617  << deadtimeresult.size() << " " << deadfracresult.size() << " " << algocount.size() << " " << techcount.size()
618  << " " << algoprescale.size() << " " << techprescale.size() << std::endl;
619  TRGScalers2DB::TriggerDeadCountResult::iterator dIt;
620  TRGScalers2DB::TriggerDeadCountResult::iterator dBeg = deadtimeresult.begin();
621  TRGScalers2DB::TriggerDeadCountResult::iterator dEnd = deadtimeresult.end();
622  unsigned int dcnt = 0;
623  for (dIt = dBeg; dIt != dEnd; ++dIt) {
624  try {
625  deadfracresult.at(dcnt);
626  } catch (std::out_of_range& er) {
627  std::cout << "[WARNING] filling FAKE deadfrac=0.0 at LS " << dcnt << std::endl;
628  deadfracresult[dcnt] = 0.0;
629  }
630  try {
631  algocount.at(dcnt);
632  } catch (std::out_of_range& er) {
633  std::vector<unsigned int> tmpzero(lumi::N_TRGALGOBIT, 0);
634  std::cout << "[WARNING] filling FAKE algocount at LS " << dcnt << std::endl;
635  algocount[dcnt] = tmpzero;
636  }
637  try {
638  techcount.at(dcnt);
639  } catch (std::out_of_range& er) {
640  std::vector<unsigned int> tmpzero(lumi::N_TRGTECHBIT, 0);
641  std::cout << "[WARNING] filling FAKE techcount at LS " << dcnt << std::endl;
642  techcount[dcnt] = tmpzero;
643  }
644  if (algoprescale.find(dcnt + 1) == algoprescale.end()) {
645  std::vector<unsigned int> tmpzero(lumi::N_TRGALGOBIT, 1);
646  std::cout << "[WARNING] filling FAKE 1 algoprescale at LS " << dcnt + 1 << std::endl;
647  algoprescale[dcnt + 1] = tmpzero;
648  }
649  if (techprescale.find(dcnt + 1) == techprescale.end()) {
650  std::vector<unsigned int> tmpzero(lumi::N_TRGTECHBIT, 1);
651  std::cout << "[WARNING] filling FAKE 1 techprescale at LS " << dcnt + 1 << std::endl;
652  techprescale[dcnt + 1] = tmpzero;
653  }
654  ++dcnt;
655  }
656  }
657  //
658  //write data into lumi db
659  //
660  unsigned long long trgdataid = 0;
661  coral::ISessionProxy* lumisession = svc->connect(m_dest, coral::Update);
662  coral::ITypeConverter& lumitpc = lumisession->typeConverter();
663  lumitpc.setCppTypeForSqlType("unsigned int", "NUMBER(7)");
664  lumitpc.setCppTypeForSqlType("unsigned int", "NUMBER(10)");
665  lumitpc.setCppTypeForSqlType("unsigned long long", "NUMBER(20)");
666  try {
667  if (m_mode == "loadoldschema") {
668  std::cout << "writing trg data to old trg table " << std::endl;
669  writeTrgData(lumisession,
670  runnumber,
671  m_source,
672  deadtimeresult.begin(),
673  deadtimeresult.end(),
674  deadfracresult,
675  algonames,
676  technames,
677  algocount,
678  techcount,
679  algoprescale,
680  techprescale,
682  std::cout << "done" << std::endl;
683  }
684  std::cout << "writing trg data to new lstrg table " << std::endl;
685  trgdataid = writeTrgDataToSchema2(lumisession,
686  runnumber,
687  m_source,
688  deadtimeresult.begin(),
689  deadtimeresult.end(),
690  deadfracresult,
691  algonames,
692  technames,
693  algocount,
694  techcount,
695  algoprescale,
696  techprescale,
698  std::cout << "done" << std::endl;
699  delete lumisession;
700  delete svc;
701  } catch (const coral::Exception& er) {
702  std::cout << "database error " << er.what() << std::endl;
703  lumisession->transaction().rollback();
704  delete lumisession;
705  delete svc;
706  throw er;
707  }
708  return trgdataid;
709  }
710  void TRGScalers2DB::writeTrgData(coral::ISessionProxy* lumisession,
711  unsigned int runnumber,
712  const std::string& source,
713  TRGScalers2DB::TriggerDeadCountResult::iterator deadtimesBeg,
714  TRGScalers2DB::TriggerDeadCountResult::iterator deadtimesEnd,
722  unsigned int commitintv) {
723  TRGScalers2DB::TriggerDeadCountResult::iterator deadIt;
724  //unsigned int totalcmsls=deadtimes.size();
725  unsigned int totalcmsls = std::distance(deadtimesBeg, deadtimesEnd);
726  std::cout << "inserting totalcmsls " << totalcmsls << std::endl;
727  std::map<unsigned long long, std::vector<unsigned long long> > idallocationtable;
728  std::cout << "\t allocating total ids " << totalcmsls * lumi::N_TRGBIT << std::endl;
729  lumisession->transaction().start(false);
730  lumi::idDealer idg(lumisession->nominalSchema());
731  unsigned long long trgID = idg.generateNextIDForTable(LumiNames::trgTableName(), totalcmsls * lumi::N_TRGBIT) -
732  totalcmsls * lumi::N_TRGBIT;
733  //lumisession->transaction().commit();
734  unsigned int trglscount = 0;
735  for (deadIt = deadtimesBeg; deadIt != deadtimesEnd; ++deadIt, ++trglscount) {
736  std::vector<unsigned long long> bitvec;
737  bitvec.reserve(lumi::N_TRGBIT);
738  const BITCOUNT& algoinbits = algocounts[trglscount];
739  const BITCOUNT& techinbits = techcounts[trglscount];
740  BITCOUNT::const_iterator algoBitIt;
741  BITCOUNT::const_iterator algoBitBeg = algoinbits.begin();
742  BITCOUNT::const_iterator algoBitEnd = algoinbits.end();
743  for (algoBitIt = algoBitBeg; algoBitIt != algoBitEnd; ++algoBitIt, ++trgID) {
744  bitvec.push_back(trgID);
745  }
746  BITCOUNT::const_iterator techBitIt;
747  BITCOUNT::const_iterator techBitBeg = techinbits.begin();
748  BITCOUNT::const_iterator techBitEnd = techinbits.end();
749  for (techBitIt = techBitBeg; techBitIt != techBitEnd; ++techBitIt, ++trgID) {
750  bitvec.push_back(trgID);
751  }
752  idallocationtable.insert(std::make_pair(trglscount, bitvec));
753  }
754  std::cout << "\t all ids allocated" << std::endl;
755  coral::AttributeList trgData;
756  trgData.extend<unsigned long long>("TRG_ID");
757  trgData.extend<unsigned int>("RUNNUM");
758  trgData.extend<unsigned int>("CMSLSNUM");
759  trgData.extend<unsigned int>("BITNUM");
760  trgData.extend<std::string>("BITNAME");
761  trgData.extend<unsigned int>("TRGCOUNT");
762  trgData.extend<unsigned long long>("DEADTIME");
763  trgData.extend<float>("DEADFRAC");
764  trgData.extend<unsigned int>("PRESCALE");
765 
766  unsigned long long& trg_id = trgData["TRG_ID"].data<unsigned long long>();
767  unsigned int& trgrunnum = trgData["RUNNUM"].data<unsigned int>();
768  unsigned int& cmslsnum = trgData["CMSLSNUM"].data<unsigned int>();
769  unsigned int& bitnum = trgData["BITNUM"].data<unsigned int>();
770  std::string& bitname = trgData["BITNAME"].data<std::string>();
771  unsigned int& count = trgData["TRGCOUNT"].data<unsigned int>();
772  unsigned long long& deadtime = trgData["DEADTIME"].data<unsigned long long>();
773  float& deadfrac = trgData["DEADFRAC"].data<float>();
774  unsigned int& prescale = trgData["PRESCALE"].data<unsigned int>();
775 
776  trglscount = 0;
777  coral::IBulkOperation* trgInserter = nullptr;
778  unsigned int comittedls = 0;
779  for (deadIt = deadtimesBeg; deadIt != deadtimesEnd; ++deadIt, ++trglscount) {
780  unsigned int cmslscount = trglscount + 1;
781  float dfra = deadfracs[trglscount];
782  const BITCOUNT& algoinbits = algocounts[trglscount];
783  const BITCOUNT& techinbits = techcounts[trglscount];
784  unsigned int trgbitcount = 0;
785  BITCOUNT::const_iterator algoBitIt;
786  BITCOUNT::const_iterator algoBitBeg = algoinbits.begin();
787  BITCOUNT::const_iterator algoBitEnd = algoinbits.end();
788  if (!lumisession->transaction().isActive()) {
789  lumisession->transaction().start(false);
790  coral::ITable& trgtable = lumisession->nominalSchema().tableHandle(LumiNames::trgTableName());
791  trgInserter = trgtable.dataEditor().bulkInsert(trgData, 2048);
792  } else {
793  if (deadIt == deadtimesBeg) {
794  coral::ITable& trgtable = lumisession->nominalSchema().tableHandle(LumiNames::trgTableName());
795  trgInserter = trgtable.dataEditor().bulkInsert(trgData, 2048);
796  }
797  }
798  for (algoBitIt = algoBitBeg; algoBitIt != algoBitEnd; ++algoBitIt, ++trgbitcount) {
799  trg_id = idallocationtable[trglscount].at(trgbitcount);
800  deadtime = *deadIt;
801  deadfrac = dfra;
802  trgrunnum = runnumber;
803  cmslsnum = cmslscount;
804  bitnum = trgbitcount;
805  bitname = algonames[trgbitcount];
806  count = *algoBitIt;
807  prescale = prescalealgo[cmslscount].at(trgbitcount);
808  //std::cout<<"cmslsnum "<<cmslsnum<<" bitnum "<<bitnum<<" bitname "<<bitname<<" prescale "<< prescale<<" count "<<count<<std::endl;
809  trgInserter->processNextIteration();
810  }
811  BITCOUNT::const_iterator techBitIt;
812  BITCOUNT::const_iterator techBitBeg = techinbits.begin();
813  BITCOUNT::const_iterator techBitEnd = techinbits.end();
814  for (techBitIt = techBitBeg; techBitIt != techBitEnd; ++techBitIt, ++trgbitcount) {
815  trg_id = idallocationtable[trglscount].at(trgbitcount);
816  deadtime = *deadIt;
817  deadfrac = dfra;
818  trgrunnum = runnumber;
819  cmslsnum = cmslscount;
820  bitnum = trgbitcount;
821  bitname = technames[trgbitcount - lumi::N_TRGALGOBIT];
822  count = *techBitIt;
823  prescale = prescaletech[cmslsnum][trgbitcount - lumi::N_TRGALGOBIT];
824  trgInserter->processNextIteration();
825  }
826  trgInserter->flush();
827  ++comittedls;
828  if (comittedls == commitintv) {
829  std::cout << "\t committing in LS chunck " << comittedls << std::endl;
830  delete trgInserter;
831  trgInserter = nullptr;
832  lumisession->transaction().commit();
833  comittedls = 0;
834  std::cout << "\t committed " << std::endl;
835  } else if (trglscount == (totalcmsls - 1)) {
836  std::cout << "\t committing at the end" << std::endl;
837  delete trgInserter;
838  trgInserter = nullptr;
839  lumisession->transaction().commit();
840  std::cout << "\t done" << std::endl;
841  }
842  }
843  }
844  unsigned long long TRGScalers2DB::writeTrgDataToSchema2(coral::ISessionProxy* lumisession,
845  unsigned int irunnumber,
846  const std::string& source,
847  TriggerDeadCountResult::iterator deadtimesBeg,
848  TriggerDeadCountResult::iterator deadtimesEnd,
856  unsigned int commitintv) {
857  TRGScalers2DB::TriggerDeadCountResult::iterator deadIt;
858  unsigned int totalcmsls = std::distance(deadtimesBeg, deadtimesEnd);
859  std::cout << "inserting totalcmsls " << totalcmsls << std::endl;
860  coral::AttributeList lstrgData;
861  lstrgData.extend<unsigned long long>("DATA_ID");
862  lstrgData.extend<unsigned int>("RUNNUM");
863  lstrgData.extend<unsigned int>("CMSLSNUM");
864  lstrgData.extend<unsigned long long>("DEADTIMECOUNT");
865  lstrgData.extend<unsigned int>("BITZEROCOUNT");
866  lstrgData.extend<unsigned int>("BITZEROPRESCALE");
867  lstrgData.extend<float>("DEADFRAC");
868  lstrgData.extend<coral::Blob>("PRESCALEBLOB");
869  lstrgData.extend<coral::Blob>("TRGCOUNTBLOB");
870 
871  unsigned long long& data_id = lstrgData["DATA_ID"].data<unsigned long long>();
872  unsigned int& trgrunnum = lstrgData["RUNNUM"].data<unsigned int>();
873  unsigned int& cmslsnum = lstrgData["CMSLSNUM"].data<unsigned int>();
874  unsigned long long& deadtime = lstrgData["DEADTIMECOUNT"].data<unsigned long long>();
875  unsigned int& bitzerocount = lstrgData["BITZEROCOUNT"].data<unsigned int>();
876  unsigned int& bitzeroprescale = lstrgData["BITZEROPRESCALE"].data<unsigned int>();
877  float& deadfrac = lstrgData["DEADFRAC"].data<float>();
878  coral::Blob& prescaleblob = lstrgData["PRESCALEBLOB"].data<coral::Blob>();
879  coral::Blob& trgcountblob = lstrgData["TRGCOUNTBLOB"].data<coral::Blob>();
880 
881  unsigned long long branch_id = 3;
882  std::string branch_name("DATA");
883  lumi::RevisionDML revisionDML;
884  lumi::RevisionDML::TrgEntry trgrundata;
885  std::stringstream op;
886  op << irunnumber;
887  std::string runnumberStr = op.str();
888  lumisession->transaction().start(false);
889  trgrundata.entry_name = runnumberStr;
890  trgrundata.source = source;
891  trgrundata.runnumber = irunnumber;
892  std::string bitnames;
893  TriggerNameResult_Algo::iterator bitnameIt;
894  TriggerNameResult_Algo::iterator bitnameItBeg = algonames.begin();
895  TriggerNameResult_Algo::iterator bitnameItEnd = algonames.end();
896  for (bitnameIt = bitnameItBeg; bitnameIt != bitnameItEnd; ++bitnameIt) {
897  if (bitnameIt != bitnameItBeg) {
898  bitnames += std::string(",");
899  }
900  bitnames += *bitnameIt;
901  }
902  TriggerNameResult_Tech::iterator techbitnameIt;
903  TriggerNameResult_Tech::iterator techbitnameItBeg = technames.begin();
904  TriggerNameResult_Tech::iterator techbitnameItEnd = technames.end();
905  for (techbitnameIt = techbitnameItBeg; techbitnameIt != techbitnameItEnd; ++techbitnameIt) {
906  bitnames += std::string(",");
907  bitnames += *techbitnameIt;
908  }
909  std::cout << "\tbitnames " << bitnames << std::endl;
910  trgrundata.bitzeroname = technames[4];
911  trgrundata.bitnames = bitnames;
912  trgrundata.entry_id = revisionDML.getEntryInBranchByName(
913  lumisession->nominalSchema(), lumi::LumiNames::trgdataTableName(), runnumberStr, branch_name);
914  if (trgrundata.entry_id == 0) {
915  revisionDML.bookNewEntry(lumisession->nominalSchema(), LumiNames::trgdataTableName(), trgrundata);
916  std::cout << "trgrundata revision_id " << trgrundata.revision_id << " entry_id " << trgrundata.entry_id
917  << " data_id " << trgrundata.data_id << std::endl;
918  revisionDML.addEntry(
919  lumisession->nominalSchema(), LumiNames::trgdataTableName(), trgrundata, branch_id, branch_name);
920  } else {
921  revisionDML.bookNewRevision(lumisession->nominalSchema(), LumiNames::trgdataTableName(), trgrundata);
922  std::cout << "trgrundata revision_id " << trgrundata.revision_id << " entry_id " << trgrundata.entry_id
923  << " data_id " << trgrundata.data_id << std::endl;
924  revisionDML.addRevision(
925  lumisession->nominalSchema(), LumiNames::trgdataTableName(), trgrundata, branch_id, branch_name);
926  }
927  std::cout << "inserting trgrundata " << std::endl;
928  revisionDML.insertTrgRunData(lumisession->nominalSchema(), trgrundata);
929  std::cout << "inserting lstrg data" << std::endl;
930 
931  unsigned int trglscount = 0;
932  // trglscount=0;
933  coral::IBulkOperation* lstrgInserter = nullptr;
934  unsigned int comittedls = 0;
935  for (deadIt = deadtimesBeg; deadIt != deadtimesEnd; ++deadIt, ++trglscount) {
936  unsigned int cmslscount = trglscount + 1;
937  if (!lumisession->transaction().isActive()) {
938  lumisession->transaction().start(false);
939  coral::ITable& lstrgtable = lumisession->nominalSchema().tableHandle(LumiNames::lstrgTableName());
940  lstrgInserter = lstrgtable.dataEditor().bulkInsert(lstrgData, 2048);
941  } else {
942  if (deadIt == deadtimesBeg) {
943  coral::ITable& lstrgtable = lumisession->nominalSchema().tableHandle(LumiNames::lstrgTableName());
944  lstrgInserter = lstrgtable.dataEditor().bulkInsert(lstrgData, 2048);
945  }
946  }
947  data_id = trgrundata.data_id;
948  trgrunnum = irunnumber;
949  cmslsnum = cmslscount;
950  deadtime = *deadIt;
951  deadfrac = deadfracs[trglscount];
952  //bitzerocount = algocounts[trglscount][0];//use algobit_0
953  //bitzeroprescale = prescalealgo[cmslsnum][0];
954  bitzerocount = techcounts[trglscount][4]; //use techbit_4
955  bitzeroprescale = prescaletech[cmslsnum][4];
956  std::vector<unsigned int> fullprescales;
957  fullprescales.reserve(prescalealgo[cmslsnum].size() + prescaletech[cmslsnum].size());
958  fullprescales.insert(fullprescales.end(), prescalealgo[cmslsnum].begin(), prescalealgo[cmslsnum].end());
959  fullprescales.insert(fullprescales.end(), prescaletech[cmslsnum].begin(), prescaletech[cmslsnum].end());
960 
961  prescaleblob.resize(sizeof(unsigned int) * (fullprescales.size()));
962  void* prescaleblob_StartAddress = prescaleblob.startingAddress();
963  std::memmove(prescaleblob_StartAddress, &fullprescales[0], sizeof(unsigned int) * (fullprescales.size()));
964 
965  std::vector<unsigned int> fullcounts;
966  fullcounts.reserve(algocounts[trglscount].size() + techcounts[trglscount].size());
967  fullcounts.insert(fullcounts.end(), algocounts[trglscount].begin(), algocounts[trglscount].end());
968  fullcounts.insert(fullcounts.end(), techcounts[trglscount].begin(), techcounts[trglscount].end());
969  trgcountblob.resize(sizeof(unsigned int) * (fullcounts.size()));
970  void* trgcountblob_StartAddress = trgcountblob.startingAddress();
971  std::memmove(trgcountblob_StartAddress, &fullcounts[0], sizeof(unsigned int) * (fullcounts.size()));
972 
973  lstrgInserter->processNextIteration();
974  lstrgInserter->flush();
975  ++comittedls;
976  if (comittedls == commitintv) {
977  std::cout << "\t committing in LS chunck " << comittedls << std::endl;
978  delete lstrgInserter;
979  lstrgInserter = nullptr;
980  lumisession->transaction().commit();
981  comittedls = 0;
982  std::cout << "\t committed " << std::endl;
983  } else if (trglscount == (totalcmsls - 1)) {
984  std::cout << "\t committing at the end" << std::endl;
985  delete lstrgInserter;
986  lstrgInserter = nullptr;
987  lumisession->transaction().commit();
988  std::cout << "\t done" << std::endl;
989  }
990  }
991 
992  return trgrundata.data_id;
993  }
994  const std::string TRGScalers2DB::dataType() const { return "TRG"; }
995  const std::string TRGScalers2DB::sourceType() const { return "DB"; }
996  //utilities
997  std::string TRGScalers2DB::int2str(unsigned int t, unsigned int width) {
998  std::stringstream ss;
999  ss.width(width);
1000  ss.fill('0');
1001  ss << t;
1002  return ss.str();
1003  }
1004  unsigned int TRGScalers2DB::str2int(const std::string& s) {
1005  std::istringstream myStream(s);
1006  unsigned int i;
1007  if (myStream >> i) {
1008  return i;
1009  } else {
1010  throw lumi::Exception(std::string("str2int error"), "str2int", "TRGScalers2DB");
1011  }
1012  }
1014 } // namespace lumi
1017 #endif
eostools.ls
def ls(path, rec=False)
Definition: eostools.py:349
lumi::DataPipe::m_source
std::string m_source
Definition: DataPipe.h:28
lumi::LumiNames::lstrgTableName
static const std::string lstrgTableName()
Definition: LumiNames.cc:12
ApeEstimator_cff.width
width
Definition: ApeEstimator_cff.py:24
lumi::TRGScalers2DB::writeTrgDataToSchema2
unsigned long long writeTrgDataToSchema2(coral::ISessionProxy *session, unsigned int runnumber, const std::string &source, TriggerDeadCountResult::iterator deadtimesBeg, TriggerDeadCountResult::iterator deadtimesEnd, TRGScalers2DB::TriggerDeadFracResult &deadfracs, TriggerNameResult_Algo &algonames, TriggerNameResult_Tech &technames, TriggerCountResult_Algo &algocounts, TriggerCountResult_Tech &techcounts, PrescaleResult_Algo &prescalealgo, PrescaleResult_Tech &prescaletech, unsigned int commitintv)
Definition: TRGScalers2DB.cc:844
lumi::TRGScalers2DB::TRGScalers2DB
TRGScalers2DB(const std::string &dest)
Definition: TRGScalers2DB.cc:111
mps_fire.i
i
Definition: mps_fire.py:428
DataPipe.h
lumi::DataPipe::m_dest
std::string m_dest
Definition: DataPipe.h:27
idDealer.h
lumi::DataPipe::m_mode
std::string m_mode
Definition: DataPipe.h:30
lumi::TRGScalers2DB::TriggerNameResult_Algo
std::vector< std::string > TriggerNameResult_Algo
Definition: TRGScalers2DB.cc:44
lumi::RevisionDML::Entry::revision_id
unsigned long long revision_id
Definition: RevisionDML.h:29
gather_cfg.cout
cout
Definition: gather_cfg.py:144
pos
Definition: PixelAliasList.h:18
lumi::DataPipe
Definition: DataPipe.h:8
lumi::DBConfig::setAuthentication
void setAuthentication(const std::string &authPath)
Definition: DBConfig.cc:15
lumi::RevisionDML::TrgEntry::source
std::string source
Definition: RevisionDML.h:45
LumiNames.h
lumi::TRGScalers2DB::TriggerCountResult_Algo
std::vector< BITCOUNT > TriggerCountResult_Algo
Definition: TRGScalers2DB.cc:52
lumi::RevisionDML::Entry::entry_id
unsigned long long entry_id
Definition: RevisionDML.h:30
lumi::RevisionDML::addRevision
void addRevision(coral::ISchema &schema, const std::string &datatableName, const Entry &revision, unsigned long long branch_id, std::string &branchname)
Definition: RevisionDML.cc:97
lumi::N_TRGTECHBIT
const unsigned int N_TRGTECHBIT
Definition: ConstantDef.h:7
lumi::TRGScalers2DB
Definition: TRGScalers2DB.cc:33
RevisionDML.h
DataPipeFactory.h
lumi::TRGScalers2DB::TriggerCountResult_Tech
std::vector< BITCOUNT > TriggerCountResult_Tech
Definition: TRGScalers2DB.cc:53
lumi::TRGScalers2DB::TriggerNameResult_Tech
std::vector< std::string > TriggerNameResult_Tech
Definition: TRGScalers2DB.cc:45
lumi::RevisionDML::Entry::entry_name
std::string entry_name
Definition: RevisionDML.h:32
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
alignCSCRings.s
s
Definition: alignCSCRings.py:92
lumi::TRGScalers2DB::dataType
const std::string dataType() const override
Definition: TRGScalers2DB.cc:994
lumi::N_TRGBIT
const unsigned int N_TRGBIT
Definition: ConstantDef.h:8
lumi::LumiNames::trgdataTableName
static const std::string trgdataTableName()
Definition: LumiNames.cc:11
lumi::TRGScalers2DB::TriggerDeadCountResult
std::vector< DEADCOUNT > TriggerDeadCountResult
Definition: TRGScalers2DB.cc:49
lumi::TRGScalers2DB::writeTrgData
void writeTrgData(coral::ISessionProxy *session, unsigned int runnumber, const std::string &source, TriggerDeadCountResult::iterator deadtimesBeg, TriggerDeadCountResult::iterator deadtimesEnd, TRGScalers2DB::TriggerDeadFracResult &deadfracs, TriggerNameResult_Algo &algonames, TriggerNameResult_Tech &technames, TriggerCountResult_Algo &algocounts, TriggerCountResult_Tech &techcounts, PrescaleResult_Algo &prescalealgo, PrescaleResult_Tech &prescaletech, unsigned int commitintv)
Definition: TRGScalers2DB.cc:710
lumi::idDealer::generateNextIDForTable
unsigned long long generateNextIDForTable(const std::string &tableName, unsigned int interval=1)
Definition: idDealer.cc:33
source
static const std::string source
Definition: EdmProvDump.cc:47
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
DEFINE_EDM_PLUGIN
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition: PluginFactory.h:124
lumi::TRGScalers2DB::PrescaleResult_Tech
std::map< unsigned int, std::vector< unsigned int > > PrescaleResult_Tech
Definition: TRGScalers2DB.cc:55
lumi::RevisionDML
Definition: RevisionDML.h:9
lumi::RevisionDML::TrgEntry::bitzeroname
std::string bitzeroname
Definition: RevisionDML.h:47
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
lumi::DataPipe::m_authpath
std::string m_authpath
Definition: DataPipe.h:29
lumi::TRGScalers2DB::str2int
unsigned int str2int(const std::string &s)
Definition: TRGScalers2DB.cc:1004
lumi::RevisionDML::TrgEntry::bitnames
std::string bitnames
Definition: RevisionDML.h:48
lumi::RevisionDML::TrgEntry
Definition: RevisionDML.h:42
edmplugin::PluginFactory
Definition: PluginFactory.h:34
cond::runnumber
Definition: Time.h:19
lumi::DBConfig
Definition: DBConfig.h:8
lumi::TRGScalers2DB::DEADCOUNT
unsigned long long DEADCOUNT
Definition: TRGScalers2DB.cc:47
lumi::TRGScalers2DB::PrescaleResult_Algo
std::map< unsigned int, std::vector< unsigned int > > PrescaleResult_Algo
Definition: TRGScalers2DB.cc:54
lumi::RevisionDML::bookNewRevision
void bookNewRevision(coral::ISchema &schema, const std::string &datatableName, Entry &revision)
Definition: RevisionDML.cc:53
lumi::TRGScalers2DB::sourceType
const std::string sourceType() const override
Definition: TRGScalers2DB.cc:995
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
prescale
Definition: PrescaleEventFilter.cc:32
lumi::RevisionDML::bookNewEntry
void bookNewEntry(coral::ISchema &schema, const std::string &datatableName, Entry &entry)
Definition: RevisionDML.cc:44
lumi::TRGScalers2DB::DEADFRAC
float DEADFRAC
Definition: TRGScalers2DB.cc:48
lumi::N_TRGALGOBIT
const unsigned int N_TRGALGOBIT
Definition: ConstantDef.h:6
lumi::TRGScalers2DB::BITCOUNT
std::vector< unsigned int > BITCOUNT
Definition: TRGScalers2DB.cc:51
HLT_FULL_cff.algo_name
algo_name
Definition: HLT_FULL_cff.py:9189
lumi::TRGScalers2DB::TriggerDeadFracResult
std::vector< DEADFRAC > TriggerDeadFracResult
Definition: TRGScalers2DB.cc:50
Exception
Definition: hltDiff.cc:246
lumi::RevisionDML::insertTrgRunData
void insertTrgRunData(coral::ISchema &schema, const TrgEntry &trgentry)
Definition: RevisionDML.cc:139
lumi::RevisionDML::addEntry
void addEntry(coral::ISchema &schema, const std::string &datatableName, const Entry &entry, unsigned long long branch_id, const std::string &branchname)
Definition: RevisionDML.cc:60
lumi::TRGScalers2DB::COMMITLSINTERVAL
const static unsigned int COMMITLSINTERVAL
Definition: TRGScalers2DB.cc:35
Exception.h
lumi::TRGScalers2DB::COMMITLSTRGINTERVAL
const static unsigned int COMMITLSTRGINTERVAL
Definition: TRGScalers2DB.cc:36
lumi::RevisionDML::TrgEntry::runnumber
unsigned int runnumber
Definition: RevisionDML.h:46
DBConfig.h
lumi::TRGScalers2DB::int2str
std::string int2str(unsigned int t, unsigned int width)
Definition: TRGScalers2DB.cc:997
lumi::idDealer
Definition: idDealer.h:8
lumi::TRGScalers2DB::retrieveData
unsigned long long retrieveData(unsigned int runnumber) override
Definition: TRGScalers2DB.cc:112
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7733
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
lumi
Definition: LumiSectionData.h:20
lumi::TRGScalers2DB::~TRGScalers2DB
~TRGScalers2DB() override
Definition: TRGScalers2DB.cc:1013
lumi::RevisionDML::Entry::data_id
unsigned long long data_id
Definition: RevisionDML.h:31
lumi::LumiNames::trgTableName
static const std::string trgTableName()
Definition: LumiNames.cc:13
lumi::RevisionDML::getEntryInBranchByName
unsigned long long getEntryInBranchByName(coral::ISchema &schema, const std::string &datatableName, const std::string &entryname, const std::string &branchname)
Definition: RevisionDML.cc:16
mps_fire.dest
dest
Definition: mps_fire.py:179
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
ConstantDef.h