CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiPixelFakeTemplateDBObjectESSource.cc
Go to the documentation of this file.
3 #include <fstream>
4 
5 SiPixelFakeTemplateDBObjectESSource::SiPixelFakeTemplateDBObjectESSource(const edm::ParameterSet& conf_) : templateCalibrations_(conf_.getParameter<vstring>("siPixelTemplateCalibrations")),
6  version_(conf_.getParameter<double>("Version"))
7 {
8  edm::LogInfo("SiPixelFakeTemplateDBObjectESSource::SiPixelFakeTemplateDBObjectESSource");
9  //the following line is needed to tell the framework what
10  // data is being produced
11  setWhatProduced(this);
12  findingRecord<SiPixelTemplateDBObjectRcd>();
13 }
14 
16 {
17 }
18 
19 std::auto_ptr<SiPixelTemplateDBObject> SiPixelFakeTemplateDBObjectESSource::produce(const SiPixelTemplateDBObjectRcd & )
20 {
21  using namespace edm::es;
22 
23  //Mostly copied from CondTools/SiPixel/test/SiPixelTemplateDBObjectUploader.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 templates to be passed to the dbobject
32  obj->setNumOfTempl(templateCalibrations_.size());
33 
34  // Set the version of the template dbobject - this is an external parameter
35  obj->setVersion(version_);
36 
37  // open the template 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("SiPixelFakeTemplateDBObjectESSource") << "Opened Template 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  // Templates 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("SiPixeFakelTemplateDBObjectESSource") << "Error opening File" << tempfile << std::endl;
83  }
84  }
85 
86  //std::cout << *obj << std::endl;
87  return std::auto_ptr<SiPixelTemplateDBObject>(obj);
88 }
89 
91  const edm::IOVSyncValue& iosv,
92  edm::ValidityInterval& oValidity ) {
94  oValidity = infinity;
95 }
96 
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:97
virtual void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &)
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
static const IOVSyncValue & beginOfTime()
const double infinity
int j
Definition: DBlmapReader.cc:9
virtual std::auto_ptr< SiPixelTemplateDBObject > produce(const SiPixelTemplateDBObjectRcd &)
std::string fullPath() const
Definition: FileInPath.cc:171