Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-17 04:57:59

0001 // system includes
0002 #include <memory>
0003 #include <fstream>
0004 
0005 // user includes
0006 #include "CondFormats/DataRecord/interface/SiPixelGenErrorDBObjectRcd.h"
0007 #include "CondFormats/SiPixelObjects/interface/SiPixelGenErrorDBObject.h"
0008 #include "FWCore/Framework/interface/ESProducer.h"
0009 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 #include "FWCore/Framework/interface/ModuleFactory.h"
0012 #include "FWCore/Framework/interface/SourceFactory.h"
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0017 
0018 class SiPixelFakeGenErrorDBObjectESSource : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0019 public:
0020   SiPixelFakeGenErrorDBObjectESSource(const edm::ParameterSet&);
0021   ~SiPixelFakeGenErrorDBObjectESSource() override = default;
0022 
0023   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0024 
0025   typedef std::vector<std::string> vstring;
0026 
0027   virtual std::unique_ptr<SiPixelGenErrorDBObject> produce(const SiPixelGenErrorDBObjectRcd&);
0028 
0029 protected:
0030   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0031                       const edm::IOVSyncValue&,
0032                       edm::ValidityInterval&) override;
0033 
0034 private:
0035   vstring GenErrorCalibrations_;
0036   float version_;
0037 };
0038 
0039 SiPixelFakeGenErrorDBObjectESSource::SiPixelFakeGenErrorDBObjectESSource(const edm::ParameterSet& conf_)
0040     : GenErrorCalibrations_(conf_.getParameter<vstring>("siPixelGenErrorCalibrations")),
0041       version_(conf_.getParameter<double>("Version")) {
0042   edm::LogInfo("SiPixelFakeGenErrorDBObjectESSource::SiPixelFakeGenErrorDBObjectESSource");
0043   //the following line is needed to tell the framework what
0044   // data is being produced
0045   setWhatProduced(this);
0046   findingRecord<SiPixelGenErrorDBObjectRcd>();
0047 }
0048 
0049 std::unique_ptr<SiPixelGenErrorDBObject> SiPixelFakeGenErrorDBObjectESSource::produce(
0050     const SiPixelGenErrorDBObjectRcd&) {
0051   using namespace edm::es;
0052 
0053   //Mostly copied from CondTools/SiPixel/test/SiPixelGenErrorDBObjectUploader.cc
0054   //--- Make the POOL-ORA object to store the database object
0055   SiPixelGenErrorDBObject* obj = new SiPixelGenErrorDBObject;
0056 
0057   // Local variables
0058   int m;
0059 
0060   // Set the number of GenErrors to be passed to the dbobject
0061   obj->setNumOfTempl(GenErrorCalibrations_.size());
0062 
0063   // Set the version of the GenError dbobject - this is an external parameter
0064   obj->setVersion(version_);
0065 
0066   //  open the GenError file(s)
0067   for (m = 0; m < obj->numOfTempl(); ++m) {
0068     edm::FileInPath file(GenErrorCalibrations_[m].c_str());
0069     std::ifstream in_file(file.fullPath(), std::ios::in);
0070 
0071     if (in_file.is_open()) {
0072       edm::LogPrint("SiPixelFakeGenErrorDBObjectESSource")
0073           << "Opened GenError File: " << file.fullPath().c_str() << std::endl;
0074 
0075       // Local variables
0076       char title_char[80], c;
0077       SiPixelGenErrorDBObject::char2float temp;
0078       float tempstore;
0079       unsigned int iter;
0080 
0081       // GenErrors contain a header char - we must be clever about storing this
0082       for (iter = 0; (c = in_file.get()) != '\n' && iter < 79; ++iter) {
0083         title_char[iter] = c;
0084       }
0085       if (iter == 79) {
0086         title_char[iter] = '\n';
0087       } else {
0088         unsigned int ilast = 3 - (iter % 4);
0089         for (unsigned int it = 0; it != ilast; it++) {
0090           title_char[iter] = ' ';
0091           iter++;
0092         }
0093         title_char[iter] = '\n';
0094       }
0095 
0096       for (unsigned int j = 0; j <= iter; j += 4) {
0097         temp.c[0] = title_char[j];
0098         temp.c[1] = title_char[j + 1];
0099         temp.c[2] = title_char[j + 2];
0100         temp.c[3] = title_char[j + 3];
0101         obj->push_back(temp.f);
0102         obj->setMaxIndex(obj->maxIndex() + 1);
0103       }
0104 
0105       // Fill the dbobject
0106       in_file >> tempstore;
0107       while (!in_file.eof()) {
0108         obj->setMaxIndex(obj->maxIndex() + 1);
0109         obj->push_back(tempstore);
0110         in_file >> tempstore;
0111       }
0112 
0113       in_file.close();
0114     } else {
0115       // If file didn't open, report this
0116       edm::LogError("SiPixeFakelGenErrorDBObjectESSource") << "Error opening File" << file.fullPath() << std::endl;
0117     }
0118   }
0119 
0120   //std::cout << *obj << std::endl;
0121   return std::unique_ptr<SiPixelGenErrorDBObject>(obj);
0122 }
0123 
0124 void SiPixelFakeGenErrorDBObjectESSource::setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0125                                                          const edm::IOVSyncValue& iosv,
0126                                                          edm::ValidityInterval& oValidity) {
0127   edm::ValidityInterval infinity(iosv.beginOfTime(), iosv.endOfTime());
0128   oValidity = infinity;
0129 }
0130 
0131 void SiPixelFakeGenErrorDBObjectESSource::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0132   edm::ParameterSetDescription desc;
0133   desc.add<vstring>(
0134       "siPixelGenErrorCalibrations",
0135       {"CalibTracker/SiPixelESProducers/data/SiPixelTemplateDBObject_0T_phase1_BoR3_v1/generror_summary_zp0310.out",
0136        "CalibTracker/SiPixelESProducers/data/SiPixelTemplateDBObject_0T_phase1_BoR3_v1/generror_summary_zp0311.out",
0137        "CalibTracker/SiPixelESProducers/data/SiPixelTemplateDBObject_0T_phase1_BoR3_v1/generror_summary_zp0312.out",
0138        "CalibTracker/SiPixelESProducers/data/SiPixelTemplateDBObject_0T_phase1_BoR3_v1/generror_summary_zp0313.out",
0139        "CalibTracker/SiPixelESProducers/data/SiPixelTemplateDBObject_0T_phase1_BoR3_v1/generror_summary_zp0314.out",
0140        "CalibTracker/SiPixelESProducers/data/SiPixelTemplateDBObject_0T_phase1_BoR3_v1/generror_summary_zp0315.out"});
0141   desc.add<double>("Version", 1.0);
0142   descriptions.addWithDefaultLabel(desc);
0143 }
0144 
0145 DEFINE_FWK_EVENTSETUP_SOURCE(SiPixelFakeGenErrorDBObjectESSource);