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 #include <memory>
24 
29 
33 
42 
44 public:
46  ~CastorDbProducer() override;
47 
48  std::shared_ptr<CastorDbService> produce(const CastorDbRecord&);
49 
50 private:
51  // ----------member data ---------------------------
60 
61  template <typename RecordT, typename TokenT>
62  void setupItem(const RecordT& fRecord, const TokenT& token, const char* name, CastorDbService* service);
63 
65 
73 
74  std::vector<std::string> mDumpRequest;
75  std::ostream* mDumpStream;
76 };
77 
79  : ESProducer(), mDumpRequest(), mDumpStream(nullptr) {
80  //the following line is needed to tell the framework what
81  // data is being produced
82  auto cc = setWhatProduced(this);
83  pedestalsToken_ = cc.consumes();
84  pedestalWidthsToken_ = cc.consumes();
85  gainsToken_ = cc.consumes();
86  gainWidthsToken_ = cc.consumes();
87  qieDataToken_ = cc.consumes();
88  channelQualityToken_ = cc.consumes();
89  electronicsMapToken_ = cc.consumes();
90 
91  //now do what ever other initialization is needed
92 
93  mDumpRequest = fConfig.getUntrackedParameter<std::vector<std::string> >("dump", std::vector<std::string>());
94  if (!mDumpRequest.empty()) {
95  std::string otputFile = fConfig.getUntrackedParameter<std::string>("file", "");
96  mDumpStream = otputFile.empty() ? &std::cout : new std::ofstream(otputFile.c_str());
97  }
98 }
99 
101  // do anything here that needs to be done at desctruction time
102  // (e.g. close files, deallocate resources etc.)
103  if (mDumpStream != &std::cout)
104  delete mDumpStream;
105 }
106 
107 //
108 // member functions
109 //
110 
111 // ------------ method called to produce the data ------------
112 std::shared_ptr<CastorDbService> CastorDbProducer::produce(const CastorDbRecord& record) {
113  auto host = holder_.makeOrGet([]() { return new HostType; });
114 
115  bool needBuildCalibrations = false;
116  bool needBuildCalibWidths = false;
117 
118  host->ifRecordChanges<CastorElectronicsMapRcd>(
119  record, [this, h = host.get()](auto const& rec) { setupItem(rec, electronicsMapToken_, "ElectronicsMap", h); });
120  host->ifRecordChanges<CastorChannelQualityRcd>(
121  record, [this, h = host.get()](auto const& rec) { setupItem(rec, channelQualityToken_, "ChannelQuality", h); });
122  host->ifRecordChanges<CastorGainWidthsRcd>(record, [this, h = host.get(), &needBuildCalibWidths](auto const& rec) {
123  setupItem(rec, gainWidthsToken_, "GainWidths", h);
124  needBuildCalibWidths = true;
125  });
126  host->ifRecordChanges<CastorQIEDataRcd>(
127  record, [this, h = host.get(), &needBuildCalibrations, &needBuildCalibWidths](auto const& rec) {
128  setupItem(rec, qieDataToken_, "QIEData", h);
129  needBuildCalibrations = true;
130  needBuildCalibWidths = true;
131  });
132  host->ifRecordChanges<CastorPedestalWidthsRcd>(record,
133  [this, h = host.get(), &needBuildCalibWidths](auto const& rec) {
134  setupItem(rec, pedestalWidthsToken_, "PedestalWidths", h);
135  needBuildCalibWidths = true;
136  });
137  host->ifRecordChanges<CastorGainsRcd>(record, [this, h = host.get(), &needBuildCalibrations](auto const& rec) {
138  setupItem(rec, gainsToken_, "Gains", h);
139  needBuildCalibrations = true;
140  });
141  host->ifRecordChanges<CastorPedestalsRcd>(record, [this, h = host.get(), &needBuildCalibrations](auto const& rec) {
142  setupItem(rec, pedestalsToken_, "Pedestals", h);
143  needBuildCalibrations = true;
144  });
145 
146  if (needBuildCalibWidths) {
147  host->buildCalibWidths();
148  }
149 
150  if (needBuildCalibrations) {
151  host->buildCalibrations();
152  }
153 
154  return host; // automatically converts to std::shared_ptr<CastorDbService>
155 }
156 
157 template <typename RecordT, typename TokenT>
158 void CastorDbProducer::setupItem(const RecordT& fRecord,
159  const TokenT& token,
160  const char* name,
162  const auto& item = fRecord.get(token);
163  service->setData(&item);
164  if (std::find(mDumpRequest.begin(), mDumpRequest.end(), name) != mDumpRequest.end()) {
165  *mDumpStream << "New HCAL/CASTOR " << name << " set" << std::endl;
167  }
168 }
169 
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
void setupItem(const RecordT &fRecord, const TokenT &token, const char *name, CastorDbService *service)
std::vector< std::string > mDumpRequest
string host
Definition: query.py:115
~CastorDbProducer() override
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::ESGetToken< CastorPedestals, CastorPedestalsRcd > pedestalsToken_
edm::ESGetToken< CastorQIEData, CastorQIEDataRcd > qieDataToken_
T getUntrackedParameter(std::string const &, T const &) const
edm::ESProductHost< CastorDbService, CastorPedestalsRcd, CastorPedestalWidthsRcd, CastorGainsRcd, CastorGainWidthsRcd, CastorQIEDataRcd, CastorChannelQualityRcd, CastorElectronicsMapRcd > HostType
edm::ESGetToken< CastorChannelQuality, CastorChannelQualityRcd > channelQualityToken_
edm::ESGetToken< CastorPedestalWidths, CastorPedestalWidthsRcd > pedestalWidthsToken_
edm::ESGetToken< CastorGainWidths, CastorGainWidthsRcd > gainWidthsToken_
std::shared_ptr< T > makeOrGet(FM &&iMakeFunc)
Takes an object from the queue if one is available, or creates one using iMakeFunc.
edm::ESGetToken< CastorElectronicsMap, CastorElectronicsMapRcd > electronicsMapToken_
bool dumpObject(std::ostream &fOutput, const CastorPedestals &fObject)
std::shared_ptr< CastorDbService > produce(const CastorDbRecord &)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
edm::ReusableObjectHolder< HostType > holder_
std::ostream * mDumpStream
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
edm::ESGetToken< CastorGains, CastorGainsRcd > gainsToken_
CastorDbProducer(const edm::ParameterSet &)