CMS 3D CMS Logo

HcalDbProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HcalDbProducer
4 // Class: HcalDbProducer
5 //
13 //
14 // Original Author: Fedor Ratnikov
15 // Created: Tue Aug 9 19:10:10 CDT 2005
16 //
17 //
18 
19 // system include files
20 #include <iostream>
21 #include <fstream>
22 #include <memory>
23 
32 
38 
40 public:
42  ~HcalDbProducer() override;
43 
44  std::shared_ptr<HcalDbService> produce(const HcalDbRecord&);
45 
46 private:
70 
71  // Helper functions and class for the tokens and work for HcalDbService
72  template <typename ProductType>
73  static void serviceSetData(HostType& host, const ProductType& item, std::false_type) {
74  host.setData(&item);
75  }
76  template <typename ProductType>
77  static void serviceSetData(HostType& host, const ProductType& item, std::true_type) {
78  host.setData(&item, true);
79  }
80  template <typename ProductType, typename RecordType, const char* LABEL, typename EffectiveType>
82  public:
84  : dumpName_(edm::typeDemangle(typeid(ProductType).name()).substr(4)) // remove leading "Hcal"
85  {
86  if constexpr (EffectiveType::value) {
87  dumpName_ = "Effective" + dumpName_;
88  }
89  }
90  void setConsumes(edm::ESConsumesCollector& cc) { token_ = cc.consumes(edm::ESInputTag{"", LABEL}); }
92  const RecordType& record,
93  const std::vector<std::string>& dumpRequest,
94  std::ostream* dumpStream) {
95  const auto& item = record.get(token_);
96  serviceSetData(host, item, EffectiveType{});
97 
98  if (std::find(dumpRequest.begin(), dumpRequest.end(), dumpName_) != dumpRequest.end()) {
99  *dumpStream << "New HCAL " << dumpName_ << " set" << std::endl;
100  HcalDbASCIIIO::dumpObject(*dumpStream, item);
101  }
102  }
103 
104  private:
107  };
108 
109  template <typename ProductType, const char* LABEL, typename EffectiveType = std::false_type>
110  struct ServiceToken {
111  using Product = ProductType;
112  static constexpr const char* label = LABEL;
113  using Effective = EffectiveType;
114  };
115 
116  template <typename RecordType, typename... TokenHolders>
118  public:
120  std::apply([&cc](auto&&... item) { ((item.setConsumes(cc)), ...); }, tokens_);
121  }
123  const HcalDbRecord& record,
124  const std::vector<std::string>& dumpRequest,
125  std::ostream* dumpStream) {
126  host.ifRecordChanges<RecordType>(record, [this, &host, &dumpRequest, &dumpStream](auto const& rec) {
127  std::apply([&host, &rec, &dumpRequest, &dumpStream](
128  auto&&... item) { ((item.setupHcalDbService(host, rec, dumpRequest, dumpStream)), ...); },
129  tokens_);
130  });
131  }
132 
133  private:
134  std::tuple<ServiceTokenImpl<typename TokenHolders::Product,
135  RecordType,
137  typename TokenHolders::Effective>...>
139  };
140 
141  // Helper class and functions for the individual products
142  template <typename ProductT, typename RecordT>
144  public:
145  using Product = ProductT;
146  using Record = RecordT;
147 
148  TokenAndTopologyHolder() = default;
149 
151  token_ = cc.consumes(tag);
152  topoToken_ = cc.consumes();
153  }
154 
155  const auto& token() const { return token_; }
156 
157  const auto& topoToken() const { return topoToken_; }
158 
159  private:
162  };
163 
164  template <typename ProductType, typename RecordType, size_t IND1, size_t IND2>
165  std::unique_ptr<ProductType> produceWithTopology(RecordType const& record) {
166  const auto& tokenHolder = std::get<IND2>(std::get<IND1>(tokenHolders_));
167  auto item = record.getTransientHandle(tokenHolder.token());
168 
169  auto productWithTopology = std::make_unique<ProductType>(*item);
170  const auto& topo = record.get(tokenHolder.topoToken());
171  productWithTopology->setTopo(&topo);
172 
173  return productWithTopology;
174  }
175 
176  template <size_t IND1, size_t IND2>
177  void setupProduce(const char* label, const edm::ESInputTag& tag) {
178  auto& holder = std::get<IND2>(std::get<IND1>(tokenHolders_));
179 
180  using HolderT = typename std::remove_reference<decltype(holder)>::type;
181  using ProductT = typename HolderT::Product;
182  using RecordT = typename HolderT::Record;
183 
184  holder.setConsumes(
186  this, &HcalDbProducer::produceWithTopology<ProductT, RecordT, IND1, IND2>, edm::es::Label(label)),
187  tag);
188  }
189 
190  template <size_t IND1, size_t... IND2s>
191  void setupProduceAllImpl(const char* label, const edm::ESInputTag& tag, std::index_sequence<IND2s...>) {
192  ((setupProduce<IND1, IND2s>(label, tag)), ...);
193  }
194 
195  template <size_t IND1>
196  void setupProduceAll(const char* label, const edm::ESInputTag& tag) {
197  setupProduceAllImpl<IND1>(
198  label, tag, std::make_index_sequence<std::tuple_size_v<std::tuple_element_t<IND1, decltype(tokenHolders_)>>>{});
199  }
200 
201  // ----------member data ---------------------------
203 
204  // Tokens for the "service" produce function
205  constexpr static const char kWithTopoEff[] = "withTopoEff";
206  constexpr static const char kWithTopo[] = "withTopo";
207  constexpr static const char kEmpty[] = "";
235 
236  // Tokens for the produceWithTopology functions
237  std::tuple<
238  // First are withTopo
239  std::tuple<TokenAndTopologyHolder<HcalPedestals, HcalPedestalsRcd>,
257  // Then withTopoEff
258  std::tuple<TokenAndTopologyHolder<HcalPedestals, HcalPedestalsRcd>,
261 
262  std::vector<std::string> mDumpRequest;
263  std::ostream* mDumpStream;
264 };
265 
266 HcalDbProducer::HcalDbProducer(const edm::ParameterSet& fConfig) : ESProducer(), mDumpRequest(), mDumpStream(nullptr) {
267  auto cc = setWhatProduced(this);
268  std::apply([&cc](auto&&... item) { ((item.setConsumes(cc)), ...); }, tokensForService_);
269 
270  // Setup all withTopo produces functions and their consumes
271  setupProduceAll<0>("withTopo", edm::ESInputTag{});
272  // Setup all withTopoEff produces functions and their consumes
273  setupProduceAll<1>("withTopoEff", edm::ESInputTag{"", "effective"});
274 
275  mDumpRequest = fConfig.getUntrackedParameter<std::vector<std::string>>("dump", std::vector<std::string>());
276  if (!mDumpRequest.empty()) {
277  std::string otputFile = fConfig.getUntrackedParameter<std::string>("file", "");
278  mDumpStream = otputFile.empty() ? &std::cout : new std::ofstream(otputFile.c_str());
279  }
280 }
281 
283  if (mDumpStream != &std::cout)
284  delete mDumpStream;
285 }
286 
287 // ------------ method called to produce the data ------------
288 std::shared_ptr<HcalDbService> HcalDbProducer::produce(const HcalDbRecord& record) {
289  auto host = holder_.makeOrGet([]() { return new HostType; });
290 
291  std::apply([this, &host, &record](
292  auto&&... item) { ((item.setupHcalDbService(*host, record, mDumpRequest, mDumpStream)), ...); },
294 
295  return host;
296 }
297 
HcalDbProducer::TokenAndTopologyHolder::token
const auto & token() const
Definition: HcalDbProducer.cc:155
HcalTPChannelParametersRcd
Definition: HcalTPChannelParametersRcd.h:7
mixOne_cfi.ESProducer
ESProducer
Definition: mixOne_cfi.py:33
edm::ESInputTag
Definition: ESInputTag.h:87
HcalSiPMCharacteristicsRcd
Definition: HcalSiPMCharacteristicsRcd.h:4
HcalElectronicsMapRcd
Definition: HcalElectronicsMapRcd.h:8
ESTransientHandle.h
HcalLutMetadataRcd
Definition: HcalLutMetadataRcd.h:25
HcalDbProducer::TokensForServiceHolder::setupHcalDbService
void setupHcalDbService(HostType &host, const HcalDbRecord &record, const std::vector< std::string > &dumpRequest, std::ostream *dumpStream)
Definition: HcalDbProducer.cc:122
HcalDbProducer::ServiceTokenImpl
Definition: HcalDbProducer.cc:81
edm::ESConsumesCollector
Definition: ESConsumesCollector.h:61
ESHandle.h
TypeDemangler.h
HcalChannelQualityRcd
Definition: HcalChannelQualityRcd.h:8
HcalGainsRcd
Definition: HcalGainsRcd.h:8
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::typeDemangle
std::string typeDemangle(char const *mangledName)
Definition: TypeDemangler.cc:93
HcalDbProducer::serviceSetData
static void serviceSetData(HostType &host, const ProductType &item, std::false_type)
Definition: HcalDbProducer.cc:73
HcalDbProducer::mDumpStream
std::ostream * mDumpStream
Definition: HcalDbProducer.cc:263
HcalL1TriggerObjectsRcd
Definition: HcalL1TriggerObjectsRcd.h:25
AllObjects.h
gather_cfg.cout
cout
Definition: gather_cfg.py:144
HcalDbProducer::HcalDbProducer
HcalDbProducer(const edm::ParameterSet &)
Definition: HcalDbProducer.cc:266
HcalDbProducer::serviceSetData
static void serviceSetData(HostType &host, const ProductType &item, std::true_type)
Definition: HcalDbProducer.cc:77
HcalMCParamsRcd
Definition: HcalMCParamsRcd.h:6
edm::ESProducer::setWhatProduced
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
ESProducer.h
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
HcalDbProducer::TokensForServiceHolder::tokens_
std::tuple< ServiceTokenImpl< typename TokenHolders::Product, RecordType, TokenHolders::label, typename TokenHolders::Effective >... > tokens_
Definition: HcalDbProducer.cc:138
HcalDbProducer::TokensForServiceHolder::setConsumes
void setConsumes(edm::ESConsumesCollector &cc)
Definition: HcalDbProducer.cc:119
apply
Vec apply(Vec v, F f)
Definition: ExtVec.h:81
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
HcalDbProducer::TokenAndTopologyHolder::topoToken
const auto & topoToken() const
Definition: HcalDbProducer.cc:157
HcalDbProducer::TokenAndTopologyHolder::topoToken_
edm::ESGetToken< HcalTopology, HcalRecNumberingRecord > topoToken_
Definition: HcalDbProducer.cc:161
HcalDbProducer::TokenAndTopologyHolder::setConsumes
void setConsumes(edm::ESConsumesCollector &&cc, const edm::ESInputTag &tag)
Definition: HcalDbProducer.cc:150
HcalDbProducer::setupProduceAll
void setupProduceAll(const char *label, const edm::ESInputTag &tag)
Definition: HcalDbProducer.cc:196
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
HcalGainWidthsRcd
Definition: HcalGainWidthsRcd.h:8
query.host
string host
Definition: query.py:115
HcalLUTCorrsRcd
Definition: HcalLUTCorrsRcd.h:25
HcalDbProducer::TokenAndTopologyHolder::Product
ProductT Product
Definition: HcalDbProducer.cc:145
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
HcalDbProducer::ServiceTokenImpl::token_
edm::ESGetToken< ProductType, RecordType > token_
Definition: HcalDbProducer.cc:105
HcalDbProducer::ServiceTokenImpl::setupHcalDbService
void setupHcalDbService(HostType &host, const RecordType &record, const std::vector< std::string > &dumpRequest, std::ostream *dumpStream)
Definition: HcalDbProducer.cc:91
HcalQIETypesRcd
Definition: HcalQIETypesRcd.h:25
HcalSiPMParametersRcd
Definition: HcalSiPMParametersRcd.h:7
ReusableObjectHolder.h
HcalDbProducer::produceWithTopology
std::unique_ptr< ProductType > produceWithTopology(RecordType const &record)
Definition: HcalDbProducer.cc:165
HcalDbProducer::tokensForService_
std::tuple< TokensForServiceHolder< HcalPedestalWidthsRcd, ServiceToken< HcalPedestalWidths, kWithTopoEff, std::true_type >, ServiceToken< HcalPedestalWidths, kWithTopo > >, TokensForServiceHolder< HcalPedestalsRcd, ServiceToken< HcalPedestals, kWithTopoEff, std::true_type >, ServiceToken< HcalPedestals, kWithTopo > >, TokensForServiceHolder< HcalRecoParamsRcd, ServiceToken< HcalRecoParams, kWithTopo > >, TokensForServiceHolder< HcalMCParamsRcd, ServiceToken< HcalMCParams, kWithTopo > >, TokensForServiceHolder< HcalLutMetadataRcd, ServiceToken< HcalLutMetadata, kWithTopo > >, TokensForServiceHolder< HcalTPParametersRcd, ServiceToken< HcalTPParameters, kEmpty > >, TokensForServiceHolder< HcalTPChannelParametersRcd, ServiceToken< HcalTPChannelParameters, kWithTopo > >, TokensForServiceHolder< HcalSiPMCharacteristicsRcd, ServiceToken< HcalSiPMCharacteristics, kEmpty > >, TokensForServiceHolder< HcalSiPMParametersRcd, ServiceToken< HcalSiPMParameters, kWithTopo > >, TokensForServiceHolder< HcalFrontEndMapRcd, ServiceToken< HcalFrontEndMap, kEmpty > >, TokensForServiceHolder< HcalElectronicsMapRcd, ServiceToken< HcalElectronicsMap, kEmpty > >, TokensForServiceHolder< HcalL1TriggerObjectsRcd, ServiceToken< HcalL1TriggerObjects, kWithTopo > >, TokensForServiceHolder< HcalZSThresholdsRcd, ServiceToken< HcalZSThresholds, kWithTopo > >, TokensForServiceHolder< HcalChannelQualityRcd, ServiceToken< HcalChannelQuality, kWithTopo > >, TokensForServiceHolder< HcalGainWidthsRcd, ServiceToken< HcalGainWidths, kWithTopo > >, TokensForServiceHolder< HcalQIETypesRcd, ServiceToken< HcalQIETypes, kWithTopo > >, TokensForServiceHolder< HcalQIEDataRcd, ServiceToken< HcalQIEData, kWithTopo > >, TokensForServiceHolder< HcalTimeCorrsRcd, ServiceToken< HcalTimeCorrs, kWithTopo > >, TokensForServiceHolder< HcalPFCorrsRcd, ServiceToken< HcalPFCorrs, kWithTopo > >, TokensForServiceHolder< HcalLUTCorrsRcd, ServiceToken< HcalLUTCorrs, kWithTopo > >, TokensForServiceHolder< HcalGainsRcd, ServiceToken< HcalGains, kWithTopo > >, TokensForServiceHolder< HcalRespCorrsRcd, ServiceToken< HcalRespCorrs, kWithTopo > > > tokensForService_
Definition: HcalDbProducer.cc:234
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
HcalDbProducer::ServiceToken::Product
ProductType Product
Definition: HcalDbProducer.cc:111
edm::es::Label
Definition: es_Label.h:56
HcalDbProducer::TokensForServiceHolder
Definition: HcalDbProducer.cc:117
HcalPedestalWidthsRcd
Definition: HcalPedestalWidthsRcd.h:8
HcalDbRecord.h
HcalTPParametersRcd
Definition: HcalTPParametersRcd.h:4
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HcalDbProducer::setupProduceAllImpl
void setupProduceAllImpl(const char *label, const edm::ESInputTag &tag, std::index_sequence< IND2s... >)
Definition: HcalDbProducer.cc:191
HcalDbProducer::kWithTopoEff
constexpr static const char kWithTopoEff[]
Definition: HcalDbProducer.cc:205
HcalDbProducer::ServiceToken
Definition: HcalDbProducer.cc:110
HcalDbProducer::produce
std::shared_ptr< HcalDbService > produce(const HcalDbRecord &)
Definition: HcalDbProducer.cc:288
edm::ParameterSet
Definition: ParameterSet.h:47
HcalPFCorrsRcd
Definition: HcalPFCorrsRcd.h:25
HcalDbProducer::TokenAndTopologyHolder::TokenAndTopologyHolder
TokenAndTopologyHolder()=default
gainCalibHelper::gainCalibPI::type
type
Definition: SiPixelGainCalibHelper.h:39
HcalDbProducer::ServiceTokenImpl::setConsumes
void setConsumes(edm::ESConsumesCollector &cc)
Definition: HcalDbProducer.cc:90
HcalDbProducer::setupProduce
void setupProduce(const char *label, const edm::ESInputTag &tag)
Definition: HcalDbProducer.cc:177
HcalFrontEndMapRcd
Definition: HcalFrontEndMapRcd.h:7
HcalAllRcds.h
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
HcalZSThresholdsRcd
Definition: HcalZSThresholdsRcd.h:25
HcalRespCorrsRcd
Definition: HcalRespCorrsRcd.h:27
HcalDbProducer::ServiceTokenImpl::ServiceTokenImpl
ServiceTokenImpl()
Definition: HcalDbProducer.cc:83
cc
edm::ESGetToken< ProductType, RecordType >
HcalDbProducer::mDumpRequest
std::vector< std::string > mDumpRequest
Definition: HcalDbProducer.cc:262
HcalDbProducer::TokenAndTopologyHolder::token_
edm::ESGetToken< ProductT, RecordT > token_
Definition: HcalDbProducer.cc:160
HcalDbProducer::kWithTopo
constexpr static const char kWithTopo[]
Definition: HcalDbProducer.cc:206
HcalDbASCIIIO::dumpObject
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
ModuleFactory.h
edm::ESProductHost
Definition: ESProductHost.h:93
DependentRecordImplementation.h
HcalDbService
Definition: HcalDbService.h:26
HcalDbProducer::ServiceTokenImpl::dumpName_
std::string dumpName_
Definition: HcalDbProducer.cc:106
HcalDbASCIIIO.h
HcalDbProducer::HostType
edm::ESProductHost< HcalDbService, HcalPedestalsRcd, HcalPedestalWidthsRcd, HcalGainsRcd, HcalGainWidthsRcd, HcalQIEDataRcd, HcalQIETypesRcd, HcalChannelQualityRcd, HcalZSThresholdsRcd, HcalRespCorrsRcd, HcalL1TriggerObjectsRcd, HcalTimeCorrsRcd, HcalLUTCorrsRcd, HcalPFCorrsRcd, HcalLutMetadataRcd, HcalSiPMParametersRcd, HcalTPChannelParametersRcd, HcalMCParamsRcd, HcalRecoParamsRcd, HcalElectronicsMapRcd, HcalFrontEndMapRcd, HcalSiPMCharacteristicsRcd, HcalTPParametersRcd > HostType
Definition: HcalDbProducer.cc:69
DEFINE_FWK_EVENTSETUP_MODULE
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
HcalDbProducer::holder_
edm::ReusableObjectHolder< HostType > holder_
Definition: HcalDbProducer.cc:202
HcalQIEDataRcd
Definition: HcalQIEDataRcd.h:8
HcalDbProducer::TokenAndTopologyHolder
Definition: HcalDbProducer.cc:143
HcalDbProducer
Definition: HcalDbProducer.cc:39
Record
relativeConstraints.value
value
Definition: relativeConstraints.py:53
HcalPedestalsRcd
Definition: HcalPedestalsRcd.h:9
HcalRecoParamsRcd
Definition: HcalRecoParamsRcd.h:6
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
HcalDbService.h
edm::ESProducer
Definition: ESProducer.h:104
ESProductHost.h
HcalDbRecord
Definition: HcalDbRecord.h:30
HcalDbProducer::~HcalDbProducer
~HcalDbProducer() override
Definition: HcalDbProducer.cc:282
HcalTimeCorrsRcd
Definition: HcalTimeCorrsRcd.h:25
HcalDbProducer::ServiceToken::Effective
EffectiveType Effective
Definition: HcalDbProducer.cc:113
label
const char * label
Definition: PFTauDecayModeTools.cc:11
HcalDbProducer::tokenHolders_
std::tuple< std::tuple< TokenAndTopologyHolder< HcalPedestals, HcalPedestalsRcd >, TokenAndTopologyHolder< HcalPedestalWidths, HcalPedestalWidthsRcd >, TokenAndTopologyHolder< HcalGains, HcalGainsRcd >, TokenAndTopologyHolder< HcalGainWidths, HcalGainWidthsRcd >, TokenAndTopologyHolder< HcalQIEData, HcalQIEDataRcd >, TokenAndTopologyHolder< HcalQIETypes, HcalQIETypesRcd >, TokenAndTopologyHolder< HcalChannelQuality, HcalChannelQualityRcd >, TokenAndTopologyHolder< HcalZSThresholds, HcalZSThresholdsRcd >, TokenAndTopologyHolder< HcalRespCorrs, HcalRespCorrsRcd >, TokenAndTopologyHolder< HcalL1TriggerObjects, HcalL1TriggerObjectsRcd >, TokenAndTopologyHolder< HcalTimeCorrs, HcalTimeCorrsRcd >, TokenAndTopologyHolder< HcalLUTCorrs, HcalLUTCorrsRcd >, TokenAndTopologyHolder< HcalPFCorrs, HcalPFCorrsRcd >, TokenAndTopologyHolder< HcalLutMetadata, HcalLutMetadataRcd >, TokenAndTopologyHolder< HcalSiPMParameters, HcalSiPMParametersRcd >, TokenAndTopologyHolder< HcalTPChannelParameters, HcalTPChannelParametersRcd >, TokenAndTopologyHolder< HcalMCParams, HcalMCParamsRcd >, TokenAndTopologyHolder< HcalRecoParams, HcalRecoParamsRcd > >, std::tuple< TokenAndTopologyHolder< HcalPedestals, HcalPedestalsRcd >, TokenAndTopologyHolder< HcalPedestalWidths, HcalPedestalWidthsRcd > > > tokenHolders_
Definition: HcalDbProducer.cc:260
HcalDbProducer::ServiceToken::label
static constexpr const char * label
Definition: HcalDbProducer.cc:112
HcalDbProducer::kEmpty
constexpr static const char kEmpty[]
Definition: HcalDbProducer.cc:207