-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41674 from mmusich/13_0_X_useFakeBSasFallBackInOn…
…lineProducer2 [13.0.X] Produce a fake `BeamSpot` object in `BeamSpotOnlineProducer` when using transient record logic and `OnlineBeamSpotESProducer` returned a fake
- Loading branch information
Showing
6 changed files
with
353 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
194 changes: 194 additions & 0 deletions
194
CondTools/BeamSpot/plugins/BeamSpotOnlineFromOfflineConverter.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
// -*- 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 <memory> | ||
#include <string> | ||
#include <fstream> | ||
#include <iostream> | ||
#include <ctime> | ||
|
||
// 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<BeamSpotObjects, BeamSpotObjectsRcd> 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 | ||
const bool fIsHLT_; | ||
uint32_t fIOVStartRun_; | ||
uint32_t fIOVStartLumi_; | ||
cond::Time_t fnewSince_; | ||
bool fuseNewSince_; | ||
}; | ||
|
||
// | ||
// constructors and destructor | ||
// | ||
BeamSpotOnlineFromOfflineConverter::BeamSpotOnlineFromOfflineConverter(const edm::ParameterSet& iConfig) | ||
: bsToken_(esConsumes()), | ||
lastAnalyzedLumi_(iConfig.getParameter<double>("lastAnalyzedLumi")), | ||
lastAnalyzedRun_(iConfig.getParameter<double>("lastAnalyzedRun")), | ||
lastAnalyzedFill_(iConfig.getParameter<double>("lastAnalyzedFill")), | ||
numTracks_(iConfig.getParameter<int>("numTracks")), | ||
numPVs_(iConfig.getParameter<int>("numPVs")), | ||
numUsedEvents_(iConfig.getParameter<int>("numUsedEvents")), | ||
numMaxPVs_(iConfig.getParameter<int>("numMaxPVs")), | ||
meanPVs_(iConfig.getParameter<double>("meanPVs")), | ||
meanPVError_(iConfig.getParameter<double>("meanPVError")), | ||
rmsPV_(iConfig.getParameter<double>("rmsPVs")), | ||
rmsPVError_(iConfig.getParameter<double>("rmsPVError")), | ||
startTime_(iConfig.getParameter<std::string>("startTime")), | ||
endTime_(iConfig.getParameter<std::string>("endTime")), | ||
lumiRange_(iConfig.getParameter<std::string>("lumiRange")), | ||
fIsHLT_(iConfig.getParameter<bool>("isHLT")) { | ||
if (iConfig.exists("IOVStartRun") && iConfig.exists("IOVStartLumi")) { | ||
fIOVStartRun_ = iConfig.getUntrackedParameter<uint32_t>("IOVStartRun"); | ||
fIOVStartLumi_ = iConfig.getUntrackedParameter<uint32_t>("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.copyFromBeamSpotObject(*inputSpot); | ||
abeam.setLastAnalyzedLumi(lastAnalyzedLumi_); | ||
abeam.setLastAnalyzedRun(lastAnalyzedRun_); | ||
abeam.setLastAnalyzedFill(lastAnalyzedFill_); | ||
abeam.setStartTimeStamp(std::time(nullptr)); | ||
abeam.setEndTimeStamp(std::time(nullptr)); | ||
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 = | ||
std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count(); | ||
abeam.setCreationTime(creationTime); | ||
|
||
edm::LogPrint("BeamSpotOnlineFromOfflineConverter") << " Writing results to DB..."; | ||
edm::LogPrint("BeamSpotOnlineFromOfflineConverter") << abeam; | ||
|
||
edm::Service<cond::service::PoolDBOutputService> 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<BeamSpotOnlineObjects>(abeam, fnewSince_, fLabel); | ||
} else | ||
poolDbService->createOneIOV<BeamSpotOnlineObjects>(abeam, poolDbService->beginOfTime(), fLabel); | ||
} else { | ||
edm::LogPrint("BeamSpotOnlineFromOfflineConverter") << "no new tag requested"; | ||
if (fuseNewSince_) { | ||
edm::LogPrint("BeamSpotOnlineFromOfflineConverter") << "Using a new Since: " << fnewSince_; | ||
poolDbService->appendOneIOV<BeamSpotOnlineObjects>(abeam, fnewSince_, fLabel); | ||
} else | ||
poolDbService->appendOneIOV<BeamSpotOnlineObjects>(abeam, poolDbService->currentTime(), fLabel); | ||
} | ||
} | ||
edm::LogPrint("BeamSpotOnlineFromOfflineConverter") << "[BeamSpotOnlineFromOfflineConverter] analyze done \n"; | ||
} | ||
|
||
// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ | ||
void BeamSpotOnlineFromOfflineConverter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { | ||
edm::ParameterSetDescription desc; | ||
desc.add<bool>("isHLT", true); | ||
desc.addOptionalUntracked<uint32_t>("IOVStartRun", 1); | ||
desc.addOptionalUntracked<uint32_t>("IOVStartLumi", 1); | ||
desc.add<double>("lastAnalyzedLumi", 1000); | ||
desc.add<double>("lastAnalyzedRun", 1); | ||
desc.add<double>("lastAnalyzedFill", -999); | ||
desc.add<int>("numTracks", 0); | ||
desc.add<int>("numPVs", 0); | ||
desc.add<int>("numUsedEvents", 0); | ||
desc.add<int>("numMaxPVs", 0); | ||
desc.add<double>("meanPVs", 0.); | ||
desc.add<double>("meanPVError", 0.); | ||
desc.add<double>("rmsPVs", 0.); | ||
desc.add<double>("rmsPVError", 0.); | ||
desc.add<std::string>("startTime", std::string("")); | ||
desc.add<std::string>("endTime", std::string("")); | ||
desc.add<std::string>("lumiRange", std::string("")); | ||
descriptions.addWithDefaultLabel(desc); | ||
} | ||
|
||
//define this as a plug-in | ||
DEFINE_FWK_MODULE(BeamSpotOnlineFromOfflineConverter); |
101 changes: 101 additions & 0 deletions
101
CondTools/BeamSpot/test/BeamSpotOnlineFromOfflineConverter_cfg.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.