CMS 3D CMS Logo

SiPixelFEDChannelContainerFromQualityConverter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CondFormats/SiPixelObjects
4 // Class: SiPixelFEDChannelContainerFromQualityConverter
5 //
9 //
10 // Original Author: Marco Musich
11 // Created: Wed, 27 Nov 2018 12:04:36 GMT
12 //
13 //
14 
15 // system include files
16 #include <memory>
17 
18 // user include files
36 
37 //
38 // class declaration
39 //
40 
42 public:
45 
46  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
48  const SiPixelQuality& theQuality, const SiPixelFedCablingMap& theFedCabling);
49 
50 private:
51  void beginJob() override;
52  void analyze(const edm::Event&, const edm::EventSetup&) override;
53  void endJob() override;
54 
55  // ----------member data ---------------------------
58 
60  const bool printdebug_;
61  const bool isMC_;
63  std::unique_ptr<SiPixelFEDChannelContainer> myQualities;
64 
65  int IOVcount_;
67 };
68 
69 //
70 // constructors and destructor
71 //
73  const edm::ParameterSet& iConfig)
74  : siPixelQualityToken_(esConsumes()),
75  siPixelCablingToken_(esConsumes()),
76  m_record(iConfig.getParameter<std::string>("record")),
77  printdebug_(iConfig.getUntrackedParameter<bool>("printDebug", false)),
78  isMC_(iConfig.getUntrackedParameter<bool>("isMC", true)),
79  removeEmptyPayloads_(iConfig.getUntrackedParameter<bool>("removeEmptyPayloads", false)) {
80  //now do what ever initialization is needed
81  myQualities = std::make_unique<SiPixelFEDChannelContainer>();
82 }
83 
85 
86 //
87 // member functions
88 //
89 
90 // ------------ method called for each event ------------
92  using namespace edm;
93 
94  unsigned int RunNumber_ = iEvent.eventAuxiliary().run();
95  unsigned int LuminosityBlockNumber_ = iEvent.eventAuxiliary().luminosityBlock();
96 
97  bool hasQualityIOV = SiPixelQualityWatcher_.check(iSetup);
98 
99  if (hasQualityIOV) {
100  //Retrieve the strip quality from conditions
103 
104  std::string scenario = std::to_string(RunNumber_) + "_" + std::to_string(LuminosityBlockNumber_);
105 
106  edm::LogInfo("SiPixelFEDChannelContainerFromQualityConverter")
107  << "Found IOV:" << RunNumber_ << "(" << LuminosityBlockNumber_ << ")" << std::endl;
108 
109  auto theSiPixelFEDChannelCollection =
110  this->createFromSiPixelQuality(*(siPixelQuality_.product()), *(cablingMapHandle.product()));
111 
112  if (removeEmptyPayloads_ && theSiPixelFEDChannelCollection.empty())
113  return;
114 
115  myQualities->setScenario(scenario, theSiPixelFEDChannelCollection);
116 
117  IOVcount_++;
118  }
119 }
120 
121 // ------------ method called once each job just before starting event loop ------------
124  const SiPixelFedCablingMap& theFedCabling) {
125  auto fedid_ = theFedCabling.det2fedMap();
126 
128 
129  auto theDisabledModules = theQuality.getBadComponentList();
130  for (const auto& mod : theDisabledModules) {
131  //mod.DetID, mod.errorType,mod.BadRocs
132 
133  int coded_badRocs = mod.BadRocs;
134  std::vector<PixelFEDChannel> disabledChannelsDetSet;
135  std::vector<sipixelobjects::CablingPathToDetUnit> path = theFedCabling.pathToDetUnit(mod.DetID);
136  auto cabling_ = theFedCabling.cablingTree();
137  unsigned int nrocs_inLink(0);
138  if (!path.empty()) {
139  const sipixelobjects::PixelFEDCabling* aFed = cabling_->fed(path.at(0).fed);
140  const sipixelobjects::PixelFEDLink* link = aFed->link(path.at(0).link);
141  nrocs_inLink = link->numberOfROCs();
142  } else {
143  throw cms::Exception("Inconsistent data") << "could not find CablingPathToDetUnit for detId:" << mod.DetID;
144  }
145 
146  std::bitset<16> bad_rocs(coded_badRocs);
147  unsigned int n_ch = bad_rocs.size() / nrocs_inLink;
148 
149  for (unsigned int i_roc = 0; i_roc < n_ch; ++i_roc) {
150  unsigned int first_idx = nrocs_inLink * i_roc;
151  unsigned int sec_idx = nrocs_inLink * (i_roc + 1) - 1;
152  unsigned int mask = pow(2, nrocs_inLink) - 1;
153  unsigned int n_setbits = (coded_badRocs >> (i_roc * nrocs_inLink)) & mask;
154 
155  if (n_setbits == 0) {
156  continue;
157  }
158 
159  if (n_setbits != mask) {
160  edm::LogWarning("SiPixelFEDChannelContainerFromQualityConverter")
161  << "Mismatch! DetId: " << mod.DetID << " " << n_setbits << " " << mask << std::endl;
162  continue;
163  }
164 
165  if (printdebug_) {
166  edm::LogVerbatim("SiPixelFEDChannelContainerFromQualityConverter") << "passed" << std::endl;
167  }
168 
169  unsigned int link_id = 99999;
170  unsigned int fed_id = 99999;
171 
172  for (auto const& p : path) {
173  const sipixelobjects::PixelFEDCabling* aFed = cabling_->fed(p.fed);
174  const sipixelobjects::PixelFEDLink* link = aFed->link(p.link);
175  const sipixelobjects::PixelROC* roc = link->roc(p.roc);
176  unsigned int first_roc = roc->idInDetUnit();
177 
178  if (first_roc == first_idx) {
179  link_id = p.link;
180  fed_id = p.fed;
181  break;
182  }
183  }
184 
185  if (printdebug_) {
186  edm::LogVerbatim("SiPixelFEDChannelContainerFromQualityConverter")
187  << " " << fed_id << " " << link_id << " " << first_idx << " " << sec_idx << std::endl;
188  }
189 
190  PixelFEDChannel ch = {fed_id, link_id, first_idx, sec_idx};
191  disabledChannelsDetSet.push_back(ch);
192 
193  if (printdebug_) {
194  edm::LogVerbatim("SiPixelFEDChannelContainerFromQualityConverter")
195  << i_roc << " " << coded_badRocs << " " << first_idx << " " << sec_idx << std::endl;
196  edm::LogVerbatim("SiPixelFEDChannelContainerFromQualityConverter")
197  << "=======================================" << std::endl;
198  }
199  }
200 
201  if (!disabledChannelsDetSet.empty()) {
202  theBadChannelCollection[mod.DetID] = disabledChannelsDetSet;
203  }
204  }
205  return theBadChannelCollection;
206 }
207 
209 
210 // ------------ method called once each job just after ending the event loop ------------
212  edm::LogInfo("SiPixelFEDChannelContainerFromQualityConverter") << "Analyzed " << IOVcount_ << " IOVs" << std::endl;
213  edm::LogInfo("SiPixelFEDChannelContainerFromQualityConverter")
214  << "Size of SiPixelFEDChannelContainer object " << myQualities->size() << std::endl
215  << std::endl;
216 
217  if (printdebug_) {
218  edm::LogInfo("SiPixelFEDChannelContainerFromQualityConverter")
219  << "Content of SiPixelFEDChannelContainer " << std::endl;
220 
221  // use built-in method in the CondFormat
222  myQualities->printAll();
223  }
224 
225  // Form the data here
227  if (poolDbService.isAvailable()) {
228  cond::Time_t valid_time = poolDbService->currentTime();
229  // this writes the payload to begin in current run defined in cfg
230  if (!isMC_) {
231  poolDbService->writeOneIOV(*myQualities, valid_time, m_record);
232  } else {
233  // for MC IOV since=1
234  poolDbService->writeOneIOV(*myQualities, 1, m_record);
235  }
236  }
237 }
238 
239 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
242  desc.setComment("Writes payloads of type SiPixelFEDChannelContainer");
243  desc.addUntracked<bool>("printDebug", false);
244  desc.addUntracked<bool>("removeEmptyPayloads", false);
245  desc.add<std::string>("record", "SiPixelStatusScenariosRcd");
246  descriptions.add("SiPixelFEDChannelContainerFromQualityConverter", desc);
247 }
248 
249 //define this as a plug-in
Log< level::Info, true > LogVerbatim
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const PixelFEDLink * link(unsigned int id) const
return link identified by id. Link id&#39;s are ranged [1, numberOfLinks]
std::unique_ptr< SiPixelFedCablingTree > cablingTree() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::string to_string(const V &value)
Definition: OMSAccess.h:71
std::vector< sipixelobjects::CablingPathToDetUnit > pathToDetUnit(uint32_t rawDetId) const final
scenario
Definition: constants.h:173
constexpr uint32_t mask
Definition: gpuClustering.h:26
int iEvent
Definition: GenABIO.cc:224
T const * product() const
Definition: ESHandle.h:86
const std::vector< disabledModuleType > getBadComponentList() const
unsigned long long Time_t
Definition: Time.h:14
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void analyze(const edm::Event &, const edm::EventSetup &) override
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
const edm::ESGetToken< SiPixelQuality, SiPixelQualityFromDbRcd > siPixelQualityToken_
Log< level::Info, false > LogInfo
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
const edm::ESGetToken< SiPixelFedCablingMap, SiPixelFedCablingMapRcd > siPixelCablingToken_
HLT enums.
SiPixelFEDChannelContainer::SiPixelFEDChannelCollection createFromSiPixelQuality(const SiPixelQuality &theQuality, const SiPixelFedCablingMap &theFedCabling)
std::unordered_map< uint32_t, unsigned int > det2fedMap() const final
bool isAvailable() const
Definition: Service.h:40
Log< level::Warning, false > LogWarning
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
std::map< DetId, std::vector< PixelFEDChannel > > SiPixelFEDChannelCollection