CMS 3D CMS Logo

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