CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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

virtual const std::string dataType () const override
 
virtual unsigned long long retrieveData (unsigned int runnumber) override
 
virtual const std::string sourceType () const override
 
 TRGWBM2DB (const std::string &dest)
 
virtual ~TRGWBM2DB ()
 
- Public Member Functions inherited from lumi::DataPipe
 DataPipe (const std::string &)
 
std::string getAuthPath () const
 
std::string getMode () const
 
float getNorm () const
 
std::string getSource () const
 
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

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

Definition at line 48 of file TRGWBM2DB.cc.

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

Definition at line 46 of file TRGWBM2DB.cc.

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

Definition at line 43 of file TRGWBM2DB.cc.

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

Definition at line 44 of file TRGWBM2DB.cc.

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

Definition at line 49 of file TRGWBM2DB.cc.

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

Definition at line 50 of file TRGWBM2DB.cc.

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

Definition at line 47 of file TRGWBM2DB.cc.

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

Definition at line 41 of file TRGWBM2DB.cc.

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

Definition at line 42 of file TRGWBM2DB.cc.

Constructor & Destructor Documentation

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

Definition at line 55 of file TRGWBM2DB.cc.

55 :DataPipe(dest){}
DataPipe(const std::string &)
Definition: DataPipe.cc:2
lumi::TRGWBM2DB::~TRGWBM2DB ( )
virtual

Definition at line 636 of file TRGWBM2DB.cc.

636 {}

Member Function Documentation

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

Implements lumi::DataPipe.

Definition at line 613 of file TRGWBM2DB.cc.

613  {
614  return "TRG";
615  }
std::string lumi::TRGWBM2DB::int2str ( unsigned int  t,
unsigned int  width 
)
private

Definition at line 620 of file TRGWBM2DB.cc.

References contentValuesCheck::ss, and edmStreamStallGrapher::t.

Referenced by retrieveData().

620  {
621  std::stringstream ss;
622  ss.width(width);
623  ss.fill('0');
624  ss<<t;
625  return ss.str();
626  }
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 56 of file TRGWBM2DB.cc.

References EnergyCorrector::c, estimatePileup2::cmslsnum, COMMITLSINTERVAL, prof2calltree::count, gather_cfg::cout, edm::hlt::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, python.CommonUtils::svc, python.IdGenerator::transaction, and lumi::LumiNames::trgTableName().

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

Implements lumi::DataPipe.

Definition at line 616 of file TRGWBM2DB.cc.

616  {
617  return "DB";
618  }
unsigned int lumi::TRGWBM2DB::str2int ( const std::string &  s)
private

Definition at line 627 of file TRGWBM2DB.cc.

References edm::hlt::Exception, i, and AlCaHLTBitMon_QueryRunRegistry::string.

627  {
628  std::istringstream myStream(s);
629  unsigned int i;
630  if(myStream>>i){
631  return i;
632  }else{
633  throw lumi::Exception(std::string("str2int error"),"str2int","TRGWBM2DB");
634  }
635  }
int i
Definition: DBlmapReader.cc:9

Member Data Documentation

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

Definition at line 30 of file TRGWBM2DB.cc.

Referenced by retrieveData().