CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AlCaRecoTriggerBitsRcdUpdate.cc
Go to the documentation of this file.
1 
10 #include <string>
11 #include <map>
12 #include <vector>
13 
14 // Framework
22 
23 // Database
25 
26 // What I want to write:
28 // Rcd for reading old one:
30 
31 
33 public:
36 
37  virtual void analyze(const edm::Event& evt, const edm::EventSetup& evtSetup) override;
38 
39 private:
40  typedef std::map<std::string, std::string> TriggerMap;
42  bool removeKeysFromMap(const std::vector<std::string> &keys, TriggerMap &triggerMap) const;
43  bool addTriggerLists(const std::vector<edm::ParameterSet> &triggerListsAdd,
44  AlCaRecoTriggerBits &bits) const;
46  void writeBitsToDB(AlCaRecoTriggerBits *bitsToWrite) const;
47 
48  unsigned int nEventCalls_;
49  const unsigned int firstRunIOV_;
50  const int lastRunIOV_;
51  const bool startEmpty_;
52  const std::vector<std::string> listNamesRemove_;
53  const std::vector<edm::ParameterSet> triggerListsAdd_;
54 };
55 
59 
61  : nEventCalls_(0),
62  firstRunIOV_(cfg.getParameter<unsigned int>("firstRunIOV")),
63  lastRunIOV_(cfg.getParameter<int>("lastRunIOV")),
64  startEmpty_(cfg.getParameter<bool>("startEmpty")),
65  listNamesRemove_(cfg.getParameter<std::vector<std::string> >("listNamesRemove")),
66  triggerListsAdd_(cfg.getParameter<std::vector<edm::ParameterSet> >("triggerListsAdd"))
67 {
68 }
69 
72 {
73  if (nEventCalls_++ > 0) { // postfix increment!
74  edm::LogWarning("BadConfig")
75  << "@SUB=analyze" << "Writing to DB to be done only once, set\n"
76  << "'process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(1))'\n"
77  << " next time. But your writing is fine.)";
78  return;
79  }
80 
81  // create what to write - starting from empty or existing list (auto_ptr?)
82  AlCaRecoTriggerBits *bitsToWrite = this->createStartTriggerBits(startEmpty_, iSetup);
83 
84  // remove some existing entries in map
86 
87  // now add new entries
88  this->addTriggerLists(triggerListsAdd_, *bitsToWrite);
89 
90  // finally write to DB
91  this->writeBitsToDB(bitsToWrite);
92 
93 }
94 
96 AlCaRecoTriggerBits* // auto_ptr?
98  const edm::EventSetup& evtSetup) const
99 {
100  if (startEmpty) {
101  return new AlCaRecoTriggerBits;
102  } else {
104  evtSetup.get<AlCaRecoTriggerBitsRcd>().get(triggerBits);
105  return new AlCaRecoTriggerBits(*triggerBits); // copy old one
106  }
107 }
108 
110 bool AlCaRecoTriggerBitsRcdUpdate::removeKeysFromMap(const std::vector<std::string> &keys,
111  TriggerMap &triggerMap) const
112 {
113  for (std::vector<std::string>::const_iterator iKey = keys.begin(), endKey = keys.end();
114  iKey != endKey; ++iKey) {
115  if (triggerMap.find(*iKey) != triggerMap.end()) {
116  // remove
117 // edm::LogError("Temp") << "@SUB=removeKeysFromMap" << "Cannot yet remove '" << *iKey
118 // << "' from map.";
119 // FIXME: test next line@
120  triggerMap.erase(*iKey);
121  } else { // not in list ==> misconfiguartion!
122  throw cms::Exception("BadConfig") << "[AlCaRecoTriggerBitsRcdUpdate::removeKeysFromMap] "
123  << "Cannot remove key '" << *iKey << "' since not in "
124  << "list - typo in configuration?\n";
125  return false;
126  }
127  }
128  return true;
129 }
130 
132 bool AlCaRecoTriggerBitsRcdUpdate::addTriggerLists(const std::vector<edm::ParameterSet> &triggerListsAdd,
133  AlCaRecoTriggerBits &bits) const
134 {
135  TriggerMap &triggerMap = bits.m_alcarecoToTrig;
136 
137  // loop on PSets, each containing the key (filter name) and a vstring with triggers
138  for (std::vector<edm::ParameterSet>::const_iterator iSet = triggerListsAdd.begin();
139  iSet != triggerListsAdd.end(); ++iSet) {
140 
141  const std::vector<std::string> paths(iSet->getParameter<std::vector<std::string> >("hltPaths"));
142  // We must avoid a map<string,vector<string> > in DB for performance reason,
143  // so we have to merge the paths into one string that will be decoded when needed:
144  const std::string mergedPaths = bits.compose(paths);
145 
146  const std::string filter(iSet->getParameter<std::string>("listName"));
147  if (triggerMap.find(filter) != triggerMap.end()) {
148  throw cms::Exception("BadConfig") << "List name '" << filter << "' already in map, either "
149  << "remove from 'triggerListsAdd' or "
150  << " add to 'listNamesRemove'.\n";
151  }
152  triggerMap[filter] = mergedPaths;
153  }
154 
155  return true;
156 }
157 
160 {
161  edm::LogInfo("") << "Uploading to the database...";
162 
164  if (!poolDbService.isAvailable()) {
165  throw cms::Exception("NotAvailable") << "PoolDBOutputService not available.\n";
166  }
167 
168  // ownership of bitsToWrite transferred
169  // FIXME: Have to check that timetype is run number! How?
170  const std::string recordName("AlCaRecoTriggerBitsRcd");
171  if (poolDbService->isNewTagRequest(recordName)) { // tag not yet existing
172  // lastRunIOV_ = -1 means infinity:
173  const cond::Time_t lastRun = (lastRunIOV_ < 0 ? poolDbService->endOfTime() : lastRunIOV_);
174  poolDbService->createNewIOV(bitsToWrite, firstRunIOV_, lastRun, recordName);
175  } else { // tag exists, can only append
176  if (lastRunIOV_ >= 0) {
177  throw cms::Exception("BadConfig") << "Tag already exists, can only append until infinity,"
178  << " but lastRunIOV = " << lastRunIOV_ << ".\n";
179  }
180  poolDbService->appendSinceTime(bitsToWrite, firstRunIOV_, recordName);
181  }
182 
183  edm::LogInfo("") << "...done for runs " << firstRunIOV_ << " to " << lastRunIOV_
184  << " (< 0 meaning infinity)!";
185 }
186 
187 //define this as a plug-in
AlCaRecoTriggerBits * createStartTriggerBits(bool startEmpty, const edm::EventSetup &evtSetup) const
std::map< std::string, std::string > m_alcarecoToTrig
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool addTriggerLists(const std::vector< edm::ParameterSet > &triggerListsAdd, AlCaRecoTriggerBits &bits) const
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision bits
std::map< std::string, std::string > TriggerMap
const std::vector< edm::ParameterSet > triggerListsAdd_
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
virtual void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup) override
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)
const T & get() const
Definition: EventSetup.h:55
std::string compose(const std::vector< std::string > &paths) const
Compose several paths into one string :
bool removeKeysFromMap(const std::vector< std::string > &keys, TriggerMap &triggerMap) const
AlCaRecoTriggerBitsRcdUpdate(const edm::ParameterSet &cfg)
const std::vector< std::string > listNamesRemove_
void writeBitsToDB(AlCaRecoTriggerBits *bitsToWrite) const
Takes over memory uresponsibility for &#39;bitsToWrite&#39;.