CMS 3D CMS Logo

SiPixelQualityProbabilitiesWriteFromASCII.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 ---------------------------
51  const bool printdebug_;
52  std::unique_ptr<SiPixelQualityProbabilities> myProbabilities;
53 };
54 
55 //
56 // constructors and destructor
57 //
59  : m_ProbInputs(iConfig.getParameter<std::string>("probabilities")),
60  m_record(iConfig.getParameter<std::string>("record")),
61  printdebug_(iConfig.getUntrackedParameter<bool>("printDebug", false)) {
62  //now do what ever initialization is needed
63  myProbabilities = std::make_unique<SiPixelQualityProbabilities>();
64 }
65 
67 
68 //
69 // member functions
70 //
71 
72 // ------------ method called for each event ------------
74  using namespace edm;
75  std::ifstream myfile(m_ProbInputs);
77 
79 
80  if (myfile.is_open()) {
81  while (getline(myfile, line)) {
82  if (printdebug_) {
83  edm::LogInfo("SiPixelQualityProbabilitiesWriteFromASCII") << line << std::endl;
84  }
85  std::istringstream iss(line);
86  int pileupBinId, nEntries;
87  iss >> pileupBinId >> nEntries;
88  edm::LogInfo("SiPixelQualityProbabilitiesWriteFromASCII")
89  << "PILEUP BIN/ENTRIES: " << pileupBinId << " " << nEntries << std::endl;
90  std::vector<std::string> ids(nEntries, "");
91  std::vector<float> probs(nEntries, 0.0);
92  for (int i = 0; i < nEntries; ++i) {
93  iss >> ids.at(i) >> probs.at(i);
94  if (printdebug_) {
95  edm::LogInfo("SiPixelQualityProbabilitiesWriteFromASCII") << ids.at(i) << " " << probs.at(i) << std::endl;
96  }
97  auto idAndProb = std::make_pair(ids.at(i), probs.at(i));
98  myProbVector.push_back(idAndProb);
99  }
100  if (nEntries > 0) {
101  myProbabilities->setProbabilities(pileupBinId, myProbVector);
102  }
103  myProbVector.clear();
104  }
105  myfile.close();
106  }
107 
108  if (printdebug_) {
109  edm::LogInfo("SiPixelQualityProbabilitiesWriteFromASCII") << "Content of SiPixelQualityProbabilities " << std::endl;
110  // use buil-in method in the CondFormat
111  myProbabilities->printAll();
112  }
113 }
114 
115 // ------------ method called once each job just after ending the event loop ------------
117  edm::LogInfo("SiPixelQualityProbabilitiesWriteFromASCII")
118  << "Size of SiPixelQualityProbabilities object " << myProbabilities->size() << std::endl
119  << std::endl;
120 
121  // Form the data here
123  if (poolDbService.isAvailable()) {
124  cond::Time_t valid_time = poolDbService->currentTime();
125  // this writes the payload to begin in current run defined in cfg
126  poolDbService->writeOneIOV(*myProbabilities, valid_time, m_record);
127  }
128 }
129 
130 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
133  desc.setComment("Writes payloads of type SiPixelQualityProbabilities");
134  desc.addUntracked<bool>("printDebug", true);
135  desc.add<std::string>("record", "SiPixelStatusScenarioProbabilityRcd");
136  desc.add<std::string>("probabilities", "");
137  descriptions.add("SiPixelQualityProbabilitiesWriteFromASCII", desc);
138 }
139 
140 //define this as a plug-in
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
bool isAvailable() const
Definition: Service.h:40
std::unique_ptr< SiPixelQualityProbabilities > myProbabilities
void analyze(const edm::Event &, const edm::EventSetup &) override