00001 #ifndef RecoLuminosity_LumiProducer_HLTV32DB_H
00002 #define RecoLuminosity_LumiProducer_HLTV32DB_H
00003 #include "CoralBase/AttributeList.h"
00004 #include "CoralBase/Attribute.h"
00005 #include "CoralBase/AttributeSpecification.h"
00006 #include "CoralBase/Blob.h"
00007 #include "CoralBase/Exception.h"
00008 #include "RelationalAccess/ConnectionService.h"
00009 #include "RelationalAccess/ISessionProxy.h"
00010 #include "RelationalAccess/ITransaction.h"
00011 #include "RelationalAccess/ITypeConverter.h"
00012 #include "RelationalAccess/IQuery.h"
00013 #include "RelationalAccess/ICursor.h"
00014 #include "RelationalAccess/ISchema.h"
00015 #include "RelationalAccess/IView.h"
00016 #include "RelationalAccess/ITable.h"
00017 #include "RelationalAccess/ITableDataEditor.h"
00018 #include "RelationalAccess/IBulkOperation.h"
00019
00020 #include "RecoLuminosity/LumiProducer/interface/DataPipe.h"
00021 #include "RecoLuminosity/LumiProducer/interface/LumiNames.h"
00022 #include "RecoLuminosity/LumiProducer/interface/idDealer.h"
00023 #include "RecoLuminosity/LumiProducer/interface/Exception.h"
00024 #include "RecoLuminosity/LumiProducer/interface/DBConfig.h"
00025 #include "RecoLuminosity/LumiProducer/interface/ConstantDef.h"
00026 #include "RecoLuminosity/LumiProducer/interface/RevisionDML.h"
00027 #include <iostream>
00028 #include <map>
00029 #include <vector>
00030 #include <string>
00031 #include <cstring>
00032 #include "RecoLuminosity/LumiProducer/interface/DataPipe.h"
00033 namespace lumi{
00034 class HLTV32DB : public DataPipe{
00035
00036 public:
00037 const static unsigned int COMMITINTERVAL=200;
00038 const static unsigned int COMMITLSINTERVAL=500;
00039
00040 explicit HLTV32DB(const std::string& dest);
00041 virtual unsigned long long retrieveData( unsigned int );
00042 virtual const std::string dataType() const;
00043 virtual const std::string sourceType() const;
00044 virtual ~HLTV32DB();
00045 struct hltinfo{
00046 unsigned int cmsluminr;
00047 std::string pathname;
00048 unsigned int hltinput;
00049 unsigned int hltaccept;
00050 unsigned int prescale;
00051 };
00052 typedef std::map< unsigned int, std::string , std::less<unsigned int> > HltPathMap;
00053 typedef std::vector< std::map<unsigned int,HLTV32DB::hltinfo,std::less<unsigned int> > > HltResult;
00054 void writeHltData(coral::ISessionProxy* lumisession,
00055 unsigned int irunnumber,
00056 const std::string& source,
00057 unsigned int npath,
00058 HltResult::iterator hltBeg,
00059 HltResult::iterator hltEnd,
00060 unsigned int commitintv);
00061 unsigned long long writeHltDataToSchema2(coral::ISessionProxy* lumisession,
00062 unsigned int irunnumber,
00063 const std::string& source,
00064 unsigned int npath,
00065 HltResult::iterator hltBeg,
00066 HltResult::iterator hltEnd,
00067 HltPathMap& hltpathmap,
00068 unsigned int commitintv);
00069 };
00070
00071
00072
00073 HLTV32DB::HLTV32DB(const std::string& dest):DataPipe(dest){}
00074 unsigned long long HLTV32DB::retrieveData( unsigned int runnumber){
00075 std::string confdbschema("CMS_HLT");
00076 std::string hltschema("CMS_RUNINFO");
00077 std::string gtschema("CMS_GT_MON");
00078 std::string confdbpathtabname("PATHS");
00079 std::string triggerpathtabname("HLT_SUPERVISOR_TRIGGERPATHS");
00080 std::string maptabname("HLT_SUPERVISOR_SCALAR_MAP_V2");
00081 std::string gttabname("LUMI_SECTIONS");
00082 coral::ConnectionService* svc=new coral::ConnectionService;
00083 lumi::DBConfig dbconf(*svc);
00084 if(!m_authpath.empty()){
00085 dbconf.setAuthentication(m_authpath);
00086 }
00091 std::string::size_type cutpos=m_source.find(';');
00092 std::string dbsource=m_source;
00093 std::string csvsource("");
00094 if(cutpos!=std::string::npos){
00095 dbsource=m_source.substr(0,cutpos);
00096 csvsource=m_source.substr(cutpos+1);
00097 }
00098
00099 coral::ISessionProxy* srcsession=svc->connect(dbsource, coral::ReadOnly);
00100 coral::ITypeConverter& tpc=srcsession->typeConverter();
00101 tpc.setCppTypeForSqlType("unsigned int","NUMBER(11)");
00102 srcsession->transaction().start(true);
00103 coral::ISchema& gtSchemaHandle=srcsession->schema(gtschema);
00104 coral::ISchema& hltSchemaHandle=srcsession->schema(hltschema);
00105 coral::ISchema& confdbSchemaHandle=srcsession->schema(confdbschema);
00106 if( !hltSchemaHandle.existsTable(triggerpathtabname) || !hltSchemaHandle.existsTable(maptabname) ){
00107 throw lumi::Exception("missing hlt tables" ,"retrieveData","HLTV32DB");
00108 }
00110
00111 std::vector< std::pair<unsigned int,unsigned int> > psindexmap;
00112 coral::AttributeList psindexVariableList;
00113 psindexVariableList.extend("runnumber",typeid(unsigned int));
00114 psindexVariableList["runnumber"].data<unsigned int>()=runnumber;
00115 coral::IQuery* qPsindex=gtSchemaHandle.tableHandle(gttabname).newQuery();
00116 coral::AttributeList psindexOutput;
00117 psindexOutput.extend("PRESCALE_INDEX",typeid(unsigned int));
00118 psindexOutput.extend("LUMI_SECTION",typeid(unsigned int));
00119 qPsindex->addToOutputList("PRESCALE_INDEX");
00120 qPsindex->addToOutputList("LUMI_SECTION");
00121 qPsindex->setCondition("RUN_NUMBER=:runnumber",psindexVariableList);
00122 qPsindex->defineOutput(psindexOutput);
00123 coral::ICursor& psindexCursor=qPsindex->execute();
00124 unsigned int lsmin=4294967295;
00125 unsigned int lsmax=0;
00126 while( psindexCursor.next() ){
00127 if( !psindexCursor.currentRow()["PRESCALE_INDEX"].isNull() ){
00128 unsigned int psindx=psindexCursor.currentRow()["PRESCALE_INDEX"].data<unsigned int>();
00129 unsigned int pslsnum=psindexCursor.currentRow()["LUMI_SECTION"].data<unsigned int>();
00130 if(pslsnum>lsmax){
00131 lsmax=pslsnum;
00132 }
00133 if(pslsnum<lsmin){
00134 lsmin=pslsnum;
00135 }
00136 psindexmap.push_back(std::make_pair(pslsnum,psindx));
00137 }
00138 }
00139 delete qPsindex;
00140 if(psindexmap.size()==0){
00141 srcsession->transaction().commit();
00142 delete srcsession;
00143 throw lumi::Exception("no psindex data found","retrieveData","HLTV32DB");
00144 }
00145
00148 HltPathMap hltpathmap;
00149 coral::AttributeList bindVariableList;
00150 bindVariableList.extend("runnumber",typeid(unsigned int));
00151 bindVariableList["runnumber"].data<unsigned int>()=runnumber;
00152 coral::IQuery* q1=hltSchemaHandle.tableHandle(triggerpathtabname).newQuery();
00153 coral::AttributeList hltpathid;
00154 hltpathid.extend("hltpathid",typeid(unsigned int));
00155 q1->addToOutputList("distinct(PATHID)","hltpathid");
00156 q1->setCondition("RUNNUMBER=:runnumber",bindVariableList);
00157 q1->defineOutput(hltpathid);
00158 coral::ICursor& c=q1->execute();
00159 unsigned int npc=0;
00160 while( c.next() ){
00161 npc++;
00162 unsigned int hid=c.currentRow()["hltpathid"].data<unsigned int>();
00163 hltpathmap.insert(std::make_pair(hid,""));
00164 }
00165 delete q1;
00168 HltPathMap::iterator mpit;
00169 HltPathMap::iterator mpitBeg=hltpathmap.begin();
00170 HltPathMap::iterator mpitEnd=hltpathmap.end();
00171 for( mpit=mpitBeg;mpit!=mpitEnd;++mpit){
00172 coral::IQuery* mq=confdbSchemaHandle.newQuery();
00173 coral::AttributeList mqbindVariableList;
00174 mqbindVariableList.extend("pathid",typeid(unsigned int));
00175 mqbindVariableList["pathid"].data<unsigned int>()=mpit->first;
00176 mq->addToTableList(confdbpathtabname);
00177 mq->addToOutputList("NAME","hltpathname");
00178 mq->setCondition("PATHID=:pathid",mqbindVariableList);
00179 coral::ICursor& mqcursor=mq->execute();
00180 while( mqcursor.next() ){
00181 std::string pathname=mqcursor.currentRow()["hltpathname"].data<std::string>();
00182 hltpathmap[mpit->first]=pathname;
00183 }
00184 delete mq;
00185 }
00186
00188 HltResult hltresult;
00189 unsigned int nls=lsmax-lsmin+1;
00190
00191 hltresult.reserve(nls);
00192
00193 for(unsigned int i=lsmin;i<=lsmax;++i){
00194 if (i==0) continue;
00195 std::map<unsigned int, HLTV32DB::hltinfo> allpaths;
00196 HltPathMap::iterator aIt;
00197 HltPathMap::iterator aItBeg=hltpathmap.begin();
00198 HltPathMap::iterator aItEnd=hltpathmap.end();
00199 for(aIt=aItBeg;aIt!=aItEnd;++aIt){
00200 HLTV32DB::hltinfo ct;
00201 ct.cmsluminr=i;
00202 ct.pathname=aIt->second;
00203 ct.hltinput=0;
00204 ct.hltaccept=0;
00205 ct.prescale=0;
00206 allpaths.insert(std::make_pair(aIt->first,ct));
00207 }
00208 hltresult.push_back(allpaths);
00209 }
00210
00211 bool lscountfromzero=false;
00212
00214 for( std::vector< std::pair<unsigned int,unsigned int> >::iterator it=psindexmap.begin();it!=psindexmap.end();++it ){
00215
00216 unsigned int lsnum=it->first;
00217 unsigned int psindex=it->second;
00218 coral::AttributeList hltdataVariableList;
00219 hltdataVariableList.extend("runnumber",typeid(unsigned int));
00220 hltdataVariableList.extend("lsnum",typeid(unsigned int));
00221 hltdataVariableList.extend("psindex",typeid(unsigned int));
00222 hltdataVariableList["runnumber"].data<unsigned int>()=runnumber;
00223 hltdataVariableList["lsnum"].data<unsigned int>()=lsnum;
00224 hltdataVariableList["psindex"].data<unsigned int>()=psindex;
00225 coral::IQuery* qHltData=hltSchemaHandle.newQuery();
00226 qHltData->addToTableList(triggerpathtabname,"t");
00227 qHltData->addToTableList(maptabname,"m");
00228 coral::AttributeList hltdataOutput;
00229 hltdataOutput.extend("L1PASS",typeid(unsigned int));
00230 hltdataOutput.extend("PACCEPT",typeid(unsigned int));
00231 hltdataOutput.extend("PATHID",typeid(unsigned int));
00232 hltdataOutput.extend("PSVALUE",typeid(unsigned int));
00233
00234 qHltData->addToOutputList("t.L1PASS","l1pass");
00235 qHltData->addToOutputList("t.PACCEPT","paccept");
00236 qHltData->addToOutputList("t.PATHID","pathid");
00237 qHltData->addToOutputList("m.PSVALUE","psvalue");
00238 qHltData->setCondition("m.PATHID=t.PATHID and m.RUNNUMBER=t.RUNNUMBER and m.RUNNUMBER=:runnumber AND m.PSINDEX=:psindex AND t.LSNUMBER=:lsnum",hltdataVariableList);
00239 qHltData->defineOutput(hltdataOutput);
00240 coral::ICursor& hltdataCursor=qHltData->execute();
00241 while( hltdataCursor.next() ){
00242 const coral::AttributeList& row=hltdataCursor.currentRow();
00243 if (lsnum==0){
00244 lscountfromzero=true;
00245 if(lscountfromzero) {
00246 std::cout<<"hlt ls count from 0 , we skip/dodge/parry it!"<<std::endl;
00247 }
00248 }else{
00249 unsigned int pathid=row["PATHID"].data<unsigned int>();
00250 std::map<unsigned int,hltinfo>& allpathinfo=hltresult.at(lsnum-1);
00251 hltinfo& pathcontent=allpathinfo[pathid];
00252 pathcontent.hltinput=row["L1PASS"].data<unsigned int>();
00253 pathcontent.hltaccept=row["PACCEPT"].data<unsigned int>();
00254 pathcontent.prescale=row["PSVALUE"].data<unsigned int>();
00255 }
00256 }
00257 delete qHltData;
00258 }
00259 srcsession->transaction().commit();
00260 delete srcsession;
00261
00262
00263
00264 unsigned int npath=hltpathmap.size();
00265 coral::ISessionProxy* destsession=svc->connect(m_dest,coral::Update);
00266 coral::ITypeConverter& lumitpc=destsession->typeConverter();
00267 lumitpc.setCppTypeForSqlType("unsigned int","NUMBER(7)");
00268 lumitpc.setCppTypeForSqlType("unsigned int","NUMBER(10)");
00269 lumitpc.setCppTypeForSqlType("unsigned long long","NUMBER(20)");
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279 unsigned int totalcmsls=hltresult.size();
00280 std::cout<<"inserting totalhltls "<<totalcmsls<<" total path "<<npath<<std::endl;
00281
00282
00283 unsigned long long hltdataid=0;
00284 try{
00285 if(m_mode=="loadoldschema"){
00286 std::cout<<"writing hlt data to old hlt table"<<std::endl;
00287 writeHltData(destsession,runnumber,dbsource,npath,hltresult.begin(),hltresult.end(),COMMITINTERVAL);
00288 std::cout<<"done"<<std::endl;
00289 }
00290 std::cout<<"writing hlt data to new lshlt table"<<std::endl;
00291
00306 hltdataid=writeHltDataToSchema2(destsession,runnumber,dbsource,npath,hltresult.begin(),hltresult.end(), hltpathmap,COMMITLSINTERVAL);
00307 std::cout<<"done"<<std::endl;
00308 delete destsession;
00309 delete svc;
00310 }catch( const coral::Exception& er){
00311 std::cout<<"database problem "<<er.what()<<std::endl;
00312 destsession->transaction().rollback();
00313 delete destsession;
00314 delete svc;
00315 throw er;
00316 }
00317 return hltdataid;
00318 }
00319 void
00320 HLTV32DB::writeHltData(coral::ISessionProxy* lumisession,
00321 unsigned int irunnumber,
00322 const std::string& source,
00323 unsigned int npath,
00324 HltResult::iterator hltItBeg,
00325 HltResult::iterator hltItEnd,
00326 unsigned int commitintv){
00327 std::map< unsigned long long, std::vector<unsigned long long> > idallocationtable;
00328 unsigned int hltlscount=0;
00329 unsigned int totalcmsls=std::distance(hltItBeg,hltItEnd);
00330 std::cout<<"\t allocating total ids "<<totalcmsls*npath<<std::endl;
00331 lumisession->transaction().start(false);
00332 lumi::idDealer idg(lumisession->nominalSchema());
00333 unsigned long long hltID = idg.generateNextIDForTable(LumiNames::hltTableName(),totalcmsls*npath)-totalcmsls*npath;
00334 for(HltResult::iterator hltIt=hltItBeg;hltIt!=hltItEnd;++hltIt,++hltlscount){
00335 std::vector<unsigned long long> pathvec;
00336 pathvec.reserve(npath);
00337 for(unsigned int i=0;i<npath;++i,++hltID){
00338 pathvec.push_back(hltID);
00339 }
00340 idallocationtable.insert(std::make_pair(hltlscount,pathvec));
00341 }
00342 std::cout<<"\t all ids allocated"<<std::endl;
00343
00344 coral::AttributeList hltData;
00345 hltData.extend("HLT_ID",typeid(unsigned long long));
00346 hltData.extend("RUNNUM",typeid(unsigned int));
00347 hltData.extend("CMSLSNUM",typeid(unsigned int));
00348 hltData.extend("PATHNAME",typeid(std::string));
00349 hltData.extend("INPUTCOUNT",typeid(unsigned int));
00350 hltData.extend("ACCEPTCOUNT",typeid(unsigned int));
00351 hltData.extend("PRESCALE",typeid(unsigned int));
00352
00353
00354 unsigned long long& hlt_id=hltData["HLT_ID"].data<unsigned long long>();
00355 unsigned int& hltrunnum=hltData["RUNNUM"].data<unsigned int>();
00356 unsigned int& cmslsnum=hltData["CMSLSNUM"].data<unsigned int>();
00357 std::string& pathname=hltData["PATHNAME"].data<std::string>();
00358 unsigned int& inputcount=hltData["INPUTCOUNT"].data<unsigned int>();
00359 unsigned int& acceptcount=hltData["ACCEPTCOUNT"].data<unsigned int>();
00360 unsigned int& prescale=hltData["PRESCALE"].data<unsigned int>();
00361 hltlscount=0;
00362 coral::IBulkOperation* hltInserter=0;
00363 unsigned int comittedls=0;
00364 for(HltResult::iterator hltIt=hltItBeg;hltIt!=hltItEnd;++hltIt,++hltlscount){
00365 std::map<unsigned int,HLTV32DB::hltinfo>::const_iterator pathIt;
00366 std::map<unsigned int,HLTV32DB::hltinfo>::const_iterator pathBeg=hltIt->begin();
00367 std::map<unsigned int,HLTV32DB::hltinfo>::const_iterator pathEnd=hltIt->end();
00368 if(!lumisession->transaction().isActive()){
00369 lumisession->transaction().start(false);
00370 coral::ITable& hlttable=lumisession->nominalSchema().tableHandle(LumiNames::hltTableName());
00371 hltInserter=hlttable.dataEditor().bulkInsert(hltData,npath);
00372 }else{
00373 if(hltIt==hltItBeg){
00374 coral::ITable& hlttable=lumisession->nominalSchema().tableHandle(LumiNames::hltTableName());
00375 hltInserter=hlttable.dataEditor().bulkInsert(hltData,npath);
00376 }
00377 }
00378 unsigned int hltpathcount=0;
00379 for(pathIt=pathBeg;pathIt!=pathEnd;++pathIt,++hltpathcount){
00380 hlt_id = idallocationtable[hltlscount].at(hltpathcount);
00381 hltrunnum = irunnumber;
00382 cmslsnum = pathIt->second.cmsluminr;
00383 pathname = pathIt->second.pathname;
00384 inputcount = pathIt->second.hltinput;
00385 acceptcount = pathIt->second.hltaccept;
00386 prescale = pathIt->second.prescale;
00387 hltInserter->processNextIteration();
00388 }
00389 hltInserter->flush();
00390 ++comittedls;
00391 if(comittedls==commitintv){
00392 std::cout<<"\t committing in LS chunck "<<comittedls<<std::endl;
00393 delete hltInserter; hltInserter=0;
00394 lumisession->transaction().commit();
00395 comittedls=0;
00396 std::cout<<"\t committed "<<std::endl;
00397 }else if( hltlscount==(totalcmsls-1) ){
00398 std::cout<<"\t committing at the end"<<std::endl;
00399 delete hltInserter; hltInserter=0;
00400 lumisession->transaction().commit();
00401 std::cout<<"\t done"<<std::endl;
00402 }
00403 }
00404 }
00405 unsigned long long
00406 HLTV32DB::writeHltDataToSchema2(coral::ISessionProxy* lumisession,
00407 unsigned int irunnumber,
00408 const std::string& source,
00409 unsigned int npath,
00410 HltResult::iterator hltItBeg,
00411 HltResult::iterator hltItEnd,
00412 HltPathMap& hltpathmap,
00413 unsigned int commitintv){
00414 HltResult::iterator hltIt;
00415 unsigned int totalcmsls=std::distance(hltItBeg,hltItEnd);
00416 std::cout<<"inserting totalcmsls "<<totalcmsls<<std::endl;
00417 coral::AttributeList lshltData;
00418 lshltData.extend("DATA_ID",typeid(unsigned long long));
00419 lshltData.extend("RUNNUM",typeid(unsigned int));
00420 lshltData.extend("CMSLSNUM",typeid(unsigned int));
00421 lshltData.extend("PRESCALEBLOB",typeid(coral::Blob));
00422 lshltData.extend("HLTCOUNTBLOB",typeid(coral::Blob));
00423 lshltData.extend("HLTACCEPTBLOB",typeid(coral::Blob));
00424 unsigned long long& data_id=lshltData["DATA_ID"].data<unsigned long long>();
00425 unsigned int& hltrunnum=lshltData["RUNNUM"].data<unsigned int>();
00426 unsigned int& cmslsnum=lshltData["CMSLSNUM"].data<unsigned int>();
00427 coral::Blob& prescaleblob=lshltData["PRESCALEBLOB"].data<coral::Blob>();
00428 coral::Blob& hltcountblob=lshltData["HLTCOUNTBLOB"].data<coral::Blob>();
00429 coral::Blob& hltacceptblob=lshltData["HLTACCEPTBLOB"].data<coral::Blob>();
00430
00431 unsigned long long branch_id=3;
00432 std::string branch_name("DATA");
00433 lumi::RevisionDML revisionDML;
00434 lumi::RevisionDML::HltEntry hltrundata;
00435 std::stringstream op;
00436 op<<irunnumber;
00437 std::string runnumberStr=op.str();
00438 lumisession->transaction().start(false);
00439 hltrundata.entry_name=runnumberStr;
00440 hltrundata.source=source;
00441 hltrundata.runnumber=irunnumber;
00442 hltrundata.npath=npath;
00443 std::string pathnames;
00444 HltPathMap::iterator hltpathmapIt;
00445 HltPathMap::iterator hltpathmapItBeg=hltpathmap.begin();
00446 HltPathMap::iterator hltpathmapItEnd=hltpathmap.end();
00447 for(hltpathmapIt=hltpathmapItBeg;hltpathmapIt!=hltpathmapItEnd;++hltpathmapIt){
00448 if(hltpathmapIt!=hltpathmapItBeg){
00449 pathnames+=std::string(",");
00450 }
00451 pathnames+=hltpathmapIt->second;
00452 }
00453 std::cout<<"\tpathnames "<<pathnames<<std::endl;
00454 hltrundata.pathnames=pathnames;
00455 hltrundata.entry_id=revisionDML.getEntryInBranchByName(lumisession->nominalSchema(),lumi::LumiNames::hltdataTableName(),runnumberStr,branch_name);
00456 if(hltrundata.entry_id==0){
00457 revisionDML.bookNewEntry(lumisession->nominalSchema(),LumiNames::hltdataTableName(),hltrundata);
00458 std::cout<<"hltrundata revision_id "<<hltrundata.revision_id<<" entry_id "<<hltrundata.entry_id<<" data_id "<<hltrundata.data_id<<std::endl;
00459 revisionDML.addEntry(lumisession->nominalSchema(),LumiNames::hltdataTableName(),hltrundata,branch_id,branch_name);
00460 }else{
00461 revisionDML.bookNewRevision(lumisession->nominalSchema(),LumiNames::hltdataTableName(),hltrundata);
00462 std::cout<<"hltrundata revision_id "<<hltrundata.revision_id<<" entry_id "<<hltrundata.entry_id<<" data_id "<<hltrundata.data_id<<std::endl;
00463 revisionDML.addRevision(lumisession->nominalSchema(),LumiNames::hltdataTableName(),hltrundata,branch_id,branch_name);
00464 }
00465 std::cout<<"inserting hltrundata"<<std::endl;
00466 revisionDML.insertHltRunData(lumisession->nominalSchema(),hltrundata);
00467 std::cout<<"inserting lshlt data"<<std::endl;
00468
00469 unsigned int hltlscount=0;
00470 coral::IBulkOperation* hltInserter=0;
00471 unsigned int comittedls=0;
00472 for(HltResult::iterator hltIt=hltItBeg;hltIt!=hltItEnd;++hltIt,++hltlscount){
00473 unsigned int cmslscount=hltlscount+1;
00474 std::map<unsigned int,HLTV32DB::hltinfo,std::less<unsigned int> >::const_iterator pathIt;
00475 std::map<unsigned int,HLTV32DB::hltinfo,std::less<unsigned int> >::const_iterator pathBeg=hltIt->begin();
00476 std::map<unsigned int,HLTV32DB::hltinfo,std::less<unsigned int> >::const_iterator pathEnd=hltIt->end();
00477 if(!lumisession->transaction().isActive()){
00478 lumisession->transaction().start(false);
00479 coral::ITable& hlttable=lumisession->nominalSchema().tableHandle(LumiNames::lshltTableName());
00480 hltInserter=hlttable.dataEditor().bulkInsert(lshltData,npath);
00481 }else{
00482 if(hltIt==hltItBeg){
00483 coral::ITable& hlttable=lumisession->nominalSchema().tableHandle(LumiNames::lshltTableName());
00484 hltInserter=hlttable.dataEditor().bulkInsert(lshltData,npath);
00485 }
00486 }
00487 data_id = hltrundata.data_id;
00488 hltrunnum = irunnumber;
00489 cmslsnum = cmslscount;
00490 std::vector<unsigned int> prescales; prescales.reserve(npath);
00491 std::vector<unsigned int> hltcounts; hltcounts.reserve(npath);
00492 std::vector<unsigned int> hltaccepts; hltaccepts.reserve(npath);
00493
00494 for(pathIt=pathBeg;pathIt!=pathEnd;++pathIt){
00495 unsigned int hltcount=pathIt->second.hltinput;
00496
00497 hltcounts.push_back(hltcount);
00498 unsigned int hltaccept=pathIt->second.hltaccept;
00499
00500 hltaccepts.push_back(hltaccept);
00501 unsigned int prescale=pathIt->second.prescale;
00502
00503 prescales.push_back(prescale);
00504 }
00505 prescaleblob.resize(sizeof(unsigned int)*npath);
00506 void* prescaleblob_StartAddress = prescaleblob.startingAddress();
00507 std::memmove(prescaleblob_StartAddress,&prescales[0],sizeof(unsigned int)*npath);
00508 hltcountblob.resize(sizeof(unsigned int)*npath);
00509 void* hltcountblob_StartAddress = hltcountblob.startingAddress();
00510 std::memmove(hltcountblob_StartAddress,&hltcounts[0],sizeof(unsigned int)*npath);
00511 hltacceptblob.resize(sizeof(unsigned int)*npath);
00512 void* hltacceptblob_StartAddress = hltacceptblob.startingAddress();
00513 std::memmove(hltacceptblob_StartAddress,&hltaccepts[0],sizeof(unsigned int)*npath);
00514
00515 hltInserter->processNextIteration();
00516 hltInserter->flush();
00517 ++comittedls;
00518 if(comittedls==commitintv){
00519 std::cout<<"\t committing in LS chunck "<<comittedls<<std::endl;
00520 delete hltInserter; hltInserter=0;
00521 lumisession->transaction().commit();
00522 comittedls=0;
00523 std::cout<<"\t committed "<<std::endl;
00524 }else if( hltlscount==(totalcmsls-1) ){
00525 std::cout<<"\t committing at the end"<<std::endl;
00526 delete hltInserter; hltInserter=0;
00527 lumisession->transaction().commit();
00528 std::cout<<"\t done"<<std::endl;
00529 }
00530 }
00531 return hltrundata.data_id;
00532 }
00533 const std::string HLTV32DB::dataType() const{
00534 return "HLTV3";
00535 }
00536 const std::string HLTV32DB::sourceType() const{
00537 return "DB";
00538 }
00539 HLTV32DB::~HLTV32DB(){}
00540 }
00541 #include "RecoLuminosity/LumiProducer/interface/DataPipeFactory.h"
00542 DEFINE_EDM_PLUGIN(lumi::DataPipeFactory,lumi::HLTV32DB,"HLTV32DB");
00543 #endif