CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/RecoLuminosity/LumiProducer/plugins/HLTV32DB.cc

Go to the documentation of this file.
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; //commit interval in LS,totalrow=nls*(~200)
00038     const static unsigned int COMMITLSINTERVAL=500; //commit interval in LS
00039     
00040     explicit HLTV32DB(const std::string& dest);
00041     virtual void 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; //order by hltpathid
00053     typedef std::vector< std::map<unsigned int,HLTV32DB::hltinfo,std::less<unsigned int> > > HltResult;
00054     
00055     void writeHltData(coral::ISessionProxy* lumisession,
00056                       unsigned int irunnumber,
00057                       const std::string& source,
00058                       unsigned int npath,
00059                       HltResult::iterator hltBeg,
00060                       HltResult::iterator hltEnd,
00061                       unsigned int commitintv);
00062     void writeHltDataToSchema2(coral::ISessionProxy* lumisession,
00063                                unsigned int irunnumber,
00064                                const std::string& source,
00065                                unsigned int npath,
00066                                HltResult::iterator hltBeg,
00067                                HltResult::iterator hltEnd,
00068                                HltPathMap& hltpathmap,
00069                                unsigned int commitintv);
00070   };//cl HLTV32DB
00071   
00072   //
00073   //implementation
00074   //
00075   
00076   HLTV32DB::HLTV32DB(const std::string& dest):DataPipe(dest){}
00077   void HLTV32DB::retrieveData( unsigned int runnumber){
00078     std::string confdbschema("CMS_HLT");
00079     std::string hltschema("CMS_RUNINFO");
00080     std::string confdbpathtabname("PATHS");
00081     std::string triggerpathtabname("HLT_SUPERVISOR_TRIGGERPATHS");
00082     std::string lstabname("HLT_SUPERVISOR_LUMISECTIONS_V3");
00083     std::string maptabname("HLT_SUPERVISOR_SCALAR_MAP_V2");
00084 
00085     coral::ConnectionService* svc=new coral::ConnectionService;
00086     lumi::DBConfig dbconf(*svc);
00087     if(!m_authpath.empty()){
00088       dbconf.setAuthentication(m_authpath);
00089     }
00090     
00099     //std::cout<<"m_source "<<m_source<<std::endl;
00100     //std::cout<<"m_source "<<m_source<<std::endl;
00101     std::string::size_type cutpos=m_source.find(';');
00102     std::string dbsource=m_source;
00103     std::string csvsource("");
00104     if(cutpos!=std::string::npos){
00105       dbsource=m_source.substr(0,cutpos);
00106       csvsource=m_source.substr(cutpos+1);
00107     }
00108     //std::cout<<"dbsource: "<<dbsource<<" , csvsource: "<<csvsource<<std::endl;
00109     coral::ISessionProxy* srcsession=svc->connect(dbsource, coral::ReadOnly);
00110     coral::ITypeConverter& tpc=srcsession->typeConverter();
00111     tpc.setCppTypeForSqlType("unsigned int","NUMBER(11)");
00112     srcsession->transaction().start(true);
00113     coral::ISchema& hltSchemaHandle=srcsession->schema(hltschema);
00114     coral::ISchema& confdbSchemaHandle=srcsession->schema(confdbschema);
00115     if( !hltSchemaHandle.existsTable(triggerpathtabname) || !hltSchemaHandle.existsTable(lstabname) || !hltSchemaHandle.existsTable(maptabname) ){
00116       throw lumi::Exception("missing hlt tables" ,"retrieveData","HLTV32DB");
00117     }
00118     HltPathMap hltpathmap;
00119     coral::AttributeList bindVariableList;
00120     bindVariableList.extend("runnumber",typeid(unsigned int));
00121     bindVariableList["runnumber"].data<unsigned int>()=runnumber;
00122     coral::IQuery* q1=hltSchemaHandle.tableHandle(triggerpathtabname).newQuery();
00123     coral::AttributeList hltpathid;
00124     hltpathid.extend("hltpathid",typeid(unsigned int));
00125     q1->addToOutputList("distinct PATHID","hltpathid");
00126     q1->setCondition("RUNNUMBER =:runnumber",bindVariableList);
00127     q1->defineOutput(hltpathid);
00128     coral::ICursor& c=q1->execute();
00129     unsigned int npc=0;
00130     while( c.next() ){
00131        npc++;
00132        unsigned int hid=c.currentRow()["hltpathid"].data<unsigned int>();
00133        hltpathmap.insert(std::make_pair(hid,""));
00134     }
00135     delete q1;
00136     HltPathMap::iterator mpit;
00137     HltPathMap::iterator mpitBeg=hltpathmap.begin();
00138     HltPathMap::iterator mpitEnd=hltpathmap.end();
00139     for( mpit=mpitBeg;mpit!=mpitEnd;++mpit){
00140       coral::IQuery* mq=confdbSchemaHandle.newQuery();
00141       coral::AttributeList mqbindVariableList;
00142       mqbindVariableList.extend("pathid",typeid(unsigned int));
00143       mqbindVariableList["pathid"].data<unsigned int>()=mpit->first;
00144       mq->addToTableList(confdbpathtabname);
00145       mq->addToOutputList("NAME","hltpathname");
00146       mq->setCondition("PATHID=:pathid",mqbindVariableList);
00147       coral::ICursor& mqcursor=mq->execute();
00148       while( mqcursor.next() ){
00149         std::string pathname=mqcursor.currentRow()["hltpathname"].data<std::string>();
00150         hltpathmap[mpit->first]=pathname;
00151       }
00152       delete mq;
00153     }
00154     //for( mpit=mpitBeg;mpit!=mpitEnd;++mpit){
00155     //  std::cout<<mpit->first<<" "<<mpit->second<<std::endl;
00156     //}
00157     unsigned int maxls=0;
00158     unsigned int minls=0;
00159     unsigned int nls=0;
00160     coral::IQuery* nq=hltSchemaHandle.tableHandle(lstabname).newQuery();
00161     coral::AttributeList nqbindVariableList;
00162     coral::AttributeList nqout;
00163     nqout.extend("minls",typeid(unsigned int));
00164     nqout.extend("maxls",typeid(unsigned int));
00165     nqbindVariableList.extend("runnumber",typeid(unsigned int));
00166     nqbindVariableList["runnumber"].data<unsigned int>()=runnumber;
00167     nq->addToOutputList("min(lsnumber)","minls");
00168     nq->addToOutputList("max(lsnumber)","maxls");
00169     nq->setCondition("RUNNUMBER =:runnumber",nqbindVariableList);    
00170     nq->defineOutput(nqout);
00171     coral::ICursor& nqcursor=nq->execute();
00172     while( nqcursor.next() ){
00173       minls=nqcursor.currentRow()["minls"].data<unsigned int>();
00174       maxls=nqcursor.currentRow()["maxls"].data<unsigned int>();
00175     }
00176     delete nq;
00177     //std::cout<<"nls "<<nls<<std::endl; 
00178     HltResult hltresult;
00179     nls=maxls-minls+1;
00180     std::cout<<"nls "<<nls<<std::endl;
00181     hltresult.reserve(nls);//
00182     //fix all size
00183     for(unsigned int i=minls;i<=maxls;++i){
00184       if (i==0) continue; //skip ls=0
00185       std::map<unsigned int, HLTV32DB::hltinfo> allpaths;
00186       HltPathMap::iterator aIt;
00187       HltPathMap::iterator aItBeg=hltpathmap.begin();
00188       HltPathMap::iterator aItEnd=hltpathmap.end();
00189       for(aIt=aItBeg;aIt!=aItEnd;++aIt){
00190         HLTV32DB::hltinfo ct;
00191         ct.cmsluminr=i;
00192         ct.pathname=aIt->second;
00193         ct.hltinput=0;
00194         ct.hltaccept=0;
00195         ct.prescale=0;  
00196         allpaths.insert(std::make_pair(aIt->first,ct));
00197       }
00198       hltresult.push_back(allpaths);
00199     }
00200     //std::cout<<"book hltresult size "<<hltresult.size()<<std::endl;
00201     coral::IQuery* jq=hltSchemaHandle.newQuery();
00202     coral::AttributeList jqbindVariableList;
00203     jqbindVariableList.extend("runnumber",typeid(unsigned int));
00204     jqbindVariableList["runnumber"].data<unsigned int>()=runnumber;
00205     coral::AttributeList jqoutput;
00206     jqoutput.extend("lsnumber",typeid(unsigned int));
00207     jqoutput.extend("pathid",typeid(unsigned int));
00208     jqoutput.extend("l1pass",typeid(unsigned int));
00209     jqoutput.extend("paccept",typeid(unsigned int));
00210     jqoutput.extend("psvalue",typeid(unsigned int));
00211     jq->addToTableList(triggerpathtabname,"tr");
00212     jq->addToTableList(lstabname,"ls");
00213     jq->addToTableList(maptabname,"sm");
00214     jq->addToOutputList("tr.LSNUMBER","lsnumber");
00215     jq->addToOutputList("tr.PATHID","pathid");
00216     jq->addToOutputList("tr.L1PASS","l1pass");
00217     jq->addToOutputList("tr.PACCEPT","paccept");
00218     jq->addToOutputList("sm.PSVALUE","psvalue");
00219     jq->setCondition("tr.RUNNUMBER=ls.RUNNUMBER AND tr.LSNUMBER=ls.LSNUMBER and sm.RUNNUMBER=tr.RUNNUMBER and sm.PATHID=tr.PATHID and sm.PSINDEX=ls.PSINDEX and tr.RUNNUMBER=:runnumber",jqbindVariableList);  
00220     jq->defineOutput(jqoutput);
00221     jq->addToOrderList("tr.LSNUMBER");
00222     jq->setRowCacheSize(10692);
00223     coral::ICursor& jqcursor=jq->execute();
00224     bool lscountfromzero=false;
00225     while( jqcursor.next() ){
00226       const coral::AttributeList& row=jqcursor.currentRow();
00227       unsigned int currentLumiSection=row["lsnumber"].data<unsigned int>();
00228       if (currentLumiSection==0){
00229         lscountfromzero=true;
00230       }else{
00231         std::map<unsigned int,hltinfo>& allpathinfo=hltresult.at(currentLumiSection-1);
00232         unsigned int pathid=row["pathid"].data<unsigned int>();
00233         //std::cout<<"look for path id "<<pathid<<std::endl;
00234         hltinfo& pathcontent=allpathinfo[pathid];
00235         pathcontent.hltinput=row["l1pass"].data<unsigned int>();
00236         pathcontent.hltaccept=row["paccept"].data<unsigned int>();
00237         pathcontent.prescale=row["psvalue"].data<unsigned int>();
00238       }
00239     }
00240     if(lscountfromzero) {
00241       std::cout<<"hlt ls count from 0 , we skip/dodge/parry it!"<<std::endl;
00242     }
00243     delete jq;
00244     srcsession->transaction().commit();
00245     delete srcsession;
00246     //
00247     // Write into DB
00248     //
00249     unsigned int npath=hltpathmap.size();    
00250     coral::ISessionProxy* destsession=svc->connect(m_dest,coral::Update);
00251     coral::ITypeConverter& lumitpc=destsession->typeConverter();
00252     lumitpc.setCppTypeForSqlType("unsigned int","NUMBER(7)");
00253     lumitpc.setCppTypeForSqlType("unsigned int","NUMBER(10)");
00254     lumitpc.setCppTypeForSqlType("unsigned long long","NUMBER(20)");
00255 
00256     //for(hltIt=hltItBeg;hltIt!=hltItEnd;++hltIt){
00257     //  std::map<unsigned int,HLTV32DB::hltinfo>::iterator pathIt;
00258     //  std::map<unsigned int,HLTV32DB::hltinfo>::iterator pathItBeg=hltIt->begin();
00259     //  std::map<unsigned int,HLTV32DB::hltinfo>::iterator pathItEnd=hltIt->end();
00260     //  for(pathIt=pathItBeg;pathIt!=pathItEnd;++pathIt){
00261     //  std::cout<<"cmslsnr "<<pathIt->second.cmsluminr<<" "<<pathIt->second.pathname<<" "<<pathIt->second.hltinput<<" "<<pathIt->second.hltaccept<<" "<<pathIt->second.prescale<<std::endl;
00262     //  }
00263     //}
00264     unsigned int totalcmsls=hltresult.size();
00265     std::cout<<"inserting totalhltls "<<totalcmsls<<" total path "<<npath<<std::endl;
00266     //HltResult::iterator hltItBeg=hltresult.begin();
00267     //HltResult::iterator hltItEnd=hltresult.end();
00268     try{     
00269        if(m_mode=="loadoldschema"){
00270           std::cout<<"writing hlt data to old hlt table"<<std::endl;
00271           writeHltData(destsession,runnumber,dbsource,npath,hltresult.begin(),hltresult.end(),COMMITINTERVAL);
00272           std::cout<<"done"<<std::endl;
00273        }
00274        std::cout<<"writing hlt data to new lshlt table"<<std::endl;
00275        writeHltDataToSchema2(destsession,runnumber,dbsource,npath,hltresult.begin(),hltresult.end(), hltpathmap,COMMITLSINTERVAL);
00276        std::cout<<"done"<<std::endl;
00277        delete destsession;
00278        delete svc;
00279     }catch( const coral::Exception& er){
00280        std::cout<<"database problem "<<er.what()<<std::endl;
00281        destsession->transaction().rollback();
00282        delete destsession;
00283        delete svc;
00284        throw er;
00285     }
00286   }
00287   void 
00288   HLTV32DB::writeHltData(coral::ISessionProxy* lumisession,
00289                        unsigned int irunnumber,
00290                        const std::string& source,
00291                        unsigned int npath,
00292                        HltResult::iterator hltItBeg,
00293                        HltResult::iterator hltItEnd,
00294                        unsigned int commitintv){ 
00295     std::map< unsigned long long, std::vector<unsigned long long> > idallocationtable;
00296     unsigned int hltlscount=0;
00297     unsigned int totalcmsls=std::distance(hltItBeg,hltItEnd);
00298     std::cout<<"\t allocating total ids "<<totalcmsls*npath<<std::endl; 
00299     lumisession->transaction().start(false);
00300     lumi::idDealer idg(lumisession->nominalSchema());
00301     unsigned long long hltID = idg.generateNextIDForTable(LumiNames::hltTableName(),totalcmsls*npath)-totalcmsls*npath;
00302     for(HltResult::iterator hltIt=hltItBeg;hltIt!=hltItEnd;++hltIt,++hltlscount){
00303       std::vector<unsigned long long> pathvec;
00304       pathvec.reserve(npath);
00305       for(unsigned int i=0;i<npath;++i,++hltID){
00306         pathvec.push_back(hltID);
00307       }
00308       idallocationtable.insert(std::make_pair(hltlscount,pathvec));
00309     }
00310     std::cout<<"\t all ids allocated"<<std::endl; 
00311     
00312     coral::AttributeList hltData;
00313     hltData.extend("HLT_ID",typeid(unsigned long long));
00314     hltData.extend("RUNNUM",typeid(unsigned int));
00315     hltData.extend("CMSLSNUM",typeid(unsigned int));
00316     hltData.extend("PATHNAME",typeid(std::string));
00317     hltData.extend("INPUTCOUNT",typeid(unsigned int));
00318     hltData.extend("ACCEPTCOUNT",typeid(unsigned int));
00319     hltData.extend("PRESCALE",typeid(unsigned int));
00320     
00321     //loop over lumi LS
00322     unsigned long long& hlt_id=hltData["HLT_ID"].data<unsigned long long>();
00323     unsigned int& hltrunnum=hltData["RUNNUM"].data<unsigned int>();
00324     unsigned int& cmslsnum=hltData["CMSLSNUM"].data<unsigned int>();
00325     std::string& pathname=hltData["PATHNAME"].data<std::string>();
00326     unsigned int& inputcount=hltData["INPUTCOUNT"].data<unsigned int>();
00327     unsigned int& acceptcount=hltData["ACCEPTCOUNT"].data<unsigned int>();
00328     unsigned int& prescale=hltData["PRESCALE"].data<unsigned int>();
00329     hltlscount=0;
00330     coral::IBulkOperation* hltInserter=0; 
00331     unsigned int comittedls=0;
00332     for(HltResult::iterator hltIt=hltItBeg;hltIt!=hltItEnd;++hltIt,++hltlscount){
00333       std::map<unsigned int,HLTV32DB::hltinfo>::const_iterator pathIt;
00334       std::map<unsigned int,HLTV32DB::hltinfo>::const_iterator pathBeg=hltIt->begin();
00335       std::map<unsigned int,HLTV32DB::hltinfo>::const_iterator pathEnd=hltIt->end();
00336       if(!lumisession->transaction().isActive()){ 
00337         lumisession->transaction().start(false);
00338         coral::ITable& hlttable=lumisession->nominalSchema().tableHandle(LumiNames::hltTableName());
00339         hltInserter=hlttable.dataEditor().bulkInsert(hltData,npath);
00340       }else{
00341         if(hltIt==hltItBeg){
00342           coral::ITable& hlttable=lumisession->nominalSchema().tableHandle(LumiNames::hltTableName());
00343           hltInserter=hlttable.dataEditor().bulkInsert(hltData,npath);
00344         }
00345       }
00346       unsigned int hltpathcount=0;
00347       for(pathIt=pathBeg;pathIt!=pathEnd;++pathIt,++hltpathcount){
00348         hlt_id = idallocationtable[hltlscount].at(hltpathcount);
00349         hltrunnum = irunnumber;
00350         cmslsnum = pathIt->second.cmsluminr;
00351         pathname = pathIt->second.pathname;
00352         inputcount = pathIt->second.hltinput;
00353         acceptcount = pathIt->second.hltaccept;
00354         prescale = pathIt->second.prescale;
00355         hltInserter->processNextIteration();
00356       }
00357       hltInserter->flush();
00358       ++comittedls;
00359       if(comittedls==commitintv){
00360         std::cout<<"\t committing in LS chunck "<<comittedls<<std::endl; 
00361         delete hltInserter; hltInserter=0;
00362         lumisession->transaction().commit();
00363         comittedls=0;
00364         std::cout<<"\t committed "<<std::endl; 
00365       }else if( hltlscount==(totalcmsls-1) ){
00366         std::cout<<"\t committing at the end"<<std::endl; 
00367         delete hltInserter; hltInserter=0;
00368         lumisession->transaction().commit();
00369         std::cout<<"\t done"<<std::endl; 
00370       }
00371     }
00372   }
00373  void 
00374  HLTV32DB::writeHltDataToSchema2(coral::ISessionProxy* lumisession,
00375                         unsigned int irunnumber,
00376                         const std::string& source,
00377                         unsigned int npath,
00378                         HltResult::iterator hltItBeg,
00379                         HltResult::iterator hltItEnd,
00380                         HltPathMap& hltpathmap,
00381                         unsigned int commitintv){
00382    HltResult::iterator hltIt;
00383    unsigned int totalcmsls=std::distance(hltItBeg,hltItEnd);
00384    std::cout<<"inserting totalcmsls "<<totalcmsls<<std::endl;
00385    coral::AttributeList lshltData;
00386    lshltData.extend("DATA_ID",typeid(unsigned long long));
00387    lshltData.extend("RUNNUM",typeid(unsigned int));
00388    lshltData.extend("CMSLSNUM",typeid(unsigned int));
00389    lshltData.extend("PRESCALEBLOB",typeid(coral::Blob));
00390    lshltData.extend("HLTCOUNTBLOB",typeid(coral::Blob));
00391    lshltData.extend("HLTACCEPTBLOB",typeid(coral::Blob));
00392    unsigned long long& data_id=lshltData["DATA_ID"].data<unsigned long long>();
00393    unsigned int& hltrunnum=lshltData["RUNNUM"].data<unsigned int>();
00394    unsigned int& cmslsnum=lshltData["CMSLSNUM"].data<unsigned int>();
00395    coral::Blob& prescaleblob=lshltData["PRESCALEBLOB"].data<coral::Blob>();
00396    coral::Blob& hltcountblob=lshltData["HLTCOUNTBLOB"].data<coral::Blob>();
00397    coral::Blob& hltacceptblob=lshltData["HLTACCEPTBLOB"].data<coral::Blob>();
00398 
00399    unsigned long long branch_id=3;
00400    std::string branch_name("DATA");
00401    lumi::RevisionDML revisionDML;
00402    lumi::RevisionDML::HltEntry hltrundata;
00403    std::stringstream op;
00404    op<<irunnumber;
00405    std::string runnumberStr=op.str();
00406    lumisession->transaction().start(false);
00407    hltrundata.entry_name=runnumberStr;
00408    hltrundata.source=source;
00409    hltrundata.runnumber=irunnumber;
00410    hltrundata.npath=npath;
00411    std::string pathnames;
00412    HltPathMap::iterator hltpathmapIt;
00413    HltPathMap::iterator hltpathmapItBeg=hltpathmap.begin();
00414    HltPathMap::iterator hltpathmapItEnd=hltpathmap.end();
00415    for(hltpathmapIt=hltpathmapItBeg;hltpathmapIt!=hltpathmapItEnd;++hltpathmapIt){
00416      if(hltpathmapIt!=hltpathmapItBeg){
00417        pathnames+=std::string(",");
00418      }     
00419      pathnames+=hltpathmapIt->second;
00420    }
00421    std::cout<<"\tpathnames "<<pathnames<<std::endl;
00422    hltrundata.pathnames=pathnames;
00423    hltrundata.entry_id=revisionDML.getEntryInBranchByName(lumisession->nominalSchema(),lumi::LumiNames::hltdataTableName(),runnumberStr,branch_name);
00424    if(hltrundata.entry_id==0){
00425      revisionDML.bookNewEntry(lumisession->nominalSchema(),LumiNames::hltdataTableName(),hltrundata);
00426      std::cout<<"hltrundata revision_id "<<hltrundata.revision_id<<" entry_id "<<hltrundata.entry_id<<" data_id "<<hltrundata.data_id<<std::endl;
00427      revisionDML.addEntry(lumisession->nominalSchema(),LumiNames::hltdataTableName(),hltrundata,branch_id,branch_name);
00428    }else{
00429      revisionDML.bookNewRevision(lumisession->nominalSchema(),LumiNames::hltdataTableName(),hltrundata);
00430      std::cout<<"hltrundata revision_id "<<hltrundata.revision_id<<" entry_id "<<hltrundata.entry_id<<" data_id "<<hltrundata.data_id<<std::endl;
00431      revisionDML.addRevision(lumisession->nominalSchema(),LumiNames::hltdataTableName(),hltrundata,branch_id,branch_name);
00432    }
00433    std::cout<<"inserting hltrundata"<<std::endl;
00434    revisionDML.insertHltRunData(lumisession->nominalSchema(),hltrundata);
00435    std::cout<<"inserting lshlt data"<<std::endl;
00436 
00437    unsigned int hltlscount=0;
00438    coral::IBulkOperation* hltInserter=0; 
00439    unsigned int comittedls=0;
00440    for(HltResult::iterator hltIt=hltItBeg;hltIt!=hltItEnd;++hltIt,++hltlscount){
00441      unsigned int cmslscount=hltlscount+1;
00442      std::map<unsigned int,HLTV32DB::hltinfo,std::less<unsigned int> >::const_iterator pathIt;
00443      std::map<unsigned int,HLTV32DB::hltinfo,std::less<unsigned int> >::const_iterator pathBeg=hltIt->begin();
00444      std::map<unsigned int,HLTV32DB::hltinfo,std::less<unsigned int> >::const_iterator pathEnd=hltIt->end();
00445      if(!lumisession->transaction().isActive()){ 
00446        lumisession->transaction().start(false);
00447        coral::ITable& hlttable=lumisession->nominalSchema().tableHandle(LumiNames::lshltTableName());
00448        hltInserter=hlttable.dataEditor().bulkInsert(lshltData,npath);
00449      }else{
00450        if(hltIt==hltItBeg){
00451          coral::ITable& hlttable=lumisession->nominalSchema().tableHandle(LumiNames::lshltTableName());
00452          hltInserter=hlttable.dataEditor().bulkInsert(lshltData,npath);
00453        }
00454      }
00455      data_id = hltrundata.data_id;
00456      hltrunnum = irunnumber;
00457      cmslsnum = cmslscount;
00458      std::vector<unsigned int> prescales; prescales.reserve(npath);
00459      std::vector<unsigned int> hltcounts; hltcounts.reserve(npath);
00460      std::vector<unsigned int> hltaccepts; hltaccepts.reserve(npath);
00461 
00462      for(pathIt=pathBeg;pathIt!=pathEnd;++pathIt){
00463        unsigned int hltcount=pathIt->second.hltinput;
00464        //std::cout<<"hltcount "<<hltcount<<std::endl;
00465        hltcounts.push_back(hltcount);
00466        unsigned int hltaccept=pathIt->second.hltaccept;
00467        //std::cout<<"hltaccept "<<hltaccept<<std::endl;       
00468        hltaccepts.push_back(hltaccept);
00469        unsigned int prescale=pathIt->second.prescale;
00470        //std::cout<<"prescale "<<prescale<<std::endl;
00471        prescales.push_back(prescale);
00472      }
00473      prescaleblob.resize(sizeof(unsigned int)*npath);
00474      void* prescaleblob_StartAddress = prescaleblob.startingAddress();
00475      std::memmove(prescaleblob_StartAddress,&prescales[0],sizeof(unsigned int)*npath);
00476      hltcountblob.resize(sizeof(unsigned int)*npath);
00477      void* hltcountblob_StartAddress = hltcountblob.startingAddress();
00478      std::memmove(hltcountblob_StartAddress,&hltcounts[0],sizeof(unsigned int)*npath);
00479      hltacceptblob.resize(sizeof(unsigned int)*npath);
00480      void* hltacceptblob_StartAddress = hltacceptblob.startingAddress();
00481      std::memmove(hltacceptblob_StartAddress,&hltaccepts[0],sizeof(unsigned int)*npath);
00482 
00483      hltInserter->processNextIteration();
00484      hltInserter->flush();
00485      ++comittedls;
00486      if(comittedls==commitintv){
00487        std::cout<<"\t committing in LS chunck "<<comittedls<<std::endl; 
00488        delete hltInserter; hltInserter=0;
00489        lumisession->transaction().commit();
00490        comittedls=0;
00491        std::cout<<"\t committed "<<std::endl; 
00492      }else if( hltlscount==(totalcmsls-1) ){
00493        std::cout<<"\t committing at the end"<<std::endl; 
00494        delete hltInserter; hltInserter=0;
00495        lumisession->transaction().commit();
00496        std::cout<<"\t done"<<std::endl; 
00497      }
00498    }
00499  }
00500   const std::string HLTV32DB::dataType() const{
00501     return "HLTV3";
00502   }
00503   const std::string HLTV32DB::sourceType() const{
00504     return "DB";
00505   }
00506   HLTV32DB::~HLTV32DB(){}
00507 }//ns lumi
00508 #include "RecoLuminosity/LumiProducer/interface/DataPipeFactory.h"
00509 DEFINE_EDM_PLUGIN(lumi::DataPipeFactory,lumi::HLTV32DB,"HLTV32DB");
00510 #endif