46 using namespace magneticfield;
49 namespace magneticfield {
66 static std::string_view closerNominalLabel(
float current);
80 DD4hep_VolumeBasedMagneticFieldESProducerFromDB::DD4hep_VolumeBasedMagneticFieldESProducerFromDB(
82 :
debug_(iConfig.getUntrackedParameter<bool>(
"debugBuilder")) {
87 const int current = iConfig.
getParameter<
int>(
"valueOverride");
96 edm::LogInfo(
"MagneticField") <<
"Current :" << iHandle->m_avg_current
97 <<
" (from RunInfo DB); using map configuration with label: " <<
label;
98 return iGet(
"",
label);
106 <<
" (from valueOverride card); using map configuration with label: " <<
label;
122 if (iConfig->version ==
"parametrizedMagneticField") {
123 return iGet.nothing();
128 chosenConfigToken_ = cc.consumes(myConfigTag);
131 std::shared_ptr<MagFieldConfig const> DD4hep_VolumeBasedMagneticFieldESProducerFromDB::chooseConfigAtRuntime(
136 return std::shared_ptr<MagFieldConfig const>(config.
product(), [](
auto*) {});
144 return std::shared_ptr<MagFieldConfig const>(
config.product(), [](
auto*) {});
152 std::unique_ptr<MagneticField> paramField =
155 edm::LogInfo(
"MagneticField") <<
"(DD4hep) Version: " << conf->version
156 <<
" geometryVersion: " << conf->geometryVersion
157 <<
" slaveFieldVersion: " << conf->slaveFieldVersion;
159 if (conf->version ==
"parametrizedMagneticField") {
168 if (!conf->keys.empty()) {
173 if (!conf->gridFiles.empty()) {
180 std::unique_ptr<std::vector<unsigned char> > tb = blob->getUncompressedBlob();
182 string sblob(tb->begin(), tb->end());
184 sblob.rfind(
"</DDDefinition>"),
185 "<MaterialSection label=\"materials.xml\"><ElementaryMaterial name=\"materials:Vacuum\" density=\"1e-13*mg/cm3\" "
186 "symbol=\" \" atomicWeight=\"1*g/mole\" atomicNumber=\"1\"/></MaterialSection>");
188 auto ddet = make_unique<cms::DDDetector>(
"cmsMagneticField:MAGF", sblob,
true);
190 builder.
build(ddet.get());
193 return std::make_unique<VolumeBasedMagneticField>(conf->geometryVersion,
200 paramField.release(),
205 constexpr std::array<int, 7>
nominalCurrents = {{-1, 0, 9558, 14416, 16819, 18268, 19262}};
206 constexpr std::array<std::string_view, 7> nominalLabels = {{
"3.8T",
"0T",
"2T",
"3T",
"3.5T",
"3.8T",
"4T"}};
209 for (; i < (int)nominalLabels.size() - 1; i++) {
210 if (2 * current < nominalCurrents[i] + nominalCurrents[i + 1])
211 return nominalLabels[
i];
213 return nominalLabels[
i];
219 desc.
add<
int>(
"valueOverride", -1)->setComment(
"Force value of current (in A); take the value from DB if < 0.");
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
edm::ESGetToken< MagFieldConfig, IdealMagneticFieldRecord > chosenConfigToken_
T getUntrackedParameter(std::string const &, T const &) const
static const std::string kDD4hep
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< MagVolume6Faces * > endcapVolumes() const
edm::ESGetToken< MagFieldConfig, MagFieldConfigRcd > mayGetConfigToken_
std::unique_ptr< MagneticField > produce(const IdealMagneticFieldRecord &iRecord)
ESHandle< ProductT > getHandle(ESGetToken< ProductT, DepRecordT > const &iToken) const
std::string to_string(const V &value)
ESTransientHandle< ProductT > getTransientHandle(ESGetToken< ProductT, DepRecordT > const &iToken) const
edm::ESGetToken< FileBlob, MFGeometryFileRcd > mayConsumeBlobToken_
std::shared_ptr< MagFieldConfig const > chooseConfigAtRuntime(const IdealMagneticFieldRecord &iRecord)
edm::ESGetToken< MagFieldConfig, MagFieldConfigRcd > knownFromParamConfigToken_
void usesResources(std::vector< std::string > const &)
static std::unique_ptr< MagneticField > get(std::string version, const edm::ParameterSet ¶meters)
void addDefault(ParameterSetDescription const &psetDescription)
static std::string_view closerNominalLabel(float current)
std::shared_ptr< MagFieldConfig const > chooseConfigViaParameter(const IdealMagneticFieldRecord &iRecord)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Log< level::Info, false > LogInfo
void setGridFiles(const TableFileMap &gridFiles)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< MagBLayer * > barrelLayers() const
Get barrel layers.
std::vector< MagESector * > endcapSectors() const
Get endcap layers.
T const * product() const
T getParameter(std::string const &) const
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
std::vector< MagVolume6Faces * > barrelVolumes() const
tuple config
parse the configuration file
void build(const cms::DDDetector *det)
void setScaling(const std::vector< int > &keys, const std::vector< double > &values)
constexpr std::array< int, 7 > nominalCurrents