diff --git a/CalibPPS/ESProducers/python/ctppsLHCInfo_cff.py b/CalibPPS/ESProducers/python/ctppsLHCInfo_cff.py index 3403647fe8463..c9c90ba55aca1 100644 --- a/CalibPPS/ESProducers/python/ctppsLHCInfo_cff.py +++ b/CalibPPS/ESProducers/python/ctppsLHCInfo_cff.py @@ -2,6 +2,8 @@ # by default, LHCInfo is now loaded from CondDB using a GT ctppsLHCInfoLabel = cms.string("") +ctppsLHCInfoPerLSLabel = cms.string("") +ctppsLHCInfoPerFillLabel = cms.string("") ## minimal LHCInfo for 2016 data #ctppsLHCInfoLabel = cms.string("ctpps_minimal") diff --git a/Calibration/PPSAlCaRecoProducer/python/ALCARECOPPSCalMaxTracks_cff.py b/Calibration/PPSAlCaRecoProducer/python/ALCARECOPPSCalMaxTracks_cff.py index 8aca8139fe15d..edb5894ff9f91 100644 --- a/Calibration/PPSAlCaRecoProducer/python/ALCARECOPPSCalMaxTracks_cff.py +++ b/Calibration/PPSAlCaRecoProducer/python/ALCARECOPPSCalMaxTracks_cff.py @@ -1,3 +1,5 @@ +print("in file ALCARECOPPSCalMaxTracks_cff.py") + import FWCore.ParameterSet.Config as cms # 1. HLT filter @@ -14,9 +16,12 @@ from EventFilter.CTPPSRawToDigi.ctppsRawToDigi_cff import totemTimingRawToDigi as _totemTimingRawToDigi from EventFilter.CTPPSRawToDigi.ctppsRawToDigi_cff import ctppsPixelDigis as _ctppsPixelDigis -ctppsDiamondRawToDigiAlCaRecoProducer = _ctppsDiamondRawToDigi.clone(rawDataTag = 'hltPPSCalibrationRaw') -totemTimingRawToDigiAlCaRecoProducer = _totemTimingRawToDigi.clone(rawDataTag = 'hltPPSCalibrationRaw') -ctppsPixelDigisAlCaRecoProducer = _ctppsPixelDigis.clone(inputLabel = 'hltPPSCalibrationRaw') +# ctppsDiamondRawToDigiAlCaRecoProducer = _ctppsDiamondRawToDigi.clone(rawDataTag = 'hltPPSCalibrationRaw') +# totemTimingRawToDigiAlCaRecoProducer = _totemTimingRawToDigi.clone(rawDataTag = 'hltPPSCalibrationRaw') +# ctppsPixelDigisAlCaRecoProducer = _ctppsPixelDigis.clone(inputLabel = 'hltPPSCalibrationRaw') +ctppsDiamondRawToDigiAlCaRecoProducer = _ctppsDiamondRawToDigi.clone(rawDataTag = 'rawDataCollector') +totemTimingRawToDigiAlCaRecoProducer = _totemTimingRawToDigi.clone(rawDataTag = 'rawDataCollector') +ctppsPixelDigisAlCaRecoProducer = _ctppsPixelDigis.clone(inputLabel = 'rawDataCollector') ctppsRawToDigiTaskAlCaRecoProducer = cms.Task( ctppsDiamondRawToDigiAlCaRecoProducer, @@ -85,7 +90,8 @@ ) from RecoPPS.ProtonReconstruction.ctppsProtons_cff import ctppsProtons as _ctppsProtons -ctppsProtonsAlCaRecoProducer = _ctppsProtons.clone(tagLocalTrackLite = 'ctppsLocalTrackLiteProducerAlCaRecoProducer') +ctppsProtonsAlCaRecoProducer = _ctppsProtons.clone(tagLocalTrackLite = 'ctppsLocalTrackLiteProducerAlCaRecoProducer', +verbosity = cms.untracked.uint32(2)) # 5. RECO - final task assembly #------------------------------------------------------ diff --git a/Calibration/PPSAlCaRecoProducer/test/test_express_AlCaRecoProducer.sh b/Calibration/PPSAlCaRecoProducer/test/test_express_AlCaRecoProducer.sh index 3f4698792197f..83f37d797cedc 100755 --- a/Calibration/PPSAlCaRecoProducer/test/test_express_AlCaRecoProducer.sh +++ b/Calibration/PPSAlCaRecoProducer/test/test_express_AlCaRecoProducer.sh @@ -2,11 +2,16 @@ function die { echo $1: status $2; exit $2; } customise_commands="process.GlobalTag.toGet = cms.VPSet()\ +\nprocess.GlobalTag.toGet.append(cms.PSet(record = cms.string(\"LHCInfoPerLSRcd\"),tag = cms.string(\"LHCInfoPerLS_end_2\"), connect = cms.string(\"sqlite_file:/eos/home-j/jchyczyn/new/CMSSW_12_5_0_pre3/src/CondTools/RunInfo/python/lhcinfo_pop_test.db\")))\ +\nprocess.GlobalTag.toGet.append(cms.PSet(record = cms.string(\"CTPPSOpticsRcd\"),tag = cms.string(\"PPSOpticalFunctions_test\"), connect = cms.string(\"sqlite_file:/afs/cern.ch/user/w/wcarvalh/public/CTPPS/optical_functions/validation/Aug22/PPSOpticalFunctions_singleIOV_2022_with_verticals.db\")))\ +\nprocess.GlobalTag.toGet.append(cms.PSet(record = cms.string(\"LHCInfoPerFillRcd\"),tag = cms.string(\"LHCInfoPerFill_end_2\"), connect = cms.string(\"sqlite_file:/eos/home-j/jchyczyn/new/CMSSW_12_5_0_pre3/src/CondTools/RunInfo/python/lhcinfo_pop_test.db\")))\ +\nprocess.GlobalTag.toGet.append(cms.PSet(record = cms.string(\"LHCInfoRcd\"),tag = cms.string(\"LHCInfo_end_2\"), connect = cms.string(\"sqlite_file:/eos/home-j/jchyczyn/new/CMSSW_12_5_0_pre3/src/CondTools/RunInfo/python/lhcinfo_pop_test.db\")))\ \nprocess.GlobalTag.toGet.append(cms.PSet(record = cms.string(\"AlCaRecoTriggerBitsRcd\"),tag = cms.string(\"AlCaRecoHLTpaths_PPS2022_express_v1\"), connect = cms.string(\"frontier://FrontierProd/CMS_CONDITIONS\")))\ -\nprocess.GlobalTag.toGet.append(cms.PSet(record = cms.string(\"PPSTimingCalibrationLUTRcd\"),tag = cms.string(\"PPSDiamondTimingCalibrationLUT_test\"), connect = cms.string(\"frontier://FrontierProd/CMS_CONDITIONS\")))\ -\nprocess.ALCARECOPPSCalMaxTracksFilter.TriggerResultsTag = cms.InputTag(\"TriggerResults\",\"\",\"HLTX\")" +\nprocess.GlobalTag.toGet.append(cms.PSet(record = cms.string(\"PPSTimingCalibrationLUTRcd\"),tag = cms.string(\"PPSDiamondTimingCalibrationLUT_test\"), connect = cms.string(\"frontier://FrontierProd/CMS_CONDITIONS\")))" +# \nprocess.ALCARECOPPSCalMaxTracksFilter.TriggerResultsTag = cms.InputTag(\"TriggerResults\",\"\",\"HLT\")" -INPUTFILE="/store/group/alca_global/pps_alcareco_producer_tests/outputALCAPPS_single.root" +INPUTFILE="/store/data/Run2022C/ZeroBias/RAW/v1/000/356/615/00000/a4076bff-3bec-459e-bd44-b66538bf5c2b.root" +# INPUTFILE="/store/group/alca_global/pps_alcareco_producer_tests/outputALCAPPS_single.root" COMMMAND=`xrdfs cms-xrd-global.cern.ch locate $INPUTFILE` STATUS=$? echo "xrdfs command status = "$STATUS @@ -15,13 +20,13 @@ if [ $STATUS -eq 0 ]; then (cmsDriver.py testExpressPPSAlCaRecoProducer -s ALCAPRODUCER:PPSCalMaxTracks,ENDJOB \ --process ALCARECO \ --scenario pp \ - --era ctpps_2018 \ + --era run3_HB \ --conditions auto:run3_data_express \ --data \ --datatier ALCARECO \ --eventcontent ALCARECO \ --nThreads 8 \ - --number 100 --filein ${INPUTFILE} \ + --number 10000 --filein ${INPUTFILE} \ --fileout file:outputALCAPPS_RECO_express.root \ --customise_commands="$customise_commands") || die 'failed running test_express_AlCaRecoProducer' $? else diff --git a/Calibration/PPSAlCaRecoProducer/test/test_prompt_PPSAlCaReco_output.py b/Calibration/PPSAlCaRecoProducer/test/test_prompt_PPSAlCaReco_output.py index 9b61d494952b7..cc296881a5d67 100644 --- a/Calibration/PPSAlCaRecoProducer/test/test_prompt_PPSAlCaReco_output.py +++ b/Calibration/PPSAlCaRecoProducer/test/test_prompt_PPSAlCaReco_output.py @@ -1,9 +1,10 @@ import FWCore.ParameterSet.Config as cms # load era modifier to run on 2018 data -from Configuration.Eras.Modifier_ctpps_2018_cff import ctpps_2018 +# from Configuration.Eras.Modifier_ctpps_2018_cff import ctpps_2018 +from Configuration.Eras.Modifier_ctpps_2022_cff import ctpps_2022 -process = cms.Process( 'TEST',ctpps_2018) +process = cms.Process( 'TEST',ctpps_2022) # LHCInfo plotter process.load("Validation.CTPPS.ctppsLHCInfoPlotter_cfi") diff --git a/CondCore/RunInfoPlugins/src/plugin.cc b/CondCore/RunInfoPlugins/src/plugin.cc index 519e4fac7eb30..a7821a6a4dd64 100644 --- a/CondCore/RunInfoPlugins/src/plugin.cc +++ b/CondCore/RunInfoPlugins/src/plugin.cc @@ -10,6 +10,10 @@ #include "CondFormats/RunInfo/interface/FillInfo.h" #include "CondFormats/DataRecord/interface/LHCInfoRcd.h" #include "CondFormats/RunInfo/interface/LHCInfo.h" +#include "CondFormats/DataRecord/interface/LHCInfoPerLSRcd.h" +#include "CondFormats/RunInfo/interface/LHCInfoPerLS.h" +#include "CondFormats/DataRecord/interface/LHCInfoPerFillRcd.h" +#include "CondFormats/RunInfo/interface/LHCInfoPerFill.h" REGISTER_PLUGIN(RunSummaryRcd, RunSummary); REGISTER_PLUGIN(RunInfoRcd, RunInfo); @@ -17,3 +21,5 @@ REGISTER_PLUGIN(L1TriggerScalerRcd, L1TriggerScaler); REGISTER_PLUGIN(MixingRcd, MixingModuleConfig); REGISTER_PLUGIN(FillInfoRcd, FillInfo); REGISTER_PLUGIN(LHCInfoRcd, LHCInfo); +REGISTER_PLUGIN(LHCInfoPerLSRcd, LHCInfoPerLS); +REGISTER_PLUGIN(LHCInfoPerFillRcd, LHCInfoPerFill); \ No newline at end of file diff --git a/CondCore/Utilities/plugins/Module_2XML.cc b/CondCore/Utilities/plugins/Module_2XML.cc index 0e99a897e891b..545686d069e15 100644 --- a/CondCore/Utilities/plugins/Module_2XML.cc +++ b/CondCore/Utilities/plugins/Module_2XML.cc @@ -211,6 +211,8 @@ PAYLOAD_2XML_MODULE(pluginUtilities_payload2xml) { PAYLOAD_2XML_CLASS(L1TriggerKeyExt); PAYLOAD_2XML_CLASS(L1TriggerKeyListExt); PAYLOAD_2XML_CLASS(LHCInfo); + PAYLOAD_2XML_CLASS(LHCInfoPerFill); + PAYLOAD_2XML_CLASS(LHCInfoPerLS); PAYLOAD_2XML_CLASS(METCorrectorParametersCollection); PAYLOAD_2XML_CLASS(MEtXYcorrectParametersCollection); PAYLOAD_2XML_CLASS(MagFieldConfig); diff --git a/CondCore/Utilities/src/CondFormats.h b/CondCore/Utilities/src/CondFormats.h index 38e8e8273909f..bc70211ada4f7 100644 --- a/CondCore/Utilities/src/CondFormats.h +++ b/CondCore/Utilities/src/CondFormats.h @@ -139,6 +139,9 @@ #include "CondFormats/RecoMuonObjects/interface/DYTParamObject.h" #include "CondFormats/RunInfo/interface/RunInfo.h" #include "CondFormats/RunInfo/interface/LHCInfo.h" +#include "CondFormats/RunInfo/interface/LHCInfoVectorizedFields.h" +#include "CondFormats/RunInfo/interface/LHCInfoPerFill.h" +#include "CondFormats/RunInfo/interface/LHCInfoPerLS.h" #include "CondFormats/RunInfo/interface/MixingModuleConfig.h" #include "CondFormats/SiPixelObjects/interface/SiPixelCalibConfiguration.h" #include "CondFormats/SiPixelObjects/interface/SiPixelCPEGenericErrorParm.h" diff --git a/CondFormats/DataRecord/interface/LHCInfoPerFillRcd.h b/CondFormats/DataRecord/interface/LHCInfoPerFillRcd.h new file mode 100644 index 0000000000000..5a4327a9baaa8 --- /dev/null +++ b/CondFormats/DataRecord/interface/LHCInfoPerFillRcd.h @@ -0,0 +1,25 @@ +#ifndef LHCInfoPerFillRcd_LHCInfoPerFillRcd_h +#define LHCInfoPerFillRcd_LHCInfoPerFillRcd_h +// -*- C++ -*- +// +// Package: CondFormats/DataRecord +// Class : LHCInfoPerFillRcd +// +/**\class LHCInfoPerFillRcd LHCInfoPerFillRcd.h CondFormats/DataRecord/interface/LHCInfoPerFillRcd.h + + Description: [one line class summary] + + Usage: + + +*/ +// +// Author: Jan Krzysztof Chyczynski +// Created: Wed, 13 Jul 2022 16:36:24 GMT +// + +#include "FWCore/Framework/interface/EventSetupRecordImplementation.h" + +class LHCInfoPerFillRcd : public edm::eventsetup::EventSetupRecordImplementation {}; + +#endif diff --git a/CondFormats/DataRecord/interface/LHCInfoPerLSRcd.h b/CondFormats/DataRecord/interface/LHCInfoPerLSRcd.h new file mode 100644 index 0000000000000..15a6aab20bfeb --- /dev/null +++ b/CondFormats/DataRecord/interface/LHCInfoPerLSRcd.h @@ -0,0 +1,26 @@ +#ifndef DataRecord_LHCInfoPerLSRcd_h +#define DataRecord_LHCInfoPerLSRcd_h +// -*- C++ -*- +// +// Package: DataRecord +// Class : LHCInfoPerLSRcd +// +/**\class LHCInfoPerLSRcd LHCInfoPerLSRcd.h CondFormats/DataRecord/interface/LHCInfoPerLSRcd.h + + Description: [one line class summary] + + Usage: + + +*/ +// +// Author: +// Created: Tue Feb 15 2022 +// $Id$ +// + +#include "FWCore/Framework/interface/EventSetupRecordImplementation.h" + +class LHCInfoPerLSRcd : public edm::eventsetup::EventSetupRecordImplementation {}; + +#endif diff --git a/CondFormats/DataRecord/src/LHCInfoPerFillRcd.cc b/CondFormats/DataRecord/src/LHCInfoPerFillRcd.cc new file mode 100644 index 0000000000000..9c9f638faa3d9 --- /dev/null +++ b/CondFormats/DataRecord/src/LHCInfoPerFillRcd.cc @@ -0,0 +1,15 @@ +// -*- C++ -*- +// +// Package: CondFormats/DataRecord +// Class : LHCInfoPerFillRcd +// +// Implementation: +// [Notes on implementation] +// +// Author: Jan Krzysztof Chyczynski +// Created: Wed, 13 Jul 2022 16:36:24 GMT + +#include "CondFormats/DataRecord/interface/LHCInfoPerFillRcd.h" +#include "FWCore/Framework/interface/eventsetuprecord_registration_macro.h" + +EVENTSETUP_RECORD_REG(LHCInfoPerFillRcd); diff --git a/CondFormats/DataRecord/src/LHCInfoPerLSRcd.cc b/CondFormats/DataRecord/src/LHCInfoPerLSRcd.cc new file mode 100644 index 0000000000000..bda8c25a75bb9 --- /dev/null +++ b/CondFormats/DataRecord/src/LHCInfoPerLSRcd.cc @@ -0,0 +1,16 @@ +// -*- C++ -*- +// +// Package: DataRecord +// Class : LHCInfoPerLSRcd +// +// Implementation: +// [Notes on implementation] +// +// Author: +// Created: Tue Feb 15 2022 +// $Id$ + +#include "CondFormats/DataRecord/interface/LHCInfoPerLSRcd.h" +#include "FWCore/Framework/interface/eventsetuprecord_registration_macro.h" + +EVENTSETUP_RECORD_REG(LHCInfoPerLSRcd); diff --git a/CondFormats/RunInfo/BuildFile.xml b/CondFormats/RunInfo/BuildFile.xml index acc4955cf3993..ae9ac304b6e7a 100644 --- a/CondFormats/RunInfo/BuildFile.xml +++ b/CondFormats/RunInfo/BuildFile.xml @@ -1,9 +1,12 @@ + + + diff --git a/CondFormats/RunInfo/interface/LHCInfoCombined.h b/CondFormats/RunInfo/interface/LHCInfoCombined.h new file mode 100644 index 0000000000000..82194b12ccce0 --- /dev/null +++ b/CondFormats/RunInfo/interface/LHCInfoCombined.h @@ -0,0 +1,56 @@ +#ifndef CondFormats_RunInfo_LHCInfoCombined_H +#define CondFormats_RunInfo_LHCInfoCombined_H + +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/ESWatcher.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/ConsumesCollector.h" + +#include "CondFormats/RunInfo/interface/LHCInfo.h" +#include "CondFormats/RunInfo/interface/LHCInfoPerLS.h" +#include "CondFormats/RunInfo/interface/LHCInfoPerFill.h" + +#include "CondFormats/DataRecord/interface/LHCInfoPerLSRcd.h" +#include "CondFormats/DataRecord/interface/LHCInfoPerFillRcd.h" +#include "CondFormats/DataRecord/interface/LHCInfoRcd.h" + +#include "CondCore/CondDB/interface/Types.h" + +#include +#include +#include +#include +#include + +class LHCInfoCombined { +public: + + LHCInfoCombined() = default; + + LHCInfoCombined(const LHCInfo& lhcInfo); + LHCInfoCombined(const LHCInfoPerLS& infoPerLS, const LHCInfoPerFill& infoPerFill); + LHCInfoCombined(const edm::EventSetup &iSetup, + const edm::ESGetToken& tokenInfoPerLS, + const edm::ESGetToken& tokenInfoPerFill, + const edm::ESGetToken& tokenInfo); + + void setFromLHCInfo(const LHCInfo& lhcInfo); + void setFromPerLS(const LHCInfoPerLS& infoPerLS); + void setFromPerFill(const LHCInfoPerFill& infoPerFill); + + float crossingAngleX; + float crossingAngleY; + float betaStarX; + float betaStarY; + float energy; + + void print(std::stringstream& ss) const; +}; + +std::ostream& operator<<(std::ostream& os, LHCInfoCombined beamInfo); + +#endif // CondFormats_RunInfo_LHCInfoCombined_H diff --git a/CondFormats/RunInfo/interface/LHCInfoPerFill.h b/CondFormats/RunInfo/interface/LHCInfoPerFill.h new file mode 100644 index 0000000000000..6611402e3ff64 --- /dev/null +++ b/CondFormats/RunInfo/interface/LHCInfoPerFill.h @@ -0,0 +1,255 @@ +#ifndef CondFormats_RunInfo_LHCInfoPerFill_H +#define CondFormats_RunInfo_LHCInfoPerFill_H + +#include "CondFormats/Serialization/interface/Serializable.h" +#include "CondFormats/RunInfo/interface/LHCInfoVectorizedFields.h" +#include "CondFormats/Common/interface/Time.h" +#include +#include +#include +#include +#include + +class LHCInfoPerFill : public LHCInfoVectorizedFields { +public: + enum FillType { UNKNOWN = 0, PROTONS, IONS, COSMICS, GAP }; + enum ParticleType { NONE = 0, PROTON, PB82, AR18, D, XE54 }; + + enum IntParamIndex { + LHC_FILL = 0, + BUNCHES_1, + BUNCHES_2, + COLLIDING_BUNCHES, + TARGET_BUNCHES, + FILL_TYPE, + PARTICLES_1, + PARTICLES_2, + ISIZE + }; + enum FloatParamIndex { + INTENSITY_1 = 0, + INTENSITY_2, + ENERGY, + DELIV_LUMI, + REC_LUMI, + LUMI_PER_B, + BEAM1_VC, + BEAM2_VC, + BEAM1_RF, + BEAM2_RF, + INST_LUMI, + INST_LUMI_ERR, + FSIZE + }; + enum TimeParamIndex { + CREATE_TIME = 0, + BEGIN_TIME, + END_TIME, + TSIZE + }; + enum StringParamIndex { + INJECTION_SCHEME = 0, + LHC_STATE, + LHC_COMMENT, + CTPPS_STATUS, + SSIZE + }; + + typedef FillType FillTypeId; + typedef ParticleType ParticleTypeId; + LHCInfoPerFill(); + + LHCInfoPerFill* cloneFill() const; + + //constant static unsigned integer hosting the maximum number of LHC bunch slots + static size_t const bunchSlots = 3564; + + //constant static unsigned integer hosting the available number of LHC bunch slots + static size_t const availableBunchSlots = 2808; + + void setFillNumber(unsigned short lhcFill); + + //getters + unsigned short const fillNumber() const; + + unsigned short const bunchesInBeam1() const; + + unsigned short const bunchesInBeam2() const; + + unsigned short const collidingBunches() const; + + unsigned short const targetBunches() const; + + FillTypeId const fillType() const; + + ParticleTypeId const particleTypeForBeam1() const; + + ParticleTypeId const particleTypeForBeam2() const; + + float const intensityForBeam1() const; + + float const intensityForBeam2() const; + + float const energy() const; + + float const delivLumi() const; + + float const recLumi() const; + + float const instLumi() const; + + float const instLumiError() const; + + cond::Time_t const createTime() const; + + cond::Time_t const beginTime() const; + + cond::Time_t const endTime() const; + + std::string const& injectionScheme() const; + + std::vector const& lumiPerBX() const; + + std::string const& lhcState() const; + + std::string const& lhcComment() const; + + std::string const& ctppsStatus() const; + + std::vector const& beam1VC() const; + + std::vector const& beam2VC() const; + + std::vector const& beam1RF() const; + + std::vector const& beam2RF() const; + + std::vector& beam1VC(); + + std::vector& beam2VC(); + + std::vector& beam1RF(); + + std::vector& beam2RF(); + + //returns a boolean, true if the injection scheme has a leading 25ns + //TODO: parse the circulating bunch configuration, instead of the string. + bool is25nsBunchSpacing() const; + + //returns a boolean, true if the bunch slot number is in the circulating bunch configuration + bool isBunchInBeam1(size_t const& bunch) const; + + bool isBunchInBeam2(size_t const& bunch) const; + + //member functions returning *by value* a vector with all filled bunch slots + std::vector bunchConfigurationForBeam1() const; + + std::vector bunchConfigurationForBeam2() const; + + //setters + void setBunchesInBeam1(unsigned short const& bunches); + + void setBunchesInBeam2(unsigned short const& bunches); + + void setCollidingBunches(unsigned short const& collidingBunches); + + void setTargetBunches(unsigned short const& targetBunches); + + void setFillType(FillTypeId const& fillType); + + void setParticleTypeForBeam1(ParticleTypeId const& particleType); + + void setParticleTypeForBeam2(ParticleTypeId const& particleType); + + void setIntensityForBeam1(float const& intensity); + + void setIntensityForBeam2(float const& intensity); + + void setEnergy(float const& energy); + + void setDelivLumi(float const& delivLumi); + + void setRecLumi(float const& recLumi); + + void setInstLumi(float const& instLumi); + + void setInstLumiError(float const& instLumiError); + + void setCreationTime(cond::Time_t const& createTime); + + void setBeginTime(cond::Time_t const& beginTime); + + void setEndTime(cond::Time_t const& endTime); + + void setInjectionScheme(std::string const& injectionScheme); + + void setLumiPerBX(std::vector const& lumiPerBX); + + void setLhcState(std::string const& lhcState); + + void setLhcComment(std::string const& lhcComment); + + void setCtppsStatus(std::string const& ctppsStatus); + + void setBeam1VC(std::vector const& beam1VC); + + void setBeam2VC(std::vector const& beam2VC); + + void setBeam1RF(std::vector const& beam1RF); + + void setBeam2RF(std::vector const& beam2RF); + + //sets all values in one go + void setInfo(unsigned short const& bunches1, + unsigned short const& bunches2, + unsigned short const& collidingBunches, + unsigned short const& targetBunches, + FillTypeId const& fillType, + ParticleTypeId const& particleType1, + ParticleTypeId const& particleType2, + float const& intensity1, + float const& intensity2, + float const& energy, + float const& delivLumi, + float const& recLumi, + float const& instLumi, + float const& instLumiError, + cond::Time_t const& createTime, + cond::Time_t const& beginTime, + cond::Time_t const& endTime, + std::string const& scheme, + std::vector const& lumiPerBX, + std::string const& lhcState, + std::string const& lhcComment, + std::string const& ctppsStatus, + std::vector const& beam1VC, + std::vector const& beam2VC, + std::vector const& beam1RF, + std::vector const& beam2RF, + std::bitset const& bunchConf1, + std::bitset const& bunchConf2); + + bool equals(const LHCInfoPerFill& rhs) const; + + bool empty() const; + + //dumping values on output stream + void print(std::stringstream& ss) const; + + std::bitset const& bunchBitsetForBeam1() const; + + std::bitset const& bunchBitsetForBeam2() const; + + void setBunchBitsetForBeam1(std::bitset const& bunchConfiguration); + + void setBunchBitsetForBeam2(std::bitset const& bunchConfiguration); + +private: + std::bitset m_bunchConfiguration1, m_bunchConfiguration2; + + COND_SERIALIZABLE; +}; + +std::ostream& operator<<(std::ostream&, LHCInfoPerFill lhcInfoPerFill); + +#endif // CondFormats_RunInfo_LHCInfoPerFill_H diff --git a/CondFormats/RunInfo/interface/LHCInfoPerLS.h b/CondFormats/RunInfo/interface/LHCInfoPerLS.h new file mode 100644 index 0000000000000..5fa3c5be3d251 --- /dev/null +++ b/CondFormats/RunInfo/interface/LHCInfoPerLS.h @@ -0,0 +1,88 @@ +#ifndef CondFormats_RunInfo_LHCInfoPerLS_H +#define CondFormats_RunInfo_LHCInfoPerLS_H + +#include "CondFormats/Serialization/interface/Serializable.h" +#include "CondFormats/RunInfo/interface/LHCInfoVectorizedFields.h" + +#include "CondCore/CondDB/interface/Types.h" + +#include +#include +#include +#include +#include + +class LHCInfoPerLS : public LHCInfoVectorizedFields { +public: + enum IntParamIndex { + LHC_FILL = 0, + LUMI_SECTION, + ISIZE + }; + enum FloatParamIndex { + CROSSING_ANGLE_X = 0, + CROSSING_ANGLE_Y, + BETA_STAR_X, + BETA_STAR_Y, + FSIZE + }; + enum TimeParamIndex { + RUN_NUMBER = 0, + TSIZE + }; + + LHCInfoPerLS(); + + //getters + unsigned short const fillNumber() const; + + unsigned int const& lumiSection() const; + + float const crossingAngleX() const; + + float const crossingAngleY() const; + + float const betaStarX() const; + + float const betaStarY() const; + + cond::Time_t runNumber() const; + + + //setters + void setFillNumber(unsigned short const& lhcFill); + + void setLumiSection(unsigned int const& lumiSection); + + void setCrossingAngleX(float const& angle); + + void setCrossingAngleY(float const& angle); + + void setBetaStarX(float const& betaStar); + + void setBetaStarY(float const& betaStar); + + void setRunNumber(cond::Time_t const& runNumber); + + //sets all values in one go + void setInfo(unsigned short const& lhcFill, + unsigned int const& lumiSection, + float const& angleX, + float const& angleY, + float const& betaX, + float const& betaY, + cond::Time_t const& runNumber); + + bool equals(const LHCInfoPerLS& rhs) const; + + bool empty() const; + + //dumping values on output stream + void print(std::stringstream& ss) const; + + COND_SERIALIZABLE; +}; + +std::ostream& operator<<(std::ostream&, LHCInfoPerLS lhcInfo); + +#endif // CondFormats_RunInfo_LHCInfoPerLS_H diff --git a/CondFormats/RunInfo/interface/LHCInfoVectorizedFields.h b/CondFormats/RunInfo/interface/LHCInfoVectorizedFields.h new file mode 100644 index 0000000000000..094f08fac0319 --- /dev/null +++ b/CondFormats/RunInfo/interface/LHCInfoVectorizedFields.h @@ -0,0 +1,44 @@ +#ifndef CondFormats_RunInfo_LHCInfoVectorizedFields_H +#define CondFormats_RunInfo_LHCInfoVectorizedFields_H + +#include "CondFormats/Serialization/interface/Serializable.h" +#include + +class LHCInfoVectorizedFields { +public: + enum IntParamIndex { ISIZE = 0 }; + enum FloatParamIndex { FSIZE = 0 }; + enum TimeParamIndex { TSIZE = 0 }; + enum StringParamIndex { SSIZE = 0 }; + + LHCInfoVectorizedFields(); + +protected: + LHCInfoVectorizedFields(size_t iSize, size_t fSize, size_t tSize, size_t sSize); + + bool m_isData = false; + std::vector > m_intParams; + std::vector > m_floatParams; + std::vector > m_timeParams; + std::vector > m_stringParams; + +public: + template + static const T& getParams(const std::vector& params, size_t index); + + template + static T& accessParams(std::vector& params, size_t index); + + template + static const T& getOneParam(const std::vector >& params, size_t index); + + template + static void setOneParam(std::vector >& params, size_t index, const T& value); + + template + static void setParams(std::vector& params, size_t index, const T& value); + + COND_SERIALIZABLE; +}; + +#endif // CondFormats_RunInfo_LHCInfoVectorizedFields_H \ No newline at end of file diff --git a/CondFormats/RunInfo/src/LHCInfoCombined.cc b/CondFormats/RunInfo/src/LHCInfoCombined.cc new file mode 100644 index 0000000000000..550892621f038 --- /dev/null +++ b/CondFormats/RunInfo/src/LHCInfoCombined.cc @@ -0,0 +1,57 @@ +#include "CondFormats/RunInfo/interface/LHCInfoCombined.h" + +LHCInfoCombined::LHCInfoCombined(const LHCInfo& lhcInfo) { + setFromLHCInfo(lhcInfo); +} + +LHCInfoCombined::LHCInfoCombined(const LHCInfoPerLS& infoPerLS, const LHCInfoPerFill& infoPerFill) { + setFromPerLS(infoPerLS); + setFromPerFill(infoPerFill); +} + +LHCInfoCombined::LHCInfoCombined(const edm::EventSetup &iSetup, + const edm::ESGetToken& tokenInfoPerLS, + const edm::ESGetToken& tokenInfoPerFill, + const edm::ESGetToken& tokenInfo) { + if(true /* era run3 */) { + edm::ESHandle hLHCInfoPerLS = iSetup.getHandle(tokenInfoPerLS); + edm::ESHandle hLHCInfoFill = iSetup.getHandle(tokenInfoPerFill); + setFromPerLS(*hLHCInfoPerLS); + setFromPerFill(*hLHCInfoFill); + } else { + edm::ESHandle hLHCInfo = iSetup.getHandle(tokenInfo); + setFromLHCInfo(*hLHCInfo); + } +} + +void LHCInfoCombined::setFromLHCInfo(const LHCInfo& lhcInfo) { + crossingAngleX = lhcInfo.crossingAngle(); + crossingAngleY = 0; + betaStarX = lhcInfo.betaStar(); + betaStarY = lhcInfo.betaStar(); + energy = lhcInfo.energy(); +} +void LHCInfoCombined::setFromPerLS(const LHCInfoPerLS& infoPerLS) { + crossingAngleX = infoPerLS.crossingAngleX(); + crossingAngleY = infoPerLS.crossingAngleY(); + betaStarX = infoPerLS.betaStarX(); + betaStarY = infoPerLS.betaStarY(); +} +void LHCInfoCombined::setFromPerFill(const LHCInfoPerFill& infoPerFill) { + energy = infoPerFill.energy(); +} + +void LHCInfoCombined::print(std::stringstream& ss) const { + ss << "Crossing angle x (urad): " << crossingAngleX << std::endl + << "Crossing angle y (urad): " << crossingAngleY << std::endl + << "Beta star x (m): " << betaStarX << std::endl + << "Beta star y (m): " << betaStarY << std::endl + << "Energy (GeV): " << energy << std::endl; +} + +std::ostream& operator<<(std::ostream& os, LHCInfoCombined beamInfo) { + std::stringstream ss; + beamInfo.print(ss); + os << ss.str(); + return os; +} diff --git a/CondFormats/RunInfo/src/LHCInfoPerFill.cc b/CondFormats/RunInfo/src/LHCInfoPerFill.cc new file mode 100644 index 0000000000000..0e84747e8b5e1 --- /dev/null +++ b/CondFormats/RunInfo/src/LHCInfoPerFill.cc @@ -0,0 +1,460 @@ +#include "CondFormats/RunInfo/interface/LHCInfoPerFill.h" +#include "CondFormats/Common/interface/TimeConversions.h" +#include +#include +#include +#include + +//helper function: returns the positions of the bits in the bitset that are set (i.e., have a value of 1). +static std::vector bitsetToVector(std::bitset const& bs) { + std::vector vec; + //reserve space only for the bits in the bitset that are set + vec.reserve(bs.count()); + for (size_t i = 0; i < bs.size(); ++i) { + if (bs.test(i)) + vec.push_back((unsigned short)i); + } + return vec; +} + +//helper function: returns the enum for fill types in string type +static std::string fillTypeToString(LHCInfoPerFill::FillTypeId const& fillType) { + std::string s_fillType("UNKNOWN"); + switch (fillType) { + case LHCInfoPerFill::UNKNOWN: + s_fillType = std::string("UNKNOWN"); + break; + case LHCInfoPerFill::PROTONS: + s_fillType = std::string("PROTONS"); + break; + case LHCInfoPerFill::IONS: + s_fillType = std::string("IONS"); + break; + case LHCInfoPerFill::COSMICS: + s_fillType = std::string("COSMICS"); + break; + case LHCInfoPerFill::GAP: + s_fillType = std::string("GAP"); + break; + default: + s_fillType = std::string("UNKNOWN"); + } + return s_fillType; +} + +//helper function: returns the enum for particle types in string type +static std::string particleTypeToString(LHCInfoPerFill::ParticleTypeId const& particleType) { + std::string s_particleType("NONE"); + switch (particleType) { + case LHCInfoPerFill::NONE: + s_particleType = std::string("NONE"); + break; + case LHCInfoPerFill::PROTON: + s_particleType = std::string("PROTON"); + break; + case LHCInfoPerFill::PB82: + s_particleType = std::string("PB82"); + break; + case LHCInfoPerFill::AR18: + s_particleType = std::string("AR18"); + break; + case LHCInfoPerFill::D: + s_particleType = std::string("D"); + break; + case LHCInfoPerFill::XE54: + s_particleType = std::string("XE54"); + break; + default: + s_particleType = std::string("NONE"); + } + return s_particleType; +} + +LHCInfoPerFill::LHCInfoPerFill() + : LHCInfoVectorizedFields (ISIZE, FSIZE, TSIZE, SSIZE) { + m_floatParams[LUMI_PER_B] = std::vector(); + m_floatParams[BEAM1_VC] = std::vector(); + m_floatParams[BEAM2_VC] = std::vector(); + m_floatParams[BEAM1_RF] = std::vector(); + m_floatParams[BEAM2_RF] = std::vector(); + m_stringParams[INJECTION_SCHEME].push_back(std::string("None")); +} + +LHCInfoPerFill* LHCInfoPerFill::cloneFill() const { + LHCInfoPerFill* ret = new LHCInfoPerFill(); + ret->m_isData = m_isData; + if (!m_intParams[0].empty()) { + for (size_t i = 0; i < ISIZE; i++) + ret->m_intParams[i] = m_intParams[i]; + for (size_t i = 0; i < DELIV_LUMI; i++) + ret->m_floatParams[i] = m_floatParams[i]; + ret->m_floatParams[LUMI_PER_B] = m_floatParams[LUMI_PER_B]; + for (size_t i = 0; i < TSIZE; i++) + ret->m_timeParams[i] = m_timeParams[i]; + for (size_t i = 0; i < LHC_STATE; i++) + ret->m_stringParams[i] = m_stringParams[i]; + ret->m_bunchConfiguration1 = m_bunchConfiguration1; + ret->m_bunchConfiguration2 = m_bunchConfiguration2; + } + return ret; +} + +//getters +unsigned short const LHCInfoPerFill::fillNumber() const { return LHCInfoPerFill::getOneParam(m_intParams, LHC_FILL); } + +unsigned short const LHCInfoPerFill::bunchesInBeam1() const { return LHCInfoPerFill::getOneParam(m_intParams, BUNCHES_1); } + +unsigned short const LHCInfoPerFill::bunchesInBeam2() const { return LHCInfoPerFill::getOneParam(m_intParams, BUNCHES_2); } + +unsigned short const LHCInfoPerFill::collidingBunches() const { + return LHCInfoPerFill::getOneParam(m_intParams, COLLIDING_BUNCHES); +} + +unsigned short const LHCInfoPerFill::targetBunches() const { return LHCInfoPerFill::getOneParam(m_intParams, TARGET_BUNCHES); } + +LHCInfoPerFill::FillTypeId const LHCInfoPerFill::fillType() const { + return static_cast(LHCInfoPerFill::getOneParam(m_intParams, FILL_TYPE)); +} + +LHCInfoPerFill::ParticleTypeId const LHCInfoPerFill::particleTypeForBeam1() const { + return static_cast(LHCInfoPerFill::getOneParam(m_intParams, PARTICLES_1)); +} + +LHCInfoPerFill::ParticleTypeId const LHCInfoPerFill::particleTypeForBeam2() const { + return static_cast(LHCInfoPerFill::getOneParam(m_intParams, PARTICLES_2)); +} + +float const LHCInfoPerFill::intensityForBeam1() const { return LHCInfoPerFill::getOneParam(m_floatParams, INTENSITY_1); } + +float const LHCInfoPerFill::intensityForBeam2() const { return LHCInfoPerFill::getOneParam(m_floatParams, INTENSITY_2); } + +float const LHCInfoPerFill::energy() const { return LHCInfoPerFill::getOneParam(m_floatParams, ENERGY); } + +float const LHCInfoPerFill::delivLumi() const { return LHCInfoPerFill::getOneParam(m_floatParams, DELIV_LUMI); } + +float const LHCInfoPerFill::recLumi() const { return LHCInfoPerFill::getOneParam(m_floatParams, REC_LUMI); } + +float const LHCInfoPerFill::instLumi() const { return LHCInfoPerFill::getOneParam(m_floatParams, INST_LUMI); } + +float const LHCInfoPerFill::instLumiError() const { return LHCInfoPerFill::getOneParam(m_floatParams, INST_LUMI_ERR); } + +cond::Time_t const LHCInfoPerFill::createTime() const { return LHCInfoPerFill::getOneParam(m_timeParams, CREATE_TIME); } + +cond::Time_t const LHCInfoPerFill::beginTime() const { return LHCInfoPerFill::getOneParam(m_timeParams, BEGIN_TIME); } + +cond::Time_t const LHCInfoPerFill::endTime() const { return LHCInfoPerFill::getOneParam(m_timeParams, END_TIME); } + +std::string const& LHCInfoPerFill::injectionScheme() const { + return LHCInfoPerFill::getOneParam(m_stringParams, INJECTION_SCHEME); +} + +std::vector const& LHCInfoPerFill::lumiPerBX() const { return LHCInfoPerFill::getParams(m_floatParams, LUMI_PER_B); } + +std::string const& LHCInfoPerFill::lhcState() const { return LHCInfoPerFill::getOneParam(m_stringParams, LHC_STATE); } + +std::string const& LHCInfoPerFill::lhcComment() const { return LHCInfoPerFill::getOneParam(m_stringParams, LHC_COMMENT); } + +std::string const& LHCInfoPerFill::ctppsStatus() const { return LHCInfoPerFill::getOneParam(m_stringParams, CTPPS_STATUS); } + +std::vector const& LHCInfoPerFill::beam1VC() const { return LHCInfoPerFill::getParams(m_floatParams, BEAM1_VC); } + +std::vector const& LHCInfoPerFill::beam2VC() const { return LHCInfoPerFill::getParams(m_floatParams, BEAM2_VC); } + +std::vector const& LHCInfoPerFill::beam1RF() const { return LHCInfoPerFill::getParams(m_floatParams, BEAM1_RF); } + +std::vector const& LHCInfoPerFill::beam2RF() const { return LHCInfoPerFill::getParams(m_floatParams, BEAM2_RF); } + +std::vector& LHCInfoPerFill::beam1VC() { return LHCInfoPerFill::accessParams(m_floatParams, BEAM1_VC); } + +std::vector& LHCInfoPerFill::beam2VC() { return LHCInfoPerFill::accessParams(m_floatParams, BEAM2_VC); } + +std::vector& LHCInfoPerFill::beam1RF() { return LHCInfoPerFill::accessParams(m_floatParams, BEAM1_RF); } + +std::vector& LHCInfoPerFill::beam2RF() { return LHCInfoPerFill::accessParams(m_floatParams, BEAM2_RF); } + +//returns a boolean, true if the injection scheme has a leading 25ns +//TODO: parse the circulating bunch configuration, instead of the string. +bool LHCInfoPerFill::is25nsBunchSpacing() const { + const std::string prefix("25ns"); + return std::equal(prefix.begin(), prefix.end(), injectionScheme().begin()); +} + +//returns a boolean, true if the bunch slot number is in the circulating bunch configuration +bool LHCInfoPerFill::isBunchInBeam1(size_t const& bunch) const { + if (bunch == 0) + throw std::out_of_range("0 not allowed"); //CMS starts counting bunch crossing from 1! + return m_bunchConfiguration1.test(bunch); +} + +bool LHCInfoPerFill::isBunchInBeam2(size_t const& bunch) const { + if (bunch == 0) + throw std::out_of_range("0 not allowed"); //CMS starts counting bunch crossing from 1! + return m_bunchConfiguration2.test(bunch); +} + +//member functions returning *by value* a vector with all filled bunch slots +std::vector LHCInfoPerFill::bunchConfigurationForBeam1() const { + return bitsetToVector(m_bunchConfiguration1); +} + +std::vector LHCInfoPerFill::bunchConfigurationForBeam2() const { + return bitsetToVector(m_bunchConfiguration2); +} + +void LHCInfoPerFill::setFillNumber(unsigned short lhcFill) { + LHCInfoPerFill::setOneParam(m_intParams, LHC_FILL, static_cast(lhcFill)); +} + +//setters +void LHCInfoPerFill::setBunchesInBeam1(unsigned short const& bunches) { + LHCInfoPerFill::setOneParam(m_intParams, BUNCHES_1, static_cast(bunches)); +} + +void LHCInfoPerFill::setBunchesInBeam2(unsigned short const& bunches) { + LHCInfoPerFill::setOneParam(m_intParams, BUNCHES_2, static_cast(bunches)); +} + +void LHCInfoPerFill::setCollidingBunches(unsigned short const& collidingBunches) { + LHCInfoPerFill::setOneParam(m_intParams, COLLIDING_BUNCHES, static_cast(collidingBunches)); +} + +void LHCInfoPerFill::setTargetBunches(unsigned short const& targetBunches) { + LHCInfoPerFill::setOneParam(m_intParams, TARGET_BUNCHES, static_cast(targetBunches)); +} + +void LHCInfoPerFill::setFillType(LHCInfoPerFill::FillTypeId const& fillType) { + LHCInfoPerFill::setOneParam(m_intParams, FILL_TYPE, static_cast(fillType)); +} + +void LHCInfoPerFill::setParticleTypeForBeam1(LHCInfoPerFill::ParticleTypeId const& particleType) { + LHCInfoPerFill::setOneParam(m_intParams, PARTICLES_1, static_cast(particleType)); +} + +void LHCInfoPerFill::setParticleTypeForBeam2(LHCInfoPerFill::ParticleTypeId const& particleType) { + LHCInfoPerFill::setOneParam(m_intParams, PARTICLES_2, static_cast(particleType)); +} + +void LHCInfoPerFill::setIntensityForBeam1(float const& intensity) { + LHCInfoPerFill::setOneParam(m_floatParams, INTENSITY_1, intensity); +} + +void LHCInfoPerFill::setIntensityForBeam2(float const& intensity) { + LHCInfoPerFill::setOneParam(m_floatParams, INTENSITY_2, intensity); +} + +void LHCInfoPerFill::setEnergy(float const& energy) { LHCInfoPerFill::setOneParam(m_floatParams, ENERGY, energy); } + +void LHCInfoPerFill::setDelivLumi(float const& delivLumi) { LHCInfoPerFill::setOneParam(m_floatParams, DELIV_LUMI, delivLumi); } + +void LHCInfoPerFill::setRecLumi(float const& recLumi) { LHCInfoPerFill::setOneParam(m_floatParams, REC_LUMI, recLumi); } + +void LHCInfoPerFill::setInstLumi(float const& instLumi) { LHCInfoPerFill::setOneParam(m_floatParams, INST_LUMI, instLumi); } + +void LHCInfoPerFill::setInstLumiError(float const& instLumiError) { + LHCInfoPerFill::setOneParam(m_floatParams, INST_LUMI_ERR, instLumiError); +} + +void LHCInfoPerFill::setCreationTime(cond::Time_t const& createTime) { + LHCInfoPerFill::setOneParam(m_timeParams, CREATE_TIME, createTime); +} + +void LHCInfoPerFill::setBeginTime(cond::Time_t const& beginTime) { + LHCInfoPerFill::setOneParam(m_timeParams, BEGIN_TIME, beginTime); +} + +void LHCInfoPerFill::setEndTime(cond::Time_t const& endTime) { LHCInfoPerFill::setOneParam(m_timeParams, END_TIME, endTime); } + +void LHCInfoPerFill::setInjectionScheme(std::string const& injectionScheme) { + LHCInfoPerFill::setOneParam(m_stringParams, INJECTION_SCHEME, injectionScheme); +} + +void LHCInfoPerFill::setLumiPerBX(std::vector const& lumiPerBX) { + LHCInfoPerFill::setParams(m_floatParams, LUMI_PER_B, lumiPerBX); +} + +void LHCInfoPerFill::setLhcState(std::string const& lhcState) { + LHCInfoPerFill::setOneParam(m_stringParams, LHC_STATE, lhcState); +} + +void LHCInfoPerFill::setLhcComment(std::string const& lhcComment) { + LHCInfoPerFill::setOneParam(m_stringParams, LHC_COMMENT, lhcComment); +} + +void LHCInfoPerFill::setCtppsStatus(std::string const& ctppsStatus) { + LHCInfoPerFill::setOneParam(m_stringParams, CTPPS_STATUS, ctppsStatus); +} + +void LHCInfoPerFill::setBeam1VC(std::vector const& beam1VC) { + LHCInfoPerFill::setParams(m_floatParams, BEAM1_VC, beam1VC); +} + +void LHCInfoPerFill::setBeam2VC(std::vector const& beam2VC) { + LHCInfoPerFill::setParams(m_floatParams, BEAM2_VC, beam2VC); +} + +void LHCInfoPerFill::setBeam1RF(std::vector const& beam1RF) { + LHCInfoPerFill::setParams(m_floatParams, BEAM1_RF, beam1RF); +} + +void LHCInfoPerFill::setBeam2RF(std::vector const& beam2RF) { + LHCInfoPerFill::setParams(m_floatParams, BEAM2_RF, beam2RF); +} + +//sets all values in one go +void LHCInfoPerFill::setInfo(unsigned short const& bunches1, + unsigned short const& bunches2, + unsigned short const& collidingBunches, + unsigned short const& targetBunches, + FillTypeId const& fillType, + ParticleTypeId const& particleType1, + ParticleTypeId const& particleType2, + float const& intensity1, + float const& intensity2, + float const& energy, + float const& delivLumi, + float const& recLumi, + float const& instLumi, + float const& instLumiError, + cond::Time_t const& createTime, + cond::Time_t const& beginTime, + cond::Time_t const& endTime, + std::string const& scheme, + std::vector const& lumiPerBX, + std::string const& lhcState, + std::string const& lhcComment, + std::string const& ctppsStatus, + std::vector const& beam1VC, + std::vector const& beam2VC, + std::vector const& beam1RF, + std::vector const& beam2RF, + std::bitset const& bunchConf1, + std::bitset const& bunchConf2) { + this->setBunchesInBeam1(bunches1); + this->setBunchesInBeam2(bunches2); + this->setCollidingBunches(collidingBunches); + this->setTargetBunches(targetBunches); + this->setFillType(fillType); + this->setParticleTypeForBeam1(particleType1); + this->setParticleTypeForBeam2(particleType2); + this->setIntensityForBeam1(intensity1); + this->setIntensityForBeam2(intensity2); + this->setEnergy(energy); + this->setDelivLumi(delivLumi); + this->setRecLumi(recLumi); + this->setInstLumi(instLumi); + this->setInstLumiError(instLumiError); + this->setCreationTime(createTime); + this->setBeginTime(beginTime); + this->setEndTime(endTime); + this->setInjectionScheme(scheme); + this->setLumiPerBX(lumiPerBX); + this->setLhcState(lhcState); + this->setLhcComment(lhcComment); + this->setCtppsStatus(ctppsStatus); + this->setBeam1VC(beam1VC); + this->setBeam2VC(beam2VC); + this->setBeam1RF(beam1RF); + this->setBeam2RF(beam2RF); + this->setBunchBitsetForBeam1(bunchConf1); + this->setBunchBitsetForBeam2(bunchConf2); +} + +void LHCInfoPerFill::print(std::stringstream& ss) const { + ss << "LHC fill: " << this->fillNumber() << std::endl + << "Bunches in Beam 1: " << this->bunchesInBeam1() << std::endl + << "Bunches in Beam 2: " << this->bunchesInBeam2() << std::endl + << "Colliding bunches at IP5: " << this->collidingBunches() << std::endl + << "Target bunches at IP5: " << this->targetBunches() << std::endl + << "Fill type: " << fillTypeToString(static_cast(this->fillType())) << std::endl + << "Particle type for Beam 1: " << particleTypeToString(static_cast(this->particleTypeForBeam1())) + << std::endl + << "Particle type for Beam 2: " << particleTypeToString(static_cast(this->particleTypeForBeam2())) + << std::endl + << "Average Intensity for Beam 1 (number of charges): " << this->intensityForBeam1() << std::endl + << "Average Intensity for Beam 2 (number of charges): " << this->intensityForBeam2() << std::endl + << "Energy (GeV): " << this->energy() << std::endl + << "Delivered Luminosity (max): " << this->delivLumi() << std::endl + << "Recorded Luminosity (max): " << this->recLumi() << std::endl + << "Instantaneous Luminosity: " << this->instLumi() << std::endl + << "Instantaneous Luminosity Error: " << this->instLumiError() << std::endl + << "Creation time of the fill: " + << boost::posix_time::to_iso_extended_string(cond::time::to_boost(this->createTime())) << std::endl + << "Begin time of Stable Beam flag: " + << boost::posix_time::to_iso_extended_string(cond::time::to_boost(this->beginTime())) << std::endl + << "End time of the fill: " << boost::posix_time::to_iso_extended_string(cond::time::to_boost(this->endTime())) + << std::endl + << "Injection scheme as given by LPC: " << this->injectionScheme() << std::endl + << "LHC State: " << this->lhcState() << std::endl + << "LHC Comments: " << this->lhcComment() << std::endl + << "CTPPS Status: " << this->ctppsStatus() << std::endl; + + ss << "Luminosity per bunch (total " << this->lumiPerBX().size() << "): "; + std::copy(this->lumiPerBX().begin(), this->lumiPerBX().end(), std::ostream_iterator(ss, ", ")); + ss << std::endl; + + ss << "Beam 1 VC (total " << this->beam1VC().size() << "): "; + std::copy(this->beam1VC().begin(), this->beam1VC().end(), std::ostream_iterator(ss, "\t")); + ss << std::endl; + + ss << "Beam 2 VC (total " << beam2VC().size() << "): "; + std::copy(beam2VC().begin(), beam2VC().end(), std::ostream_iterator(ss, "\t")); + ss << std::endl; + + ss << "Beam 1 RF (total " << beam1RF().size() << "): "; + std::copy(beam1RF().begin(), beam1RF().end(), std::ostream_iterator(ss, "\t")); + ss << std::endl; + + ss << "Beam 2 RF (total " << beam2RF().size() << "): "; + std::copy(beam2RF().begin(), beam2RF().end(), std::ostream_iterator(ss, "\t")); + ss << std::endl; + + std::vector bunchVector1 = this->bunchConfigurationForBeam1(); + std::vector bunchVector2 = this->bunchConfigurationForBeam2(); + ss << "Bunches filled for Beam 1 (total " << bunchVector1.size() << "): "; + std::copy(bunchVector1.begin(), bunchVector1.end(), std::ostream_iterator(ss, ", ")); + ss << std::endl; + ss << "Bunches filled for Beam 2 (total " << bunchVector2.size() << "): "; + std::copy(bunchVector2.begin(), bunchVector2.end(), std::ostream_iterator(ss, ", ")); + ss << std::endl; +} + +//protected getters +std::bitset const& LHCInfoPerFill::bunchBitsetForBeam1() const { return m_bunchConfiguration1; } + +std::bitset const& LHCInfoPerFill::bunchBitsetForBeam2() const { return m_bunchConfiguration2; } + +//protected setters +void LHCInfoPerFill::setBunchBitsetForBeam1(std::bitset const& bunchConfiguration) { + m_bunchConfiguration1 = bunchConfiguration; +} + +void LHCInfoPerFill::setBunchBitsetForBeam2(std::bitset const& bunchConfiguration) { + m_bunchConfiguration2 = bunchConfiguration; +} + +std::ostream& operator<<(std::ostream& os, LHCInfoPerFill beamInfo) { + std::stringstream ss; + beamInfo.print(ss); + os << ss.str(); + return os; +} + +bool LHCInfoPerFill::equals(const LHCInfoPerFill& rhs) const { + if (m_isData != rhs.m_isData) + return false; + if (m_intParams != rhs.m_intParams) + return false; + if (m_floatParams != rhs.m_floatParams) + return false; + if (m_timeParams != rhs.m_timeParams) + return false; + if (m_stringParams != rhs.m_stringParams) + return false; + if (m_bunchConfiguration1 != rhs.m_bunchConfiguration1) + return false; + if (m_bunchConfiguration2 != rhs.m_bunchConfiguration2) + return false; + return true; +} + +bool LHCInfoPerFill::empty() const { return m_intParams[0].empty(); } diff --git a/CondFormats/RunInfo/src/LHCInfoPerLS.cc b/CondFormats/RunInfo/src/LHCInfoPerLS.cc new file mode 100644 index 0000000000000..d916cfb517111 --- /dev/null +++ b/CondFormats/RunInfo/src/LHCInfoPerLS.cc @@ -0,0 +1,89 @@ +#include "CondFormats/RunInfo/interface/LHCInfoPerLS.h" +//#include "CondFormats/Common/interface/TimeConversions.h" +#include +#include +#include +#include + +LHCInfoPerLS::LHCInfoPerLS() + : LHCInfoVectorizedFields (ISIZE, FSIZE, TSIZE, SSIZE) {} + +//getters +unsigned short const LHCInfoPerLS::fillNumber() const { return LHCInfoPerLS::getOneParam(m_intParams, LHC_FILL); } + +unsigned int const& LHCInfoPerLS::lumiSection() const { return LHCInfoPerLS::getOneParam(m_intParams, LUMI_SECTION); } + +float const LHCInfoPerLS::crossingAngleX() const { return LHCInfoPerLS::getOneParam(m_floatParams, CROSSING_ANGLE_X); } + +float const LHCInfoPerLS::crossingAngleY() const { return LHCInfoPerLS::getOneParam(m_floatParams, CROSSING_ANGLE_Y); } + +float const LHCInfoPerLS::betaStarX() const { return LHCInfoPerLS::getOneParam(m_floatParams, BETA_STAR_X); } + +float const LHCInfoPerLS::betaStarY() const { return LHCInfoPerLS::getOneParam(m_floatParams, BETA_STAR_Y); } + +cond::Time_t LHCInfoPerLS::runNumber() const { return LHCInfoPerLS::getOneParam(m_timeParams, RUN_NUMBER); } + +//setters +void LHCInfoPerLS::setFillNumber(unsigned short const& lhcFill) { LHCInfoPerLS::setOneParam(m_intParams, LHC_FILL, static_cast(lhcFill)); } + +void LHCInfoPerLS::setLumiSection(unsigned int const& lumiSection) { + LHCInfoPerLS::setOneParam(m_intParams, LUMI_SECTION, lumiSection); +} + +void LHCInfoPerLS::setCrossingAngleX(float const& angle) { LHCInfoPerLS::setOneParam(m_floatParams, CROSSING_ANGLE_X, angle); } + +void LHCInfoPerLS::setCrossingAngleY(float const& angle) { LHCInfoPerLS::setOneParam(m_floatParams, CROSSING_ANGLE_Y, angle); } + +void LHCInfoPerLS::setBetaStarX(float const& betaStar) { LHCInfoPerLS::setOneParam(m_floatParams, BETA_STAR_X, betaStar); } + +void LHCInfoPerLS::setBetaStarY(float const& betaStar) { LHCInfoPerLS::setOneParam(m_floatParams, BETA_STAR_Y, betaStar); } + +void LHCInfoPerLS::setRunNumber(cond::Time_t const& runNumber) { LHCInfoPerLS::setOneParam(m_timeParams, RUN_NUMBER, runNumber); }; + +//sets all values in one go +void LHCInfoPerLS::setInfo(unsigned short const& lhcFill, + unsigned int const& lumiSection, + float const& angleX, + float const& angleY, + float const& betaX, + float const& betaY, + cond::Time_t const& runNumber) { + this->setFillNumber(lhcFill); + this->setLumiSection(lumiSection); + this->setCrossingAngleX(angleX); + this->setCrossingAngleY(angleY); + this->setBetaStarX(betaX); + this->setBetaStarY(betaY); + this->setRunNumber(runNumber); +} + +void LHCInfoPerLS::print(std::stringstream& ss) const { + ss << "LHC fill: " << this->fillNumber() << std::endl + << "Lumi section: " << this->lumiSection() << std::endl + << "Run number: " << this->runNumber() << std::endl + << "Crossing angle x (urad): " << this->crossingAngleX() << std::endl + << "Crossing angle y (urad): " << this->crossingAngleY() << std::endl + << "Beta star x (m): " << this->betaStarX() << std::endl + << "Beta star y (m): " << this->betaStarY() << std::endl; +} + +std::ostream& operator<<(std::ostream& os, LHCInfoPerLS beamInfo) { + std::stringstream ss; + beamInfo.print(ss); + os << ss.str(); + return os; +} + +bool LHCInfoPerLS::equals(const LHCInfoPerLS& rhs) const { + if (m_isData != rhs.m_isData) + return false; + if (m_intParams != rhs.m_intParams) + return false; + if (m_floatParams != rhs.m_floatParams) + return false; + if (m_timeParams != rhs.m_timeParams) + return false; + return true; +} + +bool LHCInfoPerLS::empty() const { return m_intParams[0].empty(); } diff --git a/CondFormats/RunInfo/src/LHCInfoVectorizedFields.cc b/CondFormats/RunInfo/src/LHCInfoVectorizedFields.cc new file mode 100644 index 0000000000000..bb7d14d6463bb --- /dev/null +++ b/CondFormats/RunInfo/src/LHCInfoVectorizedFields.cc @@ -0,0 +1,77 @@ +#include "CondFormats/RunInfo/interface/LHCInfoVectorizedFields.h" +#include "CondCore/CondDB/interface/Exception.h" + +LHCInfoVectorizedFields::LHCInfoVectorizedFields() + : LHCInfoVectorizedFields(ISIZE, FSIZE, TSIZE, SSIZE) {} + +LHCInfoVectorizedFields::LHCInfoVectorizedFields(size_t iSize, size_t fSize, size_t tSize, size_t sSize) { + m_intParams.resize(iSize, std::vector(1, 0)); + m_floatParams.resize(fSize, std::vector(1, 0.)); + m_timeParams.resize(tSize, std::vector(1, 0ULL)); + m_stringParams.resize(sSize, std::vector(1, "")); +} + +template +const T& LHCInfoVectorizedFields::getParams(const std::vector& params, size_t index) { +if (index >= params.size()) + throw cond::Exception("Parameter with index " + std::to_string(index) + " is out of range."); +return params[index]; +} + +template const std::vector& LHCInfoVectorizedFields::getParams(const std::vector>&, size_t); +template const std::vector& LHCInfoVectorizedFields::getParams(const std::vector>&, size_t); +template const std::vector& LHCInfoVectorizedFields::getParams(const std::vector>&, size_t); +template const std::vector& LHCInfoVectorizedFields::getParams(const std::vector>&, size_t); + +template +T& LHCInfoVectorizedFields::accessParams(std::vector& params, size_t index) { +if (index >= params.size()) + throw cond::Exception("Parameter with index " + std::to_string(index) + " is out of range."); +return params[index]; +} + +template std::vector& LHCInfoVectorizedFields::accessParams(std::vector>&, size_t); +template std::vector& LHCInfoVectorizedFields::accessParams(std::vector>&, size_t); +template std::vector& LHCInfoVectorizedFields::accessParams(std::vector>&, size_t); +template std::vector& LHCInfoVectorizedFields::accessParams(std::vector>&, size_t); + +template +const T& LHCInfoVectorizedFields::getOneParam(const std::vector >& params, size_t index) { +if (index >= params.size()) + throw cond::Exception("Parameter with index " + std::to_string(index) + " is out of range."); +const std::vector& inner = params[index]; +if (inner.empty()) + throw cond::Exception("Parameter with index " + std::to_string(index) + " type=" + typeid(T).name() + + " has no value stored."); +return inner[0]; +} + +template const unsigned int& LHCInfoVectorizedFields::getOneParam(const std::vector >&, size_t); +template const float& LHCInfoVectorizedFields::getOneParam(const std::vector >&, size_t); +template const unsigned long long& LHCInfoVectorizedFields::getOneParam(const std::vector >&, size_t); +template const std::string& LHCInfoVectorizedFields::getOneParam(const std::vector >&, size_t); + +template +void LHCInfoVectorizedFields::setOneParam(std::vector >& params, size_t index, const T& value) { +if (index >= params.size()) + throw cond::Exception("Parameter with index " + std::to_string(index) + " is out of range."); +params[index] = std::vector(1, value); +} + +template void LHCInfoVectorizedFields::setOneParam(std::vector >& params, size_t index, const unsigned int& value); +template void LHCInfoVectorizedFields::setOneParam(std::vector >& params, size_t index, const float& value); +template void LHCInfoVectorizedFields::setOneParam(std::vector >& params, size_t index, const unsigned long long& value); +template void LHCInfoVectorizedFields::setOneParam(std::vector >& params, size_t index, const std::string& value); + +template +void LHCInfoVectorizedFields::setParams(std::vector& params, size_t index, const T& value) { +if (index >= params.size()) + throw cond::Exception("Parameter with index " + std::to_string(index) + " is out of range."); +params[index] = value; +} + +template void LHCInfoVectorizedFields::setParams(std::vector>& params, size_t index, const std::vector& value); +template void LHCInfoVectorizedFields::setParams(std::vector>& params, size_t index, const std::vector& value); +template void LHCInfoVectorizedFields::setParams(std::vector>& params, size_t index, const std::vector& value); +template void LHCInfoVectorizedFields::setParams(std::vector>& params, size_t index, const std::vector& value); + diff --git a/CondFormats/RunInfo/src/T_EventSetup_LHCInfoPerFill.cc b/CondFormats/RunInfo/src/T_EventSetup_LHCInfoPerFill.cc new file mode 100644 index 0000000000000..1dcf64621db96 --- /dev/null +++ b/CondFormats/RunInfo/src/T_EventSetup_LHCInfoPerFill.cc @@ -0,0 +1,4 @@ +#include "CondFormats/RunInfo/interface/LHCInfoPerFill.h" +#include "FWCore/Utilities/interface/typelookup.h" + +TYPELOOKUP_DATA_REG(LHCInfoPerFill); diff --git a/CondFormats/RunInfo/src/T_EventSetup_LHCInfoPerLS.cc b/CondFormats/RunInfo/src/T_EventSetup_LHCInfoPerLS.cc new file mode 100644 index 0000000000000..e63f84c38bda5 --- /dev/null +++ b/CondFormats/RunInfo/src/T_EventSetup_LHCInfoPerLS.cc @@ -0,0 +1,4 @@ +#include "CondFormats/RunInfo/interface/LHCInfoPerLS.h" +#include "FWCore/Utilities/interface/typelookup.h" + +TYPELOOKUP_DATA_REG(LHCInfoPerLS); diff --git a/CondFormats/RunInfo/src/headers.h b/CondFormats/RunInfo/src/headers.h index ed905d61e435a..8c63538739804 100644 --- a/CondFormats/RunInfo/src/headers.h +++ b/CondFormats/RunInfo/src/headers.h @@ -5,3 +5,7 @@ #include "CondFormats/RunInfo/interface/MixingModuleConfig.h" #include "CondFormats/RunInfo/interface/FillInfo.h" #include "CondFormats/RunInfo/interface/LHCInfo.h" +#include "CondFormats/RunInfo/interface/LHCInfoPerLS.h" +#include "CondFormats/RunInfo/interface/LHCInfoPerFill.h" +#include "CondFormats/RunInfo/interface/LHCInfoVectorizedFields.h" +#include "CondFormats/RunInfo/interface/LHCInfoCombined.h" \ No newline at end of file diff --git a/CondFormats/RunInfo/test/README.md b/CondFormats/RunInfo/test/README.md new file mode 100644 index 0000000000000..9ee631507486e --- /dev/null +++ b/CondFormats/RunInfo/test/README.md @@ -0,0 +1,24 @@ +#jc_lhcInfo_split + +##Set CMSSW workspace and compile + +```bash +source /cvmfs/cms.cern.ch/cmsset_default.sh +scram project CMSSW CMSSW_12_5_0_pre3 +cd CMSSW_12_5_0_pre3/src/ +cmsenv +git cms-init +git cms-checkout-topic CTPPS:jc_lhcInfo_split +scram b -j 8 +``` + +##Running tests +assuming being in the CMSSW_12_5_0_pre3/src directory and having run cmsenv + +```bash +cd CondTools/RunInfo/test +cmsRun LHCInfoPerLSWriter_cfg.py +cmsRun LHCInfoPerFillWriter_cfg.py +cmsRun LHCInfoPerLSAnalyzer_cfg.py +cmsRun LHCInfoPerFillAnalyzer_cfg.py +``` \ No newline at end of file diff --git a/CondFormats/RunInfo/test/testSerializationRunInfo.cpp b/CondFormats/RunInfo/test/testSerializationRunInfo.cpp index f12858e8f7720..2d2b4763fd637 100644 --- a/CondFormats/RunInfo/test/testSerializationRunInfo.cpp +++ b/CondFormats/RunInfo/test/testSerializationRunInfo.cpp @@ -5,6 +5,9 @@ int main() { testSerialization(); testSerialization(); + testSerialization(); + testSerialization(); + testSerialization(); testSerialization(); testSerialization(); testSerialization(); diff --git a/CondTools/RunInfo/interface/LHCInfoPerFillPopConSourceHandler.h b/CondTools/RunInfo/interface/LHCInfoPerFillPopConSourceHandler.h new file mode 100644 index 0000000000000..40c1fe9db332a --- /dev/null +++ b/CondTools/RunInfo/interface/LHCInfoPerFillPopConSourceHandler.h @@ -0,0 +1,62 @@ +#ifndef LHCInfoPerFillPOPCONSOURCEHANDLER_H +#define LHCInfoPerFillPOPCONSOURCEHANDLER_H + +#include + +#include "CondCore/PopCon/interface/PopConSourceHandler.h" +#include "CondFormats/RunInfo/interface/LHCInfoPerFill.h" +#include "FWCore/ParameterSet/interface/ParameterSetfwd.h" +#include "CondTools/RunInfo/interface/OMSAccess.h" + +namespace cond { + class OMSService; +} + +class LHCInfoPerFillPopConSourceHandler : public popcon::PopConSourceHandler { +public: + LHCInfoPerFillPopConSourceHandler(const edm::ParameterSet& pset); + ~LHCInfoPerFillPopConSourceHandler() override; + void getNewObjects() override; + std::string id() const override; + + static constexpr unsigned int kLumisectionsQueryLimit = 4000; + +private: + void addEmptyPayload(cond::Time_t iov); + void addPayloadToBuffer(cond::OMSServiceResultRef& row); + + size_t getLumiData(const cond::OMSService& service, + unsigned short fillId, + const boost::posix_time::ptime& beginFillTime, + const boost::posix_time::ptime& endFillTime); + void getDipData(const cond::OMSService& service, + const boost::posix_time::ptime& beginFillTime, + const boost::posix_time::ptime& endFillTime); + bool getCTTPSData(cond::persistency::Session& session, + const boost::posix_time::ptime& beginFillTime, + const boost::posix_time::ptime& endFillTime); + bool getEcalData(cond::persistency::Session& session, + const boost::posix_time::ptime& lowerTime, + const boost::posix_time::ptime& upperTime, + bool update); + +private: + bool m_debug; + // starting date for sampling + boost::posix_time::ptime m_startTime; + boost::posix_time::ptime m_endTime; + // sampling interval in seconds + unsigned int m_samplingInterval; + bool m_endFill = true; + std::string m_name; + //for reading from relational database source + std::string m_connectionString, m_ecalConnectionString; + std::string m_dipSchema, m_authpath; + std::string m_omsBaseUrl; + std::unique_ptr m_fillPayload; + std::shared_ptr m_prevPayload; + std::vector > > m_tmpBuffer; + bool m_lastPayloadEmpty = false; +}; + +#endif diff --git a/CondTools/RunInfo/interface/LHCInfoPerLSPopConSourceHandler.h b/CondTools/RunInfo/interface/LHCInfoPerLSPopConSourceHandler.h new file mode 100644 index 0000000000000..f69e57f5311bf --- /dev/null +++ b/CondTools/RunInfo/interface/LHCInfoPerLSPopConSourceHandler.h @@ -0,0 +1,67 @@ +#ifndef LHCINFOPOPCONSOURCEHANDLER_H +#define LHCINFOPOPCONSOURCEHANDLER_H + +#include + +#include "CondCore/PopCon/interface/PopConSourceHandler.h" +#include "CondFormats/RunInfo/interface/LHCInfoPerLS.h" +#include "FWCore/ParameterSet/interface/ParameterSetfwd.h" +#include "CondCore/CondDB/interface/Types.h" +#include "CondTools/RunInfo/interface/OMSAccess.h" + + +namespace cond { + class OMSService; +} + +class LHCInfoPerLSPopConSourceHandler : public popcon::PopConSourceHandler { +public: + LHCInfoPerLSPopConSourceHandler(const edm::ParameterSet& pset); + ~LHCInfoPerLSPopConSourceHandler() override; + void getNewObjects() override; + std::string id() const override; + + static constexpr unsigned int kLumisectionsQueryLimit = 4000; + +private: + void addEmptyPayload(cond::Time_t iov); + + bool makeFillPayload(std::unique_ptr& targetPayload, + const cond::OMSServiceResult& queryResult); + + void addPayloadToBuffer(cond::OMSServiceResultRef& row); + size_t bufferAllLS(const cond::OMSServiceResult& queryResult); + size_t bufferFirstStableBeamLS(const cond::OMSServiceResult& queryResult); + + size_t getLumiData(const cond::OMSService& service, + unsigned short fillId, + const boost::posix_time::ptime& beginFillTime, + const boost::posix_time::ptime& endFillTime); + bool getCTTPSData(cond::persistency::Session& session, + const boost::posix_time::ptime& beginFillTime, + const boost::posix_time::ptime& endFillTime); + +private: + bool m_debug; + // starting date for sampling + boost::posix_time::ptime m_startTime; + boost::posix_time::ptime m_endTime; + // sampling interval in seconds + unsigned int m_samplingInterval; + bool m_endFill = true; + std::string m_name; + //for reading from relational database source + std::string m_connectionString, m_ecalConnectionString; + std::string m_dipSchema, m_authpath; + std::string m_omsBaseUrl; + std::unique_ptr m_fillPayload; + std::shared_ptr m_prevPayload; + cond::Time_t m_startFillTime; + cond::Time_t m_endFillTime; + cond::Time_t m_prevEndFillTime; + cond::Time_t m_prevStartFillTime; + std::vector > > m_tmpBuffer; + bool m_lastPayloadEmpty = false; +}; + +#endif diff --git a/CondTools/RunInfo/interface/LHCInfoPopConSourceHandler.h b/CondTools/RunInfo/interface/LHCInfoPopConSourceHandler.h index 9c49bce6f6774..7d7fa1dba7842 100644 --- a/CondTools/RunInfo/interface/LHCInfoPopConSourceHandler.h +++ b/CondTools/RunInfo/interface/LHCInfoPopConSourceHandler.h @@ -18,6 +18,8 @@ class LHCInfoPopConSourceHandler : public popcon::PopConSourceHandler { void getNewObjects() override; std::string id() const override; + static constexpr unsigned int kLumisectionsQueryLimit = 4000; + private: void addEmptyPayload(cond::Time_t iov); diff --git a/CondTools/RunInfo/interface/OMSAccess.h b/CondTools/RunInfo/interface/OMSAccess.h index 5bf98e89ae8da..3ed48c956709e 100644 --- a/CondTools/RunInfo/interface/OMSAccess.h +++ b/CondTools/RunInfo/interface/OMSAccess.h @@ -52,6 +52,12 @@ namespace cond { unsigned long int_val = from_string_impl(attributeValue, 0); return (unsigned short)int_val; } + inline unsigned long long s_to_ull(const std::string& val) { return std::stoull(val); } + template <> + inline unsigned long long from_string(const std::string& attributeValue) { + unsigned long long int_val = from_string_impl(attributeValue, 0); + return int_val; + } inline boost::posix_time::ptime s_to_time(const std::string& val) { boost::posix_time::time_input_facet* facet = new boost::posix_time::time_input_facet(OMS_TIME_FMT); @@ -147,6 +153,9 @@ namespace cond { OMSServiceResultIterator begin() const; OMSServiceResultIterator end() const; + OMSServiceResultRef front() const; + OMSServiceResultRef back() const; + // parse json returned from curl, filling the property tree size_t parseData(const std::string& data); @@ -168,7 +177,9 @@ namespace cond { static constexpr const char* const NEQ = "NEQ"; static constexpr const char* const EQ = "EQ"; static constexpr const char* const LT = "LT"; + static constexpr const char* const LE = "LE"; static constexpr const char* const GT = "GT"; + static constexpr const char* const GE = "GE"; static constexpr const char* const SNULL = "null"; public: @@ -185,6 +196,9 @@ namespace cond { std::stringstream filter; if (m_filter.empty()) { filter << "?"; + if(!m_limit.empty()){ + m_limit.front() = '&'; + } } else { filter << m_filter << "&"; } @@ -206,12 +220,23 @@ namespace cond { return filter(GT, varName, value); } template + inline OMSServiceQuery& filterGE(const std::string& varName, const T& value) { + return filter(GE, varName, value); + } + template inline OMSServiceQuery& filterLT(const std::string& varName, const T& value) { return filter(LT, varName, value); } + template + inline OMSServiceQuery& filterLE(const std::string& varName, const T& value) { + return filter(LE, varName, value); + } // not null filter inline OMSServiceQuery& filterNotNull(const std::string& varName) { return filterNEQ(varName, SNULL); } + // limit for the page size, when unspecified OMS's default limit is 100 + OMSServiceQuery& limit(int value); + // triggers the execution of the query ( calling curl functions ) bool execute(); @@ -230,6 +255,7 @@ namespace cond { private: std::string m_url; std::string m_filter; + std::string m_limit; std::string m_varList; std::unique_ptr m_result; unsigned long m_status = 0; diff --git a/CondTools/RunInfo/plugins/BuildFile.xml b/CondTools/RunInfo/plugins/BuildFile.xml index f1ed6cfc4fc16..f19a7958ab441 100644 --- a/CondTools/RunInfo/plugins/BuildFile.xml +++ b/CondTools/RunInfo/plugins/BuildFile.xml @@ -46,3 +46,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CondTools/RunInfo/plugins/LHCInfoPerFillAnalyzer.cc b/CondTools/RunInfo/plugins/LHCInfoPerFillAnalyzer.cc new file mode 100644 index 0000000000000..d69d070d1d335 --- /dev/null +++ b/CondTools/RunInfo/plugins/LHCInfoPerFillAnalyzer.cc @@ -0,0 +1,42 @@ +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/ESWatcher.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ServiceRegistry/interface/Service.h" + +#include "CondCore/DBOutputService/interface/PoolDBOutputService.h" + +#include "CondFormats/RunInfo/interface/LHCInfoPerFill.h" +#include "CondFormats/DataRecord/interface/LHCInfoPerFillRcd.h" + +#include +#include + +class LHCInfoPerFillAnalyzer : public edm::one::EDAnalyzer<> { +public: + explicit LHCInfoPerFillAnalyzer(const edm::ParameterSet&) + : tokenInfoPerFill_(esConsumes()) {} + +private: + void beginJob() override {} + void analyze(const edm::Event&, const edm::EventSetup&) override; + void endJob() override {} + + edm::ESWatcher infoPerFillWatcher_; + + edm::ESGetToken tokenInfoPerFill_; +}; + +void LHCInfoPerFillAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { + // get InfoPerFill + if (infoPerFillWatcher_.check(iSetup)) { + edm::LogInfo("LHCInfoPerFillAnalyzer") << "LHCInfoPerFill retrieved:\n" << iSetup.getData(tokenInfoPerFill_); + } +} + +DEFINE_FWK_MODULE(LHCInfoPerFillAnalyzer); \ No newline at end of file diff --git a/CondTools/RunInfo/plugins/LHCInfoPerFillPopConAnalyzer.cc b/CondTools/RunInfo/plugins/LHCInfoPerFillPopConAnalyzer.cc new file mode 100644 index 0000000000000..673ea289e788f --- /dev/null +++ b/CondTools/RunInfo/plugins/LHCInfoPerFillPopConAnalyzer.cc @@ -0,0 +1,7 @@ +#include "CondCore/PopCon/interface/PopConAnalyzer.h" +#include "CondTools/RunInfo/interface/LHCInfoPerFillPopConSourceHandler.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +typedef popcon::PopConAnalyzer LHCInfoPerFillPopConAnalyzer; +//define this as a plug-in +DEFINE_FWK_MODULE(LHCInfoPerFillPopConAnalyzer); diff --git a/CondTools/RunInfo/plugins/LHCInfoPerFillWriter.cc b/CondTools/RunInfo/plugins/LHCInfoPerFillWriter.cc new file mode 100644 index 0000000000000..915b6b685d4b9 --- /dev/null +++ b/CondTools/RunInfo/plugins/LHCInfoPerFillWriter.cc @@ -0,0 +1,63 @@ +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ServiceRegistry/interface/Service.h" + +#include "CondCore/DBOutputService/interface/PoolDBOutputService.h" + +#include "CondFormats/RunInfo/interface/LHCInfoPerFill.h" +#include "CondFormats/DataRecord/interface/LHCInfoPerFillRcd.h" + +#include +#include + +class LHCInfoPerFillWriter : public edm::one::EDAnalyzer<> { +public: + explicit LHCInfoPerFillWriter(const edm::ParameterSet&) {} + +private: + void beginJob() override {} + void analyze(const edm::Event&, const edm::EventSetup&) override; + void endJob() override {} +}; + +void LHCInfoPerFillWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { + LHCInfoPerFill lhcInfoPerFill; + lhcInfoPerFill.setFillNumber(3); + lhcInfoPerFill.setBunchesInBeam1(10); + lhcInfoPerFill.setBunchesInBeam2(8); + lhcInfoPerFill.setCollidingBunches(5); + lhcInfoPerFill.setTargetBunches(4); + lhcInfoPerFill.setFillType(lhcInfoPerFill.PROTONS); + lhcInfoPerFill.setParticleTypeForBeam1(lhcInfoPerFill.PROTON); + lhcInfoPerFill.setParticleTypeForBeam2(lhcInfoPerFill.PROTON); + lhcInfoPerFill.setIntensityForBeam1(1016.5); + lhcInfoPerFill.setIntensityForBeam2(1096.66); + lhcInfoPerFill.setEnergy(7000); + lhcInfoPerFill.setDelivLumi(2E-07); + lhcInfoPerFill.setRecLumi(2E-07); + lhcInfoPerFill.setInstLumi(0); + lhcInfoPerFill.setInstLumiError(0); + lhcInfoPerFill.setCreationTime(6561530930997627120); + lhcInfoPerFill.setBeginTime(6561530930997627120); + lhcInfoPerFill.setEndTime(6561530930997627120); + lhcInfoPerFill.setInjectionScheme("None"); + lhcInfoPerFill.setLumiPerBX({0.000114139, 0.000114139}); + lhcInfoPerFill.setLhcState("some lhcState"); + lhcInfoPerFill.setLhcComment("some lhcComment"); + lhcInfoPerFill.setCtppsStatus("some ctppsStatus"); + + // store the info into a DB object + edm::Service poolDbService; + if (poolDbService.isAvailable()) + poolDbService->writeOneIOV(lhcInfoPerFill, poolDbService->currentTime(), "LHCInfoPerFillRcd"); + else + throw cms::Exception("LHCInfoPerFillWriter") << "PoolDBService required."; +} + +DEFINE_FWK_MODULE(LHCInfoPerFillWriter); \ No newline at end of file diff --git a/CondTools/RunInfo/plugins/LHCInfoPerLSAnalyzer.cc b/CondTools/RunInfo/plugins/LHCInfoPerLSAnalyzer.cc new file mode 100644 index 0000000000000..4c8fe35bda554 --- /dev/null +++ b/CondTools/RunInfo/plugins/LHCInfoPerLSAnalyzer.cc @@ -0,0 +1,42 @@ +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/ESWatcher.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ServiceRegistry/interface/Service.h" + +#include "CondCore/DBOutputService/interface/PoolDBOutputService.h" + +#include "CondFormats/RunInfo/interface/LHCInfoPerLS.h" +#include "CondFormats/DataRecord/interface/LHCInfoPerLSRcd.h" + +#include +#include + +class LHCInfoPerLSAnalyzer : public edm::one::EDAnalyzer<> { +public: + explicit LHCInfoPerLSAnalyzer(const edm::ParameterSet&) + : tokenInfoPerLS_(esConsumes()) {} + +private: + void beginJob() override {} + void analyze(const edm::Event&, const edm::EventSetup&) override; + void endJob() override {} + + edm::ESWatcher infoPerLSWatcher_; + + edm::ESGetToken tokenInfoPerLS_; +}; + +void LHCInfoPerLSAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { + // get InfoPerLS + if (infoPerLSWatcher_.check(iSetup)) { + edm::LogInfo("LHCInfoPerLSAnalyzer") << "LHCInfoPerLS retrieved:\n" << iSetup.getData(tokenInfoPerLS_); + } +} + +DEFINE_FWK_MODULE(LHCInfoPerLSAnalyzer); \ No newline at end of file diff --git a/CondTools/RunInfo/plugins/LHCInfoPerLSPopConAnalyzer.cc b/CondTools/RunInfo/plugins/LHCInfoPerLSPopConAnalyzer.cc new file mode 100644 index 0000000000000..a33a817d25498 --- /dev/null +++ b/CondTools/RunInfo/plugins/LHCInfoPerLSPopConAnalyzer.cc @@ -0,0 +1,7 @@ +#include "CondCore/PopCon/interface/PopConAnalyzer.h" +#include "CondTools/RunInfo/interface/LHCInfoPerLSPopConSourceHandler.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +typedef popcon::PopConAnalyzer LHCInfoPerLSPopConAnalyzer; +//define this as a plug-in +DEFINE_FWK_MODULE(LHCInfoPerLSPopConAnalyzer); diff --git a/CondTools/RunInfo/plugins/LHCInfoPerLSWriter.cc b/CondTools/RunInfo/plugins/LHCInfoPerLSWriter.cc new file mode 100644 index 0000000000000..68f5aa0c519b4 --- /dev/null +++ b/CondTools/RunInfo/plugins/LHCInfoPerLSWriter.cc @@ -0,0 +1,47 @@ +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ServiceRegistry/interface/Service.h" + +#include "CondCore/DBOutputService/interface/PoolDBOutputService.h" + +#include "CondFormats/RunInfo/interface/LHCInfoPerLS.h" +#include "CondFormats/DataRecord/interface/LHCInfoPerLSRcd.h" + +#include +#include + +class LHCInfoPerLSWriter : public edm::one::EDAnalyzer<> { +public: + explicit LHCInfoPerLSWriter(const edm::ParameterSet&) {} + +private: + void beginJob() override {} + void analyze(const edm::Event&, const edm::EventSetup&) override; + void endJob() override {} +}; + +void LHCInfoPerLSWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { + LHCInfoPerLS lhcInfoPerLS; + lhcInfoPerLS.setFillNumber(7066); + lhcInfoPerLS.setLumiSection(1); + lhcInfoPerLS.setCrossingAngleX(170); + lhcInfoPerLS.setCrossingAngleY(170); + lhcInfoPerLS.setBetaStarX(11); + lhcInfoPerLS.setBetaStarY(11); + lhcInfoPerLS.setRunNumber(301765); + + // store the info into a DB object + edm::Service poolDbService; + if (poolDbService.isAvailable()) + poolDbService->writeOneIOV(lhcInfoPerLS, poolDbService->currentTime(), "LHCInfoPerLSRcd"); + else + throw cms::Exception("LHCInfoPerLSWriter") << "PoolDBService required."; +} + +DEFINE_FWK_MODULE(LHCInfoPerLSWriter); \ No newline at end of file diff --git a/CondTools/RunInfo/python/LHCInfoPerFillPopConAnalyzerEndFill.py b/CondTools/RunInfo/python/LHCInfoPerFillPopConAnalyzerEndFill.py new file mode 100644 index 0000000000000..e5291f5ddaa44 --- /dev/null +++ b/CondTools/RunInfo/python/LHCInfoPerFillPopConAnalyzerEndFill.py @@ -0,0 +1,88 @@ +import socket +import FWCore.ParameterSet.Config as cms +import FWCore.ParameterSet.VarParsing as VarParsing +process = cms.Process("LHCInfoPerFillPopulator") +from CondCore.CondDB.CondDB_cfi import * +#process.load("CondCore.DBCommon.CondDBCommon_cfi") +#process.CondDBCommon.connect = 'sqlite_file:lhcinfoperls_pop_test.db' +#process.CondDBCommon.DBParameters.authenticationPath = '.' +#process.CondDBCommon.DBParameters.messageLevel=cms.untracked.int32(1) + +sourceConnection = 'oracle://cms_omds_adg/CMS_RUNINFO_R' +if socket.getfqdn().find('.cms') != -1: + sourceConnection = 'oracle://cms_omds_lb/CMS_RUNINFO_R' + +options = VarParsing.VarParsing() +options.register( 'destinationConnection' + , 'sqlite_file:lhcinfo_pop_test.db' #default value + , VarParsing.VarParsing.multiplicity.singleton + , VarParsing.VarParsing.varType.string + , "Connection string to the DB where payloads will be possibly written." + ) +options.register( 'targetConnection' + , '' #default value + , VarParsing.VarParsing.multiplicity.singleton + , VarParsing.VarParsing.varType.string + , """Connection string to the target DB: + if not empty (default), this provides the latest IOV and payloads to compare; + it is the DB where payloads should be finally uploaded.""" + ) +options.register( 'tag' + , 'LHCInfoPerFill_PopCon_start_test' + , VarParsing.VarParsing.multiplicity.singleton + , VarParsing.VarParsing.varType.string + , "Tag written in destinationConnection and finally appended in targetConnection." + ) +options.register( 'messageLevel' + , 0 #default value + , VarParsing.VarParsing.multiplicity.singleton + , VarParsing.VarParsing.varType.int + , "Message level; default to 0" + ) +options.parseArguments() + +CondDBConnection = CondDB.clone( connect = cms.string( options.destinationConnection ) ) +CondDBConnection.DBParameters.messageLevel = cms.untracked.int32( options.messageLevel ) + +process.MessageLogger = cms.Service("MessageLogger", + cout = cms.untracked.PSet(threshold = cms.untracked.string('INFO')), + destinations = cms.untracked.vstring('cout') + ) + +process.source = cms.Source("EmptyIOVSource", + lastValue = cms.uint64(1), + timetype = cms.string('runnumber'), + firstValue = cms.uint64(1), + interval = cms.uint64(1) + ) + +process.PoolDBOutputService = cms.Service("PoolDBOutputService", + CondDBConnection, + timetype = cms.untracked.string('timestamp'), + toPut = cms.VPSet(cms.PSet(record = cms.string('LHCInfoPerFillRcd'), + tag = cms.string( options.tag ) + ) + ) + ) + +process.Test1 = cms.EDAnalyzer("LHCInfoPerFillPopConAnalyzer", + SinceAppendMode = cms.bool(True), + record = cms.string('LHCInfoPerFillRcd'), + name = cms.untracked.string('LHCInfo'), + Source = cms.PSet(fill = cms.untracked.uint32(6417), + startTime = cms.untracked.string('2022-08-18 10:10:18.000'), + endTime = cms.untracked.string('2022-08-19 00:00:00.000'), + samplingInterval = cms.untracked.uint32( 600 ), + endFill = cms.untracked.bool(True), + connectionString = cms.untracked.string("oracle://cms_orcon_adg/CMS_RUNTIME_LOGGER"), + ecalConnectionString = cms.untracked.string("oracle://cms_orcon_adg/CMS_DCS_ENV_PVSS_COND"), + DIPSchema = cms.untracked.string("CMS_BEAM_COND"), + omsBaseUrl = cms.untracked.string("http://vocms0184.cern.ch/agg/api/v1"), + #authenticationPath = cms.untracked.string("."), + debug=cms.untracked.bool(False) + ), + loggingOn = cms.untracked.bool(True), + IsDestDbCheckedInQueryLog = cms.untracked.bool(False) + ) + +process.p = cms.Path(process.Test1) diff --git a/CondTools/RunInfo/python/LHCInfoPerFillPopConAnalyzerStartFill.py b/CondTools/RunInfo/python/LHCInfoPerFillPopConAnalyzerStartFill.py new file mode 100644 index 0000000000000..b8d86b670aaa5 --- /dev/null +++ b/CondTools/RunInfo/python/LHCInfoPerFillPopConAnalyzerStartFill.py @@ -0,0 +1,88 @@ +import socket +import FWCore.ParameterSet.Config as cms +import FWCore.ParameterSet.VarParsing as VarParsing +process = cms.Process("LHCInfoPerFillPopulator") +from CondCore.CondDB.CondDB_cfi import * +#process.load("CondCore.DBCommon.CondDBCommon_cfi") +#process.CondDBCommon.connect = 'sqlite_file:lhcinfoperls_pop_test.db' +#process.CondDBCommon.DBParameters.authenticationPath = '.' +#process.CondDBCommon.DBParameters.messageLevel=cms.untracked.int32(1) + +sourceConnection = 'oracle://cms_omds_adg/CMS_RUNINFO_R' +if socket.getfqdn().find('.cms') != -1: + sourceConnection = 'oracle://cms_omds_lb/CMS_RUNINFO_R' + +options = VarParsing.VarParsing() +options.register( 'destinationConnection' + , 'sqlite_file:lhcinfo_pop_test.db' #default value + , VarParsing.VarParsing.multiplicity.singleton + , VarParsing.VarParsing.varType.string + , "Connection string to the DB where payloads will be possibly written." + ) +options.register( 'targetConnection' + , '' #default value + , VarParsing.VarParsing.multiplicity.singleton + , VarParsing.VarParsing.varType.string + , """Connection string to the target DB: + if not empty (default), this provides the latest IOV and payloads to compare; + it is the DB where payloads should be finally uploaded.""" + ) +options.register( 'tag' + , 'LHCInfoPerFill_PopCon_start_test' + , VarParsing.VarParsing.multiplicity.singleton + , VarParsing.VarParsing.varType.string + , "Tag written in destinationConnection and finally appended in targetConnection." + ) +options.register( 'messageLevel' + , 0 #default value + , VarParsing.VarParsing.multiplicity.singleton + , VarParsing.VarParsing.varType.int + , "Message level; default to 0" + ) +options.parseArguments() + +CondDBConnection = CondDB.clone( connect = cms.string( options.destinationConnection ) ) +CondDBConnection.DBParameters.messageLevel = cms.untracked.int32( options.messageLevel ) + +process.MessageLogger = cms.Service("MessageLogger", + cout = cms.untracked.PSet(threshold = cms.untracked.string('INFO')), + destinations = cms.untracked.vstring('cout') + ) + +process.source = cms.Source("EmptyIOVSource", + lastValue = cms.uint64(1), + timetype = cms.string('runnumber'), + firstValue = cms.uint64(1), + interval = cms.uint64(1) + ) + +process.PoolDBOutputService = cms.Service("PoolDBOutputService", + CondDBConnection, + timetype = cms.untracked.string('timestamp'), + toPut = cms.VPSet(cms.PSet(record = cms.string('LHCInfoPerFillRcd'), + tag = cms.string( options.tag ) + ) + ) + ) + +process.Test1 = cms.EDAnalyzer("LHCInfoPerFillPopConAnalyzer", + SinceAppendMode = cms.bool(True), + record = cms.string('LHCInfoPerFillRcd'), + name = cms.untracked.string('LHCInfo'), + Source = cms.PSet(fill = cms.untracked.uint32(6417), + startTime = cms.untracked.string('2022-08-18 10:10:18.000'), + endTime = cms.untracked.string('2022-08-19 00:00:00.000'), + samplingInterval = cms.untracked.uint32( 600 ), + endFill = cms.untracked.bool(False), + connectionString = cms.untracked.string("oracle://cms_orcon_adg/CMS_RUNTIME_LOGGER"), + ecalConnectionString = cms.untracked.string("oracle://cms_orcon_adg/CMS_DCS_ENV_PVSS_COND"), + DIPSchema = cms.untracked.string("CMS_BEAM_COND"), + omsBaseUrl = cms.untracked.string("http://vocms0184.cern.ch/agg/api/v1"), + #authenticationPath = cms.untracked.string("."), + debug=cms.untracked.bool(False) + ), + loggingOn = cms.untracked.bool(True), + IsDestDbCheckedInQueryLog = cms.untracked.bool(False) + ) + +process.p = cms.Path(process.Test1) diff --git a/CondTools/RunInfo/python/LHCInfoPerLSPopConAnalyzerEndFill.py b/CondTools/RunInfo/python/LHCInfoPerLSPopConAnalyzerEndFill.py new file mode 100644 index 0000000000000..d22ce80f9ae1b --- /dev/null +++ b/CondTools/RunInfo/python/LHCInfoPerLSPopConAnalyzerEndFill.py @@ -0,0 +1,88 @@ +import socket +import FWCore.ParameterSet.Config as cms +import FWCore.ParameterSet.VarParsing as VarParsing +process = cms.Process("LHCInfoPerLSPopulator") +from CondCore.CondDB.CondDB_cfi import * +#process.load("CondCore.DBCommon.CondDBCommon_cfi") +#process.CondDBCommon.connect = 'sqlite_file:lhcinfoperls_pop_test.db' +#process.CondDBCommon.DBParameters.authenticationPath = '.' +#process.CondDBCommon.DBParameters.messageLevel=cms.untracked.int32(1) + +sourceConnection = 'oracle://cms_omds_adg/CMS_RUNINFO_R' +if socket.getfqdn().find('.cms') != -1: + sourceConnection = 'oracle://cms_omds_lb/CMS_RUNINFO_R' + +options = VarParsing.VarParsing() +options.register( 'destinationConnection' + , 'sqlite_file:lhcinfo_pop_test.db' #default value + , VarParsing.VarParsing.multiplicity.singleton + , VarParsing.VarParsing.varType.string + , "Connection string to the DB where payloads will be possibly written." + ) +options.register( 'targetConnection' + , '' #default value + , VarParsing.VarParsing.multiplicity.singleton + , VarParsing.VarParsing.varType.string + , """Connection string to the target DB: + if not empty (default), this provides the latest IOV and payloads to compare; + it is the DB where payloads should be finally uploaded.""" + ) +options.register( 'tag' + , 'LHCInfoPerLS_PopCon_start_test' + , VarParsing.VarParsing.multiplicity.singleton + , VarParsing.VarParsing.varType.string + , "Tag written in destinationConnection and finally appended in targetConnection." + ) +options.register( 'messageLevel' + , 0 #default value + , VarParsing.VarParsing.multiplicity.singleton + , VarParsing.VarParsing.varType.int + , "Message level; default to 0" + ) +options.parseArguments() + +CondDBConnection = CondDB.clone( connect = cms.string( options.destinationConnection ) ) +CondDBConnection.DBParameters.messageLevel = cms.untracked.int32( options.messageLevel ) + +process.MessageLogger = cms.Service("MessageLogger", + cout = cms.untracked.PSet(threshold = cms.untracked.string('INFO')), + destinations = cms.untracked.vstring('cout') + ) + +process.source = cms.Source("EmptyIOVSource", + lastValue = cms.uint64(1), + timetype = cms.string('runnumber'), + firstValue = cms.uint64(1), + interval = cms.uint64(1) + ) + +process.PoolDBOutputService = cms.Service("PoolDBOutputService", + CondDBConnection, + timetype = cms.untracked.string('timestamp'), + toPut = cms.VPSet(cms.PSet(record = cms.string('LHCInfoPerLSRcd'), + tag = cms.string( options.tag ) + ) + ) + ) + +process.Test1 = cms.EDAnalyzer("LHCInfoPerLSPopConAnalyzer", + SinceAppendMode = cms.bool(True), + record = cms.string('LHCInfoPerLSRcd'), + name = cms.untracked.string('LHCInfo'), + Source = cms.PSet(fill = cms.untracked.uint32(6417), + startTime = cms.untracked.string('2022-08-18 10:10:18.000'), + endTime = cms.untracked.string('2022-08-19 10:10:18.000'), + samplingInterval = cms.untracked.uint32( 600 ), + endFill = cms.untracked.bool(True), + connectionString = cms.untracked.string("oracle://cms_orcon_adg/CMS_RUNTIME_LOGGER"), + ecalConnectionString = cms.untracked.string("oracle://cms_orcon_adg/CMS_DCS_ENV_PVSS_COND"), + DIPSchema = cms.untracked.string("CMS_BEAM_COND"), + omsBaseUrl = cms.untracked.string("http://vocms0184.cern.ch/agg/api/v1"), + #authenticationPath = cms.untracked.string("."), + debug=cms.untracked.bool(False) + ), + loggingOn = cms.untracked.bool(True), + IsDestDbCheckedInQueryLog = cms.untracked.bool(False) + ) + +process.p = cms.Path(process.Test1) diff --git a/CondTools/RunInfo/python/LHCInfoPerLSPopConAnalyzerStartFill.py b/CondTools/RunInfo/python/LHCInfoPerLSPopConAnalyzerStartFill.py new file mode 100644 index 0000000000000..41ccb23fcb933 --- /dev/null +++ b/CondTools/RunInfo/python/LHCInfoPerLSPopConAnalyzerStartFill.py @@ -0,0 +1,88 @@ +import socket +import FWCore.ParameterSet.Config as cms +import FWCore.ParameterSet.VarParsing as VarParsing +process = cms.Process("LHCInfoPerLSPopulator") +from CondCore.CondDB.CondDB_cfi import * +#process.load("CondCore.DBCommon.CondDBCommon_cfi") +#process.CondDBCommon.connect = 'sqlite_file:lhcinfoperls_pop_test.db' +#process.CondDBCommon.DBParameters.authenticationPath = '.' +#process.CondDBCommon.DBParameters.messageLevel=cms.untracked.int32(1) + +sourceConnection = 'oracle://cms_omds_adg/CMS_RUNINFO_R' +if socket.getfqdn().find('.cms') != -1: + sourceConnection = 'oracle://cms_omds_lb/CMS_RUNINFO_R' + +options = VarParsing.VarParsing() +options.register( 'destinationConnection' + , 'sqlite_file:lhcinfo_pop_test.db' #default value + , VarParsing.VarParsing.multiplicity.singleton + , VarParsing.VarParsing.varType.string + , "Connection string to the DB where payloads will be possibly written." + ) +options.register( 'targetConnection' + , '' #default value + , VarParsing.VarParsing.multiplicity.singleton + , VarParsing.VarParsing.varType.string + , """Connection string to the target DB: + if not empty (default), this provides the latest IOV and payloads to compare; + it is the DB where payloads should be finally uploaded.""" + ) +options.register( 'tag' + , 'LHCInfoPerLS_PopCon_start_test' + , VarParsing.VarParsing.multiplicity.singleton + , VarParsing.VarParsing.varType.string + , "Tag written in destinationConnection and finally appended in targetConnection." + ) +options.register( 'messageLevel' + , 0 #default value + , VarParsing.VarParsing.multiplicity.singleton + , VarParsing.VarParsing.varType.int + , "Message level; default to 0" + ) +options.parseArguments() + +CondDBConnection = CondDB.clone( connect = cms.string( options.destinationConnection ) ) +CondDBConnection.DBParameters.messageLevel = cms.untracked.int32( options.messageLevel ) + +process.MessageLogger = cms.Service("MessageLogger", + cout = cms.untracked.PSet(threshold = cms.untracked.string('INFO')), + destinations = cms.untracked.vstring('cout') + ) + +process.source = cms.Source("EmptyIOVSource", + lastValue = cms.uint64(1), + timetype = cms.string('runnumber'), + firstValue = cms.uint64(1), + interval = cms.uint64(1) + ) + +process.PoolDBOutputService = cms.Service("PoolDBOutputService", + CondDBConnection, + timetype = cms.untracked.string('timestamp'), + toPut = cms.VPSet(cms.PSet(record = cms.string('LHCInfoPerLSRcd'), + tag = cms.string( options.tag ) + ) + ) + ) + +process.Test1 = cms.EDAnalyzer("LHCInfoPerLSPopConAnalyzer", + SinceAppendMode = cms.bool(True), + record = cms.string('LHCInfoPerLSRcd'), + name = cms.untracked.string('LHCInfo'), + Source = cms.PSet(fill = cms.untracked.uint32(6417), + startTime = cms.untracked.string('2022-08-18 10:10:18.000'), + endTime = cms.untracked.string('2022-08-19 10:10:18.000'), + samplingInterval = cms.untracked.uint32( 600 ), + endFill = cms.untracked.bool(False), + connectionString = cms.untracked.string("oracle://cms_orcon_adg/CMS_RUNTIME_LOGGER"), + ecalConnectionString = cms.untracked.string("oracle://cms_orcon_adg/CMS_DCS_ENV_PVSS_COND"), + DIPSchema = cms.untracked.string("CMS_BEAM_COND"), + omsBaseUrl = cms.untracked.string("http://vocms0184.cern.ch/agg/api/v1"), + #authenticationPath = cms.untracked.string("."), + debug=cms.untracked.bool(False) + ), + loggingOn = cms.untracked.bool(True), + IsDestDbCheckedInQueryLog = cms.untracked.bool(False) + ) + +process.p = cms.Path(process.Test1) diff --git a/CondTools/RunInfo/python/LHCInfoPopConAnalyzerStartFill.py b/CondTools/RunInfo/python/LHCInfoPopConAnalyzerStartFill.py index 79166c5b8bace..33a5ef6f010f8 100644 --- a/CondTools/RunInfo/python/LHCInfoPopConAnalyzerStartFill.py +++ b/CondTools/RunInfo/python/LHCInfoPopConAnalyzerStartFill.py @@ -70,7 +70,7 @@ record = cms.string('LHCInfoRcd'), name = cms.untracked.string('LHCInfo'), Source = cms.PSet(fill = cms.untracked.uint32(6417), - startTime = cms.untracked.string('2018-04-01 00:00:00.000'), + startTime = cms.untracked.string('2022-08-18 10:00:00.000'), #endTime = cms.untracked.string('2018-03-25 05:00:00.000'), samplingInterval = cms.untracked.uint32( 600 ), endFill = cms.untracked.bool(False), diff --git a/CondTools/RunInfo/src/LHCInfoPerFillPopConSourceHandler.cc b/CondTools/RunInfo/src/LHCInfoPerFillPopConSourceHandler.cc new file mode 100644 index 0000000000000..c1601b43a7542 --- /dev/null +++ b/CondTools/RunInfo/src/LHCInfoPerFillPopConSourceHandler.cc @@ -0,0 +1,764 @@ +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "CondCore/CondDB/interface/ConnectionPool.h" +#include "CondFormats/Common/interface/TimeConversions.h" +#include "CondTools/RunInfo/interface/LHCInfoPerFillPopConSourceHandler.h" +#include "CondTools/RunInfo/interface/OMSAccess.h" +#include "RelationalAccess/ISessionProxy.h" +#include "RelationalAccess/ISchema.h" +#include "RelationalAccess/IQuery.h" +#include "RelationalAccess/ICursor.h" +#include "CoralBase/AttributeList.h" +#include "CoralBase/Attribute.h" +#include "CoralBase/AttributeSpecification.h" +#include "CoralBase/TimeStamp.h" +#include +#include +#include +#include +#include +#include + +namespace cond { + namespace LHCInfoPerFillPopConImpl { + + static const std::pair s_fillTypeMap[] = { + std::make_pair("PROTONS", LHCInfoPerFill::PROTONS), + std::make_pair("IONS", LHCInfoPerFill::IONS), + std::make_pair("COSMICS", LHCInfoPerFill::COSMICS), + std::make_pair("GAP", LHCInfoPerFill::GAP)}; + + static const std::pair s_particleTypeMap[] = { + std::make_pair("PROTON", LHCInfoPerFill::PROTON), + std::make_pair("PB82", LHCInfoPerFill::PB82), + std::make_pair("AR18", LHCInfoPerFill::AR18), + std::make_pair("D", LHCInfoPerFill::D), + std::make_pair("XE54", LHCInfoPerFill::XE54)}; + + LHCInfoPerFill::FillType fillTypeFromString(const std::string& s_fill_type) { + for (auto const& i : s_fillTypeMap) + if (s_fill_type == i.first) + return i.second; + return LHCInfoPerFill::UNKNOWN; + } + + LHCInfoPerFill::ParticleType particleTypeFromString(const std::string& s_particle_type) { + for (auto const& i : s_particleTypeMap) + if (s_particle_type == i.first) + return i.second; + return LHCInfoPerFill::NONE; + } + } + + namespace impl { + + template <> + LHCInfoPerFill::FillType from_string(const std::string& attributeValue) { + return from_string_impl(attributeValue, LHCInfoPerFill::UNKNOWN); + } + + template <> + LHCInfoPerFill::ParticleType from_string(const std::string& attributeValue) { + return from_string_impl(attributeValue, LHCInfoPerFill::NONE); + } + + } // namespace impl +} // namespace cond + +LHCInfoPerFillPopConSourceHandler::LHCInfoPerFillPopConSourceHandler(edm::ParameterSet const& pset) + : m_debug(pset.getUntrackedParameter("debug", false)), + m_startTime(), + m_endTime(), + m_samplingInterval((unsigned int)pset.getUntrackedParameter("samplingInterval", 300)), + m_endFill(pset.getUntrackedParameter("endFill", true)), + m_name(pset.getUntrackedParameter("name", "LHCInfoPerFillPopConSourceHandler")), + m_connectionString(pset.getUntrackedParameter("connectionString", "")), + m_ecalConnectionString(pset.getUntrackedParameter("ecalConnectionString", "")), + m_dipSchema(pset.getUntrackedParameter("DIPSchema", "")), + m_authpath(pset.getUntrackedParameter("authenticationPath", "")), + m_omsBaseUrl(pset.getUntrackedParameter("omsBaseUrl", "")), + m_fillPayload(), + m_prevPayload(), + m_tmpBuffer() { + if (pset.exists("startTime")) { + m_startTime = boost::posix_time::time_from_string(pset.getUntrackedParameter("startTime")); + } + boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); + m_endTime = now; + if (pset.exists("endTime")) { + m_endTime = boost::posix_time::time_from_string(pset.getUntrackedParameter("endTime")); + if (m_endTime > now) + m_endTime = now; + } +} +//L1: try with different m_dipSchema +//L2: try with different m_name +LHCInfoPerFillPopConSourceHandler::~LHCInfoPerFillPopConSourceHandler() {} + +namespace LHCInfoPerFillImpl { + + struct IOVComp { + bool operator()(const cond::Time_t& x, const std::pair>& y) { + return (x < y.first); + } + }; + + // function to search in the vector the target time + std::vector>>::const_iterator search( + const cond::Time_t& val, const std::vector>>& container) { + if (container.empty()) + return container.end(); + auto p = std::upper_bound(container.begin(), container.end(), val, IOVComp()); + return (p != container.begin()) ? p - 1 : container.end(); + } + + bool makeFillPayload(std::unique_ptr& targetPayload, const cond::OMSServiceResult& queryResult) { + bool ret = false; + if (!queryResult.empty()) { + auto row = *queryResult.begin(); + auto currentFill = row.get("fill_number"); + auto bunches1 = row.get("bunches_beam1"); + auto bunches2 = row.get("bunches_beam2"); + auto collidingBunches = row.get("bunches_colliding"); + auto targetBunches = row.get("bunches_target"); + auto fillType = row.get("fill_type_runtime"); + auto particleType1 = row.get("fill_type_party1"); + auto particleType2 = row.get("fill_type_party2"); + auto intensityBeam1 = row.get("intensity_beam1"); + auto intensityBeam2 = row.get("intensity_beam2"); + auto energy = row.get("energy"); + auto creationTime = row.get("start_time"); + auto stableBeamStartTime = row.get("start_stable_beam"); + auto beamDumpTime = row.get("end_time"); + auto injectionScheme = row.get("injection_scheme"); + targetPayload = std::make_unique(); + targetPayload->setFillNumber(currentFill); + targetPayload->setBunchesInBeam1(bunches1); + targetPayload->setBunchesInBeam2(bunches2); + targetPayload->setCollidingBunches(collidingBunches); + targetPayload->setTargetBunches(targetBunches); + targetPayload->setFillType(fillType); + targetPayload->setParticleTypeForBeam1(particleType1); + targetPayload->setParticleTypeForBeam2(particleType2); + targetPayload->setIntensityForBeam1(intensityBeam1); + targetPayload->setIntensityForBeam2(intensityBeam2); + targetPayload->setEnergy(energy); + targetPayload->setCreationTime(cond::time::from_boost(creationTime)); + targetPayload->setBeginTime(cond::time::from_boost(stableBeamStartTime)); + targetPayload->setEndTime(cond::time::from_boost(beamDumpTime)); + targetPayload->setInjectionScheme(injectionScheme); + ret = true; + } + return ret; + } + +} // namespace LHCInfoPerFillImpl + +void LHCInfoPerFillPopConSourceHandler::addPayloadToBuffer(cond::OMSServiceResultRef& row) +{ + auto lumiTime = row.get("start_time"); + auto delivLumi = row.get("delivered_lumi"); + auto recLumi = row.get("recorded_lumi"); + LHCInfoPerFill* thisLumiSectionInfo = m_fillPayload->cloneFill(); + m_tmpBuffer.emplace_back(std::make_pair(cond::time::from_boost(lumiTime), thisLumiSectionInfo)); + LHCInfoPerFill& payload = *thisLumiSectionInfo; + payload.setDelivLumi(delivLumi); + payload.setRecLumi(recLumi); +} + +size_t LHCInfoPerFillPopConSourceHandler::getLumiData(const cond::OMSService& oms, + unsigned short fillId, + const boost::posix_time::ptime& beginFillTime, + const boost::posix_time::ptime& endFillTime) { + auto query = oms.query("lumisections"); + query->addOutputVars({"start_time", "delivered_lumi", "recorded_lumi", "beams_stable"}); + query->filterEQ("fill_number", fillId); + query->filterGT("start_time", beginFillTime).filterLT("start_time", endFillTime); + query->filterEQ("beams_stable", "true"); + query->limit(kLumisectionsQueryLimit); + if (query->execute()) { + int nLumi = 0; + auto queryResult = query->result(); + edm::LogInfo(m_name) << "Found " << queryResult.size() << " lumisections with STABLE BEAM during the fill " << fillId; + + if(m_endFill) { + auto firstRow = queryResult.front(); + addPayloadToBuffer(firstRow); + nLumi++; + } + + auto lastRow = queryResult.back(); + addPayloadToBuffer(lastRow); + nLumi++; + } + return 0; +} + +namespace LHCInfoPerFillImpl { + struct LumiSectionFilter { + LumiSectionFilter(const std::vector>>& samples) + : currLow(samples.begin()), currUp(samples.begin()), end(samples.end()) { + currUp++; + } + + void reset(const std::vector>>& samples) { + currLow = samples.begin(); + currUp = samples.begin(); + currUp++; + end = samples.end(); + currentDipTime = 0; + } + + bool process(cond::Time_t dipTime) { + if (currLow == end) + return false; + bool search = false; + if (currentDipTime == 0) { + search = true; + } else { + if (dipTime == currentDipTime) + return true; + else { + cond::Time_t upper = cond::time::MAX_VAL; + if (currUp != end) + upper = currUp->first; + if (dipTime < upper && currentDipTime >= currLow->first) + return false; + else { + search = true; + } + } + } + if (search) { + while (currUp != end and currUp->first < dipTime) { + currLow++; + currUp++; + } + currentDipTime = dipTime; + return currLow != end; + } + return false; + } + + cond::Time_t currentSince() { return currLow->first; } + LHCInfoPerFill& currentPayload() { return *currLow->second; } + + std::vector>>::const_iterator current() { return currLow; } + std::vector>>::const_iterator currLow; + std::vector>>::const_iterator currUp; + std::vector>>::const_iterator end; + cond::Time_t currentDipTime = 0; + }; +} // namespace LHCInfoPerFillImpl + +void LHCInfoPerFillPopConSourceHandler::getDipData(const cond::OMSService& oms, + const boost::posix_time::ptime& beginFillTime, + const boost::posix_time::ptime& endFillTime) { + // unsure how to handle this. + // the old implementation is not helping: apparently it is checking only the bunchconfiguration for the first diptime set of values... + auto query1 = oms.query("diplogger/dip/acc/LHC/RunControl/CirculatingBunchConfig/Beam1"); + query1->filterGT("dip_time", beginFillTime).filterLT("dip_time", endFillTime); + //This query is limited to 100 rows, but currently only one is used + //If all this data is needed and saved properly the limit has to be set: query1->limit(...) + if (query1->execute()) { + auto res = query1->result(); + if (!res.empty()) { + std::bitset bunchConfiguration1(0ULL); + auto row = *res.begin(); + auto vbunchConf1 = row.getArray("value"); + for (auto vb : vbunchConf1) { + if (vb != 0) { + unsigned short slot = (vb - 1) / 10 + 1; + bunchConfiguration1[slot] = true; + } + } + m_fillPayload->setBunchBitsetForBeam1(bunchConfiguration1); + } + } + auto query2 = oms.query("diplogger/dip/acc/LHC/RunControl/CirculatingBunchConfig/Beam2"); + query2->filterGT("dip_time", beginFillTime).filterLT("dip_time", endFillTime); + //This query is limited to 100 rows, but currently only one is used + if (query2->execute()) { + auto res = query2->result(); + if (!res.empty()) { + std::bitset bunchConfiguration2(0ULL); + auto row = *res.begin(); + auto vbunchConf2 = row.getArray("value"); + for (auto vb : vbunchConf2) { + if (vb != 0) { + unsigned short slot = (vb - 1) / 10 + 1; + bunchConfiguration2[slot] = true; + } + } + m_fillPayload->setBunchBitsetForBeam2(bunchConfiguration2); + } + } + + auto query3 = oms.query("diplogger/dip/CMS/LHC/LumiPerBunch"); + query3->filterGT("dip_time", beginFillTime).filterLT("dip_time", endFillTime); + //This query is limited to 100 rows, but currently only one is used + if (query3->execute()) { + auto res = query3->result(); + if (!res.empty()) { + std::vector lumiPerBX; + auto row = *res.begin(); + auto lumiBunchInst = row.getArray("lumi_bunch_inst"); + for (auto lb : lumiBunchInst) { + if (lb != 0.) { + lumiPerBX.push_back(lb); + } + } + m_fillPayload->setLumiPerBX(lumiPerBX); + } + } +} + +bool LHCInfoPerFillPopConSourceHandler::getCTTPSData(cond::persistency::Session& session, + const boost::posix_time::ptime& beginFillTime, + const boost::posix_time::ptime& endFillTime) { + //run the fifth query against the CTPPS schema + //Initializing the CMS_CTP_CTPPS_COND schema. + coral::ISchema& CTPPS = session.coralSession().schema("CMS_PPS_SPECT_COND"); + //execute query for CTPPS Data + std::unique_ptr CTPPSDataQuery(CTPPS.newQuery()); + //FROM clause + CTPPSDataQuery->addToTableList(std::string("PPS_LHC_MACHINE_PARAMS")); + //SELECT clause + CTPPSDataQuery->addToOutputList(std::string("DIP_UPDATE_TIME")); + CTPPSDataQuery->addToOutputList(std::string("LHC_STATE")); + CTPPSDataQuery->addToOutputList(std::string("LHC_COMMENT")); + if (m_debug) { + CTPPSDataQuery->addToOutputList(std::string("RUN_NUMBER")); + CTPPSDataQuery->addToOutputList(std::string("LUMI_SECTION")); + } + //WHERE CLAUSE + coral::AttributeList CTPPSDataBindVariables; + CTPPSDataBindVariables.extend(std::string("beginFillTime")); + CTPPSDataBindVariables.extend(std::string("endFillTime")); + CTPPSDataBindVariables[std::string("beginFillTime")].data() = coral::TimeStamp(beginFillTime); + CTPPSDataBindVariables[std::string("endFillTime")].data() = coral::TimeStamp(endFillTime); + std::string conditionStr = std::string("DIP_UPDATE_TIME>= :beginFillTime and DIP_UPDATE_TIME< :endFillTime"); + CTPPSDataQuery->setCondition(conditionStr, CTPPSDataBindVariables); + //ORDER BY clause + CTPPSDataQuery->addToOrderList(std::string("DIP_UPDATE_TIME")); + //define query output + coral::AttributeList CTPPSDataOutput; + CTPPSDataOutput.extend(std::string("DIP_UPDATE_TIME")); + CTPPSDataOutput.extend(std::string("LHC_STATE")); + CTPPSDataOutput.extend(std::string("LHC_COMMENT")); + if (m_debug) { + CTPPSDataOutput.extend(std::string("RUN_NUMBER")); + CTPPSDataOutput.extend(std::string("LUMI_SECTION")); + } + CTPPSDataQuery->defineOutput(CTPPSDataOutput); + //execute the query + coral::ICursor& CTPPSDataCursor = CTPPSDataQuery->execute(); + cond::Time_t dipTime = 0; + std::string lhcState = "", lhcComment = "", ctppsStatus = ""; + + //debug informations + unsigned int lumiSection = 0; + cond::Time_t runNumber = 0; + cond::Time_t savedDipTime = 0; + unsigned int savedLumiSection = 0; + cond::Time_t savedRunNumber = 0; + + bool ret = false; + LHCInfoPerFillImpl::LumiSectionFilter filter(m_tmpBuffer); + while (CTPPSDataCursor.next()) { + if (m_debug) { + std::ostringstream CTPPS; + CTPPSDataCursor.currentRow().toOutputStream(CTPPS); + } + coral::Attribute const& dipTimeAttribute = CTPPSDataCursor.currentRow()[std::string("DIP_UPDATE_TIME")]; + if (!dipTimeAttribute.isNull()) { + dipTime = cond::time::from_boost(dipTimeAttribute.data().time()); + if (filter.process(dipTime)) { + ret = true; + coral::Attribute const& lhcStateAttribute = CTPPSDataCursor.currentRow()[std::string("LHC_STATE")]; + if (!lhcStateAttribute.isNull()) { + lhcState = lhcStateAttribute.data(); + } + coral::Attribute const& lhcCommentAttribute = CTPPSDataCursor.currentRow()[std::string("LHC_COMMENT")]; + if (!lhcCommentAttribute.isNull()) { + lhcComment = lhcCommentAttribute.data(); + } + + if (m_debug) { + coral::Attribute const& runNumberAttribute = CTPPSDataCursor.currentRow()[std::string("RUN_NUMBER")]; + if (!runNumberAttribute.isNull()) { + runNumber = runNumberAttribute.data(); + } + coral::Attribute const& lumiSectionAttribute = CTPPSDataCursor.currentRow()[std::string("LUMI_SECTION")]; + if (!lumiSectionAttribute.isNull()) { + lumiSection = lumiSectionAttribute.data(); + } + } + + for (auto it = filter.current(); it != m_tmpBuffer.end(); it++) { + // set the current values to all of the payloads of the lumi section samples after the current since + LHCInfoPerFill& payload = *(it->second); + payload.setLhcState(lhcState); + payload.setLhcComment(lhcComment); + payload.setCtppsStatus(ctppsStatus); + + if (m_debug) { + savedDipTime = dipTime; + savedLumiSection = lumiSection; + savedRunNumber = runNumber; + } + } + } + } + } + if (m_debug) { + edm::LogInfo(m_name) << "Last assigned: " << "DipTime: " << savedDipTime << " " + << "LumiSection: " << savedLumiSection << " " + << "RunNumber: " << savedRunNumber; + } + return ret; +} + +namespace LHCInfoPerFillImpl { + static const std::map vecMap = { + {"Beam1/beamPhaseMean", 1}, {"Beam2/beamPhaseMean", 2}, {"Beam1/cavPhaseMean", 3}, {"Beam2/cavPhaseMean", 4}}; + void setElementData(cond::Time_t since, + const std::string& dipVal, + unsigned int elementNr, + float value, + LHCInfoPerFill& payload, + std::set& initList) { + if (initList.find(since) == initList.end()) { + payload.beam1VC().resize(LHCInfoPerFill::bunchSlots, 0.); + payload.beam2VC().resize(LHCInfoPerFill::bunchSlots, 0.); + payload.beam1RF().resize(LHCInfoPerFill::bunchSlots, 0.); + payload.beam2RF().resize(LHCInfoPerFill::bunchSlots, 0.); + initList.insert(since); + } + // set the current values to all of the payloads of the lumi section samples after the current since + if (elementNr < LHCInfoPerFill::bunchSlots) { + switch (vecMap.at(dipVal)) { + case 1: + payload.beam1VC()[elementNr] = value; + break; + case 2: + payload.beam2VC()[elementNr] = value; + break; + case 3: + payload.beam1RF()[elementNr] = value; + break; + case 4: + payload.beam2RF()[elementNr] = value; + break; + default: + break; + } + } + } +} // namespace LHCInfoPerFillImpl + +bool LHCInfoPerFillPopConSourceHandler::getEcalData(cond::persistency::Session& session, + const boost::posix_time::ptime& lowerTime, + const boost::posix_time::ptime& upperTime, + bool update) { + //run the sixth query against the CMS_DCS_ENV_PVSS_COND schema + //Initializing the CMS_DCS_ENV_PVSS_COND schema. + coral::ISchema& ECAL = session.nominalSchema(); + //start the transaction against the fill logging schema + //execute query for ECAL Data + std::unique_ptr ECALDataQuery(ECAL.newQuery()); + //FROM clause + ECALDataQuery->addToTableList(std::string("BEAM_PHASE")); + //SELECT clause + ECALDataQuery->addToOutputList(std::string("CHANGE_DATE")); + ECALDataQuery->addToOutputList(std::string("DIP_value")); + ECALDataQuery->addToOutputList(std::string("element_nr")); + ECALDataQuery->addToOutputList(std::string("VALUE_NUMBER")); + //WHERE CLAUSE + coral::AttributeList ECALDataBindVariables; + ECALDataBindVariables.extend(std::string("lowerTime")); + ECALDataBindVariables.extend(std::string("upperTime")); + ECALDataBindVariables[std::string("lowerTime")].data() = coral::TimeStamp(lowerTime); + ECALDataBindVariables[std::string("upperTime")].data() = coral::TimeStamp(upperTime); + std::string conditionStr = std::string( + "(DIP_value LIKE '%beamPhaseMean%' OR DIP_value LIKE '%cavPhaseMean%') AND CHANGE_DATE >= :lowerTime AND " + "CHANGE_DATE < :upperTime"); + + ECALDataQuery->setCondition(conditionStr, ECALDataBindVariables); + //ORDER BY clause + ECALDataQuery->addToOrderList(std::string("CHANGE_DATE")); + ECALDataQuery->addToOrderList(std::string("DIP_value")); + ECALDataQuery->addToOrderList(std::string("element_nr")); + //define query output + coral::AttributeList ECALDataOutput; + ECALDataOutput.extend(std::string("CHANGE_DATE")); + ECALDataOutput.extend(std::string("DIP_value")); + ECALDataOutput.extend(std::string("element_nr")); + ECALDataOutput.extend(std::string("VALUE_NUMBER")); + //ECALDataQuery->limitReturnedRows( 14256 ); //3564 entries per vector. + ECALDataQuery->defineOutput(ECALDataOutput); + //execute the query + coral::ICursor& ECALDataCursor = ECALDataQuery->execute(); + cond::Time_t changeTime = 0; + cond::Time_t firstTime = 0; + std::string dipVal = ""; + unsigned int elementNr = 0; + float value = 0.; + std::set initializedVectors; + LHCInfoPerFillImpl::LumiSectionFilter filter(m_tmpBuffer); + bool ret = false; + if (m_prevPayload.get()) { + for (auto& lumiSlot : m_tmpBuffer) { + lumiSlot.second->setBeam1VC(m_prevPayload->beam1VC()); + lumiSlot.second->setBeam2VC(m_prevPayload->beam2VC()); + lumiSlot.second->setBeam1RF(m_prevPayload->beam1RF()); + lumiSlot.second->setBeam2RF(m_prevPayload->beam2RF()); + } + } + std::map iovMap; + cond::Time_t lowerLumi = m_tmpBuffer.front().first; + while (ECALDataCursor.next()) { + if (m_debug) { + std::ostringstream ECAL; + ECALDataCursor.currentRow().toOutputStream(ECAL); + } + coral::Attribute const& changeDateAttribute = ECALDataCursor.currentRow()[std::string("CHANGE_DATE")]; + if (!changeDateAttribute.isNull()) { + ret = true; + boost::posix_time::ptime chTime = changeDateAttribute.data().time(); + // move the first IOV found to the start of the fill interval selected + if (changeTime == 0) { + firstTime = cond::time::from_boost(chTime); + } + changeTime = cond::time::from_boost(chTime); + cond::Time_t iovTime = changeTime; + if (!update and changeTime == firstTime) + iovTime = lowerLumi; + coral::Attribute const& dipValAttribute = ECALDataCursor.currentRow()[std::string("DIP_value")]; + coral::Attribute const& valueNumberAttribute = ECALDataCursor.currentRow()[std::string("VALUE_NUMBER")]; + coral::Attribute const& elementNrAttribute = ECALDataCursor.currentRow()[std::string("element_nr")]; + if (!dipValAttribute.isNull() and !valueNumberAttribute.isNull()) { + dipVal = dipValAttribute.data(); + elementNr = elementNrAttribute.data(); + value = valueNumberAttribute.data(); + if (std::isnan(value)) + value = 0.; + if (filter.process(iovTime)) { + iovMap.insert(std::make_pair(changeTime, filter.current()->first)); + for (auto it = filter.current(); it != m_tmpBuffer.end(); it++) { + LHCInfoPerFill& payload = *(it->second); + LHCInfoPerFillImpl::setElementData(it->first, dipVal, elementNr, value, payload, initializedVectors); + } + } + //} + } + } + } + if (m_debug) { + for (auto& im : iovMap) { + edm::LogInfo(m_name) << "Found iov=" << im.first << " (" << cond::time::to_boost(im.first) << " ) moved to " + << im.second << " ( " << cond::time::to_boost(im.second) << " )"; + } + } + return ret; +} + +void LHCInfoPerFillPopConSourceHandler::addEmptyPayload(cond::Time_t iov) { + bool add = false; + if (m_iovs.empty()) { + if (!m_lastPayloadEmpty) + add = true; + } else { + auto lastAdded = m_iovs.rbegin()->second; + if (lastAdded->fillNumber() != 0) { + add = true; + } + } + if (add) { + auto newPayload = std::make_shared(); + m_iovs.insert(std::make_pair(iov, newPayload)); + m_prevPayload = newPayload; + } +} + +namespace LHCInfoPerFillImpl { + bool comparePayloads(const LHCInfoPerFill& rhs, const LHCInfoPerFill& lhs) { + if (rhs.fillNumber() != lhs.fillNumber() || + rhs.delivLumi() != lhs.delivLumi() || + rhs.recLumi() != lhs.recLumi() || + rhs.instLumi() != lhs.instLumi() || + rhs.instLumiError() != lhs.instLumiError() || + rhs.lhcState() != rhs.lhcState() || + rhs.lhcComment() != rhs.lhcComment() || + rhs.ctppsStatus() != rhs.ctppsStatus()) { + return false; + } + return true; + } + + size_t transferPayloads(const std::vector>>& buffer, + std::map>& iovsToTransfer, + std::shared_ptr& prevPayload) { + size_t niovs = 0; + std::stringstream condIovs; + std::stringstream formattedIovs; + for (auto& iov : buffer) { + bool add = false; + auto payload = iov.second; + cond::Time_t since = iov.first; + if (iovsToTransfer.empty()) { + add = true; + } else { + LHCInfoPerFill& lastAdded = *iovsToTransfer.rbegin()->second; + if (!comparePayloads(lastAdded, *payload)) { + add = true; + } + } + if (add) { + niovs++; + condIovs << since << " "; + formattedIovs << boost::posix_time::to_iso_extended_string(cond::time::to_boost(since)) << " "; + iovsToTransfer.insert(std::make_pair(since, payload)); + prevPayload = iov.second; + } + } + edm::LogInfo("transferPayloads") << "TRANSFERED IOVS: " << condIovs.str(); + edm::LogInfo("transferPayloads") << "FORMATTED TRANSFERED IOVS: " << formattedIovs.str(); + return niovs; + } + +} // namespace LHCInfoPerFillImpl + +void LHCInfoPerFillPopConSourceHandler::getNewObjects() { + //reference to the last payload in the tag + Ref previousFill; + + //if a new tag is created, transfer fake fill from 1 to the first fill for the first time + if (tagInfo().size == 0) { + edm::LogInfo(m_name) << "New tag " << tagInfo().name << "; from " << m_name << "::getNewObjects"; + } else { + //check what is already inside the database + edm::LogInfo(m_name) << "got info for tag " << tagInfo().name << ": size " << tagInfo().size + << ", last object valid since " << tagInfo().lastInterval.since << " ( " + << boost::posix_time::to_iso_extended_string( + cond::time::to_boost(tagInfo().lastInterval.since)) + << " ); from " << m_name << "::getNewObjects"; + } + + cond::Time_t lastSince = tagInfo().lastInterval.since; + if (tagInfo().isEmpty()) { + // for a new or empty tag, an empty payload should be added on top with since=1 + addEmptyPayload(1); + lastSince = 1; + } else { + edm::LogInfo(m_name) << "The last Iov in tag " << tagInfo().name << " valid since " << lastSince << "from " + << m_name << "::getNewObjects"; + } + + boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time(); + cond::Time_t targetSince = 0; + cond::Time_t endIov = cond::time::from_boost(executionTime); + if (!m_startTime.is_not_a_date_time()) { + targetSince = cond::time::from_boost(m_startTime); + } + if (lastSince > targetSince) + targetSince = lastSince; + + edm::LogInfo(m_name) << "Starting sampling at " + << boost::posix_time::to_simple_string(cond::time::to_boost(targetSince)); + + //retrieve the data from the relational database source + cond::persistency::ConnectionPool connection; + //configure the connection + if (m_debug) { + connection.setMessageVerbosity(coral::Debug); + } else { + connection.setMessageVerbosity(coral::Error); + } + connection.setAuthenticationPath(m_authpath); + connection.configure(); + //create the sessions + cond::persistency::Session session = connection.createSession(m_connectionString, false); + cond::persistency::Session session2 = connection.createSession(m_ecalConnectionString, false); + // fetch last payload when available + if (!tagInfo().lastInterval.payloadId.empty()) { + cond::persistency::Session session3 = dbSession(); + session3.transaction().start(true); + m_prevPayload = session3.fetchPayload(tagInfo().lastInterval.payloadId); + session3.transaction().commit(); + } + + // bool iovAdded = false; + while (true) { + if (targetSince >= endIov) { + edm::LogInfo(m_name) << "Sampling ended at the time " + << boost::posix_time::to_simple_string(cond::time::to_boost(endIov)); + break; + } + bool updateEcal = false; + boost::posix_time::ptime targetTime = cond::time::to_boost(targetSince); + boost::posix_time::ptime startSampleTime; + boost::posix_time::ptime endSampleTime; + + cond::OMSService oms; + oms.connect(m_omsBaseUrl); + auto query = oms.query("fills"); + + edm::LogInfo(m_name) << "Searching new fill after " << boost::posix_time::to_simple_string(targetTime); + query->filterNotNull("start_stable_beam").filterNotNull("fill_number"); + if (targetTime > cond::time::to_boost(m_prevPayload->createTime())) { + query->filterGE("start_time", targetTime); + } else { + query->filterGT("start_time", targetTime); + } + + query->filterLT("start_time", m_endTime); + if (m_endFill) + query->filterNotNull("end_time"); + bool foundFill = query->execute(); + if (foundFill) + foundFill = LHCInfoPerFillImpl::makeFillPayload(m_fillPayload, query->result()); + if (!foundFill) { + edm::LogInfo(m_name) << "No fill found - END of job."; + // if (iovAdded) + // addEmptyPayload(targetSince); + break; + } + + startSampleTime = cond::time::to_boost(m_fillPayload->createTime()); + cond::Time_t startFillTime = m_fillPayload->createTime(); + cond::Time_t endFillTime = m_fillPayload->endTime(); + unsigned short lhcFill = m_fillPayload->fillNumber(); + if (endFillTime == 0ULL) { + edm::LogInfo(m_name) << "Found ongoing fill " << lhcFill << " created at " << cond::time::to_boost(startFillTime); + endSampleTime = executionTime; + targetSince = endIov; + } else { + edm::LogInfo(m_name) << "Found fill " << lhcFill << " created at " << cond::time::to_boost(startFillTime) + << " ending at " << cond::time::to_boost(endFillTime); + endSampleTime = cond::time::to_boost(endFillTime); + targetSince = endFillTime; + } + + getDipData(oms, startSampleTime, endSampleTime); + getLumiData(oms, lhcFill, startSampleTime, endSampleTime); + boost::posix_time::ptime flumiStart = cond::time::to_boost(m_tmpBuffer.front().first); + boost::posix_time::ptime flumiStop = cond::time::to_boost(m_tmpBuffer.back().first); + edm::LogInfo(m_name) << "First lumi starts at " << flumiStart << " last lumi starts at " << flumiStop; + session.transaction().start(true); + getCTTPSData(session, startSampleTime, endSampleTime); + session.transaction().commit(); + session2.transaction().start(true); + getEcalData(session2, startSampleTime, endSampleTime, updateEcal); + session2.transaction().commit(); + // + size_t niovs = LHCInfoPerFillImpl::transferPayloads(m_tmpBuffer, m_iovs, m_prevPayload); + edm::LogInfo(m_name) << "Added " << niovs << " iovs within the Fill time"; + m_tmpBuffer.clear(); + // iovAdded = true; + if (m_prevPayload->fillNumber() and m_fillPayload->endTime() != 0ULL) + addEmptyPayload(m_fillPayload->endTime()); + } +} + +std::string LHCInfoPerFillPopConSourceHandler::id() const { return m_name; } diff --git a/CondTools/RunInfo/src/LHCInfoPerLSPopConSourceHandler.cc b/CondTools/RunInfo/src/LHCInfoPerLSPopConSourceHandler.cc new file mode 100644 index 0000000000000..64d742d598f5a --- /dev/null +++ b/CondTools/RunInfo/src/LHCInfoPerLSPopConSourceHandler.cc @@ -0,0 +1,544 @@ +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "CondCore/CondDB/interface/ConnectionPool.h" +#include "CondFormats/Common/interface/TimeConversions.h" +#include "CondTools/RunInfo/interface/LHCInfoPerLSPopConSourceHandler.h" +#include "CondTools/RunInfo/interface/OMSAccess.h" +#include "RelationalAccess/ISessionProxy.h" +#include "RelationalAccess/ISchema.h" +#include "RelationalAccess/IQuery.h" +#include "RelationalAccess/ICursor.h" +#include "CoralBase/AttributeList.h" +#include "CoralBase/Attribute.h" +#include "CoralBase/AttributeSpecification.h" +#include "CoralBase/TimeStamp.h" +#include +#include +#include +#include +#include +#include +#include + +LHCInfoPerLSPopConSourceHandler::LHCInfoPerLSPopConSourceHandler(edm::ParameterSet const& pset) + : m_debug(pset.getUntrackedParameter("debug", false)), + m_startTime(), + m_endTime(), + m_samplingInterval((unsigned int)pset.getUntrackedParameter("samplingInterval", 300)), + m_endFill(pset.getUntrackedParameter("endFill", true)), + m_name(pset.getUntrackedParameter("name", "LHCInfoPerLSPopConSourceHandler")), + m_connectionString(pset.getUntrackedParameter("connectionString", "")), + m_dipSchema(pset.getUntrackedParameter("DIPSchema", "")), + m_authpath(pset.getUntrackedParameter("authenticationPath", "")), + m_omsBaseUrl(pset.getUntrackedParameter("omsBaseUrl", "")), + m_fillPayload(), + m_prevPayload(), + m_tmpBuffer() { + if (pset.exists("startTime")) { + m_startTime = boost::posix_time::time_from_string(pset.getUntrackedParameter("startTime")); + } + boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); + m_endTime = now; + if (pset.exists("endTime")) { + m_endTime = boost::posix_time::time_from_string(pset.getUntrackedParameter("endTime")); + if (m_endTime > now) + m_endTime = now; + } +} +//L1: try with different m_dipSchema +//L2: try with different m_name +LHCInfoPerLSPopConSourceHandler::~LHCInfoPerLSPopConSourceHandler() {} + +namespace LHCInfoPerLSImpl { + + struct IOVComp { + bool operator()(const cond::Time_t& x, const std::pair>& y) { + return (x < y.first); + } + }; + + // function to search in the vector the target time + std::vector>>::const_iterator search( + const cond::Time_t& val, const std::vector>>& container) { + if (container.empty()) + return container.end(); + auto p = std::upper_bound(container.begin(), container.end(), val, IOVComp()); + return (p != container.begin()) ? p - 1 : container.end(); + } + +} // namespace LHCInfoPerLSImpl + +bool LHCInfoPerLSPopConSourceHandler::makeFillPayload (std::unique_ptr& targetPayload, + const cond::OMSServiceResult& queryResult) { + bool ret = false; + if (!queryResult.empty()) { + auto row = *queryResult.begin(); + auto currentFill = row.get("fill_number"); + m_startFillTime = cond::time::from_boost(row.get("start_time")); + m_endFillTime = cond::time::from_boost(row.get("end_time")); + targetPayload = std::make_unique(); + targetPayload->setFillNumber(currentFill); + ret = true; + } + return ret; +} + +void LHCInfoPerLSPopConSourceHandler::addPayloadToBuffer(cond::OMSServiceResultRef& row) +{ + auto lumiTime = row.get("start_time"); + LHCInfoPerLS* thisLumiSectionInfo = new LHCInfoPerLS(*m_fillPayload); + m_tmpBuffer.emplace_back(std::make_pair(cond::time::from_boost(lumiTime), thisLumiSectionInfo)); +} + +size_t LHCInfoPerLSPopConSourceHandler::bufferAllLS(const cond::OMSServiceResult& queryResult) +{ + for (auto r : queryResult) { + addPayloadToBuffer(r); + } + return queryResult.size(); +} + +size_t LHCInfoPerLSPopConSourceHandler::bufferFirstStableBeamLS(const cond::OMSServiceResult& queryResult) +{ + for (auto r : queryResult) { + if(r.get("beams_stable") == "true") { + addPayloadToBuffer(r); + edm::LogInfo(m_name) << "Buffered first lumisection of stable beam: LS: " + << r.get("lumisection_number") + << " run: " << r.get("run_number"); + + return 1; + } + } + return 0; +} + +size_t LHCInfoPerLSPopConSourceHandler::getLumiData(const cond::OMSService& oms, + unsigned short fillId, + const boost::posix_time::ptime& beginFillTime, + const boost::posix_time::ptime& endFillTime) { + auto query = oms.query("lumisections"); + query->addOutputVars({"start_time", "run_number", "beams_stable", "lumisection_number"}); + query->filterEQ("fill_number", fillId); + query->filterGT("start_time", beginFillTime).filterLT("start_time", endFillTime); + query->limit(kLumisectionsQueryLimit); + size_t nlumi = 0; + if (query->execute()) { + auto queryResult = query->result(); + if(m_endFill){ + nlumi = bufferAllLS(queryResult); + } + else { + nlumi = bufferFirstStableBeamLS(queryResult); + if(!nlumi && !queryResult.empty()) + { + auto firstRow = *queryResult.begin(); + addPayloadToBuffer(firstRow); + nlumi++; + } + } + edm::LogInfo(m_name) << "Found " << queryResult.size() << " lumisections during the fill " << fillId; + } + else { + edm::LogInfo(m_name) << "OMS query for lumisections of fill " << fillId << "failed, status:" << query->status(); + } + return nlumi; +} + +namespace LHCInfoPerLSImpl { + struct LumiSectionFilter { + LumiSectionFilter(const std::vector>>& samples) + : currLow(samples.begin()), currUp(samples.begin()), end(samples.end()) { + currUp++; + } + + void reset(const std::vector>>& samples) { + currLow = samples.begin(); + currUp = samples.begin(); + currUp++; + end = samples.end(); + currentDipTime = 0; + } + + bool process(cond::Time_t dipTime) { + if (currLow == end) + return false; + bool search = false; + if (currentDipTime == 0) { + search = true; + } else { + if (dipTime == currentDipTime) + return true; + else { + cond::Time_t upper = cond::time::MAX_VAL; + if (currUp != end) + upper = currUp->first; + if (dipTime < upper && currentDipTime >= currLow->first) + return false; + else { + search = true; + } + } + } + if (search) { + while (currUp != end and currUp->first < dipTime) { + currLow++; + currUp++; + } + currentDipTime = dipTime; + return currLow != end; + } + return false; + } + + cond::Time_t currentSince() { return currLow->first; } + LHCInfoPerLS& currentPayload() { return *currLow->second; } + + std::vector>>::const_iterator current() { return currLow; } + std::vector>>::const_iterator currLow; + std::vector>>::const_iterator currUp; + std::vector>>::const_iterator end; + cond::Time_t currentDipTime = 0; + }; +} // namespace LHCInfoPerLSImpl + + +bool LHCInfoPerLSPopConSourceHandler::getCTTPSData(cond::persistency::Session& session, + const boost::posix_time::ptime& beginFillTime, + const boost::posix_time::ptime& endFillTime) { + //run the fifth query against the CTPPS schema + //Initializing the CMS_CTP_CTPPS_COND schema. + coral::ISchema& CTPPS = session.coralSession().schema("CMS_PPS_SPECT_COND"); + //execute query for CTPPS Data + std::unique_ptr CTPPSDataQuery(CTPPS.newQuery()); + //FROM clause + CTPPSDataQuery->addToTableList(std::string("PPS_LHC_MACHINE_PARAMS")); + //SELECT clause + CTPPSDataQuery->addToOutputList(std::string("DIP_UPDATE_TIME")); + CTPPSDataQuery->addToOutputList(std::string("LUMI_SECTION")); + CTPPSDataQuery->addToOutputList(std::string("RUN_NUMBER")); + CTPPSDataQuery->addToOutputList(std::string("XING_ANGLE_P5_X_URAD")); + CTPPSDataQuery->addToOutputList(std::string("XING_ANGLE_P5_Y_URAD")); + CTPPSDataQuery->addToOutputList(std::string("BETA_STAR_P5_X_M")); + CTPPSDataQuery->addToOutputList(std::string("BETA_STAR_P5_Y_M")); + //WHERE CLAUSE + coral::AttributeList CTPPSDataBindVariables; + CTPPSDataBindVariables.extend(std::string("beginFillTime")); + CTPPSDataBindVariables.extend(std::string("endFillTime")); + CTPPSDataBindVariables[std::string("beginFillTime")].data() = coral::TimeStamp(beginFillTime); + CTPPSDataBindVariables[std::string("endFillTime")].data() = coral::TimeStamp(endFillTime); + std::string conditionStr = std::string("DIP_UPDATE_TIME>= :beginFillTime and DIP_UPDATE_TIME< :endFillTime"); + CTPPSDataQuery->setCondition(conditionStr, CTPPSDataBindVariables); + //ORDER BY clause + CTPPSDataQuery->addToOrderList(std::string("DIP_UPDATE_TIME")); + //define query output + coral::AttributeList CTPPSDataOutput; + CTPPSDataOutput.extend(std::string("DIP_UPDATE_TIME")); + CTPPSDataOutput.extend(std::string("LUMI_SECTION")); + CTPPSDataOutput.extend(std::string("RUN_NUMBER")); + CTPPSDataOutput.extend(std::string("XING_ANGLE_P5_X_URAD")); + CTPPSDataOutput.extend(std::string("XING_ANGLE_P5_Y_URAD")); + CTPPSDataOutput.extend(std::string("BETA_STAR_P5_X_M")); + CTPPSDataOutput.extend(std::string("BETA_STAR_P5_Y_M")); + CTPPSDataQuery->defineOutput(CTPPSDataOutput); + //execute the query + coral::ICursor& CTPPSDataCursor = CTPPSDataQuery->execute(); + cond::Time_t dipTime = 0; + unsigned int lumiSection = 0; + cond::Time_t runNumber = 0; + float crossingAngleX = 0., betaStarX = 0.; + float crossingAngleY = 0., betaStarY = 0.; + + bool ret = false; + LHCInfoPerLSImpl::LumiSectionFilter filter(m_tmpBuffer); + while (CTPPSDataCursor.next()) { + if (m_debug) { + std::ostringstream CTPPS; + CTPPSDataCursor.currentRow().toOutputStream(CTPPS); + } + coral::Attribute const& dipTimeAttribute = CTPPSDataCursor.currentRow()[std::string("DIP_UPDATE_TIME")]; + if (!dipTimeAttribute.isNull()) { + dipTime = cond::time::from_boost(dipTimeAttribute.data().time()); + if (filter.process(dipTime)) { + ret = true; + coral::Attribute const& lumiSectionAttribute = CTPPSDataCursor.currentRow()[std::string("LUMI_SECTION")]; + if (!lumiSectionAttribute.isNull()) { + lumiSection = lumiSectionAttribute.data(); + } + coral::Attribute const& runNumberAttribute = CTPPSDataCursor.currentRow()[std::string("RUN_NUMBER")]; + if (!runNumberAttribute.isNull()) { + runNumber = runNumberAttribute.data(); + } + coral::Attribute const& crossingAngleXAttribute = + CTPPSDataCursor.currentRow()[std::string("XING_ANGLE_P5_X_URAD")]; + if (!crossingAngleXAttribute.isNull()) { + crossingAngleX = crossingAngleXAttribute.data(); + } + coral::Attribute const& crossingAngleYAttribute = + CTPPSDataCursor.currentRow()[std::string("XING_ANGLE_P5_Y_URAD")]; + if (!crossingAngleYAttribute.isNull()) { + crossingAngleY = crossingAngleYAttribute.data(); + } + coral::Attribute const& betaStarXAttribute = CTPPSDataCursor.currentRow()[std::string("BETA_STAR_P5_X_M")]; + if (!betaStarXAttribute.isNull()) { + betaStarX = betaStarXAttribute.data(); + } + coral::Attribute const& betaStarYAttribute = CTPPSDataCursor.currentRow()[std::string("BETA_STAR_P5_Y_M")]; + if (!betaStarYAttribute.isNull()) { + betaStarY = betaStarYAttribute.data(); + } + for (auto it = filter.current(); it != m_tmpBuffer.end(); it++) { + // set the current values to all of the payloads of the lumi section samples after the current since + LHCInfoPerLS& payload = *(it->second); + payload.setCrossingAngleX(crossingAngleX); + payload.setCrossingAngleY(crossingAngleY); + payload.setBetaStarX(betaStarX); + payload.setBetaStarY(betaStarY); + payload.setLumiSection(lumiSection); + payload.setRunNumber(runNumber); + } + } + } + } + return ret; +} + +void LHCInfoPerLSPopConSourceHandler::addEmptyPayload(cond::Time_t iov) { + bool add = false; + if (m_iovs.empty()) { + if (!m_lastPayloadEmpty) + add = true; + } else { + auto lastAdded = m_iovs.rbegin()->second; + if (lastAdded->fillNumber() != 0) { + add = true; + } + } + if (add) { + auto newPayload = std::make_shared(); + m_iovs.insert(std::make_pair(iov, newPayload)); + m_prevPayload = newPayload; + m_prevEndFillTime = 0; + m_prevStartFillTime = 0; + } +} + +namespace LHCInfoPerLSImpl { + bool comparePayloads(const LHCInfoPerLS& rhs, const LHCInfoPerLS& lhs) { + if (rhs.fillNumber() != lhs.fillNumber()) + return false; + if (rhs.runNumber() != lhs.runNumber()) + return false; + if (rhs.crossingAngleX() != lhs.crossingAngleX()) + return false; + if (rhs.crossingAngleY() != lhs.crossingAngleY()) + return false; + if (rhs.betaStarX() != lhs.betaStarX()) + return false; + if (rhs.betaStarY() != lhs.betaStarY()) + return false; + return true; + } + + size_t transferPayloads(const std::vector>>& buffer, + std::map>& iovsToTransfer, + std::shared_ptr& prevPayload) { + size_t niovs = 0; + std::stringstream condIovs; + for (auto& iov : buffer) { + bool add = false; + auto payload = iov.second; + cond::Time_t since = iov.first; + if (iovsToTransfer.empty()) { + add = true; + } else { + LHCInfoPerLS& lastAdded = *iovsToTransfer.rbegin()->second; + if (!comparePayloads(lastAdded, *payload)) { + add = true; + } + } + if (add) { + niovs++; + condIovs << since << " "; + iovsToTransfer.insert(std::make_pair(since, payload)); + prevPayload = iov.second; + } + } + edm::LogInfo("transferPayloads") << "TRANSFERED COND IOVS: " << condIovs.str(); + return niovs; + } + +} // namespace LHCInfoPerLSImpl + +void LHCInfoPerLSPopConSourceHandler::getNewObjects() { + //if a new tag is created, transfer fake fill from 1 to the first fill for the first time + if (tagInfo().size == 0) { + edm::LogInfo(m_name) << "New tag " << tagInfo().name << "; from " << m_name << "::getNewObjects"; + } else { + //check what is already inside the database + edm::LogInfo(m_name) << "got info for tag " << tagInfo().name << ": size " << tagInfo().size + << ", last object valid since " << tagInfo().lastInterval.since << " ( " + << boost::posix_time::to_iso_extended_string( + cond::time::to_boost(tagInfo().lastInterval.since)) + << " ); from " << m_name << "::getNewObjects"; + } + + cond::Time_t lastSince = tagInfo().lastInterval.since; + if (tagInfo().isEmpty()) { + // for a new or empty tag, an empty payload should be added on top with since=1 + addEmptyPayload(1); + lastSince = 1; + } else { + edm::LogInfo(m_name) << "The last Iov in tag " << tagInfo().name << " valid since " << lastSince << "from " + << m_name << "::getNewObjects"; + } + + boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time(); + cond::Time_t targetSince = 0; + cond::Time_t endIov = cond::time::from_boost(executionTime); + if (!m_startTime.is_not_a_date_time()) { + targetSince = cond::time::from_boost(m_startTime); + } + if (lastSince > targetSince) + targetSince = lastSince; + + edm::LogInfo(m_name) << "Starting sampling at " + << boost::posix_time::to_simple_string(cond::time::to_boost(targetSince)); + + //retrieve the data from the relational database source + cond::persistency::ConnectionPool connection; + //configure the connection + if (m_debug) { + connection.setMessageVerbosity(coral::Debug); + } else { + connection.setMessageVerbosity(coral::Error); + } + connection.setAuthenticationPath(m_authpath); + connection.configure(); + //create the sessions + cond::persistency::Session session = connection.createSession(m_connectionString, false); + // fetch last payload when available + if (!tagInfo().lastInterval.payloadId.empty()) { + cond::persistency::Session session3 = dbSession(); + session3.transaction().start(true); + m_prevPayload = session3.fetchPayload(tagInfo().lastInterval.payloadId); + session3.transaction().commit(); + if(m_prevPayload->fillNumber() != 0) + { + cond::OMSService oms; + oms.connect(m_omsBaseUrl); + auto query = oms.query("fills"); + query->addOutputVar("end_time"); + query->filterEQ("fill_number", m_prevPayload->fillNumber()); + bool foundFill = query->execute(); + if (foundFill) { + auto result = query->result(); + + if (!result.empty()) { + auto endFillTime = (*result.begin()).get("end_time"); + m_prevEndFillTime = cond::time::from_boost(endFillTime); + auto startFillTime = (*result.begin()).get("start_time"); + m_prevStartFillTime = cond::time::from_boost(startFillTime); + } + else { + foundFill = false; + } + } + if (!foundFill) { + edm::LogError(m_name) << "Could not find end time of fill #" << m_prevPayload->fillNumber(); + } + } + else + { + m_prevEndFillTime = 0; + m_prevStartFillTime = 0; + } + } + + // bool iovAdded = false; + while (true) { + if (targetSince >= endIov) { + edm::LogInfo(m_name) << "Sampling ended at the time " + << boost::posix_time::to_simple_string(cond::time::to_boost(endIov)); + break; + } + boost::posix_time::ptime targetTime = cond::time::to_boost(targetSince); + boost::posix_time::ptime startSampleTime; + boost::posix_time::ptime endSampleTime; + + cond::OMSService oms; + oms.connect(m_omsBaseUrl); + auto query = oms.query("fills"); + + if (!m_endFill and m_prevPayload->fillNumber() and m_prevEndFillTime == 0ULL) { + // execute the query for the current fill + edm::LogInfo(m_name) << "Searching started fill #" << m_prevPayload->fillNumber(); + query->filterEQ("fill_number", m_prevPayload->fillNumber()); + bool foundFill = query->execute(); + if (foundFill) + foundFill = makeFillPayload(m_fillPayload, query->result()); + if (!foundFill) { + edm::LogError(m_name) << "Could not find fill #" << m_prevPayload->fillNumber(); + break; + } + startSampleTime = cond::time::to_boost(lastSince); + } else { + edm::LogInfo(m_name) << "Searching new fill after " << boost::posix_time::to_simple_string(targetTime); + query->filterNotNull("start_stable_beam").filterNotNull("fill_number"); + if (targetTime > cond::time::to_boost(m_prevStartFillTime)) { + query->filterGE("start_time", targetTime); + } else { + query->filterGT("start_time", targetTime); + } + + query->filterLT("start_time", m_endTime); + if (m_endFill) + query->filterNotNull("end_time"); + bool foundFill = query->execute(); + if (foundFill) + foundFill = makeFillPayload(m_fillPayload, query->result()); + if (!foundFill) { + edm::LogInfo(m_name) << "No fill found - END of job."; + // if (iovAdded) + // addEmptyPayload(targetSince); + break; + } + startSampleTime = cond::time::to_boost(m_startFillTime); + } + + unsigned short lhcFill = m_fillPayload->fillNumber(); + if (m_endFillTime == 0ULL) { + edm::LogInfo(m_name) << "Found ongoing fill " << lhcFill << " created at " << cond::time::to_boost(m_startFillTime); + endSampleTime = executionTime; + targetSince = endIov; + } else { + edm::LogInfo(m_name) << "Found fill " << lhcFill << " created at " << cond::time::to_boost(m_startFillTime) + << " ending at " << cond::time::to_boost(m_endFillTime); + endSampleTime = cond::time::to_boost(m_endFillTime); + targetSince = m_endFillTime; + } + + + getLumiData(oms, lhcFill, startSampleTime, endSampleTime); + boost::posix_time::ptime flumiStart = cond::time::to_boost(m_tmpBuffer.front().first); + boost::posix_time::ptime flumiStop = cond::time::to_boost(m_tmpBuffer.back().first); + edm::LogInfo(m_name) << "First lumi starts at " << flumiStart << " last lumi starts at " << flumiStop; + session.transaction().start(true); + getCTTPSData(session, startSampleTime, endSampleTime); + session.transaction().commit(); + + // + size_t niovs = LHCInfoPerLSImpl::transferPayloads(m_tmpBuffer, m_iovs, m_prevPayload); + edm::LogInfo(m_name) << "Added " << niovs << " iovs within the Fill time"; + if(niovs){ + m_prevEndFillTime = m_endFillTime; + m_prevStartFillTime = m_startFillTime; + } + m_tmpBuffer.clear(); + // iovAdded = true; + if (m_prevPayload->fillNumber() and m_endFillTime != 0ULL) + addEmptyPayload(m_endFillTime); + } +} + +std::string LHCInfoPerLSPopConSourceHandler::id() const { return m_name; } diff --git a/CondTools/RunInfo/src/LHCInfoPopConSourceHandler.cc b/CondTools/RunInfo/src/LHCInfoPopConSourceHandler.cc index 99b4ea5215b80..cec335f798e94 100644 --- a/CondTools/RunInfo/src/LHCInfoPopConSourceHandler.cc +++ b/CondTools/RunInfo/src/LHCInfoPopConSourceHandler.cc @@ -156,7 +156,9 @@ size_t LHCInfoPopConSourceHandler::getLumiData(const cond::OMSService& oms, const boost::posix_time::ptime& endFillTime) { auto query = oms.query("lumisections"); query->addOutputVars({"start_time", "delivered_lumi", "recorded_lumi"}); - query->filterEQ("fill_number", fillId).filterGT("start_time", beginFillTime).filterLT("start_time", endFillTime); + query->filterEQ("fill_number", fillId); + query->filterGT("start_time", beginFillTime).filterLT("start_time", endFillTime); + query->limit(kLumisectionsQueryLimit); size_t nlumi = 0; if (query->execute()) { auto res = query->result(); @@ -239,6 +241,8 @@ void LHCInfoPopConSourceHandler::getDipData(const cond::OMSService& oms, // the old implementation is not helping: apparently it is checking only the bunchconfiguration for the first diptime set of values... auto query1 = oms.query("diplogger/dip/acc/LHC/RunControl/CirculatingBunchConfig/Beam1"); query1->filterGT("dip_time", beginFillTime).filterLT("dip_time", endFillTime); + //This query is limited to 100 rows, but currently only one is used + //If all this data is needed and saved properly the limit has to be set: query1->limit(...) if (query1->execute()) { auto res = query1->result(); if (!res.empty()) { @@ -256,6 +260,7 @@ void LHCInfoPopConSourceHandler::getDipData(const cond::OMSService& oms, } auto query2 = oms.query("diplogger/dip/acc/LHC/RunControl/CirculatingBunchConfig/Beam2"); query2->filterGT("dip_time", beginFillTime).filterLT("dip_time", endFillTime); + //This query is limited to 100 rows, but currently only one is used if (query2->execute()) { auto res = query2->result(); if (!res.empty()) { @@ -274,6 +279,7 @@ void LHCInfoPopConSourceHandler::getDipData(const cond::OMSService& oms, auto query3 = oms.query("diplogger/dip/CMS/LHC/LumiPerBunch"); query3->filterGT("dip_time", beginFillTime).filterLT("dip_time", endFillTime); + //This query is limited to 100 rows, but currently only one is used if (query3->execute()) { auto res = query3->result(); if (!res.empty()) { @@ -573,6 +579,8 @@ namespace LHCInfoImpl { std::map>& iovsToTransfer, std::shared_ptr& prevPayload) { size_t niovs = 0; + std::stringstream condIovs; + std::stringstream formattedIovs; for (auto& iov : buffer) { bool add = false; auto payload = iov.second; @@ -587,10 +595,14 @@ namespace LHCInfoImpl { } if (add) { niovs++; + condIovs << since << " "; + formattedIovs << boost::posix_time::to_iso_extended_string(cond::time::to_boost(since)) << " "; iovsToTransfer.insert(std::make_pair(since, payload)); prevPayload = iov.second; } } + edm::LogInfo("transferPayloads") << "TRANSFERED COND IOVS: " << condIovs.str(); + edm::LogInfo("transferPayloads") << "FORMATTED COND IOVS: " << formattedIovs.str(); return niovs; } @@ -655,7 +667,7 @@ void LHCInfoPopConSourceHandler::getNewObjects() { session3.transaction().commit(); } - bool iovAdded = false; + // bool iovAdded = false; while (true) { if (targetSince >= endIov) { edm::LogInfo(m_name) << "Sampling ended at the time " @@ -695,8 +707,8 @@ void LHCInfoPopConSourceHandler::getNewObjects() { foundFill = LHCInfoImpl::makeFillPayload(m_fillPayload, query->result()); if (!foundFill) { edm::LogInfo(m_name) << "No fill found - END of job."; - if (iovAdded) - addEmptyPayload(targetSince); + // if (iovAdded) + // addEmptyPayload(targetSince); break; } startSampleTime = cond::time::to_boost(m_fillPayload->createTime()); @@ -731,7 +743,7 @@ void LHCInfoPopConSourceHandler::getNewObjects() { size_t niovs = LHCInfoImpl::transferPayloads(m_tmpBuffer, m_iovs, m_prevPayload); edm::LogInfo(m_name) << "Added " << niovs << " iovs within the Fill time"; m_tmpBuffer.clear(); - iovAdded = true; + // iovAdded = true; if (m_prevPayload->fillNumber() and m_fillPayload->endTime() != 0ULL) addEmptyPayload(m_fillPayload->endTime()); } diff --git a/CondTools/RunInfo/src/OMSAccess.cc b/CondTools/RunInfo/src/OMSAccess.cc index 951fac68c5d17..21d9941986e28 100644 --- a/CondTools/RunInfo/src/OMSAccess.cc +++ b/CondTools/RunInfo/src/OMSAccess.cc @@ -33,6 +33,16 @@ namespace cond { OMSServiceResultIterator OMSServiceResult::end() const { return OMSServiceResultIterator(m_data->end()); } + OMSServiceResultRef OMSServiceResult::front() const { + auto& attributeList = m_data->front().second.get_child("attributes"); + return OMSServiceResultRef(&attributeList); + } + + OMSServiceResultRef OMSServiceResult::back() const{ + auto& attributeList = m_data->back().second.get_child("attributes"); + return OMSServiceResultRef(&attributeList); + } + size_t OMSServiceResult::parseData(const std::string& data) { m_data = nullptr; std::stringstream sout; @@ -83,6 +93,18 @@ namespace cond { return *this; } + OMSServiceQuery& OMSServiceQuery::limit(int value) { + std::stringstream pageLimit; + if (m_filter.empty()) { + pageLimit << "?"; + } else { + pageLimit << "&"; + } + pageLimit << "page[limit]=" << value; + m_limit = pageLimit.str(); + return *this; + } + bool OMSServiceQuery::execute() { bool ret = false; std::string out; @@ -99,7 +121,7 @@ namespace cond { OMSServiceResult& OMSServiceQuery::result() { return *m_result; } - std::string OMSServiceQuery::url() { return m_url + m_filter + m_varList; } + std::string OMSServiceQuery::url() { return m_url + m_filter + m_limit + m_varList; } OMSService::OMSService() : m_baseUrl() {} diff --git a/CondTools/RunInfo/test/LHCInfoPerFillAnalyzer_cfg.py b/CondTools/RunInfo/test/LHCInfoPerFillAnalyzer_cfg.py new file mode 100644 index 0000000000000..d08964cb8c9e2 --- /dev/null +++ b/CondTools/RunInfo/test/LHCInfoPerFillAnalyzer_cfg.py @@ -0,0 +1,47 @@ +import sys + +import FWCore.ParameterSet.Config as cms + +process = cms.Process('test') + +# minimum logging +process.MessageLogger = cms.Service("MessageLogger", + cerr = cms.untracked.PSet( + enable = cms.untracked.bool(False) + ), + cout = cms.untracked.PSet( + enable = cms.untracked.bool(True), + threshold = cms.untracked.string('INFO') + ) +) + +iov = int(7133383367994638336 if len(sys.argv) < 3 else sys.argv[2]) +print("iov:", iov) + +process.source = cms.Source('EmptyIOVSource', + timetype = cms.string('timestamp'), + firstValue = cms.uint64(iov ), + lastValue = cms.uint64(iov ), + interval = cms.uint64(1) +) + +# load info from database +process.load('CondCore.CondDB.CondDB_cfi') +process.CondDB.connect = 'sqlite_file:../python/lhcinfo_pop_test.db' # SQLite input + +process.PoolDBESSource = cms.ESSource('PoolDBESSource', + process.CondDB, + DumpStats = cms.untracked.bool(True), + toGet = cms.VPSet( + cms.PSet( + record = cms.string('LHCInfoPerFillRcd'), + tag = cms.string('perFill_10_end') + ) + ) +) + +process.LHCInfoPerFillAnalyzer = cms.EDAnalyzer('LHCInfoPerFillAnalyzer') + +process.path = cms.Path( + process.LHCInfoPerFillAnalyzer +) \ No newline at end of file diff --git a/CondTools/RunInfo/test/LHCInfoPerFillWriter_cfg.py b/CondTools/RunInfo/test/LHCInfoPerFillWriter_cfg.py new file mode 100644 index 0000000000000..9ee905d9ff524 --- /dev/null +++ b/CondTools/RunInfo/test/LHCInfoPerFillWriter_cfg.py @@ -0,0 +1,31 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process('test') + +process.source = cms.Source('EmptyIOVSource', + timetype = cms.string('runnumber'), + firstValue = cms.uint64(1), + lastValue = cms.uint64(1), + interval = cms.uint64(1) +) + +# output service for database +process.load('CondCore.CondDB.CondDB_cfi') +process.CondDB.connect = 'sqlite_file:LHCInfoPerFill.sqlite' # SQLite output + +process.PoolDBOutputService = cms.Service('PoolDBOutputService', + process.CondDB, + timetype = cms.untracked.string('runnumber'), + toPut = cms.VPSet( + cms.PSet( + record = cms.string('LHCInfoPerFillRcd'), + tag = cms.string('LHCInfoPerFillFake'), + ) + ) +) + +process.LHCInfoPerFillWriter = cms.EDAnalyzer('LHCInfoPerFillWriter') + +process.path = cms.Path( + process.LHCInfoPerFillWriter +) diff --git a/CondTools/RunInfo/test/LHCInfoPerLSAnalyzer_cfg.py b/CondTools/RunInfo/test/LHCInfoPerLSAnalyzer_cfg.py new file mode 100644 index 0000000000000..6707d025da5eb --- /dev/null +++ b/CondTools/RunInfo/test/LHCInfoPerLSAnalyzer_cfg.py @@ -0,0 +1,48 @@ +import FWCore.ParameterSet.Config as cms + +import sys + +process = cms.Process('test') + +# minimum logging +process.MessageLogger = cms.Service("MessageLogger", + cerr = cms.untracked.PSet( + enable = cms.untracked.bool(False) + ), + cout = cms.untracked.PSet( + enable = cms.untracked.bool(True), + threshold = cms.untracked.string('INFO') + ) +) + + +iov = int(7133383367994638336 if len(sys.argv) < 3 else sys.argv[2]) +print("iov:", iov) + +process.source = cms.Source('EmptyIOVSource', + timetype = cms.string('timestamp'), + firstValue = cms.uint64(iov ), + lastValue = cms.uint64(iov ), + interval = cms.uint64(1) +) + +# load info from database +process.load('CondCore.CondDB.CondDB_cfi') +process.CondDB.connect = 'sqlite_file:../python/lhcinfo_pop_test.db' # SQLite input + +process.PoolDBESSource = cms.ESSource('PoolDBESSource', + process.CondDB, + DumpStats = cms.untracked.bool(True), + toGet = cms.VPSet( + cms.PSet( + record = cms.string('LHCInfoPerLSRcd'), + tag = cms.string('perLS_3_end') + ) + ) +) + +process.LHCInfoPerLSAnalyzer = cms.EDAnalyzer('LHCInfoPerLSAnalyzer') + +process.path = cms.Path( + process.LHCInfoPerLSAnalyzer +) \ No newline at end of file diff --git a/CondTools/RunInfo/test/LHCInfoPerLSWriter_cfg.py b/CondTools/RunInfo/test/LHCInfoPerLSWriter_cfg.py new file mode 100644 index 0000000000000..d617d8f322700 --- /dev/null +++ b/CondTools/RunInfo/test/LHCInfoPerLSWriter_cfg.py @@ -0,0 +1,31 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process('test') + +process.source = cms.Source('EmptyIOVSource', + timetype = cms.string('runnumber'), + firstValue = cms.uint64(1), + lastValue = cms.uint64(1), + interval = cms.uint64(1) +) + +# output service for database +process.load('CondCore.CondDB.CondDB_cfi') +process.CondDB.connect = 'sqlite_file:LHCInfoPerLS.sqlite' # SQLite output + +process.PoolDBOutputService = cms.Service('PoolDBOutputService', + process.CondDB, + timetype = cms.untracked.string('runnumber'), + toPut = cms.VPSet( + cms.PSet( + record = cms.string('LHCInfoPerLSRcd'), + tag = cms.string('LHCInfoPerLSFake'), + ) + ) +) + +process.LHCInfoPerLSWriter = cms.EDAnalyzer('LHCInfoPerLSWriter') + +process.path = cms.Path( + process.LHCInfoPerLSWriter +) diff --git a/RecoPPS/ProtonReconstruction/interface/ProtonReconstructionAlgorithm.h b/RecoPPS/ProtonReconstruction/interface/ProtonReconstructionAlgorithm.h index dcdad26c8d629..a983b1faf4074 100644 --- a/RecoPPS/ProtonReconstruction/interface/ProtonReconstructionAlgorithm.h +++ b/RecoPPS/ProtonReconstruction/interface/ProtonReconstructionAlgorithm.h @@ -12,7 +12,6 @@ #include "DataFormats/CTPPSReco/interface/CTPPSLocalTrackLiteFwd.h" #include "DataFormats/ProtonReco/interface/ForwardProtonFwd.h" -#include "CondFormats/RunInfo/interface/LHCInfo.h" #include "CondFormats/PPSObjects/interface/LHCInterpolatedOpticalFunctionsSet.h" #include "CondFormats/PPSObjects/interface/LHCInterpolatedOpticalFunctionsSetCollection.h" @@ -36,12 +35,12 @@ class ProtonReconstructionAlgorithm { /// run proton reconstruction using single-RP strategy reco::ForwardProton reconstructFromSingleRP(const CTPPSLocalTrackLiteRef &track, - const LHCInfo &lhcInfo, + const float &energy, std::ostream &os) const; /// run proton reconstruction using multiple-RP strategy reco::ForwardProton reconstructFromMultiRP(const CTPPSLocalTrackLiteRefVector &tracks, - const LHCInfo &lhcInfo, + const float &energy, std::ostream &os) const; private: diff --git a/RecoPPS/ProtonReconstruction/plugins/CTPPSProtonProducer.cc b/RecoPPS/ProtonReconstruction/plugins/CTPPSProtonProducer.cc index 49927283ea0aa..a387690392369 100644 --- a/RecoPPS/ProtonReconstruction/plugins/CTPPSProtonProducer.cc +++ b/RecoPPS/ProtonReconstruction/plugins/CTPPSProtonProducer.cc @@ -25,6 +25,11 @@ #include "CondFormats/RunInfo/interface/LHCInfo.h" #include "CondFormats/DataRecord/interface/LHCInfoRcd.h" +#include "CondFormats/RunInfo/interface/LHCInfoCombined.h" +#include "CondFormats/RunInfo/interface/LHCInfoPerLS.h" +#include "CondFormats/DataRecord/interface/LHCInfoPerLSRcd.h" +#include "CondFormats/RunInfo/interface/LHCInfoPerFill.h" +#include "CondFormats/DataRecord/interface/LHCInfoPerFillRcd.h" #include "CondFormats/DataRecord/interface/CTPPSInterpolatedOpticsRcd.h" #include "CondFormats/PPSObjects/interface/LHCInterpolatedOpticalFunctionsSetCollection.h" @@ -51,6 +56,8 @@ class CTPPSProtonProducer : public edm::stream::EDProducer<> { bool pixelDiscardBXShiftedTracks_; + std::string lhcInfoPerLSLabel_; + std::string lhcInfoPerFillLabel_; std::string lhcInfoLabel_; std::string opticsLabel_; std::string ppsAssociationCutsLabel_; @@ -73,6 +80,8 @@ class CTPPSProtonProducer : public edm::stream::EDProducer<> { bool opticsValid_; edm::ESWatcher opticsWatcher_; + edm::ESGetToken lhcInfoPerLSToken_; + edm::ESGetToken lhcInfoPerFillToken_; edm::ESGetToken lhcInfoToken_; edm::ESGetToken opticalFunctionsToken_; edm::ESGetToken geometryToken_; @@ -86,10 +95,12 @@ CTPPSProtonProducer::CTPPSProtonProducer(const edm::ParameterSet &iConfig) pixelDiscardBXShiftedTracks_(iConfig.getParameter("pixelDiscardBXShiftedTracks")), + lhcInfoPerLSLabel_(iConfig.getParameter("lhcInfoPerLSLabel")), + lhcInfoPerFillLabel_(iConfig.getParameter("lhcInfoPerFillLabel")), lhcInfoLabel_(iConfig.getParameter("lhcInfoLabel")), opticsLabel_(iConfig.getParameter("opticsLabel")), ppsAssociationCutsLabel_(iConfig.getParameter("ppsAssociationCutsLabel")), - verbosity_(iConfig.getUntrackedParameter("verbosity", 0)), + verbosity_(iConfig.getUntrackedParameter("verbosity", 2)), doSingleRPReconstruction_(iConfig.getParameter("doSingleRPReconstruction")), doMultiRPReconstruction_(iConfig.getParameter("doMultiRPReconstruction")), singleRPReconstructionLabel_(iConfig.getParameter("singleRPReconstructionLabel")), @@ -108,12 +119,16 @@ CTPPSProtonProducer::CTPPSProtonProducer(const edm::ParameterSet &iConfig) iConfig.getParameter("multiRPAlgorithm"), verbosity_), opticsValid_(false), + lhcInfoPerLSToken_(esConsumes(edm::ESInputTag("", lhcInfoPerLSLabel_))), + lhcInfoPerFillToken_(esConsumes(edm::ESInputTag("", lhcInfoPerFillLabel_))), lhcInfoToken_(esConsumes(edm::ESInputTag("", lhcInfoLabel_))), opticalFunctionsToken_(esConsumes( edm::ESInputTag("", opticsLabel_))), geometryToken_(esConsumes()), ppsAssociationCutsToken_( esConsumes(edm::ESInputTag("", ppsAssociationCutsLabel_))) { + edm::LogWarning("CTPPSProtonProducer") << "consturcting CTPPSProtonProducer"; + if (doSingleRPReconstruction_) produces(singleRPReconstructionLabel_); @@ -132,6 +147,8 @@ void CTPPSProtonProducer::fillDescriptions(edm::ConfigurationDescriptions &descr desc.add("pixelDiscardBXShiftedTracks", false) ->setComment("whether to discard pixel tracks built from BX-shifted planes"); + desc.add("lhcInfoPerFillLabel", "")->setComment("label of the LHCInfoPerFill record"); + desc.add("lhcInfoPerLSLabel", "")->setComment("label of the LHCInfoPerLS record"); desc.add("lhcInfoLabel", "")->setComment("label of the LHCInfo record"); desc.add("opticsLabel", "")->setComment("label of the optics record"); desc.add("ppsAssociationCutsLabel", "")->setComment("label of the association cuts record"); @@ -188,7 +205,11 @@ void CTPPSProtonProducer::produce(edm::Event &iEvent, const edm::EventSetup &iSe // NB: this avoids loading (possibly non-existing) conditions in workflows without proton data if (!hTracks->empty()) { // get conditions - edm::ESHandle hLHCInfo = iSetup.getHandle(lhcInfoToken_); + LHCInfoCombined lhcInfoCombined(iSetup, lhcInfoPerLSToken_, lhcInfoPerFillToken_, lhcInfoToken_); + + edm::LogWarning("CTPPSProtonProducer") << "LHCInfoCombined: \n" << lhcInfoCombined; + edm::LogWarning("CTPPSProtonProducer") << "LogWarning test"; + edm::ESHandle hOpticalFunctions = iSetup.getHandle(opticalFunctionsToken_); @@ -200,7 +221,7 @@ void CTPPSProtonProducer::produce(edm::Event &iEvent, const edm::EventSetup &iSe // re-initialise algorithm upon crossing-angle change if (opticsWatcher_.check(iSetup)) { if (hOpticalFunctions->empty()) { - edm::LogInfo("CTPPSProtonProducer") << "No optical functions available, reconstruction disabled."; + edm::LogWarning("CTPPSProtonProducer") << "No optical functions available, reconstruction disabled."; algorithm_.release(); opticsValid_ = false; } else { @@ -211,6 +232,7 @@ void CTPPSProtonProducer::produce(edm::Event &iEvent, const edm::EventSetup &iSe // do reconstruction only if optics is valid if (opticsValid_) { + edm::LogWarning("CTPPSProtonProducer") << "optics valid"; // prepare log std::ostringstream ssLog; if (verbosity_) @@ -263,10 +285,13 @@ void CTPPSProtonProducer::produce(edm::Event &iEvent, const edm::EventSetup &iSe if (verbosity_) ssLog << std::endl << "* reconstruction from track " << idx << std::endl; - singleRPResultsIndexed[idx] = - algorithm_.reconstructFromSingleRP(CTPPSLocalTrackLiteRef(hTracks, idx), *hLHCInfo, ssLog); + singleRPResultsIndexed[idx] = algorithm_.reconstructFromSingleRP(CTPPSLocalTrackLiteRef(hTracks, idx), + lhcInfoCombined.energy, ssLog); } } + else { + edm::LogWarning("CTPPSProtonProducer") << "Not executing reconstructFromSingleRP"; + } // check that exactly two tracking RPs are involved // - 1 is insufficient for multi-RP reconstruction @@ -277,6 +302,7 @@ void CTPPSProtonProducer::produce(edm::Event &iEvent, const edm::EventSetup &iSe // do multi-RP reco if chosen if (doMultiRPReconstruction_ && rpIds.size() == 2) { + // find matching track pairs from different tracking RPs, ordered: i=near, j=far RP std::vector> idx_pairs; std::map idx_pair_multiplicity; @@ -299,14 +325,14 @@ void CTPPSProtonProducer::produce(edm::Event &iEvent, const edm::EventSetup &iSe bool matching = true; - if (!ac.isSatisfied(ac.qX, tr_i.x(), tr_i.y(), hLHCInfo->crossingAngle(), tr_i.x() - tr_j.x())) + if (!ac.isSatisfied(ac.qX, tr_i.x(), tr_i.y(), lhcInfoCombined.crossingAngleX, tr_i.x() - tr_j.x())) matching = false; - else if (!ac.isSatisfied(ac.qY, tr_i.x(), tr_i.y(), hLHCInfo->crossingAngle(), tr_i.y() - tr_j.y())) + else if (!ac.isSatisfied(ac.qY, tr_i.x(), tr_i.y(), lhcInfoCombined.crossingAngleX, tr_i.y() - tr_j.y())) matching = false; - else if (!ac.isSatisfied(ac.qXi, tr_i.x(), tr_i.y(), hLHCInfo->crossingAngle(), pr_i.xi() - pr_j.xi())) + else if (!ac.isSatisfied(ac.qXi, tr_i.x(), tr_i.y(), lhcInfoCombined.crossingAngleX, pr_i.xi() - pr_j.xi())) matching = false; else if (!ac.isSatisfied( - ac.qThetaY, tr_i.x(), tr_i.y(), hLHCInfo->crossingAngle(), pr_i.thetaY() - pr_j.thetaY())) + ac.qThetaY, tr_i.x(), tr_i.y(), lhcInfoCombined.crossingAngleX, pr_i.thetaY() - pr_j.thetaY())) matching = false; if (!matching) @@ -424,7 +450,8 @@ void CTPPSProtonProducer::produce(edm::Event &iEvent, const edm::EventSetup &iSe ssLog << std::endl << " time = " << time << " +- " << time_unc << std::endl; // process tracking-RP data - reco::ForwardProton proton = algorithm_.reconstructFromMultiRP(sel_track_for_kin_reco, *hLHCInfo, ssLog); + reco::ForwardProton proton = algorithm_.reconstructFromMultiRP(sel_track_for_kin_reco, + lhcInfoCombined.energy, ssLog); // save combined output proton.setContributingLocalTracks(sel_tracks); @@ -434,6 +461,9 @@ void CTPPSProtonProducer::produce(edm::Event &iEvent, const edm::EventSetup &iSe pOutMultiRP->emplace_back(proton); } } + else { + edm::LogWarning("CTPPSProtonProducer") << "Not executing reconstructFromMultiRP"; + } // save single-RP results (un-indexed) for (const auto &p : singleRPResultsIndexed) @@ -442,8 +472,15 @@ void CTPPSProtonProducer::produce(edm::Event &iEvent, const edm::EventSetup &iSe // dump log if (verbosity_) - edm::LogInfo("CTPPSProtonProducer") << ssLog.str(); + edm::LogWarning("CTPPSProtonProducer") << ssLog.str(); } + else { + edm::LogWarning("CTPPSProtonProducer") << "optics invalid"; + } + + } + else { + edm::LogWarning("CTPPSProtonProducer") << "tracks already exists, not using LHCInfoCombined"; } // save output diff --git a/RecoPPS/ProtonReconstruction/python/ctppsProtons_cff.py b/RecoPPS/ProtonReconstruction/python/ctppsProtons_cff.py index 392d72ab12c30..6e9a8fcae7fe8 100644 --- a/RecoPPS/ProtonReconstruction/python/ctppsProtons_cff.py +++ b/RecoPPS/ProtonReconstruction/python/ctppsProtons_cff.py @@ -9,7 +9,12 @@ # import and adjust proton-reconstructions settings from RecoPPS.ProtonReconstruction.ctppsProtons_cfi import * +print("in file ctppsProtons_cfi") +# print(ctppsProtons) + ctppsProtons.lhcInfoLabel = ctppsLHCInfoLabel +ctppsProtons.lhcInfoPerLSLabel = ctppsLHCInfoPerLSLabel +ctppsProtons.lhcInfoPerFillLabel = ctppsLHCInfoPerFillLabel ctppsProtons.pixelDiscardBXShiftedTracks = True ctppsProtons.default_time = -999. diff --git a/RecoPPS/ProtonReconstruction/src/ProtonReconstructionAlgorithm.cc b/RecoPPS/ProtonReconstruction/src/ProtonReconstructionAlgorithm.cc index 77243b6510a5e..b65081423cf76 100644 --- a/RecoPPS/ProtonReconstruction/src/ProtonReconstructionAlgorithm.cc +++ b/RecoPPS/ProtonReconstruction/src/ProtonReconstructionAlgorithm.cc @@ -169,7 +169,7 @@ double ProtonReconstructionAlgorithm::newtonGoalFcn(double xi, //---------------------------------------------------------------------------------------------------- reco::ForwardProton ProtonReconstructionAlgorithm::reconstructFromMultiRP(const CTPPSLocalTrackLiteRefVector &tracks, - const LHCInfo &lhcInfo, + const float &energy, std::ostream &os) const { // make sure optics is available for all tracks for (const auto &it : tracks) { @@ -391,7 +391,8 @@ reco::ForwardProton ProtonReconstructionAlgorithm::reconstructFromMultiRP(const const FP::Point vertex(0., vtx_y, 0.); const double cos_th_sq = 1. - th_x * th_x - th_y * th_y; const double cos_th = (cos_th_sq > 0.) ? sqrt(cos_th_sq) : 1.; - const double p = lhcInfo.energy() * (1. - xi); + const double p = energy * (1. - xi); + edm::LogWarning("ProtonRecoAlgo") << "Energy: " << energy << " hexfloat: " << std::hexfloat << energy; const FP::Vector momentum(-p * th_x, // the signs reflect change LHC --> CMS convention +p * th_y, sign_z * p * cos_th); @@ -403,7 +404,7 @@ reco::ForwardProton ProtonReconstructionAlgorithm::reconstructFromMultiRP(const //---------------------------------------------------------------------------------------------------- reco::ForwardProton ProtonReconstructionAlgorithm::reconstructFromSingleRP(const CTPPSLocalTrackLiteRef &track, - const LHCInfo &lhcInfo, + const float &energy, std::ostream &os) const { CTPPSDetId rpId(track->rpId()); @@ -441,7 +442,8 @@ reco::ForwardProton ProtonReconstructionAlgorithm::reconstructFromSingleRP(const const FP::Point vertex(0., 0., 0.); const double cos_th_sq = 1. - th_y * th_y; const double cos_th = (cos_th_sq > 0.) ? sqrt(cos_th_sq) : 1.; - const double p = lhcInfo.energy() * (1. - xi); + const double p = energy * (1. - xi); + edm::LogWarning("ProtonRecoAlgo") << "Energy: " << energy << " hexfloat: " << std::hexfloat << energy; const FP::Vector momentum(0., p * th_y, sign_z * p * cos_th); FP::CovarianceMatrix cm;