CMS 3D CMS Logo

SiPixelQualityProbabilitiesTestReader.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <map>
13 
15 public:
18 
19  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
20 
21 private:
22  void analyze(const edm::Event& e, const edm::EventSetup& c) override;
23 
24  // ----------member data ---------------------------
26  const bool printdebug_;
28 };
29 
31  : siPixelQPToken_(esConsumes()),
32  printdebug_(p.getUntrackedParameter<bool>("printDebug", true)),
33  formatedOutput_(p.getUntrackedParameter<std::string>("outputFile", "")) {
34  edm::LogInfo("SiPixelQualityProbabilitiesTestReader") << "SiPixelQualityProbabilitiesTestReader" << std::endl;
35 }
36 
38  edm::LogInfo("SiPixelQualityProbabilitiesTestReader") << "~SiPixelQualityProbabilitiesTestReader " << std::endl;
39 }
40 
42  edm::LogInfo("SiPixelQualityProbabilitiesTestReader")
43  << "### SiPixelQualityProbabilitiesTestReader::analyze ###" << std::endl;
44  edm::LogInfo("SiPixelQualityProbabilitiesTestReader") << " I AM IN RUN NUMBER " << e.id().run() << std::endl;
45  edm::LogInfo("SiPixelQualityProbabilitiesTestReader") << " ---EVENT NUMBER " << e.id().event() << std::endl;
46 
48  edm::eventsetup::EventSetupRecordKey::TypeTag::findType("SiPixelStatusScenarioProbabilityRcd"));
49 
51  //record not found
52  edm::LogInfo("SiPixelQualityProbabilitiesTestReader") << "Record \"SiPixelStatusScenarioProbabilityRcd"
53  << "\" does not exist " << std::endl;
54  }
55 
56  //this part gets the handle of the event source and the record (i.e. the Database)
57  edm::ESHandle<SiPixelQualityProbabilities> scenarioProbabilityHandle = context.getHandle(siPixelQPToken_);
58  edm::LogInfo("SiPixelQualityProbabilitiesTestReader") << "got eshandle from context" << std::endl;
59 
60  const SiPixelQualityProbabilities* myProbabilities = scenarioProbabilityHandle.product();
61  edm::LogInfo("SiPixelQualityProbabilitiesTestReader") << "got SiPixelQualityProbabilities* " << std::endl;
62  edm::LogInfo("SiPixelQualityProbabilitiesTestReader") << "print pointer address : " << myProbabilities << std::endl;
63 
64  edm::LogInfo("SiPixelQualityProbabilitiesTestReader") << "Size " << myProbabilities->size() << std::endl;
65  edm::LogInfo("SiPixelQualityProbabilitiesTestReader") << "Content of my Probabilities " << std::endl;
66  // use built-in method in the CondFormat to print the content
67  if (printdebug_) {
68  myProbabilities->printAll();
69  }
70 
71  FILE* pFile = nullptr;
72  if (!formatedOutput_.empty())
73  pFile = fopen(formatedOutput_.c_str(), "w");
74  if (pFile) {
75  fprintf(pFile, "SiPixelQualityProbabilities::printAll() \n");
76  fprintf(pFile,
77  " ========================================================================================================="
78  "========== \n");
79 
80  SiPixelQualityProbabilities::probabilityMap m_probabilities = myProbabilities->getProbability_Map();
81 
82  for (auto it = m_probabilities.begin(); it != m_probabilities.end(); ++it) {
83  fprintf(pFile,
84  " ======================================================================================================="
85  "============ \n");
86  fprintf(pFile, "PU bin : %i \n ", (it->first));
87  for (const auto& entry : it->second) {
88  fprintf(pFile, "Quality snapshot %s, probability %f \n", (entry.first).c_str(), entry.second);
89  }
90  }
91  }
92 }
93 
96  desc.setComment("Reads payloads of type SiPixelQualityProbabilities");
97  desc.addUntracked<bool>("printDebug", true);
98  desc.addUntracked<std::string>("outputFile", "");
99  descriptions.add("SiPixelQualityProbabilitiesTestReader", desc);
100 }
101 
void analyze(const edm::Event &e, const edm::EventSetup &c) override
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
std::map< unsigned int, probabilityVec > probabilityMap
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
T const * product() const
Definition: ESHandle.h:86
Log< level::Info, false > LogInfo
const probabilityMap & getProbability_Map() const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
heterocontainer::HCTypeTag TypeTag
const edm::ESGetToken< SiPixelQualityProbabilities, SiPixelStatusScenarioProbabilityRcd > siPixelQPToken_
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag
Definition: HCTypeTag.cc:121