CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SiPixelFakeGenErrorDBObjectESSource.cc
Go to the documentation of this file.
3 #include <fstream>
4 
6  : GenErrorCalibrations_(conf_.getParameter<vstring>("siPixelGenErrorCalibrations")),
7  version_(conf_.getParameter<double>("Version")) {
8  edm::LogInfo("SiPixelFakeGenErrorDBObjectESSource::SiPixelFakeGenErrorDBObjectESSource");
9  //the following line is needed to tell the framework what
10  // data is being produced
11  setWhatProduced(this);
12  findingRecord<SiPixelGenErrorDBObjectRcd>();
13 }
14 
16 
17 std::unique_ptr<SiPixelGenErrorDBObject> SiPixelFakeGenErrorDBObjectESSource::produce(
19  using namespace edm::es;
20 
21  //Mostly copied from CondTools/SiPixel/test/SiPixelGenErrorDBObjectUploader.cc
22  //--- Make the POOL-ORA object to store the database object
24 
25  // Local variables
26  const char* tempfile;
27  int m;
28 
29  // Set the number of GenErrors to be passed to the dbobject
30  obj->setNumOfTempl(GenErrorCalibrations_.size());
31 
32  // Set the version of the GenError dbobject - this is an external parameter
33  obj->setVersion(version_);
34 
35  // open the GenError file(s)
36  for (m = 0; m < obj->numOfTempl(); ++m) {
38  tempfile = (file.fullPath()).c_str();
39 
40  std::ifstream in_file(tempfile, std::ios::in);
41 
42  if (in_file.is_open()) {
43  edm::LogInfo("SiPixelFakeGenErrorDBObjectESSource")
44  << "Opened GenError File: " << file.fullPath().c_str() << std::endl;
45 
46  // Local variables
47  char title_char[80], c;
49  float tempstore;
50  unsigned int iter;
51 
52  // GenErrors contain a header char - we must be clever about storing this
53  for (iter = 0; (c = in_file.get()) != '\n' && iter < 79; ++iter) {
54  title_char[iter] = c;
55  }
56  if (iter == 79) {
57  title_char[iter] = '\n';
58  } else {
59  unsigned int ilast = 3 - (iter % 4);
60  for (unsigned int it = 0; it != ilast; it++) {
61  title_char[iter] = ' ';
62  iter++;
63  }
64  title_char[iter] = '\n';
65  }
66 
67  for (unsigned int j = 0; j <= iter; j += 4) {
68  temp.c[0] = title_char[j];
69  temp.c[1] = title_char[j + 1];
70  temp.c[2] = title_char[j + 2];
71  temp.c[3] = title_char[j + 3];
72  obj->push_back(temp.f);
73  obj->setMaxIndex(obj->maxIndex() + 1);
74  }
75 
76  // Fill the dbobject
77  in_file >> tempstore;
78  while (!in_file.eof()) {
79  obj->setMaxIndex(obj->maxIndex() + 1);
80  obj->push_back(tempstore);
81  in_file >> tempstore;
82  }
83 
84  in_file.close();
85  } else {
86  // If file didn't open, report this
87  edm::LogError("SiPixeFakelGenErrorDBObjectESSource") << "Error opening File" << tempfile << std::endl;
88  }
89  }
90 
91  //std::cout << *obj << std::endl;
92  return std::unique_ptr<SiPixelGenErrorDBObject>(obj);
93 }
94 
96  const edm::IOVSyncValue& iosv,
97  edm::ValidityInterval& oValidity) {
99  oValidity = infinity;
100 }
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
const edm::EventSetup & c
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::Info, false > LogInfo
std::string fullPath() const
Definition: FileInPath.cc:161