CMS 3D CMS Logo

SiStripDcsInfo.cc
Go to the documentation of this file.
4 
7 
11 
16 
17 //Run Info
22 
23 #include <iostream>
24 #include <iomanip>
25 #include <stdio.h>
26 #include <string>
27 #include <sstream>
28 #include <math.h>
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 = 0;
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 = 0;
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 = 0;
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 = 0;
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 = 0;
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 = 0;
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
111  if( eSetup.find( recordKey ) != 0) {
112 
113  edm::ESHandle<RunInfo> sumFED;
114  eSetup.get<RunInfoRcd>().get(sumFED);
115 
116  if ( sumFED.isValid() ) {
117  std::vector<int> FedsInIds= sumFED->m_fed_in;
118  for(unsigned int it = 0; it < FedsInIds.size(); ++it) {
119  int fedID = FedsInIds[it];
120  if(fedID>=siStripFedIdMin && fedID<=siStripFedIdMax) ++nFEDConnected_;
121  }
122  LogDebug ("SiStripDcsInfo") << " SiStripDcsInfo :: Connected FEDs " << nFEDConnected_;
123  }
124  }
125 
126  bookStatus();
127  fillDummyStatus();
128  if (nFEDConnected_ > 0) readCabling(eSetup);
129 }
130 //
131 // -- Analyze
132 //
134 }
135 //
136 // -- Begin Luminosity Block
137 //
139  LogDebug( "SiStripDcsInfo") << "SiStripDcsInfo::beginLuminosityBlock";
140 
141  if (nFEDConnected_ == 0) return;
142 
143  // initialise BadModule list
144  for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
145  it->second.FaultyDetectors.clear();
146  }
147  readStatus(eSetup);
148  nLumiAnalysed_++;
149 }
150 
151 //
152 // -- End Luminosity Block
153 //
155  LogDebug( "SiStripDcsInfo") << "SiStripDcsInfo::endLuminosityBlock";
156 
157  if (nFEDConnected_ == 0) return;
158  readStatus(eSetup);
159  fillStatus();
160 }
161 //
162 // -- End Run
163 //
165  LogDebug ("SiStripDcsInfo") <<"SiStripDcsInfo::EndRun";
166 
167  if (nFEDConnected_ == 0) return;
168 
169  for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
170  it->second.FaultyDetectors.clear();
171  }
172  readStatus(eSetup);
173  addBadModules();
174 }
175 //
176 // -- Book MEs for SiStrip Dcs Fraction
177 //
179  if (!bookedStatus_) {
180  std::string strip_dir = "";
181  SiStripUtility::getTopFolderPath(dqmStore_, "SiStrip", strip_dir);
182  if (strip_dir.size() > 0) dqmStore_->setCurrentFolder(strip_dir+"/EventInfo");
183  else dqmStore_->setCurrentFolder("SiStrip/EventInfo");
184 
185  DcsFraction_= dqmStore_->bookFloat("DCSSummary");
186 
188 
189  dqmStore_->cd();
190  if (strip_dir.size() > 0) dqmStore_->setCurrentFolder(strip_dir+"/EventInfo/DCSContents");
191  else dqmStore_->setCurrentFolder("SiStrip/EventInfo/DCSContents");
192  for (std::map<std::string,SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
193  SubDetMEs local_mes;
194  std::string me_name;
195  me_name = "SiStrip_" + it->first;
196  it->second.DcsFractionME = dqmStore_->bookFloat(me_name);
197  it->second.DcsFractionME->setLumiFlag();
198  }
199  bookedStatus_ = true;
200  dqmStore_->cd();
201  }
202 }
203 //
204 // -- Read Cabling
205 //
207 
208  //Retrieve tracker topology from geometry
209  edm::ESHandle<TrackerTopology> tTopoHandle;
210  eSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
211  const TrackerTopology* const tTopo = tTopoHandle.product();
212 
213  unsigned long long cacheID = eSetup.get<SiStripFedCablingRcd>().cacheIdentifier();
214  if (m_cacheIDCabling_ != cacheID) {
215  m_cacheIDCabling_ = cacheID;
216  LogDebug("SiStripDcsInfo") <<"SiStripDcsInfo::readCabling : "
217  << " Change in Cache";
218  eSetup.get<SiStripDetCablingRcd>().get(detCabling_);
219 
220  std::vector<uint32_t> SelectedDetIds;
221  detCabling_->addActiveDetectorsRawIds(SelectedDetIds);
222  LogDebug( "SiStripDcsInfo") << " SiStripDcsInfo::readCabling : "
223  << " Total Detectors " << SelectedDetIds.size();
224 
225 
226  // initialise total # of detectors first
227  for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
228  it->second.TotalDetectors = 0;
229  }
230 
231  for (std::vector<uint32_t>::const_iterator idetid=SelectedDetIds.begin(); idetid != SelectedDetIds.end(); ++idetid){
232  uint32_t detId = *idetid;
233  if (detId == 0 || detId == 0xFFFFFFFF) continue;
235  SiStripUtility::getSubDetectorTag(detId,subdet_tag,tTopo);
236 
237  std::map<std::string, SubDetMEs>::iterator iPos = SubDetMEsMap.find(subdet_tag);
238  if (iPos != SubDetMEsMap.end()){
239  iPos->second.TotalDetectors++;
240  }
241  }
242  }
243 }
244 //
245 // -- Get Faulty Detectors
246 //
248 
249  //Retrieve tracker topology from geometry
250  edm::ESHandle<TrackerTopology> tTopoHandle;
251  eSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
252  const TrackerTopology* const tTopo = tTopoHandle.product();
253 
254  eSetup.get<SiStripDetVOffRcd>().get(siStripDetVOff_);
255  std::vector <uint32_t> FaultyDetIds;
256  siStripDetVOff_->getDetIds(FaultyDetIds);
257  LogDebug( "SiStripDcsInfo") << " SiStripDcsInfo::readStatus : "
258  << " Faulty Detectors " << FaultyDetIds.size();
259  // Read and fille bad modules
260  for (std::vector<uint32_t>::const_iterator ihvoff=FaultyDetIds.begin(); ihvoff!=FaultyDetIds.end();++ihvoff){
261  uint32_t detId_hvoff = (*ihvoff);
262  if (!detCabling_->IsConnected(detId_hvoff)) continue;
264  SiStripUtility::getSubDetectorTag(detId_hvoff,subdet_tag,tTopo);
265 
266  std::map<std::string, SubDetMEs>::iterator iPos = SubDetMEsMap.find(subdet_tag);
267  if (iPos != SubDetMEsMap.end()){
268  std::vector<uint32_t>::iterator ibad = std::find(iPos->second.FaultyDetectors.begin(), iPos->second.FaultyDetectors.end(), detId_hvoff);
269  if (ibad == iPos->second.FaultyDetectors.end()) iPos->second.FaultyDetectors.push_back( detId_hvoff);
270  }
271  }
272 }
273 //
274 // -- Fill Status
275 //
277  if (!bookedStatus_) bookStatus();
278  if (bookedStatus_) {
279  float total_det = 0.0;
280  float faulty_det = 0.0;
281  float fraction;
282  for (std::map<std::string,SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
283  int total_subdet = it->second.TotalDetectors;
284  int faulty_subdet = it->second.FaultyDetectors.size();
285  if (nFEDConnected_ == 0 || total_subdet == 0) fraction = -1;
286  else fraction = 1.0 - faulty_subdet*1.0/total_subdet;
287  it->second.DcsFractionME->Reset();
288  it->second.DcsFractionME->Fill(fraction);
289  edm::LogInfo( "SiStripDcsInfo") << " SiStripDcsInfo::fillStatus : Sub Detector "
290  << it->first << " Total Number " << total_subdet
291  << " Faulty ones " << faulty_subdet;
292  total_det += total_subdet;
293  faulty_det += faulty_subdet;
294  }
295  if (nFEDConnected_ == 0 || total_det == 0) fraction = -1.0;
296  else fraction = 1 - faulty_det/total_det;
297  DcsFraction_->Reset();
298  DcsFraction_->Fill(fraction);
301  for (std::map<std::string,SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
302  for (std::vector<uint32_t>::iterator ifaulty = it->second.FaultyDetectors.begin(); ifaulty != it->second.FaultyDetectors.end(); ifaulty++) {
303  uint32_t detId_faulty = (*ifaulty);
304  if(IsLumiGoodDcs_) it->second.NLumiDetectorIsFaulty[detId_faulty]++;
305  }
306  }
307  }
308 }
309 //
310 // -- Fill with Dummy values
311 //
313  if (!bookedStatus_) bookStatus();
314  if (bookedStatus_) {
315  for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
316  it->second.DcsFractionME->Reset();
317  it->second.DcsFractionME->Fill(-1.0);
318  }
319  DcsFraction_->Reset();
320  DcsFraction_->Fill(-1.0);
321  }
322 }
323 //
324 // -- Add Bad Modules
325 //
327 
328  dqmStore_->cd();
329  std::string mdir = "MechanicalView";
330  if (!SiStripUtility::goToDir(dqmStore_, mdir)) {
331  dqmStore_->setCurrentFolder("SiStrip/"+mdir);
332  }
333  std::string mechanical_dir = dqmStore_->pwd();
334  std::string tag = "DCSError";
335 
336  for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
337 
338  std::unordered_map<uint32_t,uint16_t> lumiCountBadModules = it->second.NLumiDetectorIsFaulty;
339  for(std::unordered_map<uint32_t,uint16_t>::iterator ilumibad = lumiCountBadModules.begin();
340  ilumibad != lumiCountBadModules.end(); ilumibad++) {
341  uint32_t ibad = (*ilumibad).first;
342  uint32_t nBadLumi = (*ilumibad).second;
343  if(nBadLumi <= MaxAcceptableBadDcsLumi_) continue;
344  std::string bad_module_folder = mechanical_dir + "/" +
345  it->second.folder_name + "/"
346  "BadModuleList";
347  dqmStore_->setCurrentFolder(bad_module_folder);
348 
349  std::ostringstream detid_str;
350  detid_str << ibad;
351  std::string full_path = bad_module_folder + "/" + detid_str.str();
352  MonitorElement* me = dqmStore_->get(full_path);
353  uint16_t flag = 0;
354  if (me) {
355  flag = me->getIntValue();
356  me->Reset();
357  } else me = dqmStore_->bookInt(detid_str.str());
359  me->Fill(flag);
360  }
361  }
362  dqmStore_->cd();
363 }
364 
#define LogDebug(id)
static void setBadModuleFlag(std::string &hname, uint16_t &flg)
DQMStore * dqmStore_
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &eSetup)
Begin Luminosity Block.
void beginRun(edm::Run const &run, edm::EventSetup const &eSetup)
Begin Run.
void addActiveDetectorsRawIds(std::vector< uint32_t > &) const
SiStripDcsInfo(const edm::ParameterSet &ps)
Constructor.
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:718
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &iSetup)
End Of Luminosity.
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag
float MaxAcceptableBadDcsLumi_
bool IsConnected(const uint32_t &det_id) const
float MinAcceptableDcsDetFrac_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
void analyze(edm::Event const &, edm::EventSetup const &)
Analyze.
MonitorElement * bookFloat(const char *name)
Book float.
Definition: DQMStore.cc:972
const eventsetup::EventSetupRecord * find(const eventsetup::EventSetupRecordKey &) const
Definition: EventSetup.cc:91
void Fill(long long x)
void getDetIds(std::vector< uint32_t > &DetIds_) const
std::map< std::string, SubDetMEs > SubDetMEsMap
virtual ~SiStripDcsInfo()
Destructor.
std::vector< int > m_fed_in
Definition: RunInfo.h:26
const std::string subdet_tag("SubDet")
void endRun(edm::Run const &run, edm::EventSetup const &eSetup)
EndRun.
MonitorElement * DcsFractionME
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. "my/long/dir/my_histo")
Definition: DQMStore.cc:1789
edm::ESHandle< SiStripDetVOff > siStripDetVOff_
void readCabling(edm::EventSetup const &)
int64_t getIntValue(void) const
const T & get() const
Definition: EventSetup.h:55
MonitorElement * DcsFraction_
static void getSubDetectorTag(uint32_t det_id, std::string &subdet_tag, const TrackerTopology *tTopo)
edm::ESHandle< SiStripDetCabling > detCabling_
HLT enums.
unsigned long long m_cacheIDCabling_
std::vector< uint32_t > FaultyDetectors
void beginJob()
BeginJob.
void setLumiFlag(void)
this ME is meant to be stored for each luminosity section
bool isValid() const
Definition: ESHandle.h:47
MonitorElement * bookInt(const char *name)
Book int.
Definition: DQMStore.cc:942
void Reset(void)
reset ME (ie. contents, errors, etc)
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)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:741
Definition: event.py:1
Definition: Run.h:42
const std::string & pwd(void) const
Definition: DQMStore.cc:713