File indexing completed on 2024-04-06 12:26:35
0001 #ifndef RecoLuminosity_LumiProducer_HLTV32DB_H
0002 #define RecoLuminosity_LumiProducer_HLTV32DB_H
0003 #include "CoralBase/AttributeList.h"
0004 #include "CoralBase/Attribute.h"
0005 #include "CoralBase/AttributeSpecification.h"
0006 #include "CoralBase/Blob.h"
0007 #include "CoralBase/Exception.h"
0008 #include "RelationalAccess/ConnectionService.h"
0009 #include "RelationalAccess/ISessionProxy.h"
0010 #include "RelationalAccess/ITransaction.h"
0011 #include "RelationalAccess/ITypeConverter.h"
0012 #include "RelationalAccess/IQuery.h"
0013 #include "RelationalAccess/ICursor.h"
0014 #include "RelationalAccess/ISchema.h"
0015 #include "RelationalAccess/IView.h"
0016 #include "RelationalAccess/ITable.h"
0017 #include "RelationalAccess/ITableDataEditor.h"
0018 #include "RelationalAccess/IBulkOperation.h"
0019
0020 #include "RecoLuminosity/LumiProducer/interface/DataPipe.h"
0021 #include "RecoLuminosity/LumiProducer/interface/LumiNames.h"
0022 #include "RecoLuminosity/LumiProducer/interface/idDealer.h"
0023 #include "RecoLuminosity/LumiProducer/interface/Exception.h"
0024 #include "RecoLuminosity/LumiProducer/interface/DBConfig.h"
0025 #include "RecoLuminosity/LumiProducer/interface/ConstantDef.h"
0026 #include "RecoLuminosity/LumiProducer/interface/RevisionDML.h"
0027 #include <iostream>
0028 #include <map>
0029 #include <vector>
0030 #include <string>
0031 #include <cstring>
0032 #include "RecoLuminosity/LumiProducer/interface/DataPipe.h"
0033 namespace lumi {
0034 class HLTV32DB : public DataPipe {
0035 public:
0036 const static unsigned int COMMITINTERVAL = 200;
0037 const static unsigned int COMMITLSINTERVAL = 500;
0038
0039 explicit HLTV32DB(const std::string& dest);
0040 unsigned long long retrieveData(unsigned int) override;
0041 const std::string dataType() const override;
0042 const std::string sourceType() const override;
0043 ~HLTV32DB() override;
0044 struct hltinfo {
0045 unsigned int cmsluminr;
0046 std::string pathname;
0047 unsigned int hltinput;
0048 unsigned int hltaccept;
0049 unsigned int prescale;
0050 };
0051 typedef std::map<unsigned int, std::string, std::less<unsigned int> > HltPathMap;
0052 typedef std::vector<std::map<unsigned int, HLTV32DB::hltinfo, std::less<unsigned int> > > HltResult;
0053 void writeHltData(coral::ISessionProxy* lumisession,
0054 unsigned int irunnumber,
0055 const std::string& source,
0056 unsigned int npath,
0057 HltResult::iterator hltBeg,
0058 HltResult::iterator hltEnd,
0059 unsigned int commitintv);
0060 unsigned long long writeHltDataToSchema2(coral::ISessionProxy* lumisession,
0061 unsigned int irunnumber,
0062 const std::string& source,
0063 unsigned int npath,
0064 HltResult::iterator hltBeg,
0065 HltResult::iterator hltEnd,
0066 HltPathMap& hltpathmap,
0067 unsigned int commitintv);
0068 };
0069
0070
0071
0072 HLTV32DB::HLTV32DB(const std::string& dest) : DataPipe(dest) {}
0073 unsigned long long HLTV32DB::retrieveData(unsigned int runnumber) {
0074 std::string confdbschema("CMS_HLT");
0075 std::string hltschema("CMS_RUNINFO");
0076 std::string gtschema("CMS_GT_MON");
0077 std::string confdbpathtabname("PATHS");
0078 std::string triggerpathtabname("HLT_SUPERVISOR_TRIGGERPATHS");
0079 std::string maptabname("HLT_SUPERVISOR_SCALAR_MAP_V2");
0080 std::string gttabname("LUMI_SECTIONS");
0081 coral::ConnectionService* svc = new coral::ConnectionService;
0082 lumi::DBConfig dbconf(*svc);
0083 if (!m_authpath.empty()) {
0084 dbconf.setAuthentication(m_authpath);
0085 }
0086
0087
0088
0089
0090 std::string::size_type cutpos = m_source.find(';');
0091 std::string dbsource = m_source;
0092 std::string csvsource("");
0093 if (cutpos != std::string::npos) {
0094 dbsource = m_source.substr(0, cutpos);
0095 csvsource = m_source.substr(cutpos + 1);
0096 }
0097
0098 coral::ISessionProxy* srcsession = svc->connect(dbsource, coral::ReadOnly);
0099 coral::ITypeConverter& tpc = srcsession->typeConverter();
0100 tpc.setCppTypeForSqlType("unsigned int", "NUMBER(11)");
0101 srcsession->transaction().start(true);
0102 coral::ISchema& gtSchemaHandle = srcsession->schema(gtschema);
0103 coral::ISchema& hltSchemaHandle = srcsession->schema(hltschema);
0104 coral::ISchema& confdbSchemaHandle = srcsession->schema(confdbschema);
0105 if (!hltSchemaHandle.existsTable(triggerpathtabname) || !hltSchemaHandle.existsTable(maptabname)) {
0106 throw lumi::Exception("missing hlt tables", "retrieveData", "HLTV32DB");
0107 }
0108
0109
0110 std::vector<std::pair<unsigned int, unsigned int> > psindexmap;
0111 coral::AttributeList psindexVariableList;
0112 psindexVariableList.extend("runnumber", typeid(unsigned int));
0113 psindexVariableList["runnumber"].data<unsigned int>() = runnumber;
0114 coral::IQuery* qPsindex = gtSchemaHandle.tableHandle(gttabname).newQuery();
0115 coral::AttributeList psindexOutput;
0116 psindexOutput.extend("PRESCALE_INDEX", typeid(unsigned int));
0117 psindexOutput.extend("LUMI_SECTION", typeid(unsigned int));
0118 qPsindex->addToOutputList("PRESCALE_INDEX");
0119 qPsindex->addToOutputList("LUMI_SECTION");
0120 qPsindex->setCondition("RUN_NUMBER=:runnumber", psindexVariableList);
0121 qPsindex->defineOutput(psindexOutput);
0122 coral::ICursor& psindexCursor = qPsindex->execute();
0123 unsigned int lsmin = 4294967295;
0124 unsigned int lsmax = 0;
0125 while (psindexCursor.next()) {
0126 if (!psindexCursor.currentRow()["PRESCALE_INDEX"].isNull()) {
0127 unsigned int psindx = psindexCursor.currentRow()["PRESCALE_INDEX"].data<unsigned int>();
0128 unsigned int pslsnum = psindexCursor.currentRow()["LUMI_SECTION"].data<unsigned int>();
0129 if (pslsnum > lsmax) {
0130 lsmax = pslsnum;
0131 }
0132 if (pslsnum < lsmin) {
0133 lsmin = pslsnum;
0134 }
0135 psindexmap.push_back(std::make_pair(pslsnum, psindx));
0136 }
0137 }
0138 delete qPsindex;
0139 if (psindexmap.empty()) {
0140 srcsession->transaction().commit();
0141 delete srcsession;
0142 throw lumi::Exception("no psindex data found", "retrieveData", "HLTV32DB");
0143 }
0144
0145
0146
0147 HltPathMap hltpathmap;
0148 coral::AttributeList bindVariableList;
0149 bindVariableList.extend("runnumber", typeid(unsigned int));
0150 bindVariableList["runnumber"].data<unsigned int>() = runnumber;
0151 coral::IQuery* q1 = hltSchemaHandle.tableHandle(triggerpathtabname).newQuery();
0152 coral::AttributeList hltpathid;
0153 hltpathid.extend("hltpathid", typeid(unsigned int));
0154 q1->addToOutputList("distinct(PATHID)", "hltpathid");
0155 q1->setCondition("RUNNUMBER=:runnumber", bindVariableList);
0156 q1->defineOutput(hltpathid);
0157 coral::ICursor& c = q1->execute();
0158 while (c.next()) {
0159 unsigned int hid = c.currentRow()["hltpathid"].data<unsigned int>();
0160 hltpathmap.insert(std::make_pair(hid, ""));
0161 }
0162 delete q1;
0163
0164
0165 HltPathMap::iterator mpit;
0166 HltPathMap::iterator mpitBeg = hltpathmap.begin();
0167 HltPathMap::iterator mpitEnd = hltpathmap.end();
0168 for (mpit = mpitBeg; mpit != mpitEnd; ++mpit) {
0169 coral::IQuery* mq = confdbSchemaHandle.newQuery();
0170 coral::AttributeList mqbindVariableList;
0171 mqbindVariableList.extend("pathid", typeid(unsigned int));
0172 mqbindVariableList["pathid"].data<unsigned int>() = mpit->first;
0173 mq->addToTableList(confdbpathtabname);
0174 mq->addToOutputList("NAME", "hltpathname");
0175 mq->setCondition("PATHID=:pathid", mqbindVariableList);
0176 coral::ICursor& mqcursor = mq->execute();
0177 while (mqcursor.next()) {
0178 std::string pathname = mqcursor.currentRow()["hltpathname"].data<std::string>();
0179 hltpathmap[mpit->first] = pathname;
0180 }
0181 delete mq;
0182 }
0183
0184
0185 HltResult hltresult;
0186 unsigned int nls = lsmax - lsmin + 1;
0187
0188 hltresult.reserve(nls);
0189
0190 for (unsigned int i = lsmin; i <= lsmax; ++i) {
0191 if (i == 0)
0192 continue;
0193 std::map<unsigned int, HLTV32DB::hltinfo> allpaths;
0194 HltPathMap::iterator aIt;
0195 HltPathMap::iterator aItBeg = hltpathmap.begin();
0196 HltPathMap::iterator aItEnd = hltpathmap.end();
0197 for (aIt = aItBeg; aIt != aItEnd; ++aIt) {
0198 HLTV32DB::hltinfo ct;
0199 ct.cmsluminr = i;
0200 ct.pathname = aIt->second;
0201 ct.hltinput = 0;
0202 ct.hltaccept = 0;
0203 ct.prescale = 0;
0204 allpaths.insert(std::make_pair(aIt->first, ct));
0205 }
0206 hltresult.push_back(allpaths);
0207 }
0208
0209 bool lscountfromzero = false;
0210
0211
0212 for (std::vector<std::pair<unsigned int, unsigned int> >::iterator it = psindexmap.begin(); it != psindexmap.end();
0213 ++it) {
0214
0215 unsigned int lsnum = it->first;
0216 unsigned int psindex = it->second;
0217 coral::AttributeList hltdataVariableList;
0218 hltdataVariableList.extend("runnumber", typeid(unsigned int));
0219 hltdataVariableList.extend("lsnum", typeid(unsigned int));
0220 hltdataVariableList.extend("psindex", typeid(unsigned int));
0221 hltdataVariableList["runnumber"].data<unsigned int>() = runnumber;
0222 hltdataVariableList["lsnum"].data<unsigned int>() = lsnum;
0223 hltdataVariableList["psindex"].data<unsigned int>() = psindex;
0224 coral::IQuery* qHltData = hltSchemaHandle.newQuery();
0225 qHltData->addToTableList(triggerpathtabname, "t");
0226 qHltData->addToTableList(maptabname, "m");
0227 coral::AttributeList hltdataOutput;
0228 hltdataOutput.extend("L1PASS", typeid(unsigned int));
0229 hltdataOutput.extend("PACCEPT", typeid(unsigned int));
0230 hltdataOutput.extend("PATHID", typeid(unsigned int));
0231 hltdataOutput.extend("PSVALUE", typeid(unsigned int));
0232
0233 qHltData->addToOutputList("t.L1PASS", "l1pass");
0234 qHltData->addToOutputList("t.PACCEPT", "paccept");
0235 qHltData->addToOutputList("t.PATHID", "pathid");
0236 qHltData->addToOutputList("m.PSVALUE", "psvalue");
0237 qHltData->setCondition(
0238 "m.PATHID=t.PATHID and m.RUNNUMBER=t.RUNNUMBER and m.RUNNUMBER=:runnumber AND m.PSINDEX=:psindex AND "
0239 "t.LSNUMBER=:lsnum",
0240 hltdataVariableList);
0241 qHltData->defineOutput(hltdataOutput);
0242 coral::ICursor& hltdataCursor = qHltData->execute();
0243 while (hltdataCursor.next()) {
0244 const coral::AttributeList& row = hltdataCursor.currentRow();
0245 if (lsnum == 0) {
0246 lscountfromzero = true;
0247 if (lscountfromzero) {
0248 std::cout << "hlt ls count from 0 , we skip/dodge/parry it!" << std::endl;
0249 }
0250 } else {
0251 unsigned int pathid = row["PATHID"].data<unsigned int>();
0252 std::map<unsigned int, hltinfo>& allpathinfo = hltresult.at(lsnum - 1);
0253 hltinfo& pathcontent = allpathinfo[pathid];
0254 pathcontent.hltinput = row["L1PASS"].data<unsigned int>();
0255 pathcontent.hltaccept = row["PACCEPT"].data<unsigned int>();
0256 pathcontent.prescale = row["PSVALUE"].data<unsigned int>();
0257 }
0258 }
0259 delete qHltData;
0260 }
0261 srcsession->transaction().commit();
0262 delete srcsession;
0263
0264
0265
0266 unsigned int npath = hltpathmap.size();
0267 coral::ISessionProxy* destsession = svc->connect(m_dest, coral::Update);
0268 coral::ITypeConverter& lumitpc = destsession->typeConverter();
0269 lumitpc.setCppTypeForSqlType("unsigned int", "NUMBER(7)");
0270 lumitpc.setCppTypeForSqlType("unsigned int", "NUMBER(10)");
0271 lumitpc.setCppTypeForSqlType("unsigned long long", "NUMBER(20)");
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281 unsigned int totalcmsls = hltresult.size();
0282 std::cout << "inserting totalhltls " << totalcmsls << " total path " << npath << std::endl;
0283
0284
0285 unsigned long long hltdataid = 0;
0286 try {
0287 if (m_mode == "loadoldschema") {
0288 std::cout << "writing hlt data to old hlt table" << std::endl;
0289 writeHltData(destsession, runnumber, dbsource, npath, hltresult.begin(), hltresult.end(), COMMITINTERVAL);
0290 std::cout << "done" << std::endl;
0291 }
0292 std::cout << "writing hlt data to new lshlt table" << std::endl;
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308 hltdataid = writeHltDataToSchema2(
0309 destsession, runnumber, dbsource, npath, hltresult.begin(), hltresult.end(), hltpathmap, COMMITLSINTERVAL);
0310 std::cout << "done" << std::endl;
0311 delete destsession;
0312 delete svc;
0313 } catch (const coral::Exception& er) {
0314 std::cout << "database problem " << er.what() << std::endl;
0315 destsession->transaction().rollback();
0316 delete destsession;
0317 delete svc;
0318 throw er;
0319 }
0320 return hltdataid;
0321 }
0322 void HLTV32DB::writeHltData(coral::ISessionProxy* lumisession,
0323 unsigned int irunnumber,
0324 const std::string& source,
0325 unsigned int npath,
0326 HltResult::iterator hltItBeg,
0327 HltResult::iterator hltItEnd,
0328 unsigned int commitintv) {
0329 std::map<unsigned long long, std::vector<unsigned long long> > idallocationtable;
0330 unsigned int hltlscount = 0;
0331 unsigned int totalcmsls = std::distance(hltItBeg, hltItEnd);
0332 std::cout << "\t allocating total ids " << totalcmsls * npath << std::endl;
0333 lumisession->transaction().start(false);
0334 lumi::idDealer idg(lumisession->nominalSchema());
0335 unsigned long long hltID =
0336 idg.generateNextIDForTable(LumiNames::hltTableName(), totalcmsls * npath) - totalcmsls * npath;
0337 for (HltResult::iterator hltIt = hltItBeg; hltIt != hltItEnd; ++hltIt, ++hltlscount) {
0338 std::vector<unsigned long long> pathvec;
0339 pathvec.reserve(npath);
0340 for (unsigned int i = 0; i < npath; ++i, ++hltID) {
0341 pathvec.push_back(hltID);
0342 }
0343 idallocationtable.insert(std::make_pair(hltlscount, pathvec));
0344 }
0345 std::cout << "\t all ids allocated" << std::endl;
0346
0347 coral::AttributeList hltData;
0348 hltData.extend("HLT_ID", typeid(unsigned long long));
0349 hltData.extend("RUNNUM", typeid(unsigned int));
0350 hltData.extend("CMSLSNUM", typeid(unsigned int));
0351 hltData.extend("PATHNAME", typeid(std::string));
0352 hltData.extend("INPUTCOUNT", typeid(unsigned int));
0353 hltData.extend("ACCEPTCOUNT", typeid(unsigned int));
0354 hltData.extend("PRESCALE", typeid(unsigned int));
0355
0356
0357 unsigned long long& hlt_id = hltData["HLT_ID"].data<unsigned long long>();
0358 unsigned int& hltrunnum = hltData["RUNNUM"].data<unsigned int>();
0359 unsigned int& cmslsnum = hltData["CMSLSNUM"].data<unsigned int>();
0360 std::string& pathname = hltData["PATHNAME"].data<std::string>();
0361 unsigned int& inputcount = hltData["INPUTCOUNT"].data<unsigned int>();
0362 unsigned int& acceptcount = hltData["ACCEPTCOUNT"].data<unsigned int>();
0363 unsigned int& prescale = hltData["PRESCALE"].data<unsigned int>();
0364 hltlscount = 0;
0365 coral::IBulkOperation* hltInserter = nullptr;
0366 unsigned int comittedls = 0;
0367 for (HltResult::iterator hltIt = hltItBeg; hltIt != hltItEnd; ++hltIt, ++hltlscount) {
0368 std::map<unsigned int, HLTV32DB::hltinfo>::const_iterator pathIt;
0369 std::map<unsigned int, HLTV32DB::hltinfo>::const_iterator pathBeg = hltIt->begin();
0370 std::map<unsigned int, HLTV32DB::hltinfo>::const_iterator pathEnd = hltIt->end();
0371 if (!lumisession->transaction().isActive()) {
0372 lumisession->transaction().start(false);
0373 coral::ITable& hlttable = lumisession->nominalSchema().tableHandle(LumiNames::hltTableName());
0374 hltInserter = hlttable.dataEditor().bulkInsert(hltData, npath);
0375 } else {
0376 if (hltIt == hltItBeg) {
0377 coral::ITable& hlttable = lumisession->nominalSchema().tableHandle(LumiNames::hltTableName());
0378 hltInserter = hlttable.dataEditor().bulkInsert(hltData, npath);
0379 }
0380 }
0381 unsigned int hltpathcount = 0;
0382 for (pathIt = pathBeg; pathIt != pathEnd; ++pathIt, ++hltpathcount) {
0383 hlt_id = idallocationtable[hltlscount].at(hltpathcount);
0384 hltrunnum = irunnumber;
0385 cmslsnum = pathIt->second.cmsluminr;
0386 pathname = pathIt->second.pathname;
0387 inputcount = pathIt->second.hltinput;
0388 acceptcount = pathIt->second.hltaccept;
0389 prescale = pathIt->second.prescale;
0390 hltInserter->processNextIteration();
0391 }
0392 hltInserter->flush();
0393 ++comittedls;
0394 if (comittedls == commitintv) {
0395 std::cout << "\t committing in LS chunck " << comittedls << std::endl;
0396 delete hltInserter;
0397 hltInserter = nullptr;
0398 lumisession->transaction().commit();
0399 comittedls = 0;
0400 std::cout << "\t committed " << std::endl;
0401 } else if (hltlscount == (totalcmsls - 1)) {
0402 std::cout << "\t committing at the end" << std::endl;
0403 delete hltInserter;
0404 hltInserter = nullptr;
0405 lumisession->transaction().commit();
0406 std::cout << "\t done" << std::endl;
0407 }
0408 }
0409 }
0410 unsigned long long HLTV32DB::writeHltDataToSchema2(coral::ISessionProxy* lumisession,
0411 unsigned int irunnumber,
0412 const std::string& source,
0413 unsigned int npath,
0414 HltResult::iterator hltItBeg,
0415 HltResult::iterator hltItEnd,
0416 HltPathMap& hltpathmap,
0417 unsigned int commitintv) {
0418 unsigned int totalcmsls = std::distance(hltItBeg, hltItEnd);
0419 std::cout << "inserting totalcmsls " << totalcmsls << std::endl;
0420 coral::AttributeList lshltData;
0421 lshltData.extend("DATA_ID", typeid(unsigned long long));
0422 lshltData.extend("RUNNUM", typeid(unsigned int));
0423 lshltData.extend("CMSLSNUM", typeid(unsigned int));
0424 lshltData.extend("PRESCALEBLOB", typeid(coral::Blob));
0425 lshltData.extend("HLTCOUNTBLOB", typeid(coral::Blob));
0426 lshltData.extend("HLTACCEPTBLOB", typeid(coral::Blob));
0427 unsigned long long& data_id = lshltData["DATA_ID"].data<unsigned long long>();
0428 unsigned int& hltrunnum = lshltData["RUNNUM"].data<unsigned int>();
0429 unsigned int& cmslsnum = lshltData["CMSLSNUM"].data<unsigned int>();
0430 coral::Blob& prescaleblob = lshltData["PRESCALEBLOB"].data<coral::Blob>();
0431 coral::Blob& hltcountblob = lshltData["HLTCOUNTBLOB"].data<coral::Blob>();
0432 coral::Blob& hltacceptblob = lshltData["HLTACCEPTBLOB"].data<coral::Blob>();
0433
0434 unsigned long long branch_id = 3;
0435 std::string branch_name("DATA");
0436 lumi::RevisionDML revisionDML;
0437 lumi::RevisionDML::HltEntry hltrundata;
0438 std::stringstream op;
0439 op << irunnumber;
0440 std::string runnumberStr = op.str();
0441 lumisession->transaction().start(false);
0442 hltrundata.entry_name = runnumberStr;
0443 hltrundata.source = source;
0444 hltrundata.runnumber = irunnumber;
0445 hltrundata.npath = npath;
0446 std::string pathnames;
0447 HltPathMap::iterator hltpathmapIt;
0448 HltPathMap::iterator hltpathmapItBeg = hltpathmap.begin();
0449 HltPathMap::iterator hltpathmapItEnd = hltpathmap.end();
0450 for (hltpathmapIt = hltpathmapItBeg; hltpathmapIt != hltpathmapItEnd; ++hltpathmapIt) {
0451 if (hltpathmapIt != hltpathmapItBeg) {
0452 pathnames += std::string(",");
0453 }
0454 pathnames += hltpathmapIt->second;
0455 }
0456 std::cout << "\tpathnames " << pathnames << std::endl;
0457 hltrundata.pathnames = pathnames;
0458 hltrundata.entry_id = revisionDML.getEntryInBranchByName(
0459 lumisession->nominalSchema(), lumi::LumiNames::hltdataTableName(), runnumberStr, branch_name);
0460 if (hltrundata.entry_id == 0) {
0461 revisionDML.bookNewEntry(lumisession->nominalSchema(), LumiNames::hltdataTableName(), hltrundata);
0462 std::cout << "hltrundata revision_id " << hltrundata.revision_id << " entry_id " << hltrundata.entry_id
0463 << " data_id " << hltrundata.data_id << std::endl;
0464 revisionDML.addEntry(
0465 lumisession->nominalSchema(), LumiNames::hltdataTableName(), hltrundata, branch_id, branch_name);
0466 } else {
0467 revisionDML.bookNewRevision(lumisession->nominalSchema(), LumiNames::hltdataTableName(), hltrundata);
0468 std::cout << "hltrundata revision_id " << hltrundata.revision_id << " entry_id " << hltrundata.entry_id
0469 << " data_id " << hltrundata.data_id << std::endl;
0470 revisionDML.addRevision(
0471 lumisession->nominalSchema(), LumiNames::hltdataTableName(), hltrundata, branch_id, branch_name);
0472 }
0473 std::cout << "inserting hltrundata" << std::endl;
0474 revisionDML.insertHltRunData(lumisession->nominalSchema(), hltrundata);
0475 std::cout << "inserting lshlt data" << std::endl;
0476
0477 unsigned int hltlscount = 0;
0478 coral::IBulkOperation* hltInserter = nullptr;
0479 unsigned int comittedls = 0;
0480 for (HltResult::iterator hltIt = hltItBeg; hltIt != hltItEnd; ++hltIt, ++hltlscount) {
0481 unsigned int cmslscount = hltlscount + 1;
0482 std::map<unsigned int, HLTV32DB::hltinfo, std::less<unsigned int> >::const_iterator pathIt;
0483 std::map<unsigned int, HLTV32DB::hltinfo, std::less<unsigned int> >::const_iterator pathBeg = hltIt->begin();
0484 std::map<unsigned int, HLTV32DB::hltinfo, std::less<unsigned int> >::const_iterator pathEnd = hltIt->end();
0485 if (!lumisession->transaction().isActive()) {
0486 lumisession->transaction().start(false);
0487 coral::ITable& hlttable = lumisession->nominalSchema().tableHandle(LumiNames::lshltTableName());
0488 hltInserter = hlttable.dataEditor().bulkInsert(lshltData, npath);
0489 } else {
0490 if (hltIt == hltItBeg) {
0491 coral::ITable& hlttable = lumisession->nominalSchema().tableHandle(LumiNames::lshltTableName());
0492 hltInserter = hlttable.dataEditor().bulkInsert(lshltData, npath);
0493 }
0494 }
0495 data_id = hltrundata.data_id;
0496 hltrunnum = irunnumber;
0497 cmslsnum = cmslscount;
0498 std::vector<unsigned int> prescales;
0499 prescales.reserve(npath);
0500 std::vector<unsigned int> hltcounts;
0501 hltcounts.reserve(npath);
0502 std::vector<unsigned int> hltaccepts;
0503 hltaccepts.reserve(npath);
0504
0505 for (pathIt = pathBeg; pathIt != pathEnd; ++pathIt) {
0506 unsigned int hltcount = pathIt->second.hltinput;
0507
0508 hltcounts.push_back(hltcount);
0509 unsigned int hltaccept = pathIt->second.hltaccept;
0510
0511 hltaccepts.push_back(hltaccept);
0512 unsigned int prescale = pathIt->second.prescale;
0513
0514 prescales.push_back(prescale);
0515 }
0516 prescaleblob.resize(sizeof(unsigned int) * npath);
0517 void* prescaleblob_StartAddress = prescaleblob.startingAddress();
0518 std::memmove(prescaleblob_StartAddress, &prescales[0], sizeof(unsigned int) * npath);
0519 hltcountblob.resize(sizeof(unsigned int) * npath);
0520 void* hltcountblob_StartAddress = hltcountblob.startingAddress();
0521 std::memmove(hltcountblob_StartAddress, &hltcounts[0], sizeof(unsigned int) * npath);
0522 hltacceptblob.resize(sizeof(unsigned int) * npath);
0523 void* hltacceptblob_StartAddress = hltacceptblob.startingAddress();
0524 std::memmove(hltacceptblob_StartAddress, &hltaccepts[0], sizeof(unsigned int) * npath);
0525
0526 hltInserter->processNextIteration();
0527 hltInserter->flush();
0528 ++comittedls;
0529 if (comittedls == commitintv) {
0530 std::cout << "\t committing in LS chunck " << comittedls << std::endl;
0531 delete hltInserter;
0532 hltInserter = nullptr;
0533 lumisession->transaction().commit();
0534 comittedls = 0;
0535 std::cout << "\t committed " << std::endl;
0536 } else if (hltlscount == (totalcmsls - 1)) {
0537 std::cout << "\t committing at the end" << std::endl;
0538 delete hltInserter;
0539 hltInserter = nullptr;
0540 lumisession->transaction().commit();
0541 std::cout << "\t done" << std::endl;
0542 }
0543 }
0544 return hltrundata.data_id;
0545 }
0546 const std::string HLTV32DB::dataType() const { return "HLTV3"; }
0547 const std::string HLTV32DB::sourceType() const { return "DB"; }
0548 HLTV32DB::~HLTV32DB() {}
0549 }
0550 #include "RecoLuminosity/LumiProducer/interface/DataPipeFactory.h"
0551 DEFINE_EDM_PLUGIN(lumi::DataPipeFactory, lumi::HLTV32DB, "HLTV32DB");
0552 #endif