test
CMS 3D CMS Logo

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