Classes | |
struct | beamData |
struct | LumiSource |
struct | PerBXData |
struct | PerLumiData |
Public Types | |
typedef std::vector< PerLumiData > | LumiResult |
Public Member Functions | |
virtual const std::string | dataType () const |
Lumi2DB (const std::string &dest) | |
virtual void | retrieveData (unsigned int) |
virtual const std::string | sourceType () const |
virtual | ~Lumi2DB () |
Static Public Attributes | |
static const unsigned int | COMMITLSINTERVAL = 500 |
static const unsigned int | NORMFACTOR = 6370 |
Private Member Functions | |
float | applyCalibration (float varToCalibrate) const |
bool | isLumiDataValid (LumiResult::iterator lumiBeg, LumiResult::iterator lumiEnd) |
void | parseSourceString (lumi::Lumi2DB::LumiSource &result) const |
void | retrieveBeamIntensity (HCAL_HLX::DIP_COMBINED_DATA *dataPtr, Lumi2DB::beamData &b) const |
void | writeAllLumiData (coral::ISessionProxy *session, unsigned int irunnumber, const std::string &ilumiversion, LumiResult::iterator lumiBeg, LumiResult::iterator lumiEnd) |
void | writeBeamIntensityOnly (coral::ISessionProxy *session, unsigned int irunnumber, const std::string &ilumiversion, LumiResult::iterator lumiBeg, LumiResult::iterator lumiEnd) |
Definition at line 32 of file Lumi2DB.cc.
typedef std::vector<PerLumiData> lumi::Lumi2DB::LumiResult |
Definition at line 83 of file Lumi2DB.cc.
lumi::Lumi2DB::Lumi2DB | ( | const std::string & | dest | ) |
Definition at line 397 of file Lumi2DB.cc.
lumi::Lumi2DB::~Lumi2DB | ( | ) | [virtual] |
Definition at line 673 of file Lumi2DB.cc.
{}
float lumi::Lumi2DB::applyCalibration | ( | float | varToCalibrate | ) | const [private] |
Definition at line 98 of file Lumi2DB.cc.
References NORMFACTOR.
{ return float(varToCalibrate)*float(lumi::Lumi2DB::NORMFACTOR); }
const std::string lumi::Lumi2DB::dataType | ( | ) | const [virtual] |
bool lumi::Lumi2DB::isLumiDataValid | ( | LumiResult::iterator | lumiBeg, |
LumiResult::iterator | lumiEnd | ||
) | [private] |
Definition at line 102 of file Lumi2DB.cc.
{ lumi::Lumi2DB::LumiResult::iterator lumiIt; int nBad=0; for(lumiIt=lumiBeg;lumiIt!=lumiEnd;++lumiIt){ //std::cout<<"instlumi before calib "<<lumiIt->instlumi<<std::endl; if(lumiIt->instlumi<=1.0e-8){//cut before calib ++nBad; } } if(nBad==std::distance(lumiBeg,lumiEnd)){ return false; } return true; }
void lumi::Lumi2DB::parseSourceString | ( | lumi::Lumi2DB::LumiSource & | result | ) | const [private] |
Definition at line 400 of file Lumi2DB.cc.
References lumi::Lumi2DB::LumiSource::datestr, Exception, lumi::Lumi2DB::LumiSource::firstsection, csv2json::pieces, pos, lumi::Lumi2DB::LumiSource::run, and lumi::Lumi2DB::LumiSource::version.
{ //parse lumi source file name if(m_source.length()==0) throw lumi::Exception("lumi source is not set","parseSourceString","Lumi2DB"); //std::cout<<"source "<<m_source<<std::endl; size_t tempIndex = m_source.find_last_of("."); size_t nameLength = m_source.length(); std::string FileSuffix= m_source.substr(tempIndex+1,nameLength - tempIndex); std::string::size_type lastPos=m_source.find_first_not_of("_",0); std::string::size_type pos = m_source.find_first_of("_",lastPos); std::vector<std::string> pieces; while( std::string::npos != pos || std::string::npos != lastPos){ pieces.push_back(m_source.substr(lastPos,pos-lastPos)); lastPos=m_source.find_first_not_of("_",pos); pos=m_source.find_first_of("_",lastPos); } if( pieces[1]!="LUMI" || pieces[2]!="RAW" || FileSuffix!="root"){ throw lumi::Exception("not lumi raw data file CMS_LUMI_RAW","parseSourceString","Lumi2DB"); } std::strcpy(result.datestr,pieces[3].c_str()); std::strcpy(result.version,pieces[5].c_str()); //std::cout<<"version : "<<result.version<<std::endl; result.run = atoi(pieces[4].c_str()); //std::cout<<"run : "<<result.run<<std::endl; result.firstsection = atoi(pieces[5].c_str()); //std::cout<<"first section : "<< result.firstsection<<std::endl; }
void lumi::Lumi2DB::retrieveBeamIntensity | ( | HCAL_HLX::DIP_COMBINED_DATA * | dataPtr, |
Lumi2DB::beamData & | b | ||
) | const [private] |
Definition at line 428 of file Lumi2DB.cc.
References a, HCAL_HLX::DIP_COMBINED_DATA::Beam, lumi::Lumi2DB::beamData::beamintensity_1, lumi::Lumi2DB::beamData::beamintensity_2, lumi::Lumi2DB::beamData::bxindex, gather_cfg::cout, i, lumi::N_BX, and lumi::Lumi2DB::beamData::nlivebx.
{ if(dataPtr==0){ std::cout<<"HCAL_HLX::DIP_COMBINED_DATA* dataPtr=0"<<std::endl; b.bxindex=0; b.beamintensity_1=0; b.beamintensity_2=0; b.nlivebx=0; }else{ b.bxindex=(short*)::malloc(sizeof(short)*lumi::N_BX); b.beamintensity_1=(float*)::malloc(sizeof(float)*lumi::N_BX); b.beamintensity_2=(float*)::malloc(sizeof(float)*lumi::N_BX); short a=0;//a is position in lumidetail array for(unsigned int i=0;i<lumi::N_BX;++i){ if(i==0 && (dataPtr->Beam[0].averageBunchIntensities[0]>0 || dataPtr->Beam[1].averageBunchIntensities[0]>0) ){ b.bxindex[a]=0; b.beamintensity_1[a]=dataPtr->Beam[0].averageBunchIntensities[0]; b.beamintensity_2[a]=dataPtr->Beam[1].averageBunchIntensities[0]; ++a; continue; } if(dataPtr->Beam[0].averageBunchIntensities[i-1]>0 || dataPtr->Beam[1].averageBunchIntensities[i-1]>0){ b.bxindex[a]=i; b.beamintensity_1[a]=dataPtr->Beam[0].averageBunchIntensities[i-1]; b.beamintensity_2[a]=dataPtr->Beam[1].averageBunchIntensities[i-1]; ++a; //if(i!=0){ // std::cout<<"beam intensity "<<dataPtr->sectionNumber<<" "<<dataPtr->timestamp-1262300400<<" "<<(i-1)*10+1<<" "<<b.beamintensity_1[a]<<" "<<b.beamintensity_2[a]<<std::endl; //} } } b.nlivebx=a; } }
void lumi::Lumi2DB::retrieveData | ( | unsigned int | runnumber | ) | [virtual] |
if(bOCC1.lumivalue*6.370>1.0e-04){ if(i!=0){ std::cout<<i<<" detail "<<(i-1)*10+1<<" "<<(timestp-1262300400)<<" "<<bOCC1.lumivalue*6.37<<" "<<bOCC1.lumierr*6.37<<std::endl; } }
Implements lumi::DataPipe.
Definition at line 464 of file Lumi2DB.cc.
References b, HCAL_HLX::LUMI_SECTION_HEADER::bCMSLive, lumi::Lumi2DB::PerLumiData::beamenergy, lumi::Lumi2DB::PerLumiData::beamintensity_1, lumi::Lumi2DB::PerLumiData::beamintensity_2, lumi::Lumi2DB::PerLumiData::beammode, lumi::Lumi2DB::PerLumiData::bxET, lumi::Lumi2DB::PerLumiData::bxindex, lumi::Lumi2DB::PerLumiData::bxOCC1, lumi::Lumi2DB::PerLumiData::bxOCC2, lumi::Lumi2DB::PerLumiData::cmsalive, lumi::Lumi2DB::PerLumiData::cmslsnr, gather_cfg::cout, HCAL_HLX::LUMI_SUMMARY::DeadTimeNormalization, lumi::Lumi2DB::PerLumiData::dtnorm, lumi::Lumi2DB::beamData::energy, HCAL_HLX::LUMI_DETAIL::ETLumi, HCAL_HLX::LUMI_DETAIL::ETLumiErr, HCAL_HLX::LUMI_DETAIL::ETLumiQlty, Exception, h, i, HCAL_HLX::LUMI_SUMMARY::InstantLumi, HCAL_HLX::LUMI_SUMMARY::InstantLumiErr, HCAL_HLX::LUMI_SUMMARY::InstantLumiQlty, lumi::Lumi2DB::PerLumiData::instlumi, lumi::Lumi2DB::PerLumiData::instlumierror, lumi::Lumi2DB::PerLumiData::lhcnorm, HCAL_HLX::LUMI_SUMMARY::LHCNormalization, lumi::Lumi2DB::PerBXData::lumierr, tablePrinter::lumiheader, lumi::Lumi2DB::PerLumiData::lumilsnr, lumi::Lumi2DB::PerBXData::lumiquality, lumi::Lumi2DB::PerLumiData::lumisectionquality, lumi::Lumi2DB::PerBXData::lumivalue, lumi::Lumi2DB::beamData::mode, lumi::N_BX, lumi::Lumi2DB::PerLumiData::nlivebx, lumi::Lumi2DB::PerLumiData::numorbit, HCAL_HLX::LUMI_SECTION_HEADER::numOrbits, HCAL_HLX::LUMI_DETAIL::OccLumi, HCAL_HLX::LUMI_DETAIL::OccLumiErr, HCAL_HLX::LUMI_DETAIL::OccLumiQlty, lumi::Lumi2DB::LumiSource::run, HCAL_HLX::LUMI_SECTION_HEADER::sectionNumber, python::CommonUtils::session, lumi::DBConfig::setAuthentication(), LaserTracksInput_cfi::source, HCAL_HLX::LUMI_SECTION_HEADER::startOrbit, lumi::Lumi2DB::PerLumiData::startorbit, python::CommonUtils::svc, lumi::Lumi2DB::LumiSource::version, and lumi::Exception::what().
{ lumi::Lumi2DB::LumiResult lumiresult; //check filename is in lumiraw format lumi::Lumi2DB::LumiSource filenamecontent; try{ parseSourceString(filenamecontent); }catch(const lumi::Exception& er){ std::cout<<er.what()<<std::endl; throw er; } if( filenamecontent.run!=runnumber ){ throw lumi::Exception("runnumber in file name does not match requested run number","retrieveData","Lumi2DB"); } TFile* source=TFile::Open(m_source.c_str(),"READ"); TTree *hlxtree = (TTree*)source->Get("HLXData"); if(!hlxtree){ throw lumi::Exception(std::string("non-existing HLXData "),"retrieveData","Lumi2DB"); } //hlxtree->Print(); std::auto_ptr<HCAL_HLX::LUMI_SECTION> localSection(new HCAL_HLX::LUMI_SECTION); HCAL_HLX::LUMI_SECTION_HEADER* lumiheader = &(localSection->hdr); HCAL_HLX::LUMI_SUMMARY* lumisummary = &(localSection->lumiSummary); HCAL_HLX::LUMI_DETAIL* lumidetail = &(localSection->lumiDetail); hlxtree->SetBranchAddress("Header.",&lumiheader); hlxtree->SetBranchAddress("Summary.",&lumisummary); hlxtree->SetBranchAddress("Detail.",&lumidetail); size_t nentries=hlxtree->GetEntries(); //source->GetListOfKeys()->Print(); std::map<unsigned int, Lumi2DB::beamData> dipmap; TTree *diptree= (TTree*)source->Get("DIPCombined"); if(diptree){ //throw lumi::Exception(std::string("non-existing DIPData "),"retrieveData","Lumi2DB"); std::auto_ptr<HCAL_HLX::DIP_COMBINED_DATA> dipdata(new HCAL_HLX::DIP_COMBINED_DATA); diptree->SetBranchAddress("DIPCombined.",&dipdata); size_t ndipentries=diptree->GetEntries(); for(size_t i=0;i<ndipentries;++i){ diptree->GetEntry(i); beamData b; //std::cout<<"Beam Mode : "<<dipdata->beamMode<<"\n"; //std::cout<<"Beam Energy : "<<dipdata->Energy<<"\n"; //std::cout<<"sectionUmber : "<<dipdata->sectionNumber<<"\n"; unsigned int dipls=dipdata->sectionNumber; if (std::string(dipdata->beamMode).empty()){ b.mode="N/A"; }else{ b.mode=dipdata->beamMode; } b.energy=dipdata->Energy; this->retrieveBeamIntensity(dipdata.get(),b); dipmap.insert(std::make_pair(dipls,b)); } }else{ for(size_t i=0;i<nentries;++i){ beamData b; b.mode="N/A"; b.energy=0.0; this->retrieveBeamIntensity(0,b); dipmap.insert(std::make_pair(i,b)); } } //diptree->Print(); size_t ncmslumi=0; std::cout<<"processing total lumi lumisection "<<nentries<<std::endl; //size_t lumisecid=0; //unsigned int lumilumisecid=0; //runnumber=lumiheader->runNumber; // //hardcode the first LS is always alive // for(size_t i=0;i<nentries;++i){ lumi::Lumi2DB::PerLumiData h; h.cmsalive=1; hlxtree->GetEntry(i); //std::cout<<"live flag "<<lumiheader->bCMSLive <<std::endl; if( !lumiheader->bCMSLive && i!=0){ std::cout<<"\t non-CMS LS "<<lumiheader->sectionNumber<<" "; h.cmsalive=0; } ++ncmslumi; h.bxET.reserve(lumi::N_BX); h.bxOCC1.reserve(lumi::N_BX); h.bxOCC2.reserve(lumi::N_BX); //runnumber=lumiheader->runNumber; //if(runnumber!=m_run) throw std::runtime_error(std::string("requested run ")+this->int2str(m_run)+" does not match runnumber in the data header "+this->int2str(runnumber)); h.lumilsnr=lumiheader->sectionNumber; std::map<unsigned int , Lumi2DB::beamData >::iterator beamIt=dipmap.find(h.lumilsnr); if ( beamIt!=dipmap.end() ){ h.beammode=beamIt->second.mode; h.beamenergy=beamIt->second.energy; h.nlivebx=beamIt->second.nlivebx; if(h.nlivebx!=0){ h.bxindex=(short*)malloc(sizeof(short)*h.nlivebx); h.beamintensity_1=(float*)malloc(sizeof(float)*h.nlivebx); h.beamintensity_2=(float*)malloc(sizeof(float)*h.nlivebx); if(h.bxindex==0 || h.beamintensity_1==0 || h.beamintensity_2==0){ std::cout<<"malloc failed"<<std::endl; } //std::cout<<"h.bxindex size "<<sizeof(short)*h.nlivebx<<std::endl; //std::cout<<"h.beamintensity_1 size "<<sizeof(float)*h.nlivebx<<std::endl; //std::cout<<"h.beamintensity_2 size "<<sizeof(float)*h.nlivebx<<std::endl; std::memmove(h.bxindex,beamIt->second.bxindex,sizeof(short)*h.nlivebx); std::memmove(h.beamintensity_1,beamIt->second.beamintensity_1,sizeof(float)*h.nlivebx); std::memmove(h.beamintensity_2,beamIt->second.beamintensity_2,sizeof(float)*h.nlivebx); ::free(beamIt->second.bxindex);beamIt->second.bxindex=0; ::free(beamIt->second.beamintensity_1);beamIt->second.beamintensity_1=0; ::free(beamIt->second.beamintensity_2);beamIt->second.beamintensity_2=0; }else{ //std::cout<<"h.nlivebx is zero"<<std::endl; h.bxindex=0; h.beamintensity_1=0; h.beamintensity_2=0; } }else{ h.beammode="N/A"; h.beamenergy=0.0; h.nlivebx=0; h.bxindex=0; h.beamintensity_1=0; h.beamintensity_2=0; } h.startorbit=lumiheader->startOrbit; h.numorbit=lumiheader->numOrbits; if(h.cmsalive==0){ h.cmslsnr=0; //the dead ls has cmsls number=0 }else{ h.cmslsnr=ncmslumi;//we guess cms lumils } h.instlumi=lumisummary->InstantLumi; //std::cout<<"instant lumi "<<lumisummary->InstantLumi<<std::endl; h.instlumierror=lumisummary->InstantLumiErr; h.lumisectionquality=lumisummary->InstantLumiQlty; h.dtnorm=lumisummary->DeadTimeNormalization; h.lhcnorm=lumisummary->LHCNormalization; //unsigned int timestp=lumiheader->timestamp; //std::cout<<"cmslsnum "<<ncmslumi<<"timestp "<<timestp<<std::endl; for(size_t i=0;i<lumi::N_BX;++i){ lumi::Lumi2DB::PerBXData bET; lumi::Lumi2DB::PerBXData bOCC1; lumi::Lumi2DB::PerBXData bOCC2; //bET.idx=i+1; bET.lumivalue=lumidetail->ETLumi[i]; bET.lumierr=lumidetail->ETLumiErr[i]; bET.lumiquality=lumidetail->ETLumiQlty[i]; h.bxET.push_back(bET); //bOCC1.idx=i+1; bOCC1.lumivalue=lumidetail->OccLumi[0][i]; bOCC1.lumierr=lumidetail->OccLumiErr[0][i]; bOCC1.lumiquality=lumidetail->OccLumiQlty[0][i]; h.bxOCC1.push_back(bOCC1); //bOCC2.idx=i+1; bOCC2.lumivalue=lumidetail->OccLumi[1][i]; bOCC2.lumierr=lumidetail->OccLumiErr[1][i]; bOCC2.lumiquality=lumidetail->OccLumiQlty[1][i]; h.bxOCC2.push_back(bOCC2); } lumiresult.push_back(h); } std::cout<<std::endl; if ( isLumiDataValid(lumiresult.begin(),lumiresult.end()) ){ coral::ConnectionService* svc=new coral::ConnectionService; lumi::DBConfig dbconf(*svc); if(!m_authpath.empty()){ dbconf.setAuthentication(m_authpath); } coral::ISessionProxy* session=svc->connect(m_dest,coral::Update); coral::ITypeConverter& tpc=session->typeConverter(); tpc.setCppTypeForSqlType("unsigned int","NUMBER(10)"); try{ const std::string lversion(filenamecontent.version); if(m_mode==std::string("beamintensity_only")){ writeBeamIntensityOnly(session,runnumber,lversion,lumiresult.begin(),lumiresult.end()); }else{ writeAllLumiData(session,runnumber,lversion,lumiresult.begin(),lumiresult.end()); } }catch( const coral::Exception& er){ session->transaction().rollback(); delete session; delete svc; throw er; } delete session; delete svc; }else{ std::cout<<"no valid lumi data found, quit"<<std::endl; throw lumi::Exception("no valid lumi data found","retrieveData","Lumi2DB"); } }
const std::string lumi::Lumi2DB::sourceType | ( | ) | const [virtual] |
void lumi::Lumi2DB::writeAllLumiData | ( | coral::ISessionProxy * | session, |
unsigned int | irunnumber, | ||
const std::string & | ilumiversion, | ||
LumiResult::iterator | lumiBeg, | ||
LumiResult::iterator | lumiEnd | ||
) | [private] |
Definition at line 193 of file Lumi2DB.cc.
References COMMITLSINTERVAL, gather_cfg::cout, lumi::idDealer::generateNextIDForTable(), j, gen::k, lumi::LumiNames::lumidetailTableName(), lumi::LumiNames::lumisummaryTableName(), ExpressReco_HICollisions_FallBack::lumiversion, lumi::N_BX, and lumi::N_LUMIALGO.
{ coral::AttributeList summaryData; coral::AttributeList detailData; summaryData.extend("LUMISUMMARY_ID",typeid(unsigned long long)); summaryData.extend("RUNNUM",typeid(unsigned int)); summaryData.extend("CMSLSNUM",typeid(unsigned int)); summaryData.extend("LUMILSNUM",typeid(unsigned int)); summaryData.extend("LUMIVERSION",typeid(std::string)); summaryData.extend("DTNORM",typeid(float)); summaryData.extend("LHCNORM",typeid(float)); summaryData.extend("INSTLUMI",typeid(float)); summaryData.extend("INSTLUMIERROR",typeid(float)); summaryData.extend("INSTLUMIQUALITY",typeid(short)); summaryData.extend("LUMISECTIONQUALITY",typeid(short)); summaryData.extend("CMSALIVE",typeid(short)); summaryData.extend("STARTORBIT",typeid(unsigned int)); summaryData.extend("NUMORBIT",typeid(unsigned int)); summaryData.extend("BEAMENERGY",typeid(float)); summaryData.extend("BEAMSTATUS",typeid(std::string)); summaryData.extend("CMSBXINDEXBLOB",typeid(coral::Blob)); summaryData.extend("BEAMINTENSITYBLOB_1",typeid(coral::Blob)); summaryData.extend("BEAMINTENSITYBLOB_2",typeid(coral::Blob)); detailData.extend("LUMIDETAIL_ID",typeid(unsigned long long)); detailData.extend("LUMISUMMARY_ID",typeid(unsigned long long)); detailData.extend("BXLUMIVALUE",typeid(coral::Blob)); detailData.extend("BXLUMIERROR",typeid(coral::Blob)); detailData.extend("BXLUMIQUALITY",typeid(coral::Blob)); detailData.extend("ALGONAME",typeid(std::string)); unsigned long long& lumisummary_id=summaryData["LUMISUMMARY_ID"].data<unsigned long long>(); unsigned int& lumirunnum = summaryData["RUNNUM"].data<unsigned int>(); std::string& lumiversion = summaryData["LUMIVERSION"].data<std::string>(); float& dtnorm = summaryData["DTNORM"].data<float>(); float& lhcnorm = summaryData["LHCNORM"].data<float>(); float& instlumi = summaryData["INSTLUMI"].data<float>(); float& instlumierror = summaryData["INSTLUMIERROR"].data<float>(); short& instlumiquality = summaryData["INSTLUMIQUALITY"].data<short>(); short& lumisectionquality = summaryData["LUMISECTIONQUALITY"].data<short>(); short& alive = summaryData["CMSALIVE"].data<short>(); unsigned int& lumilsnr = summaryData["LUMILSNUM"].data<unsigned int>(); unsigned int& cmslsnr = summaryData["CMSLSNUM"].data<unsigned int>(); unsigned int& startorbit = summaryData["STARTORBIT"].data<unsigned int>(); unsigned int& numorbit = summaryData["NUMORBIT"].data<unsigned int>(); float& beamenergy = summaryData["BEAMENERGY"].data<float>(); std::string& beamstatus = summaryData["BEAMSTATUS"].data<std::string>(); coral::Blob& bxindex = summaryData["CMSBXINDEXBLOB"].data<coral::Blob>(); coral::Blob& beamintensity_1 = summaryData["BEAMINTENSITYBLOB_1"].data<coral::Blob>(); coral::Blob& beamintensity_2 = summaryData["BEAMINTENSITYBLOB_2"].data<coral::Blob>(); unsigned long long& lumidetail_id=detailData["LUMIDETAIL_ID"].data<unsigned long long>(); unsigned long long& d2lumisummary_id=detailData["LUMISUMMARY_ID"].data<unsigned long long>(); coral::Blob& bxlumivalue=detailData["BXLUMIVALUE"].data<coral::Blob>(); coral::Blob& bxlumierror=detailData["BXLUMIERROR"].data<coral::Blob>(); coral::Blob& bxlumiquality=detailData["BXLUMIQUALITY"].data<coral::Blob>(); std::string& algoname=detailData["ALGONAME"].data<std::string>(); lumi::Lumi2DB::LumiResult::const_iterator lumiIt; coral::IBulkOperation* summaryInserter=0; coral::IBulkOperation* detailInserter=0; //one loop for ids //nested transaction doesn't work with bulk inserter unsigned int totallumils=std::distance(lumiBeg,lumiEnd); unsigned int lumiindx=0; std::map< unsigned long long,std::vector<unsigned long long> > idallocationtable; std::cout<<"\t allocating total lumisummary ids "<<totallumils<<std::endl; std::cout<<"\t allocating total lumidetail ids "<<totallumils*lumi::N_LUMIALGO<<std::endl; session->transaction().start(false); lumi::idDealer idg(session->nominalSchema()); unsigned long long lumisummaryID = idg.generateNextIDForTable(LumiNames::lumisummaryTableName(),totallumils)-totallumils; unsigned long long lumidetailID=idg.generateNextIDForTable(LumiNames::lumidetailTableName(),totallumils*lumi::N_LUMIALGO)-totallumils*lumi::N_LUMIALGO; session->transaction().commit(); for(lumiIt=lumiBeg;lumiIt!=lumiEnd;++lumiIt,++lumiindx,++lumisummaryID){ std::vector< unsigned long long > allIDs; allIDs.reserve(1+lumi::N_LUMIALGO); allIDs.push_back(lumisummaryID); for( unsigned int j=0; j<lumi::N_LUMIALGO; ++j, ++lumidetailID){ allIDs.push_back(lumidetailID); } idallocationtable.insert(std::make_pair(lumiindx,allIDs)); } std::cout<<"\t all ids allocated"<<std::endl; lumiindx=0; unsigned int comittedls=0; for(lumiIt=lumiBeg;lumiIt!=lumiEnd;++lumiIt,++lumiindx){ if(!session->transaction().isActive()){ session->transaction().start(false); coral::ITable& summarytable=session->nominalSchema().tableHandle(LumiNames::lumisummaryTableName()); summaryInserter=summarytable.dataEditor().bulkInsert(summaryData,totallumils); coral::ITable& detailtable=session->nominalSchema().tableHandle(LumiNames::lumidetailTableName()); detailInserter=detailtable.dataEditor().bulkInsert(detailData,totallumils*lumi::N_LUMIALGO); } lumisummary_id=idallocationtable[lumiindx][0]; lumirunnum = irunnumber; lumiversion = ilumiversion; dtnorm = lumiIt->dtnorm; lhcnorm = lumiIt->lhcnorm; //instlumi = lumiIt->instlumi; //instlumierror = lumiIt->instlumierror; instlumi = applyCalibration(lumiIt->instlumi); instlumierror = applyCalibration(lumiIt->instlumierror); instlumiquality = lumiIt->instlumiquality; lumisectionquality = lumiIt->lumisectionquality; alive = lumiIt->cmsalive; cmslsnr = lumiIt->cmslsnr; lumilsnr = lumiIt->lumilsnr; startorbit = lumiIt->startorbit; numorbit = lumiIt->numorbit; beamenergy = lumiIt->beamenergy; beamstatus = lumiIt->beammode; short nlivebx=lumiIt->nlivebx; //std::cout<<"nlivebx "<<nlivebx<<std::endl; if(nlivebx!=0){ bxindex.resize(sizeof(short)*nlivebx); beamintensity_1.resize(sizeof(float)*nlivebx); beamintensity_2.resize(sizeof(float)*nlivebx); void* bxindex_StartAddress = bxindex.startingAddress(); void* beamIntensity1_StartAddress = beamintensity_1.startingAddress(); void* beamIntensity2_StartAddress = beamintensity_2.startingAddress(); std::memmove(bxindex_StartAddress,lumiIt->bxindex,sizeof(short)*nlivebx); std::memmove(beamIntensity1_StartAddress,lumiIt->beamintensity_1,sizeof(float)*nlivebx); std::memmove(beamIntensity2_StartAddress,lumiIt->beamintensity_2,sizeof(float)*nlivebx); ::free(lumiIt->bxindex); ::free(lumiIt->beamintensity_1); ::free(lumiIt->beamintensity_2); }else{ bxindex.resize(0); beamintensity_1.resize(0); beamintensity_2.resize(0); } //insert the new row summaryInserter->processNextIteration(); summaryInserter->flush(); unsigned int algoindx=1; for( unsigned int j=0; j<lumi:: N_LUMIALGO; ++j,++algoindx ){ d2lumisummary_id=idallocationtable[lumiindx].at(0); lumidetail_id=idallocationtable[lumiindx].at(algoindx); std::vector<PerBXData>::const_iterator bxIt; std::vector<PerBXData>::const_iterator bxBeg; std::vector<PerBXData>::const_iterator bxEnd; if(j==0) { algoname=std::string("ET"); bxBeg=lumiIt->bxET.begin(); bxEnd=lumiIt->bxET.end(); } if(j==1) { algoname=std::string("OCC1"); bxBeg=lumiIt->bxOCC1.begin(); bxEnd=lumiIt->bxOCC1.end(); } if(j==2) { algoname=std::string("OCC2"); bxBeg=lumiIt->bxOCC2.begin(); bxEnd=lumiIt->bxOCC2.end(); } float lumivalue[lumi::N_BX]={0.0}; float lumierror[lumi::N_BX]={0.0}; int lumiquality[lumi::N_BX]={0}; bxlumivalue.resize(sizeof(float)*lumi::N_BX); bxlumierror.resize(sizeof(float)*lumi::N_BX); bxlumiquality.resize(sizeof(short)*lumi::N_BX); void* bxlumivalueStartAddress=bxlumivalue.startingAddress(); void* bxlumierrorStartAddress=bxlumierror.startingAddress(); void* bxlumiqualityStartAddress=bxlumiquality.startingAddress(); unsigned int k=0; for( bxIt=bxBeg;bxIt!=bxEnd;++bxIt,++k ){ lumivalue[k]=bxIt->lumivalue; lumierror[k]=bxIt->lumierr; lumiquality[k]=bxIt->lumiquality; } std::memmove(bxlumivalueStartAddress,lumivalue,sizeof(float)*lumi::N_BX); std::memmove(bxlumierrorStartAddress,lumierror,sizeof(float)*lumi::N_BX); std::memmove(bxlumiqualityStartAddress,lumiquality,sizeof(short)*lumi::N_BX); detailInserter->processNextIteration(); } detailInserter->flush(); ++comittedls; if(comittedls==Lumi2DB::COMMITLSINTERVAL){ std::cout<<"\t committing in LS chunck "<<comittedls<<std::endl; delete summaryInserter; summaryInserter=0; delete detailInserter; detailInserter=0; session->transaction().commit(); comittedls=0; std::cout<<"\t committed "<<std::endl; }else if( lumiindx==(totallumils-1) ){ std::cout<<"\t committing at the end"<<std::endl; delete summaryInserter; summaryInserter=0; delete detailInserter; detailInserter=0; session->transaction().commit(); std::cout<<"\t done"<<std::endl; } } }
void lumi::Lumi2DB::writeBeamIntensityOnly | ( | coral::ISessionProxy * | session, |
unsigned int | irunnumber, | ||
const std::string & | ilumiversion, | ||
LumiResult::iterator | lumiBeg, | ||
LumiResult::iterator | lumiEnd | ||
) | [private] |
Definition at line 117 of file Lumi2DB.cc.
References COMMITLSINTERVAL, gather_cfg::cout, idDealer::inputData, lumi::LumiNames::lumisummaryTableName(), ExpressReco_HICollisions_FallBack::lumiversion, and cond::runnumber.
{ coral::AttributeList inputData; inputData.extend("bxindex",typeid(coral::Blob)); inputData.extend("beamintensity_1",typeid(coral::Blob)); inputData.extend("beamintensity_2",typeid(coral::Blob)); inputData.extend("runnum",typeid(unsigned int)); inputData.extend("startorbit",typeid(unsigned int)); inputData.extend("lumiversion",typeid(std::string)); coral::Blob& bxindex = inputData["bxindex"].data<coral::Blob>(); coral::Blob& beamintensity_1 = inputData["beamintensity_1"].data<coral::Blob>(); coral::Blob& beamintensity_2 = inputData["beamintensity_2"].data<coral::Blob>(); unsigned int& runnumber = inputData["runnum"].data<unsigned int>(); unsigned int& startorbit = inputData["startorbit"].data<unsigned int>(); std::string& lumiversion = inputData["lumiversion"].data<std::string>(); lumi::Lumi2DB::LumiResult::const_iterator lumiIt; coral::IBulkOperation* summaryUpdater=0; unsigned int totallumils=std::distance(lumiBeg,lumiEnd); unsigned int lumiindx=0; unsigned int comittedls=0; std::string setClause("CMSBXINDEXBLOB=:bxindex,BEAMINTENSITYBLOB_1=:beamintensity_1,BEAMINTENSITYBLOB_2=:beamintensity_2"); std::string condition("RUNNUM=:runnum AND STARTORBIT=:startorbit AND LUMIVERSION=:lumiversion"); runnumber=irunnumber; lumiversion=ilumiversion; for(lumiIt=lumiBeg;lumiIt!=lumiEnd;++lumiIt,++lumiindx){ if(!session->transaction().isActive()){ session->transaction().start(false); } startorbit=lumiIt->startorbit; //std::cout<<"runnumber "<<irunnumber<<" starorbit "<<startorbit<<" lumiversion "<<lumiversion<<" totallumils "<<totallumils<<std::endl; short nlivebx=lumiIt->nlivebx; if(nlivebx!=0){ bxindex.resize(sizeof(short)*nlivebx); beamintensity_1.resize(sizeof(float)*nlivebx); beamintensity_2.resize(sizeof(float)*nlivebx); void* bxindex_StartAddress = bxindex.startingAddress(); void* beamIntensity1_StartAddress = beamintensity_1.startingAddress(); void* beamIntensity2_StartAddress = beamintensity_2.startingAddress(); std::memmove(bxindex_StartAddress,lumiIt->bxindex,sizeof(short)*nlivebx); std::memmove(beamIntensity1_StartAddress,lumiIt->beamintensity_1,sizeof(float)*nlivebx); std::memmove(beamIntensity2_StartAddress,lumiIt->beamintensity_2,sizeof(float)*nlivebx); ::free(lumiIt->bxindex); ::free(lumiIt->beamintensity_1); ::free(lumiIt->beamintensity_2); }else{ bxindex.resize(0); beamintensity_1.resize(0); beamintensity_2.resize(0); } coral::ITable& summarytable=session->nominalSchema().tableHandle(LumiNames::lumisummaryTableName()); summaryUpdater=summarytable.dataEditor().bulkUpdateRows(setClause,condition,inputData,totallumils); summaryUpdater->processNextIteration(); summaryUpdater->flush(); ++comittedls; if(comittedls==Lumi2DB::COMMITLSINTERVAL){ std::cout<<"\t committing in LS chunck "<<comittedls<<std::endl; delete summaryUpdater; summaryUpdater=0; session->transaction().commit(); comittedls=0; std::cout<<"\t committed "<<std::endl; }else if( lumiindx==(totallumils-1) ){ std::cout<<"\t committing at the end"<<std::endl; delete summaryUpdater; summaryUpdater=0; session->transaction().commit(); std::cout<<"\t done"<<std::endl; } } }
const unsigned int lumi::Lumi2DB::COMMITLSINTERVAL = 500 [static] |
Definition at line 34 of file Lumi2DB.cc.
Referenced by writeAllLumiData(), and writeBeamIntensityOnly().
const unsigned int lumi::Lumi2DB::NORMFACTOR = 6370 [static] |
Definition at line 35 of file Lumi2DB.cc.
Referenced by applyCalibration().