CMS 3D CMS Logo

SiStripDaqInfo.cc
Go to the documentation of this file.
4 
6 
7 #include "SiStripDaqInfo.h"
10 
12 
13 //Run Info
17 
18 // FED cabling and numbering
22 
23 #include <cassert>
24 #include <cmath>
25 #include <cstdio>
26 #include <iomanip>
27 #include <iostream>
28 #include <sstream>
29 #include <string>
30 #include <vector>
31 
33  edm::LogInfo("SiStripDaqInfo") << "SiStripDaqInfo::Deleting SiStripDaqInfo ";
34 }
35 
36 //
37 // -- Book MEs for SiStrip Daq Fraction
38 //
40  edm::LogInfo("SiStripDcsInfo") << " SiStripDaqInfo::bookStatus " << bookedStatus_;
41  if (bookedStatus_)
42  return;
43 
44  dqm_store.cd();
45  std::string strip_dir = "";
46  SiStripUtility::getTopFolderPath(dqm_store, "SiStrip", strip_dir);
47  if (!strip_dir.empty())
48  dqm_store.setCurrentFolder(strip_dir + "/EventInfo");
49  else
50  dqm_store.setCurrentFolder("SiStrip/EventInfo");
51 
52  daqFraction_ = dqm_store.bookFloat("DAQSummary");
53 
54  dqm_store.cd();
55  if (!strip_dir.empty())
56  dqm_store.setCurrentFolder(strip_dir + "/EventInfo/DAQContents");
57  else
58  dqm_store.setCurrentFolder("SiStrip/EventInfo/DAQContents");
59 
60  std::vector<std::string> det_types;
61  det_types.push_back("TIB");
62  det_types.push_back("TOB");
63  det_types.push_back("TIDF");
64  det_types.push_back("TIDB");
65  det_types.push_back("TECF");
66  det_types.push_back("TECB");
67 
68  for (auto const& det : det_types) {
69  std::string const me_name{"SiStrip_" + det};
70  SubDetMEs local_mes{dqm_store.bookFloat(me_name), 0};
71  subDetMEsMap_.emplace(det, std::move(local_mes));
72  }
73  bookedStatus_ = true;
74  dqm_store.cd();
75 }
76 //
77 // -- Fill with Dummy values
78 //
80  if (!bookedStatus_) {
81  bookStatus(dqm_store);
82  }
83  assert(bookedStatus_);
84 
85  for (auto& pr : subDetMEsMap_) {
86  pr.second.daqFractionME->Reset();
87  pr.second.daqFractionME->Fill(-1.0);
88  }
90  daqFraction_->Fill(-1.0);
91 }
92 
94  edm::LogInfo("SiStripDaqInfo") << "SiStripDaqInfo:: Begining of Run";
95 
96  // Check latest Fed cabling and create TrackerMapCreator
97  unsigned long long cacheID = eSetup.get<SiStripFedCablingRcd>().cacheIdentifier();
98  if (m_cacheID_ != cacheID) {
99  m_cacheID_ = cacheID;
100 
101  eSetup.get<SiStripFedCablingRcd>().get(fedCabling_);
102 
103  readFedIds(fedCabling_, eSetup);
104  }
105  auto& dqm_store = *edm::Service<DQMStore>{};
106  if (!bookedStatus_) {
107  bookStatus(dqm_store);
108  }
109  if (nFedTotal_ == 0) {
110  fillDummyStatus(dqm_store);
111  edm::LogInfo("SiStripDaqInfo") << " SiStripDaqInfo::No FEDs Connected!!!";
112  return;
113  }
114 
115  float nFEDConnected = 0.0;
116  constexpr int siStripFedIdMin{FEDNumbering::MINSiStripFEDID};
117  constexpr int siStripFedIdMax{FEDNumbering::MAXSiStripFEDID};
118 
119  auto runInfoRec = eSetup.tryToGet<RunInfoRcd>();
120  if (!runInfoRec)
121  return;
122 
123  edm::ESHandle<RunInfo> sumFED;
124  runInfoRec->get(sumFED);
125 
126  if (!sumFED.isValid())
127  return;
128 
129  auto const& fedsInIds = sumFED->m_fed_in;
130  for (auto const fedID : fedsInIds) {
131  if (fedID >= siStripFedIdMin && fedID <= siStripFedIdMax)
132  ++nFEDConnected;
133  }
134  edm::LogInfo("SiStripDaqInfo") << " SiStripDaqInfo::Total # of FEDs " << nFedTotal_ << " Connected FEDs "
135  << nFEDConnected;
136  if (nFEDConnected > 0) {
137  daqFraction_->Reset();
138  daqFraction_->Fill(nFEDConnected / nFedTotal_);
139  readSubdetFedFractions(dqm_store, fedsInIds, eSetup);
140  }
141 }
142 
144 
145 //
146 // -- Read Sub Detector FEDs
147 //
149  //Retrieve tracker topology from geometry
150  edm::ESHandle<TrackerTopology> tTopoHandle;
151  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
152  const TrackerTopology* const tTopo = tTopoHandle.product();
153 
154  auto feds = fedCabling_->fedIds();
155 
156  nFedTotal_ = feds.size();
157  for (auto const fed : feds) {
158  auto fedChannels = fedCabling_->fedConnections(fed);
159  for (auto const& conn : fedChannels) {
160  if (!conn.isConnected())
161  continue;
162  uint32_t detId = conn.detId();
163  if (detId == 0 || detId == 0xFFFFFFFF)
164  continue;
166  SiStripUtility::getSubDetectorTag(detId, subdet_tag, tTopo);
167  subDetFedMap_[subdet_tag].push_back(fed);
168  break;
169  }
170  }
171 }
172 //
173 // -- Fill Subdet FEDIds
174 //
176  std::vector<int> const& fed_ids,
177  edm::EventSetup const& iSetup) {
178  //Retrieve tracker topology from geometry
179  edm::ESHandle<TrackerTopology> tTopoHandle;
180  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
181  const TrackerTopology* const tTopo = tTopoHandle.product();
182 
183  constexpr int siStripFedIdMin{FEDNumbering::MINSiStripFEDID};
184  constexpr int siStripFedIdMax{FEDNumbering::MAXSiStripFEDID};
185 
186  // initialiase
187  for (auto const& pr : subDetFedMap_) {
188  auto const& name = pr.first;
189  auto iPos = subDetMEsMap_.find(name);
190  if (iPos == subDetMEsMap_.end())
191  continue;
192  iPos->second.connectedFeds = 0;
193  }
194  // count sub detector feds
195 
196  for (auto const& [name, subdetIds] : subDetFedMap_) {
197  auto iPos = subDetMEsMap_.find(name);
198  if (iPos == subDetMEsMap_.end())
199  continue;
200  iPos->second.connectedFeds = 0;
201  for (auto const subdetId : subdetIds) {
202  bool fedid_found = false;
203  for (auto const fedId : fed_ids) {
204  if (fedId < siStripFedIdMin || fedId > siStripFedIdMax)
205  continue;
206  if (subdetId == fedId) {
207  fedid_found = true;
208  iPos->second.connectedFeds++;
209  break;
210  }
211  }
212  if (!fedid_found)
213  findExcludedModule(dqm_store, subdetId, tTopo);
214  }
215  if (auto nFedSubDet = subdetIds.size(); nFedSubDet > 0) {
216  iPos->second.daqFractionME->Reset();
217  int const nFedsConnected = iPos->second.connectedFeds;
218  iPos->second.daqFractionME->Fill(nFedsConnected * 1.0 / nFedSubDet);
219  }
220  }
221 }
222 //
223 // -- find Excluded Modules
224 //
226  unsigned short const fed_id,
227  TrackerTopology const* tTopo) {
228  dqm_store.cd();
229  std::string mdir = "MechanicalView";
230  if (!SiStripUtility::goToDir(dqm_store, mdir)) {
231  dqm_store.setCurrentFolder("SiStrip/" + mdir);
232  }
233  std::string mechanical_dir = dqm_store.pwd();
234  auto fedChannels = fedCabling_->fedConnections(fed_id);
235  int ichannel = 0;
236  std::string tag = "ExcludedFedChannel";
237  std::string bad_module_folder;
238  for (auto const& conn : fedChannels) {
239  if (!conn.isConnected())
240  continue;
241  uint32_t detId = conn.detId();
242  if (detId == 0 || detId == 0xFFFFFFFF)
243  continue;
244 
245  ichannel++;
246  if (ichannel == 1) {
247  std::string subdet_folder;
248  SiStripFolderOrganizer folder_organizer;
249  folder_organizer.getSubDetFolder(detId, tTopo, subdet_folder);
250  if (!dqm_store.dirExists(subdet_folder)) {
251  subdet_folder = mechanical_dir + subdet_folder.substr(subdet_folder.find(mdir) + mdir.size());
252  }
253  bad_module_folder = subdet_folder + "/" + "BadModuleList";
254  dqm_store.setCurrentFolder(bad_module_folder);
255  }
256  std::ostringstream detid_str;
257  detid_str << detId;
258  std::string full_path = bad_module_folder + "/" + detid_str.str();
259  MonitorElement* me = dqm_store.get(full_path);
260  uint16_t flag = 0;
261  if (me) {
262  flag = me->getIntValue();
263  me->Reset();
264  } else
265  me = dqm_store.bookInt(detid_str.str());
267  me->Fill(flag);
268  }
269  dqm_store.cd();
270 }
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)
std::optional< T > tryToGet() const
Definition: EventSetup.h:94
void getSubDetFolder(const uint32_t &detid, const TrackerTopology *tTopo, std::string &folder_name)
void beginRun(edm::Run const &run, edm::EventSetup const &eSetup) override
virtual int64_t getIntValue() const
std::string const & pwd() const
Definition: DQMStore.cc:618
void bookStatus(DQMStore &dqm_store)
MonitorElement * bookInt(char_string const &name)
Book int.
Definition: DQMStore.cc:1072
void cd()
go to top directory (ie. root)
Definition: DQMStore.cc:621
void Fill(long long x)
virtual void Reset()
reset ME (ie. contents, errors, etc)
MonitorElement * get(std::string const &path) const
get ME from full pathname (e.g. "my/long/dir/my_histo")
Definition: DQMStore.cc:1509
std::map< std::string, std::vector< unsigned short > > subDetFedMap_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< int > m_fed_in
Definition: RunInfo.h:25
FedsConstIterRange fedIds() const
void readFedIds(edm::ESHandle< SiStripFedCabling > const &fedcabling, edm::EventSetup const &iSetup)
const std::string subdet_tag("SubDet")
void analyze(edm::Event const &, edm::EventSetup const &) override
SiStripDaqInfo(edm::ParameterSet const &ps)
ConnsConstIterRange fedConnections(uint16_t fed_id) const
std::map< std::string, SubDetMEs > subDetMEsMap_
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:639
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_
T get() const
Definition: EventSetup.h:73
MonitorElement * bookFloat(char_string const &name)
Book float.
Definition: DQMStore.cc:1087
void fillDummyStatus(DQMStore &dqm_store)
bool isValid() const
Definition: ESHandle.h:44
unsigned long long m_cacheID_
T const * product() const
Definition: ESHandle.h:86
static void getTopFolderPath(DQMStore &dqm_store, std::string const &top_dir, std::string &path)
def move(src, dest)
Definition: eostools.py:511
#define constexpr
Definition: event.py:1
Definition: Run.h:45
edm::ESHandle< SiStripFedCabling > fedCabling_
bool dirExists(std::string const &path) const
true if directory exists
Definition: DQMStore.cc:698