CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Static Private Member Functions | Private Attributes
magneticfield::DD4hep_VolumeBasedMagneticFieldESProducerFromDB Class Reference
Inheritance diagram for magneticfield::DD4hep_VolumeBasedMagneticFieldESProducerFromDB:
edm::ESProducer edm::ESProxyFactoryProducer edm::eventsetup::DataProxyProvider

Public Member Functions

std::shared_ptr< MagFieldConfig const > chooseConfigAtRuntime (const IdealMagneticFieldRecord &iRecord)
 
std::shared_ptr< MagFieldConfig const > chooseConfigViaParameter (const IdealMagneticFieldRecord &iRecord)
 
 DD4hep_VolumeBasedMagneticFieldESProducerFromDB (const DD4hep_VolumeBasedMagneticFieldESProducerFromDB &)=delete
 
 DD4hep_VolumeBasedMagneticFieldESProducerFromDB (const edm::ParameterSet &iConfig)
 
const DD4hep_VolumeBasedMagneticFieldESProducerFromDBoperator= (const DD4hep_VolumeBasedMagneticFieldESProducerFromDB &)=delete
 
std::unique_ptr< MagneticFieldproduce (const IdealMagneticFieldRecord &iRecord)
 
- Public Member Functions inherited from edm::ESProducer
 ESProducer ()
 
 ESProducer (const ESProducer &)=delete
 
ESProxyIndex const * getTokenIndices (unsigned int iIndex) const
 
ESProducer const & operator= (const ESProducer &)=delete
 
template<typename Record >
void updateFromMayConsumes (unsigned int iIndex, const Record &iRecord)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &) final
 
 ~ESProducer () noexcept(false) override
 
- Public Member Functions inherited from edm::ESProxyFactoryProducer
 ESProxyFactoryProducer ()
 
 ESProxyFactoryProducer (const ESProxyFactoryProducer &)=delete
 
const ESProxyFactoryProduceroperator= (const ESProxyFactoryProducer &)=delete
 
 ~ESProxyFactoryProducer () noexcept(false) override
 
- Public Member Functions inherited from edm::eventsetup::DataProxyProvider
void createKeyedProxies (EventSetupRecordKey const &key, unsigned int nConcurrentIOVs)
 
 DataProxyProvider ()
 
 DataProxyProvider (const DataProxyProvider &)=delete
 
const ComponentDescriptiondescription () const
 
void fillRecordsNotAllowingConcurrentIOVs (std::set< EventSetupRecordKey > &recordsNotAllowingConcurrentIOVs) const
 
virtual void initConcurrentIOVs (EventSetupRecordKey const &key, unsigned int nConcurrentIOVs)
 
bool isUsingRecord (const EventSetupRecordKey &key) const
 
KeyedProxieskeyedProxies (const EventSetupRecordKey &iRecordKey, unsigned int iovIndex=0)
 
const DataProxyProvideroperator= (const DataProxyProvider &)=delete
 
void setAppendToDataLabel (const edm::ParameterSet &)
 
void setDescription (const ComponentDescription &iDescription)
 
std::set< EventSetupRecordKeyusingRecords () const
 
virtual ~DataProxyProvider () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::eventsetup::DataProxyProvider
static void prevalidate (ConfigurationDescriptions &)
 

Static Private Member Functions

static std::string_view closerNominalLabel (float current)
 

Private Attributes

edm::ESGetToken< MagFieldConfig, IdealMagneticFieldRecordchosenConfigToken_
 
const bool debug_
 
edm::ESGetToken< MagFieldConfig, MagFieldConfigRcdknownFromParamConfigToken_
 
edm::ESGetToken< FileBlob, MFGeometryFileRcdmayConsumeBlobToken_
 
edm::ESGetToken< MagFieldConfig, MagFieldConfigRcdmayGetConfigToken_
 

Additional Inherited Members

- Protected Types inherited from edm::ESProxyFactoryProducer
using EventSetupRecordKey = eventsetup::EventSetupRecordKey
 
- Protected Types inherited from edm::eventsetup::DataProxyProvider
using KeyedProxiesVector = std::vector< std::pair< DataKey, std::shared_ptr< DataProxy > >>
 
- Protected Member Functions inherited from edm::ESProducer
template<typename T >
auto setWhatProduced (T *iThis, const char *iLabel)
 
template<typename T >
auto setWhatProduced (T *iThis, const es::Label &iLabel={})
 
template<typename T >
auto setWhatProduced (T *iThis, const std::string &iLabel)
 
template<typename T , typename TDecorator >
auto setWhatProduced (T *iThis, const TDecorator &iDec, const es::Label &iLabel={})
 
template<typename T , typename TReturn , typename TRecord >
auto setWhatProduced (T *iThis, TReturn(T ::*iMethod)(const TRecord &), const es::Label &iLabel={})
 
template<typename T , typename TReturn , typename TRecord , typename TArg >
ESConsumesCollectorT< TRecord > setWhatProduced (T *iThis, TReturn(T ::*iMethod)(const TRecord &), const TArg &iDec, const es::Label &iLabel={})
 
- Protected Member Functions inherited from edm::ESProxyFactoryProducer
template<class TFactory >
void registerFactory (std::unique_ptr< TFactory > iFactory, const std::string &iLabel=std::string())
 
virtual void registerFactoryWithKey (const EventSetupRecordKey &iRecord, std::unique_ptr< eventsetup::ProxyFactoryBase > iFactory, const std::string &iLabel=std::string())
 
KeyedProxiesVector registerProxies (const EventSetupRecordKey &, unsigned int iovIndex) override
 
- Protected Member Functions inherited from edm::eventsetup::DataProxyProvider
template<class T >
void usingRecord ()
 
void usingRecordWithKey (const EventSetupRecordKey &key)
 

Detailed Description

Definition at line 49 of file DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc.

Constructor & Destructor Documentation

◆ DD4hep_VolumeBasedMagneticFieldESProducerFromDB() [1/2]

DD4hep_VolumeBasedMagneticFieldESProducerFromDB::DD4hep_VolumeBasedMagneticFieldESProducerFromDB ( const edm::ParameterSet iConfig)

Definition at line 79 of file DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc.

81  : debug_(iConfig.getUntrackedParameter<bool>("debugBuilder")) {
82  std::string const myConfigLabel = "VBMFESChoice";
83 
84  //Based on configuration, pick algorithm to produce the proper MagFieldConfig with a specific label
85  const int current = iConfig.getParameter<int>("valueOverride");
86  if (current < 0) {
87  //We do not know what to get until we first read RunInfo
90  .setMayConsume(
92  [](auto const& iGet, edm::ESTransientHandle<RunInfo> iHandle) {
93  auto const label = closerNominalLabel(iHandle->m_avg_current);
94  edm::LogInfo("MagneticField") << "Current :" << iHandle->m_avg_current
95  << " (from RunInfo DB); using map configuration with label: " << label;
96  return iGet("", label);
97  },
99 
100  } else {
101  //we know exactly what we are going to get
102  auto const label = closerNominalLabel(current);
103  edm::LogInfo("MagneticField") << "Current :" << current
104  << " (from valueOverride card); using map configuration with label: " << label;
108  }
109 
110  auto const label = iConfig.getUntrackedParameter<std::string>("label");
111  auto const myConfigTag = edm::ESInputTag(iConfig.getParameter<std::string>("@module_label"), myConfigLabel);
112 
113  //We use the MagFieldConfig created above to decide which FileBlob to use
114  setWhatProduced(this, label)
115  .setMayConsume(
117  [](auto const& iGet, edm::ESTransientHandle<MagFieldConfig> iConfig) {
118  if (iConfig->version == "parametrizedMagneticField") {
119  return iGet.nothing();
120  }
121  return iGet("", std::to_string(iConfig->geometryVersion));
122  },
124  .setConsumes(chosenConfigToken_, myConfigTag); //Use same tag as the choice
125 }

References chooseConfigAtRuntime(), chooseConfigViaParameter(), chosenConfigToken_, closerNominalLabel(), MagFieldConfig::geometryVersion, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), knownFromParamConfigToken_, label, RunInfo::m_avg_current, mayConsumeBlobToken_, mayGetConfigToken_, alignCSCRings::s, edm::ESProducer::setWhatProduced(), AlCaHLTBitMon_QueryRunRegistry::string, and MagFieldConfig::version.

◆ DD4hep_VolumeBasedMagneticFieldESProducerFromDB() [2/2]

magneticfield::DD4hep_VolumeBasedMagneticFieldESProducerFromDB::DD4hep_VolumeBasedMagneticFieldESProducerFromDB ( const DD4hep_VolumeBasedMagneticFieldESProducerFromDB )
delete

Member Function Documentation

◆ chooseConfigAtRuntime()

std::shared_ptr< MagFieldConfig const > DD4hep_VolumeBasedMagneticFieldESProducerFromDB::chooseConfigAtRuntime ( const IdealMagneticFieldRecord iRecord)

Definition at line 127 of file DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc.

128  {
130 
131  //just forward what we just got but do not take ownership
132  return std::shared_ptr<MagFieldConfig const>(config.product(), [](auto*) {});
133 }

References edm::eventsetup::DependentRecordImplementation< RecordT, ListT >::getHandle(), and mayGetConfigToken_.

Referenced by DD4hep_VolumeBasedMagneticFieldESProducerFromDB().

◆ chooseConfigViaParameter()

std::shared_ptr< MagFieldConfig const > DD4hep_VolumeBasedMagneticFieldESProducerFromDB::chooseConfigViaParameter ( const IdealMagneticFieldRecord iRecord)

Definition at line 135 of file DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc.

136  {
138 
139  //just forward what we just got but do not take ownership
140  return std::shared_ptr<MagFieldConfig const>(config.product(), [](auto*) {});
141 }

References edm::eventsetup::DependentRecordImplementation< RecordT, ListT >::getHandle(), and knownFromParamConfigToken_.

Referenced by DD4hep_VolumeBasedMagneticFieldESProducerFromDB().

◆ closerNominalLabel()

std::string_view DD4hep_VolumeBasedMagneticFieldESProducerFromDB::closerNominalLabel ( float  current)
staticprivate

Definition at line 199 of file DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc.

199  {
200  constexpr std::array<int, 7> nominalCurrents = {{-1, 0, 9558, 14416, 16819, 18268, 19262}};
201  constexpr std::array<std::string_view, 7> nominalLabels = {{"3.8T", "0T", "2T", "3T", "3.5T", "3.8T", "4T"}};
202 
203  int i = 0;
204  for (; i < (int)nominalLabels.size() - 1; i++) {
205  if (2 * current < nominalCurrents[i] + nominalCurrents[i + 1])
206  return nominalLabels[i];
207  }
208  return nominalLabels[i];
209 }

References mps_fire::i, createfilelist::int, and RunInfoPI::nominalCurrents.

Referenced by DD4hep_VolumeBasedMagneticFieldESProducerFromDB().

◆ fillDescriptions()

void DD4hep_VolumeBasedMagneticFieldESProducerFromDB::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 211 of file DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc.

211  {
213  desc.addUntracked<bool>("debugBuilder", false);
214  desc.add<int>("valueOverride", -1)->setComment("Force value of current (in A); take the value from DB if < 0.");
215  desc.addUntracked<std::string>("label", "");
216 
217  descriptions.addDefault(desc);
218 }

References edm::ParameterSetDescription::add(), edm::ConfigurationDescriptions::addDefault(), edm::ParameterSetDescription::addUntracked(), and AlCaHLTBitMon_QueryRunRegistry::string.

◆ operator=()

const DD4hep_VolumeBasedMagneticFieldESProducerFromDB& magneticfield::DD4hep_VolumeBasedMagneticFieldESProducerFromDB::operator= ( const DD4hep_VolumeBasedMagneticFieldESProducerFromDB )
delete

◆ produce()

std::unique_ptr< MagneticField > DD4hep_VolumeBasedMagneticFieldESProducerFromDB::produce ( const IdealMagneticFieldRecord iRecord)

Definition at line 144 of file DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc.

145  {
146  auto const& conf = iRecord.getTransientHandle(chosenConfigToken_);
147 
148  std::unique_ptr<MagneticField> paramField =
149  ParametrizedMagneticFieldFactory::get(conf->slaveFieldVersion, conf->slaveFieldParameters);
150 
151  edm::LogInfo("MagneticField") << "Version: " << conf->version << " geometryVersion: " << conf->geometryVersion
152  << " slaveFieldVersion: " << conf->slaveFieldVersion;
153 
154  if (conf->version == "parametrizedMagneticField") {
155  // The map consist of only the parametrization in this case
156  return paramField;
157  }
158 
159  // Full VolumeBased map + parametrization
160  MagGeoBuilder builder(conf->version, conf->geometryVersion, debug_);
161 
162  // Set scaling factors
163  if (!conf->keys.empty()) {
164  builder.setScaling(conf->keys, conf->values);
165  }
166 
167  // Set specification for the grid tables to be used.
168  if (!conf->gridFiles.empty()) {
169  builder.setGridFiles(conf->gridFiles);
170  }
171 
172  // Build the geometry from the DB blob
173 
174  auto const& blob = iRecord.getTransientHandle(mayConsumeBlobToken_);
175  std::unique_ptr<std::vector<unsigned char> > tb = blob->getUncompressedBlob();
176 
177  string sblob(tb->begin(), tb->end());
178  sblob.insert(
179  sblob.rfind("</DDDefinition>"),
180  "<MaterialSection label=\"materials.xml\"><ElementaryMaterial name=\"materials:Vacuum\" density=\"1e-13*mg/cm3\" "
181  "symbol=\" \" atomicWeight=\"1*g/mole\" atomicNumber=\"1\"/></MaterialSection>");
182 
183  auto ddet = make_unique<cms::DDDetector>("", sblob, true);
184 
185  builder.build(ddet.get());
186 
187  // Build the VB map. Ownership of the parametrization is transferred to it
188  return std::make_unique<VolumeBasedMagneticField>(conf->geometryVersion,
189  builder.barrelLayers(),
190  builder.endcapSectors(),
191  builder.barrelVolumes(),
192  builder.endcapVolumes(),
193  builder.maxR(),
194  builder.maxZ(),
195  paramField.release(),
196  true);
197 }

References magneticfield::MagGeoBuilder::barrelLayers(), magneticfield::MagGeoBuilder::barrelVolumes(), magneticfield::MagGeoBuilder::build(), chosenConfigToken_, debug_, magneticfield::MagGeoBuilder::endcapSectors(), magneticfield::MagGeoBuilder::endcapVolumes(), ParametrizedMagneticFieldFactory::get(), edm::eventsetup::DependentRecordImplementation< RecordT, ListT >::getTransientHandle(), magneticfield::MagGeoBuilder::maxR(), magneticfield::MagGeoBuilder::maxZ(), mayConsumeBlobToken_, magneticfield::MagGeoBuilder::setGridFiles(), and magneticfield::MagGeoBuilder::setScaling().

Member Data Documentation

◆ chosenConfigToken_

edm::ESGetToken<MagFieldConfig, IdealMagneticFieldRecord> magneticfield::DD4hep_VolumeBasedMagneticFieldESProducerFromDB::chosenConfigToken_
private

◆ debug_

const bool magneticfield::DD4hep_VolumeBasedMagneticFieldESProducerFromDB::debug_
private

Definition at line 75 of file DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc.

Referenced by produce().

◆ knownFromParamConfigToken_

edm::ESGetToken<MagFieldConfig, MagFieldConfigRcd> magneticfield::DD4hep_VolumeBasedMagneticFieldESProducerFromDB::knownFromParamConfigToken_
private

◆ mayConsumeBlobToken_

edm::ESGetToken<FileBlob, MFGeometryFileRcd> magneticfield::DD4hep_VolumeBasedMagneticFieldESProducerFromDB::mayConsumeBlobToken_
private

◆ mayGetConfigToken_

edm::ESGetToken<MagFieldConfig, MagFieldConfigRcd> magneticfield::DD4hep_VolumeBasedMagneticFieldESProducerFromDB::mayGetConfigToken_
private
mps_fire.i
i
Definition: mps_fire.py:355
edm::ESProductTag
Definition: ESProductTag.h:29
edm::ESInputTag
Definition: ESInputTag.h:87
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
RunInfoPI::nominalCurrents
constexpr std::array< int, 7 > nominalCurrents
Definition: RunInfoPayloadInspectoHelper.h:16
ParametrizedMagneticFieldFactory::get
static std::unique_ptr< MagneticField > get(std::string version, const edm::ParameterSet &parameters)
magneticfield::DD4hep_VolumeBasedMagneticFieldESProducerFromDB::chosenConfigToken_
edm::ESGetToken< MagFieldConfig, IdealMagneticFieldRecord > chosenConfigToken_
Definition: DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc:72
edm::eventsetup::DependentRecordImplementation::getHandle
ESHandle< ProductT > getHandle(ESGetToken< ProductT, DepRecordT > const &iToken) const
Definition: DependentRecordImplementation.h:86
edm::LogInfo
Definition: MessageLogger.h:254
edm::ESProducer::setWhatProduced
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:138
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
MagFieldConfig::version
std::string version
Version of the data tables to be used.
Definition: MagFieldConfig.h:41
magneticfield::MagGeoBuilder
Definition: DD4hep_MagGeoBuilder.h:35
MagFieldConfig::geometryVersion
int geometryVersion
Version of the geometry to be used.
Definition: MagFieldConfig.h:38
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
magneticfield::DD4hep_VolumeBasedMagneticFieldESProducerFromDB::chooseConfigAtRuntime
std::shared_ptr< MagFieldConfig const > chooseConfigAtRuntime(const IdealMagneticFieldRecord &iRecord)
Definition: DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc:127
magneticfield::DD4hep_VolumeBasedMagneticFieldESProducerFromDB::closerNominalLabel
static std::string_view closerNominalLabel(float current)
Definition: DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc:199
config
Definition: config.py:1
alignCSCRings.s
s
Definition: alignCSCRings.py:92
edm::eventsetup::DependentRecordImplementation::getTransientHandle
ESTransientHandle< ProductT > getTransientHandle(ESGetToken< ProductT, DepRecordT > const &iToken) const
Definition: DependentRecordImplementation.h:99
edm::ESHandle
Definition: DTSurvey.h:22
edm::es::Label
Definition: es_Label.h:54
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSetDescription::addUntracked
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:100
magneticfield::DD4hep_VolumeBasedMagneticFieldESProducerFromDB::debug_
const bool debug_
Definition: DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc:75
createfilelist.int
int
Definition: createfilelist.py:10
magneticfield::DD4hep_VolumeBasedMagneticFieldESProducerFromDB::chooseConfigViaParameter
std::shared_ptr< MagFieldConfig const > chooseConfigViaParameter(const IdealMagneticFieldRecord &iRecord)
Definition: DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc:135
magneticfield::DD4hep_VolumeBasedMagneticFieldESProducerFromDB::mayGetConfigToken_
edm::ESGetToken< MagFieldConfig, MagFieldConfigRcd > mayGetConfigToken_
Definition: DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc:67
edm::ESTransientHandle
Definition: ESTransientHandle.h:41
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
magneticfield::DD4hep_VolumeBasedMagneticFieldESProducerFromDB::mayConsumeBlobToken_
edm::ESGetToken< FileBlob, MFGeometryFileRcd > mayConsumeBlobToken_
Definition: DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc:74
RunInfo::m_avg_current
float m_avg_current
Definition: RunInfo.h:28
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
label
const char * label
Definition: PFTauDecayModeTools.cc:11
magneticfield::DD4hep_VolumeBasedMagneticFieldESProducerFromDB::knownFromParamConfigToken_
edm::ESGetToken< MagFieldConfig, MagFieldConfigRcd > knownFromParamConfigToken_
Definition: DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc:68