CMS 3D CMS Logo

SiStripDcsInfo.cc
Go to the documentation of this file.
4 
7 
9 #include "SiStripDcsInfo.h"
11 
16 
17 //Run Info
22 
23 #include <iostream>
24 #include <iomanip>
25 #include <cstdio>
26 #include <string>
27 #include <sstream>
28 #include <cmath>
29 
30 //
31 // -- Contructor
32 //
34  dqmStore_(edm::Service<DQMStore>().operator->()),
35  m_cacheIDCabling_(0),
36  m_cacheIDDcs_(0),
37  bookedStatus_(false),
38  nLumiAnalysed_(0),
39  nGoodDcsLumi_(0)
40 {
41  // Create MessageSender
42  LogDebug( "SiStripDcsInfo") << "SiStripDcsInfo::Deleting SiStripDcsInfo ";
43 }
44 //
45 // -- Destructor
46 //
48  LogDebug("SiStripDcsInfo") << "SiStripDcsInfo::Deleting SiStripDcsInfo ";
49 
50 }
51 //
52 // -- Begin Job
53 //
56  SubDetMEs local_mes;
57 
58  tag = "TIB";
59  local_mes.folder_name = "TIB";
60  local_mes.DcsFractionME = nullptr;
61  local_mes.TotalDetectors = 0;
62  local_mes.FaultyDetectors.clear();
63  SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
64 
65  tag = "TOB";
66  local_mes.folder_name = "TOB";
67  local_mes.DcsFractionME = nullptr;
68  local_mes.TotalDetectors = 0;
69  local_mes.FaultyDetectors.clear();
70  SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
71 
72  tag = "TECB";
73  local_mes.folder_name = "TEC/MINUS";
74  local_mes.DcsFractionME = nullptr;
75  local_mes.TotalDetectors = 0;
76  local_mes.FaultyDetectors.clear();
77  SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
78 
79  tag = "TECF";
80  local_mes.folder_name = "TEC/PLUS";
81  local_mes.DcsFractionME = nullptr;
82  local_mes.TotalDetectors = 0;
83  local_mes.FaultyDetectors.clear();
84  SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
85 
86  tag = "TIDB";
87  local_mes.folder_name = "TID/MINUS";
88  local_mes.DcsFractionME = nullptr;
89  local_mes.TotalDetectors = 0;
90  local_mes.FaultyDetectors.clear();
91  SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
92 
93  tag = "TIDF";
94  local_mes.folder_name = "TID/PLUS";
95  local_mes.DcsFractionME = nullptr;
96  local_mes.TotalDetectors = 0;
97  local_mes.FaultyDetectors.clear();
98  SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
99 }
100 //
101 // -- Begin Run
102 //
104  LogDebug ("SiStripDcsInfo") <<"SiStripDcsInfo:: Begining of Run";
105  nFEDConnected_ = 0;
106  const int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
107  const int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
108 
109  // Count Tracker FEDs from RunInfo
110  if(auto runInfoRec = eSetup.tryToGet<RunInfoRcd>()) {
111 
112  edm::ESHandle<RunInfo> sumFED;
113  runInfoRec->get(sumFED);
114 
115  if ( sumFED.isValid() ) {
116  std::vector<int> FedsInIds= sumFED->m_fed_in;
117  for(unsigned int it = 0; it < FedsInIds.size(); ++it) {
118  int fedID = FedsInIds[it];
119  if(fedID>=siStripFedIdMin && fedID<=siStripFedIdMax) ++nFEDConnected_;
120  }
121  LogDebug ("SiStripDcsInfo") << " SiStripDcsInfo :: Connected FEDs " << nFEDConnected_;
122  }
123  }
124 
125  bookStatus();
126  fillDummyStatus();
127  if (nFEDConnected_ > 0) readCabling(eSetup);
128 }
129 //
130 // -- Analyze
131 //
133 }
134 //
135 // -- Begin Luminosity Block
136 //
138  LogDebug( "SiStripDcsInfo") << "SiStripDcsInfo::beginLuminosityBlock";
139 
140  if (nFEDConnected_ == 0) return;
141 
142  // initialise BadModule list
143  for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
144  it->second.FaultyDetectors.clear();
145  }
146  readStatus(eSetup);
147  nLumiAnalysed_++;
148 }
149 
150 //
151 // -- End Luminosity Block
152 //
154  LogDebug( "SiStripDcsInfo") << "SiStripDcsInfo::endLuminosityBlock";
155 
156  if (nFEDConnected_ == 0) return;
157  readStatus(eSetup);
158  fillStatus();
159 }
160 //
161 // -- End Run
162 //
164  LogDebug ("SiStripDcsInfo") <<"SiStripDcsInfo::EndRun";
165 
166  if (nFEDConnected_ == 0) return;
167 
168  for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
169  it->second.FaultyDetectors.clear();
170  }
171  readStatus(eSetup);
172  addBadModules();
173 }
174 //
175 // -- Book MEs for SiStrip Dcs Fraction
176 //
178  if (!bookedStatus_) {
179  std::string strip_dir = "";
180  SiStripUtility::getTopFolderPath(dqmStore_, "SiStrip", strip_dir);
181  if (!strip_dir.empty()) dqmStore_->setCurrentFolder(strip_dir+"/EventInfo");
182  else dqmStore_->setCurrentFolder("SiStrip/EventInfo");
183 
184  DcsFraction_= dqmStore_->bookFloat("DCSSummary");
185 
187 
188  dqmStore_->cd();
189  if (!strip_dir.empty()) dqmStore_->setCurrentFolder(strip_dir+"/EventInfo/DCSContents");
190  else dqmStore_->setCurrentFolder("SiStrip/EventInfo/DCSContents");
191  for (std::map<std::string,SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
192  SubDetMEs local_mes;
193  std::string me_name;
194  me_name = "SiStrip_" + it->first;
195  it->second.DcsFractionME = dqmStore_->bookFloat(me_name);
196  it->second.DcsFractionME->setLumiFlag();
197  }
198  bookedStatus_ = true;
199  dqmStore_->cd();
200  }
201 }
202 //
203 // -- Read Cabling
204 //
206 
207  //Retrieve tracker topology from geometry
208  edm::ESHandle<TrackerTopology> tTopoHandle;
209  eSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
210  const TrackerTopology* const tTopo = tTopoHandle.product();
211 
212  unsigned long long cacheID = eSetup.get<SiStripFedCablingRcd>().cacheIdentifier();
213  if (m_cacheIDCabling_ != cacheID) {
214  m_cacheIDCabling_ = cacheID;
215  LogDebug("SiStripDcsInfo") <<"SiStripDcsInfo::readCabling : "
216  << " Change in Cache";
217  eSetup.get<SiStripDetCablingRcd>().get(detCabling_);
218 
219  std::vector<uint32_t> SelectedDetIds;
220  detCabling_->addActiveDetectorsRawIds(SelectedDetIds);
221  LogDebug( "SiStripDcsInfo") << " SiStripDcsInfo::readCabling : "
222  << " Total Detectors " << SelectedDetIds.size();
223 
224 
225  // initialise total # of detectors first
226  for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
227  it->second.TotalDetectors = 0;
228  }
229 
230  for (std::vector<uint32_t>::const_iterator idetid=SelectedDetIds.begin(); idetid != SelectedDetIds.end(); ++idetid){
231  uint32_t detId = *idetid;
232  if (detId == 0 || detId == 0xFFFFFFFF) continue;
234  SiStripUtility::getSubDetectorTag(detId,subdet_tag,tTopo);
235 
236  std::map<std::string, SubDetMEs>::iterator iPos = SubDetMEsMap.find(subdet_tag);
237  if (iPos != SubDetMEsMap.end()){
238  iPos->second.TotalDetectors++;
239  }
240  }
241  }
242 }
243 //
244 // -- Get Faulty Detectors
245 //
247 
248  //Retrieve tracker topology from geometry
249  edm::ESHandle<TrackerTopology> tTopoHandle;
250  eSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
251  const TrackerTopology* const tTopo = tTopoHandle.product();
252 
253  eSetup.get<SiStripDetVOffRcd>().get(siStripDetVOff_);
254  std::vector <uint32_t> FaultyDetIds;
255  siStripDetVOff_->getDetIds(FaultyDetIds);
256  LogDebug( "SiStripDcsInfo") << " SiStripDcsInfo::readStatus : "
257  << " Faulty Detectors " << FaultyDetIds.size();
258  // Read and fille bad modules
259  for (std::vector<uint32_t>::const_iterator ihvoff=FaultyDetIds.begin(); ihvoff!=FaultyDetIds.end();++ihvoff){
260  uint32_t detId_hvoff = (*ihvoff);
261  if (!detCabling_->IsConnected(detId_hvoff)) continue;
263  SiStripUtility::getSubDetectorTag(detId_hvoff,subdet_tag,tTopo);
264 
265  std::map<std::string, SubDetMEs>::iterator iPos = SubDetMEsMap.find(subdet_tag);
266  if (iPos != SubDetMEsMap.end()){
267  std::vector<uint32_t>::iterator ibad = std::find(iPos->second.FaultyDetectors.begin(), iPos->second.FaultyDetectors.end(), detId_hvoff);
268  if (ibad == iPos->second.FaultyDetectors.end()) iPos->second.FaultyDetectors.push_back( detId_hvoff);
269  }
270  }
271 }
272 //
273 // -- Fill Status
274 //
276  if (!bookedStatus_) bookStatus();
277  if (bookedStatus_) {
278  float total_det = 0.0;
279  float faulty_det = 0.0;
280  float fraction;
281  for (std::map<std::string,SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
282  int total_subdet = it->second.TotalDetectors;
283  int faulty_subdet = it->second.FaultyDetectors.size();
284  if (nFEDConnected_ == 0 || total_subdet == 0) fraction = -1;
285  else fraction = 1.0 - faulty_subdet*1.0/total_subdet;
286  it->second.DcsFractionME->Reset();
287  it->second.DcsFractionME->Fill(fraction);
288  edm::LogInfo( "SiStripDcsInfo") << " SiStripDcsInfo::fillStatus : Sub Detector "
289  << it->first << " Total Number " << total_subdet
290  << " Faulty ones " << faulty_subdet;
291  total_det += total_subdet;
292  faulty_det += faulty_subdet;
293  }
294  if (nFEDConnected_ == 0 || total_det == 0) fraction = -1.0;
295  else fraction = 1 - faulty_det/total_det;
296  DcsFraction_->Reset();
297  DcsFraction_->Fill(fraction);
300  for (std::map<std::string,SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
301  for (std::vector<uint32_t>::iterator ifaulty = it->second.FaultyDetectors.begin(); ifaulty != it->second.FaultyDetectors.end(); ifaulty++) {
302  uint32_t detId_faulty = (*ifaulty);
303  if(IsLumiGoodDcs_) it->second.NLumiDetectorIsFaulty[detId_faulty]++;
304  }
305  }
306  }
307 }
308 //
309 // -- Fill with Dummy values
310 //
312  if (!bookedStatus_) bookStatus();
313  if (bookedStatus_) {
314  for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
315  it->second.DcsFractionME->Reset();
316  it->second.DcsFractionME->Fill(-1.0);
317  }
318  DcsFraction_->Reset();
319  DcsFraction_->Fill(-1.0);
320  }
321 }
322 //
323 // -- Add Bad Modules
324 //
326 
327  dqmStore_->cd();
328  std::string mdir = "MechanicalView";
329  if (!SiStripUtility::goToDir(dqmStore_, mdir)) {
330  dqmStore_->setCurrentFolder("SiStrip/"+mdir);
331  }
332  std::string mechanical_dir = dqmStore_->pwd();
333  std::string tag = "DCSError";
334 
335  for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
336 
337  std::unordered_map<uint32_t,uint16_t> lumiCountBadModules = it->second.NLumiDetectorIsFaulty;
338  for(std::unordered_map<uint32_t,uint16_t>::iterator ilumibad = lumiCountBadModules.begin();
339  ilumibad != lumiCountBadModules.end(); ilumibad++) {
340  uint32_t ibad = (*ilumibad).first;
341  uint32_t nBadLumi = (*ilumibad).second;
342  if(nBadLumi <= MaxAcceptableBadDcsLumi_) continue;
343  std::string bad_module_folder = mechanical_dir + "/" +
344  it->second.folder_name + "/"
345  "BadModuleList";
346  dqmStore_->setCurrentFolder(bad_module_folder);
347 
348  std::ostringstream detid_str;
349  detid_str << ibad;
350  std::string full_path = bad_module_folder + "/" + detid_str.str();
351  MonitorElement* me = dqmStore_->get(full_path);
352  uint16_t flag = 0;
353  if (me) {
354  flag = me->getIntValue();
355  me->Reset();
356  } else me = dqmStore_->bookInt(detid_str.str());
358  me->Fill(flag);
359  }
360  }
361  dqmStore_->cd();
362 }
363 
#define LogDebug(id)
static void setBadModuleFlag(std::string &hname, uint16_t &flg)
DQMStore * dqmStore_
std::optional< T > tryToGet() const
Definition: EventSetup.h:80
int64_t getIntValue() const
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &iSetup) override
End Of Luminosity.
void addActiveDetectorsRawIds(std::vector< uint32_t > &) const
SiStripDcsInfo(const edm::ParameterSet &ps)
Constructor.
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
float MaxAcceptableBadDcsLumi_
bool IsConnected(const uint32_t &det_id) const
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &eSetup) override
Begin Luminosity Block.
float MinAcceptableDcsDetFrac_
MonitorElement * bookInt(char_string const &name)
Book int.
Definition: DQMStore.cc:1015
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
MonitorElement * bookFloat(char_string const &name)
Book float.
Definition: DQMStore.cc:1036
void Fill(long long x)
void setLumiFlag()
this ME is meant to be stored for each luminosity section
void getDetIds(std::vector< uint32_t > &DetIds_) const
std::map< std::string, SubDetMEs > SubDetMEsMap
std::vector< int > m_fed_in
Definition: RunInfo.h:26
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")
MonitorElement * DcsFractionME
~SiStripDcsInfo() override
Destructor.
void Reset()
reset ME (ie. contents, errors, etc)
std::string const & pwd() const
Definition: DQMStore.cc:533
edm::ESHandle< SiStripDetVOff > siStripDetVOff_
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:565
void readCabling(edm::EventSetup const &)
void cd()
go to top directory (ie. root)
Definition: DQMStore.cc:540
void beginRun(edm::Run const &run, edm::EventSetup const &eSetup) override
Begin Run.
MonitorElement * DcsFraction_
static void getSubDetectorTag(uint32_t det_id, std::string &subdet_tag, const TrackerTopology *tTopo)
void beginJob() override
BeginJob.
void endRun(edm::Run const &run, edm::EventSetup const &eSetup) override
EndRun.
edm::ESHandle< SiStripDetCabling > detCabling_
HLT enums.
void analyze(edm::Event const &, edm::EventSetup const &) override
Analyze.
T get() const
Definition: EventSetup.h:62
unsigned long long m_cacheIDCabling_
std::vector< uint32_t > FaultyDetectors
bool isValid() const
Definition: ESHandle.h:47
void readStatus(edm::EventSetup const &)
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