CMS 3D CMS Logo

SiStripNoisesGetAllChecker.cc
Go to the documentation of this file.
16 
17 #include <iostream>
18 #include <exception>
19 
21 public:
23  ~SiStripNoisesGetAllChecker() override = default;
24 
25  void analyze(const edm::Event&, const edm::EventSetup&) override;
26 
27 private:
30  void checkModuleNoise(const SiStripNoises&, const uint32_t detID, uint16_t maxNStrips);
31 };
32 
34  : noisesToken_(esConsumes()), tkGeomToken_(esConsumes()) {}
35 
37  const auto& siStripNoises = iSetup.getData(noisesToken_);
38 
39  const auto& tkGeom = &iSetup.getData(tkGeomToken_);
40  const auto& tkDets = tkGeom->dets();
41 
42  edm::LogInfo("SiStripNoisesGetAllChecker") << "Starting to loop over all SiStrip modules...";
43 
44  // Get all DetIDs associated with SiStripNoises
45  std::vector<uint32_t> detIDs;
46  siStripNoises.getDetIds(detIDs);
47 
48  size_t exceptionCounts{0};
49  for (const auto& detID : detIDs) {
50  uint16_t maxNStrips{0};
51  auto det = std::find_if(tkDets.begin(), tkDets.end(), [detID](auto& elem) -> bool {
52  return (elem->geographicalId().rawId() == detID);
53  });
54  const StripTopology& p = dynamic_cast<const StripGeomDetUnit*>(*det)->specificTopology();
55  maxNStrips = p.nstrips();
56 
57  try {
58  checkModuleNoise(siStripNoises, detID, maxNStrips);
59  } catch (const std::exception& e) {
60  // Increment the exception counter if checkModuleNoise itself throws an exception
61  edm::LogError("SiStripNoisesGetAllChecker")
62  << "Exception in checkModuleNoise for detID " << detID << ": " << e.what();
63  ++exceptionCounts;
64  } catch (...) {
65  edm::LogError("SiStripNoisesGetAllChecker") << "Unknown exception in checkModuleNoise for detID " << detID;
66  ++exceptionCounts;
67  }
68  }
69 
70  std::ostringstream message;
71 
72  // Define the box width
73  const int boxWidth = 50;
74 
75  message << "\n"
76  << std::string(boxWidth, '*') << "\n"
77  << "* " << std::setw(boxWidth - 4) << std::left << "SiStripNoisesGetAllChecker Summary"
78  << " *\n"
79  << std::string(boxWidth, '*') << "\n"
80  << "* " << std::setw(boxWidth - 4) << std::left
81  << ("Completed loop over " + std::to_string(detIDs.size()) + " SiStrip modules.") << " *\n"
82  << "* " << std::setw(boxWidth - 4) << std::left
83  << ("Encountered " + std::to_string(exceptionCounts) + " exceptions.") << " *\n"
84  << std::string(boxWidth, '*');
85 
86  edm::LogSystem("SiStripNoisesGetAllChecker") << message.str();
87 }
88 
90  const uint32_t detID,
91  uint16_t maxNStrips) {
92  try {
93  SiStripNoises::Range detNoiseRange = siStripNoises.getRange(detID);
94  std::vector<float> noises;
95  noises.resize(maxNStrips);
96  siStripNoises.allNoises(noises, detNoiseRange);
97  edm::LogInfo("SiStripNoisesGetAllChecker") << "Successfully processed detID: " << detID;
98  } catch (const std::exception& e) {
99  edm::LogError("SiStripNoisesGetAllChecker") << "Exception caught for detID " << detID << ": " << e.what();
100  throw; // Re-throw the exception to allow the outer loop to handle it
101  } catch (...) {
102  edm::LogError("SiStripNoisesGetAllChecker") << "Unknown exception caught for detID " << detID;
103  throw; // Re-throw the unknown exception
104  }
105 }
106 
107 // Define this as a plug-in
SiStripNoisesGetAllChecker(const edm::ParameterSet &)
Log< level::System, false > LogSystem
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
void allNoises(std::vector< float > &noises, const Range &range) const
void analyze(const edm::Event &, const edm::EventSetup &) override
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_
Log< level::Error, false > LogError
static std::string to_string(const XMLCh *ch)
~SiStripNoisesGetAllChecker() override=default
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Log< level::Info, false > LogInfo
const Range getRange(const uint32_t detID) const
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripNoises.h:47
const edm::ESGetToken< SiStripNoises, SiStripNoisesRcd > noisesToken_
void checkModuleNoise(const SiStripNoises &, const uint32_t detID, uint16_t maxNStrips)