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 // FED cabling and numbering
22 
23 #include <iostream>
24 #include <iomanip>
25 #include <cstdio>
26 #include <string>
27 #include <sstream>
28 #include <cmath>
29 #include <vector>
30 
31 //
32 // -- Contructor
33 //
35  m_cacheID_(0) {
36 
37  // Create MessageSender
38  edm::LogInfo( "SiStripDaqInfo") << "SiStripDaqInfo::Deleting SiStripDaqInfo ";
39 
40  // get back-end interface
42  nFedTotal = 0;
43  bookedStatus_ = false;
44 }
46  edm::LogInfo("SiStripDaqInfo") << "SiStripDaqInfo::Deleting SiStripDaqInfo ";
47 
48 }
49 //
50 // -- Begin Job
51 //
53 
54 }
55 //
56 // -- Book MEs for SiStrip Daq Fraction
57 //
59  edm::LogInfo( "SiStripDcsInfo") << " SiStripDaqInfo::bookStatus " << bookedStatus_;
60  if (!bookedStatus_) {
61  dqmStore_->cd();
62  std::string strip_dir = "";
63  SiStripUtility::getTopFolderPath(dqmStore_, "SiStrip", strip_dir);
64  if (!strip_dir.empty()) dqmStore_->setCurrentFolder(strip_dir+"/EventInfo");
65  else dqmStore_->setCurrentFolder("SiStrip/EventInfo");
66 
67 
68  DaqFraction_= dqmStore_->bookFloat("DAQSummary");
69 
70  dqmStore_->cd();
71  if (!strip_dir.empty()) dqmStore_->setCurrentFolder(strip_dir+"/EventInfo/DAQContents");
72  else dqmStore_->setCurrentFolder("SiStrip/EventInfo/DAQContents");
73 
74  std::vector<std::string> det_type;
75  det_type.push_back("TIB");
76  det_type.push_back("TOB");
77  det_type.push_back("TIDF");
78  det_type.push_back("TIDB");
79  det_type.push_back("TECF");
80  det_type.push_back("TECB");
81 
82  for ( std::vector<std::string>::iterator it = det_type.begin(); it != det_type.end(); it++) {
83  std::string det = (*it);
84 
85  SubDetMEs local_mes;
86  std::string me_name;
87  me_name = "SiStrip_" + det;
88  local_mes.DaqFractionME = dqmStore_->bookFloat(me_name);
89  local_mes.ConnectedFeds = 0;
90  SubDetMEsMap.insert(make_pair(det, local_mes));
91  }
92  bookedStatus_ = true;
93  dqmStore_->cd();
94  }
95 }
96 //
97 // -- Fill with Dummy values
98 //
100  if (!bookedStatus_) bookStatus();
101  if (bookedStatus_) {
102  for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
103  it->second.DaqFractionME->Reset();
104  it->second.DaqFractionME->Fill(-1.0);
105  }
106  DaqFraction_->Reset();
107  DaqFraction_->Fill(-1.0);
108  }
109 }
110 //
111 // -- Begin Run
112 //
114  edm::LogInfo ("SiStripDaqInfo") <<"SiStripDaqInfo:: Begining of Run";
115 
116  // Check latest Fed cabling and create TrackerMapCreator
117  unsigned long long cacheID = eSetup.get<SiStripFedCablingRcd>().cacheIdentifier();
118  if (m_cacheID_ != cacheID) {
119  m_cacheID_ = cacheID;
120 
121  eSetup.get<SiStripFedCablingRcd>().get(fedCabling_);
122 
123  readFedIds(fedCabling_, eSetup);
124  }
125  if (!bookedStatus_) bookStatus();
126  if (nFedTotal == 0) {
127  fillDummyStatus();
128  edm::LogInfo ("SiStripDaqInfo") <<" SiStripDaqInfo::No FEDs Connected!!!";
129  return;
130  }
131 
132  float nFEDConnected = 0.0;
133  const int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
134  const int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
135 
136  if(auto runInfoRec = eSetup.tryToGet<RunInfoRcd>()) {
137 
138  edm::ESHandle<RunInfo> sumFED;
139  runInfoRec->get(sumFED);
140 
141  if ( sumFED.isValid() ) {
142  std::vector<int> FedsInIds= sumFED->m_fed_in;
143  for(unsigned int it = 0; it < FedsInIds.size(); ++it) {
144  int fedID = FedsInIds[it];
145 
146  if(fedID>=siStripFedIdMin && fedID<=siStripFedIdMax) ++nFEDConnected;
147  }
148  edm::LogInfo ("SiStripDaqInfo") <<" SiStripDaqInfo::Total # of FEDs " << nFedTotal
149  << " Connected FEDs " << nFEDConnected;
150  if (nFEDConnected > 0) {
151  DaqFraction_->Reset();
152  DaqFraction_->Fill(nFEDConnected/nFedTotal);
153  readSubdetFedFractions(FedsInIds,eSetup);
154  }
155  }
156  }
157 }
158 //
159 // -- Analyze
160 //
162 }
163 
164 //
165 // -- End Luminosity Block
166 //
168  edm::LogInfo( "SiStripDaqInfo") << "SiStripDaqInfo::endLuminosityBlock";
169 }
170 //
171 // -- End Run
172 //
174  edm::LogInfo ("SiStripDaqInfo") <<"SiStripDaqInfo::EndRun";
175 }
176 //
177 // -- Read Sub Detector FEDs
178 //
180 
181  //Retrieve tracker topology from geometry
182  edm::ESHandle<TrackerTopology> tTopoHandle;
183  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
184  const TrackerTopology* const tTopo = tTopoHandle.product();
185 
186  auto feds = fedCabling_->fedIds();
187 
188  nFedTotal = feds.size();
189  for(std::vector<unsigned short>::const_iterator ifed = feds.begin(); ifed != feds.end(); ifed++){
190  auto fedChannels = fedCabling_->fedConnections( *ifed );
191  for (auto iconn = fedChannels.begin(); iconn < fedChannels.end(); iconn++){
192  if (!iconn->isConnected()) continue;
193  uint32_t detId = iconn->detId();
194  if (detId == 0 || detId == 0xFFFFFFFF) continue;
196  SiStripUtility::getSubDetectorTag(detId,subdet_tag,tTopo);
197  subDetFedMap[subdet_tag].push_back(*ifed);
198  break;
199  }
200  }
201 }
202 //
203 // -- Fill Subdet FEDIds
204 //
205 void SiStripDaqInfo::readSubdetFedFractions(std::vector<int>& fed_ids, edm::EventSetup const& iSetup) {
206 
207  //Retrieve tracker topology from geometry
208  edm::ESHandle<TrackerTopology> tTopoHandle;
209  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
210  const TrackerTopology* const tTopo = tTopoHandle.product();
211 
212  const int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
213  const int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
214 
215  // initialiase
216  for (std::map<std::string, std::vector<unsigned short> >::const_iterator it = subDetFedMap.begin();
217  it != subDetFedMap.end(); it++) {
218  std::string name = it->first;
219  std::map<std::string, SubDetMEs>::iterator iPos = SubDetMEsMap.find(name);
220  if (iPos == SubDetMEsMap.end()) continue;
221  iPos->second.ConnectedFeds = 0;
222  }
223  // count sub detector feds
224 
225 
226  for (std::map<std::string, std::vector<unsigned short> >::const_iterator it = subDetFedMap.begin();
227  it != subDetFedMap.end(); it++) {
228  std::string name = it->first;
229  std::vector<unsigned short> subdetIds = it->second;
230  std::map<std::string, SubDetMEs>::iterator iPos = SubDetMEsMap.find(name);
231  if (iPos == SubDetMEsMap.end()) continue;
232  iPos->second.ConnectedFeds = 0;
233  for (std::vector<unsigned short>::iterator iv = subdetIds.begin();
234  iv != subdetIds.end(); iv++) {
235  bool fedid_found = false;
236  for(unsigned int it = 0; it < fed_ids.size(); ++it) {
237  unsigned short fedID = fed_ids[it];
238  if(fedID < siStripFedIdMin || fedID > siStripFedIdMax) continue;
239  if ((*iv) == fedID) {
240  fedid_found = true;
241  iPos->second.ConnectedFeds++;
242  break;
243  }
244  }
245  if (!fedid_found) findExcludedModule((*iv),tTopo);
246  }
247  int nFedsConnected = iPos->second.ConnectedFeds;
248  int nFedSubDet = subdetIds.size();
249  if (nFedSubDet > 0) {
250  iPos->second.DaqFractionME->Reset();
251  iPos->second.DaqFractionME->Fill(nFedsConnected*1.0/nFedSubDet);
252  }
253  }
254 }
255 //
256 // -- find Excluded Modules
257 //
258 void SiStripDaqInfo::findExcludedModule(unsigned short fed_id, const TrackerTopology* tTopo) {
259  dqmStore_->cd();
260  std::string mdir = "MechanicalView";
261  if (!SiStripUtility::goToDir(dqmStore_, mdir)) {
262  dqmStore_->setCurrentFolder("SiStrip/"+mdir);
263  }
264  std::string mechanical_dir = dqmStore_->pwd();
265  auto fedChannels = fedCabling_->fedConnections(fed_id);
266  int ichannel = 0;
267  std::string tag = "ExcludedFedChannel";
268  std::string bad_module_folder;
269  for (std::vector<FedChannelConnection>::const_iterator iconn = fedChannels.begin();
270  iconn < fedChannels.end(); iconn++){
271  if (!iconn->isConnected()) continue;
272  uint32_t detId = iconn->detId();
273  if (detId == 0 || detId == 0xFFFFFFFF) continue;
274 
275  ichannel++;
276  if (ichannel == 1) {
277  std::string subdet_folder ;
278  SiStripFolderOrganizer folder_organizer;
279  folder_organizer.getSubDetFolder(detId,tTopo,subdet_folder);
280  if (!dqmStore_->dirExists(subdet_folder)) {
281  subdet_folder = mechanical_dir + subdet_folder.substr(subdet_folder.find(mdir)+mdir.size());
282  }
283  bad_module_folder = subdet_folder + "/" + "BadModuleList";
284  dqmStore_->setCurrentFolder(bad_module_folder);
285  }
286  std::ostringstream detid_str;
287  detid_str << detId;
288  std::string full_path = bad_module_folder + "/" + detid_str.str();
289  MonitorElement* me = dqmStore_->get(full_path);
290  uint16_t flag = 0;
291  if (me) {
292  flag = me->getIntValue();
293  me->Reset();
294  } else me = dqmStore_->bookInt(detid_str.str());
296  me->Fill(flag);
297  }
298  dqmStore_->cd();
299 }
static void setBadModuleFlag(std::string &hname, uint16_t &flg)
std::optional< T > tryToGet() const
Definition: EventSetup.h:80
int64_t getIntValue() const
void getSubDetFolder(const uint32_t &detid, const TrackerTopology *tTopo, std::string &folder_name)
void readFedIds(const edm::ESHandle< SiStripFedCabling > &fedcabling, edm::EventSetup const &iSetup)
void beginRun(edm::Run const &run, edm::EventSetup const &eSetup) override
Begin Run.
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
MonitorElement * bookInt(char_string const &name)
Book int.
Definition: DQMStore.cc:1015
void findExcludedModule(unsigned short fed_id, const TrackerTopology *tTopo)
MonitorElement * bookFloat(char_string const &name)
Book float.
Definition: DQMStore.cc:1036
void Fill(long long x)
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &iSetup) override
End Of Luminosity.
edm::ESHandle< SiStripFedCabling > fedCabling_
void beginJob() override
BeginJob.
bool dirExists(std::string const &path) const
true if directory exists
Definition: DQMStore.cc:629
std::vector< int > m_fed_in
Definition: RunInfo.h:26
FedsConstIterRange fedIds() const
MonitorElement * get(std::string const &path) const
get ME from full pathname (e.g. "my/long/dir/my_histo")
Definition: DQMStore.cc:1601
const std::string subdet_tag("SubDet")
void analyze(edm::Event const &, edm::EventSetup const &) override
Analyze.
SiStripDaqInfo(const edm::ParameterSet &ps)
Constructor.
void endRun(edm::Run const &run, edm::EventSetup const &eSetup) override
EndRun.
void Reset()
reset ME (ie. contents, errors, etc)
DQMStore * dqmStore_
std::map< std::string, SubDetMEs > SubDetMEsMap
std::string const & pwd() const
Definition: DQMStore.cc:533
~SiStripDaqInfo() override
Destructor.
std::map< std::string, std::vector< unsigned short > > subDetFedMap
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:565
void cd()
go to top directory (ie. root)
Definition: DQMStore.cc:540
MonitorElement * DaqFractionME
void readSubdetFedFractions(std::vector< int > &fed_ids, edm::EventSetup const &iSetup)
ConnsConstIterRange fedConnections(uint16_t fed_id) const
static void getSubDetectorTag(uint32_t det_id, std::string &subdet_tag, const TrackerTopology *tTopo)
T get() const
Definition: EventSetup.h:62
void fillDummyStatus()
MonitorElement * DaqFraction_
bool isValid() const
Definition: ESHandle.h:47
unsigned long long m_cacheID_
static bool goToDir(DQMStore *dqm_store, std::string name)
T const * product() const
Definition: ESHandle.h:86
static void getTopFolderPath(DQMStore *dqm_store, std::string top_dir, std::string &path)
Definition: event.py:1
Definition: Run.h:44