CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 {
40  // Create MessageSender
41  LogDebug( "SiStripDcsInfo") << "SiStripDcsInfo::Deleting SiStripDcsInfo ";
42 }
43 //
44 // -- Destructor
45 //
47  LogDebug("SiStripDcsInfo") << "SiStripDcsInfo::Deleting SiStripDcsInfo ";
48 
49 }
50 //
51 // -- Begin Job
52 //
55  SubDetMEs local_mes;
56 
57  tag = "TIB";
58  local_mes.folder_name = "TIB";
59  local_mes.DcsFractionME = 0;
60  local_mes.TotalDetectors = 0;
61  local_mes.FaultyDetectors.clear();
62  SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
63 
64  tag = "TOB";
65  local_mes.folder_name = "TOB";
66  local_mes.DcsFractionME = 0;
67  local_mes.TotalDetectors = 0;
68  local_mes.FaultyDetectors.clear();
69  SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
70 
71  tag = "TECB";
72  local_mes.folder_name = "TEC/MINUS";
73  local_mes.DcsFractionME = 0;
74  local_mes.TotalDetectors = 0;
75  local_mes.FaultyDetectors.clear();
76  SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
77 
78  tag = "TECF";
79  local_mes.folder_name = "TEC/PLUS";
80  local_mes.DcsFractionME = 0;
81  local_mes.TotalDetectors = 0;
82  local_mes.FaultyDetectors.clear();
83  SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
84 
85  tag = "TIDB";
86  local_mes.folder_name = "TID/MINUS";
87  local_mes.DcsFractionME = 0;
88  local_mes.TotalDetectors = 0;
89  local_mes.FaultyDetectors.clear();
90  SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
91 
92  tag = "TIDF";
93  local_mes.folder_name = "TID/PLUS";
94  local_mes.DcsFractionME = 0;
95  local_mes.TotalDetectors = 0;
96  local_mes.FaultyDetectors.clear();
97  SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
98 }
99 //
100 // -- Begin Run
101 //
103  LogDebug ("SiStripDcsInfo") <<"SiStripDcsInfo:: Begining of Run";
104  nFEDConnected_ = 0;
105  const int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
106  const int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
107 
108  // Count Tracker FEDs from RunInfo
110  if( eSetup.find( recordKey ) != 0) {
111 
112  edm::ESHandle<RunInfo> sumFED;
113  eSetup.get<RunInfoRcd>().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  fillStatus();
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);
299  }
300 }
301 //
302 // -- Fill with Dummy values
303 //
305  if (!bookedStatus_) bookStatus();
306  if (bookedStatus_) {
307  for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
308  it->second.DcsFractionME->Reset();
309  it->second.DcsFractionME->Fill(-1.0);
310  }
311  DcsFraction_->Reset();
312  DcsFraction_->Fill(-1.0);
313  }
314 }
315 //
316 // -- Add Bad Modules
317 //
319 
320  dqmStore_->cd();
321  std::string mdir = "MechanicalView";
322  if (!SiStripUtility::goToDir(dqmStore_, mdir)) {
323  dqmStore_->setCurrentFolder("SiStrip/"+mdir);
324  }
325  std::string mechanical_dir = dqmStore_->pwd();
326  std::string tag = "DCSError";
327 
328  for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
329  std::vector<uint32_t> badModules = it->second.FaultyDetectors;
330  for (std::vector<uint32_t>::iterator ibad = badModules.begin();
331  ibad != badModules.end(); ibad++) {
332 
333  std::string bad_module_folder = mechanical_dir + "/" +
334  it->second.folder_name + "/"
335  "BadModuleList";
336  dqmStore_->setCurrentFolder(bad_module_folder);
337 
338  std::ostringstream detid_str;
339  detid_str << (*ibad);
340  std::string full_path = bad_module_folder + "/" + detid_str.str();
341  MonitorElement* me = dqmStore_->get(full_path);
342  uint16_t flag = 0;
343  if (me) {
344  flag = me->getIntValue();
345  me->Reset();
346  } else me = dqmStore_->bookInt(detid_str.str());
348  me->Fill(flag);
349  }
350  }
351  dqmStore_->cd();
352 }
353 
#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.
SiStripDcsInfo(const edm::ParameterSet &ps)
Constructor.
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:684
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &iSetup)
End Of Luminosity.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
void analyze(edm::Event const &, edm::EventSetup const &)
Analyze.
MonitorElement * bookFloat(const char *name)
Book float.
Definition: DQMStore.cc:931
const eventsetup::EventSetupRecord * find(const eventsetup::EventSetupRecordKey &) const
Definition: EventSetup.cc:91
void Fill(long long x)
std::map< std::string, SubDetMEs > SubDetMEsMap
virtual ~SiStripDcsInfo()
Destructor.
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. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1748
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
edm::ESHandle< SiStripDetVOff > siStripDetVOff_
void readCabling(edm::EventSetup const &)
int64_t getIntValue(void) const
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
MonitorElement * DcsFraction_
static void getSubDetectorTag(uint32_t det_id, std::string &subdet_tag, const TrackerTopology *tTopo)
edm::ESHandle< SiStripDetCabling > detCabling_
unsigned long long m_cacheIDCabling_
std::vector< uint32_t > FaultyDetectors
void beginJob()
BeginJob.
volatile std::atomic< bool > shutdown_flag false
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:901
void Reset(void)
reset ME (ie. contents, errors, etc)
void readStatus(edm::EventSetup const &)
static bool goToDir(DQMStore *dqm_store, std::string name)
static void getTopFolderPath(DQMStore *dqm_store, std::string top_dir, std::string &path)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:707
Definition: Run.h:43
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag
Definition: HCTypeTag.cc:125
const std::string & pwd(void) const
Definition: DQMStore.cc:679