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::TRG2DB Class Reference
Inheritance diagram for lumi::TRG2DB:
lumi::DataPipe

Public Member Functions

virtual const std::string dataType () const
 
virtual void retrieveData (unsigned int runnumber)
 
virtual const std::string sourceType () const
 
 TRG2DB (const std::string &dest)
 
virtual ~TRG2DB ()
 
- Public Member Functions inherited from lumi::DataPipe
 DataPipe (const std::string &)
 
std::string getAuthPath () const
 
std::string getMode () const
 
std::string getSource () const
 
void setAuthPath (const std::string &authpath)
 
void setMode (const std::string &mode)
 
void setSource (const std::string &source)
 
virtual ~DataPipe ()
 

Static Public Attributes

static const unsigned int COMMITLSINTERVAL =150
 

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
 
std::string m_source
 

Detailed Description

Definition at line 28 of file TRG2DB.cc.

Member Typedef Documentation

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

Definition at line 48 of file TRG2DB.cc.

typedef unsigned long long lumi::TRG2DB::DEADCOUNT
private

Definition at line 46 of file TRG2DB.cc.

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

Definition at line 43 of file TRG2DB.cc.

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

Definition at line 44 of file TRG2DB.cc.

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

Definition at line 49 of file TRG2DB.cc.

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

Definition at line 50 of file TRG2DB.cc.

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

Definition at line 47 of file TRG2DB.cc.

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

Definition at line 41 of file TRG2DB.cc.

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

Definition at line 42 of file TRG2DB.cc.

Constructor & Destructor Documentation

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

Definition at line 55 of file TRG2DB.cc.

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

Definition at line 598 of file TRG2DB.cc.

598 {}

Member Function Documentation

const std::string lumi::TRG2DB::dataType ( ) const
virtual

Implements lumi::DataPipe.

Definition at line 575 of file TRG2DB.cc.

575  {
576  return "TRG";
577  }
std::string lumi::TRG2DB::int2str ( unsigned int  t,
unsigned int  width 
)
private

Definition at line 582 of file TRG2DB.cc.

References matplotRender::t.

Referenced by retrieveData().

582  {
583  std::stringstream ss;
584  ss.width(width);
585  ss.fill('0');
586  ss<<t;
587  return ss.str();
588  }
void lumi::TRG2DB::retrieveData ( unsigned int  runnumber)
virtual

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_gt_mon

Part II query tables in schema cms_gt

Implements lumi::DataPipe.

Definition at line 56 of file TRG2DB.cc.

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

Implements lumi::DataPipe.

Definition at line 578 of file TRG2DB.cc.

578  {
579  return "DB";
580  }
unsigned int lumi::TRG2DB::str2int ( const std::string &  s)
private

Definition at line 589 of file TRG2DB.cc.

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

589  {
590  std::istringstream myStream(s);
591  unsigned int i;
592  if(myStream>>i){
593  return i;
594  }else{
595  throw lumi::Exception(std::string("str2int error"),"str2int","TRG2DB");
596  }
597  }
int i
Definition: DBlmapReader.cc:9
string s
Definition: asciidump.py:422

Member Data Documentation

const unsigned int lumi::TRG2DB::COMMITLSINTERVAL =150
static

Definition at line 30 of file TRG2DB.cc.

Referenced by retrieveData().