CMS 3D CMS Logo

DDDetectorESProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: DetectorDescription/DDDetectorESProducer
4 // Class: DDDetectorESProducer
5 //
13 //
14 // Original Author: Ianna Osborne
15 // Created: Fri, 07 Dec 2018 11:20:52 GMT
16 //
17 //
18 
19 #include <memory>
20 
29 
34 #include "DD4hep/Detector.h"
35 
36 using namespace std;
37 using namespace cms;
38 using namespace edm;
39 
41 public:
43  ~DDDetectorESProducer() override;
44 
45  using ReturnType = unique_ptr<DDDetector>;
47 
48  ReturnType produceGeom(const IdealGeometryRecord&);
49  ReturnType produceMagField(const IdealMagneticFieldRecord&);
50  ReturnType produce();
52 
53 protected:
54  void setIntervalFor(const eventsetup::EventSetupRecordKey&, const IOVSyncValue&, ValidityInterval&) override;
55 
56 private:
57  const bool fromDB_;
58  const string appendToDataLabel_;
59  const string confGeomXMLFiles_;
60  const string rootDDName_;
61  const string label_;
64 };
65 
67  : fromDB_(iConfig.getParameter<bool>("fromDB")),
68  appendToDataLabel_(iConfig.getParameter<string>("appendToDataLabel")),
69  confGeomXMLFiles_(fromDB_ ? "none" : iConfig.getParameter<FileInPath>("confGeomXMLFiles").fullPath()),
70  rootDDName_(iConfig.getParameter<string>("rootDDName")),
71  label_(iConfig.getParameter<string>("label")) {
73  edm::LogVerbatim("Geometry") << "DDDetectorESProducer::fromDB " << fromDB_ << " appendToDataLabel "
74  << appendToDataLabel_ << " rootDDName " << rootDDName_ << " label " << label_
75  << " confGeomXMLFiles " << confGeomXMLFiles_;
76  if (rootDDName_ == "MagneticFieldVolumes:MAGF" || rootDDName_ == "cmsMagneticField:MAGF") {
77  auto c = setWhatProduced(this,
79  edm::es::Label(iConfig.getParameter<std::string>("@module_label")));
80  if (fromDB_) {
81  mfToken_ = c.consumes(edm::ESInputTag("", label_));
82  }
83  findingRecord<IdealMagneticFieldRecord>();
84  } else {
86  if (fromDB_) {
87  geomToken_ = c.consumes(edm::ESInputTag("", label_));
88  }
89  findingRecord<IdealGeometryRecord>();
90  }
91 }
92 
94 
97 
98  desc.addOptional<FileInPath>("confGeomXMLFiles");
99  desc.add<string>("rootDDName", "cms:OCMS");
100  desc.add<string>("label", "");
101  desc.add<bool>("fromDB", false);
102  descriptions.add("DDDetectorESProducer", desc);
103 
105  descDB.add<string>("rootDDName", "cms:OCMS");
106  descDB.add<string>("label", "Extended");
107  descDB.add<bool>("fromDB", true);
108  descriptions.add("DDDetectorESProducerFromDB", descDB);
109 }
110 
112  const IOVSyncValue& iTime,
113  ValidityInterval& oInterval) {
114  oInterval = ValidityInterval(IOVSyncValue::beginOfTime(), IOVSyncValue::endOfTime()); //infinite
115 }
116 
118  LogVerbatim("Geometry") << "DDDetectorESProducer::Produce MF " << appendToDataLabel_;
119  if (fromDB_) {
121  unique_ptr<vector<unsigned char> > tb = (*gdd).getUncompressedBlob();
122 
123  return make_unique<cms::DDDetector>(label_, string(tb->begin(), tb->end()), true);
124  } else {
125  return make_unique<DDDetector>(appendToDataLabel_, confGeomXMLFiles_);
126  }
127 }
128 
130  LogVerbatim("Geometry") << "DDDetectorESProducer::Produce " << appendToDataLabel_;
131  if (fromDB_) {
133  unique_ptr<vector<unsigned char> > tb = (*gdd).getUncompressedBlob();
134 
135  return make_unique<cms::DDDetector>(label_, string(tb->begin(), tb->end()), true);
136  } else {
137  return make_unique<DDDetector>(appendToDataLabel_, confGeomXMLFiles_, false);
138  }
139 }
140 
142  LogVerbatim("Geometry") << "DDDetectorESProducer::Produce " << appendToDataLabel_;
143  return make_unique<DDDetector>(appendToDataLabel_, confGeomXMLFiles_, false);
144 }
145 
ESTransientHandle< ProductT > getTransientHandle(ESGetToken< ProductT, DepRecordT > const &iToken) const
edm::ESGetToken< FileBlob, GeometryFileRcd > geomToken_
Log< level::Info, true > LogVerbatim
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
static const std::string kDD4hep
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:17
unique_ptr< DDDetector > ReturnType
edm::ESGetToken< FileBlob, MFGeometryFileRcd > mfToken_
void usesResources(std::vector< std::string > const &)
Definition: ESProducer.cc:117
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void setIntervalFor(const eventsetup::EventSetupRecordKey &, const IOVSyncValue &, ValidityInterval &) override
Namespace of DDCMS conversion namespace.
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:91
ReturnType produceMagField(const IdealMagneticFieldRecord &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(ConfigurationDescriptions &)
DDDetectorESProducer(const ParameterSet &)
HLT enums.
ReturnType produceGeom(const IdealGeometryRecord &)