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 
21 // system include files
22 #include <iostream>
23 #include <fstream>
24 
26 
30 
31 
33 
34 #include "CastorDbProducer.h"
35 
37  : ESProducer(),
38  mDumpRequest (),
39  mDumpStream(nullptr)
40 {
41  //the following line is needed to tell the framework what
42  // data is being produced
43  setWhatProduced(this);
44 
45  //now do what ever other initialization is needed
46 
47  mDumpRequest = fConfig.getUntrackedParameter <std::vector <std::string> > ("dump", std::vector<std::string>());
48  if (!mDumpRequest.empty()) {
49  std::string otputFile = fConfig.getUntrackedParameter <std::string> ("file", "");
50  mDumpStream = otputFile.empty () ? &std::cout : new std::ofstream (otputFile.c_str());
51  }
52 }
53 
54 
56 {
57 
58  // do anything here that needs to be done at desctruction time
59  // (e.g. close files, deallocate resources etc.)
60  if (mDumpStream != &std::cout) delete mDumpStream;
61 }
62 
63 
64 //
65 // member functions
66 //
67 
68 // ------------ method called to produce the data ------------
69 std::shared_ptr<CastorDbService> CastorDbProducer::produce( const CastorDbRecord& record)
70 {
71  auto host = holder_.makeOrGet([]() {
72  return new HostType;
73  });
74 
75  bool needBuildCalibrations = false;
76  bool needBuildCalibWidths = false;
77 
78  host->ifRecordChanges<CastorElectronicsMapRcd>(record,
79  [this, h=host.get()](auto const& rec) {
80  setupElectronicsMap(rec, h);
81  });
82  host->ifRecordChanges<CastorChannelQualityRcd>(record,
83  [this, h=host.get()](auto const& rec) {
84  setupChannelQuality(rec, h);
85  });
86  host->ifRecordChanges<CastorGainWidthsRcd>(record,
87  [this, h=host.get(),
88  &needBuildCalibWidths](auto const& rec) {
89  setupGainWidths(rec, h);
90  needBuildCalibWidths = true;
91  });
92  host->ifRecordChanges<CastorQIEDataRcd>(record,
93  [this, h=host.get(),
94  &needBuildCalibrations,
95  &needBuildCalibWidths](auto const& rec) {
96  setupQIEData(rec, h);
97  needBuildCalibrations = true;
98  needBuildCalibWidths = true;
99  });
100  host->ifRecordChanges<CastorPedestalWidthsRcd>(record,
101  [this, h=host.get(),
102  &needBuildCalibWidths](auto const& rec) {
103  setupPedestalWidths(rec, h);
104  needBuildCalibWidths = true;
105  });
106  host->ifRecordChanges<CastorGainsRcd>(record,
107  [this, h=host.get(),
108  &needBuildCalibrations](auto const& rec) {
109  setupGains(rec, h);
110  needBuildCalibrations = true;
111  });
112  host->ifRecordChanges<CastorPedestalsRcd>(record,
113  [this, h=host.get(),
114  &needBuildCalibrations](auto const& rec) {
115  setupPedestals(rec, h);
116  needBuildCalibrations = true;
117  });
118 
119  if (needBuildCalibWidths) {
120  host->buildCalibWidths();
121  }
122 
123  if (needBuildCalibrations) {
124  host->buildCalibrations();
125  }
126 
127  return host; // automatically converts to std::shared_ptr<CastorDbService>
128 }
129 
132 
134  fRecord.get (item);
135 
136  service->setData(item.product());
137  if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("Pedestals")) != mDumpRequest.end()) {
138  *mDumpStream << "New HCAL/CASTOR Pedestals set" << std::endl;
140  }
141 }
142 
146  fRecord.get (item);
147  service->setData(item.product());
148  if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("PedestalWidths")) != mDumpRequest.end()) {
149  *mDumpStream << "New HCAL/CASTOR Pedestals set" << std::endl;
151  }
152 }
153 
154 
158  fRecord.get (item);
159  service->setData(item.product());
160  if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("Gains")) != mDumpRequest.end()) {
161  *mDumpStream << "New HCAL/CASTOR Gains set" << std::endl;
163  }
164 }
165 
166 
170  fRecord.get (item);
171  service->setData(item.product());
172  if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("GainWidths")) != mDumpRequest.end()) {
173  *mDumpStream << "New HCAL/CASTOR GainWidths set" << std::endl;
175  }
176 }
177 
181  fRecord.get (item);
182  service->setData(item.product());
183  if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("QIEData")) != mDumpRequest.end()) {
184  *mDumpStream << "New HCAL/CASTOR QIEData set" << std::endl;
186  }
187 }
188 
192  fRecord.get (item);
193  service->setData(item.product());
194  if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("ChannelQuality")) != mDumpRequest.end()) {
195  *mDumpStream << "New HCAL/CASTOR ChannelQuality set" << std::endl;
197  }
198 }
199 
203  fRecord.get (item);
204  service->setData(item.product());
205  if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("ElectronicsMap")) != mDumpRequest.end()) {
206  *mDumpStream << "New HCAL/CASTOR Electronics Map set" << std::endl;
208  }
209 }
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
~CastorDbProducer() override
#define nullptr
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
edm::ESProductHost< CastorDbService, CastorPedestalsRcd, CastorPedestalWidthsRcd, CastorGainsRcd, CastorGainWidthsRcd, CastorQIEDataRcd, CastorChannelQualityRcd, CastorElectronicsMapRcd > HostType
void setupGains(const CastorGainsRcd &, CastorDbService *)
void setupChannelQuality(const CastorChannelQualityRcd &, CastorDbService *)
void get(HolderT &iHolder) const
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 &)