CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Static Public Attributes | Private Member Functions
lumi::Lumi2DB Class Reference
Inheritance diagram for lumi::Lumi2DB:
lumi::DataPipe

Classes

struct  beamData
 
struct  LumiSource
 
struct  PerBXData
 
struct  PerLumiData
 

Public Types

typedef std::vector< PerLumiDataLumiResult
 

Public Member Functions

const std::string dataType () const override
 
bool hasStableBeam (lumi::Lumi2DB::LumiResult::iterator lumiBeg, lumi::Lumi2DB::LumiResult::iterator lumiEnd)
 
 Lumi2DB (const std::string &dest)
 
unsigned long long retrieveData (unsigned int) override
 
const std::string sourceType () const override
 
 ~Lumi2DB () override
 
- Public Member Functions inherited from lumi::DataPipe
 DataPipe (const std::string &)
 
 DataPipe (const DataPipe &)=delete
 
std::string getAuthPath () const
 
std::string getMode () const
 
float getNorm () const
 
std::string getSource () const
 
const DataPipeoperator= (const DataPipe &)=delete
 
void setAuthPath (const std::string &authpath)
 
void setMode (const std::string &mode)
 
void setNoCheckingStableBeam ()
 
void setNorm (float norm)
 
void setNoValidate ()
 
void setSource (const std::string &source)
 
virtual ~DataPipe ()
 

Static Public Attributes

static const unsigned int COMMITLSINTERVAL = 500
 

Private Member Functions

float applyCalibration (float varToCalibrate) const
 
void cleanTemporaryMemory (lumi::Lumi2DB::LumiResult::iterator lumiBeg, lumi::Lumi2DB::LumiResult::iterator lumiEnd)
 
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)
 
unsigned int writeAllLumiDataToSchema2 (coral::ISessionProxy *session, const std::string &source, unsigned int runnumber, float bgev, unsigned int ncollidingbunches, LumiResult::iterator lumiBeg, LumiResult::iterator lumiEnd)
 
void writeBeamIntensityOnly (coral::ISessionProxy *session, unsigned int irunnumber, const std::string &ilumiversion, LumiResult::iterator lumiBeg, LumiResult::iterator lumiEnd)
 

Additional Inherited Members

- Protected Attributes inherited from lumi::DataPipe
std::string m_authpath
 
std::string m_dest
 
std::string m_mode
 
bool m_nocheckingstablebeam
 
float m_norm
 
bool m_novalidate
 
std::string m_source
 

Detailed Description

Definition at line 33 of file Lumi2DB.cc.

Member Typedef Documentation

◆ LumiResult

typedef std::vector<PerLumiData> lumi::Lumi2DB::LumiResult

Definition at line 84 of file Lumi2DB.cc.

Constructor & Destructor Documentation

◆ Lumi2DB()

lumi::Lumi2DB::Lumi2DB ( const std::string &  dest)

Definition at line 680 of file Lumi2DB.cc.

680 : DataPipe(dest) {}
DataPipe(const std::string &)
Definition: DataPipe.cc:2

◆ ~Lumi2DB()

lumi::Lumi2DB::~Lumi2DB ( )
override

Definition at line 996 of file Lumi2DB.cc.

996 {}

Member Function Documentation

◆ applyCalibration()

float lumi::Lumi2DB::applyCalibration ( float  varToCalibrate) const
private

Definition at line 116 of file Lumi2DB.cc.

References nano_mu_digi_cff::float, and lumi::DataPipe::m_norm.

116  { //#only used for writing into schema_v1
117  return float(varToCalibrate) * m_norm;
118 }
float m_norm
Definition: DataPipe.h:34

◆ cleanTemporaryMemory()

void lumi::Lumi2DB::cleanTemporaryMemory ( lumi::Lumi2DB::LumiResult::iterator  lumiBeg,
lumi::Lumi2DB::LumiResult::iterator  lumiEnd 
)
private

Definition at line 671 of file Lumi2DB.cc.

References free().

672  {
673  lumi::Lumi2DB::LumiResult::const_iterator lumiIt;
674  for (lumiIt = lumiBeg; lumiIt != lumiEnd; ++lumiIt) {
675  ::free(lumiIt->bxindex);
676  ::free(lumiIt->beamintensity_1);
677  ::free(lumiIt->beamintensity_2);
678  }
679 }
void free(void *ptr) noexcept

◆ dataType()

const std::string lumi::Lumi2DB::dataType ( ) const
overridevirtual

Implements lumi::DataPipe.

Definition at line 994 of file Lumi2DB.cc.

994 { return "LUMI"; }

◆ hasStableBeam()

bool lumi::Lumi2DB::hasStableBeam ( lumi::Lumi2DB::LumiResult::iterator  lumiBeg,
lumi::Lumi2DB::LumiResult::iterator  lumiEnd 
)

Definition at line 119 of file Lumi2DB.cc.

120  {
121  //
122  // the run has at least 1 stable beams LS
123  //
124  lumi::Lumi2DB::LumiResult::iterator lumiIt;
125  int nStable = 0;
126  for (lumiIt = lumiBeg; lumiIt != lumiEnd; ++lumiIt) {
127  if (lumiIt->beammode == "STABLE BEAMS") {
128  ++nStable;
129  }
130  }
131  if (nStable == 0) {
132  return false;
133  }
134  return true;
135 }

◆ isLumiDataValid()

bool lumi::Lumi2DB::isLumiDataValid ( LumiResult::iterator  lumiBeg,
LumiResult::iterator  lumiEnd 
)
private

Definition at line 136 of file Lumi2DB.cc.

References HLT_2024v14_cff::distance.

137  {
138  //
139  // validate lumidata: all ls has lumi less than 0.5e-08 before calibration, then invalid data
140  //
141  lumi::Lumi2DB::LumiResult::iterator lumiIt;
142  int nBad = 0;
143  for (lumiIt = lumiBeg; lumiIt != lumiEnd; ++lumiIt) {
144  //std::cout<<"instlumi before calib "<<lumiIt->instlumi<<std::endl;
145  if (lumiIt->instlumi <= 0.5e-8) { //cut before calib
146  ++nBad;
147  }
148  }
149  if (nBad == std::distance(lumiBeg, lumiEnd)) {
150  return false;
151  }
152  return true;
153 }

◆ parseSourceString()

void lumi::Lumi2DB::parseSourceString ( lumi::Lumi2DB::LumiSource result) const
private

Definition at line 681 of file Lumi2DB.cc.

References Exception, csv2json::pieces, mps_fire::result, and AlCaHLTBitMon_QueryRunRegistry::string.

681  {
682  //parse lumi source file name
683  if (m_source.length() == 0)
684  throw lumi::Exception("lumi source is not set", "parseSourceString", "Lumi2DB");
685  //std::cout<<"source "<<m_source<<std::endl;
686  size_t tempIndex = m_source.find_last_of('.');
687  size_t nameLength = m_source.length();
688  std::string FileSuffix = m_source.substr(tempIndex + 1, nameLength - tempIndex);
689  std::string::size_type lastPos = m_source.find_first_not_of('_', 0);
690  std::string::size_type pos = m_source.find_first_of('_', lastPos);
691  std::vector<std::string> pieces;
692  while (std::string::npos != pos || std::string::npos != lastPos) {
693  pieces.push_back(m_source.substr(lastPos, pos - lastPos));
694  lastPos = m_source.find_first_not_of('_', pos);
695  pos = m_source.find_first_of('_', lastPos);
696  }
697  if (pieces[1] != "LUMI" || pieces[2] != "RAW" || FileSuffix != "root") {
698  throw lumi::Exception("not lumi raw data file CMS_LUMI_RAW", "parseSourceString", "Lumi2DB");
699  }
700  std::strcpy(result.datestr, pieces[3].c_str());
701  std::strcpy(result.version, pieces[5].c_str());
702  //std::cout<<"version : "<<result.version<<std::endl;
703  result.run = atoi(pieces[4].c_str());
704  //std::cout<<"run : "<<result.run<<std::endl;
705  result.firstsection = atoi(pieces[5].c_str());
706  //std::cout<<"first section : "<< result.firstsection<<std::endl;
707 }
uint16_t size_type
std::string m_source
Definition: DataPipe.h:30

◆ retrieveBeamIntensity()

void lumi::Lumi2DB::retrieveBeamIntensity ( HCAL_HLX::DIP_COMBINED_DATA dataPtr,
Lumi2DB::beamData b 
) const
private

Definition at line 709 of file Lumi2DB.cc.

References a, HCAL_HLX::BEAM_INFO::averageBunchIntensities, b, HCAL_HLX::DIP_COMBINED_DATA::Beam, gather_cfg::cout, mps_fire::i, malloc(), and lumi::N_BX.

709  {
710  if (dataPtr == nullptr) {
711  std::cout << "HCAL_HLX::DIP_COMBINED_DATA* dataPtr=0" << std::endl;
712  b.bxindex = nullptr;
713  b.beamintensity_1 = nullptr;
714  b.beamintensity_2 = nullptr;
715  b.nlivebx = 0;
716  } else {
717  b.bxindex = (short*)::malloc(sizeof(short) * lumi::N_BX);
718  b.beamintensity_1 = (float*)::malloc(sizeof(float) * lumi::N_BX);
719  b.beamintensity_2 = (float*)::malloc(sizeof(float) * lumi::N_BX);
720 
721  short a = 0; //a is position in lumidetail array
722  for (unsigned int i = 0; i < lumi::N_BX; ++i) {
723  if (i == 0) {
724  if (dataPtr->Beam[0].averageBunchIntensities[0] > 0 || dataPtr->Beam[1].averageBunchIntensities[0] > 0) {
725  b.bxindex[a] = 0;
726  b.beamintensity_1[a] = dataPtr->Beam[0].averageBunchIntensities[0];
727  b.beamintensity_2[a] = dataPtr->Beam[1].averageBunchIntensities[0];
728  ++a;
729  }
730  continue;
731  }
732  if (dataPtr->Beam[0].averageBunchIntensities[i - 1] > 0 || dataPtr->Beam[1].averageBunchIntensities[i - 1] > 0) {
733  b.bxindex[a] = i;
734  b.beamintensity_1[a] = dataPtr->Beam[0].averageBunchIntensities[i - 1];
735  b.beamintensity_2[a] = dataPtr->Beam[1].averageBunchIntensities[i - 1];
736  ++a;
737  //if(i!=0){
738  // std::cout<<"beam intensity "<<dataPtr->sectionNumber<<" "<<dataPtr->timestamp-1262300400<<" "<<(i-1)*10+1<<" "<<b.beamintensity_1[a]<<" "<<b.beamintensity_2[a]<<std::endl;
739  //}
740  }
741  }
742  b.nlivebx = a;
743  }
744 }
void * malloc(size_t size) noexcept
const unsigned int N_BX
Definition: ConstantDef.h:5
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121

◆ retrieveData()

unsigned long long lumi::Lumi2DB::retrieveData ( unsigned int  runnumber)
overridevirtual

retrieve lumi per ls data from root file

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 748 of file Lumi2DB.cc.

References b, HCAL_HLX::LUMI_SECTION_HEADER::bCMSLive, gather_cfg::cout, HCAL_HLX::LUMI_SUMMARY::DeadTimeNormalization, HCAL_HLX::LUMI_DETAIL::ETLumi, HCAL_HLX::LUMI_DETAIL::ETLumiErr, HCAL_HLX::LUMI_DETAIL::ETLumiQlty, Exception, free(), h, mps_fire::i, HCAL_HLX::LUMI_SUMMARY::InstantLumi, HCAL_HLX::LUMI_SUMMARY::InstantLumiErr, HCAL_HLX::LUMI_SUMMARY::InstantLumiQlty, HCAL_HLX::LUMI_SUMMARY::LHCNormalization, lumi::Lumi2DB::PerBXData::lumierr, lumi::Lumi2DB::PerBXData::lumiquality, lumi::Lumi2DB::PerBXData::lumivalue, malloc(), lumi::N_BX, HCAL_HLX::LUMI_SECTION_HEADER::numBunches, 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, cond::runnumber, HCAL_HLX::LUMI_SECTION_HEADER::sectionNumber, lumi::DBConfig::setAuthentication(), source, HCAL_HLX::LUMI_SECTION_HEADER::startOrbit, AlCaHLTBitMon_QueryRunRegistry::string, lumi::Lumi2DB::LumiSource::version, and lumi::Exception::what().

748  {
749  lumi::Lumi2DB::LumiResult lumiresult;
750  //check filename is in lumiraw format
751  lumi::Lumi2DB::LumiSource filenamecontent;
752  unsigned int lumidataid = 0;
753  try {
754  parseSourceString(filenamecontent);
755  } catch (const lumi::Exception& er) {
756  std::cout << er.what() << std::endl;
757  throw er;
758  }
759  if (filenamecontent.run != runnumber) {
760  throw lumi::Exception("runnumber in file name does not match requested run number", "retrieveData", "Lumi2DB");
761  }
762  TFile* source = TFile::Open(m_source.c_str(), "READ");
763  TTree* hlxtree = (TTree*)source->Get("HLXData");
764  if (!hlxtree) {
765  throw lumi::Exception(std::string("non-existing HLXData "), "retrieveData", "Lumi2DB");
766  }
767  //hlxtree->Print();
768  std::unique_ptr<HCAL_HLX::LUMI_SECTION> localSection(new HCAL_HLX::LUMI_SECTION);
769  HCAL_HLX::LUMI_SECTION_HEADER* lumiheader = &(localSection->hdr);
770  HCAL_HLX::LUMI_SUMMARY* lumisummary = &(localSection->lumiSummary);
771  HCAL_HLX::LUMI_DETAIL* lumidetail = &(localSection->lumiDetail);
772 
773  hlxtree->SetBranchAddress("Header.", &lumiheader);
774  hlxtree->SetBranchAddress("Summary.", &lumisummary);
775  hlxtree->SetBranchAddress("Detail.", &lumidetail);
776 
777  size_t nentries = hlxtree->GetEntries();
778  unsigned int nstablebeam = 0;
779  float bgev = 0.0;
780  //source->GetListOfKeys()->Print();
781  std::map<unsigned int, Lumi2DB::beamData> dipmap;
782  TTree* diptree = (TTree*)source->Get("DIPCombined");
783  if (diptree) {
784  //throw lumi::Exception(std::string("non-existing DIPData "),"retrieveData","Lumi2DB");
785  std::unique_ptr<HCAL_HLX::DIP_COMBINED_DATA> dipdata(new HCAL_HLX::DIP_COMBINED_DATA);
786  diptree->SetBranchAddress("DIPCombined.", &dipdata);
787  size_t ndipentries = diptree->GetEntries();
788  for (size_t i = 0; i < ndipentries; ++i) {
789  diptree->GetEntry(i);
790  //unsigned int fillnumber=dipdata->FillNumber;
791  //std::vector<short> collidingidx;collidingidx.reserve(LUMI::N_BX);
792  //for(unsigned int i=0;i<lumi::N_BX;++i){
793  //int isb1colliding=dipdata->beam[0].beamConfig[i];
794  //int isb2colliding=dipdata->beam[1].beamConfig[i];
795  //if(isb1colliding && isb2colliding&&isb1colliding==1&&isb2colliding==1){
796  // collidingidx.push_back(i);
797  // }
798  //}
799  beamData b;
800  //std::cout<<"Beam Mode : "<<dipdata->beamMode<<"\n";
801  //std::cout<<"Beam Energy : "<<dipdata->Energy<<"\n";
802  //std::cout<<"sectionUmber : "<<dipdata->sectionNumber<<"\n";
803  unsigned int dipls = dipdata->sectionNumber;
804  if (std::string(dipdata->beamMode).empty()) {
805  b.mode = "N/A";
806  } else {
807  b.mode = dipdata->beamMode;
808  }
809  b.energy = dipdata->Energy;
810  if (b.mode == "STABLE BEAMS") {
811  ++nstablebeam;
812  bgev += b.energy;
813  }
814  this->retrieveBeamIntensity(dipdata.get(), b);
815  dipmap.insert(std::make_pair(dipls, b));
816  }
817  } else {
818  for (size_t i = 0; i < nentries; ++i) {
819  beamData b;
820  b.mode = "N/A";
821  b.energy = 0.0;
822  this->retrieveBeamIntensity(nullptr, b);
823  dipmap.insert(std::make_pair(i, b));
824  }
825  }
826  //diptree->Print();
827 
828  size_t ncmslumi = 0;
829  std::cout << "processing total lumi lumisection " << nentries << std::endl;
830  //size_t lumisecid=0;
831  //unsigned int lumilumisecid=0;
832  //runnumber=lumiheader->runNumber;
833  //
834  //hardcode the first LS is always alive
835  //
836  unsigned int ncollidingbunches = 0;
837  for (size_t i = 0; i < nentries; ++i) {
839  h.cmsalive = 1;
840  hlxtree->GetEntry(i);
841  //std::cout<<"live flag "<<lumiheader->bCMSLive <<std::endl;
842  if (!lumiheader->bCMSLive && i != 0) {
843  std::cout << "\t non-CMS LS " << lumiheader->sectionNumber << " ";
844  h.cmsalive = 0;
845  }
846  ++ncmslumi;
847  if (ncmslumi == 1) { //just take the first ls
848  ncollidingbunches = lumiheader->numBunches;
849  }
850  h.bxET.reserve(lumi::N_BX);
851  h.bxOCC1.reserve(lumi::N_BX);
852  h.bxOCC2.reserve(lumi::N_BX);
853 
854  //runnumber=lumiheader->runNumber;
855  //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));
856  h.lumilsnr = lumiheader->sectionNumber;
857  std::map<unsigned int, Lumi2DB::beamData>::iterator beamIt = dipmap.find(h.lumilsnr);
858  if (beamIt != dipmap.end()) {
859  h.beammode = beamIt->second.mode;
860  h.beamenergy = beamIt->second.energy;
861  h.nlivebx = beamIt->second.nlivebx;
862  if (h.nlivebx != 0) {
863  h.bxindex = (short*)malloc(sizeof(short) * h.nlivebx);
864  h.beamintensity_1 = (float*)malloc(sizeof(float) * h.nlivebx);
865  h.beamintensity_2 = (float*)malloc(sizeof(float) * h.nlivebx);
866  if (h.bxindex == nullptr || h.beamintensity_1 == nullptr || h.beamintensity_2 == nullptr) {
867  std::cout << "malloc failed" << std::endl;
868  }
869  //std::cout<<"h.bxindex size "<<sizeof(short)*h.nlivebx<<std::endl;
870  //std::cout<<"h.beamintensity_1 size "<<sizeof(float)*h.nlivebx<<std::endl;
871  //std::cout<<"h.beamintensity_2 size "<<sizeof(float)*h.nlivebx<<std::endl;
872 
873  std::memmove(h.bxindex, beamIt->second.bxindex, sizeof(short) * h.nlivebx);
874  std::memmove(h.beamintensity_1, beamIt->second.beamintensity_1, sizeof(float) * h.nlivebx);
875  std::memmove(h.beamintensity_2, beamIt->second.beamintensity_2, sizeof(float) * h.nlivebx);
876 
877  ::free(beamIt->second.bxindex);
878  beamIt->second.bxindex = nullptr;
879  ::free(beamIt->second.beamintensity_1);
880  beamIt->second.beamintensity_1 = nullptr;
881  ::free(beamIt->second.beamintensity_2);
882  beamIt->second.beamintensity_2 = nullptr;
883  } else {
884  //std::cout<<"h.nlivebx is zero"<<std::endl;
885  h.bxindex = nullptr;
886  h.beamintensity_1 = nullptr;
887  h.beamintensity_2 = nullptr;
888  }
889  } else {
890  h.beammode = "N/A";
891  h.beamenergy = 0.0;
892  h.nlivebx = 0;
893  h.bxindex = nullptr;
894  h.beamintensity_1 = nullptr;
895  h.beamintensity_2 = nullptr;
896  }
897  h.startorbit = lumiheader->startOrbit;
898  h.numorbit = lumiheader->numOrbits;
899  if (h.cmsalive == 0) {
900  h.cmslsnr = 0; //the dead ls has cmsls number=0
901  } else {
902  h.cmslsnr = ncmslumi; //we guess cms lumils
903  }
904  h.instlumi = lumisummary->InstantLumi;
905  //std::cout<<"instant lumi "<<lumisummary->InstantLumi<<std::endl;
906  h.instlumierror = lumisummary->InstantLumiErr;
907  h.lumisectionquality = lumisummary->InstantLumiQlty;
908  h.dtnorm = lumisummary->DeadTimeNormalization;
909  h.lhcnorm = lumisummary->LHCNormalization;
910  //unsigned int timestp=lumiheader->timestamp;
911  //std::cout<<"cmslsnum "<<ncmslumi<<"timestp "<<timestp<<std::endl;
912  for (size_t i = 0; i < lumi::N_BX; ++i) {
916  //bET.idx=i+1;
917  bET.lumivalue = lumidetail->ETLumi[i];
918  bET.lumierr = lumidetail->ETLumiErr[i];
919  bET.lumiquality = lumidetail->ETLumiQlty[i];
920  h.bxET.push_back(bET);
921 
922  //bOCC1.idx=i+1;
923 
924  bOCC1.lumivalue = lumidetail->OccLumi[0][i];
925  bOCC1.lumierr = lumidetail->OccLumiErr[0][i];
932  bOCC1.lumiquality = lumidetail->OccLumiQlty[0][i];
933  h.bxOCC1.push_back(bOCC1);
934 
935  //bOCC2.idx=i+1;
936  bOCC2.lumivalue = lumidetail->OccLumi[1][i];
937  bOCC2.lumierr = lumidetail->OccLumiErr[1][i];
938  bOCC2.lumiquality = lumidetail->OccLumiQlty[1][i];
939  h.bxOCC2.push_back(bOCC2);
940  }
941  lumiresult.push_back(h);
942  }
943  std::cout << std::endl;
944  if (nstablebeam != 0) {
945  bgev = bgev / nstablebeam; //nominal beam energy=sum(energy)/nstablebeams
946  }
947  std::cout << "avg stable beam energy " << bgev << std::endl;
948  if (!m_novalidate && !isLumiDataValid(lumiresult.begin(), lumiresult.end())) {
949  throw lumi::invalidDataException("all lumi values are <0.5e-08", "isLumiDataValid", "Lumi2DB");
950  }
951  if (!m_nocheckingstablebeam && !hasStableBeam(lumiresult.begin(), lumiresult.end())) {
952  throw lumi::noStableBeamException("no LS has STABLE BEAMS", "hasStableBeam", "Lumi2DB");
953  }
954  coral::ConnectionService* svc = new coral::ConnectionService;
955  lumi::DBConfig dbconf(*svc);
956  if (!m_authpath.empty()) {
957  dbconf.setAuthentication(m_authpath);
958  }
959  coral::ISessionProxy* session = svc->connect(m_dest, coral::Update);
960  coral::ITypeConverter& tpc = session->typeConverter();
961  tpc.setCppTypeForSqlType("unsigned int", "NUMBER(10)");
962  //
963  //write to old lumisummary
964  //
965  try {
966  const std::string lversion(filenamecontent.version);
967  if (m_mode == std::string("beamintensity_only")) {
968  std::cout << "writing beam intensity only to old lumisummary table " << std::endl;
969  writeBeamIntensityOnly(session, runnumber, lversion, lumiresult.begin(), lumiresult.end());
970  std::cout << "done" << std::endl;
971  } else {
972  if (m_mode == "loadoldschema") {
973  std::cout << "writing all lumi data to old lumisummary table " << std::endl;
974  writeAllLumiData(session, runnumber, lversion, lumiresult.begin(), lumiresult.end());
975  std::cout << "done" << std::endl;
976  }
977  }
978  std::cout << "writing all lumi data to lumisummary_V2 table " << std::endl;
979  lumidataid = writeAllLumiDataToSchema2(
980  session, m_source, runnumber, bgev, ncollidingbunches, lumiresult.begin(), lumiresult.end());
981  std::cout << "done" << std::endl;
982  cleanTemporaryMemory(lumiresult.begin(), lumiresult.end());
983  delete session;
984  delete svc;
985  } catch (const coral::Exception& er) {
986  std::cout << "database error " << er.what() << std::endl;
987  session->transaction().rollback();
988  delete session;
989  delete svc;
990  throw er;
991  }
992  return lumidataid;
993 }
char const * what() const override
Definition: Exception.h:10
std::vector< PerLumiData > LumiResult
Definition: Lumi2DB.cc:84
void writeBeamIntensityOnly(coral::ISessionProxy *session, unsigned int irunnumber, const std::string &ilumiversion, LumiResult::iterator lumiBeg, LumiResult::iterator lumiEnd)
Definition: Lumi2DB.cc:154
bool hasStableBeam(lumi::Lumi2DB::LumiResult::iterator lumiBeg, lumi::Lumi2DB::LumiResult::iterator lumiEnd)
Definition: Lumi2DB.cc:119
bool m_novalidate
Definition: DataPipe.h:33
void free(void *ptr) noexcept
std::string m_dest
Definition: DataPipe.h:29
void cleanTemporaryMemory(lumi::Lumi2DB::LumiResult::iterator lumiBeg, lumi::Lumi2DB::LumiResult::iterator lumiEnd)
Definition: Lumi2DB.cc:671
unsigned int writeAllLumiDataToSchema2(coral::ISessionProxy *session, const std::string &source, unsigned int runnumber, float bgev, unsigned int ncollidingbunches, LumiResult::iterator lumiBeg, LumiResult::iterator lumiEnd)
Definition: Lumi2DB.cc:436
std::string m_source
Definition: DataPipe.h:30
void parseSourceString(lumi::Lumi2DB::LumiSource &result) const
Definition: Lumi2DB.cc:681
void * malloc(size_t size) noexcept
const unsigned int N_BX
Definition: ConstantDef.h:5
double b
Definition: hdecay.h:120
std::string m_authpath
Definition: DataPipe.h:31
std::string m_mode
Definition: DataPipe.h:32
bool isLumiDataValid(LumiResult::iterator lumiBeg, LumiResult::iterator lumiEnd)
Definition: Lumi2DB.cc:136
void writeAllLumiData(coral::ISessionProxy *session, unsigned int irunnumber, const std::string &ilumiversion, LumiResult::iterator lumiBeg, LumiResult::iterator lumiEnd)
Definition: Lumi2DB.cc:229
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
static std::string const source
Definition: EdmProvDump.cc:49
bool m_nocheckingstablebeam
Definition: DataPipe.h:35
void retrieveBeamIntensity(HCAL_HLX::DIP_COMBINED_DATA *dataPtr, Lumi2DB::beamData &b) const
Definition: Lumi2DB.cc:709

◆ sourceType()

const std::string lumi::Lumi2DB::sourceType ( ) const
overridevirtual

Implements lumi::DataPipe.

Definition at line 995 of file Lumi2DB.cc.

995 { return "DB"; }

◆ writeAllLumiData()

void lumi::Lumi2DB::writeAllLumiData ( coral::ISessionProxy *  session,
unsigned int  irunnumber,
const std::string &  ilumiversion,
LumiResult::iterator  lumiBeg,
LumiResult::iterator  lumiEnd 
)
private

Definition at line 229 of file Lumi2DB.cc.

References alive, COMMITLSINTERVAL, gather_cfg::cout, HLT_2024v14_cff::distance, lumi::idDealer::generateNextIDForTable(), dqmiolumiharvest::j, dqmdumpme::k, lumi::LumiNames::lumidetailTableName(), lumi::LumiNames::lumisummaryTableName(), FastTimerService_cff::lumiversion, lumi::N_BX, lumi::N_LUMIALGO, and AlCaHLTBitMon_QueryRunRegistry::string.

233  {
234  coral::AttributeList summaryData;
235  coral::AttributeList detailData;
236  summaryData.extend("LUMISUMMARY_ID", typeid(unsigned long long));
237  summaryData.extend("RUNNUM", typeid(unsigned int));
238  summaryData.extend("CMSLSNUM", typeid(unsigned int));
239  summaryData.extend("LUMILSNUM", typeid(unsigned int));
240  summaryData.extend("LUMIVERSION", typeid(std::string));
241  summaryData.extend("DTNORM", typeid(float));
242  summaryData.extend("LHCNORM", typeid(float));
243  summaryData.extend("INSTLUMI", typeid(float));
244  summaryData.extend("INSTLUMIERROR", typeid(float));
245  summaryData.extend("INSTLUMIQUALITY", typeid(short));
246  summaryData.extend("LUMISECTIONQUALITY", typeid(short));
247  summaryData.extend("CMSALIVE", typeid(short));
248  summaryData.extend("STARTORBIT", typeid(unsigned int));
249  summaryData.extend("NUMORBIT", typeid(unsigned int));
250  summaryData.extend("BEAMENERGY", typeid(float));
251  summaryData.extend("BEAMSTATUS", typeid(std::string));
252  summaryData.extend("CMSBXINDEXBLOB", typeid(coral::Blob));
253  summaryData.extend("BEAMINTENSITYBLOB_1", typeid(coral::Blob));
254  summaryData.extend("BEAMINTENSITYBLOB_2", typeid(coral::Blob));
255 
256  detailData.extend("LUMIDETAIL_ID", typeid(unsigned long long));
257  detailData.extend("LUMISUMMARY_ID", typeid(unsigned long long));
258  detailData.extend("BXLUMIVALUE", typeid(coral::Blob));
259  detailData.extend("BXLUMIERROR", typeid(coral::Blob));
260  detailData.extend("BXLUMIQUALITY", typeid(coral::Blob));
261  detailData.extend("ALGONAME", typeid(std::string));
262 
263  unsigned long long& lumisummary_id = summaryData["LUMISUMMARY_ID"].data<unsigned long long>();
264  unsigned int& lumirunnum = summaryData["RUNNUM"].data<unsigned int>();
265  std::string& lumiversion = summaryData["LUMIVERSION"].data<std::string>();
266  float& dtnorm = summaryData["DTNORM"].data<float>();
267  float& lhcnorm = summaryData["LHCNORM"].data<float>();
268  float& instlumi = summaryData["INSTLUMI"].data<float>();
269  float& instlumierror = summaryData["INSTLUMIERROR"].data<float>();
270  short& instlumiquality = summaryData["INSTLUMIQUALITY"].data<short>();
271  short& lumisectionquality = summaryData["LUMISECTIONQUALITY"].data<short>();
272  short& alive = summaryData["CMSALIVE"].data<short>();
273  unsigned int& lumilsnr = summaryData["LUMILSNUM"].data<unsigned int>();
274  unsigned int& cmslsnr = summaryData["CMSLSNUM"].data<unsigned int>();
275  unsigned int& startorbit = summaryData["STARTORBIT"].data<unsigned int>();
276  unsigned int& numorbit = summaryData["NUMORBIT"].data<unsigned int>();
277  float& beamenergy = summaryData["BEAMENERGY"].data<float>();
278  std::string& beamstatus = summaryData["BEAMSTATUS"].data<std::string>();
279  coral::Blob& bxindex = summaryData["CMSBXINDEXBLOB"].data<coral::Blob>();
280  coral::Blob& beamintensity_1 = summaryData["BEAMINTENSITYBLOB_1"].data<coral::Blob>();
281  coral::Blob& beamintensity_2 = summaryData["BEAMINTENSITYBLOB_2"].data<coral::Blob>();
282 
283  unsigned long long& lumidetail_id = detailData["LUMIDETAIL_ID"].data<unsigned long long>();
284  unsigned long long& d2lumisummary_id = detailData["LUMISUMMARY_ID"].data<unsigned long long>();
285  coral::Blob& bxlumivalue = detailData["BXLUMIVALUE"].data<coral::Blob>();
286  coral::Blob& bxlumierror = detailData["BXLUMIERROR"].data<coral::Blob>();
287  coral::Blob& bxlumiquality = detailData["BXLUMIQUALITY"].data<coral::Blob>();
288  std::string& algoname = detailData["ALGONAME"].data<std::string>();
289 
290  lumi::Lumi2DB::LumiResult::const_iterator lumiIt;
291  coral::IBulkOperation* summaryInserter = nullptr;
292  coral::IBulkOperation* detailInserter = nullptr;
293  //one loop for ids
294  //nested transaction doesn't work with bulk inserter
295  unsigned int totallumils = std::distance(lumiBeg, lumiEnd);
296  unsigned int lumiindx = 0;
297  std::map<unsigned long long, std::vector<unsigned long long> > idallocationtable;
298  std::cout << "\t allocating total lumisummary ids " << totallumils << std::endl;
299  std::cout << "\t allocating total lumidetail ids " << totallumils * lumi::N_LUMIALGO << std::endl;
300 
301  session->transaction().start(false);
302  lumi::idDealer idg(session->nominalSchema());
303  unsigned long long lumisummaryID =
304  idg.generateNextIDForTable(LumiNames::lumisummaryTableName(), totallumils) - totallumils;
305  unsigned long long lumidetailID =
306  idg.generateNextIDForTable(LumiNames::lumidetailTableName(), totallumils * lumi::N_LUMIALGO) -
307  totallumils * lumi::N_LUMIALGO;
308  session->transaction().commit();
309  for (lumiIt = lumiBeg; lumiIt != lumiEnd; ++lumiIt, ++lumiindx, ++lumisummaryID) {
310  std::vector<unsigned long long> allIDs;
311  allIDs.reserve(1 + lumi::N_LUMIALGO);
312  allIDs.push_back(lumisummaryID);
313  for (unsigned int j = 0; j < lumi::N_LUMIALGO; ++j, ++lumidetailID) {
314  allIDs.push_back(lumidetailID);
315  }
316  idallocationtable.insert(std::make_pair(lumiindx, allIDs));
317  }
318  std::cout << "\t all ids allocated" << std::endl;
319  lumiindx = 0;
320  unsigned int comittedls = 0;
321  for (lumiIt = lumiBeg; lumiIt != lumiEnd; ++lumiIt, ++lumiindx) {
322  if (!session->transaction().isActive()) {
323  session->transaction().start(false);
324  coral::ITable& summarytable = session->nominalSchema().tableHandle(LumiNames::lumisummaryTableName());
325  summaryInserter = summarytable.dataEditor().bulkInsert(summaryData, totallumils);
326  coral::ITable& detailtable = session->nominalSchema().tableHandle(LumiNames::lumidetailTableName());
327  detailInserter = detailtable.dataEditor().bulkInsert(detailData, totallumils * lumi::N_LUMIALGO);
328  }
329  lumisummary_id = idallocationtable[lumiindx][0];
330  lumirunnum = irunnumber;
331  lumiversion = ilumiversion;
332  dtnorm = lumiIt->dtnorm;
333  lhcnorm = lumiIt->lhcnorm;
334  //instlumi = lumiIt->instlumi;
335  //instlumierror = lumiIt->instlumierror;
336  instlumi = applyCalibration(lumiIt->instlumi);
337  instlumierror = applyCalibration(lumiIt->instlumierror);
338  instlumiquality = lumiIt->instlumiquality;
339  lumisectionquality = lumiIt->lumisectionquality;
340  alive = lumiIt->cmsalive;
341  cmslsnr = lumiIt->cmslsnr;
342 
343  lumilsnr = lumiIt->lumilsnr;
344  startorbit = lumiIt->startorbit;
345  numorbit = lumiIt->numorbit;
346  beamenergy = lumiIt->beamenergy;
347  beamstatus = lumiIt->beammode;
348  short nlivebx = lumiIt->nlivebx;
349  //std::cout<<"nlivebx "<<nlivebx<<std::endl;
350  if (nlivebx != 0) {
351  bxindex.resize(sizeof(short) * nlivebx);
352  beamintensity_1.resize(sizeof(float) * nlivebx);
353  beamintensity_2.resize(sizeof(float) * nlivebx);
354  void* bxindex_StartAddress = bxindex.startingAddress();
355  void* beamIntensity1_StartAddress = beamintensity_1.startingAddress();
356  void* beamIntensity2_StartAddress = beamintensity_2.startingAddress();
357  std::memmove(bxindex_StartAddress, lumiIt->bxindex, sizeof(short) * nlivebx);
358  std::memmove(beamIntensity1_StartAddress, lumiIt->beamintensity_1, sizeof(float) * nlivebx);
359  std::memmove(beamIntensity2_StartAddress, lumiIt->beamintensity_2, sizeof(float) * nlivebx);
360  //::free(lumiIt->bxindex);
361  //::free(lumiIt->beamintensity_1);
362  //::free(lumiIt->beamintensity_2);
363  } else {
364  bxindex.resize(0);
365  beamintensity_1.resize(0);
366  beamintensity_2.resize(0);
367  }
368  //insert the new row
369  summaryInserter->processNextIteration();
370  summaryInserter->flush();
371  unsigned int algoindx = 1;
372  for (unsigned int j = 0; j < lumi::N_LUMIALGO; ++j, ++algoindx) {
373  d2lumisummary_id = idallocationtable[lumiindx].at(0);
374  lumidetail_id = idallocationtable[lumiindx].at(algoindx);
375  std::vector<PerBXData>::const_iterator bxIt;
376  std::vector<PerBXData>::const_iterator bxBeg;
377  std::vector<PerBXData>::const_iterator bxEnd;
378  if (j == 0) {
379  algoname = std::string("ET");
380  bxBeg = lumiIt->bxET.begin();
381  bxEnd = lumiIt->bxET.end();
382  }
383  if (j == 1) {
384  algoname = std::string("OCC1");
385  bxBeg = lumiIt->bxOCC1.begin();
386  bxEnd = lumiIt->bxOCC1.end();
387  }
388  if (j == 2) {
389  algoname = std::string("OCC2");
390  bxBeg = lumiIt->bxOCC2.begin();
391  bxEnd = lumiIt->bxOCC2.end();
392  }
393  float lumivalue[lumi::N_BX] = {0.0};
394  float lumierror[lumi::N_BX] = {0.0};
395  int lumiquality[lumi::N_BX] = {0};
396  bxlumivalue.resize(sizeof(float) * lumi::N_BX);
397  bxlumierror.resize(sizeof(float) * lumi::N_BX);
398  bxlumiquality.resize(sizeof(short) * lumi::N_BX);
399  void* bxlumivalueStartAddress = bxlumivalue.startingAddress();
400  void* bxlumierrorStartAddress = bxlumierror.startingAddress();
401  void* bxlumiqualityStartAddress = bxlumiquality.startingAddress();
402  unsigned int k = 0;
403  for (bxIt = bxBeg; bxIt != bxEnd; ++bxIt, ++k) {
404  lumivalue[k] = bxIt->lumivalue;
405  lumierror[k] = bxIt->lumierr;
406  lumiquality[k] = bxIt->lumiquality;
407  }
408  std::memmove(bxlumivalueStartAddress, lumivalue, sizeof(float) * lumi::N_BX);
409  std::memmove(bxlumierrorStartAddress, lumierror, sizeof(float) * lumi::N_BX);
410  std::memmove(bxlumiqualityStartAddress, lumiquality, sizeof(short) * lumi::N_BX);
411  detailInserter->processNextIteration();
412  }
413  detailInserter->flush();
414  ++comittedls;
415  if (comittedls == Lumi2DB::COMMITLSINTERVAL) {
416  std::cout << "\t committing in LS chunck " << comittedls << std::endl;
417  delete summaryInserter;
418  summaryInserter = nullptr;
419  delete detailInserter;
420  detailInserter = nullptr;
421  session->transaction().commit();
422  comittedls = 0;
423  std::cout << "\t committed " << std::endl;
424  } else if (lumiindx == (totallumils - 1)) {
425  std::cout << "\t committing at the end" << std::endl;
426  delete summaryInserter;
427  summaryInserter = nullptr;
428  delete detailInserter;
429  detailInserter = nullptr;
430  session->transaction().commit();
431  std::cout << "\t done" << std::endl;
432  }
433  }
434 }
const unsigned int N_LUMIALGO
Definition: ConstantDef.h:4
float applyCalibration(float varToCalibrate) const
Definition: Lumi2DB.cc:116
static const unsigned int COMMITLSINTERVAL
Definition: Lumi2DB.cc:35
static const std::string lumisummaryTableName()
Definition: LumiNames.cc:5
const unsigned int N_BX
Definition: ConstantDef.h:5
static const std::string lumidetailTableName()
Definition: LumiNames.cc:7
unsigned long long generateNextIDForTable(const std::string &tableName, unsigned int interval=1)
Definition: idDealer.cc:33
std::bitset< 8 > alive

◆ writeAllLumiDataToSchema2()

unsigned int lumi::Lumi2DB::writeAllLumiDataToSchema2 ( coral::ISessionProxy *  session,
const std::string &  source,
unsigned int  runnumber,
float  bgev,
unsigned int  ncollidingbunches,
LumiResult::iterator  lumiBeg,
LumiResult::iterator  lumiEnd 
)
private

Definition at line 436 of file Lumi2DB.cc.

References lumi::RevisionDML::addEntry(), lumi::RevisionDML::addRevision(), lumi::RevisionDML::LumiEntry::bgev, lumi::RevisionDML::bookNewEntry(), lumi::RevisionDML::bookNewRevision(), COMMITLSINTERVAL, gather_cfg::cout, lumi::RevisionDML::Entry::data_id, HLT_2024v14_cff::distance, lumi::RevisionDML::Entry::entry_id, lumi::RevisionDML::Entry::entry_name, lumi::RevisionDML::getEntryInBranchByName(), lumi::RevisionDML::insertLumiRunData(), dqmiolumiharvest::j, dqmdumpme::k, lumi::LumiNames::lumidataTableName(), lumi::LumiNames::lumisummaryv2TableName(), lumi::N_BX, lumi::N_LUMIALGO, lumi::RevisionDML::LumiEntry::ncollidingbunches, findAndChange::op, lumi::RevisionDML::Entry::revision_id, lumi::RevisionDML::LumiEntry::runnumber, lumi::RevisionDML::LumiEntry::source, source, and AlCaHLTBitMon_QueryRunRegistry::string.

442  {
444  //output: lumi data id
446  std::cout << "writeAllLumiDataToSchema2" << std::endl;
447  coral::AttributeList summaryData;
448  summaryData.extend("DATA_ID", typeid(unsigned long long));
449  summaryData.extend("RUNNUM", typeid(unsigned int));
450  summaryData.extend("LUMILSNUM", typeid(unsigned int));
451  summaryData.extend("CMSLSNUM", typeid(unsigned int));
452  summaryData.extend("INSTLUMI", typeid(float));
453  summaryData.extend("INSTLUMIERROR", typeid(float));
454  summaryData.extend("INSTLUMIQUALITY", typeid(short));
455  summaryData.extend("BEAMSTATUS", typeid(std::string));
456  summaryData.extend("BEAMENERGY", typeid(float));
457  summaryData.extend("NUMORBIT", typeid(unsigned int));
458  summaryData.extend("STARTORBIT", typeid(unsigned int));
459  summaryData.extend("CMSBXINDEXBLOB", typeid(coral::Blob));
460  summaryData.extend("BEAMINTENSITYBLOB_1", typeid(coral::Blob));
461  summaryData.extend("BEAMINTENSITYBLOB_2", typeid(coral::Blob));
462  summaryData.extend("BXLUMIVALUE_OCC1", typeid(coral::Blob));
463  summaryData.extend("BXLUMIERROR_OCC1", typeid(coral::Blob));
464  summaryData.extend("BXLUMIQUALITY_OCC1", typeid(coral::Blob));
465  summaryData.extend("BXLUMIVALUE_OCC2", typeid(coral::Blob));
466  summaryData.extend("BXLUMIERROR_OCC2", typeid(coral::Blob));
467  summaryData.extend("BXLUMIQUALITY_OCC2", typeid(coral::Blob));
468  summaryData.extend("BXLUMIVALUE_ET", typeid(coral::Blob));
469  summaryData.extend("BXLUMIERROR_ET", typeid(coral::Blob));
470  summaryData.extend("BXLUMIQUALITY_ET", typeid(coral::Blob));
471 
472  unsigned long long& data_id = summaryData["DATA_ID"].data<unsigned long long>();
473  unsigned int& lumirunnum = summaryData["RUNNUM"].data<unsigned int>();
474  unsigned int& lumilsnr = summaryData["LUMILSNUM"].data<unsigned int>();
475  unsigned int& cmslsnr = summaryData["CMSLSNUM"].data<unsigned int>();
476  float& instlumi = summaryData["INSTLUMI"].data<float>();
477  float& instlumierror = summaryData["INSTLUMIERROR"].data<float>();
478  short& instlumiquality = summaryData["INSTLUMIQUALITY"].data<short>();
479  std::string& beamstatus = summaryData["BEAMSTATUS"].data<std::string>();
480  float& beamenergy = summaryData["BEAMENERGY"].data<float>();
481  unsigned int& numorbit = summaryData["NUMORBIT"].data<unsigned int>();
482  unsigned int& startorbit = summaryData["STARTORBIT"].data<unsigned int>();
483  coral::Blob& bxindex = summaryData["CMSBXINDEXBLOB"].data<coral::Blob>();
484  coral::Blob& beamintensity_1 = summaryData["BEAMINTENSITYBLOB_1"].data<coral::Blob>();
485  coral::Blob& beamintensity_2 = summaryData["BEAMINTENSITYBLOB_2"].data<coral::Blob>();
486  coral::Blob& bxlumivalue_et = summaryData["BXLUMIVALUE_ET"].data<coral::Blob>();
487  coral::Blob& bxlumierror_et = summaryData["BXLUMIERROR_ET"].data<coral::Blob>();
488  coral::Blob& bxlumiquality_et = summaryData["BXLUMIQUALITY_ET"].data<coral::Blob>();
489  coral::Blob& bxlumivalue_occ1 = summaryData["BXLUMIVALUE_OCC1"].data<coral::Blob>();
490  coral::Blob& bxlumierror_occ1 = summaryData["BXLUMIERROR_OCC1"].data<coral::Blob>();
491  coral::Blob& bxlumiquality_occ1 = summaryData["BXLUMIQUALITY_OCC1"].data<coral::Blob>();
492  coral::Blob& bxlumivalue_occ2 = summaryData["BXLUMIVALUE_OCC2"].data<coral::Blob>();
493  coral::Blob& bxlumierror_occ2 = summaryData["BXLUMIERROR_OCC2"].data<coral::Blob>();
494  coral::Blob& bxlumiquality_occ2 = summaryData["BXLUMIQUALITY_OCC2"].data<coral::Blob>();
495 
496  lumi::Lumi2DB::LumiResult::const_iterator lumiIt;
497  coral::IBulkOperation* summaryInserter = nullptr;
498 
499  unsigned int totallumils = std::distance(lumiBeg, lumiEnd);
500  unsigned int lumiindx = 0;
501  unsigned int comittedls = 0;
502 
503  unsigned long long branch_id = 3;
504  std::string branch_name("DATA");
505  lumi::RevisionDML revisionDML;
506  lumi::RevisionDML::LumiEntry lumirundata;
507  std::stringstream op;
508  op << irunnumber;
509  std::string runnumberStr = op.str();
510  session->transaction().start(false);
511  lumirundata.entry_name = runnumberStr;
512  lumirundata.source = source;
513  lumirundata.runnumber = irunnumber;
514  lumirundata.bgev = bgev;
515  lumirundata.ncollidingbunches = ncollidingbunches;
516  lumirundata.data_id = 0;
517  lumirundata.entry_id = revisionDML.getEntryInBranchByName(
518  session->nominalSchema(), lumi::LumiNames::lumidataTableName(), runnumberStr, branch_name);
519  //std::cout<<"entry_id "<<lumirundata.entry_id<<std::endl;
520  if (lumirundata.entry_id == 0) {
521  revisionDML.bookNewEntry(session->nominalSchema(), LumiNames::lumidataTableName(), lumirundata);
522  std::cout << "it's a new run lumirundata revision_id " << lumirundata.revision_id << " entry_id "
523  << lumirundata.entry_id << " data_id " << lumirundata.data_id << std::endl;
524  revisionDML.addEntry(session->nominalSchema(), LumiNames::lumidataTableName(), lumirundata, branch_id, branch_name);
525  std::cout << "added entry " << std::endl;
526  } else {
527  revisionDML.bookNewRevision(session->nominalSchema(), LumiNames::lumidataTableName(), lumirundata);
528  std::cout << "lumirundata revision_id " << lumirundata.revision_id << " entry_id " << lumirundata.entry_id
529  << " data_id " << lumirundata.data_id << std::endl;
530  revisionDML.addRevision(
531  session->nominalSchema(), LumiNames::lumidataTableName(), lumirundata, branch_id, branch_name);
532  }
533  revisionDML.insertLumiRunData(session->nominalSchema(), lumirundata);
534  for (lumiIt = lumiBeg; lumiIt != lumiEnd; ++lumiIt, ++lumiindx) {
535  if (!session->transaction().isActive()) {
536  session->transaction().start(false);
537  coral::ITable& summarytable = session->nominalSchema().tableHandle(LumiNames::lumisummaryv2TableName());
538  summaryInserter = summarytable.dataEditor().bulkInsert(summaryData, totallumils);
539  } else {
540  if (lumiIt == lumiBeg) {
541  coral::ITable& summarytable = session->nominalSchema().tableHandle(LumiNames::lumisummaryv2TableName());
542  summaryInserter = summarytable.dataEditor().bulkInsert(summaryData, totallumils);
543  }
544  }
545  data_id = lumirundata.data_id;
546  lumirunnum = irunnumber;
547  lumilsnr = lumiIt->lumilsnr;
548  cmslsnr = lumiIt->cmslsnr;
549  instlumi = lumiIt->instlumi; // not calibrated!
550  instlumierror = lumiIt->instlumierror; // not calibrated!
551  instlumiquality = lumiIt->instlumiquality;
552  beamstatus = lumiIt->beammode;
553  beamenergy = lumiIt->beamenergy;
554  numorbit = lumiIt->numorbit;
555  startorbit = lumiIt->startorbit;
556  short nlivebx = lumiIt->nlivebx;
557  //std::cout<<"nlivebx "<<nlivebx<<std::endl;
558  if (nlivebx != 0) {
559  bxindex.resize(sizeof(short) * nlivebx);
560  beamintensity_1.resize(sizeof(float) * nlivebx);
561  beamintensity_2.resize(sizeof(float) * nlivebx);
562  void* bxindex_StartAddress = bxindex.startingAddress();
563  void* beamIntensity1_StartAddress = beamintensity_1.startingAddress();
564  void* beamIntensity2_StartAddress = beamintensity_2.startingAddress();
565  std::memmove(bxindex_StartAddress, lumiIt->bxindex, sizeof(short) * nlivebx);
566  std::memmove(beamIntensity1_StartAddress, lumiIt->beamintensity_1, sizeof(float) * nlivebx);
567  std::memmove(beamIntensity2_StartAddress, lumiIt->beamintensity_2, sizeof(float) * nlivebx);
568  //::free(lumiIt->bxindex);
569  //::free(lumiIt->beamintensity_1);
570  //::free(lumiIt->beamintensity_2);
571  } else {
572  bxindex.resize(0);
573  beamintensity_1.resize(0);
574  beamintensity_2.resize(0);
575  }
576  for (unsigned int j = 0; j < lumi::N_LUMIALGO; ++j) {
577  std::vector<PerBXData>::const_iterator bxIt;
578  std::vector<PerBXData>::const_iterator bxBeg;
579  std::vector<PerBXData>::const_iterator bxEnd;
580  if (j == 0) { //the push_back order in the input data is ET,OCC1,OCC2
581  //algoname=std::string("ET");
582  bxBeg = lumiIt->bxET.begin();
583  bxEnd = lumiIt->bxET.end();
584  float lumivalue[lumi::N_BX] = {0.0};
585  float lumierror[lumi::N_BX] = {0.0};
586  int lumiquality[lumi::N_BX] = {0};
587  bxlumivalue_et.resize(sizeof(float) * lumi::N_BX);
588  bxlumierror_et.resize(sizeof(float) * lumi::N_BX);
589  bxlumiquality_et.resize(sizeof(short) * lumi::N_BX);
590  void* bxlumivalueStartAddress = bxlumivalue_et.startingAddress();
591  void* bxlumierrorStartAddress = bxlumierror_et.startingAddress();
592  void* bxlumiqualityStartAddress = bxlumiquality_et.startingAddress();
593  unsigned int k = 0;
594  for (bxIt = bxBeg; bxIt != bxEnd; ++bxIt, ++k) {
595  lumivalue[k] = bxIt->lumivalue;
596  lumierror[k] = bxIt->lumierr;
597  lumiquality[k] = bxIt->lumiquality;
598  }
599  std::memmove(bxlumivalueStartAddress, lumivalue, sizeof(float) * lumi::N_BX);
600  std::memmove(bxlumierrorStartAddress, lumierror, sizeof(float) * lumi::N_BX);
601  std::memmove(bxlumiqualityStartAddress, lumiquality, sizeof(short) * lumi::N_BX);
602  }
603  if (j == 1) {
604  //algoname=std::string("OCC1");
605  bxBeg = lumiIt->bxOCC1.begin();
606  bxEnd = lumiIt->bxOCC1.end();
607  float lumivalue[lumi::N_BX] = {0.0};
608  float lumierror[lumi::N_BX] = {0.0};
609  int lumiquality[lumi::N_BX] = {0};
610  bxlumivalue_occ1.resize(sizeof(float) * lumi::N_BX);
611  bxlumierror_occ1.resize(sizeof(float) * lumi::N_BX);
612  bxlumiquality_occ1.resize(sizeof(short) * lumi::N_BX);
613  void* bxlumivalueStartAddress = bxlumivalue_occ1.startingAddress();
614  void* bxlumierrorStartAddress = bxlumierror_occ1.startingAddress();
615  void* bxlumiqualityStartAddress = bxlumiquality_occ1.startingAddress();
616  unsigned int k = 0;
617  for (bxIt = bxBeg; bxIt != bxEnd; ++bxIt, ++k) {
618  lumivalue[k] = bxIt->lumivalue;
619  lumierror[k] = bxIt->lumierr;
620  lumiquality[k] = bxIt->lumiquality;
621  }
622  std::memmove(bxlumivalueStartAddress, lumivalue, sizeof(float) * lumi::N_BX);
623  std::memmove(bxlumierrorStartAddress, lumierror, sizeof(float) * lumi::N_BX);
624  std::memmove(bxlumiqualityStartAddress, lumiquality, sizeof(short) * lumi::N_BX);
625  }
626  if (j == 2) {
627  //algoname=std::string("OCC2");
628  bxBeg = lumiIt->bxOCC2.begin();
629  bxEnd = lumiIt->bxOCC2.end();
630  float lumivalue[lumi::N_BX] = {0.0};
631  float lumierror[lumi::N_BX] = {0.0};
632  int lumiquality[lumi::N_BX] = {0};
633  bxlumivalue_occ2.resize(sizeof(float) * lumi::N_BX);
634  bxlumierror_occ2.resize(sizeof(float) * lumi::N_BX);
635  bxlumiquality_occ2.resize(sizeof(short) * lumi::N_BX);
636  void* bxlumivalueStartAddress = bxlumivalue_occ2.startingAddress();
637  void* bxlumierrorStartAddress = bxlumierror_occ2.startingAddress();
638  void* bxlumiqualityStartAddress = bxlumiquality_occ2.startingAddress();
639  unsigned int k = 0;
640  for (bxIt = bxBeg; bxIt != bxEnd; ++bxIt, ++k) {
641  lumivalue[k] = bxIt->lumivalue;
642  lumierror[k] = bxIt->lumierr;
643  lumiquality[k] = bxIt->lumiquality;
644  }
645  std::memmove(bxlumivalueStartAddress, lumivalue, sizeof(float) * lumi::N_BX);
646  std::memmove(bxlumierrorStartAddress, lumierror, sizeof(float) * lumi::N_BX);
647  std::memmove(bxlumiqualityStartAddress, lumiquality, sizeof(short) * lumi::N_BX);
648  }
649  }
650  summaryInserter->processNextIteration();
651  summaryInserter->flush();
652  ++comittedls;
653  if (comittedls == Lumi2DB::COMMITLSINTERVAL) {
654  std::cout << "\t committing in LS chunck " << comittedls << std::endl;
655  delete summaryInserter;
656  summaryInserter = nullptr;
657  session->transaction().commit();
658  comittedls = 0;
659  std::cout << "\t committed " << std::endl;
660  } else if (lumiindx == (totallumils - 1)) {
661  std::cout << "\t committing at the end" << std::endl;
662  delete summaryInserter;
663  summaryInserter = nullptr;
664  session->transaction().commit();
665  std::cout << "\t done" << std::endl;
666  }
667  }
668  return lumirundata.data_id;
669 }
void addEntry(coral::ISchema &schema, const std::string &datatableName, const Entry &entry, unsigned long long branch_id, const std::string &branchname)
Definition: RevisionDML.cc:60
const unsigned int N_LUMIALGO
Definition: ConstantDef.h:4
static const unsigned int COMMITLSINTERVAL
Definition: Lumi2DB.cc:35
void insertLumiRunData(coral::ISchema &schema, const LumiEntry &lumientry)
Definition: RevisionDML.cc:120
unsigned long long data_id
Definition: RevisionDML.h:31
unsigned long long getEntryInBranchByName(coral::ISchema &schema, const std::string &datatableName, const std::string &entryname, const std::string &branchname)
Definition: RevisionDML.cc:16
unsigned long long revision_id
Definition: RevisionDML.h:29
static const std::string lumidataTableName()
Definition: LumiNames.cc:3
unsigned long long entry_id
Definition: RevisionDML.h:30
void bookNewEntry(coral::ISchema &schema, const std::string &datatableName, Entry &entry)
Definition: RevisionDML.cc:44
const unsigned int N_BX
Definition: ConstantDef.h:5
unsigned int ncollidingbunches
Definition: RevisionDML.h:40
static const std::string lumisummaryv2TableName()
Definition: LumiNames.cc:6
void addRevision(coral::ISchema &schema, const std::string &datatableName, const Entry &revision, unsigned long long branch_id, std::string &branchname)
Definition: RevisionDML.cc:97
static std::string const source
Definition: EdmProvDump.cc:49
void bookNewRevision(coral::ISchema &schema, const std::string &datatableName, Entry &revision)
Definition: RevisionDML.cc:53

◆ writeBeamIntensityOnly()

void lumi::Lumi2DB::writeBeamIntensityOnly ( coral::ISessionProxy *  session,
unsigned int  irunnumber,
const std::string &  ilumiversion,
LumiResult::iterator  lumiBeg,
LumiResult::iterator  lumiEnd 
)
private

Definition at line 154 of file Lumi2DB.cc.

References COMMITLSINTERVAL, gather_cfg::cout, HLT_2024v14_cff::distance, free(), lumi::LumiNames::lumisummaryTableName(), FastTimerService_cff::lumiversion, cond::runnumber, and AlCaHLTBitMon_QueryRunRegistry::string.

158  {
159  coral::AttributeList inputData;
160  inputData.extend("bxindex", typeid(coral::Blob));
161  inputData.extend("beamintensity_1", typeid(coral::Blob));
162  inputData.extend("beamintensity_2", typeid(coral::Blob));
163  inputData.extend("runnum", typeid(unsigned int));
164  inputData.extend("startorbit", typeid(unsigned int));
165  inputData.extend("lumiversion", typeid(std::string));
166  coral::Blob& bxindex = inputData["bxindex"].data<coral::Blob>();
167  coral::Blob& beamintensity_1 = inputData["beamintensity_1"].data<coral::Blob>();
168  coral::Blob& beamintensity_2 = inputData["beamintensity_2"].data<coral::Blob>();
169  unsigned int& runnumber = inputData["runnum"].data<unsigned int>();
170  unsigned int& startorbit = inputData["startorbit"].data<unsigned int>();
171  std::string& lumiversion = inputData["lumiversion"].data<std::string>();
172 
173  lumi::Lumi2DB::LumiResult::const_iterator lumiIt;
174  coral::IBulkOperation* summaryUpdater = nullptr;
175  unsigned int totallumils = std::distance(lumiBeg, lumiEnd);
176  unsigned int lumiindx = 0;
177  unsigned int comittedls = 0;
178  std::string setClause(
179  "CMSBXINDEXBLOB=:bxindex,BEAMINTENSITYBLOB_1=:beamintensity_1,BEAMINTENSITYBLOB_2=:beamintensity_2");
180  std::string condition("RUNNUM=:runnum AND STARTORBIT=:startorbit AND LUMIVERSION=:lumiversion");
181  runnumber = irunnumber;
182  lumiversion = ilumiversion;
183  for (lumiIt = lumiBeg; lumiIt != lumiEnd; ++lumiIt, ++lumiindx) {
184  if (!session->transaction().isActive()) {
185  session->transaction().start(false);
186  }
187  startorbit = lumiIt->startorbit;
188  //std::cout<<"runnumber "<<irunnumber<<" starorbit "<<startorbit<<" lumiversion "<<lumiversion<<" totallumils "<<totallumils<<std::endl;
189  short nlivebx = lumiIt->nlivebx;
190  if (nlivebx != 0) {
191  bxindex.resize(sizeof(short) * nlivebx);
192  beamintensity_1.resize(sizeof(float) * nlivebx);
193  beamintensity_2.resize(sizeof(float) * nlivebx);
194  void* bxindex_StartAddress = bxindex.startingAddress();
195  void* beamIntensity1_StartAddress = beamintensity_1.startingAddress();
196  void* beamIntensity2_StartAddress = beamintensity_2.startingAddress();
197  std::memmove(bxindex_StartAddress, lumiIt->bxindex, sizeof(short) * nlivebx);
198  std::memmove(beamIntensity1_StartAddress, lumiIt->beamintensity_1, sizeof(float) * nlivebx);
199  std::memmove(beamIntensity2_StartAddress, lumiIt->beamintensity_2, sizeof(float) * nlivebx);
200  ::free(lumiIt->bxindex);
201  ::free(lumiIt->beamintensity_1);
202  ::free(lumiIt->beamintensity_2);
203  } else {
204  bxindex.resize(0);
205  beamintensity_1.resize(0);
206  beamintensity_2.resize(0);
207  }
208  coral::ITable& summarytable = session->nominalSchema().tableHandle(LumiNames::lumisummaryTableName());
209  summaryUpdater = summarytable.dataEditor().bulkUpdateRows(setClause, condition, inputData, totallumils);
210  summaryUpdater->processNextIteration();
211  summaryUpdater->flush();
212  ++comittedls;
213  if (comittedls == Lumi2DB::COMMITLSINTERVAL) {
214  std::cout << "\t committing in LS chunck " << comittedls << std::endl;
215  delete summaryUpdater;
216  summaryUpdater = nullptr;
217  session->transaction().commit();
218  comittedls = 0;
219  std::cout << "\t committed " << std::endl;
220  } else if (lumiindx == (totallumils - 1)) {
221  std::cout << "\t committing at the end" << std::endl;
222  delete summaryUpdater;
223  summaryUpdater = nullptr;
224  session->transaction().commit();
225  std::cout << "\t done" << std::endl;
226  }
227  }
228 }
void free(void *ptr) noexcept
static const unsigned int COMMITLSINTERVAL
Definition: Lumi2DB.cc:35
static const std::string lumisummaryTableName()
Definition: LumiNames.cc:5

Member Data Documentation

◆ COMMITLSINTERVAL

const unsigned int lumi::Lumi2DB::COMMITLSINTERVAL = 500
static

Definition at line 35 of file Lumi2DB.cc.

Referenced by writeAllLumiData(), writeAllLumiDataToSchema2(), and writeBeamIntensityOnly().