CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
AlCaRecoTriggerBitsRcdUpdate Class Reference
Inheritance diagram for AlCaRecoTriggerBitsRcdUpdate:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

 AlCaRecoTriggerBitsRcdUpdate (const edm::ParameterSet &cfg)
 
virtual void analyze (const edm::Event &evt, const edm::EventSetup &evtSetup) override
 
 ~AlCaRecoTriggerBitsRcdUpdate ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Types

typedef std::map< std::string, std::string > TriggerMap
 

Private Member Functions

bool addTriggerLists (const std::vector< edm::ParameterSet > &triggerListsAdd, AlCaRecoTriggerBits &bits) const
 
AlCaRecoTriggerBitscreateStartTriggerBits (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
 
void writeBitsToDB (AlCaRecoTriggerBits *bitsToWrite) const
 Takes over memory uresponsibility for 'bitsToWrite'. More...
 

Private Attributes

const std::vector< edm::ParameterSetalcarecoReplace_
 
const unsigned int firstRunIOV_
 
const int lastRunIOV_
 
const std::vector< std::string > listNamesRemove_
 
unsigned int nEventCalls_
 
const bool startEmpty_
 
const std::vector< edm::ParameterSettriggerListsAdd_
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Module to write trigger bit mappings (AlCaRecoTriggerBits) to DB. Can be configured to read an old one and update this by

Definition at line 32 of file AlCaRecoTriggerBitsRcdUpdate.cc.

Member Typedef Documentation

typedef std::map<std::string, std::string> AlCaRecoTriggerBitsRcdUpdate::TriggerMap
private

Definition at line 40 of file AlCaRecoTriggerBitsRcdUpdate.cc.

Constructor & Destructor Documentation

AlCaRecoTriggerBitsRcdUpdate::AlCaRecoTriggerBitsRcdUpdate ( const edm::ParameterSet cfg)
explicit

Definition at line 63 of file AlCaRecoTriggerBitsRcdUpdate.cc.

64  : nEventCalls_(0),
65  firstRunIOV_(cfg.getParameter<unsigned int>("firstRunIOV")),
66  lastRunIOV_(cfg.getParameter<int>("lastRunIOV")),
67  startEmpty_(cfg.getParameter<bool>("startEmpty")),
68  listNamesRemove_(cfg.getParameter<std::vector<std::string> >("listNamesRemove")),
69  triggerListsAdd_(cfg.getParameter<std::vector<edm::ParameterSet> >("triggerListsAdd")),
70  alcarecoReplace_(cfg.getParameter<std::vector<edm::ParameterSet> >("alcarecoToReplace"))
71 {
72 }
T getParameter(std::string const &) const
const std::vector< edm::ParameterSet > triggerListsAdd_
const std::vector< edm::ParameterSet > alcarecoReplace_
const std::vector< std::string > listNamesRemove_
AlCaRecoTriggerBitsRcdUpdate::~AlCaRecoTriggerBitsRcdUpdate ( )
inline

Definition at line 35 of file AlCaRecoTriggerBitsRcdUpdate.cc.

References analyze().

35 {}

Member Function Documentation

bool AlCaRecoTriggerBitsRcdUpdate::addTriggerLists ( const std::vector< edm::ParameterSet > &  triggerListsAdd,
AlCaRecoTriggerBits bits 
) const
private

Definition at line 168 of file AlCaRecoTriggerBitsRcdUpdate.cc.

References AlCaRecoTriggerBits::compose(), Exception, ALCARECOTkAlBeamHalo_cff::filter, AlCaRecoTriggerBits::m_alcarecoToTrig, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by analyze().

170 {
171  TriggerMap &triggerMap = bits.m_alcarecoToTrig;
172 
173  // loop on PSets, each containing the key (filter name) and a vstring with triggers
174  for (std::vector<edm::ParameterSet>::const_iterator iSet = triggerListsAdd.begin();
175  iSet != triggerListsAdd.end(); ++iSet) {
176 
177  const std::vector<std::string> paths(iSet->getParameter<std::vector<std::string> >("hltPaths"));
178  // We must avoid a map<string,vector<string> > in DB for performance reason,
179  // so we have to merge the paths into one string that will be decoded when needed:
180  const std::string mergedPaths = bits.compose(paths);
181 
182  const std::string filter(iSet->getParameter<std::string>("listName"));
183  if (triggerMap.find(filter) != triggerMap.end()) {
184  throw cms::Exception("BadConfig") << "List name '" << filter << "' already in map, either "
185  << "remove from 'triggerListsAdd' or "
186  << " add to 'listNamesRemove'.\n";
187  }
188  triggerMap[filter] = mergedPaths;
189  }
190 
191  return true;
192 }
std::map< std::string, std::string > m_alcarecoToTrig
std::map< std::string, std::string > TriggerMap
std::string compose(const std::vector< std::string > &paths) const
Compose several paths into one string :
void AlCaRecoTriggerBitsRcdUpdate::analyze ( const edm::Event evt,
const edm::EventSetup evtSetup 
)
overridevirtual

Definition at line 75 of file AlCaRecoTriggerBitsRcdUpdate.cc.

References addTriggerLists(), alcarecoReplace_, createStartTriggerBits(), listNamesRemove_, AlCaRecoTriggerBits::m_alcarecoToTrig, nEventCalls_, removeKeysFromMap(), replaceKeysFromMap(), startEmpty_, triggerListsAdd_, and writeBitsToDB().

Referenced by ~AlCaRecoTriggerBitsRcdUpdate().

76 {
77  if (nEventCalls_++ > 0) { // postfix increment!
78  edm::LogWarning("BadConfig")
79  << "@SUB=analyze" << "Writing to DB to be done only once, set\n"
80  << "'process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(1))'\n"
81  << " next time. But your writing is fine.)";
82  return;
83  }
84 
85  // create what to write - starting from empty or existing list (auto_ptr?)
86  AlCaRecoTriggerBits *bitsToWrite = this->createStartTriggerBits(startEmpty_, iSetup);
87 
88  // remove some existing entries in map
90 
91  // now add new entries
92  this->addTriggerLists(triggerListsAdd_, *bitsToWrite);
93 
94  // now replace keys
96 
97  // finally write to DB
98  this->writeBitsToDB(bitsToWrite);
99 
100 }
AlCaRecoTriggerBits * createStartTriggerBits(bool startEmpty, const edm::EventSetup &evtSetup) const
std::map< std::string, std::string > m_alcarecoToTrig
bool addTriggerLists(const std::vector< edm::ParameterSet > &triggerListsAdd, AlCaRecoTriggerBits &bits) const
const std::vector< edm::ParameterSet > triggerListsAdd_
const std::vector< edm::ParameterSet > alcarecoReplace_
bool removeKeysFromMap(const std::vector< std::string > &keys, TriggerMap &triggerMap) const
const std::vector< std::string > listNamesRemove_
void writeBitsToDB(AlCaRecoTriggerBits *bitsToWrite) const
Takes over memory uresponsibility for &#39;bitsToWrite&#39;.
bool replaceKeysFromMap(const std::vector< edm::ParameterSet > &alcarecoReplace, TriggerMap &triggerMap) const
AlCaRecoTriggerBits * AlCaRecoTriggerBitsRcdUpdate::createStartTriggerBits ( bool  startEmpty,
const edm::EventSetup evtSetup 
) const
private

Definition at line 104 of file AlCaRecoTriggerBitsRcdUpdate.cc.

References edm::EventSetup::get().

Referenced by analyze().

106 {
107  if (startEmpty) {
108  return new AlCaRecoTriggerBits;
109  } else {
111  evtSetup.get<AlCaRecoTriggerBitsRcd>().get(triggerBits);
112  return new AlCaRecoTriggerBits(*triggerBits); // copy old one
113  }
114 }
const T & get() const
Definition: EventSetup.h:55
bool AlCaRecoTriggerBitsRcdUpdate::removeKeysFromMap ( const std::vector< std::string > &  keys,
TriggerMap triggerMap 
) const
private

Definition at line 117 of file AlCaRecoTriggerBitsRcdUpdate.cc.

References Exception.

Referenced by analyze().

119 {
120  for (std::vector<std::string>::const_iterator iKey = keys.begin(), endKey = keys.end();
121  iKey != endKey; ++iKey) {
122  if (triggerMap.find(*iKey) != triggerMap.end()) {
123  // remove
124 // edm::LogError("Temp") << "@SUB=removeKeysFromMap" << "Cannot yet remove '" << *iKey
125 // << "' from map.";
126 // FIXME: test next line@
127  triggerMap.erase(*iKey);
128  } else { // not in list ==> misconfiguartion!
129  throw cms::Exception("BadConfig") << "[AlCaRecoTriggerBitsRcdUpdate::removeKeysFromMap] "
130  << "Cannot remove key '" << *iKey << "' since not in "
131  << "list - typo in configuration?\n";
132  return false;
133  }
134  }
135  return true;
136 }
bool AlCaRecoTriggerBitsRcdUpdate::replaceKeysFromMap ( const std::vector< edm::ParameterSet > &  alcarecoReplace,
TriggerMap triggerMap 
) const
private

Definition at line 139 of file AlCaRecoTriggerBitsRcdUpdate.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by analyze().

141 {
142 
143  std::vector<std::pair<std::string,std::string> > keyPairs;
144  keyPairs.reserve(alcarecoReplace.size());
145 
146  for(auto &iSet : alcarecoReplace ){
147  const std::string oldKey(iSet.getParameter<std::string>("oldKey"));
148  const std::string newKey(iSet.getParameter<std::string>("newKey"));
149  keyPairs.push_back(std::make_pair(oldKey,newKey));
150  }
151 
152  for(auto& iKey : keyPairs){
153  if(triggerMap.find(iKey.first) != triggerMap.end() ){
154  std::string bitsToReplace = triggerMap[iKey.first];
155  triggerMap.erase(iKey.first);
156  triggerMap[iKey.second] = bitsToReplace;
157  } else { // not in list ==> misconfiguration!
158  edm::LogWarning("AlCaRecoTriggerBitsRcdUpdate") << "[AlCaRecoTriggerBitsRcdUpdate::replaceKeysFromMap] "
159  << "Cannot replace key '" << iKey.first << "with " << iKey.second << " since not in "
160  << "list - typo in configuration?\n";
161  return false;
162  }
163  }
164  return true;
165 }
void AlCaRecoTriggerBitsRcdUpdate::writeBitsToDB ( AlCaRecoTriggerBits bitsToWrite) const
private

Takes over memory uresponsibility for 'bitsToWrite'.

Definition at line 195 of file AlCaRecoTriggerBitsRcdUpdate.cc.

References cond::service::PoolDBOutputService::appendSinceTime(), cond::service::PoolDBOutputService::createNewIOV(), DEFINE_FWK_MODULE, cond::service::PoolDBOutputService::endOfTime(), Exception, firstRunIOV_, edm::Service< T >::isAvailable(), cond::service::PoolDBOutputService::isNewTagRequest(), ntuplemaker::lastRun, lastRunIOV_, align_cfg::recordName, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by analyze().

196 {
197  edm::LogInfo("") << "Uploading to the database...";
198 
200  if (!poolDbService.isAvailable()) {
201  throw cms::Exception("NotAvailable") << "PoolDBOutputService not available.\n";
202  }
203 
204  // ownership of bitsToWrite transferred
205  // FIXME: Have to check that timetype is run number! How?
206  const std::string recordName("AlCaRecoTriggerBitsRcd");
207  if (poolDbService->isNewTagRequest(recordName)) { // tag not yet existing
208  // lastRunIOV_ = -1 means infinity:
209  const cond::Time_t lastRun = (lastRunIOV_ < 0 ? poolDbService->endOfTime() : lastRunIOV_);
210  poolDbService->createNewIOV(bitsToWrite, firstRunIOV_, lastRun, recordName);
211  } else { // tag exists, can only append
212  if (lastRunIOV_ >= 0) {
213  throw cms::Exception("BadConfig") << "Tag already exists, can only append until infinity,"
214  << " but lastRunIOV = " << lastRunIOV_ << ".\n";
215  }
216  poolDbService->appendSinceTime(bitsToWrite, firstRunIOV_, recordName);
217  }
218 
219  edm::LogInfo("") << "...done for runs " << firstRunIOV_ << " to " << lastRunIOV_
220  << " (< 0 meaning infinity)!";
221 }
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
unsigned long long Time_t
Definition: Time.h:16
bool isNewTagRequest(const std::string &recordName)
bool isAvailable() const
Definition: Service.h:46
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)

Member Data Documentation

const std::vector<edm::ParameterSet> AlCaRecoTriggerBitsRcdUpdate::alcarecoReplace_
private

Definition at line 56 of file AlCaRecoTriggerBitsRcdUpdate.cc.

Referenced by analyze().

const unsigned int AlCaRecoTriggerBitsRcdUpdate::firstRunIOV_
private

Definition at line 51 of file AlCaRecoTriggerBitsRcdUpdate.cc.

Referenced by writeBitsToDB().

const int AlCaRecoTriggerBitsRcdUpdate::lastRunIOV_
private

Definition at line 52 of file AlCaRecoTriggerBitsRcdUpdate.cc.

Referenced by writeBitsToDB().

const std::vector<std::string> AlCaRecoTriggerBitsRcdUpdate::listNamesRemove_
private

Definition at line 54 of file AlCaRecoTriggerBitsRcdUpdate.cc.

Referenced by analyze().

unsigned int AlCaRecoTriggerBitsRcdUpdate::nEventCalls_
private

Definition at line 50 of file AlCaRecoTriggerBitsRcdUpdate.cc.

Referenced by analyze().

const bool AlCaRecoTriggerBitsRcdUpdate::startEmpty_
private

Definition at line 53 of file AlCaRecoTriggerBitsRcdUpdate.cc.

Referenced by analyze().

const std::vector<edm::ParameterSet> AlCaRecoTriggerBitsRcdUpdate::triggerListsAdd_
private

Definition at line 55 of file AlCaRecoTriggerBitsRcdUpdate.cc.

Referenced by analyze().