From 5a3afffd4a64b32c6049cee8d8afd4beef9090cf Mon Sep 17 00:00:00 2001 From: mmusich Date: Mon, 24 Apr 2023 15:53:01 +0200 Subject: [PATCH 1/5] put fake beamspot in the event if the arbitration returns a fake BS, by letting the BeamSpotOnlineProducer deal automatically with the arbitrated one --- .../plugins/BeamSpotOnlineProducer.cc | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/RecoVertex/BeamSpotProducer/plugins/BeamSpotOnlineProducer.cc b/RecoVertex/BeamSpotProducer/plugins/BeamSpotOnlineProducer.cc index dbfddf0305934..1eb0a4a91a4e2 100644 --- a/RecoVertex/BeamSpotProducer/plugins/BeamSpotOnlineProducer.cc +++ b/RecoVertex/BeamSpotProducer/plugins/BeamSpotOnlineProducer.cc @@ -102,39 +102,39 @@ void BeamSpotOnlineProducer::produce(Event& iEvent, const EventSetup& iSetup) { bool fallBackToDB = false; if (useTransientRecord_) { auto const& spotDB = iSetup.getData(beamTransientToken_); + if (spotDB.beamType() != 2) { if (shoutMODE && beamTransientRcdESWatcher_.check(iSetup)) { - edm::LogWarning("BeamSpotFromDB") - << "Online Beam Spot producer falls back to DB value because the ESProducer returned a fake beamspot "; + edm::LogWarning("BeamSpotFromDB") << "Online Beam Spot producer writes a fake beamspot value because the " + "ESProducer returned a fake beamspot!"; } - fallBackToDB = true; - } else { - // translate from BeamSpotObjects to reco::BeamSpot - // in case we need to switch to LHC reference frame - // ignore for the moment rotations, and translations - double f = 1.; - if (changeFrame_) - f = -1.; - reco::BeamSpot::Point apoint(f * spotDB.x(), f * spotDB.y(), f * spotDB.z()); + } - reco::BeamSpot::CovarianceMatrix matrix; - for (int i = 0; i < 7; ++i) { - for (int j = 0; j < 7; ++j) { - matrix(i, j) = spotDB.covariance(i, j); - } - } - double sigmaZ = spotDB.sigmaZ(); - if (theSetSigmaZ > 0) - sigmaZ = theSetSigmaZ; + // translate from BeamSpotObjects to reco::BeamSpot + // in case we need to switch to LHC reference frame + // ignore for the moment rotations, and translations + double f = 1.; + if (changeFrame_) + f = -1.; + reco::BeamSpot::Point apoint(f * spotDB.x(), f * spotDB.y(), f * spotDB.z()); - // this assume beam width same in x and y - aSpot = reco::BeamSpot(apoint, sigmaZ, spotDB.dxdz(), spotDB.dydz(), spotDB.beamWidthX(), matrix); - aSpot.setBeamWidthY(spotDB.beamWidthY()); - aSpot.setEmittanceX(spotDB.emittanceX()); - aSpot.setEmittanceY(spotDB.emittanceY()); - aSpot.setbetaStar(spotDB.betaStar()); - aSpot.setType(reco::BeamSpot::Tracker); + reco::BeamSpot::CovarianceMatrix matrix; + for (int i = 0; i < 7; ++i) { + for (int j = 0; j < 7; ++j) { + matrix(i, j) = spotDB.covariance(i, j); + } } + double sigmaZ = spotDB.sigmaZ(); + if (theSetSigmaZ > 0) + sigmaZ = theSetSigmaZ; + + // this assume beam width same in x and y + aSpot = reco::BeamSpot(apoint, sigmaZ, spotDB.dxdz(), spotDB.dydz(), spotDB.beamWidthX(), matrix); + aSpot.setBeamWidthY(spotDB.beamWidthY()); + aSpot.setEmittanceX(spotDB.emittanceX()); + aSpot.setEmittanceY(spotDB.emittanceY()); + aSpot.setbetaStar(spotDB.betaStar()); + aSpot.setType(static_cast(spotDB.beamType())); } else { // get scalar collection Handle handleScaler; From 0b2e1056426f5188428ea8b0708806e234d00fe1 Mon Sep 17 00:00:00 2001 From: mmusich Date: Sat, 6 May 2023 21:08:58 +0200 Subject: [PATCH 2/5] add a converter from BeamSpotObjects to BeamSpotOnlineObjects --- .../BeamSpotOnlineFromOfflineConverter.cc | 174 ++++++++++++++++++ .../BeamSpotOnlineFromOfflineConverter_cfg.py | 101 ++++++++++ 2 files changed, 275 insertions(+) create mode 100644 CondTools/BeamSpot/plugins/BeamSpotOnlineFromOfflineConverter.cc create mode 100644 CondTools/BeamSpot/test/BeamSpotOnlineFromOfflineConverter_cfg.py diff --git a/CondTools/BeamSpot/plugins/BeamSpotOnlineFromOfflineConverter.cc b/CondTools/BeamSpot/plugins/BeamSpotOnlineFromOfflineConverter.cc new file mode 100644 index 0000000000000..18fc03ba9246a --- /dev/null +++ b/CondTools/BeamSpot/plugins/BeamSpotOnlineFromOfflineConverter.cc @@ -0,0 +1,174 @@ +// -*- C++ -*- +// +// Package: CondTools/BeamSpot +// Class: BeamSpotOnlineFromOfflineConverter +// +/**\class BeamSpotOnlineFromOfflineConverter BeamSpotOnlineFromOfflineConverter.cc CondTools/BeamSpot/plugins/BeamSpotOnlineFromOfflineConverter.cc + + Description: EDAnalyzer to create a BeamSpotOnlineHLTObjectsRcd from a BeamSpotObjectsRcd (inserting some parameters manually) + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Marco Musich +// Created: Sat, 06 May 2023 21:10:00 GMT +// +// + +// system include files +#include +#include +#include +#include +#include + +// user include files +#include "CondCore/DBOutputService/interface/PoolDBOutputService.h" +#include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h" +#include "CondFormats/BeamSpotObjects/interface/BeamSpotOnlineObjects.h" +#include "CondFormats/DataRecord/interface/BeamSpotObjectsRcd.h" +#include "CondFormats/DataRecord/interface/BeamSpotOnlineHLTObjectsRcd.h" +#include "CondFormats/DataRecord/interface/BeamSpotOnlineLegacyObjectsRcd.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ServiceRegistry/interface/Service.h" +#include "FWCore/Utilities/interface/InputTag.h" + +// +// class declaration +// + +class BeamSpotOnlineFromOfflineConverter : public edm::one::EDAnalyzer<> { +public: + explicit BeamSpotOnlineFromOfflineConverter(const edm::ParameterSet&); + ~BeamSpotOnlineFromOfflineConverter() override = default; + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + cond::Time_t pack(uint32_t, uint32_t); + +private: + void analyze(const edm::Event&, const edm::EventSetup&) override; + + // ----------member data --------------------------- + const edm::ESGetToken bsToken_; + + // IoV-structure + bool fIsHLT_; + uint32_t fIOVStartRun_; + uint32_t fIOVStartLumi_; + cond::Time_t fnewSince_; + bool fuseNewSince_; + + // parameters that can't be copied from the BeamSpotObject + int lastAnalyzedLumi_, lastAnalyzedRun_, lastAnalyzedFill_; +}; + +// +// constructors and destructor +// +BeamSpotOnlineFromOfflineConverter::BeamSpotOnlineFromOfflineConverter(const edm::ParameterSet& iConfig) + : bsToken_(esConsumes()) { + lastAnalyzedLumi_ = iConfig.getParameter("lastAnalyzedLumi"); + lastAnalyzedRun_ = iConfig.getParameter("lastAnalyzedRun"); + lastAnalyzedFill_ = iConfig.getParameter("lastAnalyzedFill"); + + fIsHLT_ = iConfig.getParameter("isHLT"); + if (iConfig.exists("IOVStartRun") && iConfig.exists("IOVStartLumi")) { + fIOVStartRun_ = iConfig.getUntrackedParameter("IOVStartRun"); + fIOVStartLumi_ = iConfig.getUntrackedParameter("IOVStartLumi"); + fnewSince_ = BeamSpotOnlineFromOfflineConverter::pack(fIOVStartRun_, fIOVStartLumi_); + fuseNewSince_ = true; + edm::LogPrint("BeamSpotOnlineFromOfflineConverter") << "useNewSince = True"; + } else { + fuseNewSince_ = false; + edm::LogPrint("BeamSpotOnlineFromOfflineConverter") << "useNewSince = False"; + } +} + +// +// member functions +// + +// ------------ Create a since object (cond::Time_t) by packing Run and LS (both uint32_t) ------------ +cond::Time_t BeamSpotOnlineFromOfflineConverter::pack(uint32_t fIOVStartRun, uint32_t fIOVStartLumi) { + return ((uint64_t)fIOVStartRun << 32 | fIOVStartLumi); +} + +// ------------ method called for each event ------------ +void BeamSpotOnlineFromOfflineConverter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { + const std::string fLabel = (fIsHLT_) ? "BeamSpotOnlineHLTObjectsRcd" : "BeamSpotOnlineLegacyObjectsRcd"; + const BeamSpotObjects* inputSpot = &iSetup.getData(bsToken_); + + BeamSpotOnlineObjects abeam; + + abeam.setLastAnalyzedLumi(lastAnalyzedLumi_); + abeam.setLastAnalyzedRun(lastAnalyzedRun_); + abeam.setLastAnalyzedFill(lastAnalyzedFill_); + abeam.setStartTimeStamp(std::time(nullptr)); + abeam.setEndTimeStamp(std::time(nullptr)); + abeam.setType(inputSpot->beamType()); + abeam.setPosition(inputSpot->x(), inputSpot->y(), inputSpot->z()); + abeam.setSigmaZ(inputSpot->sigmaZ()); + abeam.setdxdz(inputSpot->dxdz()); + abeam.setdydz(inputSpot->dydz()); + abeam.setBeamWidthX(inputSpot->beamWidthX()); + abeam.setBeamWidthY(inputSpot->beamWidthY()); + abeam.setEmittanceX(inputSpot->emittanceX()); + abeam.setEmittanceY(inputSpot->emittanceY()); + abeam.setBetaStar(inputSpot->betaStar()); + + for (int i = 0; i < 7; ++i) { + for (int j = 0; j < 7; ++j) { + abeam.setCovariance(i, j, inputSpot->covariance(i, j)); + } + } + + // Set the creation time of the payload to the current time + auto creationTime = + std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + abeam.setCreationTime(creationTime); + + edm::LogPrint("BeamSpotOnlineFromOfflineConverter") << " Writing results to DB..."; + + edm::Service poolDbService; + if (poolDbService.isAvailable()) { + edm::LogPrint("BeamSpotOnlineFromOfflineConverter") << "poolDBService available"; + if (poolDbService->isNewTagRequest(fLabel)) { + edm::LogPrint("BeamSpotOnlineFromOfflineConverter") << "new tag requested"; + if (fuseNewSince_) { + edm::LogPrint("BeamSpotOnlineFromOfflineConverter") << "Using a new Since: " << fnewSince_; + poolDbService->createOneIOV(abeam, fnewSince_, fLabel); + } else + poolDbService->createOneIOV(abeam, poolDbService->beginOfTime(), fLabel); + } else { + edm::LogPrint("BeamSpotOnlineFromOfflineConverter") << "no new tag requested"; + if (fuseNewSince_) { + edm::LogPrint("BeamSpotOnlineFromOfflineConverter") << "Using a new Since: " << fnewSince_; + poolDbService->appendOneIOV(abeam, fnewSince_, fLabel); + } else + poolDbService->appendOneIOV(abeam, poolDbService->currentTime(), fLabel); + } + } + edm::LogPrint("BeamSpotOnlineFromOfflineConverter") << "[BeamSpotOnlineFromOfflineConverter] endJob done \n"; +} + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void BeamSpotOnlineFromOfflineConverter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.add("isHLT", true); + desc.addOptionalUntracked("IOVStartRun", 1); + desc.addOptionalUntracked("IOVStartLumi", 1); + desc.add("lastAnalyzedLumi", 1000); + desc.add("lastAnalyzedRun", 1); + desc.add("lastAnalyzedFill", -999); + descriptions.addWithDefaultLabel(desc); +} + +//define this as a plug-in +DEFINE_FWK_MODULE(BeamSpotOnlineFromOfflineConverter); diff --git a/CondTools/BeamSpot/test/BeamSpotOnlineFromOfflineConverter_cfg.py b/CondTools/BeamSpot/test/BeamSpotOnlineFromOfflineConverter_cfg.py new file mode 100644 index 0000000000000..84361db367bbd --- /dev/null +++ b/CondTools/BeamSpot/test/BeamSpotOnlineFromOfflineConverter_cfg.py @@ -0,0 +1,101 @@ +import FWCore.ParameterSet.Config as cms +import FWCore.ParameterSet.VarParsing as VarParsing + +process = cms.Process("READ") + +options = VarParsing.VarParsing() +options.register('unitTest', + False, # default value + VarParsing.VarParsing.multiplicity.singleton, # singleton or list + VarParsing.VarParsing.varType.bool, # string, int, or float + "are we running the unit test?") +options.register('inputTag', + "myTagName", # default value + VarParsing.VarParsing.multiplicity.singleton, # singleton or list + VarParsing.VarParsing.varType.string, # string, int, or float + "output tag name") +options.register('inputRecord', + "BeamSpotOnlineLegacyObjectsRcd", # default value + VarParsing.VarParsing.multiplicity.singleton, # singleton or list + VarParsing.VarParsing.varType.string, # string, int, or float + "type of record") +options.register('startRun', + 1, # default value + VarParsing.VarParsing.multiplicity.singleton, # singleton or list + VarParsing.VarParsing.varType.int, # string, int, or float + "location of the input data") +options.register('startLumi', + 1, # default value + VarParsing.VarParsing.multiplicity.singleton, # singleton or list + VarParsing.VarParsing.varType.int, # string, int, or float + "IOV Start Lumi") +options.parseArguments() + +process.load("FWCore.MessageService.MessageLogger_cfi") +process.MessageLogger.cerr.FwkReport.reportEvery = 100000 # do not clog output with IO + +process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(1)) + +#################################################################### +# Empty source +#################################################################### +process.source = cms.Source("EmptySource", + firstRun = cms.untracked.uint32(options.startRun), + firstLuminosityBlock = cms.untracked.uint32(options.startLumi), + numberEventsInLuminosityBlock = cms.untracked.uint32(1), + numberEventsInRun = cms.untracked.uint32(1)) + +#################################################################### +# Connect to conditions DB +#################################################################### + +# either from Global Tag +process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") +from Configuration.AlCa.GlobalTag import GlobalTag +process.GlobalTag = GlobalTag(process.GlobalTag,"auto:phase2_realistic") + +# ...or specify database connection and tag: +#from CondCore.CondDB.CondDB_cfi import * +#CondDBBeamSpotObjects = CondDB.clone(connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS')) +#process.dbInput = cms.ESSource("PoolDBESSource", +# CondDBBeamSpotObjects, +# toGet = cms.VPSet(cms.PSet(record = cms.string('BeamSpotOnlineLegacyObjectsRcd'), # BeamSpotOnlineLegacy record +# tag = cms.string('BSLegacy_tag') # choose your favourite tag +# ) +# ) +# ) +# ...or from a local db file +# input database (in this case the local sqlite file) + +#################################################################### +# Load and configure outputservice +#################################################################### +if options.unitTest : + if options.inputRecord == "BeamSpotOnlineLegacyObjectsRcd" : + tag_name = 'BSLegacy_tag' + else: + tag_name = 'BSHLT_tag' +else: + tag_name = options.inputTag + +from CondCore.CondDB.CondDB_cfi import * +CondDBBeamSpotObjects = CondDB.clone(connect = cms.string('sqlite_file:test_%s.db' % tag_name)) # choose an output name +process.PoolDBOutputService = cms.Service("PoolDBOutputService", + CondDBBeamSpotObjects, + timetype = cms.untracked.string('lumiid'), #('lumiid'), #('runnumber') + toPut = cms.VPSet(cms.PSet(record = cms.string(options.inputRecord), # BeamSpotOnline record + tag = cms.string(tag_name))), # choose your favourite tag + loadBlobStreamer = cms.untracked.bool(False) + ) + +isForHLT = (options.inputRecord == "BeamSpotOnlineHLTObjectsRcd") +print("isForHLT: ",isForHLT) + +#################################################################### +# Load and configure analyzer +#################################################################### +from CondTools.BeamSpot.beamSpotOnlineFromOfflineConverter_cfi import beamSpotOnlineFromOfflineConverter +process.BeamSpotOnlineFromOfflineConverter = beamSpotOnlineFromOfflineConverter.clone(isHLT = isForHLT) + +# Put module in path: +process.p = cms.Path(process.BeamSpotOnlineFromOfflineConverter) From 6f1912eae5366630cd0543e704bf3c236fa16b47 Mon Sep 17 00:00:00 2001 From: mmusich Date: Sat, 6 May 2023 22:06:32 +0200 Subject: [PATCH 3/5] add a method to copy parameters from BeamSpotObjects into BeamSpotOnlineObjects --- .../interface/BeamSpotOnlineObjects.h | 5 +++- .../src/BeamSpotOnlineObjects.cc | 23 ++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CondFormats/BeamSpotObjects/interface/BeamSpotOnlineObjects.h b/CondFormats/BeamSpotObjects/interface/BeamSpotOnlineObjects.h index 3a6f171a4ddc1..91765287a5377 100644 --- a/CondFormats/BeamSpotObjects/interface/BeamSpotOnlineObjects.h +++ b/CondFormats/BeamSpotObjects/interface/BeamSpotOnlineObjects.h @@ -44,6 +44,9 @@ class BeamSpotOnlineObjects : public BeamSpotObjects { enum TimeParamIndex { CREATE_TIME = 0, START_TIMESTAMP = 1, END_TIMESTAMP = 2, TSIZE = 3 }; /// Setters Methods + // copy all copiable members from BeamSpotObjects + void copyFromBeamSpotObject(const BeamSpotObjects& bs); + // set lastAnalyzedLumi_, last analyzed lumisection void setLastAnalyzedLumi(int val) { lastAnalyzedLumi_ = val; } @@ -164,4 +167,4 @@ class BeamSpotOnlineObjects : public BeamSpotObjects { std::ostream& operator<<(std::ostream&, BeamSpotOnlineObjects beam); -#endif \ No newline at end of file +#endif diff --git a/CondFormats/BeamSpotObjects/src/BeamSpotOnlineObjects.cc b/CondFormats/BeamSpotObjects/src/BeamSpotOnlineObjects.cc index dfee339cae9e8..9517de935d274 100644 --- a/CondFormats/BeamSpotObjects/src/BeamSpotOnlineObjects.cc +++ b/CondFormats/BeamSpotObjects/src/BeamSpotOnlineObjects.cc @@ -92,6 +92,27 @@ cond::Time_t BeamSpotOnlineObjects::endTimeStamp() const { } // setters +void BeamSpotOnlineObjects::copyFromBeamSpotObject(const BeamSpotObjects& bs) { + setType(bs.beamType()); + setPosition(bs.x(), bs.y(), bs.z()); + setSigmaZ(bs.sigmaZ()); + setdxdz(bs.dxdz()); + setdydz(bs.dydz()); + setBeamWidthX(bs.beamWidthX()); + setBeamWidthY(bs.beamWidthY()); + setBeamWidthXError(bs.beamWidthXError()); + setBeamWidthYError(bs.beamWidthYError()); + setEmittanceX(bs.emittanceX()); + setEmittanceY(bs.emittanceY()); + setBetaStar(bs.betaStar()); + + for (int i = 0; i < 7; ++i) { + for (int j = 0; j < 7; ++j) { + setCovariance(i, j, bs.covariance(i, j)); + } + } +} + void BeamSpotOnlineObjects::setNumTracks(int nTracks) { BeamSpotOnlineObjectsImpl::setOneParam(intParams_, NUM_TRACKS, nTracks); } @@ -173,4 +194,4 @@ std::ostream& operator<<(std::ostream& os, BeamSpotOnlineObjects beam) { beam.print(ss); os << ss.str(); return os; -} \ No newline at end of file +} From 5c011c8a90fbbebd3ac9f7a471538cd6b56123e0 Mon Sep 17 00:00:00 2001 From: mmusich Date: Sat, 6 May 2023 22:07:14 +0200 Subject: [PATCH 4/5] use BeamSpotOnlineObjects::copyFromBeamSpotObject into BeamSpotOnlineFromOfflineConverter --- .../BeamSpotOnlineFromOfflineConverter.cc | 76 ++++++++++++------- 1 file changed, 48 insertions(+), 28 deletions(-) diff --git a/CondTools/BeamSpot/plugins/BeamSpotOnlineFromOfflineConverter.cc b/CondTools/BeamSpot/plugins/BeamSpotOnlineFromOfflineConverter.cc index 18fc03ba9246a..bb2df56d1db45 100644 --- a/CondTools/BeamSpot/plugins/BeamSpotOnlineFromOfflineConverter.cc +++ b/CondTools/BeamSpot/plugins/BeamSpotOnlineFromOfflineConverter.cc @@ -58,27 +58,40 @@ class BeamSpotOnlineFromOfflineConverter : public edm::one::EDAnalyzer<> { // ----------member data --------------------------- const edm::ESGetToken bsToken_; + // parameters that can't be copied from the BeamSpotObject + const int lastAnalyzedLumi_, lastAnalyzedRun_, lastAnalyzedFill_; + const int numTracks_, numPVs_, numUsedEvents_, numMaxPVs_; + const float meanPVs_, meanPVError_, rmsPV_, rmsPVError_; + const std::string startTime_, endTime_, lumiRange_; + // IoV-structure - bool fIsHLT_; + const bool fIsHLT_; uint32_t fIOVStartRun_; uint32_t fIOVStartLumi_; cond::Time_t fnewSince_; bool fuseNewSince_; - - // parameters that can't be copied from the BeamSpotObject - int lastAnalyzedLumi_, lastAnalyzedRun_, lastAnalyzedFill_; }; // // constructors and destructor // BeamSpotOnlineFromOfflineConverter::BeamSpotOnlineFromOfflineConverter(const edm::ParameterSet& iConfig) - : bsToken_(esConsumes()) { - lastAnalyzedLumi_ = iConfig.getParameter("lastAnalyzedLumi"); - lastAnalyzedRun_ = iConfig.getParameter("lastAnalyzedRun"); - lastAnalyzedFill_ = iConfig.getParameter("lastAnalyzedFill"); - - fIsHLT_ = iConfig.getParameter("isHLT"); + : bsToken_(esConsumes()), + lastAnalyzedLumi_(iConfig.getParameter("lastAnalyzedLumi")), + lastAnalyzedRun_(iConfig.getParameter("lastAnalyzedRun")), + lastAnalyzedFill_(iConfig.getParameter("lastAnalyzedFill")), + numTracks_(iConfig.getParameter("numTracks")), + numPVs_(iConfig.getParameter("numPVs")), + numUsedEvents_(iConfig.getParameter("numUsedEvents")), + numMaxPVs_(iConfig.getParameter("numMaxPVs")), + meanPVs_(iConfig.getParameter("meanPVs")), + meanPVError_(iConfig.getParameter("meanPVError")), + rmsPV_(iConfig.getParameter("rmsPVs")), + rmsPVError_(iConfig.getParameter("rmsPVError")), + startTime_(iConfig.getParameter("startTime")), + endTime_(iConfig.getParameter("endTime")), + lumiRange_(iConfig.getParameter("lumiRange")), + fIsHLT_(iConfig.getParameter("isHLT")) { if (iConfig.exists("IOVStartRun") && iConfig.exists("IOVStartLumi")) { fIOVStartRun_ = iConfig.getUntrackedParameter("IOVStartRun"); fIOVStartLumi_ = iConfig.getUntrackedParameter("IOVStartLumi"); @@ -106,28 +119,23 @@ void BeamSpotOnlineFromOfflineConverter::analyze(const edm::Event& iEvent, const const BeamSpotObjects* inputSpot = &iSetup.getData(bsToken_); BeamSpotOnlineObjects abeam; - + abeam.copyFromBeamSpotObject(*inputSpot); abeam.setLastAnalyzedLumi(lastAnalyzedLumi_); abeam.setLastAnalyzedRun(lastAnalyzedRun_); abeam.setLastAnalyzedFill(lastAnalyzedFill_); abeam.setStartTimeStamp(std::time(nullptr)); abeam.setEndTimeStamp(std::time(nullptr)); - abeam.setType(inputSpot->beamType()); - abeam.setPosition(inputSpot->x(), inputSpot->y(), inputSpot->z()); - abeam.setSigmaZ(inputSpot->sigmaZ()); - abeam.setdxdz(inputSpot->dxdz()); - abeam.setdydz(inputSpot->dydz()); - abeam.setBeamWidthX(inputSpot->beamWidthX()); - abeam.setBeamWidthY(inputSpot->beamWidthY()); - abeam.setEmittanceX(inputSpot->emittanceX()); - abeam.setEmittanceY(inputSpot->emittanceY()); - abeam.setBetaStar(inputSpot->betaStar()); - - for (int i = 0; i < 7; ++i) { - for (int j = 0; j < 7; ++j) { - abeam.setCovariance(i, j, inputSpot->covariance(i, j)); - } - } + abeam.setNumTracks(numTracks_); + abeam.setNumPVs(numPVs_); + abeam.setUsedEvents(numUsedEvents_); + abeam.setMaxPVs(numMaxPVs_); + abeam.setMeanPV(meanPVs_); + abeam.setMeanErrorPV(meanPVError_); + abeam.setRmsPV(rmsPV_); + abeam.setRmsErrorPV(rmsPVError_); + abeam.setStartTime(startTime_); + abeam.setEndTime(endTime_); + abeam.setLumiRange(lumiRange_); // Set the creation time of the payload to the current time auto creationTime = @@ -135,6 +143,7 @@ void BeamSpotOnlineFromOfflineConverter::analyze(const edm::Event& iEvent, const abeam.setCreationTime(creationTime); edm::LogPrint("BeamSpotOnlineFromOfflineConverter") << " Writing results to DB..."; + edm::LogPrint("BeamSpotOnlineFromOfflineConverter") << abeam; edm::Service poolDbService; if (poolDbService.isAvailable()) { @@ -155,7 +164,7 @@ void BeamSpotOnlineFromOfflineConverter::analyze(const edm::Event& iEvent, const poolDbService->appendOneIOV(abeam, poolDbService->currentTime(), fLabel); } } - edm::LogPrint("BeamSpotOnlineFromOfflineConverter") << "[BeamSpotOnlineFromOfflineConverter] endJob done \n"; + edm::LogPrint("BeamSpotOnlineFromOfflineConverter") << "[BeamSpotOnlineFromOfflineConverter] analyze done \n"; } // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ @@ -167,6 +176,17 @@ void BeamSpotOnlineFromOfflineConverter::fillDescriptions(edm::ConfigurationDesc desc.add("lastAnalyzedLumi", 1000); desc.add("lastAnalyzedRun", 1); desc.add("lastAnalyzedFill", -999); + desc.add("numTracks", 0); + desc.add("numPVs", 0); + desc.add("numUsedEvents", 0); + desc.add("numMaxPVs", 0); + desc.add("meanPVs", 0.); + desc.add("meanPVError", 0.); + desc.add("rmsPVs", 0.); + desc.add("rmsPVError", 0.); + desc.add("startTime", std::string("")); + desc.add("endTime", std::string("")); + desc.add("lumiRange", std::string("")); descriptions.addWithDefaultLabel(desc); } From 991186be170060dbee10ee3b6912b247fce9fba4 Mon Sep 17 00:00:00 2001 From: mmusich Date: Sun, 7 May 2023 11:29:53 +0200 Subject: [PATCH 5/5] add BeamSpotOnlineFromOfflineConverter_cfg.py to package unit tests --- CondTools/BeamSpot/test/testReadWriteOnlineBSFromDB.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CondTools/BeamSpot/test/testReadWriteOnlineBSFromDB.sh b/CondTools/BeamSpot/test/testReadWriteOnlineBSFromDB.sh index 0ae82bd5977e3..55a4939c547dc 100755 --- a/CondTools/BeamSpot/test/testReadWriteOnlineBSFromDB.sh +++ b/CondTools/BeamSpot/test/testReadWriteOnlineBSFromDB.sh @@ -30,5 +30,9 @@ cmsRun ${LOCAL_TEST_DIR}/BeamSpotOnlineRecordsReader_cfg.py unitTest=True inputR printf "TESTING Reading BeamSpotOnlineHLTObjectsRcd DB object ...\n\n" cmsRun ${LOCAL_TEST_DIR}/BeamSpotOnlineRecordsReader_cfg.py unitTest=True inputRecord=BeamSpotOnlineHLTObjectsRcd || die "Failure reading payload for BeamSpotOnlineHLTObjectsRcd" $? -echo "TESTING reading BeamSpotObjectRcd DB object ...\n\n" +printf "TESTING reading BeamSpotObjectRcd DB object ...\n\n" cmsRun ${LOCAL_TEST_DIR}/BeamSpotRcdPrinter_cfg.py || die "Failure running BeamSpotRcdPrinter" $? + +printf "TESTING converting BeamSpotOnlineObjects from BeamSpotObjects ...\n\n" +cmsRun ${LOCAL_TEST_DIR}/BeamSpotOnlineFromOfflineConverter_cfg.py unitTest=True || die "Failure running BeamSpotRcdPrinter" $? +