CMS 3D CMS Logo

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