CMS 3D CMS Logo

SiPixelFakeGenErrorDBObjectESSource.cc
Go to the documentation of this file.
1 // system includes
2 #include <memory>
3 #include <fstream>
4 
5 // user includes
17 
19 public:
21  ~SiPixelFakeGenErrorDBObjectESSource() override = default;
22 
23  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
24 
25  typedef std::vector<std::string> vstring;
26 
27  virtual std::unique_ptr<SiPixelGenErrorDBObject> produce(const SiPixelGenErrorDBObjectRcd&);
28 
29 protected:
31  const edm::IOVSyncValue&,
32  edm::ValidityInterval&) override;
33 
34 private:
36  float version_;
37 };
38 
40  : GenErrorCalibrations_(conf_.getParameter<vstring>("siPixelGenErrorCalibrations")),
41  version_(conf_.getParameter<double>("Version")) {
42  edm::LogInfo("SiPixelFakeGenErrorDBObjectESSource::SiPixelFakeGenErrorDBObjectESSource");
43  //the following line is needed to tell the framework what
44  // data is being produced
45  setWhatProduced(this);
46  findingRecord<SiPixelGenErrorDBObjectRcd>();
47 }
48 
49 std::unique_ptr<SiPixelGenErrorDBObject> SiPixelFakeGenErrorDBObjectESSource::produce(
51  using namespace edm::es;
52 
53  //Mostly copied from CondTools/SiPixel/test/SiPixelGenErrorDBObjectUploader.cc
54  //--- Make the POOL-ORA object to store the database object
56 
57  // Local variables
58  int m;
59 
60  // Set the number of GenErrors to be passed to the dbobject
61  obj->setNumOfTempl(GenErrorCalibrations_.size());
62 
63  // Set the version of the GenError dbobject - this is an external parameter
64  obj->setVersion(version_);
65 
66  // open the GenError file(s)
67  for (m = 0; m < obj->numOfTempl(); ++m) {
69  std::ifstream in_file(file.fullPath(), std::ios::in);
70 
71  if (in_file.is_open()) {
72  edm::LogPrint("SiPixelFakeGenErrorDBObjectESSource")
73  << "Opened GenError File: " << file.fullPath().c_str() << std::endl;
74 
75  // Local variables
76  char title_char[80], c;
78  float tempstore;
79  unsigned int iter;
80 
81  // GenErrors contain a header char - we must be clever about storing this
82  for (iter = 0; (c = in_file.get()) != '\n' && iter < 79; ++iter) {
83  title_char[iter] = c;
84  }
85  if (iter == 79) {
86  title_char[iter] = '\n';
87  } else {
88  unsigned int ilast = 3 - (iter % 4);
89  for (unsigned int it = 0; it != ilast; it++) {
90  title_char[iter] = ' ';
91  iter++;
92  }
93  title_char[iter] = '\n';
94  }
95 
96  for (unsigned int j = 0; j <= iter; j += 4) {
97  temp.c[0] = title_char[j];
98  temp.c[1] = title_char[j + 1];
99  temp.c[2] = title_char[j + 2];
100  temp.c[3] = title_char[j + 3];
101  obj->push_back(temp.f);
102  obj->setMaxIndex(obj->maxIndex() + 1);
103  }
104 
105  // Fill the dbobject
106  in_file >> tempstore;
107  while (!in_file.eof()) {
108  obj->setMaxIndex(obj->maxIndex() + 1);
109  obj->push_back(tempstore);
110  in_file >> tempstore;
111  }
112 
113  in_file.close();
114  } else {
115  // If file didn't open, report this
116  edm::LogError("SiPixeFakelGenErrorDBObjectESSource") << "Error opening File" << file.fullPath() << std::endl;
117  }
118  }
119 
120  //std::cout << *obj << std::endl;
121  return std::unique_ptr<SiPixelGenErrorDBObject>(obj);
122 }
123 
125  const edm::IOVSyncValue& iosv,
126  edm::ValidityInterval& oValidity) {
128  oValidity = infinity;
129 }
130 
133  desc.add<vstring>(
134  "siPixelGenErrorCalibrations",
135  {"CalibTracker/SiPixelESProducers/data/SiPixelTemplateDBObject_0T_phase1_BoR3_v1/generror_summary_zp0310.out",
136  "CalibTracker/SiPixelESProducers/data/SiPixelTemplateDBObject_0T_phase1_BoR3_v1/generror_summary_zp0311.out",
137  "CalibTracker/SiPixelESProducers/data/SiPixelTemplateDBObject_0T_phase1_BoR3_v1/generror_summary_zp0312.out",
138  "CalibTracker/SiPixelESProducers/data/SiPixelTemplateDBObject_0T_phase1_BoR3_v1/generror_summary_zp0313.out",
139  "CalibTracker/SiPixelESProducers/data/SiPixelTemplateDBObject_0T_phase1_BoR3_v1/generror_summary_zp0314.out",
140  "CalibTracker/SiPixelESProducers/data/SiPixelTemplateDBObject_0T_phase1_BoR3_v1/generror_summary_zp0315.out"});
141  desc.add<double>("Version", 1.0);
142  descriptions.addWithDefaultLabel(desc);
143 }
144 
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:166
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
virtual std::unique_ptr< SiPixelGenErrorDBObject > produce(const SiPixelGenErrorDBObjectRcd &)
Log< level::Error, false > LogError
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88
const double infinity
Log< level::Warning, true > LogPrint
Log< level::Info, false > LogInfo
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:92
~SiPixelFakeGenErrorDBObjectESSource() override=default
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)