Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[90X] AlCaRecoTriggerBits updates #17568

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions CondTools/HLT/python/AlCaRecoTriggerBitsRcdUpdate_cfi.py
Expand Up @@ -22,6 +22,14 @@
cms.PSet(listName = cms.string('TkAlMinBias'),
hltPaths = cms.vstring('path_1', 'path_3')
)
)

),

alcarecoToReplace = cms.VPSet(
cms.PSet(oldKey = cms.string('TkAlZMuMu'),
newKey = cms.string('testKey1')
),
cms.PSet(oldKey = cms.string('TkAlMinBias'),
newKey = cms.string('testKey2')
)
)
)
37 changes: 36 additions & 1 deletion CondTools/HLT/src/AlCaRecoTriggerBitsRcdUpdate.cc
Expand Up @@ -40,6 +40,8 @@ class AlCaRecoTriggerBitsRcdUpdate : public edm::EDAnalyzer {
typedef std::map<std::string, std::string> TriggerMap;
AlCaRecoTriggerBits* createStartTriggerBits(bool startEmpty, const edm::EventSetup& evtSetup) const;
bool removeKeysFromMap(const std::vector<std::string> &keys, TriggerMap &triggerMap) const;
bool replaceKeysFromMap(const std::vector<edm::ParameterSet> &alcarecoReplace,
TriggerMap &triggerMap) const;
bool addTriggerLists(const std::vector<edm::ParameterSet> &triggerListsAdd,
AlCaRecoTriggerBits &bits) const;
/// Takes over memory uresponsibility for 'bitsToWrite'.
Expand All @@ -51,6 +53,7 @@ class AlCaRecoTriggerBitsRcdUpdate : public edm::EDAnalyzer {
const bool startEmpty_;
const std::vector<std::string> listNamesRemove_;
const std::vector<edm::ParameterSet> triggerListsAdd_;
const std::vector<edm::ParameterSet> alcarecoReplace_;
};

///////////////////////////////////////////////////////////////////////
Expand All @@ -63,7 +66,8 @@ AlCaRecoTriggerBitsRcdUpdate::AlCaRecoTriggerBitsRcdUpdate(const edm::ParameterS
lastRunIOV_(cfg.getParameter<int>("lastRunIOV")),
startEmpty_(cfg.getParameter<bool>("startEmpty")),
listNamesRemove_(cfg.getParameter<std::vector<std::string> >("listNamesRemove")),
triggerListsAdd_(cfg.getParameter<std::vector<edm::ParameterSet> >("triggerListsAdd"))
triggerListsAdd_(cfg.getParameter<std::vector<edm::ParameterSet> >("triggerListsAdd")),
alcarecoReplace_(cfg.getParameter<std::vector<edm::ParameterSet> >("alcarecoToReplace"))
{
}

Expand All @@ -87,6 +91,9 @@ void AlCaRecoTriggerBitsRcdUpdate::analyze(const edm::Event& evt, const edm::Eve
// now add new entries
this->addTriggerLists(triggerListsAdd_, *bitsToWrite);

// now replace keys
this->replaceKeysFromMap(alcarecoReplace_,bitsToWrite->m_alcarecoToTrig);

// finally write to DB
this->writeBitsToDB(bitsToWrite);

Expand Down Expand Up @@ -128,6 +135,34 @@ bool AlCaRecoTriggerBitsRcdUpdate::removeKeysFromMap(const std::vector<std::stri
return true;
}

///////////////////////////////////////////////////////////////////////
bool AlCaRecoTriggerBitsRcdUpdate::replaceKeysFromMap(const std::vector<edm::ParameterSet> &alcarecoReplace,
TriggerMap &triggerMap) const
{

std::vector<std::pair<std::string,std::string> > keyPairs;

for(auto &iSet : alcarecoReplace ){
const std::string oldKey(iSet.getParameter<std::string>("oldKey"));
const std::string newKey(iSet.getParameter<std::string>("newKey"));
keyPairs.push_back(std::make_pair(oldKey,newKey));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmusich - please reserve the size of keyPairs. It is known in this case.

}

for(auto& iKey : keyPairs){
if(triggerMap.find(iKey.first) != triggerMap.end() ){
std::string bitsToReplace = triggerMap[iKey.first];
triggerMap.erase(iKey.first);
triggerMap[iKey.second] = bitsToReplace;
} else { // not in list ==> misconfiguration!
edm::LogWarning("AlCaRecoTriggerBitsRcdUpdate") << "[AlCaRecoTriggerBitsRcdUpdate::replaceKeysFromMap] "
<< "Cannot replace key '" << iKey.first << "with " << iKey.second << " since not in "
<< "list - typo in configuration?\n";
return false;
}
}
return true;
}

///////////////////////////////////////////////////////////////////////
bool AlCaRecoTriggerBitsRcdUpdate::addTriggerLists(const std::vector<edm::ParameterSet> &triggerListsAdd,
AlCaRecoTriggerBits &bits) const
Expand Down
70 changes: 70 additions & 0 deletions CondTools/HLT/test/AlCaRecoTriggerBitsRcdRead_TEMPL_cfg.py
@@ -0,0 +1,70 @@
import FWCore.ParameterSet.Config as cms
import FWCore.ParameterSet.VarParsing as VarParsing

process = cms.Process("READ")

options = VarParsing.VarParsing()
options.register( "inputDB",
"frontier://FrontierProd/CMS_CONDITIONS", #default value
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.string,
"the input DB"
)

options.register( "inputTag",
"AlCaRecoHLTpaths8e29_1e31_v7_hlt", #default value
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.string,
"the input tag"
)

options.parseArguments()


process.load("FWCore.MessageLogger.MessageLogger_cfi")
process.MessageLogger.cerr = cms.untracked.PSet(placeholder = cms.untracked.bool(True))
process.MessageLogger.cout = cms.untracked.PSet(INFO = cms.untracked.PSet(
reportEvery = cms.untracked.int32(1000)
))

# the module writing to DB
process.load("CondTools.HLT.AlCaRecoTriggerBitsRcdRead_cfi")
# 'twiki' is default - others are text, python (future: html?)
#process.AlCaRecoTriggerBitsRcdRead.outputType = 'twiki'
# If rawFileName stays empty (default), use the message logger for output.
# Otherwise use the file name specified, adding a suffix according to outputType:
process.AlCaRecoTriggerBitsRcdRead.rawFileName = 'triggerBits'+options.inputTag

# No data, but might want to specify the 'firstRun' to check (default is 1):
process.source = cms.Source("EmptySource",
numberEventsInRun = cms.untracked.uint32(1), # do not change!
firstRun = cms.untracked.uint32(1)
)
# With 'numberEventsInRun = 1' above,
# this will check IOVs until run (!) number specified as 'input' here,
# so take care to choose a one that is not too small...:
process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(500000) )

# Input for AlCaRecoTriggerBitsRcd,
# either via GlobalTag
# (loading of Configuration.StandardSequences.CondDBESSource_cff equivalent to CondCore.ESSources.CondDBESSource_cfi
# as entry point for condition records in the EventSetup,
# but sufficient and faster than Configuration.StandardSequences.FrontierConditions_GlobalTag_cff):
#from Configuration.AlCa.autoCond import autoCond
#process.load("Configuration.StandardSequences.CondDBESSource_cff")
#process.GlobalTag.globaltag = autoCond['run2_data'] #choose your tag

# ...or specify database and tag:
from CondCore.CondDB.CondDB_cfi import *
#CondDBTriggerBits = CondDB.clone(connect = cms.string('frontier://FrontierProd/CMS_COND_31X_HLT'))
CondDBTriggerBits = CondDB.clone(connect = cms.string(options.inputDB))
process.dbInput = cms.ESSource("PoolDBESSource",
CondDBTriggerBits,
toGet = cms.VPSet(cms.PSet(record = cms.string('AlCaRecoTriggerBitsRcd'),
tag = cms.string(options.inputTag) # choose tag you want
)
)
)

# Put module in path:
process.p = cms.Path(process.AlCaRecoTriggerBitsRcdRead)
2 changes: 1 addition & 1 deletion CondTools/HLT/test/AlCaRecoTriggerBitsRcdRead_cfg.py
Expand Up @@ -24,7 +24,7 @@
# With 'numberEventsInRun = 1' above,
# this will check IOVs until run (!) number specified as 'input' here,
# so take care to choose a one that is not too small...:
process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(250000) )
process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(350000) )

# Input for AlCaRecoTriggerBitsRcd,
# either via GlobalTag
Expand Down
136 changes: 136 additions & 0 deletions CondTools/HLT/test/AlCaRecoTriggerBitsRcdUpdate_TEMPL_cfg.py
@@ -0,0 +1,136 @@
# Config file template to write new/update AlCaRecoTriggerBits stored
# in AlCaRecoTriggerBitsRcd that is used to get selected HLT paths for
# the HLTHighLevel filter for AlCaReco production.
#
# Please understand that there are two IOVs involved:
# 1) One for the output tag. Here the usually used default is 1->inf,
# changed by process.AlCaRecoTriggerBitsRcdUpdate.firstRunIOV
# and process.AlCaRecoTriggerBitsRcdUpdate.lastRunIOV.
# 2) The IOV of the tag of the input AlCaRecoTriggerBitsRcd.
# That is chosen by process.source.firstRun (but irrelevant if
# process.AlCaRecoTriggerBitsRcdUpdate.startEmpty = True)
#
# See also further comments below, especially the WARNING.
#
# Author : Marco Musich
# Date : Feb 2016

import FWCore.ParameterSet.Config as cms
import FWCore.ParameterSet.VarParsing as VarParsing

process = cms.Process("UPDATEDB")

options = VarParsing.VarParsing()
options.register( "inputDB",
"frontier://FrontierProd/CMS_CONDITIONS", #default value
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.string,
"the input DB"
)

options.register( "inputTag",
"AlCaRecoHLTpaths8e29_1e31_v7_hlt", #default value
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.string,
"the input tag"
)

options.register( "outputDB",
"sqlite_file:AlCaRecoTriggerBits.db", #default value
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.string,
"the output DB"
)

options.register( "outputTag",
"testTag", #default value
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.string,
"the input DB"
)

options.register( "firstRun",
1, #default value
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.int,
"the first run"
)

options.parseArguments()

process.load("FWCore.MessageLogger.MessageLogger_cfi")
process.MessageLogger.cerr = cms.untracked.PSet(placeholder = cms.untracked.bool(True))
process.MessageLogger.cout = cms.untracked.PSet(INFO = cms.untracked.PSet(
reportEvery = cms.untracked.int32(1)
))

# the module writing to DB
process.load("CondTools.HLT.AlCaRecoTriggerBitsRcdUpdate_cfi")
# The IOV that you want to write out, defaut is 1 to -1/inf.
process.AlCaRecoTriggerBitsRcdUpdate.firstRunIOV = options.firstRun # docu see...
#process.AlCaRecoTriggerBitsRcdUpdate.lastRunIOV = -1 # ...cfi
# If you want to start from scratch, comment the next line:
process.AlCaRecoTriggerBitsRcdUpdate.startEmpty = False
# In case you want to remove 'keys', use this possibly comma separated list.
# Also if you want to replace settings for one 'key', you have to remove it first.
#process.AlCaRecoTriggerBitsRcdUpdate.listNamesRemove = ["SiStripCalZeroBias"]
# Here specifiy 'key' and corresponding paths for new entries or updated ones:
# process.AlCaRecoTriggerBitsRcdUpdate.triggerListsAdd = [
# cms.PSet(listName = cms.string('AlCaEcalTrg'), # to be updated
# hltPaths = cms.vstring('AlCa_EcalPhiSym*')
# )
# ]

process.AlCaRecoTriggerBitsRcdUpdate.triggerListsAdd = []
process.AlCaRecoTriggerBitsRcdUpdate.alcarecoToReplace = [
cms.PSet(oldKey = cms.string('SiStripCalMinBiasAfterAbortGap'),
newKey = cms.string('SiStripCalMinBiasAAG')
)
]

# No data, but have to specify run number if you do not want 1, see below:
process.source = cms.Source("EmptySource",
#numberEventsInRun = cms.untracked.uint32(1),
firstRun = cms.untracked.uint32(options.firstRun) # 1 is default
)
process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(1) )

# DB input - needed only for AlCaRecoTriggerBitsRcdUpdate.startEmpty = False
# WARNING:
# Take care in case the input tag has several IOVs: The run number that will be
# used to define which payload you get is defined by the run number in the
# EmptySource above!
# Either a global tag...
# from Configuration.AlCa.autoCond import autoCond
# process.load("Configuration.StandardSequences.CondDBESSource_cff")
# process.GlobalTag.globaltag = autoCond['run2_data'] #choose your tag

# ...or (recommended since simpler) directly from DB/sqlite

process.load("CondCore.CondDB.CondDB_cfi")

# DB input service:
process.CondDB.connect = options.inputDB
process.dbInput = cms.ESSource("PoolDBESSource",
process.CondDB,
toGet = cms.VPSet(cms.PSet(record = cms.string('AlCaRecoTriggerBitsRcd'),
tag = cms.string(options.inputTag)
)
)
)

# DB output service:
process.CondDB.connect = options.outputDB
process.PoolDBOutputService = cms.Service("PoolDBOutputService",
process.CondDB,
timetype = cms.untracked.string('runnumber'),
toPut = cms.VPSet(cms.PSet(record = cms.string('AlCaRecoTriggerBitsRcd'),
tag = cms.string(options.outputTag) # choose output tag you want
)
)
)

# Put module in path:
process.p = cms.Path(process.AlCaRecoTriggerBitsRcdUpdate)


43 changes: 24 additions & 19 deletions CondTools/HLT/test/AlCaRecoTriggerBitsRcdUpdate_cfg.py
Expand Up @@ -48,6 +48,9 @@
hltPaths = cms.vstring())
]

# Here specify the 'keys' to be replaced
process.AlCaRecoTriggerBitsRcdUpdate.alcarecoToReplace = []

# No data, but have to specify run number if you do not want 1, see below:
process.source = cms.Source("EmptySource",
#numberEventsInRun = cms.untracked.uint32(1),
Expand All @@ -62,38 +65,40 @@
# EmptySource above!
# Either a global tag...
#process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
# process.GlobalTag.globaltag = "DESIGN_3X_V13::All" # may choose non-default tag
# process.GlobalTag.globaltag = "90X_dataRun2_Express_v0" # may choose non-default tag
# ...or (recommended since simpler) directly from DB/sqlite
import CondCore.DBCommon.CondDBSetup_cfi

process.load("CondCore.CondDB.CondDB_cfi")

# from local sqlite file
#process.CondDB.connect = 'sqlite_file:AlCaRecoTriggerBits.db'
# from conditons Database
process.CondDB.connect = 'frontier://FrontierProd/CMS_CONDITIONS'

process.dbInput = cms.ESSource(
"PoolDBESSource",
CondCore.DBCommon.CondDBSetup_cfi.CondDBSetup,
# connect = cms.string('sqlite_file:AlCaRecoTriggerBits.db'),
connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS'),
toGet = cms.VPSet(cms.PSet(
record = cms.string('AlCaRecoTriggerBitsRcd'),
# tag = cms.string('TestTag') # choose tag to update
tag = cms.string('AlCaRecoHLTpaths8e29_1e31_v7_hlt')
)
process.CondDB,
toGet = cms.VPSet(cms.PSet(record = cms.string('AlCaRecoTriggerBitsRcd'),
# tag = cms.string('TestTag') # choose tag to update
tag = cms.string('AlCaRecoHLTpaths8e29_1e31_v7_hlt')
)
)
)

# DB output service:
import CondCore.DBCommon.CondDBSetup_cfi
process.CondDB.connect = 'sqlite_file:AlCaRecoTriggerBits.db'
#process.CondDB.connect = 'sqlite_file:AlCaRecoTriggerBitsUpdate.db'

process.PoolDBOutputService = cms.Service(
"PoolDBOutputService",
CondCore.DBCommon.CondDBSetup_cfi.CondDBSetup,
process.CondDB,
timetype = cms.untracked.string('runnumber'),
connect = cms.string('sqlite_file:AlCaRecoTriggerBits.db'),
# connect = cms.string('sqlite_file:AlCaRecoTriggerBitsUpdate.db'),
toPut = cms.VPSet(cms.PSet(
record = cms.string('AlCaRecoTriggerBitsRcd'),
tag = cms.string('TestTag') # choose output tag you want
)
toPut = cms.VPSet(cms.PSet(record = cms.string('AlCaRecoTriggerBitsRcd'),
tag = cms.string('TestTag') # choose output tag you want
)
)
)


# Put module in path:
process.p = cms.Path(process.AlCaRecoTriggerBitsRcdUpdate)

Expand Down
20 changes: 20 additions & 0 deletions CondTools/HLT/test/README.md
@@ -0,0 +1,20 @@
Commands to run the workflow multi-IOV:

## TO UPDATE
```
python run_wf.py -f frontier://PromptProd/CMS_CONDITIONS -i AlCaRecoHLTpaths8e29_1e31_v24_offline -d AlCaRecoHLTpaths_TEST
```

will create an update sqlite file called `AlCaRecoHLTpaths_TEST.db` with an updated tag ` AlCaRecoHLTpaths_TEST` (the same IOV structure will be preserved)

Options available:
* `-f` specifies connection (allows both condDB and sqlite files)
* `-i` specifies input tag
* `-d` specifies the output tag
* `[-C]` (optional) if set to false leaves transient files IOV-by-IOV


## TO READ BACK
```
cmsRun AlCaRecoTriggerBitsRcdRead_TEMPL_cfg.py inputDB=AlCaRecoHLTpaths_TEST.db inputTag=AlCaRecoHLTpaths_TEST
```