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
21 
22 #include <iostream>
23 #include <iomanip>
24 #include <stdio.h>
25 #include <string>
26 #include <sstream>
27 #include <math.h>
28 
29 //
30 // -- Contructor
31 //
33  dqmStore_(edm::Service<DQMStore>().operator->()),
34  m_cacheIDCabling_(0),
35  m_cacheIDDcs_(0),
36  bookedStatus_(false),
37  nLumiAnalysed_(0)
38 {
39  // Create MessageSender
40  LogDebug( "SiStripDcsInfo") << "SiStripDcsInfo::Deleting SiStripDcsInfo ";
41 }
42 //
43 // -- Destructor
44 //
46  LogDebug("SiStripDcsInfo") << "SiStripDcsInfo::Deleting SiStripDcsInfo ";
47 
48 }
49 //
50 // -- Begin Job
51 //
53  std::string tag;
54  SubDetMEs local_mes;
55 
56  tag = "TIB";
57  local_mes.folder_name = "TIB";
58  local_mes.DcsFractionME = 0;
59  local_mes.TotalDetectors = 0;
60  local_mes.FaultyDetectors.clear();
61  SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
62 
63  tag = "TOB";
64  local_mes.folder_name = "TOB";
65  local_mes.DcsFractionME = 0;
66  local_mes.TotalDetectors = 0;
67  local_mes.FaultyDetectors.clear();
68  SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
69 
70  tag = "TECB";
71  local_mes.folder_name = "TEC/side_1";
72  local_mes.DcsFractionME = 0;
73  local_mes.TotalDetectors = 0;
74  local_mes.FaultyDetectors.clear();
75  SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
76 
77  tag = "TECF";
78  local_mes.folder_name = "TEC/side_2";
79  local_mes.DcsFractionME = 0;
80  local_mes.TotalDetectors = 0;
81  local_mes.FaultyDetectors.clear();
82  SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
83 
84  tag = "TIDB";
85  local_mes.folder_name = "TID/side_1";
86  local_mes.DcsFractionME = 0;
87  local_mes.TotalDetectors = 0;
88  local_mes.FaultyDetectors.clear();
89  SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
90 
91  tag = "TIDF";
92  local_mes.folder_name = "TID/side_2";
93  local_mes.DcsFractionME = 0;
94  local_mes.TotalDetectors = 0;
95  local_mes.FaultyDetectors.clear();
96  SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
97 }
98 //
99 // -- Begin Run
100 //
102  LogDebug ("SiStripDcsInfo") <<"SiStripDcsInfo:: Begining of Run";
103  nFEDConnected_ = 0;
104  const int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
105  const int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
106 
107  // Count Tracker FEDs from RunInfo
109  if( eSetup.find( recordKey ) != 0) {
110 
111  edm::ESHandle<RunInfo> sumFED;
112  eSetup.get<RunInfoRcd>().get(sumFED);
113 
114  if ( sumFED.isValid() ) {
115  std::vector<int> FedsInIds= sumFED->m_fed_in;
116  for(unsigned int it = 0; it < FedsInIds.size(); ++it) {
117  int fedID = FedsInIds[it];
118  if(fedID>=siStripFedIdMin && fedID<=siStripFedIdMax) ++nFEDConnected_;
119  }
120  LogDebug ("SiStripDcsInfo") << " SiStripDcsInfo :: Connected FEDs " << nFEDConnected_;
121  }
122  }
123 
124  bookStatus();
125  fillDummyStatus();
126  if (nFEDConnected_ > 0) readCabling(eSetup);
127 }
128 //
129 // -- Analyze
130 //
132 }
133 //
134 // -- Begin Luminosity Block
135 //
137  LogDebug( "SiStripDcsInfo") << "SiStripDcsInfo::beginLuminosityBlock";
138 
139  if (nFEDConnected_ == 0) return;
140 
141  // initialise BadModule list
142  for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
143  it->second.FaultyDetectors.clear();
144  }
145  readStatus(eSetup);
146  nLumiAnalysed_++;
147 }
148 
149 //
150 // -- End Luminosity Block
151 //
153  LogDebug( "SiStripDcsInfo") << "SiStripDcsInfo::endLuminosityBlock";
154 
155  if (nFEDConnected_ == 0) return;
156  readStatus(eSetup);
157  fillStatus();
158 }
159 //
160 // -- End Run
161 //
163  LogDebug ("SiStripDcsInfo") <<"SiStripDcsInfo::EndRun";
164 
165  if (nFEDConnected_ == 0) return;
166 
167  for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
168  it->second.FaultyDetectors.clear();
169  }
170  readStatus(eSetup);
171  fillStatus();
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.size() > 0) 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.size() > 0) 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  unsigned long long cacheID = eSetup.get<SiStripFedCablingRcd>().cacheIdentifier();
207  if (m_cacheIDCabling_ != cacheID) {
208  m_cacheIDCabling_ = cacheID;
209  LogDebug("SiStripDcsInfo") <<"SiStripDcsInfo::readCabling : "
210  << " Change in Cache";
211  eSetup.get<SiStripDetCablingRcd>().get(detCabling_);
212 
213  std::vector<uint32_t> SelectedDetIds;
214  detCabling_->addActiveDetectorsRawIds(SelectedDetIds);
215  LogDebug( "SiStripDcsInfo") << " SiStripDcsInfo::readCabling : "
216  << " Total Detectors " << SelectedDetIds.size();
217 
218 
219  // initialise total # of detectors first
220  for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
221  it->second.TotalDetectors = 0;
222  }
223 
224  for (std::vector<uint32_t>::const_iterator idetid=SelectedDetIds.begin(); idetid != SelectedDetIds.end(); ++idetid){
225  uint32_t detId = *idetid;
226  if (detId == 0 || detId == 0xFFFFFFFF) continue;
227  std::string subdet_tag;
228  SiStripUtility::getSubDetectorTag(detId,subdet_tag);
229 
230  std::map<std::string, SubDetMEs>::iterator iPos = SubDetMEsMap.find(subdet_tag);
231  if (iPos != SubDetMEsMap.end()){
232  iPos->second.TotalDetectors++;
233  }
234  }
235  }
236 }
237 //
238 // -- Get Faulty Detectors
239 //
241 
242  eSetup.get<SiStripDetVOffRcd>().get(siStripDetVOff_);
243  std::vector <uint32_t> FaultyDetIds;
244  siStripDetVOff_->getDetIds(FaultyDetIds);
245  LogDebug( "SiStripDcsInfo") << " SiStripDcsInfo::readStatus : "
246  << " Faulty Detectors " << FaultyDetIds.size();
247  // Read and fille bad modules
248  for (std::vector<uint32_t>::const_iterator ihvoff=FaultyDetIds.begin(); ihvoff!=FaultyDetIds.end();++ihvoff){
249  uint32_t detId_hvoff = (*ihvoff);
250  if (!detCabling_->IsConnected(detId_hvoff)) continue;
251  std::string subdet_tag;
252  SiStripUtility::getSubDetectorTag(detId_hvoff,subdet_tag);
253 
254  std::map<std::string, SubDetMEs>::iterator iPos = SubDetMEsMap.find(subdet_tag);
255  if (iPos != SubDetMEsMap.end()){
256  std::vector<uint32_t>::iterator ibad = std::find(iPos->second.FaultyDetectors.begin(), iPos->second.FaultyDetectors.end(), detId_hvoff);
257  if (ibad == iPos->second.FaultyDetectors.end()) iPos->second.FaultyDetectors.push_back( detId_hvoff);
258  }
259  }
260 }
261 //
262 // -- Fill Status
263 //
265  if (!bookedStatus_) bookStatus();
266  if (bookedStatus_) {
267  float total_det = 0.0;
268  float faulty_det = 0.0;
269  float fraction;
270  for (std::map<std::string,SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
271  int total_subdet = it->second.TotalDetectors;
272  int faulty_subdet = it->second.FaultyDetectors.size();
273  if (nFEDConnected_ == 0 || total_subdet == 0) fraction = -1;
274  else fraction = 1.0 - faulty_subdet*1.0/total_subdet;
275  it->second.DcsFractionME->Reset();
276  it->second.DcsFractionME->Fill(fraction);
277  edm::LogInfo( "SiStripDcsInfo") << " SiStripDcsInfo::fillStatus : Sub Detector "
278  << it->first << " Total Number " << total_subdet
279  << " Faulty ones " << faulty_subdet;
280  total_det += total_subdet;
281  faulty_det += faulty_subdet;
282  }
283  if (nFEDConnected_ == 0 || total_det == 0) fraction = -1.0;
284  else fraction = 1 - faulty_det/total_det;
285  DcsFraction_->Reset();
286  DcsFraction_->Fill(fraction);
287  }
288 }
289 //
290 // -- Fill with Dummy values
291 //
293  if (!bookedStatus_) bookStatus();
294  if (bookedStatus_) {
295  for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
296  it->second.DcsFractionME->Reset();
297  it->second.DcsFractionME->Fill(-1.0);
298  }
299  DcsFraction_->Reset();
300  DcsFraction_->Fill(-1.0);
301  }
302 }
303 //
304 // -- Add Bad Modules
305 //
307 
308  dqmStore_->cd();
309  std::string mdir = "MechanicalView";
310  if (!SiStripUtility::goToDir(dqmStore_, mdir)) {
311  dqmStore_->setCurrentFolder("SiStrip/"+mdir);
312  }
313  std::string mechanical_dir = dqmStore_->pwd();
314  std::string tag = "DCSError";
315 
316  for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
317  std::vector<uint32_t> badModules = it->second.FaultyDetectors;
318  for (std::vector<uint32_t>::iterator ibad = badModules.begin();
319  ibad != badModules.end(); ibad++) {
320 
321  std::string bad_module_folder = mechanical_dir + "/" +
322  it->second.folder_name + "/"
323  "BadModuleList";
324  dqmStore_->setCurrentFolder(bad_module_folder);
325 
326  std::ostringstream detid_str;
327  detid_str << (*ibad);
328  std::string full_path = bad_module_folder + "/" + detid_str.str();
329  MonitorElement* me = dqmStore_->get(full_path);
330  uint16_t flag = 0;
331  if (me) {
332  flag = me->getIntValue();
333  me->Reset();
334  } else me = dqmStore_->bookInt(detid_str.str());
336  me->Fill(flag);
337  }
338  }
339  dqmStore_->cd();
340 }
341 
#define LogDebug(id)
static void setBadModuleFlag(std::string &hname, uint16_t &flg)
DQMStore * dqmStore_
long int flag
Definition: mlp_lapack.h:47
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:406
#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:654
static void getSubDetectorTag(uint32_t det_id, std::string &subdet_tag)
const eventsetup::EventSetupRecord * find(const eventsetup::EventSetupRecordKey &) const
Definition: EventSetup.cc:90
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:1468
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:55
MonitorElement * DcsFraction_
edm::ESHandle< SiStripDetCabling > detCabling_
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:37
MonitorElement * bookInt(const char *name)
Book int.
Definition: DQMStore.cc:624
void Reset(void)
reset ME (ie. contents, errors, etc)
void readStatus(edm::EventSetup const &)
static bool goToDir(DQMStore *dqm_store, std::string name)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
Definition: Run.h:33
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag
Definition: HCTypeTag.cc:129
const std::string & pwd(void) const
Definition: DQMStore.cc:401
static void getTopFolderPath(DQMStore *dqm_store, std::string type, std::string &path)