CMS 3D CMS Logo

VolumeBasedMagneticFieldESProducer.cc
Go to the documentation of this file.
1 
12 
16 
20 
21 #include <string>
22 #include <vector>
23 #include <iostream>
24 
25 namespace magneticfield {
27  public:
29 
30  std::unique_ptr<MagneticField> produce(const IdealMagneticFieldRecord& iRecord);
31 
32  // forbid copy ctor and assignment op.
35 
36  private:
37  const bool debug_;
43  };
44 } // namespace magneticfield
45 
46 using namespace std;
47 using namespace magneticfield;
48 
50  : debug_{iConfig.getUntrackedParameter<bool>("debugBuilder", false)},
51  useParametrizedTrackerField_{iConfig.getParameter<bool>("useParametrizedTrackerField")},
52  conf_{iConfig, debug_},
53  version_{iConfig.getParameter<std::string>("version")} {
54  auto cc = setWhatProduced(this, iConfig.getUntrackedParameter<std::string>("label", ""));
55  cpvToken_ = cc.consumes(edm::ESInputTag{"", "magfield"});
56  if (useParametrizedTrackerField_) {
57  paramFieldToken_ = cc.consumes(edm::ESInputTag{"", iConfig.getParameter<string>("paramLabel")});
58  }
59 }
60 
61 // ------------ method called to produce the data ------------
62 std::unique_ptr<MagneticField> VolumeBasedMagneticFieldESProducer::produce(const IdealMagneticFieldRecord& iRecord) {
63  LogTrace("MagGeoBuilder") << "VolumeBasedMagneticFieldESProducer::produce() " << version_;
64 
65  auto cpv = iRecord.getTransientHandle(cpvToken_);
67 
68  // Set scaling factors
69  if (!conf_.keys.empty()) {
70  builder.setScaling(conf_.keys, conf_.values);
71  }
72 
73  // Set specification for the grid tables to be used.
74  if (!conf_.gridFiles.empty()) {
75  builder.setGridFiles(conf_.gridFiles);
76  }
77 
78  builder.build(*cpv);
79 
80  // Get slave field (from ES)
81  const MagneticField* paramField = nullptr;
83  paramField = &iRecord.get(paramFieldToken_);
84  }
85  return std::make_unique<VolumeBasedMagneticField>(conf_.geometryVersion,
86  builder.barrelLayers(),
87  builder.endcapSectors(),
88  builder.barrelVolumes(),
89  builder.endcapVolumes(),
90  builder.maxR(),
91  builder.maxZ(),
92  paramField,
93  false);
94 }
95 
ESTransientHandle< ProductT > getTransientHandle(ESGetToken< ProductT, DepRecordT > const &iToken) const
std::vector< MagVolume6Faces * > barrelVolumes() const
std::vector< MagESector * > endcapSectors() const
Get endcap layers.
const VolumeBasedMagneticFieldESProducer & operator=(const VolumeBasedMagneticFieldESProducer &)=delete
std::unique_ptr< MagneticField > produce(const IdealMagneticFieldRecord &iRecord)
std::vector< MagBLayer * > barrelLayers() const
Get barrel layers.
std::vector< double > values
#define LogTrace(id)
edm::ESGetToken< DDCompactView, IdealMagneticFieldRecord > cpvToken_
magneticfield::TableFileMap gridFiles
Specification of which data table is to be used for each volume.
T getUntrackedParameter(std::string const &, T const &) const
virtual void build(const DDCompactView &cpv)
std::vector< int > keys
Scaling factors for the field in specific volumes.
std::vector< MagVolume6Faces * > endcapVolumes() const
std::string version
Version of the data tables to be used.
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
void setScaling(const std::vector< int > &keys, const std::vector< double > &values)
int geometryVersion
Version of the geometry to be used.
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > paramFieldToken_
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
void setGridFiles(const magneticfield::TableFileMap &gridFiles)