File indexing completed on 2024-04-06 12:03:25
0001 #include <string>
0002 #include <iostream>
0003 #include <map>
0004 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0005 #include "FWCore/Framework/interface/ESHandle.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 #include "FWCore/Framework/interface/Frameworkfwd.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "CondFormats/SiPixelObjects/interface/SiPixelQualityProbabilities.h"
0012 #include "CondFormats/DataRecord/interface/SiPixelStatusScenarioProbabilityRcd.h"
0013
0014 class SiPixelQualityProbabilitiesTestReader : public edm::one::EDAnalyzer<> {
0015 public:
0016 explicit SiPixelQualityProbabilitiesTestReader(edm::ParameterSet const& p);
0017 ~SiPixelQualityProbabilitiesTestReader() override;
0018
0019 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0020
0021 private:
0022 void analyze(const edm::Event& e, const edm::EventSetup& c) override;
0023
0024
0025 const edm::ESGetToken<SiPixelQualityProbabilities, SiPixelStatusScenarioProbabilityRcd> siPixelQPToken_;
0026 const bool printdebug_;
0027 const std::string formatedOutput_;
0028 };
0029
0030 SiPixelQualityProbabilitiesTestReader::SiPixelQualityProbabilitiesTestReader(edm::ParameterSet const& p)
0031 : siPixelQPToken_(esConsumes()),
0032 printdebug_(p.getUntrackedParameter<bool>("printDebug", true)),
0033 formatedOutput_(p.getUntrackedParameter<std::string>("outputFile", "")) {
0034 edm::LogInfo("SiPixelQualityProbabilitiesTestReader") << "SiPixelQualityProbabilitiesTestReader" << std::endl;
0035 }
0036
0037 SiPixelQualityProbabilitiesTestReader::~SiPixelQualityProbabilitiesTestReader() {
0038 edm::LogInfo("SiPixelQualityProbabilitiesTestReader") << "~SiPixelQualityProbabilitiesTestReader " << std::endl;
0039 }
0040
0041 void SiPixelQualityProbabilitiesTestReader::analyze(const edm::Event& e, const edm::EventSetup& context) {
0042 edm::LogInfo("SiPixelQualityProbabilitiesTestReader")
0043 << "### SiPixelQualityProbabilitiesTestReader::analyze ###" << std::endl;
0044 edm::LogInfo("SiPixelQualityProbabilitiesTestReader") << " I AM IN RUN NUMBER " << e.id().run() << std::endl;
0045 edm::LogInfo("SiPixelQualityProbabilitiesTestReader") << " ---EVENT NUMBER " << e.id().event() << std::endl;
0046
0047 edm::eventsetup::EventSetupRecordKey recordKey(
0048 edm::eventsetup::EventSetupRecordKey::TypeTag::findType("SiPixelStatusScenarioProbabilityRcd"));
0049
0050 if (recordKey.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) {
0051
0052 edm::LogInfo("SiPixelQualityProbabilitiesTestReader") << "Record \"SiPixelStatusScenarioProbabilityRcd"
0053 << "\" does not exist " << std::endl;
0054 }
0055
0056
0057 edm::ESHandle<SiPixelQualityProbabilities> scenarioProbabilityHandle = context.getHandle(siPixelQPToken_);
0058 edm::LogInfo("SiPixelQualityProbabilitiesTestReader") << "got eshandle from context" << std::endl;
0059
0060 const SiPixelQualityProbabilities* myProbabilities = scenarioProbabilityHandle.product();
0061 edm::LogInfo("SiPixelQualityProbabilitiesTestReader") << "got SiPixelQualityProbabilities* " << std::endl;
0062 edm::LogInfo("SiPixelQualityProbabilitiesTestReader") << "print pointer address : " << myProbabilities << std::endl;
0063
0064 edm::LogInfo("SiPixelQualityProbabilitiesTestReader") << "Size " << myProbabilities->size() << std::endl;
0065 edm::LogInfo("SiPixelQualityProbabilitiesTestReader") << "Content of my Probabilities " << std::endl;
0066
0067 if (printdebug_) {
0068 myProbabilities->printAll();
0069 }
0070
0071 FILE* pFile = nullptr;
0072 if (!formatedOutput_.empty())
0073 pFile = fopen(formatedOutput_.c_str(), "w");
0074 if (pFile) {
0075 fprintf(pFile, "SiPixelQualityProbabilities::printAll() \n");
0076 fprintf(pFile,
0077 " ========================================================================================================="
0078 "========== \n");
0079
0080 SiPixelQualityProbabilities::probabilityMap m_probabilities = myProbabilities->getProbability_Map();
0081
0082 for (auto it = m_probabilities.begin(); it != m_probabilities.end(); ++it) {
0083 fprintf(pFile,
0084 " ======================================================================================================="
0085 "============ \n");
0086 fprintf(pFile, "PU bin : %i \n ", (it->first));
0087 for (const auto& entry : it->second) {
0088 fprintf(pFile, "Quality snapshot %s, probability %f \n", (entry.first).c_str(), entry.second);
0089 }
0090 }
0091 }
0092 }
0093
0094 void SiPixelQualityProbabilitiesTestReader::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0095 edm::ParameterSetDescription desc;
0096 desc.setComment("Reads payloads of type SiPixelQualityProbabilities");
0097 desc.addUntracked<bool>("printDebug", true);
0098 desc.addUntracked<std::string>("outputFile", "");
0099 descriptions.add("SiPixelQualityProbabilitiesTestReader", desc);
0100 }
0101
0102 DEFINE_FWK_MODULE(SiPixelQualityProbabilitiesTestReader);