CMS 3D CMS Logo

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