CMS 3D CMS Logo

SiStripDaqInfo.cc
Go to the documentation of this file.
4 
6 
7 #include "SiStripDaqInfo.h"
10 
11 //Run Info
13 
14 // FED cabling and numbering
16 
17 #include <cassert>
18 #include <cmath>
19 #include <cstdio>
20 #include <iomanip>
21 #include <iostream>
22 #include <sstream>
23 #include <string>
24 #include <vector>
25 
27  : fedCablingToken_{esConsumes<edm::Transition::BeginRun>()},
28  tTopoToken_{esConsumes<edm::Transition::BeginRun>()},
29  runInfoToken_{esConsumes<edm::Transition::BeginRun>()} {
30  edm::LogInfo("SiStripDaqInfo") << "SiStripDaqInfo::Deleting SiStripDaqInfo ";
31 }
32 
33 //
34 // -- Book MEs for SiStrip Daq Fraction
35 //
37  edm::LogInfo("SiStripDcsInfo") << " SiStripDaqInfo::bookStatus " << bookedStatus_;
38  if (bookedStatus_)
39  return;
40 
41  dqm_store.cd();
42  std::string strip_dir = "";
43  SiStripUtility::getTopFolderPath(dqm_store, "SiStrip", strip_dir);
44  if (!strip_dir.empty())
45  dqm_store.setCurrentFolder(strip_dir + "/EventInfo");
46  else
47  dqm_store.setCurrentFolder("SiStrip/EventInfo");
48 
49  daqFraction_ = dqm_store.bookFloat("DAQSummary");
50 
51  dqm_store.cd();
52  if (!strip_dir.empty())
53  dqm_store.setCurrentFolder(strip_dir + "/EventInfo/DAQContents");
54  else
55  dqm_store.setCurrentFolder("SiStrip/EventInfo/DAQContents");
56 
57  std::vector<std::string> det_types;
58  det_types.push_back("TIB");
59  det_types.push_back("TOB");
60  det_types.push_back("TIDF");
61  det_types.push_back("TIDB");
62  det_types.push_back("TECF");
63  det_types.push_back("TECB");
64 
65  for (auto const& det : det_types) {
66  std::string const me_name{"SiStrip_" + det};
67  SubDetMEs local_mes{dqm_store.bookFloat(me_name), 0};
68  subDetMEsMap_.emplace(det, local_mes);
69  }
70  bookedStatus_ = true;
71  dqm_store.cd();
72 }
73 //
74 // -- Fill with Dummy values
75 //
77  if (!bookedStatus_) {
78  bookStatus(dqm_store);
79  }
81 
82  for (auto& pr : subDetMEsMap_) {
83  pr.second.daqFractionME->Reset();
84  pr.second.daqFractionME->Fill(-1.0);
85  }
87  daqFraction_->Fill(-1.0);
88 }
89 
91  edm::LogInfo("SiStripDaqInfo") << "SiStripDaqInfo:: Begining of Run";
92 
93  // Check latest Fed cabling and create TrackerMapCreator
94  if (fedCablingWatcher_.check(eSetup)) {
96  readFedIds(fedCabling_, eSetup);
97  }
98  auto& dqm_store = *edm::Service<DQMStore>{};
99  if (!bookedStatus_) {
100  bookStatus(dqm_store);
101  }
102  if (nFedTotal_ == 0) {
103  fillDummyStatus(dqm_store);
104  edm::LogInfo("SiStripDaqInfo") << " SiStripDaqInfo::No FEDs Connected!!!";
105  return;
106  }
107 
108  float nFEDConnected = 0.0;
109  constexpr int siStripFedIdMin{FEDNumbering::MINSiStripFEDID};
110  constexpr int siStripFedIdMax{FEDNumbering::MAXSiStripFEDID};
111 
112  if (!eSetup.tryToGet<RunInfoRcd>())
113  return;
114  auto sumFED = eSetup.getHandle(runInfoToken_);
115  if (!sumFED)
116  return;
117 
118  auto const& fedsInIds = sumFED->m_fed_in;
119  for (auto const fedID : fedsInIds) {
120  if (fedID >= siStripFedIdMin && fedID <= siStripFedIdMax)
121  ++nFEDConnected;
122  }
123  edm::LogInfo("SiStripDaqInfo") << " SiStripDaqInfo::Total # of FEDs " << nFedTotal_ << " Connected FEDs "
124  << nFEDConnected;
125  if (nFEDConnected > 0) {
126  daqFraction_->Reset();
127  daqFraction_->Fill(nFEDConnected / nFedTotal_);
128  readSubdetFedFractions(dqm_store, fedsInIds, eSetup);
129  }
130 }
131 
133 
134 //
135 // -- Read Sub Detector FEDs
136 //
137 void SiStripDaqInfo::readFedIds(const SiStripFedCabling* fedcabling, edm::EventSetup const& iSetup) {
138  //Retrieve tracker topology from geometry
139  const auto tTopo = &iSetup.getData(tTopoToken_);
140 
141  auto feds = fedCabling_->fedIds();
142 
143  nFedTotal_ = feds.size();
144  for (auto const fed : feds) {
145  auto fedChannels = fedCabling_->fedConnections(fed);
146  for (auto const& conn : fedChannels) {
147  if (!conn.isConnected())
148  continue;
149  uint32_t detId = conn.detId();
150  if (detId == 0 || detId == 0xFFFFFFFF)
151  continue;
154  subDetFedMap_[subdet_tag].push_back(fed);
155  break;
156  }
157  }
158 }
159 //
160 // -- Fill Subdet FEDIds
161 //
163  std::vector<int> const& fed_ids,
164  edm::EventSetup const& iSetup) {
165  //Retrieve tracker topology from geometry
166  const auto tTopo = &iSetup.getData(tTopoToken_);
167 
168  constexpr int siStripFedIdMin{FEDNumbering::MINSiStripFEDID};
169  constexpr int siStripFedIdMax{FEDNumbering::MAXSiStripFEDID};
170 
171  // initialiase
172  for (auto const& pr : subDetFedMap_) {
173  auto const& name = pr.first;
174  auto iPos = subDetMEsMap_.find(name);
175  if (iPos == subDetMEsMap_.end())
176  continue;
177  iPos->second.connectedFeds = 0;
178  }
179  // count sub detector feds
180 
181  for (auto const& [name, subdetIds] : subDetFedMap_) {
182  auto iPos = subDetMEsMap_.find(name);
183  if (iPos == subDetMEsMap_.end())
184  continue;
185  iPos->second.connectedFeds = 0;
186  for (auto const subdetId : subdetIds) {
187  bool fedid_found = false;
188  for (auto const fedId : fed_ids) {
189  if (fedId < siStripFedIdMin || fedId > siStripFedIdMax)
190  continue;
191  if (subdetId == fedId) {
192  fedid_found = true;
193  iPos->second.connectedFeds++;
194  break;
195  }
196  }
197  if (!fedid_found)
198  findExcludedModule(dqm_store, subdetId, tTopo);
199  }
200  if (auto nFedSubDet = subdetIds.size(); nFedSubDet > 0) {
201  iPos->second.daqFractionME->Reset();
202  int const nFedsConnected = iPos->second.connectedFeds;
203  iPos->second.daqFractionME->Fill(nFedsConnected * 1.0 / nFedSubDet);
204  }
205  }
206 }
207 //
208 // -- find Excluded Modules
209 //
211  unsigned short const fed_id,
212  TrackerTopology const* tTopo) {
213  dqm_store.cd();
214  std::string mdir = "MechanicalView";
215  if (!SiStripUtility::goToDir(dqm_store, mdir)) {
216  dqm_store.setCurrentFolder("SiStrip/" + mdir);
217  }
218  std::string mechanical_dir = dqm_store.pwd();
219  auto fedChannels = fedCabling_->fedConnections(fed_id);
220  int ichannel = 0;
221  std::string tag = "ExcludedFedChannel";
222  std::string bad_module_folder;
223  for (auto const& conn : fedChannels) {
224  if (!conn.isConnected())
225  continue;
226  uint32_t detId = conn.detId();
227  if (detId == 0 || detId == 0xFFFFFFFF)
228  continue;
229 
230  ichannel++;
231  if (ichannel == 1) {
232  std::string subdet_folder;
233  SiStripFolderOrganizer folder_organizer;
234  folder_organizer.getSubDetFolder(detId, tTopo, subdet_folder);
235  if (!dqm_store.dirExists(subdet_folder)) {
236  subdet_folder = mechanical_dir + subdet_folder.substr(subdet_folder.find(mdir) + mdir.size());
237  }
238  bad_module_folder = subdet_folder + "/" + "BadModuleList";
239  dqm_store.setCurrentFolder(bad_module_folder);
240  }
241  std::ostringstream detid_str;
242  detid_str << detId;
243  std::string full_path = bad_module_folder + "/" + detid_str.str();
244  MonitorElement* me = dqm_store.get(full_path);
245  uint16_t flag = 0;
246  if (me) {
247  flag = me->getIntValue();
248  me->Reset();
249  } else
250  me = dqm_store.bookInt(detid_str.str());
252  me->Fill(flag);
253  }
254  dqm_store.cd();
255 }
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
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
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ESGetToken< SiStripFedCabling, SiStripFedCablingRcd > fedCablingToken_
void setCurrentFolder(std::string const &fullpath) override
Definition: DQMStore.h:646
std::optional< T > tryToGet() const
Definition: EventSetup.h:103
virtual bool dirExists(std::string const &path) const
Definition: DQMStore.cc:730
void bookStatus(DQMStore &dqm_store)
std::string pwd() override
Definition: DQMStore.h:644
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.
std::map< std::string, std::vector< unsigned short > > subDetFedMap_
const std::string subdet_tag("SubDet")
void analyze(edm::Event const &, edm::EventSetup const &) override
bool getData(T &iHolder) const
Definition: EventSetup.h:122
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
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:673
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