CMS 3D CMS Logo

SiPixelFakeTemplateDBObjectESSource.cc
Go to the documentation of this file.
1 // system includes
2 #include <memory>
3 #include <fstream>
4 
5 // framework includes
17 
19 public:
22 
23  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
24 
25  typedef std::vector<std::string> vstring;
26 
27  virtual std::unique_ptr<SiPixelTemplateDBObject> produce(const SiPixelTemplateDBObjectRcd&);
28 
29 protected:
31  const edm::IOVSyncValue&,
32  edm::ValidityInterval&) override;
33 
34 private:
36  float version_;
37 };
38 
40  : templateCalibrations_(conf_.getParameter<vstring>("siPixelTemplateCalibrations")),
41  version_(conf_.getParameter<double>("Version")) {
42  edm::LogInfo("SiPixelFakeTemplateDBObjectESSource::SiPixelFakeTemplateDBObjectESSource");
43  //the following line is needed to tell the framework what
44  // data is being produced
45  setWhatProduced(this);
46  findingRecord<SiPixelTemplateDBObjectRcd>();
47 }
48 
50 
51 std::unique_ptr<SiPixelTemplateDBObject> SiPixelFakeTemplateDBObjectESSource::produce(
53  using namespace edm::es;
54 
55  //Mostly copied from CondTools/SiPixel/test/SiPixelTemplateDBObjectUploader.cc
56  //--- Make the POOL-ORA object to store the database object
58 
59  // Local variables
60  const char* tempfile;
61  int m;
62 
63  // Set the number of templates to be passed to the dbobject
64  obj->setNumOfTempl(templateCalibrations_.size());
65 
66  // Set the version of the template dbobject - this is an external parameter
67  obj->setVersion(version_);
68 
69  // open the template file(s)
70  for (m = 0; m < obj->numOfTempl(); ++m) {
72  tempfile = (file.fullPath()).c_str();
73 
74  std::ifstream in_file(tempfile, std::ios::in);
75 
76  if (in_file.is_open()) {
77  edm::LogPrint("SiPixelFakeTemplateDBObjectESSource")
78  << "Opened Template File: " << file.fullPath().c_str() << std::endl;
79 
80  // Local variables
81  char title_char[80], c;
83  float tempstore;
84  unsigned int iter;
85 
86  // Templates contain a header char - we must be clever about storing this
87  for (iter = 0; (c = in_file.get()) != '\n' && iter < 79; ++iter) {
88  title_char[iter] = c;
89  }
90  if (iter == 79) {
91  title_char[iter] = '\n';
92  } else {
93  unsigned int ilast = 3 - (iter % 4);
94  for (unsigned int it = 0; it != ilast; it++) {
95  title_char[iter] = ' ';
96  iter++;
97  }
98  title_char[iter] = '\n';
99  }
100 
101  for (unsigned int j = 0; j <= iter; j += 4) {
102  temp.c[0] = title_char[j];
103  temp.c[1] = title_char[j + 1];
104  temp.c[2] = title_char[j + 2];
105  temp.c[3] = title_char[j + 3];
106  obj->push_back(temp.f);
107  obj->setMaxIndex(obj->maxIndex() + 1);
108  }
109 
110  // Fill the dbobject
111  in_file >> tempstore;
112  while (!in_file.eof()) {
113  obj->setMaxIndex(obj->maxIndex() + 1);
114  obj->push_back(tempstore);
115  in_file >> tempstore;
116  }
117 
118  in_file.close();
119  } else {
120  // If file didn't open, report this
121  edm::LogError("SiPixeFakelTemplateDBObjectESSource") << "Error opening File" << tempfile << std::endl;
122  }
123  }
124 
125  //std::cout << *obj << std::endl;
126  return std::unique_ptr<SiPixelTemplateDBObject>(obj);
127 }
128 
130  const edm::IOVSyncValue& iosv,
131  edm::ValidityInterval& oValidity) {
133  oValidity = infinity;
134 }
135 
138  desc.add<vstring>(
139  "siPixelTemplateCalibrations",
140  {"CalibTracker/SiPixelESProducers/data/SiPixelTemplateDBObject_0T_phase1_BoR3_v1/template_summary_zp0310.out",
141  "CalibTracker/SiPixelESProducers/data/SiPixelTemplateDBObject_0T_phase1_BoR3_v1/template_summary_zp0311.out",
142  "CalibTracker/SiPixelESProducers/data/SiPixelTemplateDBObject_0T_phase1_BoR3_v1/template_summary_zp0312.out",
143  "CalibTracker/SiPixelESProducers/data/SiPixelTemplateDBObject_0T_phase1_BoR3_v1/template_summary_zp0313.out",
144  "CalibTracker/SiPixelESProducers/data/SiPixelTemplateDBObject_0T_phase1_BoR3_v1/template_summary_zp0314.out",
145  "CalibTracker/SiPixelESProducers/data/SiPixelTemplateDBObject_0T_phase1_BoR3_v1/template_summary_zp0315.out"});
146  desc.add<double>("Version", 1.0);
147  descriptions.addWithDefaultLabel(desc);
148 }
149 
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
Log< level::Error, false > LogError
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
virtual std::unique_ptr< SiPixelTemplateDBObject > produce(const SiPixelTemplateDBObjectRcd &)
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)