CMS 3D CMS Logo

SiStripDaqInfo.cc
Go to the documentation of this file.
18 
19 #include <cassert>
20 #include <cmath>
21 #include <cstdio>
22 #include <iomanip>
23 #include <iostream>
24 #include <sstream>
25 #include <fstream>
26 #include <string>
27 #include <vector>
28 #include <map>
29 
30 class SiStripFedCabling;
31 class TrackerTopology;
32 
33 class SiStripDaqInfo : public edm::one::EDAnalyzer<edm::one::SharedResources, edm::one::WatchRuns> {
34 public:
37 
39 
40 private:
41  void beginRun(edm::Run const& run, edm::EventSetup const& eSetup) override;
42  void analyze(edm::Event const&, edm::EventSetup const&) override;
43  void endRun(edm::Run const& run, edm::EventSetup const& eSetup) override{};
44 
45  void readFedIds(const SiStripFedCabling* fedcabling, edm::EventSetup const& iSetup);
46  void readSubdetFedFractions(DQMStore& dqm_store, std::vector<int> const& fed_ids, edm::EventSetup const& iSetup);
47  void bookStatus(DQMStore& dqm_store);
48  void fillDummyStatus(DQMStore& dqm_store);
49  void findExcludedModule(DQMStore& dqm_store, unsigned short fed_id, TrackerTopology const* tTopo);
50 
51  std::map<std::string, std::vector<unsigned short>> subDetFedMap_;
52 
54 
55  struct SubDetMEs {
58  };
59 
60  std::map<std::string, SubDetMEs> subDetMEsMap_;
61 
62  int nFedTotal_{};
63  bool bookedStatus_{false};
64 
70 };
71 
73  : fedCablingToken_{esConsumes<edm::Transition::BeginRun>()},
74  tTopoToken_{esConsumes<edm::Transition::BeginRun>()},
75  runInfoToken_{esConsumes<edm::Transition::BeginRun>()} {
76  usesResource("DQMStore");
77  edm::LogInfo("SiStripDaqInfo") << "SiStripDaqInfo::Deleting SiStripDaqInfo ";
78 }
79 
80 //
81 // -- Book MEs for SiStrip Daq Fraction
82 //
84  edm::LogInfo("SiStripDcsInfo") << " SiStripDaqInfo::bookStatus " << bookedStatus_;
85  if (bookedStatus_)
86  return;
87 
88  dqm_store.cd();
89  std::string strip_dir = "";
90  SiStripUtility::getTopFolderPath(dqm_store, "SiStrip", strip_dir);
91  if (!strip_dir.empty())
92  dqm_store.setCurrentFolder(strip_dir + "/EventInfo");
93  else
94  dqm_store.setCurrentFolder("SiStrip/EventInfo");
95 
96  daqFraction_ = dqm_store.bookFloat("DAQSummary");
97 
98  dqm_store.cd();
99  if (!strip_dir.empty())
100  dqm_store.setCurrentFolder(strip_dir + "/EventInfo/DAQContents");
101  else
102  dqm_store.setCurrentFolder("SiStrip/EventInfo/DAQContents");
103 
104  std::vector<std::string> det_types;
105  det_types.push_back("TIB");
106  det_types.push_back("TOB");
107  det_types.push_back("TIDF");
108  det_types.push_back("TIDB");
109  det_types.push_back("TECF");
110  det_types.push_back("TECB");
111 
112  for (auto const& det : det_types) {
113  std::string const me_name{"SiStrip_" + det};
114  SubDetMEs local_mes{dqm_store.bookFloat(me_name), 0};
115  subDetMEsMap_.emplace(det, local_mes);
116  }
117  bookedStatus_ = true;
118  dqm_store.cd();
119 }
120 //
121 // -- Fill with Dummy values
122 //
124  if (!bookedStatus_) {
125  bookStatus(dqm_store);
126  }
128 
129  for (auto& pr : subDetMEsMap_) {
130  pr.second.daqFractionME->Reset();
131  pr.second.daqFractionME->Fill(-1.0);
132  }
133  daqFraction_->Reset();
134  daqFraction_->Fill(-1.0);
135 }
136 
138  edm::LogInfo("SiStripDaqInfo") << "SiStripDaqInfo:: Begining of Run";
139 
140  // Check latest Fed cabling and create TrackerMapCreator
141  if (fedCablingWatcher_.check(eSetup)) {
143  readFedIds(fedCabling_, eSetup);
144  }
145  auto& dqm_store = *edm::Service<DQMStore>{};
146  if (!bookedStatus_) {
147  bookStatus(dqm_store);
148  }
149  if (nFedTotal_ == 0) {
150  fillDummyStatus(dqm_store);
151  edm::LogInfo("SiStripDaqInfo") << " SiStripDaqInfo::No FEDs Connected!!!";
152  return;
153  }
154 
155  float nFEDConnected = 0.0;
156  constexpr int siStripFedIdMin{FEDNumbering::MINSiStripFEDID};
157  constexpr int siStripFedIdMax{FEDNumbering::MAXSiStripFEDID};
158 
159  if (!eSetup.tryToGet<RunInfoRcd>())
160  return;
161  auto sumFED = eSetup.getHandle(runInfoToken_);
162  if (!sumFED)
163  return;
164 
165  auto const& fedsInIds = sumFED->m_fed_in;
166  for (auto const fedID : fedsInIds) {
167  if (fedID >= siStripFedIdMin && fedID <= siStripFedIdMax)
168  ++nFEDConnected;
169  }
170  edm::LogInfo("SiStripDaqInfo") << " SiStripDaqInfo::Total # of FEDs " << nFedTotal_ << " Connected FEDs "
171  << nFEDConnected;
172  if (nFEDConnected > 0) {
173  daqFraction_->Reset();
174  daqFraction_->Fill(nFEDConnected / nFedTotal_);
175  readSubdetFedFractions(dqm_store, fedsInIds, eSetup);
176  }
177 }
178 
180 
181 //
182 // -- Read Sub Detector FEDs
183 //
184 void SiStripDaqInfo::readFedIds(const SiStripFedCabling* fedcabling, edm::EventSetup const& iSetup) {
185  //Retrieve tracker topology from geometry
186  const auto tTopo = &iSetup.getData(tTopoToken_);
187 
188  auto feds = fedCabling_->fedIds();
189 
190  nFedTotal_ = feds.size();
191  for (auto const fed : feds) {
192  auto fedChannels = fedCabling_->fedConnections(fed);
193  for (auto const& conn : fedChannels) {
194  if (!conn.isConnected())
195  continue;
196  uint32_t detId = conn.detId();
197  if (detId == 0 || detId == 0xFFFFFFFF)
198  continue;
201  subDetFedMap_[subdet_tag].push_back(fed);
202  break;
203  }
204  }
205 }
206 //
207 // -- Fill Subdet FEDIds
208 //
210  std::vector<int> const& fed_ids,
211  edm::EventSetup const& iSetup) {
212  //Retrieve tracker topology from geometry
213  const auto tTopo = &iSetup.getData(tTopoToken_);
214 
215  constexpr int siStripFedIdMin{FEDNumbering::MINSiStripFEDID};
216  constexpr int siStripFedIdMax{FEDNumbering::MAXSiStripFEDID};
217 
218  // initialiase
219  for (auto const& pr : subDetFedMap_) {
220  auto const& name = pr.first;
221  auto iPos = subDetMEsMap_.find(name);
222  if (iPos == subDetMEsMap_.end())
223  continue;
224  iPos->second.connectedFeds = 0;
225  }
226  // count sub detector feds
227 
228  for (auto const& [name, subdetIds] : subDetFedMap_) {
229  auto iPos = subDetMEsMap_.find(name);
230  if (iPos == subDetMEsMap_.end())
231  continue;
232  iPos->second.connectedFeds = 0;
233  for (auto const subdetId : subdetIds) {
234  bool fedid_found = false;
235  for (auto const fedId : fed_ids) {
236  if (fedId < siStripFedIdMin || fedId > siStripFedIdMax)
237  continue;
238  if (subdetId == fedId) {
239  fedid_found = true;
240  iPos->second.connectedFeds++;
241  break;
242  }
243  }
244  if (!fedid_found)
245  findExcludedModule(dqm_store, subdetId, tTopo);
246  }
247  if (auto nFedSubDet = subdetIds.size(); nFedSubDet > 0) {
248  iPos->second.daqFractionME->Reset();
249  int const nFedsConnected = iPos->second.connectedFeds;
250  iPos->second.daqFractionME->Fill(nFedsConnected * 1.0 / nFedSubDet);
251  }
252  }
253 }
254 //
255 // -- find Excluded Modules
256 //
258  unsigned short const fed_id,
259  TrackerTopology const* tTopo) {
260  dqm_store.cd();
261  std::string mdir = "MechanicalView";
262  if (!SiStripUtility::goToDir(dqm_store, mdir)) {
263  dqm_store.setCurrentFolder("SiStrip/" + mdir);
264  }
265  std::string mechanical_dir = dqm_store.pwd();
266  auto fedChannels = fedCabling_->fedConnections(fed_id);
267  int ichannel = 0;
268  std::string tag = "ExcludedFedChannel";
269  std::string bad_module_folder;
270  for (auto const& conn : fedChannels) {
271  if (!conn.isConnected())
272  continue;
273  uint32_t detId = conn.detId();
274  if (detId == 0 || detId == 0xFFFFFFFF)
275  continue;
276 
277  ichannel++;
278  if (ichannel == 1) {
279  std::string subdet_folder;
280  SiStripFolderOrganizer folder_organizer;
281  folder_organizer.getSubDetFolder(detId, tTopo, subdet_folder);
282  if (!dqm_store.dirExists(subdet_folder)) {
283  subdet_folder = mechanical_dir + subdet_folder.substr(subdet_folder.find(mdir) + mdir.size());
284  }
285  bad_module_folder = subdet_folder + "/" + "BadModuleList";
286  dqm_store.setCurrentFolder(bad_module_folder);
287  }
288  std::ostringstream detid_str;
289  detid_str << detId;
290  std::string full_path = bad_module_folder + "/" + detid_str.str();
291  MonitorElement* me = dqm_store.get(full_path);
292  uint16_t flag = 0;
293  if (me) {
294  flag = me->getIntValue();
295  me->Reset();
296  } else
297  me = dqm_store.bookInt(detid_str.str());
299  me->Fill(flag);
300  }
301  dqm_store.cd();
302 }
static void setBadModuleFlag(std::string &hname, uint16_t &flg)
void findExcludedModule(DQMStore &dqm_store, unsigned short fed_id, TrackerTopology const *tTopo)
void readSubdetFedFractions(DQMStore &dqm_store, std::vector< int > const &fed_ids, edm::EventSetup const &iSetup)
MonitorElement * bookFloat(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:80
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
void getSubDetFolder(const uint32_t &detid, const TrackerTopology *tTopo, std::string &folder_name)
edm::ESGetToken< RunInfo, RunInfoRcd > runInfoToken_
void beginRun(edm::Run const &run, edm::EventSetup const &eSetup) override
edm::ESGetToken< SiStripFedCabling, SiStripFedCablingRcd > fedCablingToken_
void setCurrentFolder(std::string const &fullpath) override
Definition: DQMStore.h:647
std::optional< T > tryToGet() const
Definition: EventSetup.h:100
virtual bool dirExists(std::string const &path) const
Definition: DQMStore.cc:769
void bookStatus(DQMStore &dqm_store)
std::string pwd() override
Definition: DQMStore.h:645
void readFedIds(const SiStripFedCabling *fedcabling, edm::EventSetup const &iSetup)
assert(be >=bs)
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
void Fill(long long x)
virtual void Reset()
Remove all data from the ME, keept the empty histogram with all its settings.
MonitorElement * daqFractionME
std::map< std::string, std::vector< unsigned short > > subDetFedMap_
dqm::harvesting::MonitorElement MonitorElement
const std::string subdet_tag("SubDet")
void analyze(edm::Event const &, edm::EventSetup const &) override
void endRun(edm::Run const &run, edm::EventSetup const &eSetup) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
dqm::harvesting::DQMStore DQMStore
SiStripDaqInfo(edm::ParameterSet const &ps)
Log< level::Info, false > LogInfo
MonitorElement * bookInt(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:73
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:712
edm::ESWatcher< SiStripFedCablingRcd > fedCablingWatcher_
std::map< std::string, SubDetMEs > subDetMEsMap_
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
const SiStripFedCabling * fedCabling_
static void getSubDetectorTag(uint32_t det_id, std::string &subdet_tag, const TrackerTopology *tTopo)
static bool goToDir(DQMStore &dqm_store, std::string const &name)
MonitorElement * daqFraction_
conn
Definition: getInfo.py:9
void fillDummyStatus(DQMStore &dqm_store)
FedsConstIterRange fedIds() const
static void getTopFolderPath(DQMStore &dqm_store, std::string const &top_dir, std::string &path)
ConnsConstIterRange fedConnections(uint16_t fed_id) const
Definition: event.py:1
Definition: Run.h:45