File indexing completed on 2024-10-17 04:57:59
0001
0002 #include <memory>
0003 #include <fstream>
0004
0005
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
0044
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
0054
0055 SiPixelGenErrorDBObject* obj = new SiPixelGenErrorDBObject;
0056
0057
0058 int m;
0059
0060
0061 obj->setNumOfTempl(GenErrorCalibrations_.size());
0062
0063
0064 obj->setVersion(version_);
0065
0066
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
0076 char title_char[80], c;
0077 SiPixelGenErrorDBObject::char2float temp;
0078 float tempstore;
0079 unsigned int iter;
0080
0081
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
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
0116 edm::LogError("SiPixeFakelGenErrorDBObjectESSource") << "Error opening File" << file.fullPath() << std::endl;
0117 }
0118 }
0119
0120
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);