CMS 3D CMS Logo

CastorDbProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CastorDbProducer
4 // Class: CastorDbProducer
5 //
13 //
14 // Original Author: Fedor Ratnikov
15 // Created: Tue Aug 9 19:10:10 CDT 2005
16 // Adapted for CASTOR by L. Mundim
17 //
18 //
19 
20 // system include files
21 #include <iostream>
22 #include <fstream>
23 
25 
29 
31 
32 #include "CastorDbProducer.h"
33 
35  : ESProducer(), mDumpRequest(), mDumpStream(nullptr) {
36  //the following line is needed to tell the framework what
37  // data is being produced
38  setWhatProduced(this);
39 
40  //now do what ever other initialization is needed
41 
42  mDumpRequest = fConfig.getUntrackedParameter<std::vector<std::string> >("dump", std::vector<std::string>());
43  if (!mDumpRequest.empty()) {
44  std::string otputFile = fConfig.getUntrackedParameter<std::string>("file", "");
45  mDumpStream = otputFile.empty() ? &std::cout : new std::ofstream(otputFile.c_str());
46  }
47 }
48 
50  // do anything here that needs to be done at desctruction time
51  // (e.g. close files, deallocate resources etc.)
52  if (mDumpStream != &std::cout)
53  delete mDumpStream;
54 }
55 
56 //
57 // member functions
58 //
59 
60 // ------------ method called to produce the data ------------
61 std::shared_ptr<CastorDbService> CastorDbProducer::produce(const CastorDbRecord& record) {
62  auto host = holder_.makeOrGet([]() { return new HostType; });
63 
64  bool needBuildCalibrations = false;
65  bool needBuildCalibWidths = false;
66 
67  host->ifRecordChanges<CastorElectronicsMapRcd>(
68  record, [this, h = host.get()](auto const& rec) { setupElectronicsMap(rec, h); });
69  host->ifRecordChanges<CastorChannelQualityRcd>(
70  record, [this, h = host.get()](auto const& rec) { setupChannelQuality(rec, h); });
71  host->ifRecordChanges<CastorGainWidthsRcd>(record, [this, h = host.get(), &needBuildCalibWidths](auto const& rec) {
72  setupGainWidths(rec, h);
73  needBuildCalibWidths = true;
74  });
75  host->ifRecordChanges<CastorQIEDataRcd>(
76  record, [this, h = host.get(), &needBuildCalibrations, &needBuildCalibWidths](auto const& rec) {
77  setupQIEData(rec, h);
78  needBuildCalibrations = true;
79  needBuildCalibWidths = true;
80  });
81  host->ifRecordChanges<CastorPedestalWidthsRcd>(record,
82  [this, h = host.get(), &needBuildCalibWidths](auto const& rec) {
83  setupPedestalWidths(rec, h);
84  needBuildCalibWidths = true;
85  });
86  host->ifRecordChanges<CastorGainsRcd>(record, [this, h = host.get(), &needBuildCalibrations](auto const& rec) {
87  setupGains(rec, h);
88  needBuildCalibrations = true;
89  });
90  host->ifRecordChanges<CastorPedestalsRcd>(record, [this, h = host.get(), &needBuildCalibrations](auto const& rec) {
91  setupPedestals(rec, h);
92  needBuildCalibrations = true;
93  });
94 
95  if (needBuildCalibWidths) {
96  host->buildCalibWidths();
97  }
98 
99  if (needBuildCalibrations) {
100  host->buildCalibrations();
101  }
102 
103  return host; // automatically converts to std::shared_ptr<CastorDbService>
104 }
105 
108  fRecord.get(item);
109 
110  service->setData(item.product());
111  if (std::find(mDumpRequest.begin(), mDumpRequest.end(), std::string("Pedestals")) != mDumpRequest.end()) {
112  *mDumpStream << "New HCAL/CASTOR Pedestals set" << std::endl;
114  }
115 }
116 
119  fRecord.get(item);
120  service->setData(item.product());
121  if (std::find(mDumpRequest.begin(), mDumpRequest.end(), std::string("PedestalWidths")) != mDumpRequest.end()) {
122  *mDumpStream << "New HCAL/CASTOR Pedestals set" << std::endl;
124  }
125 }
126 
129  fRecord.get(item);
130  service->setData(item.product());
131  if (std::find(mDumpRequest.begin(), mDumpRequest.end(), std::string("Gains")) != mDumpRequest.end()) {
132  *mDumpStream << "New HCAL/CASTOR Gains set" << std::endl;
134  }
135 }
136 
139  fRecord.get(item);
140  service->setData(item.product());
141  if (std::find(mDumpRequest.begin(), mDumpRequest.end(), std::string("GainWidths")) != mDumpRequest.end()) {
142  *mDumpStream << "New HCAL/CASTOR GainWidths set" << std::endl;
144  }
145 }
146 
149  fRecord.get(item);
150  service->setData(item.product());
151  if (std::find(mDumpRequest.begin(), mDumpRequest.end(), std::string("QIEData")) != mDumpRequest.end()) {
152  *mDumpStream << "New HCAL/CASTOR QIEData set" << std::endl;
154  }
155 }
156 
159  fRecord.get(item);
160  service->setData(item.product());
161  if (std::find(mDumpRequest.begin(), mDumpRequest.end(), std::string("ChannelQuality")) != mDumpRequest.end()) {
162  *mDumpStream << "New HCAL/CASTOR ChannelQuality set" << std::endl;
164  }
165 }
166 
169  fRecord.get(item);
170  service->setData(item.product());
171  if (std::find(mDumpRequest.begin(), mDumpRequest.end(), std::string("ElectronicsMap")) != mDumpRequest.end()) {
172  *mDumpStream << "New HCAL/CASTOR Electronics Map set" << std::endl;
174  }
175 }
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:124
T getUntrackedParameter(std::string const &, T const &) const
host
Definition: query.py:115
void setupElectronicsMap(const CastorElectronicsMapRcd &, CastorDbService *)
std::vector< std::string > mDumpRequest
void setupQIEData(const CastorQIEDataRcd &, CastorDbService *)
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
JetCorrectorParameters::Record record
Definition: classes.h:7
#define nullptr
~CastorDbProducer() override
std::shared_ptr< T > makeOrGet(F iFunc)
If there isn&#39;t an object already available, creates a new one using iFunc.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
edm::ESProductHost< CastorDbService, CastorPedestalsRcd, CastorPedestalWidthsRcd, CastorGainsRcd, CastorGainWidthsRcd, CastorQIEDataRcd, CastorChannelQualityRcd, CastorElectronicsMapRcd > HostType
void setupGains(const CastorGainsRcd &, CastorDbService *)
void setupChannelQuality(const CastorChannelQualityRcd &, CastorDbService *)
bool dumpObject(std::ostream &fOutput, const CastorPedestals &fObject)
void setupPedestalWidths(const CastorPedestalWidthsRcd &, CastorDbService *)
std::shared_ptr< CastorDbService > produce(const CastorDbRecord &)
void setupPedestals(const CastorPedestalsRcd &, CastorDbService *)
edm::ReusableObjectHolder< HostType > holder_
void setData(const CastorPedestals *fItem)
std::ostream * mDumpStream
void setupGainWidths(const CastorGainWidthsRcd &, CastorDbService *)
T const * product() const
Definition: ESHandle.h:86
CastorDbProducer(const edm::ParameterSet &)