CMS 3D CMS Logo

SiStripBadModuleConfigurableFakeESSource.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CalibTracker/SiStripESProducers
4 // Class: SiStripBadModuleConfigurableFakeESSource
5 //
14 // system include files
15 #include <memory>
16 
17 // user include files
20 
26 
28 
30 public:
33 
35  const edm::IOVSyncValue& iov,
36  edm::ValidityInterval& iValidity) override;
37 
38  typedef std::unique_ptr<SiStripBadStrip> ReturnType;
40 
41 private:
42  using Parameters = std::vector<edm::ParameterSet>;
46  bool m_doByAPVs;
49 
50  std::vector<uint32_t> selectDetectors(const TrackerTopology* tTopo, const std::vector<uint32_t>& detIds) const;
51  std::vector<std::pair<uint32_t, std::vector<uint32_t>>> selectAPVs() const;
52 };
53 
57 
59  setWhatProduced(this).setConsumes(trackTopoToken_);
60  findingRecord<SiStripBadModuleRcd>();
61 
62  m_badComponentList = iConfig.getUntrackedParameter<Parameters>("BadComponentList");
63  m_doByAPVs = iConfig.getUntrackedParameter<bool>("doByAPVs", false);
64  m_badAPVsList = iConfig.getUntrackedParameter<Parameters>("BadAPVList");
65  m_printDebug = iConfig.getUntrackedParameter<bool>("printDebug", false);
67  SiStripDetInfoFileReader{iConfig.getParameter<edm::FileInPath>("SiStripDetInfoFile").fullPath()};
68 }
69 
71 
73  const edm::IOVSyncValue& iov,
74  edm::ValidityInterval& iValidity) {
75  iValidity = edm::ValidityInterval{iov.beginOfTime(), iov.endOfTime()};
76 }
77 
78 // ------------ method called to produce the data ------------
80  const SiStripBadModuleRcd& iRecord) {
81  using namespace edm::es;
82 
83  TrackerTopology const& tTopo = iRecord.get(trackTopoToken_);
84 
85  auto quality = std::make_unique<SiStripQuality>();
86 
87  if (!m_doByAPVs) {
88  std::vector<uint32_t> selDetIds{selectDetectors(&tTopo, m_detInfoFileReader.getAllDetIds())};
89  edm::LogInfo("SiStripQualityConfigurableFakeESSource")
90  << "[produce] number of selected dets to be removed " << selDetIds.size() << std::endl;
91 
92  std::stringstream ss;
93  for (const auto selId : selDetIds) {
94  SiStripQuality::InputVector theSiStripVector;
95 
96  unsigned short firstBadStrip{0};
97  unsigned short NconsecutiveBadStrips = m_detInfoFileReader.getNumberOfApvsAndStripLength(selId).first * 128;
98  unsigned int theBadStripRange{quality->encode(firstBadStrip, NconsecutiveBadStrips)};
99 
100  if (m_printDebug) {
101  ss << "detid " << selId << " \t"
102  << " firstBadStrip " << firstBadStrip << "\t "
103  << " NconsecutiveBadStrips " << NconsecutiveBadStrips << "\t "
104  << " packed integer " << std::hex << theBadStripRange << std::dec << std::endl;
105  }
106 
107  theSiStripVector.push_back(theBadStripRange);
108 
109  if (!quality->put(selId, SiStripBadStrip::Range{theSiStripVector.begin(), theSiStripVector.end()})) {
110  edm::LogError("SiStripQualityConfigurableFakeESSource") << "[produce] detid already exists";
111  }
112  }
113  if (m_printDebug) {
114  edm::LogInfo("SiStripQualityConfigurableFakeESSource") << ss.str();
115  }
116  quality->cleanUp();
117  //quality->fillBadComponents();
118  } else {
119  std::vector<std::pair<uint32_t, std::vector<uint32_t>>> selAPVs{selectAPVs()};
120  edm::LogInfo("SiStripQualityConfigurableFakeESSource")
121  << "[produce] number of selected dets to be removed " << selAPVs.size() << std::endl;
122 
123  std::stringstream ss;
124  for (const auto& selId : selAPVs) {
125  SiStripQuality::InputVector theSiStripVector;
126  auto the_detid = selId.first;
127 
128  for (const auto apv : selId.second) {
129  unsigned short firstBadStrip = apv * 128;
130  unsigned short NconsecutiveBadStrips = 128;
131  unsigned int theBadStripRange{quality->encode(firstBadStrip, NconsecutiveBadStrips)};
132 
133  if (m_printDebug) {
134  ss << "detid " << the_detid << " \t"
135  << " firstBadStrip " << firstBadStrip << "\t "
136  << " NconsecutiveBadStrips " << NconsecutiveBadStrips << "\t "
137  << " packed integer " << std::hex << theBadStripRange << std::dec << std::endl;
138  }
139 
140  theSiStripVector.push_back(theBadStripRange);
141  }
142 
143  if (!quality->put(the_detid, SiStripBadStrip::Range{theSiStripVector.begin(), theSiStripVector.end()})) {
144  edm::LogError("SiStripQualityConfigurableFakeESSource") << "[produce] detid already exists";
145  }
146  } // loop on the packed list of detid/apvs
147 
148  if (m_printDebug) {
149  edm::LogInfo("SiStripQualityConfigurableFakeESSource") << ss.str();
150  }
151  quality->cleanUp();
152 
153  } // do it by APVs
154 
155  if (m_printDebug) {
156  std::stringstream ss1;
157  for (const auto& badComp : quality->getBadComponentList()) {
158  ss1 << "bad module " << badComp.detid << " " << badComp.BadModule << "\n";
159  }
160  edm::LogInfo("SiStripQualityConfigurableFakeESSource") << ss1.str();
161  }
162 
163  return quality;
164 }
165 
166 namespace {
167  bool _isSel(uint32_t requested,
168  uint32_t i) { // internal helper: accept all i if requested is 0, otherwise require match
169  return (requested == 0) || (requested == i);
170  }
171 
172  SiStripDetId::SubDetector subDetFromString(const std::string& subDetStr) {
174  if (subDetStr == "TIB")
175  subDet = SiStripDetId::TIB;
176  else if (subDetStr == "TID")
177  subDet = SiStripDetId::TID;
178  else if (subDetStr == "TOB")
179  subDet = SiStripDetId::TOB;
180  else if (subDetStr == "TEC")
181  subDet = SiStripDetId::TEC;
182  return subDet;
183  }
184 } // namespace
185 
186 std::vector<std::pair<uint32_t, std::vector<uint32_t>>> SiStripBadModuleConfigurableFakeESSource::selectAPVs() const {
187  std::vector<std::pair<uint32_t, std::vector<uint32_t>>> selList;
188  selList.clear();
189 
190  for (const auto& badAPV : m_badAPVsList) {
191  const uint32_t det{badAPV.getParameter<uint32_t>("DetId")};
192  std::vector<uint32_t> apvs{badAPV.getParameter<std::vector<uint32_t>>("APVs")};
193  auto pair = std::make_pair(det, apvs);
194  selList.push_back(pair);
195  }
196  return selList;
197 }
198 
200  const TrackerTopology* tTopo, const std::vector<uint32_t>& detIds) const {
201  std::vector<uint32_t> selList;
202  std::stringstream ss;
203  for (const auto& badComp : m_badComponentList) {
204  const std::string subDetStr{badComp.getParameter<std::string>("SubDet")};
205  if (m_printDebug)
206  ss << "Bad SubDet " << subDetStr << " \t";
207  const SiStripDetId::SubDetector subDet = subDetFromString(subDetStr);
208 
209  const std::vector<uint32_t> genericBadDetIds{
210  badComp.getUntrackedParameter<std::vector<uint32_t>>("detidList", std::vector<uint32_t>())};
211  const bool anySubDet{!genericBadDetIds.empty()};
212 
213  std::cout << "genericBadDetIds.size() = " << genericBadDetIds.size() << std::endl;
214 
215  using DetIdIt = std::vector<uint32_t>::const_iterator;
216  const DetIdIt beginDetIt = std::lower_bound(
217  detIds.begin(), detIds.end(), DetId(DetId::Tracker, anySubDet ? SiStripDetId::TIB : subDet).rawId());
218  const DetIdIt endDetIt = std::lower_bound(
219  detIds.begin(), detIds.end(), DetId(DetId::Tracker, anySubDet ? SiStripDetId::TEC + 1 : subDet + 1).rawId());
220 
221  if (anySubDet) {
222  std::copy_if(beginDetIt, endDetIt, std::back_inserter(selList), [&genericBadDetIds](uint32_t detId) {
223  std::cout << "AnySubDet" << detId << std::endl;
224  return std::find(genericBadDetIds.begin(), genericBadDetIds.end(), detId) != genericBadDetIds.end();
225  });
226  } else {
227  switch (subDet) {
228  case SiStripDetId::TIB:
229  std::copy_if(beginDetIt, endDetIt, std::back_inserter(selList), [tTopo, &badComp](uint32_t detectorId) {
230  const DetId detId{detectorId};
231  return ((detId.subdetId() == SiStripDetId::TIB) &&
232  _isSel(badComp.getParameter<uint32_t>("layer"), tTopo->tibLayer(detId)) &&
233  _isSel(badComp.getParameter<uint32_t>("bkw_frw"), tTopo->tibIsZPlusSide(detId) ? 2 : 1) &&
234  _isSel(badComp.getParameter<uint32_t>("int_ext"), tTopo->tibIsInternalString(detId) ? 1 : 2) &&
235  _isSel(badComp.getParameter<uint32_t>("ster"),
236  tTopo->tibIsStereo(detId) ? 1 : (tTopo->tibIsRPhi(detId) ? 2 : -1)) &&
237  _isSel(badComp.getParameter<uint32_t>("string_"), tTopo->tibString(detId)) &&
238  _isSel(badComp.getParameter<uint32_t>("detid"), detId.rawId()));
239  });
240  break;
241  case SiStripDetId::TID:
242  std::copy_if(beginDetIt, endDetIt, std::back_inserter(selList), [tTopo, &badComp](uint32_t detectorId) {
243  const DetId detId{detectorId};
244  return ((detId.subdetId() == SiStripDetId::TID) &&
245  _isSel(badComp.getParameter<uint32_t>("wheel"), tTopo->tidWheel(detId)) &&
246  _isSel(badComp.getParameter<uint32_t>("side"), tTopo->tidIsZPlusSide(detId) ? 2 : 1) &&
247  _isSel(badComp.getParameter<uint32_t>("ster"),
248  tTopo->tidIsStereo(detId) ? 1 : (tTopo->tidIsRPhi(detId) ? 2 : -1)) &&
249  _isSel(badComp.getParameter<uint32_t>("ring"), tTopo->tidRing(detId)) &&
250  _isSel(badComp.getParameter<uint32_t>("detid"), detId.rawId()));
251  });
252  break;
253  case SiStripDetId::TOB:
254  std::copy_if(beginDetIt, endDetIt, std::back_inserter(selList), [tTopo, &badComp](uint32_t detectorId) {
255  const DetId detId{detectorId};
256  return ((detId.subdetId() == SiStripDetId::TOB) &&
257  _isSel(badComp.getParameter<uint32_t>("layer"), tTopo->tobLayer(detId)) &&
258  _isSel(badComp.getParameter<uint32_t>("bkw_frw"), tTopo->tobIsZPlusSide(detId) ? 2 : 1) &&
259  _isSel(badComp.getParameter<uint32_t>("ster"),
260  tTopo->tobIsStereo(detId) ? 1 : (tTopo->tobIsRPhi(detId) ? 2 : -1)) &&
261  _isSel(badComp.getParameter<uint32_t>("rod"), tTopo->tobRod(detId)) &&
262  _isSel(badComp.getParameter<uint32_t>("detid"), detId.rawId()));
263  });
264  break;
265  case SiStripDetId::TEC:
266  std::copy_if(beginDetIt, endDetIt, std::back_inserter(selList), [tTopo, &badComp](uint32_t detectorId) {
267  const DetId detId{detectorId};
268  return ((detId.subdetId() == SiStripDetId::TEC) &&
269  _isSel(badComp.getParameter<uint32_t>("wheel"), tTopo->tecWheel(detId)) &&
270  _isSel(badComp.getParameter<uint32_t>("side"), tTopo->tecIsZPlusSide(detId) ? 2 : 1) &&
271  _isSel(badComp.getParameter<uint32_t>("ster"), tTopo->tecIsStereo(detId) ? 1 : 2) &&
272  _isSel(badComp.getParameter<uint32_t>("petal_bkw_frw"), tTopo->tecIsFrontPetal(detId) ? 2 : 2) &&
273  _isSel(badComp.getParameter<uint32_t>("petal"), tTopo->tecPetalNumber(detId)) &&
274  _isSel(badComp.getParameter<uint32_t>("ring"), tTopo->tecRing(detId)) &&
275  _isSel(badComp.getParameter<uint32_t>("detid"), detId.rawId()));
276  });
277  break;
278  default:
279  break;
280  }
281  }
282  }
283  if (m_printDebug) {
284  edm::LogInfo("SiStripBadModuleGenerator") << ss.str();
285  }
286  return selList;
287 }
288 
289 //define this as a plug-in
TrackerTopology::tecIsFrontPetal
bool tecIsFrontPetal(const DetId &id) const
Definition: TrackerTopology.h:416
SiStripDetId::UNKNOWN
static constexpr auto UNKNOWN
Definition: SiStripDetId.h:36
mps_fire.i
i
Definition: mps_fire.py:355
TrackerTopology::tibIsInternalString
bool tibIsInternalString(const DetId &id) const
Definition: TrackerTopology.h:429
MessageLogger.h
SiStripBadModuleConfigurableFakeESSource
Definition: SiStripBadModuleConfigurableFakeESSource.cc:29
SiStripBadModuleConfigurableFakeESSource::SiStripBadModuleConfigurableFakeESSource
SiStripBadModuleConfigurableFakeESSource(const edm::ParameterSet &)
Definition: SiStripBadModuleConfigurableFakeESSource.cc:58
ESHandle.h
TrackerTopology::tobIsStereo
bool tobIsStereo(const DetId &id) const
Definition: TrackerTopology.h:264
contentValuesFiles.fullPath
fullPath
Definition: contentValuesFiles.py:64
TrackerTopology
Definition: TrackerTopology.h:16
TrackerTopology::tidIsRPhi
bool tidIsRPhi(const DetId &id) const
Definition: TrackerTopology.h:272
gather_cfg.cout
cout
Definition: gather_cfg.py:144
SiStripBadModuleConfigurableFakeESSource::setIntervalFor
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &iov, edm::ValidityInterval &iValidity) override
Definition: SiStripBadModuleConfigurableFakeESSource.cc:72
edm::LogInfo
Definition: MessageLogger.h:254
edm::ESProducer::setWhatProduced
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:138
edm::ValidityInterval
Definition: ValidityInterval.h:28
ESProducer.h
TrackerTopology::tecIsStereo
bool tecIsStereo(const DetId &id) const
Definition: TrackerTopology.h:265
SiStripDetId.h
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
SiStripBadStrip.h
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
SiStripDetInfoFileReader
Definition: SiStripDetInfoFileReader.h:30
edm::EventSetupRecordIntervalFinder
Definition: EventSetupRecordIntervalFinder.h:33
edm::eventsetup::EventSetupRecordKey
Definition: EventSetupRecordKey.h:30
TrackerTopology::tidRing
unsigned int tidRing(const DetId &id) const
Definition: TrackerTopology.h:218
TrackerTopology::tobIsRPhi
bool tobIsRPhi(const DetId &id) const
Definition: TrackerTopology.h:269
TrackerTopology::tobRod
unsigned int tobRod(const DetId &id) const
Definition: TrackerTopology.h:195
TrackerTopology::tidWheel
unsigned int tidWheel(const DetId &id) const
Definition: TrackerTopology.h:201
SiStripBadModuleConfigurableFakeESSource::produce
ReturnType produce(const SiStripBadModuleRcd &)
Definition: SiStripBadModuleConfigurableFakeESSource.cc:79
TrackerTopology::tidIsStereo
bool tidIsStereo(const DetId &id) const
Definition: TrackerTopology.h:267
SiStripBadModuleConfigurableFakeESSource::m_printDebug
bool m_printDebug
Definition: SiStripBadModuleConfigurableFakeESSource.cc:45
SiStripBadModuleConfigurableFakeESSource::m_badComponentList
Parameters m_badComponentList
Definition: SiStripBadModuleConfigurableFakeESSource.cc:43
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
DetId
Definition: DetId.h:17
edm::FileInPath
Definition: FileInPath.h:64
TrackerTopology.h
SiStripBadStrip::Range
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripBadStrip.h:53
SiStripBadModuleConfigurableFakeESSource::m_badAPVsList
Parameters m_badAPVsList
Definition: SiStripBadModuleConfigurableFakeESSource.cc:44
TrackerTopology::tibIsStereo
bool tibIsStereo(const DetId &id) const
Definition: TrackerTopology.h:266
TrackerTopology::tobIsZPlusSide
bool tobIsZPlusSide(const DetId &id) const
Definition: TrackerTopology.h:252
SiStripDetInfoFileReader.h
SiStripBadModuleRcd
Definition: SiStripCondDataRecords.h:16
edm::eventsetup::DependentRecordImplementation::get
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
Definition: DependentRecordImplementation.h:112
SiStripDetId::TEC
static constexpr auto TEC
Definition: SiStripDetId.h:40
cuda_std::lower_bound
__host__ constexpr __device__ RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
Definition: cudastdAlgorithm.h:27
edm::IOVSyncValue
Definition: IOVSyncValue.h:31
DEFINE_FWK_EVENTSETUP_SOURCE
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:91
EventSetupRecordIntervalFinder.h
SiStripBadModuleConfigurableFakeESSource::selectAPVs
std::vector< std::pair< uint32_t, std::vector< uint32_t > > > selectAPVs() const
Definition: SiStripBadModuleConfigurableFakeESSource.cc:186
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SiStripBadModuleConfigurableFakeESSource::trackTopoToken_
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > trackTopoToken_
Definition: SiStripBadModuleConfigurableFakeESSource.cc:48
SourceFactory.h
TrackerTopology::tibString
unsigned int tibString(const DetId &id) const
Definition: TrackerTopology.h:419
SiStripBadModuleConfigurableFakeESSource::m_doByAPVs
bool m_doByAPVs
Definition: SiStripBadModuleConfigurableFakeESSource.cc:46
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
DetId::Tracker
Definition: DetId.h:25
SiStripCondDataRecords.h
edm::IOVSyncValue::endOfTime
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
TrackerTopology::tecPetalNumber
unsigned int tecPetalNumber(const DetId &id) const
Definition: TrackerTopology.h:221
TrackerTopology::tidIsZPlusSide
bool tidIsZPlusSide(const DetId &id) const
Definition: TrackerTopology.h:258
TrackerTopology::tecRing
unsigned int tecRing(const DetId &id) const
ring id
Definition: TrackerTopology.h:217
SiStripDetId::TOB
static constexpr auto TOB
Definition: SiStripDetId.h:39
SiStripBadStrip::InputVector
Container InputVector
Definition: SiStripBadStrip.h:56
SiStripBadModuleConfigurableFakeESSource::Parameters
std::vector< edm::ParameterSet > Parameters
Definition: SiStripBadModuleConfigurableFakeESSource.cc:42
SiStripDetInfoFileReader::getAllDetIds
const std::vector< uint32_t > & getAllDetIds() const
Definition: SiStripDetInfoFileReader.h:52
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd >
SiStripDetId::TID
static constexpr auto TID
Definition: SiStripDetId.h:38
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
TrackerTopology::tobLayer
unsigned int tobLayer(const DetId &id) const
Definition: TrackerTopology.h:147
SiStripDetInfoFileReader::getNumberOfApvsAndStripLength
const std::pair< unsigned short, double > getNumberOfApvsAndStripLength(uint32_t detId) const
Definition: SiStripDetInfoFileReader.cc:101
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
qcdUeDQM_cfi.quality
quality
Definition: qcdUeDQM_cfi.py:31
SiStripBadModuleConfigurableFakeESSource::selectDetectors
std::vector< uint32_t > selectDetectors(const TrackerTopology *tTopo, const std::vector< uint32_t > &detIds) const
Definition: SiStripBadModuleConfigurableFakeESSource.cc:199
SiStripQuality.h
SiStripDetId::TIB
static constexpr auto TIB
Definition: SiStripDetId.h:37
TrackerTopology::tibIsZPlusSide
bool tibIsZPlusSide(const DetId &id) const
Definition: TrackerTopology.h:255
edm::es
Definition: es_Label.h:33
edm::IOVSyncValue::beginOfTime
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88
SiStripBadModuleConfigurableFakeESSource::~SiStripBadModuleConfigurableFakeESSource
~SiStripBadModuleConfigurableFakeESSource() override
Definition: SiStripBadModuleConfigurableFakeESSource.cc:70
SiStripBadModuleConfigurableFakeESSource::ReturnType
std::unique_ptr< SiStripBadStrip > ReturnType
Definition: SiStripBadModuleConfigurableFakeESSource.cc:38
TrackerTopology::tecIsZPlusSide
bool tecIsZPlusSide(const DetId &id) const
Definition: TrackerTopology.h:261
SiStripBadModuleConfigurableFakeESSource::m_detInfoFileReader
SiStripDetInfoFileReader m_detInfoFileReader
Definition: SiStripBadModuleConfigurableFakeESSource.cc:47
edm::ESProducer
Definition: ESProducer.h:101
ParameterSet.h
TrackerTopology::tibIsRPhi
bool tibIsRPhi(const DetId &id) const
Definition: TrackerTopology.h:271
SiStripSubdetector::Subdetector
Subdetector
Definition: SiStripEnums.h:5
TrackerTopology::tecWheel
unsigned int tecWheel(const DetId &id) const
Definition: TrackerTopology.h:198
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
TrackerTopology::tibLayer
unsigned int tibLayer(const DetId &id) const
Definition: TrackerTopology.h:150