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 void 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  void 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  //
111  TRGScalers2DB::TRGScalers2DB(const std::string& dest):DataPipe(dest){}
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;
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 
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  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  }
667  void
668  TRGScalers2DB::writeTrgData(coral::ISessionProxy* lumisession,
669  unsigned int runnumber,
670  const std::string& source,
671  TRGScalers2DB::TriggerDeadCountResult::iterator deadtimesBeg,TRGScalers2DB::TriggerDeadCountResult::iterator deadtimesEnd,
679  unsigned int commitintv){
680  TRGScalers2DB::TriggerDeadCountResult::iterator deadIt;
681  //unsigned int totalcmsls=deadtimes.size();
682  unsigned int totalcmsls=std::distance(deadtimesBeg,deadtimesEnd);
683  std::cout<<"inserting totalcmsls "<<totalcmsls<<std::endl;
684  std::map< unsigned long long, std::vector<unsigned long long> > idallocationtable;
685  std::cout<<"\t allocating total ids "<<totalcmsls*lumi::N_TRGBIT<<std::endl;
686  lumisession->transaction().start(false);
687  lumi::idDealer idg(lumisession->nominalSchema());
688  unsigned long long trgID = idg.generateNextIDForTable(LumiNames::trgTableName(),totalcmsls*lumi::N_TRGBIT)-totalcmsls*lumi::N_TRGBIT;
689  //lumisession->transaction().commit();
690  unsigned int trglscount=0;
691  for(deadIt=deadtimesBeg;deadIt!=deadtimesEnd;++deadIt,++trglscount){
692  std::vector<unsigned long long> bitvec;
693  bitvec.reserve(lumi::N_TRGBIT);
694  const BITCOUNT& algoinbits=algocounts[trglscount];
695  const BITCOUNT& techinbits=techcounts[trglscount];
696  BITCOUNT::const_iterator algoBitIt;
697  BITCOUNT::const_iterator algoBitBeg=algoinbits.begin();
698  BITCOUNT::const_iterator algoBitEnd=algoinbits.end();
699  for(algoBitIt=algoBitBeg;algoBitIt!=algoBitEnd;++algoBitIt,++trgID){
700  bitvec.push_back(trgID);
701  }
702  BITCOUNT::const_iterator techBitIt;
703  BITCOUNT::const_iterator techBitBeg=techinbits.begin();
704  BITCOUNT::const_iterator techBitEnd=techinbits.end();
705  for(techBitIt=techBitBeg;techBitIt!=techBitEnd;++techBitIt,++trgID){
706  bitvec.push_back(trgID);
707  }
708  idallocationtable.insert(std::make_pair(trglscount,bitvec));
709  }
710  std::cout<<"\t all ids allocated"<<std::endl;
711  coral::AttributeList trgData;
712  trgData.extend<unsigned long long>("TRG_ID");
713  trgData.extend<unsigned int>("RUNNUM");
714  trgData.extend<unsigned int>("CMSLSNUM");
715  trgData.extend<unsigned int>("BITNUM");
716  trgData.extend<std::string>("BITNAME");
717  trgData.extend<unsigned int>("TRGCOUNT");
718  trgData.extend<unsigned long long>("DEADTIME");
719  trgData.extend<float>("DEADFRAC");
720  trgData.extend<unsigned int>("PRESCALE");
721 
722  unsigned long long& trg_id=trgData["TRG_ID"].data<unsigned long long>();
723  unsigned int& trgrunnum=trgData["RUNNUM"].data<unsigned int>();
724  unsigned int& cmslsnum=trgData["CMSLSNUM"].data<unsigned int>();
725  unsigned int& bitnum=trgData["BITNUM"].data<unsigned int>();
726  std::string& bitname=trgData["BITNAME"].data<std::string>();
727  unsigned int& count=trgData["TRGCOUNT"].data<unsigned int>();
728  unsigned long long& deadtime=trgData["DEADTIME"].data<unsigned long long>();
729  float& deadfrac=trgData["DEADFRAC"].data<float>();
730  unsigned int& prescale=trgData["PRESCALE"].data<unsigned int>();
731 
732  trglscount=0;
733  coral::IBulkOperation* trgInserter=0;
734  unsigned int comittedls=0;
735  for(deadIt=deadtimesBeg;deadIt!=deadtimesEnd;++deadIt,++trglscount ){
736  unsigned int cmslscount=trglscount+1;
737  float dfra=deadfracs[trglscount];
738  const BITCOUNT& algoinbits=algocounts[trglscount];
739  const BITCOUNT& techinbits=techcounts[trglscount];
740  unsigned int trgbitcount=0;
741  BITCOUNT::const_iterator algoBitIt;
742  BITCOUNT::const_iterator algoBitBeg=algoinbits.begin();
743  BITCOUNT::const_iterator algoBitEnd=algoinbits.end();
744  if(!lumisession->transaction().isActive()){
745  lumisession->transaction().start(false);
746  coral::ITable& trgtable=lumisession->nominalSchema().tableHandle(LumiNames::trgTableName());
747  trgInserter=trgtable.dataEditor().bulkInsert(trgData,2048);
748  }else{
749  if(deadIt==deadtimesBeg){
750  coral::ITable& trgtable=lumisession->nominalSchema().tableHandle(LumiNames::trgTableName());
751  trgInserter=trgtable.dataEditor().bulkInsert(trgData,2048);
752  }
753  }
754  for(algoBitIt=algoBitBeg;algoBitIt!=algoBitEnd;++algoBitIt,++trgbitcount){
755  trg_id = idallocationtable[trglscount].at(trgbitcount);
756  deadtime=*deadIt;
757  deadfrac=dfra;
758  trgrunnum = runnumber;
759  cmslsnum = cmslscount;
760  bitnum=trgbitcount;
761  bitname=algonames[trgbitcount];
762  count=*algoBitIt;
763  prescale=prescalealgo[cmslscount].at(trgbitcount);
764  //std::cout<<"cmslsnum "<<cmslsnum<<" bitnum "<<bitnum<<" bitname "<<bitname<<" prescale "<< prescale<<" count "<<count<<std::endl;
765  trgInserter->processNextIteration();
766  }
767  BITCOUNT::const_iterator techBitIt;
768  BITCOUNT::const_iterator techBitBeg=techinbits.begin();
769  BITCOUNT::const_iterator techBitEnd=techinbits.end();
770  for(techBitIt=techBitBeg;techBitIt!=techBitEnd;++techBitIt,++trgbitcount){
771  trg_id = idallocationtable[trglscount].at(trgbitcount);
772  deadtime=*deadIt;
773  deadfrac=dfra;
774  trgrunnum = runnumber;
775  cmslsnum = cmslscount;
776  bitnum=trgbitcount;
777  bitname=technames[trgbitcount-lumi::N_TRGALGOBIT];
778  count=*techBitIt;
779  prescale=prescaletech[cmslsnum][trgbitcount-lumi::N_TRGALGOBIT];
780  trgInserter->processNextIteration();
781  }
782  trgInserter->flush();
783  ++comittedls;
784  if(comittedls==commitintv){
785  std::cout<<"\t committing in LS chunck "<<comittedls<<std::endl;
786  delete trgInserter; trgInserter=0;
787  lumisession->transaction().commit();
788  comittedls=0;
789  std::cout<<"\t committed "<<std::endl;
790  }else if( trglscount==( totalcmsls-1) ){
791  std::cout<<"\t committing at the end"<<std::endl;
792  delete trgInserter; trgInserter=0;
793  lumisession->transaction().commit();
794  std::cout<<"\t done"<<std::endl;
795  }
796  }
797  }
798  void
799  TRGScalers2DB::writeTrgDataToSchema2(coral::ISessionProxy* lumisession,
800  unsigned int irunnumber,
801  const std::string& source,
802  TriggerDeadCountResult::iterator deadtimesBeg,
803  TriggerDeadCountResult::iterator deadtimesEnd,
811  unsigned int commitintv){
812  TRGScalers2DB::TriggerDeadCountResult::iterator deadIt;
813  unsigned int totalcmsls=std::distance(deadtimesBeg,deadtimesEnd);
814  std::cout<<"inserting totalcmsls "<<totalcmsls<<std::endl;
815  coral::AttributeList lstrgData;
816  lstrgData.extend<unsigned long long>("DATA_ID");
817  lstrgData.extend<unsigned int>("RUNNUM");
818  lstrgData.extend<unsigned int>("CMSLSNUM");
819  lstrgData.extend<unsigned long long>("DEADTIMECOUNT");
820  lstrgData.extend<unsigned int>("BITZEROCOUNT");
821  lstrgData.extend<unsigned int>("BITZEROPRESCALE");
822  lstrgData.extend<float>("DEADFRAC");
823  lstrgData.extend<coral::Blob>("PRESCALEBLOB");
824  lstrgData.extend<coral::Blob>("TRGCOUNTBLOB");
825 
826  unsigned long long& data_id=lstrgData["DATA_ID"].data<unsigned long long>();
827  unsigned int& trgrunnum=lstrgData["RUNNUM"].data<unsigned int>();
828  unsigned int& cmslsnum=lstrgData["CMSLSNUM"].data<unsigned int>();
829  unsigned long long& deadtime=lstrgData["DEADTIMECOUNT"].data<unsigned long long>();
830  unsigned int& bitzerocount=lstrgData["BITZEROCOUNT"].data<unsigned int>();
831  unsigned int& bitzeroprescale=lstrgData["BITZEROPRESCALE"].data<unsigned int>();
832  float& deadfrac=lstrgData["DEADFRAC"].data<float>();
833  coral::Blob& prescaleblob=lstrgData["PRESCALEBLOB"].data<coral::Blob>();
834  coral::Blob& trgcountblob=lstrgData["TRGCOUNTBLOB"].data<coral::Blob>();
835 
836  unsigned long long branch_id=3;
837  std::string branch_name("DATA");
838  lumi::RevisionDML revisionDML;
840  std::stringstream op;
841  op<<irunnumber;
842  std::string runnumberStr=op.str();
843  lumisession->transaction().start(false);
844  trgrundata.entry_name=runnumberStr;
845  trgrundata.source=source;
846  trgrundata.runnumber=irunnumber;
847  std::string bitnames;
848  TriggerNameResult_Algo::iterator bitnameIt;
849  TriggerNameResult_Algo::iterator bitnameItBeg=algonames.begin();
850  TriggerNameResult_Algo::iterator bitnameItEnd=algonames.end();
851  for (bitnameIt=bitnameItBeg;bitnameIt!=bitnameItEnd;++bitnameIt){
852  if(bitnameIt!=bitnameItBeg){
853  bitnames+=std::string(",");
854  }
855  bitnames+=*bitnameIt;
856  }
857  TriggerNameResult_Tech::iterator techbitnameIt;
858  TriggerNameResult_Tech::iterator techbitnameItBeg=technames.begin();
859  TriggerNameResult_Tech::iterator techbitnameItEnd=technames.end();
860  for(techbitnameIt=techbitnameItBeg;techbitnameIt!=techbitnameItEnd;++techbitnameIt){
861  bitnames+=std::string(",");
862  bitnames+=*techbitnameIt;
863  }
864  std::cout<<"\tbitnames "<<bitnames<<std::endl;
865  trgrundata.bitzeroname=technames[4];
866  trgrundata.bitnames=bitnames;
867  trgrundata.entry_id=revisionDML.getEntryInBranchByName(lumisession->nominalSchema(),lumi::LumiNames::trgdataTableName(),runnumberStr,branch_name);
868  if(trgrundata.entry_id==0){
869  revisionDML.bookNewEntry(lumisession->nominalSchema(),LumiNames::trgdataTableName(),trgrundata);
870  std::cout<<"trgrundata revision_id "<<trgrundata.revision_id<<" entry_id "<<trgrundata.entry_id<<" data_id "<<trgrundata.data_id<<std::endl;
871  revisionDML.addEntry(lumisession->nominalSchema(),LumiNames::trgdataTableName(),trgrundata,branch_id,branch_name);
872  }else{
873  revisionDML.bookNewRevision(lumisession->nominalSchema(),LumiNames::trgdataTableName(),trgrundata);
874  std::cout<<"trgrundata revision_id "<<trgrundata.revision_id<<" entry_id "<<trgrundata.entry_id<<" data_id "<<trgrundata.data_id<<std::endl;
875  revisionDML.addRevision(lumisession->nominalSchema(),LumiNames::trgdataTableName(),trgrundata,branch_id,branch_name);
876  }
877  std::cout<<"inserting trgrundata "<<std::endl;
878  revisionDML.insertTrgRunData(lumisession->nominalSchema(),trgrundata);
879  std::cout<<"inserting lstrg data"<<std::endl;
880 
881  unsigned int trglscount=0;
882  // trglscount=0;
883  coral::IBulkOperation* lstrgInserter=0;
884  unsigned int comittedls=0;
885  for(deadIt=deadtimesBeg;deadIt!=deadtimesEnd;++deadIt,++trglscount ){
886  unsigned int cmslscount=trglscount+1;
887  if(!lumisession->transaction().isActive()){
888  lumisession->transaction().start(false);
889  coral::ITable& lstrgtable=lumisession->nominalSchema().tableHandle(LumiNames::lstrgTableName());
890  lstrgInserter=lstrgtable.dataEditor().bulkInsert(lstrgData,2048);
891  }else{
892  if(deadIt==deadtimesBeg){
893  coral::ITable& lstrgtable=lumisession->nominalSchema().tableHandle(LumiNames::lstrgTableName());
894  lstrgInserter=lstrgtable.dataEditor().bulkInsert(lstrgData,2048);
895  }
896  }
897  data_id = trgrundata.data_id;
898  trgrunnum = irunnumber;
899  cmslsnum = cmslscount;
900  deadtime = *deadIt;
901  deadfrac = deadfracs[trglscount];
902  //bitzerocount = algocounts[trglscount][0];//use algobit_0
903  //bitzeroprescale = prescalealgo[cmslsnum][0];
904  bitzerocount=techcounts[trglscount][4]; //use techbit_4
905  bitzeroprescale=prescaletech[cmslsnum][4];
906  std::vector<unsigned int> fullprescales;
907  fullprescales.reserve(prescalealgo[cmslsnum].size()+prescaletech[cmslsnum].size());
908  fullprescales.insert(fullprescales.end(),prescalealgo[cmslsnum].begin(),prescalealgo[cmslsnum].end());
909  fullprescales.insert(fullprescales.end(),prescaletech[cmslsnum].begin(),prescaletech[cmslsnum].end());
910 
911  prescaleblob.resize(sizeof(unsigned int)*(fullprescales.size()));
912  void* prescaleblob_StartAddress = prescaleblob.startingAddress();
913  std::memmove(prescaleblob_StartAddress,&fullprescales[0],sizeof(unsigned int)*(fullprescales.size()));
914 
915  std::vector<unsigned int> fullcounts;
916  fullcounts.reserve(algocounts[trglscount].size()+techcounts[trglscount].size());
917  fullcounts.insert(fullcounts.end(),algocounts[trglscount].begin(),algocounts[trglscount].end());
918  fullcounts.insert(fullcounts.end(),techcounts[trglscount].begin(),techcounts[trglscount].end());
919  trgcountblob.resize(sizeof(unsigned int)*(fullcounts.size()));
920  void* trgcountblob_StartAddress = trgcountblob.startingAddress();
921  std::memmove(trgcountblob_StartAddress,&fullcounts[0],sizeof(unsigned int)*(fullcounts.size()));
922 
923  lstrgInserter->processNextIteration();
924  lstrgInserter->flush();
925  ++comittedls;
926  if(comittedls==commitintv){
927  std::cout<<"\t committing in LS chunck "<<comittedls<<std::endl;
928  delete lstrgInserter; lstrgInserter=0;
929  lumisession->transaction().commit();
930  comittedls=0;
931  std::cout<<"\t committed "<<std::endl;
932  }else if( trglscount==( totalcmsls-1) ){
933  std::cout<<"\t committing at the end"<<std::endl;
934  delete lstrgInserter; lstrgInserter=0;
935  lumisession->transaction().commit();
936  std::cout<<"\t done"<<std::endl;
937  }
938  }
939 
940 
941  }
942  const std::string TRGScalers2DB::dataType() const{
943  return "TRG";
944  }
945  const std::string TRGScalers2DB::sourceType() const{
946  return "DB";
947  }
948  //utilities
949  std::string TRGScalers2DB::int2str(unsigned int t, unsigned int width){
950  std::stringstream ss;
951  ss.width(width);
952  ss.fill('0');
953  ss<<t;
954  return ss.str();
955  }
956  unsigned int TRGScalers2DB::str2int(const std::string& s){
957  std::istringstream myStream(s);
958  unsigned int i;
959  if(myStream>>i){
960  return i;
961  }else{
962  throw lumi::Exception(std::string("str2int error"),"str2int","TRGScalers2DB");
963  }
964  }
966 }//ns lumi
969 #endif
int i
Definition: DBlmapReader.cc:9
std::vector< DEADFRAC > TriggerDeadFracResult
static const std::string trgTableName()
Definition: LumiNames.cc:14
static const std::string trgdataTableName()
Definition: LumiNames.cc:50
static const unsigned int COMMITLSTRGINTERVAL
void addEntry(coral::ISchema &schema, const std::string &datatableName, const Entry &entry, unsigned long long branch_id, const std::string &branchname)
Definition: RevisionDML.cc:61
std::vector< BITCOUNT > TriggerCountResult_Algo
tuple lumi
Definition: fjr2json.py:35
virtual void retrieveData(unsigned int runnumber)
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:53
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:22
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:14
std::map< unsigned int, std::vector< unsigned int > > PrescaleResult_Tech
list trgrundata
Definition: dataDML.py:2358
unsigned long long revision_id
Definition: RevisionDML.h:20
std::vector< DEADCOUNT > TriggerDeadCountResult
void insertTrgRunData(coral::ISchema &schema, const TrgEntry &trgentry)
Definition: RevisionDML.cc:144
unsigned long long entry_id
Definition: RevisionDML.h:21
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:43
void 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)
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:99
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:53