CMS 3D CMS Logo

HLTV32DB.cc
Go to the documentation of this file.
1 #ifndef RecoLuminosity_LumiProducer_HLTV32DB_H
2 #define RecoLuminosity_LumiProducer_HLTV32DB_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"
19 
27 #include <iostream>
28 #include <map>
29 #include <vector>
30 #include <string>
31 #include <cstring>
33 namespace lumi{
34  class HLTV32DB : public DataPipe{
35 
36  public:
37  const static unsigned int COMMITINTERVAL=200; //commit interval in LS,totalrow=nls*(~200)
38  const static unsigned int COMMITLSINTERVAL=500; //commit interval in LS
39 
40  explicit HLTV32DB(const std::string& dest);
41  unsigned long long retrieveData( unsigned int ) override;
42  const std::string dataType() const override;
43  const std::string sourceType() const override;
44  ~HLTV32DB() override;
45  struct hltinfo{
46  unsigned int cmsluminr;
48  unsigned int hltinput;
49  unsigned int hltaccept;
50  unsigned int prescale;
51  };
52  typedef std::map< unsigned int, std::string , std::less<unsigned int> > HltPathMap; //order by hltpathid
53  typedef std::vector< std::map<unsigned int,HLTV32DB::hltinfo,std::less<unsigned int> > > HltResult;
54  void writeHltData(coral::ISessionProxy* lumisession,
55  unsigned int irunnumber,
56  const std::string& source,
57  unsigned int npath,
58  HltResult::iterator hltBeg,
59  HltResult::iterator hltEnd,
60  unsigned int commitintv);
61  unsigned long long writeHltDataToSchema2(coral::ISessionProxy* lumisession,
62  unsigned int irunnumber,
63  const std::string& source,
64  unsigned int npath,
65  HltResult::iterator hltBeg,
66  HltResult::iterator hltEnd,
67  HltPathMap& hltpathmap,
68  unsigned int commitintv);
69  };//cl HLTV32DB
70  //
71  //implementation
72  //
74  unsigned long long HLTV32DB::retrieveData( unsigned int runnumber){
75  std::string confdbschema("CMS_HLT");
76  std::string hltschema("CMS_RUNINFO");
77  std::string gtschema("CMS_GT_MON");
78  std::string confdbpathtabname("PATHS");
79  std::string triggerpathtabname("HLT_SUPERVISOR_TRIGGERPATHS");
80  std::string maptabname("HLT_SUPERVISOR_SCALAR_MAP_V2");
81  std::string gttabname("LUMI_SECTIONS");
82  coral::ConnectionService* svc=new coral::ConnectionService;
83  lumi::DBConfig dbconf(*svc);
84  if(!m_authpath.empty()){
86  }
91  std::string::size_type cutpos=m_source.find(';');
92  std::string dbsource=m_source;
93  std::string csvsource("");
94  if(cutpos!=std::string::npos){
95  dbsource=m_source.substr(0,cutpos);
96  csvsource=m_source.substr(cutpos+1);
97  }
98  //std::cout<<"dbsource: "<<dbsource<<" , csvsource: "<<csvsource<<std::endl;
99  coral::ISessionProxy* srcsession=svc->connect(dbsource, coral::ReadOnly);
100  coral::ITypeConverter& tpc=srcsession->typeConverter();
101  tpc.setCppTypeForSqlType("unsigned int","NUMBER(11)");
102  srcsession->transaction().start(true);
103  coral::ISchema& gtSchemaHandle=srcsession->schema(gtschema);
104  coral::ISchema& hltSchemaHandle=srcsession->schema(hltschema);
105  coral::ISchema& confdbSchemaHandle=srcsession->schema(confdbschema);
106  if( !hltSchemaHandle.existsTable(triggerpathtabname) || !hltSchemaHandle.existsTable(maptabname) ){
107  throw lumi::Exception("missing hlt tables" ,"retrieveData","HLTV32DB");
108  }
110  //this is trg lumi section number
111  std::vector< std::pair<unsigned int,unsigned int> > psindexmap;
112  coral::AttributeList psindexVariableList;
113  psindexVariableList.extend("runnumber",typeid(unsigned int));
114  psindexVariableList["runnumber"].data<unsigned int>()=runnumber;
115  coral::IQuery* qPsindex=gtSchemaHandle.tableHandle(gttabname).newQuery();
116  coral::AttributeList psindexOutput;
117  psindexOutput.extend("PRESCALE_INDEX",typeid(unsigned int));
118  psindexOutput.extend("LUMI_SECTION",typeid(unsigned int));
119  qPsindex->addToOutputList("PRESCALE_INDEX");
120  qPsindex->addToOutputList("LUMI_SECTION");
121  qPsindex->setCondition("RUN_NUMBER=:runnumber",psindexVariableList);
122  qPsindex->defineOutput(psindexOutput);
123  coral::ICursor& psindexCursor=qPsindex->execute();
124  unsigned int lsmin=4294967295;
125  unsigned int lsmax=0;
126  while( psindexCursor.next() ){
127  if( !psindexCursor.currentRow()["PRESCALE_INDEX"].isNull() ){
128  unsigned int psindx=psindexCursor.currentRow()["PRESCALE_INDEX"].data<unsigned int>();
129  unsigned int pslsnum=psindexCursor.currentRow()["LUMI_SECTION"].data<unsigned int>();
130  if(pslsnum>lsmax){
131  lsmax=pslsnum;
132  }
133  if(pslsnum<lsmin){
134  lsmin=pslsnum;
135  }
136  psindexmap.push_back(std::make_pair(pslsnum,psindx));
137  }
138  }
139  delete qPsindex;
140  if(psindexmap.empty()){
141  srcsession->transaction().commit();
142  delete srcsession;
143  throw lumi::Exception("no psindex data found","retrieveData","HLTV32DB");
144  }
145 
148  HltPathMap hltpathmap;
149  coral::AttributeList bindVariableList;
150  bindVariableList.extend("runnumber",typeid(unsigned int));
151  bindVariableList["runnumber"].data<unsigned int>()=runnumber;
152  coral::IQuery* q1=hltSchemaHandle.tableHandle(triggerpathtabname).newQuery();
153  coral::AttributeList hltpathid;
154  hltpathid.extend("hltpathid",typeid(unsigned int));
155  q1->addToOutputList("distinct(PATHID)","hltpathid");
156  q1->setCondition("RUNNUMBER=:runnumber",bindVariableList);
157  q1->defineOutput(hltpathid);
158  coral::ICursor& c=q1->execute();
159  unsigned int npc=0;
160  while( c.next() ){
161  npc++;
162  unsigned int hid=c.currentRow()["hltpathid"].data<unsigned int>();
163  hltpathmap.insert(std::make_pair(hid,""));
164  }
165  delete q1;
168  HltPathMap::iterator mpit;
169  HltPathMap::iterator mpitBeg=hltpathmap.begin();
170  HltPathMap::iterator mpitEnd=hltpathmap.end();
171  for( mpit=mpitBeg;mpit!=mpitEnd;++mpit){//loop over paths
172  coral::IQuery* mq=confdbSchemaHandle.newQuery();
173  coral::AttributeList mqbindVariableList;
174  mqbindVariableList.extend("pathid",typeid(unsigned int));
175  mqbindVariableList["pathid"].data<unsigned int>()=mpit->first;
176  mq->addToTableList(confdbpathtabname);
177  mq->addToOutputList("NAME","hltpathname");
178  mq->setCondition("PATHID=:pathid",mqbindVariableList);
179  coral::ICursor& mqcursor=mq->execute();
180  while( mqcursor.next() ){
181  std::string pathname=mqcursor.currentRow()["hltpathname"].data<std::string>();
182  hltpathmap[mpit->first]=pathname;
183  }
184  delete mq;
185  }
186 
188  HltResult hltresult;
189  unsigned int nls=lsmax-lsmin+1;
190  //std::cout<<"nls "<<nls<<std::endl;
191  hltresult.reserve(nls);//
192  //fix all size
193  for(unsigned int i=lsmin;i<=lsmax;++i){
194  if (i==0) continue; //skip ls=0
195  std::map<unsigned int, HLTV32DB::hltinfo> allpaths;
196  HltPathMap::iterator aIt;
197  HltPathMap::iterator aItBeg=hltpathmap.begin();
198  HltPathMap::iterator aItEnd=hltpathmap.end();
199  for(aIt=aItBeg;aIt!=aItEnd;++aIt){
201  ct.cmsluminr=i;
202  ct.pathname=aIt->second;
203  ct.hltinput=0;
204  ct.hltaccept=0;
205  ct.prescale=0;
206  allpaths.insert(std::make_pair(aIt->first,ct));
207  }
208  hltresult.push_back(allpaths);
209  }
210 
211  bool lscountfromzero=false;
212 
214  for( std::vector< std::pair<unsigned int,unsigned int> >::iterator it=psindexmap.begin();it!=psindexmap.end();++it ){
215  //loop over ls
216  unsigned int lsnum=it->first;
217  unsigned int psindex=it->second;
218  coral::AttributeList hltdataVariableList;
219  hltdataVariableList.extend("runnumber",typeid(unsigned int));
220  hltdataVariableList.extend("lsnum",typeid(unsigned int));
221  hltdataVariableList.extend("psindex",typeid(unsigned int));
222  hltdataVariableList["runnumber"].data<unsigned int>()=runnumber;
223  hltdataVariableList["lsnum"].data<unsigned int>()=lsnum;
224  hltdataVariableList["psindex"].data<unsigned int>()=psindex;
225  coral::IQuery* qHltData=hltSchemaHandle.newQuery();
226  qHltData->addToTableList(triggerpathtabname,"t");
227  qHltData->addToTableList(maptabname,"m");
228  coral::AttributeList hltdataOutput;
229  hltdataOutput.extend("L1PASS",typeid(unsigned int));
230  hltdataOutput.extend("PACCEPT",typeid(unsigned int));
231  hltdataOutput.extend("PATHID",typeid(unsigned int));
232  hltdataOutput.extend("PSVALUE",typeid(unsigned int));
233 
234  qHltData->addToOutputList("t.L1PASS","l1pass");
235  qHltData->addToOutputList("t.PACCEPT","paccept");
236  qHltData->addToOutputList("t.PATHID","pathid");
237  qHltData->addToOutputList("m.PSVALUE","psvalue");
238  qHltData->setCondition("m.PATHID=t.PATHID and m.RUNNUMBER=t.RUNNUMBER and m.RUNNUMBER=:runnumber AND m.PSINDEX=:psindex AND t.LSNUMBER=:lsnum",hltdataVariableList);
239  qHltData->defineOutput(hltdataOutput);
240  coral::ICursor& hltdataCursor=qHltData->execute();
241  while( hltdataCursor.next() ){
242  const coral::AttributeList& row=hltdataCursor.currentRow();
243  if (lsnum==0){
244  lscountfromzero=true;
245  if(lscountfromzero) {
246  std::cout<<"hlt ls count from 0 , we skip/dodge/parry it!"<<std::endl;
247  }
248  }else{
249  unsigned int pathid=row["PATHID"].data<unsigned int>();
250  std::map<unsigned int,hltinfo>& allpathinfo=hltresult.at(lsnum-1);
251  hltinfo& pathcontent=allpathinfo[pathid];
252  pathcontent.hltinput=row["L1PASS"].data<unsigned int>();
253  pathcontent.hltaccept=row["PACCEPT"].data<unsigned int>();
254  pathcontent.prescale=row["PSVALUE"].data<unsigned int>();
255  }
256  }
257  delete qHltData;
258  }
259  srcsession->transaction().commit();
260  delete srcsession;
261  //
262  // Write into DB
263  //
264  unsigned int npath=hltpathmap.size();
265  coral::ISessionProxy* destsession=svc->connect(m_dest,coral::Update);
266  coral::ITypeConverter& lumitpc=destsession->typeConverter();
267  lumitpc.setCppTypeForSqlType("unsigned int","NUMBER(7)");
268  lumitpc.setCppTypeForSqlType("unsigned int","NUMBER(10)");
269  lumitpc.setCppTypeForSqlType("unsigned long long","NUMBER(20)");
270 
271  //for(hltIt=hltItBeg;hltIt!=hltItEnd;++hltIt){
272  // std::map<unsigned int,HLTV32DB::hltinfo>::iterator pathIt;
273  // std::map<unsigned int,HLTV32DB::hltinfo>::iterator pathItBeg=hltIt->begin();
274  // std::map<unsigned int,HLTV32DB::hltinfo>::iterator pathItEnd=hltIt->end();
275  // for(pathIt=pathItBeg;pathIt!=pathItEnd;++pathIt){
276  // std::cout<<"cmslsnr "<<pathIt->second.cmsluminr<<" "<<pathIt->second.pathname<<" "<<pathIt->second.hltinput<<" "<<pathIt->second.hltaccept<<" "<<pathIt->second.prescale<<std::endl;
277  // }
278  //}
279  unsigned int totalcmsls=hltresult.size();
280  std::cout<<"inserting totalhltls "<<totalcmsls<<" total path "<<npath<<std::endl;
281  //HltResult::iterator hltItBeg=hltresult.begin();
282  //HltResult::iterator hltItEnd=hltresult.end();
283  unsigned long long hltdataid=0;
284  try{
285  if(m_mode=="loadoldschema"){
286  std::cout<<"writing hlt data to old hlt table"<<std::endl;
287  writeHltData(destsession,runnumber,dbsource,npath,hltresult.begin(),hltresult.end(),COMMITINTERVAL);
288  std::cout<<"done"<<std::endl;
289  }
290  std::cout<<"writing hlt data to new lshlt table"<<std::endl;
291  //std::cout<<"npath "<<npath<<std::endl;
306  hltdataid=writeHltDataToSchema2(destsession,runnumber,dbsource,npath,hltresult.begin(),hltresult.end(), hltpathmap,COMMITLSINTERVAL);
307  std::cout<<"done"<<std::endl;
308  delete destsession;
309  delete svc;
310  }catch( const coral::Exception& er){
311  std::cout<<"database problem "<<er.what()<<std::endl;
312  destsession->transaction().rollback();
313  delete destsession;
314  delete svc;
315  throw er;
316  }
317  return hltdataid;
318  }
319  void
320  HLTV32DB::writeHltData(coral::ISessionProxy* lumisession,
321  unsigned int irunnumber,
322  const std::string& source,
323  unsigned int npath,
324  HltResult::iterator hltItBeg,
325  HltResult::iterator hltItEnd,
326  unsigned int commitintv){
327  std::map< unsigned long long, std::vector<unsigned long long> > idallocationtable;
328  unsigned int hltlscount=0;
329  unsigned int totalcmsls=std::distance(hltItBeg,hltItEnd);
330  std::cout<<"\t allocating total ids "<<totalcmsls*npath<<std::endl;
331  lumisession->transaction().start(false);
332  lumi::idDealer idg(lumisession->nominalSchema());
333  unsigned long long hltID = idg.generateNextIDForTable(LumiNames::hltTableName(),totalcmsls*npath)-totalcmsls*npath;
334  for(HltResult::iterator hltIt=hltItBeg;hltIt!=hltItEnd;++hltIt,++hltlscount){
335  std::vector<unsigned long long> pathvec;
336  pathvec.reserve(npath);
337  for(unsigned int i=0;i<npath;++i,++hltID){
338  pathvec.push_back(hltID);
339  }
340  idallocationtable.insert(std::make_pair(hltlscount,pathvec));
341  }
342  std::cout<<"\t all ids allocated"<<std::endl;
343 
344  coral::AttributeList hltData;
345  hltData.extend("HLT_ID",typeid(unsigned long long));
346  hltData.extend("RUNNUM",typeid(unsigned int));
347  hltData.extend("CMSLSNUM",typeid(unsigned int));
348  hltData.extend("PATHNAME",typeid(std::string));
349  hltData.extend("INPUTCOUNT",typeid(unsigned int));
350  hltData.extend("ACCEPTCOUNT",typeid(unsigned int));
351  hltData.extend("PRESCALE",typeid(unsigned int));
352 
353  //loop over lumi LS
354  unsigned long long& hlt_id=hltData["HLT_ID"].data<unsigned long long>();
355  unsigned int& hltrunnum=hltData["RUNNUM"].data<unsigned int>();
356  unsigned int& cmslsnum=hltData["CMSLSNUM"].data<unsigned int>();
357  std::string& pathname=hltData["PATHNAME"].data<std::string>();
358  unsigned int& inputcount=hltData["INPUTCOUNT"].data<unsigned int>();
359  unsigned int& acceptcount=hltData["ACCEPTCOUNT"].data<unsigned int>();
360  unsigned int& prescale=hltData["PRESCALE"].data<unsigned int>();
361  hltlscount=0;
362  coral::IBulkOperation* hltInserter=nullptr;
363  unsigned int comittedls=0;
364  for(HltResult::iterator hltIt=hltItBeg;hltIt!=hltItEnd;++hltIt,++hltlscount){
365  std::map<unsigned int,HLTV32DB::hltinfo>::const_iterator pathIt;
366  std::map<unsigned int,HLTV32DB::hltinfo>::const_iterator pathBeg=hltIt->begin();
367  std::map<unsigned int,HLTV32DB::hltinfo>::const_iterator pathEnd=hltIt->end();
368  if(!lumisession->transaction().isActive()){
369  lumisession->transaction().start(false);
370  coral::ITable& hlttable=lumisession->nominalSchema().tableHandle(LumiNames::hltTableName());
371  hltInserter=hlttable.dataEditor().bulkInsert(hltData,npath);
372  }else{
373  if(hltIt==hltItBeg){
374  coral::ITable& hlttable=lumisession->nominalSchema().tableHandle(LumiNames::hltTableName());
375  hltInserter=hlttable.dataEditor().bulkInsert(hltData,npath);
376  }
377  }
378  unsigned int hltpathcount=0;
379  for(pathIt=pathBeg;pathIt!=pathEnd;++pathIt,++hltpathcount){
380  hlt_id = idallocationtable[hltlscount].at(hltpathcount);
381  hltrunnum = irunnumber;
382  cmslsnum = pathIt->second.cmsluminr;
383  pathname = pathIt->second.pathname;
384  inputcount = pathIt->second.hltinput;
385  acceptcount = pathIt->second.hltaccept;
386  prescale = pathIt->second.prescale;
387  hltInserter->processNextIteration();
388  }
389  hltInserter->flush();
390  ++comittedls;
391  if(comittedls==commitintv){
392  std::cout<<"\t committing in LS chunck "<<comittedls<<std::endl;
393  delete hltInserter; hltInserter=nullptr;
394  lumisession->transaction().commit();
395  comittedls=0;
396  std::cout<<"\t committed "<<std::endl;
397  }else if( hltlscount==(totalcmsls-1) ){
398  std::cout<<"\t committing at the end"<<std::endl;
399  delete hltInserter; hltInserter=nullptr;
400  lumisession->transaction().commit();
401  std::cout<<"\t done"<<std::endl;
402  }
403  }
404  }
405  unsigned long long
406  HLTV32DB::writeHltDataToSchema2(coral::ISessionProxy* lumisession,
407  unsigned int irunnumber,
408  const std::string& source,
409  unsigned int npath,
410  HltResult::iterator hltItBeg,
411  HltResult::iterator hltItEnd,
412  HltPathMap& hltpathmap,
413  unsigned int commitintv){
414  HltResult::iterator hltIt;
415  unsigned int totalcmsls=std::distance(hltItBeg,hltItEnd);
416  std::cout<<"inserting totalcmsls "<<totalcmsls<<std::endl;
417  coral::AttributeList lshltData;
418  lshltData.extend("DATA_ID",typeid(unsigned long long));
419  lshltData.extend("RUNNUM",typeid(unsigned int));
420  lshltData.extend("CMSLSNUM",typeid(unsigned int));
421  lshltData.extend("PRESCALEBLOB",typeid(coral::Blob));
422  lshltData.extend("HLTCOUNTBLOB",typeid(coral::Blob));
423  lshltData.extend("HLTACCEPTBLOB",typeid(coral::Blob));
424  unsigned long long& data_id=lshltData["DATA_ID"].data<unsigned long long>();
425  unsigned int& hltrunnum=lshltData["RUNNUM"].data<unsigned int>();
426  unsigned int& cmslsnum=lshltData["CMSLSNUM"].data<unsigned int>();
427  coral::Blob& prescaleblob=lshltData["PRESCALEBLOB"].data<coral::Blob>();
428  coral::Blob& hltcountblob=lshltData["HLTCOUNTBLOB"].data<coral::Blob>();
429  coral::Blob& hltacceptblob=lshltData["HLTACCEPTBLOB"].data<coral::Blob>();
430 
431  unsigned long long branch_id=3;
432  std::string branch_name("DATA");
435  std::stringstream op;
436  op<<irunnumber;
437  std::string runnumberStr=op.str();
438  lumisession->transaction().start(false);
439  hltrundata.entry_name=runnumberStr;
440  hltrundata.source=source;
441  hltrundata.runnumber=irunnumber;
442  hltrundata.npath=npath;
444  HltPathMap::iterator hltpathmapIt;
445  HltPathMap::iterator hltpathmapItBeg=hltpathmap.begin();
446  HltPathMap::iterator hltpathmapItEnd=hltpathmap.end();
447  for(hltpathmapIt=hltpathmapItBeg;hltpathmapIt!=hltpathmapItEnd;++hltpathmapIt){
448  if(hltpathmapIt!=hltpathmapItBeg){
449  pathnames+=std::string(",");
450  }
451  pathnames+=hltpathmapIt->second;
452  }
453  std::cout<<"\tpathnames "<<pathnames<<std::endl;
454  hltrundata.pathnames=pathnames;
455  hltrundata.entry_id=revisionDML.getEntryInBranchByName(lumisession->nominalSchema(),lumi::LumiNames::hltdataTableName(),runnumberStr,branch_name);
456  if(hltrundata.entry_id==0){
457  revisionDML.bookNewEntry(lumisession->nominalSchema(),LumiNames::hltdataTableName(),hltrundata);
458  std::cout<<"hltrundata revision_id "<<hltrundata.revision_id<<" entry_id "<<hltrundata.entry_id<<" data_id "<<hltrundata.data_id<<std::endl;
459  revisionDML.addEntry(lumisession->nominalSchema(),LumiNames::hltdataTableName(),hltrundata,branch_id,branch_name);
460  }else{
461  revisionDML.bookNewRevision(lumisession->nominalSchema(),LumiNames::hltdataTableName(),hltrundata);
462  std::cout<<"hltrundata revision_id "<<hltrundata.revision_id<<" entry_id "<<hltrundata.entry_id<<" data_id "<<hltrundata.data_id<<std::endl;
463  revisionDML.addRevision(lumisession->nominalSchema(),LumiNames::hltdataTableName(),hltrundata,branch_id,branch_name);
464  }
465  std::cout<<"inserting hltrundata"<<std::endl;
466  revisionDML.insertHltRunData(lumisession->nominalSchema(),hltrundata);
467  std::cout<<"inserting lshlt data"<<std::endl;
468 
469  unsigned int hltlscount=0;
470  coral::IBulkOperation* hltInserter=nullptr;
471  unsigned int comittedls=0;
472  for(HltResult::iterator hltIt=hltItBeg;hltIt!=hltItEnd;++hltIt,++hltlscount){
473  unsigned int cmslscount=hltlscount+1;
474  std::map<unsigned int,HLTV32DB::hltinfo,std::less<unsigned int> >::const_iterator pathIt;
475  std::map<unsigned int,HLTV32DB::hltinfo,std::less<unsigned int> >::const_iterator pathBeg=hltIt->begin();
476  std::map<unsigned int,HLTV32DB::hltinfo,std::less<unsigned int> >::const_iterator pathEnd=hltIt->end();
477  if(!lumisession->transaction().isActive()){
478  lumisession->transaction().start(false);
479  coral::ITable& hlttable=lumisession->nominalSchema().tableHandle(LumiNames::lshltTableName());
480  hltInserter=hlttable.dataEditor().bulkInsert(lshltData,npath);
481  }else{
482  if(hltIt==hltItBeg){
483  coral::ITable& hlttable=lumisession->nominalSchema().tableHandle(LumiNames::lshltTableName());
484  hltInserter=hlttable.dataEditor().bulkInsert(lshltData,npath);
485  }
486  }
487  data_id = hltrundata.data_id;
488  hltrunnum = irunnumber;
489  cmslsnum = cmslscount;
490  std::vector<unsigned int> prescales; prescales.reserve(npath);
491  std::vector<unsigned int> hltcounts; hltcounts.reserve(npath);
492  std::vector<unsigned int> hltaccepts; hltaccepts.reserve(npath);
493 
494  for(pathIt=pathBeg;pathIt!=pathEnd;++pathIt){
495  unsigned int hltcount=pathIt->second.hltinput;
496  //std::cout<<"hltcount "<<hltcount<<std::endl;
497  hltcounts.push_back(hltcount);
498  unsigned int hltaccept=pathIt->second.hltaccept;
499  //std::cout<<"hltaccept "<<hltaccept<<std::endl;
500  hltaccepts.push_back(hltaccept);
501  unsigned int prescale=pathIt->second.prescale;
502  //std::cout<<"prescale "<<prescale<<std::endl;
503  prescales.push_back(prescale);
504  }
505  prescaleblob.resize(sizeof(unsigned int)*npath);
506  void* prescaleblob_StartAddress = prescaleblob.startingAddress();
507  std::memmove(prescaleblob_StartAddress,&prescales[0],sizeof(unsigned int)*npath);
508  hltcountblob.resize(sizeof(unsigned int)*npath);
509  void* hltcountblob_StartAddress = hltcountblob.startingAddress();
510  std::memmove(hltcountblob_StartAddress,&hltcounts[0],sizeof(unsigned int)*npath);
511  hltacceptblob.resize(sizeof(unsigned int)*npath);
512  void* hltacceptblob_StartAddress = hltacceptblob.startingAddress();
513  std::memmove(hltacceptblob_StartAddress,&hltaccepts[0],sizeof(unsigned int)*npath);
514 
515  hltInserter->processNextIteration();
516  hltInserter->flush();
517  ++comittedls;
518  if(comittedls==commitintv){
519  std::cout<<"\t committing in LS chunck "<<comittedls<<std::endl;
520  delete hltInserter; hltInserter=nullptr;
521  lumisession->transaction().commit();
522  comittedls=0;
523  std::cout<<"\t committed "<<std::endl;
524  }else if( hltlscount==(totalcmsls-1) ){
525  std::cout<<"\t committing at the end"<<std::endl;
526  delete hltInserter; hltInserter=nullptr;
527  lumisession->transaction().commit();
528  std::cout<<"\t done"<<std::endl;
529  }
530  }
531  return hltrundata.data_id;
532  }
534  return "HLTV3";
535  }
537  return "DB";
538  }
540 }//ns lumi
543 #endif
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
static const std::string lshltTableName()
Definition: LumiNames.cc:44
std::vector< std::map< unsigned int, HLTV32DB::hltinfo, std::less< unsigned int > > > HltResult
Definition: HLTV32DB.cc:53
uint16_t size_type
std::map< unsigned int, std::string, std::less< unsigned int > > HltPathMap
Definition: HLTV32DB.cc:52
static const std::string hltdataTableName()
Definition: LumiNames.cc:41
unsigned int cmsluminr
Definition: HLTV32DB.cc:46
std::string m_dest
Definition: DataPipe.h:27
const std::string dataType() const override
Definition: HLTV32DB.cc:533
hltrundata
Definition: dataDML.py:2372
void writeHltData(coral::ISessionProxy *lumisession, unsigned int irunnumber, const std::string &source, unsigned int npath, HltResult::iterator hltBeg, HltResult::iterator hltEnd, unsigned int commitintv)
Definition: HLTV32DB.cc:320
unsigned long long data_id
Definition: RevisionDML.h:30
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
unsigned long long revision_id
Definition: RevisionDML.h:28
std::string pathname
Definition: HLTV32DB.cc:47
static const unsigned int COMMITINTERVAL
Definition: HLTV32DB.cc:37
unsigned long long entry_id
Definition: RevisionDML.h:29
std::string m_source
Definition: DataPipe.h:28
static const unsigned int COMMITLSINTERVAL
Definition: HLTV32DB.cc:38
void bookNewEntry(coral::ISchema &schema, const std::string &datatableName, Entry &entry)
Definition: RevisionDML.cc:46
void insertHltRunData(coral::ISchema &schema, const HltEntry &hltentry)
Definition: RevisionDML.cc:168
unsigned int hltaccept
Definition: HLTV32DB.cc:49
double q1[4]
Definition: TauolaWrapper.h:87
static const std::string hltTableName()
Definition: LumiNames.cc:38
const std::string sourceType() const override
Definition: HLTV32DB.cc:536
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
~HLTV32DB() override
Definition: HLTV32DB.cc:539
unsigned long long writeHltDataToSchema2(coral::ISessionProxy *lumisession, unsigned int irunnumber, const std::string &source, unsigned int npath, HltResult::iterator hltBeg, HltResult::iterator hltEnd, HltPathMap &hltpathmap, unsigned int commitintv)
Definition: HLTV32DB.cc:406
#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
unsigned int prescale
Definition: HLTV32DB.cc:50
unsigned long long retrieveData(unsigned int) override
Definition: HLTV32DB.cc:74
HLTV32DB(const std::string &dest)
Definition: HLTV32DB.cc:73
static std::string const source
Definition: EdmProvDump.cc:43
void bookNewRevision(coral::ISchema &schema, const std::string &datatableName, Entry &revision)
Definition: RevisionDML.cc:56
unsigned int hltinput
Definition: HLTV32DB.cc:48