CMS 3D CMS Logo

AlCaRecoTriggerBitsRcdRead.cc
Go to the documentation of this file.
1 
18 #include <string>
19 #include <map>
20 //#include <vector>
21 #include <sstream>
22 #include <fstream>
23 
24 // Framework
34 
35 // What I want to read:
38 
40 public:
43 
44  void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup) override {}
45  void beginRun(const edm::Run &run, const edm::EventSetup &evtSetup) override;
46  void endJob() override;
47 
48 private:
49  // types
50  enum OutputType { kText, kTwiki, kPython }; //kHtml};
51 
52  // methods
53  OutputType stringToEnum(const std::string &outputType) const;
55 
56  // members
62  std::unique_ptr<std::ofstream> output_;
63 };
64 
68 
70  : outputType_(this->stringToEnum(cfg.getUntrackedParameter<std::string>("outputType"))), firstRun_(0), lastRun_(0) {
71  // edm::LogInfo("") << "@SUB=AlCaRecoTriggerBitsRcdRead"
72  // << cfg.getParameter<std::string>("@module_label");
73 
74  std::string fileName(cfg.getUntrackedParameter<std::string>("rawFileName"));
75  switch (outputType_) { // now append suffix
76  case kText:
77  fileName += ".txt";
78  break;
79  case kPython:
80  fileName += ".py";
81  break;
82  case kTwiki:
83  fileName += ".twiki";
84  break;
85  }
86  if (!fileName.empty()) {
87  output_.reset(new std::ofstream(fileName.c_str()));
88  if (!output_->good()) {
89  edm::LogError("IOproblem") << "Could not open output file " << fileName << ".";
90  output_.reset();
91  }
92  }
93 }
94 
97  if (outputTypeStr == "text")
98  return kText;
99  if (outputTypeStr == "twiki")
100  return kTwiki;
101  if (outputTypeStr == "python")
102  return kPython;
103  // if (outputTypeStr == "html") return kHtml;
104 
105  throw cms::Exception("BadConfig") << "AlCaRecoTriggerBitsRcdRead: "
106  << "outputType '" << outputTypeStr << "' not known,"
107  << " use 'text', 'twiki' or 'python'\n";
108 
109  return kTwiki; // never reached, to please compiler
110 }
111 
114  if (watcher_.check(iSetup)) { // new IOV for this run
115  // Print last IOV - if there has already been one:
116  if (lastRun_ != 0)
118 
119  // Get AlCaRecoTriggerBits from EventSetup:
121  iSetup.get<AlCaRecoTriggerBitsRcd>().get(triggerBits);
122  lastTriggerBits_ = *triggerBits; // copy for later use
123  firstRun_ = run.run(); // keep track where it started
124  }
125 
126  lastRun_ = run.run(); // keep track of last visited run
127 }
128 
131  // Print for very last IOV, not treated yet in beginRun(..):
133 }
134 
138  const AlCaRecoTriggerBits &triggerBits) const {
139  // Get map of strings to concatenated list of names of HLT paths:
140  typedef std::map<std::string, std::string> TriggerMap;
141  const TriggerMap &triggerMap = triggerBits.m_alcarecoToTrig;
142 
143  // Collect output for given run numbers via ostringstream.
144  // Format depends on outputType_ configuration.
145  std::ostringstream output;
146  switch (outputType_) {
147  case kPython:
148  output << " triggerLists = cms.VPSet(\n";
149  [[fallthrough]];
150  case kText:
151  output << "#\n# AlCaRecoTriggerBits settings for IOV " << firstRun << "-" << lastRun << ":\n#\n";
152  break;
153  case kTwiki:
154  output << "---+++++ *IOV*: " << firstRun << "-" << lastRun << "\n"
155  << "| *TriggerBits list key* | *HLT paths* |\n";
156  break;
157  }
158 
159  // if (outputType_ == kPython) output << " triggerLists = cms.VPSet(\n";
160 
161  // loop over entries in map
162  for (TriggerMap::const_iterator i = triggerMap.begin(); i != triggerMap.end(); ++i) {
163  if (outputType_ == kPython && i != triggerMap.begin())
164  output << ",\n";
165 
166  switch (outputType_) {
167  case kPython:
168  output << " cms.PSet(listName = cms.string('" << i->first << "'),\n"
169  << " hltPaths = cms.vstring(";
170  break;
171  case kText:
172  output << "trigger list key: '" << i->first << "'\npaths:\n";
173  break;
174  case kTwiki:
175  output << "| '" << i->first << "' | ";
176  }
177  // We must avoid a map<string,vector<string> > in DB for performance reason,
178  // so the paths are mapped into one string separated by ';':
179  const std::vector<std::string> paths = triggerBits.decompose(i->second);
180  for (unsigned int iPath = 0; iPath < paths.size(); ++iPath) {
181  if (iPath != 0) {
182  output << ", "; // next path
183  switch (outputType_) {
184  case kPython: // only 2 per line
185  case kText: // only 4 per line
186  if (0 == (iPath % (outputType_ == kPython ? 2 : 4))) {
187  output << "\n";
188  if (outputType_ == kPython)
189  output << " ";
190  }
191  break;
192  case kTwiki: // Twiki will handle that
193  break;
194  }
195  }
196  output << "'" << paths[iPath] << "'";
197  }
198  switch (outputType_) {
199  case kPython:
200  output << ")\n )";
201  break;
202  case kText:
203  output << "\n#\n";
204  break;
205  case kTwiki:
206  output << " |\n";
207  }
208  }
209  if (outputType_ == kPython)
210  output << "\n ) # closing of VPSet triggerLists\n";
211 
212  // Final output - either message logger or output file:
213  if (output_.get())
214  *output_ << output.str();
215  else
216  edm::LogInfo("") << output.str();
217 }
218 
219 //define this as a plug-in
edm::ESWatcher::check
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
dataset.firstRun
firstRun
Definition: dataset.py:940
AlCaRecoTriggerBitsRcdRead::AlCaRecoTriggerBitsRcdRead
AlCaRecoTriggerBitsRcdRead(const edm::ParameterSet &cfg)
Definition: AlCaRecoTriggerBitsRcdRead.cc:69
edm::RunNumber_t
unsigned int RunNumber_t
Definition: RunLumiEventNumber.h:14
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
edm::ESWatcher< AlCaRecoTriggerBitsRcd >
ESHandle.h
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:32
edm::Run
Definition: Run.h:45
AlCaRecoTriggerBitsRcdRead::analyze
void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup) override
Definition: AlCaRecoTriggerBitsRcdRead.cc:44
AlCaRecoTriggerBitsRcdRead::firstRun_
edm::RunNumber_t firstRun_
Definition: AlCaRecoTriggerBitsRcdRead.cc:59
AlCaRecoTriggerBitsRcdRead::~AlCaRecoTriggerBitsRcdRead
~AlCaRecoTriggerBitsRcdRead() override
Definition: AlCaRecoTriggerBitsRcdRead.cc:42
SiStripBadComponentsDQMServiceTemplate_cfg.lastRun
lastRun
Definition: SiStripBadComponentsDQMServiceTemplate_cfg.py:27
edm::LogInfo
Definition: MessageLogger.h:254
AlCaRecoTriggerBitsRcdRead::lastRun_
edm::RunNumber_t lastRun_
Definition: AlCaRecoTriggerBitsRcdRead.cc:60
EDAnalyzer.h
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
AlCaRecoTriggerBits.h
AlCaRecoTriggerBitsRcdRead::printMap
void printMap(edm::RunNumber_t firstRun, edm::RunNumber_t lastRun, const AlCaRecoTriggerBits &triggerMap) const
Definition: AlCaRecoTriggerBitsRcdRead.cc:136
edm::EDAnalyzer
Definition: EDAnalyzer.h:29
AlCaRecoTriggerBitsRcdRead::lastTriggerBits_
AlCaRecoTriggerBits lastTriggerBits_
Definition: AlCaRecoTriggerBitsRcdRead.cc:61
MakerMacros.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Run.h
edm::ESHandle
Definition: DTSurvey.h:22
AlCaRecoTriggerBits::decompose
std::vector< std::string > decompose(const std::string &concatPaths) const
Decompose one value of map from concatenated string.
Definition: AlCaRecoTriggerBits.cc:31
AlCaRecoTriggerBits
Definition: AlCaRecoTriggerBits.h:9
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
AlCaRecoTriggerBitsRcdRead::beginRun
void beginRun(const edm::Run &run, const edm::EventSetup &evtSetup) override
Definition: AlCaRecoTriggerBitsRcdRead.cc:113
AlCaRecoTriggerBitsRcd
Definition: AlCaRecoTriggerBitsRcd.h:22
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
AlCaRecoTriggerBitsRcdRead::output_
std::unique_ptr< std::ofstream > output_
Definition: AlCaRecoTriggerBitsRcdRead.cc:62
AlCaRecoTriggerBitsRcdRead::kText
Definition: AlCaRecoTriggerBitsRcdRead.cc:50
AlCaRecoTriggerBitsRcdRead::kPython
Definition: AlCaRecoTriggerBitsRcdRead.cc:50
AlCaRecoTriggerBitsRcd.h
edm::EventSetup
Definition: EventSetup.h:57
AlCaRecoTriggerBitsRcdRead::kTwiki
Definition: AlCaRecoTriggerBitsRcdRead.cc:50
get
#define get
AlCaRecoTriggerBitsRcdRead::endJob
void endJob() override
Definition: AlCaRecoTriggerBitsRcdRead.cc:130
looper.cfg
cfg
Definition: looper.py:297
AlCaRecoTriggerBitsRcdRead::outputType_
const OutputType outputType_
Definition: AlCaRecoTriggerBitsRcdRead.cc:57
AlCaRecoTriggerBitsRcdRead::stringToEnum
OutputType stringToEnum(const std::string &outputType) const
Definition: AlCaRecoTriggerBitsRcdRead.cc:96
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
AlCaRecoTriggerBitsRcdRead
Definition: AlCaRecoTriggerBitsRcdRead.cc:39
AlCaRecoTriggerBits::m_alcarecoToTrig
std::map< std::string, std::string > m_alcarecoToTrig
Definition: AlCaRecoTriggerBits.h:21
ESWatcher.h
Exception
Definition: hltDiff.cc:246
AlCaRecoTriggerBitsRcdRead::watcher_
edm::ESWatcher< AlCaRecoTriggerBitsRcd > watcher_
Definition: AlCaRecoTriggerBitsRcdRead.cc:58
EventSetup.h
Skims_PA_cff.paths
paths
Definition: Skims_PA_cff.py:18
Exception.h
ParameterSet.h
AlCaRecoTriggerBitsRcdRead::OutputType
OutputType
Definition: AlCaRecoTriggerBitsRcdRead.cc:50
edm::Event
Definition: Event.h:73