CMS 3D CMS Logo

SiStripBadModuleFedErrESSource.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CalibTracker/SiStripESProducers
4 // Class: SiStripBadModuleFedErrESSource
5 //
30 // system include files
31 #include <memory>
32 
33 // user include files
36 
39 
40 class DQMStore;
41 class MonitorElement;
42 
44 public:
47 
49 
50  typedef std::shared_ptr<SiStripBadStrip> ReturnType;
51  ReturnType produce( const SiStripBadModuleFedErrRcd& );
52 
53 private:
54  bool m_readFlag;
56  float m_cutoff;
57 
58  std::vector<std::pair<uint16_t,uint16_t>> getFedBadChannelList( DQMStore* dqmStore, const MonitorElement* me ) const;
59  float getProcessedEvents( DQMStore* dqmStore ) const;
60 };
61 
69 
71 {
72  setWhatProduced(this);
73  findingRecord<SiStripBadModuleFedErrRcd>();
74 
75  m_readFlag = iConfig.getParameter<bool>("ReadFromFile");
76  m_fileName = iConfig.getParameter<std::string>("FileName");
77  m_cutoff = iConfig.getParameter<double>("BadStripCutoff");
78 }
79 
81 
83 {
84  iValidity = edm::ValidityInterval{iov.beginOfTime(), iov.endOfTime()};
85 }
86 
88 {
89  dqmStore->cd();
90 
91  const std::string dname{"SiStrip/ReadoutView"};
92  const std::string hpath{dname+"/nTotalBadActiveChannels"};
93  if ( dqmStore->dirExists(dname) ) {
94  MonitorElement* me = dqmStore->get(hpath);
95  if (me) return me->getEntries();
96  }
97  return 0;
98 }
99 
100 std::vector<std::pair<uint16_t,uint16_t>> SiStripBadModuleFedErrESSource::getFedBadChannelList( DQMStore* dqmStore, const MonitorElement* me ) const
101 {
102  std::vector<std::pair<uint16_t,uint16_t>> ret;
103  if (me->kind() == MonitorElement::DQM_KIND_TH2F) {
104  TH2F* th2 = me->getTH2F();
105  float entries = getProcessedEvents(dqmStore);
106  if ( ! entries ) entries = th2->GetBinContent(th2->GetMaximumBin());
107  for ( uint16_t i = 1; i < th2->GetNbinsY()+1; ++i ) {
108  for ( uint16_t j = 1; j < th2->GetNbinsX()+1; ++j ) {
109  if ( th2->GetBinContent(j,i) > m_cutoff * entries ) {
110  edm::LogInfo("SiStripBadModuleFedErrService") << " [SiStripBadModuleFedErrService::getFedBadChannelList] :: FedId & Channel " << th2->GetYaxis()->GetBinLowEdge(i) << " " << th2->GetXaxis()->GetBinLowEdge(j);
111  ret.push_back(std::pair<uint16_t, uint16_t>(th2->GetYaxis()->GetBinLowEdge(i), th2->GetXaxis()->GetBinLowEdge(j)));
112  }
113  }
114  }
115  }
116  return ret;
117 }
118 
119 // ------------ method called to produce the data ------------
122 {
123  using namespace edm::es;
124 
126  iRecord.getRecord<SiStripFedCablingRcd>().get(cabling);
127 
128  std::shared_ptr<SiStripQuality> quality{new SiStripQuality};
129 
130  DQMStore* dqmStore = edm::Service<DQMStore>().operator->();
131  if ( m_readFlag ) { // open requested file
132  edm::LogInfo("SiStripBadModuleFedErrService") << "[SiStripBadModuleFedErrService::openRequestedFile] Accessing root File" << m_fileName;
133  if ( ! dqmStore->load(m_fileName, DQMStore::OpenRunDirs::StripRunDirs, true) ) {
134  edm::LogError("SiStripBadModuleFedErrService")<<"[SiStripBadModuleFedErrService::openRequestedFile] Requested file " << m_fileName << "Can not be opened!! ";
135  return quality;
136  }
137  }
138 
139  dqmStore->cd();
140 
141  const std::string dname{"SiStrip/ReadoutView"};
142  const std::string hpath{dname + "/FedIdVsApvId"};
143  if ( dqmStore->dirExists(dname) ) {
144  MonitorElement* me = dqmStore->get(hpath);
145  if ( me ) {
146  std::map<uint32_t, std::set<int>> detectorMap;
147  for ( const auto& elm : getFedBadChannelList(dqmStore, me) ) {
148  const uint16_t fId = elm.first;
149  const uint16_t fChan = elm.second/2;
150  if ( ( fId == 9999 ) && ( fChan == 9999 ) ) continue;
151 
152  FedChannelConnection channel = cabling->fedConnection(fId, fChan);
153  detectorMap[channel.detId()].insert(channel.apvPairNumber());
154  }
155 
156  for ( const auto& detElm : detectorMap ) { // pair(detId, pairs)
157  SiStripQuality::InputVector theSiStripVector;
158  unsigned short firstBadStrip{0};
159  unsigned short fNconsecutiveBadStrips{0};
160  int last_pair = -1;
161  for ( const auto pair : detElm.second ) {
162  if ( last_pair == -1 ) {
163  firstBadStrip = pair * 128*2;
164  fNconsecutiveBadStrips = 128*2;
165  } else if ( pair - last_pair > 1 ) {
166  theSiStripVector.push_back(quality->encode(firstBadStrip, fNconsecutiveBadStrips));
167  firstBadStrip = pair * 128*2;
168  fNconsecutiveBadStrips = 128*2;
169  } else {
170  fNconsecutiveBadStrips += 128*2;
171  }
172  last_pair = pair;
173  }
174  unsigned int theBadStripRange = quality->encode(firstBadStrip, fNconsecutiveBadStrips);
175  theSiStripVector.push_back(theBadStripRange);
176 
177  edm::LogInfo("SiStripBadModuleFedErrService")
178  << " SiStripBadModuleFedErrService::readBadComponentsFromFed "
179  << " detid " << detElm.first
180  << " firstBadStrip " << firstBadStrip
181  << " NconsecutiveBadStrips " << fNconsecutiveBadStrips
182  << " packed integer " << std::hex << theBadStripRange << std::dec;
183 
184  if ( ! quality->put(detElm.first, SiStripBadStrip::Range{theSiStripVector.begin(), theSiStripVector.end()}) ) {
185  edm::LogError("SiStripBadModuleFedErrService") << "[SiStripBadModuleFedErrService::readBadComponentsFromFed] detid already exists";
186  }
187  }
188  quality->cleanUp();
189  }
190  }
191 
192  return quality;
193 }
194 
195 //define this as a plug-in
T getParameter(std::string const &) const
SiStripBadModuleFedErrESSource(const edm::ParameterSet &)
FedChannelConnection fedConnection(uint16_t fed_id, uint16_t fed_ch) const
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:718
uint16_t apvPairNumber() const
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:97
std::shared_ptr< SiStripBadStrip > ReturnType
double getEntries(void) const
get # of entries
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
static const IOVSyncValue & beginOfTime()
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &iov, edm::ValidityInterval &iValidity)
const uint32_t & detId() const
Class containning control, module, detector and connection information, at the level of a FED channel...
Kind kind(void) const
Get the type of the monitor element.
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. "my/long/dir/my_histo")
Definition: DQMStore.cc:1789
bool dirExists(const std::string &path) const
true if directory exists
Definition: DQMStore.cc:806
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:92
std::vector< std::pair< uint16_t, uint16_t > > getFedBadChannelList(DQMStore *dqmStore, const MonitorElement *me) const
float getProcessedEvents(DQMStore *dqmStore) const
std::pair< ContainerIterator, ContainerIterator > Range
ReturnType produce(const SiStripBadModuleFedErrRcd &)
TH2F * getTH2F(void) const
Container InputVector