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