CMS 3D CMS Logo

SiStripNoisesAndBadCompsChecker.cc
Go to the documentation of this file.
1 // system includes
2 #include <iostream>
3 #include <fstream>
4 
5 // user includes
12 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h" /* for STRIPS_PER_APV*/
22 
23 class SiStripNoisesAndBadCompsChecker : public edm::one::EDAnalyzer<edm::one::SharedResources> {
24 public:
25  explicit SiStripNoisesAndBadCompsChecker(const edm::ParameterSet& iConfig);
26 
27  ~SiStripNoisesAndBadCompsChecker() override = default;
28 
29  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
30 
31  void analyze(const edm::Event&, const edm::EventSetup&) override;
32 
33 private:
34  const bool writePayload_;
36  const uint32_t printdebug_;
39 
40  const std::string k_Name_ = "SiStripNoisesAndBadCompsChecker";
41  const std::string k_Record_ = "SiStripNoisesRcd";
42 };
43 
45  : writePayload_(iConfig.getUntrackedParameter<bool>("writePayload", true)),
46  fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",
48  printdebug_(iConfig.getUntrackedParameter<uint32_t>("printDebug", std::numeric_limits<unsigned int>::max())),
49  noiseToken_(esConsumes()),
50  deadChannelToken_(esConsumes()) {
52 }
53 
55  SiStripNoises obj; /* this is the output object */
56 
57  unsigned int count{0};
58 
60  const auto& DetInfos = reader.getAllData();
61 
62  auto const& deadChannel = iSetup.getData(deadChannelToken_);
63  auto const& noise = iSetup.getData(noiseToken_);
64 
65  for (const auto& it : DetInfos) {
66  const auto& nAPVs = it.second.nApvs;
67 
68  SiStripNoises::Range detNoiseRange = noise.getRange(it.first);
69 
70  // fill in the information about the dead channels
71  SiStripBadStrip::Range detBadStripRange = deadChannel.getRange(it.first);
72  std::vector<bool> badChannels;
73  badChannels.clear();
74  badChannels.insert(badChannels.begin(), sistrip::STRIPS_PER_APV * nAPVs, false);
75  for (SiStripBadStrip::ContainerIterator it2 = detBadStripRange.first; it2 != detBadStripRange.second; ++it2) {
76  SiStripBadStrip::data fs = deadChannel.decode(*it2);
77  for (int strip = fs.firstStrip; strip < fs.firstStrip + fs.range; ++strip) {
78  badChannels[strip] = true;
79  }
80  }
81 
82  SiStripNoises::InputVector theSiStripVector;
83  for (int strip = 0; strip < sistrip::STRIPS_PER_APV * nAPVs; ++strip) {
84  const auto& theNoise = noise.getNoise(strip, detNoiseRange);
85  if (!badChannels[strip]) {
86  try {
87  noise.verify(strip, detNoiseRange);
88  } catch (cms::Exception& e) {
89  if (count < printdebug_) {
90  edm::LogPrint(k_Name_) << "WARNING: out-of-range "
91  << " detid: " << it.first << " strip: " << strip << " noise:" << theNoise;
92  }
93  count++;
94  }
95  } // is strip is not masked
96  obj.setData(theNoise, theSiStripVector);
97  } // loop on the strips
98 
99  if (!obj.put(it.first, theSiStripVector))
100  edm::LogError(k_Name_) << "[SiStripNoisesAndBadCompsChecker::analyze] detid already exists";
101  } // loop on the detids
102  edm::LogPrint(k_Name_) << "Found " << count << " strips in out-of-bounds!";
103 
104  if (writePayload_) {
105  edm::LogInfo(k_Name_) << "Will write an updated fixed payload";
106 
107  //And now write sistripnoises data in DB
109 
110  if (mydbservice.isAvailable()) {
111  if (mydbservice->isNewTagRequest("SiStripNoisesRcd")) {
112  mydbservice->createOneIOV<SiStripNoises>(obj, mydbservice->beginOfTime(), k_Record_);
113  } else {
114  mydbservice->appendOneIOV<SiStripNoises>(obj, mydbservice->currentTime(), k_Record_);
115  }
116  } else {
117  edm::LogError("SiStripNoisesBuilder") << "Service is unavailable, will not write any output";
118  }
119  }
120 }
121 
122 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
125 
126  desc.setComment(
127  "Given a certain Global Tag, checks that the all the unmasked strips, do have a noise within the payload range");
128  desc.addUntracked<bool>("writePayload", true);
130  desc.addUntracked<uint32_t>("printDebug", std::numeric_limits<unsigned int>::max());
131  descriptions.addWithDefaultLabel(desc);
132 }
133 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::ESGetToken< SiStripNoises, SiStripNoisesRcd > noiseToken_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
std::string fullPath() const
Definition: FileInPath.cc:161
std::vector< unsigned int >::const_iterator ContainerIterator
std::vector< uint16_t > InputVector
Definition: SiStripNoises.h:50
reader
Definition: DQM.py:105
Log< level::Error, false > LogError
~SiStripNoisesAndBadCompsChecker() override=default
void createOneIOV(const T &payload, cond::Time_t firstSinceTime, const std::string &recordName)
const edm::ESGetToken< SiStripBadStrip, SiStripBadChannelRcd > deadChannelToken_
void appendOneIOV(const T &payload, cond::Time_t sinceTime, const std::string &recordName)
bool isNewTagRequest(const std::string &recordName)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
SiStripDetInfo read(std::string filePath)
Log< level::Warning, true > LogPrint
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Log< level::Info, false > LogInfo
SiStripNoisesAndBadCompsChecker(const edm::ParameterSet &iConfig)
static const std::string kSharedResource
void analyze(const edm::Event &, const edm::EventSetup &) override
HLT enums.
static const uint16_t STRIPS_PER_APV
std::pair< ContainerIterator, ContainerIterator > Range
static constexpr char const *const kDefaultFile
bool isAvailable() const
Definition: Service.h:40
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripNoises.h:47