Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:14:30

0001 #include "CalibTracker/SiPixelESProducers/interface/SiPixelFakeGenErrorDBObjectESSource.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include <fstream>
0004 
0005 SiPixelFakeGenErrorDBObjectESSource::SiPixelFakeGenErrorDBObjectESSource(const edm::ParameterSet& conf_)
0006     : GenErrorCalibrations_(conf_.getParameter<vstring>("siPixelGenErrorCalibrations")),
0007       version_(conf_.getParameter<double>("Version")) {
0008   edm::LogInfo("SiPixelFakeGenErrorDBObjectESSource::SiPixelFakeGenErrorDBObjectESSource");
0009   //the following line is needed to tell the framework what
0010   // data is being produced
0011   setWhatProduced(this);
0012   findingRecord<SiPixelGenErrorDBObjectRcd>();
0013 }
0014 
0015 SiPixelFakeGenErrorDBObjectESSource::~SiPixelFakeGenErrorDBObjectESSource() {}
0016 
0017 std::unique_ptr<SiPixelGenErrorDBObject> SiPixelFakeGenErrorDBObjectESSource::produce(
0018     const SiPixelGenErrorDBObjectRcd&) {
0019   using namespace edm::es;
0020 
0021   //Mostly copied from CondTools/SiPixel/test/SiPixelGenErrorDBObjectUploader.cc
0022   //--- Make the POOL-ORA object to store the database object
0023   SiPixelGenErrorDBObject* obj = new SiPixelGenErrorDBObject;
0024 
0025   // Local variables
0026   const char* tempfile;
0027   int m;
0028 
0029   // Set the number of GenErrors to be passed to the dbobject
0030   obj->setNumOfTempl(GenErrorCalibrations_.size());
0031 
0032   // Set the version of the GenError dbobject - this is an external parameter
0033   obj->setVersion(version_);
0034 
0035   //  open the GenError file(s)
0036   for (m = 0; m < obj->numOfTempl(); ++m) {
0037     edm::FileInPath file(GenErrorCalibrations_[m].c_str());
0038     tempfile = (file.fullPath()).c_str();
0039 
0040     std::ifstream in_file(tempfile, std::ios::in);
0041 
0042     if (in_file.is_open()) {
0043       edm::LogInfo("SiPixelFakeGenErrorDBObjectESSource")
0044           << "Opened GenError File: " << file.fullPath().c_str() << std::endl;
0045 
0046       // Local variables
0047       char title_char[80], c;
0048       SiPixelGenErrorDBObject::char2float temp;
0049       float tempstore;
0050       unsigned int iter;
0051 
0052       // GenErrors contain a header char - we must be clever about storing this
0053       for (iter = 0; (c = in_file.get()) != '\n' && iter < 79; ++iter) {
0054         title_char[iter] = c;
0055       }
0056       if (iter == 79) {
0057         title_char[iter] = '\n';
0058       } else {
0059         unsigned int ilast = 3 - (iter % 4);
0060         for (unsigned int it = 0; it != ilast; it++) {
0061           title_char[iter] = ' ';
0062           iter++;
0063         }
0064         title_char[iter] = '\n';
0065       }
0066 
0067       for (unsigned int j = 0; j <= iter; j += 4) {
0068         temp.c[0] = title_char[j];
0069         temp.c[1] = title_char[j + 1];
0070         temp.c[2] = title_char[j + 2];
0071         temp.c[3] = title_char[j + 3];
0072         obj->push_back(temp.f);
0073         obj->setMaxIndex(obj->maxIndex() + 1);
0074       }
0075 
0076       // Fill the dbobject
0077       in_file >> tempstore;
0078       while (!in_file.eof()) {
0079         obj->setMaxIndex(obj->maxIndex() + 1);
0080         obj->push_back(tempstore);
0081         in_file >> tempstore;
0082       }
0083 
0084       in_file.close();
0085     } else {
0086       // If file didn't open, report this
0087       edm::LogError("SiPixeFakelGenErrorDBObjectESSource") << "Error opening File" << tempfile << std::endl;
0088     }
0089   }
0090 
0091   //std::cout << *obj << std::endl;
0092   return std::unique_ptr<SiPixelGenErrorDBObject>(obj);
0093 }
0094 
0095 void SiPixelFakeGenErrorDBObjectESSource::setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0096                                                          const edm::IOVSyncValue& iosv,
0097                                                          edm::ValidityInterval& oValidity) {
0098   edm::ValidityInterval infinity(iosv.beginOfTime(), iosv.endOfTime());
0099   oValidity = infinity;
0100 }