CMS 3D CMS Logo

SiPixelQualityProbabilitiesTestWriter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CondFormats/SiPixelObjects
4 // Class: SiPixelQualityProbabilitiesTestWriter
5 //
9 //
10 // Original Author: Marco Musich
11 // Created: Wed, 30 Nov 2018 13:22:00 GMT
12 //
13 //
14 
15 // system include files
16 #include <memory>
17 #include <fstream>
18 
19 // user include files
32 
33 //
34 // class declaration
35 //
36 
38 public:
41 
42  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
43 
44 private:
45  void analyze(const edm::Event&, const edm::EventSetup&) override;
46  void endJob() override;
47 
48  // ----------member data ---------------------------
52  const bool printdebug_;
53  std::unique_ptr<SiPixelQualityProbabilities> myProbabilities;
54 };
55 
56 //
57 // constructors and destructor
58 //
60  : m_ProbInputs(iConfig.getParameter<std::string>("probabilities")),
61  m_SnapshotInputs(iConfig.getParameter<std::string>("snapshots")),
62  m_record(iConfig.getParameter<std::string>("record")),
63  printdebug_(iConfig.getUntrackedParameter<bool>("printDebug", false)) {
64  //now do what ever initialization is needed
65  myProbabilities = std::make_unique<SiPixelQualityProbabilities>();
66 }
67 
69 
70 //
71 // member functions
72 //
73 
74 // ------------ method called for each event ------------
76  using namespace edm;
77  std::ifstream myfile(m_ProbInputs);
78  std::ifstream mysnapshots(m_SnapshotInputs);
79  std::string line1, line2;
80  std::map<int, std::string> snapshotIdToString;
81 
82  if (mysnapshots.is_open()) {
83  while (getline(mysnapshots, line1)) {
84  //edm::LogInfo("SiPixelQualityProbabilitiesTestWriter") << line1 << std::endl;
85  std::istringstream iss(line1);
86  int id, run, ls;
87  iss >> id >> run >> ls;
88  snapshotIdToString[id] = std::to_string(run) + "_" + std::to_string(ls);
89  }
90  }
91 
93 
94  if (myfile.is_open()) {
95  while (getline(myfile, line2)) {
96  edm::LogInfo("SiPixelQualityProbabilitiesTestWriter") << line2 << std::endl;
97  std::istringstream iss(line2);
98  int pileupBinId, nEntries;
99  iss >> pileupBinId >> nEntries;
100  edm::LogInfo("SiPixelQualityProbabilitiesTestWriter")
101  << "PILEUP BIN/ENTRIES: " << pileupBinId << " " << nEntries << std::endl;
102  std::vector<int> ids(nEntries, 0);
103  std::vector<float> probs(nEntries, 0.0);
104  for (int i = 0; i < nEntries; ++i) {
105  iss >> ids.at(i) >> probs.at(i);
106  //edm::LogInfo("SiPixelQualityProbabilitiesTestWriter") << ids.at(i) << " " << probs.at(i)<< std::endl;
107  auto idAndProb = std::make_pair(snapshotIdToString.at(ids.at(i)), probs.at(i));
108  myProbVector.push_back(idAndProb);
109  }
110  if (nEntries > 0)
111  myProbabilities->setProbabilities(pileupBinId, myProbVector);
112  myProbVector.clear();
113  }
114  myfile.close();
115  }
116 
117  if (printdebug_) {
118  edm::LogInfo("SiPixelQualityProbabilitiesTestWriter") << "Content of SiPixelQualityProbabilities " << std::endl;
119  // use buil-in method in the CondFormat
120  myProbabilities->printAll();
121  }
122 }
123 
124 // ------------ method called once each job just after ending the event loop ------------
126  edm::LogInfo("SiPixelQualityProbabilitiesTestWriter")
127  << "Size of SiPixelQualityProbabilities object " << myProbabilities->size() << std::endl
128  << std::endl;
129 
130  // Form the data here
132  if (poolDbService.isAvailable()) {
133  cond::Time_t valid_time = poolDbService->currentTime();
134  // this writes the payload to begin in current run defined in cfg
135  poolDbService->writeOneIOV(*myProbabilities, valid_time, m_record);
136  }
137 }
138 
139 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
142  desc.setComment("Writes payloads of type SiPixelQualityProbabilities");
143  desc.addUntracked<bool>("printDebug", true);
144  desc.add<std::string>("record", "SiPixelStatusScenarioProbabilityRcd");
145  desc.add<std::string>("snapshots", "");
146  desc.add<std::string>("probabilities", "");
147  descriptions.add("SiPixelQualityProbabilitiesTestWriter", desc);
148 }
149 
150 //define this as a plug-in
std::string to_string(const V &value)
Definition: OMSAccess.h:77
int iEvent
Definition: GenABIO.cc:224
std::vector< std::pair< std::string, float > > probabilityVec
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
Log< level::Info, false > LogInfo
def ls(path, rec=False)
Definition: eostools.py:349
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
HLT enums.
bool isAvailable() const
Definition: Service.h:40
void analyze(const edm::Event &, const edm::EventSetup &) override
std::unique_ptr< SiPixelQualityProbabilities > myProbabilities