Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <string>
00019 #include <map>
00020
00021 #include <sstream>
00022 #include <fstream>
00023
00024
00025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00026 #include "FWCore/Framework/interface/EventSetup.h"
00027 #include "FWCore/Framework/interface/ESHandle.h"
00028 #include "FWCore/Framework/interface/ESWatcher.h"
00029 #include "FWCore/Framework/interface/EDAnalyzer.h"
00030 #include "FWCore/Framework/interface/MakerMacros.h"
00031 #include "FWCore/Framework/interface/Run.h"
00032 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00033 #include "FWCore/Utilities/interface/Exception.h"
00034
00035
00036 #include "CondFormats/HLTObjects/interface/AlCaRecoTriggerBits.h"
00037 #include "CondFormats/DataRecord/interface/AlCaRecoTriggerBitsRcd.h"
00038
00039
00040 class AlCaRecoTriggerBitsRcdRead : public edm::EDAnalyzer {
00041 public:
00042 explicit AlCaRecoTriggerBitsRcdRead(const edm::ParameterSet &cfg);
00043 ~AlCaRecoTriggerBitsRcdRead() {}
00044
00045 virtual void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup) {}
00046 virtual void beginRun(const edm::Run &run, const edm::EventSetup &evtSetup);
00047 virtual void endJob();
00048
00049
00050 private:
00051
00052 enum OutputType {kText, kTwiki, kPython};
00053
00054
00055 OutputType stringToEnum(const std::string &outputType) const;
00056 void printMap(edm::RunNumber_t firstRun, edm::RunNumber_t lastRun,
00057 const AlCaRecoTriggerBits &triggerMap) const;
00058
00059
00060 const OutputType outputType_;
00061 edm::ESWatcher<AlCaRecoTriggerBitsRcd> watcher_;
00062 edm::RunNumber_t firstRun_;
00063 edm::RunNumber_t lastRun_;
00064 AlCaRecoTriggerBits lastTriggerBits_;
00065 std::auto_ptr<std::ofstream> output_;
00066 };
00067
00071
00072 AlCaRecoTriggerBitsRcdRead::AlCaRecoTriggerBitsRcdRead(const edm::ParameterSet& cfg)
00073 : outputType_(this->stringToEnum(cfg.getUntrackedParameter<std::string>("outputType"))),
00074 firstRun_(0), lastRun_(0)
00075 {
00076
00077
00078
00079 std::string fileName(cfg.getUntrackedParameter<std::string>("rawFileName"));
00080 switch (outputType_) {
00081 case kText: fileName += ".txt"; break;
00082 case kPython: fileName += ".py"; break;
00083 case kTwiki: fileName += ".twiki"; break;
00084 }
00085 if (fileName.size()) {
00086 output_.reset(new std::ofstream(fileName.c_str()));
00087 if (!output_->good()) {
00088 edm::LogError("IOproblem") << "Could not open output file " << fileName << ".";
00089 output_.reset();
00090 }
00091 }
00092
00093 }
00094
00096 AlCaRecoTriggerBitsRcdRead::OutputType
00097 AlCaRecoTriggerBitsRcdRead::stringToEnum(const std::string &outputTypeStr) const
00098 {
00099 if (outputTypeStr == "text") return kText;
00100 if (outputTypeStr == "twiki") return kTwiki;
00101 if (outputTypeStr == "python") return kPython;
00102
00103
00104 throw cms::Exception("BadConfig") << "AlCaRecoTriggerBitsRcdRead: "
00105 << "outputType '" << outputTypeStr << "' not known,"
00106 << " use 'text', 'twiki' or 'python'\n";
00107
00108 return kTwiki;
00109 }
00110
00112 void AlCaRecoTriggerBitsRcdRead::beginRun(const edm::Run& run, const edm::EventSetup& iSetup)
00113 {
00114 if (watcher_.check(iSetup)) {
00115
00116 if (lastRun_ != 0) this->printMap(firstRun_, lastRun_, lastTriggerBits_);
00117
00118
00119 edm::ESHandle<AlCaRecoTriggerBits> triggerBits;
00120 iSetup.get<AlCaRecoTriggerBitsRcd>().get(triggerBits);
00121 lastTriggerBits_ = *triggerBits;
00122 firstRun_ = run.run();
00123 }
00124
00125 lastRun_ = run.run();
00126 }
00127
00129 void AlCaRecoTriggerBitsRcdRead::endJob()
00130 {
00131
00132 this->printMap(firstRun_, lastRun_, lastTriggerBits_);
00133 }
00134
00136 void AlCaRecoTriggerBitsRcdRead::printMap(edm::RunNumber_t firstRun,
00137 edm::RunNumber_t lastRun,
00138 const AlCaRecoTriggerBits &triggerBits) const
00139 {
00140
00141 typedef std::map<std::string, std::string> TriggerMap;
00142 const TriggerMap &triggerMap = triggerBits.m_alcarecoToTrig;
00143
00144
00145
00146 std::ostringstream output;
00147 switch (outputType_) {
00148 case kPython:
00149 output << " triggerLists = cms.VPSet(\n";
00150
00151 case kText:
00152 output << "#\n# AlCaRecoTriggerBits settings for IOV "
00153 << firstRun << "-" << lastRun << ":\n#\n";
00154 break;
00155 case kTwiki:
00156 output << "---+++++ *IOV*: " << firstRun << "-" << lastRun << "\n"
00157 << "| *TriggerBits list key* | *HLT paths* |\n";
00158 break;
00159 }
00160
00161
00162
00163
00164 for (TriggerMap::const_iterator i = triggerMap.begin(); i != triggerMap.end(); ++i) {
00165
00166 if (outputType_ == kPython && i != triggerMap.begin()) output << ",\n";
00167
00168 switch (outputType_) {
00169 case kPython:
00170 output << " cms.PSet(listName = cms.string('" << i->first << "'),\n"
00171 << " hltPaths = cms.vstring(";
00172 break;
00173 case kText:
00174 output << "trigger list key: '" << i->first << "'\npaths:\n";
00175 break;
00176 case kTwiki:
00177 output << "| '" << i->first << "' | ";
00178 }
00179
00180
00181 const std::vector<std::string> paths = triggerBits.decompose(i->second);
00182 for (unsigned int iPath = 0; iPath < paths.size(); ++iPath) {
00183 if (iPath != 0) {
00184 output << ", ";
00185 switch (outputType_) {
00186 case kPython:
00187 case kText:
00188 if (0 == (iPath % (outputType_ == kPython ? 2 : 4))) {
00189 output << "\n";
00190 if (outputType_ == kPython) output << " ";
00191 }
00192 break;
00193 case kTwiki:
00194 break;
00195 }
00196 }
00197 output << "'" << paths[iPath] << "'";
00198 }
00199 switch (outputType_) {
00200 case kPython:
00201 output << ")\n )";
00202 break;
00203 case kText:
00204 output << "\n#\n";
00205 break;
00206 case kTwiki:
00207 output << " |\n";
00208 }
00209 }
00210 if (outputType_ == kPython) output << "\n ) # closing of VPSet triggerLists\n";
00211
00212
00213 if (output_.get()) *output_ << output.str();
00214 else edm::LogInfo("") << output.str();
00215 }
00216
00217
00218
00219
00220 DEFINE_FWK_MODULE(AlCaRecoTriggerBitsRcdRead);