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 
CastorChannelQualityRcd.h
CastorPedestalsRcd.h
service
Definition: service.py:1
CastorDbProducer::gainWidthsToken_
edm::ESGetToken< CastorGainWidths, CastorGainWidthsRcd > gainWidthsToken_
Definition: CastorDbProducer.cc:69
mixOne_cfi.ESProducer
ESProducer
Definition: mixOne_cfi.py:33
CastorDbProducer::pedestalWidthsToken_
edm::ESGetToken< CastorPedestalWidths, CastorPedestalWidthsRcd > pedestalWidthsToken_
Definition: CastorDbProducer.cc:67
CastorDbProducer
Definition: CastorDbProducer.cc:43
CastorDbProducer::electronicsMapToken_
edm::ESGetToken< CastorElectronicsMap, CastorElectronicsMapRcd > electronicsMapToken_
Definition: CastorDbProducer.cc:72
CastorQIEDataRcd.h
CastorQIEDataRcd
Definition: CastorQIEDataRcd.h:24
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::ESProducer::setWhatProduced
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
AllObjects.h
ESProducer.h
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
CastorDbProducer::produce
std::shared_ptr< CastorDbService > produce(const CastorDbRecord &)
Definition: CastorDbProducer.cc:112
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
CastorPedestalWidthsRcd
Definition: CastorPedestalWidthsRcd.h:24
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
CastorGainWidthsRcd.h
query.host
string host
Definition: query.py:115
CastorDbProducer::holder_
edm::ReusableObjectHolder< HostType > holder_
Definition: CastorDbProducer.cc:64
edm::ReusableObjectHolder< HostType >
edm::ReusableObjectHolder::makeOrGet
std::shared_ptr< T > makeOrGet(F iFunc)
If there isn't an object already available, creates a new one using iFunc.
Definition: ReusableObjectHolder.h:126
CastorDbProducer::mDumpStream
std::ostream * mDumpStream
Definition: CastorDbProducer.cc:75
ReusableObjectHolder.h
CastorElectronicsMapRcd.h
h
CastorPedestalWidthsRcd.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CastorDbProducer::gainsToken_
edm::ESGetToken< CastorGains, CastorGainsRcd > gainsToken_
Definition: CastorDbProducer.cc:68
CastorDbProducer::CastorDbProducer
CastorDbProducer(const edm::ParameterSet &)
Definition: CastorDbProducer.cc:78
CastorDbProducer::mDumpRequest
std::vector< std::string > mDumpRequest
Definition: CastorDbProducer.cc:74
CastorDbASCIIIO::dumpObject
bool dumpObject(std::ostream &fOutput, const CastorPedestals &fObject)
Definition: CastorDbASCIIIO.cc:323
edm::ParameterSet
Definition: ParameterSet.h:47
CastorChannelQualityRcd
Definition: CastorChannelQualityRcd.h:24
CastorGainsRcd.h
CastorDbProducer::setupItem
void setupItem(const RecordT &fRecord, const TokenT &token, const char *name, CastorDbService *service)
Definition: CastorDbProducer.cc:158
CastorDbService
Definition: CastorDbService.h:28
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
CastorDbProducer::~CastorDbProducer
~CastorDbProducer() override
Definition: CastorDbProducer.cc:100
cc
edm::ESGetToken< CastorPedestals, CastorPedestalsRcd >
CastorDbRecord
Definition: CastorDbRecord.h:29
CastorDbASCIIIO.h
ModuleFactory.h
edm::ESProductHost
Definition: ESProductHost.h:93
CastorDbProducer::pedestalsToken_
edm::ESGetToken< CastorPedestals, CastorPedestalsRcd > pedestalsToken_
Definition: CastorDbProducer.cc:66
CastorDbProducer::qieDataToken_
edm::ESGetToken< CastorQIEData, CastorQIEDataRcd > qieDataToken_
Definition: CastorDbProducer.cc:70
DEFINE_FWK_EVENTSETUP_MODULE
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
CastorElectronicsMapRcd
Definition: CastorElectronicsMapRcd.h:4
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
CastorDbService.h
edm::ESProducer
Definition: ESProducer.h:104
ESProductHost.h
CastorGainsRcd
Definition: CastorGainsRcd.h:24
CastorDbProducer::HostType
edm::ESProductHost< CastorDbService, CastorPedestalsRcd, CastorPedestalWidthsRcd, CastorGainsRcd, CastorGainWidthsRcd, CastorQIEDataRcd, CastorChannelQualityRcd, CastorElectronicsMapRcd > HostType
Definition: CastorDbProducer.cc:59
CastorDbRecord.h
CastorDbProducer::channelQualityToken_
edm::ESGetToken< CastorChannelQuality, CastorChannelQualityRcd > channelQualityToken_
Definition: CastorDbProducer.cc:71
CastorPedestalsRcd
Definition: CastorPedestalsRcd.h:24
CastorGainWidthsRcd
Definition: CastorGainWidthsRcd.h:24
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316