CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Attributes | Private Types | Private Member Functions
lumi::TRGWBM2DB Class Reference
Inheritance diagram for lumi::TRGWBM2DB:
lumi::DataPipe

Public Member Functions

const std::string dataType () const override
 
unsigned long long retrieveData (unsigned int runnumber) override
 
const std::string sourceType () const override
 
 TRGWBM2DB (const std::string &dest)
 
 ~TRGWBM2DB () override
 
- Public Member Functions inherited from lumi::DataPipe
 DataPipe (const std::string &)
 
 DataPipe (const DataPipe &)=delete
 
std::string getAuthPath () const
 
std::string getMode () const
 
float getNorm () const
 
std::string getSource () const
 
const DataPipeoperator= (const DataPipe &)=delete
 
void setAuthPath (const std::string &authpath)
 
void setMode (const std::string &mode)
 
void setNoCheckingStableBeam ()
 
void setNorm (float norm)
 
void setNoValidate ()
 
void setSource (const std::string &source)
 
virtual ~DataPipe ()
 

Static Public Attributes

static const unsigned int COMMITLSINTERVAL = 20
 

Private Types

typedef std::vector< unsigned int > BITCOUNT
 
typedef unsigned long long DEADCOUNT
 
typedef std::vector< unsigned int > PrescaleResult_Algo
 
typedef std::vector< unsigned int > PrescaleResult_Tech
 
typedef std::vector< BITCOUNTTriggerCountResult_Algo
 
typedef std::vector< BITCOUNTTriggerCountResult_Tech
 
typedef std::vector< DEADCOUNTTriggerDeadCountResult
 
typedef std::vector< std::string > TriggerNameResult_Algo
 
typedef std::vector< std::string > TriggerNameResult_Tech
 

Private Member Functions

std::string int2str (unsigned int t, unsigned int width)
 
unsigned int str2int (const std::string &s)
 

Additional Inherited Members

- Protected Attributes inherited from lumi::DataPipe
std::string m_authpath
 
std::string m_dest
 
std::string m_mode
 
bool m_nocheckingstablebeam
 
float m_norm
 
bool m_novalidate
 
std::string m_source
 

Detailed Description

Definition at line 28 of file TRGWBM2DB.cc.

Member Typedef Documentation

◆ BITCOUNT

typedef std::vector<unsigned int> lumi::TRGWBM2DB::BITCOUNT
private

Definition at line 50 of file TRGWBM2DB.cc.

◆ DEADCOUNT

typedef unsigned long long lumi::TRGWBM2DB::DEADCOUNT
private

Definition at line 48 of file TRGWBM2DB.cc.

◆ PrescaleResult_Algo

typedef std::vector<unsigned int> lumi::TRGWBM2DB::PrescaleResult_Algo
private

Definition at line 45 of file TRGWBM2DB.cc.

◆ PrescaleResult_Tech

typedef std::vector<unsigned int> lumi::TRGWBM2DB::PrescaleResult_Tech
private

Definition at line 46 of file TRGWBM2DB.cc.

◆ TriggerCountResult_Algo

typedef std::vector<BITCOUNT> lumi::TRGWBM2DB::TriggerCountResult_Algo
private

Definition at line 51 of file TRGWBM2DB.cc.

◆ TriggerCountResult_Tech

typedef std::vector<BITCOUNT> lumi::TRGWBM2DB::TriggerCountResult_Tech
private

Definition at line 52 of file TRGWBM2DB.cc.

◆ TriggerDeadCountResult

typedef std::vector<DEADCOUNT> lumi::TRGWBM2DB::TriggerDeadCountResult
private

Definition at line 49 of file TRGWBM2DB.cc.

◆ TriggerNameResult_Algo

typedef std::vector<std::string> lumi::TRGWBM2DB::TriggerNameResult_Algo
private

Definition at line 43 of file TRGWBM2DB.cc.

◆ TriggerNameResult_Tech

typedef std::vector<std::string> lumi::TRGWBM2DB::TriggerNameResult_Tech
private

Definition at line 44 of file TRGWBM2DB.cc.

Constructor & Destructor Documentation

◆ TRGWBM2DB()

lumi::TRGWBM2DB::TRGWBM2DB ( const std::string &  dest)
explicit

Definition at line 57 of file TRGWBM2DB.cc.

57 : DataPipe(dest) {}
DataPipe(const std::string &)
Definition: DataPipe.cc:2

◆ ~TRGWBM2DB()

lumi::TRGWBM2DB::~TRGWBM2DB ( )
override

Definition at line 643 of file TRGWBM2DB.cc.

643 {}

Member Function Documentation

◆ dataType()

const std::string lumi::TRGWBM2DB::dataType ( ) const
overridevirtual

Implements lumi::DataPipe.

Definition at line 624 of file TRGWBM2DB.cc.

624 { return "TRG"; }

◆ int2str()

std::string lumi::TRGWBM2DB::int2str ( unsigned int  t,
unsigned int  width 
)
private

Definition at line 627 of file TRGWBM2DB.cc.

References contentValuesCheck::ss, submitPVValidationJobs::t, and ApeEstimator_cff::width.

Referenced by retrieveData().

627  {
628  std::stringstream ss;
629  ss.width(width);
630  ss.fill('0');
631  ss << t;
632  return ss.str();
633  }

◆ retrieveData()

unsigned long long lumi::TRGWBM2DB::retrieveData ( unsigned int  runnumber)
overridevirtual

transaction.start(true); //true means readonly transaction std::cout<<"schema name "<<session->schema(gtmonschema).schemaName()<<std::endl; std::set<std::string> listofviews; listofviews=session->schema(gtmonschema).listViews(); for( std::set<std::string>::iterator it=listofviews.begin(); it!=listofviews.end();++it ){ std::cout<<"view: "<<*it<<std::endl; } std::cout<<"schema name "<<session->schema(gtschema).schemaName()<<std::endl; listofviews.clear(); listofviews=session->schema(gtschema).listViews(); for( std::set<std::string>::iterator it=listofviews.begin(); it!=listofviews.end();++it ){ std::cout<<"view: "<<*it<<std::endl; } std::cout<<"commit transaction"<<std::endl; transaction.commit();

Part I query tables in schema cms_wbm

Part II query tables in schema cms_gt

Implements lumi::DataPipe.

Definition at line 58 of file TRGWBM2DB.cc.

References HLT_2022v15_cff::algo_name, HltBtagPostValidation_cff::c, COMMITLSINTERVAL, submitPVResolutionJobs::count, gather_cfg::cout, Exception, lumi::idDealer::generateNextIDForTable(), int2str(), lumi::DataPipe::m_authpath, lumi::DataPipe::m_dest, lumi::DataPipe::m_source, lumi::N_TRGALGOBIT, lumi::N_TRGBIT, lumi::N_TRGTECHBIT, cond::runnumber, alignCSCRings::s, lumi::DBConfig::setAuthentication(), contentValuesCheck::ss, AlCaHLTBitMon_QueryRunRegistry::string, and lumi::LumiNames::trgTableName().

58  {
59  std::string runnumberstr = int2str(runnumber, 6);
60  //query source GT database
61  coral::ConnectionService* svc = new coral::ConnectionService;
62  lumi::DBConfig dbconf(*svc);
63  if (!m_authpath.empty()) {
64  dbconf.setAuthentication(m_authpath);
65  }
66  //std::cout<<"m_source "<<m_source<<std::endl;
67  coral::ISessionProxy* trgsession = svc->connect(m_source, coral::ReadOnly);
68  coral::ITypeConverter& tpc = trgsession->typeConverter();
69 
70  tpc.setCppTypeForSqlType("unsigned int", "NUMBER(7)");
71  tpc.setCppTypeForSqlType("unsigned int", "NUMBER(10)");
72  tpc.setCppTypeForSqlType("unsigned long long", "NUMBER(20)");
73 
74  coral::AttributeList bindVariableList;
75  bindVariableList.extend("runnumber", typeid(unsigned int));
76  bindVariableList["runnumber"].data<unsigned int>() = runnumber;
77  std::string wbmschema("CMS_WBM");
78  std::string algoname("LEVEL1_TRIGGER_ALGO_CONDITIONS");
79  std::string techname("LEVEL1_TRIGGER_TECH_CONDITIONS");
80  std::string deadname("LEVEL1_TRIGGER_CONDITIONS");
81 
82  std::string gtschema("CMS_GT");
83  std::string runtechviewname("GT_RUN_TECH_VIEW");
84  std::string runalgoviewname("GT_RUN_ALGO_VIEW");
85  std::string runprescalgoviewname("GT_RUN_PRESC_ALGO_VIEW");
86  std::string runpresctechviewname("GT_RUN_PRESC_TECH_VIEW");
87 
88  //data exchange format
89  lumi::TRGWBM2DB::BITCOUNT mybitcount_algo;
90  mybitcount_algo.reserve(lumi::N_TRGALGOBIT);
91  lumi::TRGWBM2DB::BITCOUNT mybitcount_tech;
92  mybitcount_tech.reserve(lumi::N_TRGTECHBIT);
94  algonames.reserve(lumi::N_TRGALGOBIT);
96  technames.reserve(lumi::N_TRGTECHBIT);
98  algoprescale.reserve(lumi::N_TRGALGOBIT);
100  techprescale.reserve(lumi::N_TRGTECHBIT);
102  algocount.reserve(400);
104  techcount.reserve(400);
106  deadtimeresult.reserve(400);
107  coral::ITransaction& transaction = trgsession->transaction();
108  transaction.start(true);
109  //uncomment if you want to see all the visible views
132  coral::ISchema& wbmschemaHandle = trgsession->schema(wbmschema);
133  if (!wbmschemaHandle.existsTable(algoname)) {
134  throw lumi::Exception(std::string("non-existing table ") + algoname, "retrieveData", "TRGWBM2DB");
135  }
136  if (!wbmschemaHandle.existsTable(techname)) {
137  throw lumi::Exception(std::string("non-existing table ") + techname, "retrieveData", "TRGWBM2DB");
138  }
139  if (!wbmschemaHandle.existsTable(deadname)) {
140  throw lumi::Exception(std::string("non-existing table ") + deadname, "retrieveData", "TRGWBM2DB");
141  }
142  //
143  //select LUMISEGMENTNR,GTALGOCOUNTS,BIT from cms_wbm.LEVEL1_TRIGGER_ALGO_CONDITIONS where RUNNUMBER=133881 order by LUMISEGMENTNR,BIT;
144  //note: LUMISEGMENTNR count from 1
145  //note: BIT count from 0-127
146  //
147  coral::IQuery* Queryalgo = wbmschemaHandle.newQuery();
148  Queryalgo->addToTableList(algoname);
149  coral::AttributeList qalgoOutput;
150  qalgoOutput.extend("counts", typeid(unsigned int));
151  qalgoOutput.extend("lsnr", typeid(unsigned int));
152  qalgoOutput.extend("algobit", typeid(unsigned int));
153  Queryalgo->addToOutputList("GTALGOCOUNTS", "counts");
154  Queryalgo->addToOutputList("LUMISEGMENTNR", "lsnr");
155  Queryalgo->addToOutputList("BIT", "algobit");
156  Queryalgo->setCondition("RUNNUMBER =:runnumber", bindVariableList);
157  Queryalgo->addToOrderList("LUMISEGMENTNR");
158  Queryalgo->addToOrderList("BIT");
159  Queryalgo->defineOutput(qalgoOutput);
160  coral::ICursor& c = Queryalgo->execute();
161  unsigned int s = 0;
162  while (c.next()) {
163  const coral::AttributeList& row = c.currentRow();
164  //row.toOutputStream( std::cout ) << std::endl;
165  unsigned int lsnr = row["lsnr"].data<unsigned int>();
166  unsigned int count = row["counts"].data<unsigned int>();
167  mybitcount_algo.push_back(count);
168  unsigned int algobit = row["algobit"].data<unsigned int>();
169  if (algobit == (lumi::N_TRGALGOBIT - 1)) {
170  ++s;
171  while (s != lsnr) {
172  std::cout << "ALGO COUNT alert: found hole in LS range" << std::endl;
173  std::cout << " fill all algocount 0 for LS " << s << std::endl;
174  std::vector<unsigned int> tmpzero(lumi::N_TRGALGOBIT, 0);
175  algocount.push_back(tmpzero);
176  ++s;
177  }
178  algocount.push_back(mybitcount_algo);
179  mybitcount_algo.clear();
180  }
181  }
182  if (s == 0) {
183  c.close();
184  delete Queryalgo;
185  transaction.commit();
186  throw lumi::Exception(std::string("requested run ") + runnumberstr + std::string(" doesn't exist for algocounts"),
187  "retrieveData",
188  "TRGWBM2DB");
189  }
190  delete Queryalgo;
191  transaction.commit();
192  //std::cout<<"read algo counts"<<std::endl;
193  //
194  //select LUMISEGMENTNR,GTTECHCOUNTS,BIT from cms_wbm.LEVEL1_TRIGGER_TECH_CONDITIONS where RUNNUMBER=133881 order by LUMISEGMENTNR,BIT;
195  //note: LUMISEGMENTNR count from 1
196  //note: BIT count from 0-63
197  //
198  transaction.start(true);
199  coral::IQuery* Querytech = wbmschemaHandle.newQuery();
200  Querytech->addToTableList(techname);
201  coral::AttributeList qtechOutput;
202  qtechOutput.extend("counts", typeid(unsigned int));
203  qtechOutput.extend("lsnr", typeid(unsigned int));
204  qtechOutput.extend("techbit", typeid(unsigned int));
205  Querytech->addToOutputList("GTTECHCOUNTS", "counts");
206  Querytech->addToOutputList("LUMISEGMENTNR", "lsnr");
207  Querytech->addToOutputList("BIT", "techbit");
208  Querytech->setCondition("RUNNUMBER=:runnumber", bindVariableList);
209  Querytech->addToOrderList("LUMISEGMENTNR");
210  Querytech->addToOrderList("BIT");
211  Querytech->defineOutput(qtechOutput);
212  coral::ICursor& techcursor = Querytech->execute();
213 
214  s = 0;
215  while (techcursor.next()) {
216  const coral::AttributeList& row = techcursor.currentRow();
217  //row.toOutputStream( std::cout ) << std::endl;
218  unsigned int lsnr = row["lsnr"].data<unsigned int>();
219  unsigned int count = row["counts"].data<unsigned int>();
220  unsigned int techbit = row["techbit"].data<unsigned int>();
221  mybitcount_tech.push_back(count);
222  if (techbit == (lumi::N_TRGTECHBIT - 1)) {
223  ++s;
224  while (s != lsnr) {
225  std::cout << "TECH COUNT alert: found hole in LS range" << std::endl;
226  std::cout << " fill all techcount with 0 for LS " << s << std::endl;
227  std::vector<unsigned int> tmpzero(lumi::N_TRGTECHBIT, 0);
228  techcount.push_back(tmpzero);
229  ++s;
230  }
231  techcount.push_back(mybitcount_tech);
232  mybitcount_tech.clear();
233  }
234  }
235  if (s == 0) {
236  techcursor.close();
237  delete Querytech;
238  transaction.commit();
239  throw lumi::Exception(std::string("requested run ") + runnumberstr + std::string(" doesn't exist for techcounts"),
240  "retrieveData",
241  "TRGWBM2DB");
242  }
243  delete Querytech;
244  transaction.commit();
245  //std::cout<<"read tech counts"<<std::endl;
246  //
247  //select LUMISEGMENTNR,DEADTIMEBEAMACTIVE from cms_wbm.LEVEL1_TRIGGER_CONDITIONS where RUNNUMBER=133881 order by LUMISEGMENTNR;
248  //Note: LUMISEGMENTNR counts from 1
249  //
250  transaction.start(true);
251  coral::IQuery* Querydead = wbmschemaHandle.newQuery();
252  Querydead->addToTableList(deadname);
253  coral::AttributeList qdeadOutput;
254  qdeadOutput.extend("counts", typeid(unsigned int));
255  qdeadOutput.extend("lsnr", typeid(unsigned int));
256  Querydead->addToOutputList("DEADTIMEBEAMACTIVE", "counts");
257  Querydead->addToOutputList("LUMISEGMENTNR", "lsnr");
258  coral::AttributeList bindVariablesDead;
259  bindVariablesDead.extend("runnumber", typeid(int));
260  bindVariablesDead["runnumber"].data<int>() = runnumber;
261  Querydead->setCondition("RUNNUMBER=:runnumber", bindVariablesDead);
262  Querydead->addToOrderList("LUMISEGMENTNR");
263  Querydead->defineOutput(qdeadOutput);
264  coral::ICursor& deadcursor = Querydead->execute();
265  s = 0;
266  while (deadcursor.next()) {
267  const coral::AttributeList& row = deadcursor.currentRow();
268  //row.toOutputStream( std::cout ) << std::endl;
269  ++s;
270  unsigned int lsnr = row["lsnr"].data<unsigned int>();
271  while (s != lsnr) {
272  std::cout << "DEADTIME alert: found hole in LS range" << std::endl;
273  std::cout << " fill deadtimebeamactive 0 for LS " << s << std::endl;
274  deadtimeresult.push_back(0);
275  ++s;
276  }
277  unsigned int count = row["counts"].data<unsigned int>();
278  deadtimeresult.push_back(count);
279  }
280  //std::cout<<"deadtimeresult raw "<<deadtimeresult.size()<<std::endl;
281  if (s == 0) {
282  deadcursor.close();
283  delete Querydead;
284  transaction.commit();
285  throw lumi::Exception(std::string("requested run ") + runnumberstr + std::string(" doesn't exist for deadcounts"),
286  "retrieveData",
287  "TRGWBM2DB");
288  return 0;
289  }
290  delete Querydead;
291  transaction.commit();
292  //std::cout<<"read dead counts"<<std::endl;
297  transaction.start(true);
298  coral::ISchema& gtschemaHandle = trgsession->schema(gtschema);
299  if (!gtschemaHandle.existsView(runtechviewname)) {
300  throw lumi::Exception(std::string("non-existing view ") + runtechviewname, "str2int", "TRGWBM2DB");
301  }
302  if (!gtschemaHandle.existsView(runalgoviewname)) {
303  throw lumi::Exception(std::string("non-existing view ") + runalgoviewname, "str2int", "TRGWBM2DB");
304  }
305  if (!gtschemaHandle.existsView(runprescalgoviewname)) {
306  throw lumi::Exception(std::string("non-existing view ") + runprescalgoviewname, "str2int", "TRGWBM2DB");
307  }
308  if (!gtschemaHandle.existsView(runpresctechviewname)) {
309  throw lumi::Exception(std::string("non-existing view ") + runpresctechviewname, "str2int", "TRGWBM2DB");
310  }
311  //
312  //select algo_index,alias from cms_gt.gt_run_algo_view where runnumber=:runnumber order by algo_index;
313  //
314  std::map<unsigned int, std::string> triggernamemap;
315  coral::IQuery* QueryName = gtschemaHandle.newQuery();
316  QueryName->addToTableList(runalgoviewname);
317  coral::AttributeList qAlgoNameOutput;
318  qAlgoNameOutput.extend("algo_index", typeid(unsigned int));
319  qAlgoNameOutput.extend("alias", typeid(std::string));
320  QueryName->addToOutputList("algo_index");
321  QueryName->addToOutputList("alias");
322  QueryName->setCondition("runnumber =:runnumber", bindVariableList);
323  QueryName->addToOrderList("algo_index");
324  QueryName->defineOutput(qAlgoNameOutput);
325  coral::ICursor& algonamecursor = QueryName->execute();
326  while (algonamecursor.next()) {
327  const coral::AttributeList& row = algonamecursor.currentRow();
328  //row.toOutputStream( std::cout ) << std::endl;
329  unsigned int algo_index = row["algo_index"].data<unsigned int>();
330  std::string algo_name = row["alias"].data<std::string>();
331  triggernamemap.insert(std::make_pair(algo_index, algo_name));
332  }
333  delete QueryName;
334  //std::cout<<"read alias"<<std::endl;
335  transaction.commit();
336 
337  //
338  //select techtrig_index,name from cms_gt.gt_run_tech_view where runnumber=:runnumber order by techtrig_index;
339  //
340  transaction.start(true);
341  std::map<unsigned int, std::string> techtriggernamemap;
342  coral::IQuery* QueryTechName = gtschemaHandle.newQuery();
343  QueryTechName->addToTableList(runtechviewname);
344  coral::AttributeList qTechNameOutput;
345  qTechNameOutput.extend("techtrig_index", typeid(unsigned int));
346  qTechNameOutput.extend("name", typeid(std::string));
347  QueryTechName->addToOutputList("techtrig_index");
348  QueryTechName->addToOutputList("name");
349  QueryTechName->setCondition("runnumber =:runnumber", bindVariableList);
350  QueryTechName->addToOrderList("techtrig_index");
351  QueryTechName->defineOutput(qTechNameOutput);
352  coral::ICursor& technamecursor = QueryTechName->execute();
353  while (technamecursor.next()) {
354  const coral::AttributeList& row = technamecursor.currentRow();
355  //row.toOutputStream( std::cout ) << std::endl;
356  unsigned int tech_index = row["techtrig_index"].data<unsigned int>();
357  std::string tech_name = row["name"].data<std::string>();
358  techtriggernamemap.insert(std::make_pair(tech_index, tech_name));
359  }
360  delete QueryTechName;
361  transaction.commit();
362  //
363  //select prescale_factor_algo_000,prescale_factor_algo_001..._127 from cms_gt.gt_run_presc_algo_view where runr=:runnumber and prescale_index=0;
364  //
365  transaction.start(true);
366  coral::IQuery* QueryAlgoPresc = gtschemaHandle.newQuery();
367  QueryAlgoPresc->addToTableList(runprescalgoviewname);
368  coral::AttributeList qAlgoPrescOutput;
369  std::string algoprescBase("PRESCALE_FACTOR_ALGO_");
370  for (unsigned int bitidx = 0; bitidx < lumi::N_TRGALGOBIT; ++bitidx) {
371  std::string algopresc = algoprescBase + int2str(bitidx, 3);
372  qAlgoPrescOutput.extend(algopresc, typeid(unsigned int));
373  }
374  for (unsigned int bitidx = 0; bitidx < lumi::N_TRGALGOBIT; ++bitidx) {
375  std::string algopresc = algoprescBase + int2str(bitidx, 3);
376  QueryAlgoPresc->addToOutputList(algopresc);
377  }
378  coral::AttributeList PrescbindVariable;
379  PrescbindVariable.extend("runnumber", typeid(int));
380  PrescbindVariable.extend("prescaleindex", typeid(int));
381  PrescbindVariable["runnumber"].data<int>() = runnumber;
382  PrescbindVariable["prescaleindex"].data<int>() = 0;
383  QueryAlgoPresc->setCondition("runnr =:runnumber AND prescale_index =:prescaleindex", PrescbindVariable);
384  QueryAlgoPresc->defineOutput(qAlgoPrescOutput);
385  coral::ICursor& algopresccursor = QueryAlgoPresc->execute();
386  while (algopresccursor.next()) {
387  const coral::AttributeList& row = algopresccursor.currentRow();
388  //row.toOutputStream( std::cout ) << std::endl;
389  for (unsigned int bitidx = 0; bitidx < 128; ++bitidx) {
390  std::string algopresc = algoprescBase + int2str(bitidx, 3);
391  algoprescale.push_back(row[algopresc].data<unsigned int>());
392  }
393  }
394  delete QueryAlgoPresc;
395  transaction.commit();
396 
397  //
398  //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;
399  //
400  transaction.start(true);
401  coral::IQuery* QueryTechPresc = gtschemaHandle.newQuery();
402  QueryTechPresc->addToTableList(runpresctechviewname);
403  coral::AttributeList qTechPrescOutput;
404  std::string techprescBase("PRESCALE_FACTOR_TT_");
405  for (unsigned int bitidx = 0; bitidx < lumi::N_TRGTECHBIT; ++bitidx) {
406  std::string techpresc = techprescBase + this->int2str(bitidx, 3);
407  qTechPrescOutput.extend(techpresc, typeid(unsigned int));
408  }
409  for (unsigned int bitidx = 0; bitidx < lumi::N_TRGTECHBIT; ++bitidx) {
410  std::string techpresc = techprescBase + int2str(bitidx, 3);
411  QueryTechPresc->addToOutputList(techpresc);
412  }
413  coral::AttributeList TechPrescbindVariable;
414  TechPrescbindVariable.extend("runnumber", typeid(int));
415  TechPrescbindVariable.extend("prescaleindex", typeid(int));
416  TechPrescbindVariable["runnumber"].data<int>() = runnumber;
417  TechPrescbindVariable["prescaleindex"].data<int>() = 0;
418  QueryTechPresc->setCondition("runnr =:runnumber AND prescale_index =:prescaleindex", TechPrescbindVariable);
419  QueryTechPresc->defineOutput(qTechPrescOutput);
420  coral::ICursor& techpresccursor = QueryTechPresc->execute();
421  while (techpresccursor.next()) {
422  const coral::AttributeList& row = techpresccursor.currentRow();
423  //row.toOutputStream( std::cout ) << std::endl;
424  for (unsigned int bitidx = 0; bitidx < lumi::N_TRGTECHBIT; ++bitidx) {
425  std::string techpresc = techprescBase + int2str(bitidx, 3);
426  techprescale.push_back(row[techpresc].data<unsigned int>());
427  }
428  }
429  delete QueryTechPresc;
430  transaction.commit();
431  transaction.commit();
432  //std::cout<<"tech prescale ok"<<std::endl;
433  delete trgsession;
434 
435  //
436  //reprocess Algo name result filling unallocated trigger bit with string "False"
437  //
438  for (size_t algoidx = 0; algoidx < lumi::N_TRGALGOBIT; ++algoidx) {
439  std::map<unsigned int, std::string>::iterator pos = triggernamemap.find(algoidx);
440  if (pos != triggernamemap.end()) {
441  algonames.push_back(pos->second);
442  } else {
443  algonames.push_back("False");
444  }
445  }
446  //
447  //reprocess Tech name result filling unallocated trigger bit with string "False"
448  //
449  std::stringstream ss;
450  for (size_t techidx = 0; techidx < lumi::N_TRGTECHBIT; ++techidx) {
451  ss << techidx;
452  technames.push_back(ss.str());
453  ss.str(""); //clear the string buffer after usage
454  }
455  //
456  //cross check result size
457  //
458  if (algonames.size() != lumi::N_TRGALGOBIT || technames.size() != lumi::N_TRGTECHBIT) {
459  throw lumi::Exception("wrong number of bits", "retrieveData", "TRGWBM2DB");
460  }
461  if (algoprescale.size() != lumi::N_TRGALGOBIT || techprescale.size() != lumi::N_TRGTECHBIT) {
462  throw lumi::Exception("wrong number of prescale", "retrieveData", "TRGWBM2DB");
463  }
464  if (deadtimeresult.size() != algocount.size() || deadtimeresult.size() != techcount.size()) {
465  throw lumi::Exception("inconsistent number of LS", "retrieveData", "TRGWBM2DB");
466  }
467  //
468  //write data into lumi db
469  //
470  coral::ISessionProxy* lumisession = svc->connect(m_dest, coral::Update);
471  coral::ITypeConverter& lumitpc = lumisession->typeConverter();
472  lumitpc.setCppTypeForSqlType("unsigned int", "NUMBER(7)");
473  lumitpc.setCppTypeForSqlType("unsigned int", "NUMBER(10)");
474  lumitpc.setCppTypeForSqlType("unsigned long long", "NUMBER(20)");
475 
476  TriggerDeadCountResult::const_iterator deadIt;
477  TriggerDeadCountResult::const_iterator deadBeg = deadtimeresult.begin();
478  TriggerDeadCountResult::const_iterator deadEnd = deadtimeresult.end();
479 
480  unsigned int totalcmsls = deadtimeresult.size();
481  std::cout << "inserting totalcmsls " << totalcmsls << std::endl;
482  std::map<unsigned long long, std::vector<unsigned long long> > idallocationtable;
483  try {
484  std::cout << "\t allocating total ids " << totalcmsls * lumi::N_TRGBIT << std::endl;
485  lumisession->transaction().start(false);
486  lumi::idDealer idg(lumisession->nominalSchema());
487  unsigned long long trgID = idg.generateNextIDForTable(LumiNames::trgTableName(), totalcmsls * lumi::N_TRGBIT) -
488  totalcmsls * lumi::N_TRGBIT;
489  lumisession->transaction().commit();
490  unsigned int trglscount = 0;
491  for (deadIt = deadBeg; deadIt != deadEnd; ++deadIt, ++trglscount) {
492  std::vector<unsigned long long> bitvec;
493  bitvec.reserve(lumi::N_TRGBIT);
494  BITCOUNT& algoinbits = algocount[trglscount];
495  BITCOUNT& techinbits = techcount[trglscount];
496  BITCOUNT::const_iterator algoBitIt;
497  BITCOUNT::const_iterator algoBitBeg = algoinbits.begin();
498  BITCOUNT::const_iterator algoBitEnd = algoinbits.end();
499  for (algoBitIt = algoBitBeg; algoBitIt != algoBitEnd; ++algoBitIt, ++trgID) {
500  bitvec.push_back(trgID);
501  }
502  BITCOUNT::const_iterator techBitIt;
503  BITCOUNT::const_iterator techBitBeg = techinbits.begin();
504  BITCOUNT::const_iterator techBitEnd = techinbits.end();
505  for (techBitIt = techBitBeg; techBitIt != techBitEnd; ++techBitIt, ++trgID) {
506  bitvec.push_back(trgID);
507  }
508  idallocationtable.insert(std::make_pair(trglscount, bitvec));
509  }
510  std::cout << "\t all ids allocated" << std::endl;
511  coral::AttributeList trgData;
512  trgData.extend<unsigned long long>("TRG_ID");
513  trgData.extend<unsigned int>("RUNNUM");
514  trgData.extend<unsigned int>("CMSLSNUM");
515  trgData.extend<unsigned int>("BITNUM");
516  trgData.extend<std::string>("BITNAME");
517  trgData.extend<unsigned int>("TRGCOUNT");
518  trgData.extend<unsigned long long>("DEADTIME");
519  trgData.extend<unsigned int>("PRESCALE");
520 
521  unsigned long long& trg_id = trgData["TRG_ID"].data<unsigned long long>();
522  unsigned int& trgrunnum = trgData["RUNNUM"].data<unsigned int>();
523  unsigned int& cmslsnum = trgData["CMSLSNUM"].data<unsigned int>();
524  unsigned int& bitnum = trgData["BITNUM"].data<unsigned int>();
525  std::string& bitname = trgData["BITNAME"].data<std::string>();
526  unsigned int& count = trgData["TRGCOUNT"].data<unsigned int>();
527  unsigned long long& deadtime = trgData["DEADTIME"].data<unsigned long long>();
528  unsigned int& prescale = trgData["PRESCALE"].data<unsigned int>();
529 
530  trglscount = 0;
531  coral::IBulkOperation* trgInserter = nullptr;
532  unsigned int comittedls = 0;
533  for (deadIt = deadBeg; deadIt != deadEnd; ++deadIt, ++trglscount) {
534  unsigned int cmslscount = trglscount + 1;
535  BITCOUNT& algoinbits = algocount[trglscount];
536  BITCOUNT& techinbits = techcount[trglscount];
537  unsigned int trgbitcount = 0;
538  BITCOUNT::const_iterator algoBitIt;
539  BITCOUNT::const_iterator algoBitBeg = algoinbits.begin();
540  BITCOUNT::const_iterator algoBitEnd = algoinbits.end();
541  if (!lumisession->transaction().isActive()) {
542  lumisession->transaction().start(false);
543  coral::ITable& trgtable = lumisession->nominalSchema().tableHandle(LumiNames::trgTableName());
544  trgInserter = trgtable.dataEditor().bulkInsert(trgData, 2048);
545  }
546  for (algoBitIt = algoBitBeg; algoBitIt != algoBitEnd; ++algoBitIt, ++trgbitcount) {
547  trg_id = idallocationtable[trglscount].at(trgbitcount);
548  deadtime = *deadIt;
549  trgrunnum = runnumber;
550  cmslsnum = cmslscount;
551  bitnum = trgbitcount;
552  bitname = algonames[trgbitcount];
553  count = *algoBitIt;
554  prescale = algoprescale[trgbitcount];
555 
556  //coral::AttributeList rowbuf;
557  //trgtable.dataEditor().rowBuffer(rowbuf);
558  //rowbuf["TRG_ID"].data<unsigned long long>()=idg.generateNextIDForTable(LumiNames::trgTableName());
559  //rowbuf["RUNNUM"].data<unsigned int>()=runnumber;
560  //rowbuf["CMSLSNUM"].data<unsigned int>()=cmslscount;
561  //rowbuf["BITNUM"].data<unsigned int>()=trgbitcount;
562  //rowbuf["BITNAME"].data<std::string>()=algonames[trgbitcount];
563  //rowbuf["TRGCOUNT"].data<unsigned int>()=*algoBitIt;
564  //rowbuf["DEADTIME"].data<unsigned long long>()=*deadIt;
565  //rowbuf["PRESCALE"].data<unsigned int>()=algoprescale[trgbitcount];
566  //trgtable.dataEditor().insertRow(rowbuf);
567  trgInserter->processNextIteration();
568  //std::cout<<"tot "<<tot<<std::endl;
569  }
570  BITCOUNT::const_iterator techBitIt;
571  BITCOUNT::const_iterator techBitBeg = techinbits.begin();
572  BITCOUNT::const_iterator techBitEnd = techinbits.end();
573  for (techBitIt = techBitBeg; techBitIt != techBitEnd; ++techBitIt, ++trgbitcount) {
574  trg_id = idallocationtable[trglscount].at(trgbitcount);
575  deadtime = *deadIt;
576  trgrunnum = runnumber;
577  cmslsnum = cmslscount;
578  bitnum = trgbitcount;
579  bitname = technames[trgbitcount - lumi::N_TRGALGOBIT];
580  count = *techBitIt;
581  prescale = techprescale[trgbitcount - lumi::N_TRGALGOBIT];
582  trgInserter->processNextIteration();
583  //coral::AttributeList rowbuf;
584  //trgtable.dataEditor().rowBuffer(rowbuf);
585  //rowbuf["TRG_ID"].data<unsigned long long>()=idg.generateNextIDForTable(LumiNames::trgTableName());
586  //rowbuf["RUNNUM"].data<unsigned int>()=runnumber;
587  //rowbuf["CMSLSNUM"].data<unsigned int>()=cmslscount;
588  //rowbuf["BITNUM"].data<unsigned int>()=trgbitcount;
589  //rowbuf["BITNAME"].data<std::string>()=technames[trgbitcount-lumi::N_TRGALGOBIT];
590  //rowbuf["TRGCOUNT"].data<unsigned int>()=*techBitIt;
591  //rowbuf["DEADTIME"].data<unsigned long long>()=*deadIt;
592  //rowbuf["PRESCALE"].data<unsigned int>()=techprescale[trgbitcount-lumi::N_TRGALGOBIT];
593  //trgtable.dataEditor().insertRow(rowbuf);
594  }
595  trgInserter->flush(); //flush every ls
596  ++comittedls;
597  if (comittedls == TRGWBM2DB::COMMITLSINTERVAL) {
598  std::cout << "\t committing in LS chunck " << comittedls << std::endl;
599  delete trgInserter;
600  trgInserter = nullptr;
601  lumisession->transaction().commit();
602  comittedls = 0;
603  std::cout << "\t committed " << std::endl;
604  } else if (trglscount == (totalcmsls - 1)) {
605  std::cout << "\t committing at the end" << std::endl;
606  delete trgInserter;
607  trgInserter = nullptr;
608  lumisession->transaction().commit();
609  std::cout << "\t done" << std::endl;
610  }
611  }
612  } catch (const coral::Exception& er) {
613  lumisession->transaction().rollback();
614  delete lumisession;
615  delete svc;
616  throw er;
617  }
618  //std::cout<<"about to commit "<<std::endl;
619  //lumisession->transaction().commit();
620  delete lumisession;
621  delete svc;
622  return 0;
623  }
std::vector< BITCOUNT > TriggerCountResult_Tech
Definition: TRGWBM2DB.cc:52
static const std::string trgTableName()
Definition: LumiNames.cc:13
std::vector< BITCOUNT > TriggerCountResult_Algo
Definition: TRGWBM2DB.cc:51
std::string m_dest
Definition: DataPipe.h:29
const unsigned int N_TRGTECHBIT
Definition: ConstantDef.h:7
std::string int2str(unsigned int t, unsigned int width)
Definition: TRGWBM2DB.cc:627
std::vector< std::string > TriggerNameResult_Algo
Definition: TRGWBM2DB.cc:43
std::vector< std::string > TriggerNameResult_Tech
Definition: TRGWBM2DB.cc:44
std::string m_source
Definition: DataPipe.h:30
std::vector< DEADCOUNT > TriggerDeadCountResult
Definition: TRGWBM2DB.cc:49
std::vector< unsigned int > PrescaleResult_Tech
Definition: TRGWBM2DB.cc:46
unsigned long long generateNextIDForTable(const std::string &tableName, unsigned int interval=1)
Definition: idDealer.cc:33
static const unsigned int COMMITLSINTERVAL
Definition: TRGWBM2DB.cc:30
std::string m_authpath
Definition: DataPipe.h:31
const unsigned int N_TRGALGOBIT
Definition: ConstantDef.h:6
std::vector< unsigned int > BITCOUNT
Definition: TRGWBM2DB.cc:50
const unsigned int N_TRGBIT
Definition: ConstantDef.h:8
std::vector< unsigned int > PrescaleResult_Algo
Definition: TRGWBM2DB.cc:45

◆ sourceType()

const std::string lumi::TRGWBM2DB::sourceType ( ) const
overridevirtual

Implements lumi::DataPipe.

Definition at line 625 of file TRGWBM2DB.cc.

625 { return "DB"; }

◆ str2int()

unsigned int lumi::TRGWBM2DB::str2int ( const std::string &  s)
private

Definition at line 634 of file TRGWBM2DB.cc.

References Exception, mps_fire::i, alignCSCRings::s, and AlCaHLTBitMon_QueryRunRegistry::string.

634  {
635  std::istringstream myStream(s);
636  unsigned int i;
637  if (myStream >> i) {
638  return i;
639  } else {
640  throw lumi::Exception(std::string("str2int error"), "str2int", "TRGWBM2DB");
641  }
642  }

Member Data Documentation

◆ COMMITLSINTERVAL

const unsigned int lumi::TRGWBM2DB::COMMITLSINTERVAL = 20
static

Definition at line 30 of file TRGWBM2DB.cc.

Referenced by retrieveData().