CMS 3D CMS Logo

SiPixelFakeGenErrorDBObjectESSource.cc
Go to the documentation of this file.
3 #include <fstream>
4 
5 SiPixelFakeGenErrorDBObjectESSource::SiPixelFakeGenErrorDBObjectESSource(const edm::ParameterSet& conf_) : GenErrorCalibrations_(conf_.getParameter<vstring>("siPixelGenErrorCalibrations")),
6  version_(conf_.getParameter<double>("Version"))
7 {
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 }
18 
19 std::unique_ptr<SiPixelGenErrorDBObject> SiPixelFakeGenErrorDBObjectESSource::produce(const SiPixelGenErrorDBObjectRcd & )
20 {
21  using namespace edm::es;
22 
23  //Mostly copied from CondTools/SiPixel/test/SiPixelGenErrorDBObjectUploader.cc
24  //--- Make the POOL-ORA object to store the database object
26 
27  // Local variables
28  const char *tempfile;
29  int m;
30 
31  // Set the number of GenErrors to be passed to the dbobject
33 
34  // Set the version of the GenError dbobject - this is an external parameter
35  obj->setVersion(version_);
36 
37  // open the GenError file(s)
38  for(m=0; m< obj->numOfTempl(); ++m){
39 
41  tempfile = (file.fullPath()).c_str();
42 
43  std::ifstream in_file(tempfile, std::ios::in);
44 
45  if(in_file.is_open()){
46  edm::LogInfo("SiPixelFakeGenErrorDBObjectESSource") << "Opened GenError File: " << file.fullPath().c_str() << std::endl;
47 
48  // Local variables
49  char title_char[80], c;
51  float tempstore;
52  int iter,j;
53 
54  // GenErrors contain a header char - we must be clever about storing this
55  for (iter = 0; (c=in_file.get()) != '\n'; ++iter) {
56  if(iter < 79) {title_char[iter] = c;}
57  }
58  if(iter > 78) {iter=78;}
59  title_char[iter+1] ='\n';
60 
61  for(j=0; j<80; j+=4) {
62  temp.c[0] = title_char[j];
63  temp.c[1] = title_char[j+1];
64  temp.c[2] = title_char[j+2];
65  temp.c[3] = title_char[j+3];
66  obj->push_back(temp.f);
67  obj->setMaxIndex(obj->maxIndex()+1);
68  }
69 
70  // Fill the dbobject
71  in_file >> tempstore;
72  while(!in_file.eof()) {
73  obj->setMaxIndex(obj->maxIndex()+1);
74  obj->push_back(tempstore);
75  in_file >> tempstore;
76  }
77 
78  in_file.close();
79  }
80  else {
81  // If file didn't open, report this
82  edm::LogError("SiPixeFakelGenErrorDBObjectESSource") << "Error opening File" << tempfile << std::endl;
83  }
84  }
85 
86  //std::cout << *obj << std::endl;
87  return std::unique_ptr<SiPixelGenErrorDBObject>(obj);
88 }
89 
91  const edm::IOVSyncValue& iosv,
92  edm::ValidityInterval& oValidity ) {
94  oValidity = infinity;
95 }
96 
void setNumOfTempl(int numOfTempl)
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:97
virtual std::unique_ptr< SiPixelGenErrorDBObject > produce(const SiPixelGenErrorDBObjectRcd &)
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
static const IOVSyncValue & beginOfTime()
const double infinity
void setVersion(float version)
std::string fullPath() const
Definition: FileInPath.cc:184