retrieve hlt info with 2 queries select count(distinct PATHNAME ) as npath from HLT_SUPERVISOR_LUMISECTIONS_V2 where runnr=110823 and lsnumber=1; select l.PATHNAME,l.LSNUMBER,l.L1PASS,l.PACCEPT,m.PSVALUE from hlt_supervisor_lumisections_v2 l, hlt_supervisor_scalar_map m where l.RUNNR=m.RUNNR and l.PSINDEX=m.PSINDEX and l.PATHNAME=m.PATHNAME and l.RUNNR=83037 order by l.LSNUMBER;
Implements lumi::DataPipe.
Definition at line 55 of file HLT2DB.cc.
References lumi::HLT2DB::hltinfo::cmsluminr, COMMITLSINTERVAL, gather_cfg::cout, python::DBCopy::destsession, Exception, lumi::idDealer::generateNextIDForTable(), lumi::HLT2DB::hltinfo::hltaccept, lumi::HLT2DB::hltinfo::hltconfigid, lumi::HLT2DB::hltinfo::hltinput, lumi::LumiNames::hltTableName(), lumi::DataPipe::m_authpath, lumi::DataPipe::m_dest, lumi::DataPipe::m_source, lumi::HLT2DB::hltinfo::pathname, lumi::HLT2DB::hltinfo::prescale, q2, cond::runnumber, lumi::DBConfig::setAuthentication(), and python::CommonUtils::svc.
{
std::string hltschema("CMS_RUNINFO");
std::string tabname("HLT_SUPERVISOR_LUMISECTIONS_V2");
std::string maptabname("HLT_SUPERVISOR_SCALAR_MAP");
coral::ConnectionService* svc=new coral::ConnectionService;
lumi::DBConfig dbconf(*svc);
if(!m_authpath.empty()){
dbconf.setAuthentication(m_authpath);
}
coral::ISessionProxy* srcsession=svc->connect(m_source, coral::ReadOnly);
coral::ITypeConverter& tpc=srcsession->typeConverter();
tpc.setCppTypeForSqlType("unsigned int","NUMBER(11)");
srcsession->transaction().start(true);
coral::ISchema& hltSchemaHandle=srcsession->schema(hltschema);
if( !hltSchemaHandle.existsTable(tabname) || !hltSchemaHandle.existsTable(maptabname) ){
throw lumi::Exception("missing hlt tables" ,"retrieveData","HLT2DB");
}
std::vector< std::vector<HLT2DB::hltinfo> > hltresult;
coral::AttributeList bindVariableList;
bindVariableList.extend("runnumber",typeid(unsigned int));
bindVariableList.extend("lsnumber",typeid(unsigned int));
bindVariableList["runnumber"].data<unsigned int>()=runnumber;
bindVariableList["lsnumber"].data<unsigned int>()=1;
unsigned int npath=0;
coral::IQuery* q2=srcsession->nominalSchema().newQuery();
coral::AttributeList q2bindVariableList;
q2bindVariableList.extend("runnumber",typeid(unsigned int));
q2bindVariableList["runnumber"].data<unsigned int>()=runnumber;
q2->addToTableList(tabname,"l");
q2->addToTableList(maptabname,"m");
q2->addToOutputList("l.LSNUMBER","lsnumber");
q2->addToOutputList("l.PATHNAME","pathname");
q2->addToOutputList("l.L1PASS","hltinput");
q2->addToOutputList("l.PACCEPT","hltratecounter");
q2->addToOutputList("m.PSVALUE","prescale");
q2->addToOutputList("m.HLTKEY","hltconfigid");
q2->setCondition("l.RUNNR=m.RUNNR and l.PSINDEX=m.PSINDEX and l.PATHNAME=m.PATHNAME and l.RUNNR =:runnumber",q2bindVariableList);
q2->addToOrderList("lsnumber");
q2->setRowCacheSize(10692);
coral::ICursor& cursor2=q2->execute();
unsigned int lastLumiSection=1;
unsigned int currentLumiSection=0;
std::vector<hltinfo> allpaths;
allpaths.reserve(200);
while( cursor2.next() ){
hltinfo pathcontent;
const coral::AttributeList& row=cursor2.currentRow();
currentLumiSection=row["lsnumber"].data<unsigned int>();
pathcontent.cmsluminr=currentLumiSection;
pathcontent.hltinput=row["hltinput"].data<unsigned int>();
pathcontent.hltaccept=row["hltratecounter"].data<unsigned int>();
pathcontent.pathname=row["pathname"].data<std::string>();
pathcontent.prescale=row["prescale"].data<unsigned int>();
pathcontent.hltconfigid=row["hltconfigid"].data<unsigned int>();
if(currentLumiSection != lastLumiSection){
hltresult.push_back(allpaths);
allpaths.clear();
}
lastLumiSection=currentLumiSection;
allpaths.push_back(pathcontent);
npath=allpaths.size();
}
hltresult.push_back(allpaths);
cursor2.close();
delete q2;
srcsession->transaction().commit();
delete srcsession;
unsigned int totalcmsls=hltresult.size();
std::cout<<"inserting totalhltls "<<totalcmsls<<std::endl;
std::map< unsigned long long, std::vector<unsigned long long> > idallocationtable;
coral::ISessionProxy* destsession=svc->connect(m_dest,coral::Update);
coral::ITypeConverter& lumitpc=destsession->typeConverter();
lumitpc.setCppTypeForSqlType("unsigned int","NUMBER(7)");
lumitpc.setCppTypeForSqlType("unsigned int","NUMBER(10)");
lumitpc.setCppTypeForSqlType("unsigned long long","NUMBER(20)");
std::vector< std::vector<HLT2DB::hltinfo> >::const_iterator hltIt;
std::vector< std::vector<HLT2DB::hltinfo> >::const_iterator hltBeg=hltresult.begin();
std::vector< std::vector<HLT2DB::hltinfo> >::const_iterator hltEnd=hltresult.end();
try{
std::cout<<"\t allocating total ids "<<totalcmsls*npath<<std::endl;
destsession->transaction().start(false);
lumi::idDealer idg(destsession->nominalSchema());
unsigned long long hltID = idg.generateNextIDForTable(LumiNames::hltTableName(),totalcmsls*npath)-totalcmsls*npath;
destsession->transaction().commit();
unsigned int hltlscount=0;
for(hltIt=hltBeg;hltIt!=hltEnd;++hltIt,++hltlscount){
std::vector<unsigned long long> pathvec;
pathvec.reserve(200);
std::vector<HLT2DB::hltinfo>::const_iterator pathIt;
std::vector<HLT2DB::hltinfo>::const_iterator pathBeg=hltIt->begin();
std::vector<HLT2DB::hltinfo>::const_iterator pathEnd=hltIt->end();
for(pathIt=pathBeg;pathIt!=pathEnd;++pathIt,++hltID){
pathvec.push_back(hltID);
}
idallocationtable.insert(std::make_pair(hltlscount,pathvec));
}
std::cout<<"\t all ids allocated"<<std::endl;
coral::AttributeList hltData;
hltData.extend("HLT_ID",typeid(unsigned long long));
hltData.extend("RUNNUM",typeid(unsigned int));
hltData.extend("CMSLSNUM",typeid(unsigned int));
hltData.extend("PATHNAME",typeid(std::string));
hltData.extend("INPUTCOUNT",typeid(unsigned int));
hltData.extend("ACCEPTCOUNT",typeid(unsigned int));
hltData.extend("PRESCALE",typeid(unsigned int));
unsigned long long& hlt_id=hltData["HLT_ID"].data<unsigned long long>();
unsigned int& hltrunnum=hltData["RUNNUM"].data<unsigned int>();
unsigned int& cmslsnum=hltData["CMSLSNUM"].data<unsigned int>();
std::string& pathname=hltData["PATHNAME"].data<std::string>();
unsigned int& inputcount=hltData["INPUTCOUNT"].data<unsigned int>();
unsigned int& acceptcount=hltData["ACCEPTCOUNT"].data<unsigned int>();
unsigned int& prescale=hltData["PRESCALE"].data<unsigned int>();
hltlscount=0;
coral::IBulkOperation* hltInserter=0;
unsigned int comittedls=0;
for(hltIt=hltBeg;hltIt!=hltEnd;++hltIt,++hltlscount){
std::vector<HLT2DB::hltinfo>::const_iterator pathIt;
std::vector<HLT2DB::hltinfo>::const_iterator pathBeg=hltIt->begin();
std::vector<HLT2DB::hltinfo>::const_iterator pathEnd=hltIt->end();
if(!destsession->transaction().isActive()){
destsession->transaction().start(false);
coral::ITable& hlttable=destsession->nominalSchema().tableHandle(LumiNames::hltTableName());
hltInserter=hlttable.dataEditor().bulkInsert(hltData,200);
}
unsigned int hltpathcount=0;
for(pathIt=pathBeg;pathIt!=pathEnd;++pathIt,++hltpathcount){
hlt_id = idallocationtable[hltlscount].at(hltpathcount);
hltrunnum = runnumber;
cmslsnum = pathIt->cmsluminr;
pathname = pathIt->pathname;
inputcount = pathIt->hltinput;
acceptcount = pathIt->hltaccept;
prescale = pathIt->prescale;
hltInserter->processNextIteration();
}
hltInserter->flush();
++comittedls;
if(comittedls==HLT2DB::COMMITLSINTERVAL){
std::cout<<"\t committing in LS chunck "<<comittedls<<std::endl;
delete hltInserter; hltInserter=0;
destsession->transaction().commit();
comittedls=0;
std::cout<<"\t committed "<<std::endl;
}else if( hltlscount==(totalcmsls-1) ){
std::cout<<"\t committing at the end"<<std::endl;
delete hltInserter; hltInserter=0;
destsession->transaction().commit();
std::cout<<"\t done"<<std::endl;
}
}
}catch( const coral::Exception& er){
std::cout<<"database problem "<<er.what()<<std::endl;
destsession->transaction().rollback();
delete destsession;
delete svc;
throw er;
}
delete destsession;
delete svc;
}