CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SiStripOfflineDQM.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiStripMonitorCluster
4 // Class: SiStripOfflineDQM
5 //
14 //
15 // Original Author: Samvel Khalatyan (ksamdev at gmail dot com)
16 // Created: Wed Oct 5 16:42:34 CET 2006
17 //
18 //
19 
25 
27 
29 
32 
35 
36 #include "SiStripOfflineDQM.h"
37 
38 //Run Info
41 
42 #include <iostream>
43 #include <iomanip>
44 #include <cstdio>
45 #include <string>
46 #include <sstream>
47 #include <cmath>
48 
50  : actionExecutor_{pSet},
51  usedWithEDMtoMEConverter_{pSet.getUntrackedParameter<bool>("UsedWithEDMtoMEConverter", false)},
52  createSummary_{pSet.getUntrackedParameter<bool>("CreateSummary", false)},
53  createTkMap_{pSet.getUntrackedParameter<bool>("CreateTkMap", false)},
54  createTkInfoFile_{pSet.getUntrackedParameter<bool>("CreateTkInfoFile", false)},
55  inputFileName_{pSet.getUntrackedParameter<std::string>("InputFileName", "")},
56  outputFileName_{pSet.getUntrackedParameter<std::string>("OutputFileName", "")},
57  globalStatusFilling_{pSet.getUntrackedParameter<int>("GlobalStatusFilling", 1)},
58  printFaultyModuleList_{pSet.getUntrackedParameter<bool>("PrintFaultyModuleList", false)},
59  detCablingToken_{globalStatusFilling_ > 0 || createTkMap_
60  ? decltype(detCablingToken_){esConsumes<edm::Transition::EndRun>()}
61  : decltype(detCablingToken_){}},
62  tTopoToken_{globalStatusFilling_ > 0 || createTkMap_
63  ? decltype(tTopoToken_){esConsumes<edm::Transition::EndRun>()}
64  : decltype(tTopoToken_){}},
65  tkDetMapToken_{globalStatusFilling_ > 0 || createTkMap_
66  ? decltype(tkDetMapToken_){esConsumes<edm::Transition::EndRun>()}
67  : decltype(tkDetMapToken_){}},
68  geomDetToken_{createTkMap_ && createTkInfoFile_ ? decltype(geomDetToken_){esConsumes<edm::Transition::EndRun>()}
69  : decltype(geomDetToken_){}},
70  runInfoToken_{esConsumes<edm::Transition::BeginRun>()} {
71  if (createTkMap_) {
73  for (const auto& ps : pSet.getUntrackedParameter<std::vector<edm::ParameterSet>>("TkMapOptions")) {
74  edm::ParameterSet tkMapPSet = ps;
75  const auto map_type = ps.getUntrackedParameter<std::string>("mapName", "");
76  tkMapPSet.augment(pSet.getUntrackedParameter<edm::ParameterSet>("TkmapParameters"));
77  const bool useSSQ = tkMapPSet.getUntrackedParameter<bool>("useSSQuality", false);
78  auto token = useSSQ ? QualityToken{esConsumes<edm::Transition::EndRun>(
79  edm::ESInputTag{"", tkMapPSet.getUntrackedParameter<std::string>("ssqLabel", "")})}
80  : QualityToken{};
81  tkMapOptions_.emplace_back(map_type, std::move(tkMapPSet), useSSQ, std::move(token));
82  }
83  }
84 
85  if (createTkInfoFile_) {
86  tkinfoTree_ = edm::Service<TFileService> { } -> make<TTree>("TkDetIdInfo", ""); }
87 
88  // explicit dependency to make sure the QTest reults needed here are present
89  // already in endRun.
90  consumes<DQMToken, edm::InRun>(edm::InputTag("siStripQTester", "DQMGenerationQTestRun"));
91  consumes<DQMToken, edm::InLumi>(edm::InputTag("siStripQTester", "DQMGenerationQTestLumi"));
92  usesResource("DQMStore");
93  produces<DQMToken, edm::Transition::EndRun>("DQMGenerationSiStripAnalyserRun");
94  produces<DQMToken, edm::Transition::EndLuminosityBlock>("DQMGenerationSiStripAnalyserLumi");
95 }
96 
98  // Essential: reads xml file to get the histogram names to create summary
99  // Read the summary configuration file
100  if (createSummary_) {
102  edm::LogInfo("ReadConfigurationProblem") << "SiStripOfflineDQM:: Error to read configuration file!! Summary "
103  "will not be produced!!!";
104  createSummary_ = false;
105  }
106  }
107  edm::LogInfo("BeginJobDone") << "SiStripOfflineDQM::beginJob done";
108 }
109 
110 void SiStripOfflineDQM::beginRun(edm::Run const& run, edm::EventSetup const& eSetup) {
111  edm::LogInfo("BeginRun") << "SiStripOfflineDQM:: Begining of Run";
112 
113  int nFEDs = 0;
114  if (eSetup.tryToGet<RunInfoRcd>()) {
115  if (auto sumFED = eSetup.getHandle(runInfoToken_)) {
116  constexpr int siStripFedIdMin{FEDNumbering::MINSiStripFEDID};
117  constexpr int siStripFedIdMax{FEDNumbering::MAXSiStripFEDID};
118 
119  for (auto const fedID : sumFED->m_fed_in) {
120  if (fedID >= siStripFedIdMin && fedID <= siStripFedIdMax)
121  ++nFEDs;
122  }
123  }
124  }
125  auto& dqm_store = *edm::Service<DQMStore>{};
126  trackerFEDsFound_ = (nFEDs > 0);
128  if (!openInputFile(dqm_store))
129  createSummary_ = false;
130  }
131  if (globalStatusFilling_ > 0) {
132  actionExecutor_.createStatus(dqm_store);
133  }
134 }
135 
137 
139  edm::LogInfo("EndLumiBlock") << "SiStripOfflineDQM::endLuminosityBlock";
140  if (trackerFEDsFound_) {
141  if (globalStatusFilling_ > 0) {
142  auto& dqm_store = *edm::Service<DQMStore>{};
144  }
145  }
146 }
147 
148 void SiStripOfflineDQM::endRun(edm::Run const& run, edm::EventSetup const& eSetup) {
149  edm::LogInfo("EndOfRun") << "SiStripOfflineDQM::endRun";
150 
151  auto& dqm_store = *edm::Service<DQMStore>{};
152  if (globalStatusFilling_ > 0) {
153  actionExecutor_.createStatus(dqm_store);
154  if (!trackerFEDsFound_) {
156  return;
157  }
158  // Fill Global Status
160  dqm_store, &eSetup.getData(detCablingToken_), &eSetup.getData(tkDetMapToken_), &eSetup.getData(tTopoToken_));
161  }
162 
164  return;
165 
166  // create Summary Plots
167  if (createSummary_)
169 
170  // Create TrackerMap
171  if (createTkMap_) {
173  &eSetup.getData(detCablingToken_), &eSetup.getData(tkDetMapToken_), &eSetup.getData(tTopoToken_))) {
174  std::vector<std::string> mapNames;
175  for (const auto& mapOptions : tkMapOptions_) {
176  edm::LogInfo("TkMapParameters") << mapOptions.pset;
177  std::string map_type = mapOptions.type;
179  mapOptions.pset, dqm_store, map_type, mapOptions.useSSQ ? &eSetup.getData(mapOptions.token) : nullptr);
180  mapNames.push_back(map_type);
181  }
182  if (createTkInfoFile_) {
183  actionExecutor_.createTkInfoFile(mapNames, tkinfoTree_, dqm_store, &eSetup.getData(geomDetToken_));
184  }
185  }
186  }
187 }
188 
190  edm::LogInfo("EndOfJob") << "SiStripOfflineDQM::endJob";
192  return;
193 
195  std::ostringstream str_val;
196  auto& dqm_store = *edm::Service<DQMStore>{};
197  actionExecutor_.printFaultyModuleList(dqm_store, str_val);
198  std::cout << str_val.str() << std::endl;
199  }
200 }
201 
203  if (inputFileName_.empty()) {
204  return false;
205  }
206  edm::LogInfo("OpenFile") << "SiStripOfflineDQM::openInputFile: Accessing root File" << inputFileName_;
207  dqm::harvesting::DQMStore* temp = dynamic_cast<dqm::harvesting::DQMStore*>(&dqm_store);
208  LegacyIOHelper leo(temp);
209  return leo.open(inputFileName_);
210 }
211 
T getUntrackedParameter(std::string const &, T const &) const
std::optional< T > tryToGet() const
Definition: EventSetup.h:109
std::string const inputFileName_
SiStripOfflineDQM(edm::ParameterSet const &ps)
void fillStatusAtLumi(DQMStore &dqm_store)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void endRun(edm::Run const &run, edm::EventSetup const &eSetup) override
std::vector< MapOptions > tkMapOptions_
edm::ESGetToken< SiStripDetCabling, SiStripDetCablingRcd > detCablingToken_
void augment(ParameterSet const &from)
bool open(std::string const &filename, std::string const &path="", uint32_t const run=0)
bool getData(T &iHolder) const
Definition: EventSetup.h:128
bool openInputFile(DQMStore &dqm_store)
bool const createTkInfoFile_
def move
Definition: eostools.py:511
edm::ESGetToken< TkDetMap, TrackerTopologyRcd > tkDetMapToken_
void fillStatus(DQMStore &dqm_store, const SiStripDetCabling *cabling, const TkDetMap *tkDetMap, const TrackerTopology *tTopo)
void endJob() override
edm::ESGetToken< RunInfo, RunInfoRcd > runInfoToken_
Log< level::Info, false > LogInfo
void printFaultyModuleList(DQMStore &dqm_store, std::ostringstream &str_val)
void produce(edm::Event &e, edm::EventSetup const &eSetup) override
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &iSetup) override
void createStatus(DQMStore &dqm_store)
void beginRun(edm::Run const &run, edm::EventSetup const &eSetup) override
void beginJob() override
void createOfflineTkMap(const edm::ParameterSet &tkmapPset, DQMStore &dqm_store, std::string &map_type, const SiStripQuality *stripQuality)
void createTkInfoFile(std::vector< std::string > tkhmap_names, TTree *tkinfo_tree, DQMStore &dqm_store, const GeometricDet *geomDet)
void createSummaryOffline(DQMStore &dqm_store)
SiStripActionExecutor actionExecutor_
tuple cout
Definition: gather_cfg.py:144
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
bool readTkMapConfiguration(const SiStripDetCabling *detCabling, const TkDetMap *tkDetMap, const TrackerTopology *tTopo)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
edm::ESGetToken< GeometricDet, IdealGeometryRecord > geomDetToken_
tTopoToken_
Definition: Run.h:45