CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Attributes
cms::DDNamespace Class Reference

#include <DDNamespace.h>

Public Member Functions

void addConstant (const std::string &name, const std::string &value, const std::string &type) const
 
void addConstantNS (const std::string &name, const std::string &value, const std::string &type) const
 
void addRotation (const std::string &name, const dd4hep::Rotation3D &rot) const
 
dd4hep::Solid addSolid (const std::string &name, dd4hep::Solid solid) const
 
dd4hep::Solid addSolidNS (const std::string &name, dd4hep::Solid solid) const
 
dd4hep::Volume addVolume (dd4hep::Volume vol) const
 Add rotation matrix to current namespace. More...
 
dd4hep::Volume addVolumeNS (dd4hep::Volume vol) const
 
template<typename T >
T attr (xml_elt_t element, const xml_tag_t &name) const
 
template<typename T >
T attr (xml_elt_t element, const xml_tag_t &name, T defaultValue) const
 
DDParsingContext *const context () const
 
 DDNamespace ()=delete
 
 DDNamespace (const DDNamespace &)=delete
 
 DDNamespace (DDParsingContext &)
 
 DDNamespace (DDParsingContext &, xml_h, bool)
 
 DDNamespace (DDParsingContext *)
 
 DDNamespace (DDParsingContext *, xml_h)
 
dd4hep::Material material (const std::string &name) const
 
std::string_view name () const
 
DDNamespaceoperator= (const DDNamespace &)=delete
 
std::string prepend (const std::string &) const
 
std::string realName (const std::string &) const
 
const dd4hep::Rotation3D & rotation (const std::string &name) const
 
DDParsingContextsetContext ()
 
dd4hep::Solid solid (const std::string &name) const
 
std::vector< double > vecDbl (const std::string &name) const
 
dd4hep::Volume volume (const std::string &name, bool exc=true) const
 
 ~DDNamespace ()
 

Static Public Member Functions

static std::string nsName (const std::string &)
 
static std::string objName (const std::string &)
 

Private Attributes

DDParsingContextm_context = nullptr
 
std::string m_name
 
bool m_pop = false
 

Detailed Description

Definition at line 16 of file DDNamespace.h.

Constructor & Destructor Documentation

◆ DDNamespace() [1/6]

DDNamespace::DDNamespace ( DDParsingContext context,
xml_h  element 
)

Definition at line 14 of file DDNamespace.cc.

14  : m_context(context) {
15  dd4hep::Path path(xml_handler_t::system_path(element));
16  m_name = path.filename().substr(0, path.filename().rfind('.'));
17  if (!m_name.empty())
19  m_context->namespaces.emplace(m_name);
20  m_pop = true;
21  dd4hep::printout(m_context->debug_namespaces ? dd4hep::ALWAYS : dd4hep::DEBUG,
22  "DD4CMS",
23  "+++ Current namespace is now: %s",
24  m_name.c_str());
25  return;
26 }

References DEBUG, cms::DDParsingContext::debug_namespaces, m_context, m_name, m_pop, NAMESPACE_SEP, cms::DDParsingContext::namespaces, castor_dqm_sourceclient_file_cfg::path, and mps_fire::Path.

◆ DDNamespace() [2/6]

DDNamespace::DDNamespace ( DDParsingContext ctx,
xml_h  element,
bool   
)

Definition at line 28 of file DDNamespace.cc.

28  : m_context(&ctx) {
29  dd4hep::Path path(xml_handler_t::system_path(element));
30  m_name = path.filename().substr(0, path.filename().rfind('.'));
31  if (!m_name.empty())
33  m_context->namespaces.emplace(m_name);
34  m_pop = true;
35  dd4hep::printout(m_context->debug_namespaces ? dd4hep::ALWAYS : dd4hep::DEBUG,
36  "DD4CMS",
37  "+++ Current namespace is now: %s",
38  m_name.c_str());
39  return;
40 }

References DEBUG, cms::DDParsingContext::debug_namespaces, m_context, m_name, m_pop, NAMESPACE_SEP, cms::DDParsingContext::namespaces, castor_dqm_sourceclient_file_cfg::path, and mps_fire::Path.

◆ DDNamespace() [3/6]

DDNamespace::DDNamespace ( DDParsingContext ctx)

Definition at line 42 of file DDNamespace.cc.

42  : m_context(ctx) {
43  if (!m_context->ns(m_name))
44  m_name.clear();
45 }

References m_context, m_name, and cms::DDParsingContext::ns().

◆ DDNamespace() [4/6]

DDNamespace::DDNamespace ( DDParsingContext ctx)

Definition at line 47 of file DDNamespace.cc.

47  : m_context(&ctx) {
48  if (!m_context->ns(m_name))
49  m_name.clear();
50 }

References m_context, m_name, and cms::DDParsingContext::ns().

◆ ~DDNamespace()

DDNamespace::~DDNamespace ( )

Definition at line 52 of file DDNamespace.cc.

52  {
53  if (m_pop) {
54  string result("");
55  if (m_context->namespaces.try_pop(result))
56  m_name = result;
57  else
58  m_name.clear();
59  dd4hep::printout(m_context->debug_namespaces ? dd4hep::ALWAYS : dd4hep::DEBUG,
60  "DD4CMS",
61  "+++ Current namespace is now: %s",
62  m_name.c_str());
63  }
64 }

References DEBUG, cms::DDParsingContext::debug_namespaces, m_context, m_name, m_pop, cms::DDParsingContext::namespaces, and mps_fire::result.

◆ DDNamespace() [5/6]

cms::DDNamespace::DDNamespace ( )
delete

◆ DDNamespace() [6/6]

cms::DDNamespace::DDNamespace ( const DDNamespace )
delete

Member Function Documentation

◆ addConstant()

void DDNamespace::addConstant ( const std::string &  name,
const std::string &  value,
const std::string &  type 
) const

Definition at line 103 of file DDNamespace.cc.

103  {
104  addConstantNS(prepend(nam), val, typ);
105 }

References addConstantNS(), prepend(), and heppy_batch::val.

◆ addConstantNS()

void DDNamespace::addConstantNS ( const std::string &  name,
const std::string &  value,
const std::string &  type 
) const

Definition at line 107 of file DDNamespace.cc.

107  {
108  const string& v = val;
109  const string& n = nam;
110  dd4hep::printout(m_context->debug_constants ? dd4hep::ALWAYS : dd4hep::DEBUG,
111  "DD4CMS",
112  "+++ Add constant object: %-40s = %s [type:%s]",
113  n.c_str(),
114  v.c_str(),
115  typ.c_str());
116  dd4hep::_toDictionary(n, v, typ);
117  dd4hep::Constant c(n, v, typ);
118  m_context->description.load()->addConstant(c);
119 }

References HltBtagPostValidation_cff::c, DEBUG, cms::DDParsingContext::debug_constants, cms::DDParsingContext::description, m_context, dqmiodumpmetadata::n, findQualityFiles::v, and heppy_batch::val.

Referenced by addConstant(), and load_dddefinition().

◆ addRotation()

void DDNamespace::addRotation ( const std::string &  name,
const dd4hep::Rotation3D &  rot 
) const

Definition at line 125 of file DDNamespace.cc.

125  {
126  string n = prepend(name);
127  m_context->rotations[n] = rot;
128 }

References m_context, dqmiodumpmetadata::n, name(), prepend(), makeMuonMisalignmentScenario::rot, and cms::DDParsingContext::rotations.

◆ addSolid()

dd4hep::Solid DDNamespace::addSolid ( const std::string &  name,
dd4hep::Solid  solid 
) const

Definition at line 221 of file DDNamespace.cc.

221  {
222  return addSolidNS(prepend(name), sol);
223 }

References addSolidNS(), name(), and prepend().

Referenced by algorithm(), and convert_boolean().

◆ addSolidNS()

dd4hep::Solid DDNamespace::addSolidNS ( const std::string &  name,
dd4hep::Solid  solid 
) const

Definition at line 206 of file DDNamespace.cc.

206  {
207  dd4hep::printout(m_context->debug_shapes ? dd4hep::ALWAYS : dd4hep::DEBUG,
208  "DD4CMS",
209  "+++ Add shape of type %s : %s",
210  solid->IsA()->GetName(),
211  name.c_str());
212 
213  auto shape = m_context->shapes.emplace(name, solid.setName(name));
214  if (!shape.second) {
215  m_context->shapes[name] = solid.setName(name);
216  }
217 
218  return solid;
219 }

References DEBUG, cms::DDParsingContext::debug_shapes, m_context, name(), cms::DDParsingContext::shapes, and solid().

Referenced by addSolid(), algorithm(), DDHGCalGeom::constructLayers(), HGCalEEAlgo::ConstructLayers(), HGCalHEAlgo::HGCalHEAlgo(), and HGCalHEAlgo::positionMix().

◆ addVolume()

dd4hep::Volume DDNamespace::addVolume ( dd4hep::Volume  vol) const

Add rotation matrix to current namespace.

Definition at line 170 of file DDNamespace.cc.

170  {
171  string n = prepend(vol.name());
172  dd4hep::Solid s = vol.solid();
173  dd4hep::Material m = vol.material();
174  //vol->SetName(n.c_str());
175  m_context->volumes[n] = vol;
176  const char* solidName = "Invalid solid";
177  if (s.isValid()) // Protect against seg fault
178  solidName = s.name(); // If Solid is not valid, s.name() will seg fault.
179  dd4hep::printout(m_context->debug_volumes ? dd4hep::ALWAYS : dd4hep::DEBUG,
180  "DD4CMS",
181  "+++ Add volume:%-38s as [%s] Solid:%-26s[%-16s] Material:%s",
182  vol.name(),
183  n.c_str(),
184  solidName,
185  s.type(),
186  m.name());
187  return vol;
188 }

References DEBUG, cms::DDParsingContext::debug_volumes, visualization-live-secondInstance_cfg::m, m_context, g4SimHits_cfi::Material, dqmiodumpmetadata::n, prepend(), alignCSCRings::s, and cms::DDParsingContext::volumes.

Referenced by algorithm(), and load_dddefinition().

◆ addVolumeNS()

dd4hep::Volume DDNamespace::addVolumeNS ( dd4hep::Volume  vol) const

Definition at line 150 of file DDNamespace.cc.

150  {
151  string n = vol.name();
152  dd4hep::Solid s = vol.solid();
153  dd4hep::Material m = vol.material();
154  vol->SetName(n.c_str());
155  m_context->volumes[n] = vol;
156  const char* solidName = "Invalid solid";
157  if (s.isValid()) // Protect against seg fault
158  solidName = s.name(); // If Solid is not valid, s.name() will seg fault.
159  dd4hep::printout(m_context->debug_volumes ? dd4hep::ALWAYS : dd4hep::DEBUG,
160  "DD4CMS",
161  "+++ Add volumeNS:%-38s Solid:%-26s[%-16s] Material:%s",
162  vol.name(),
163  solidName,
164  s.type(),
165  m.name());
166  return vol;
167 }

References DEBUG, cms::DDParsingContext::debug_volumes, visualization-live-secondInstance_cfg::m, m_context, g4SimHits_cfi::Material, dqmiodumpmetadata::n, alignCSCRings::s, and cms::DDParsingContext::volumes.

Referenced by algorithm(), HCalEndcapAlgo::constructGeneralVolume(), HGCalEEAlgo::ConstructLayers(), HGCalHEAlgo::HGCalHEAlgo(), and HGCalHEAlgo::positionMix().

◆ attr() [1/2]

template<typename T >
T cms::DDNamespace::attr ( xml_elt_t  element,
const xml_tag_t &  name 
) const
inline

Definition at line 34 of file DDNamespace.h.

34  {
35  std::string val = realName(element.attr<std::string>(name));
36  element.setAttr(name, val);
37  return element.attr<T>(name);
38  }

References name(), realName(), AlCaHLTBitMon_QueryRunRegistry::string, and heppy_batch::val.

◆ attr() [2/2]

template<typename T >
T cms::DDNamespace::attr ( xml_elt_t  element,
const xml_tag_t &  name,
T  defaultValue 
) const
inline

Definition at line 41 of file DDNamespace.h.

41  {
42  if (element.hasAttr(name)) {
43  std::string val = realName(element.attr<std::string>(name));
44  element.setAttr(name, val);
45  return element.attr<T>(name);
46  }
47  return defaultValue;
48  }

References name(), realName(), AlCaHLTBitMon_QueryRunRegistry::string, and heppy_batch::val.

◆ context()

DDParsingContext* const cms::DDNamespace::context ( ) const
inline

Definition at line 65 of file DDNamespace.h.

65 { return m_context; }

References m_context.

Referenced by convert_boolean(), and cms::DDAlgoArguments::resolveValue().

◆ material()

dd4hep::Material DDNamespace::material ( const std::string &  name) const

◆ name()

std::string_view cms::DDNamespace::name ( void  ) const
inline

◆ nsName()

string DDNamespace::nsName ( const std::string &  )
static

Definition at line 89 of file DDNamespace.cc.

89  {
90  size_t idx;
91  if ((idx = nam.find(NAMESPACE_SEP)) != string::npos)
92  return nam.substr(0, idx);
93  return "";
94 }

References training_settings::idx, and NAMESPACE_SEP.

Referenced by algorithm().

◆ objName()

string DDNamespace::objName ( const std::string &  )
static

Definition at line 96 of file DDNamespace.cc.

96  {
97  size_t idx;
98  if ((idx = nam.find(NAMESPACE_SEP)) != string::npos)
99  return nam.substr(idx + 1);
100  return "";
101 }

References training_settings::idx, and NAMESPACE_SEP.

Referenced by algorithm().

◆ operator=()

DDNamespace& cms::DDNamespace::operator= ( const DDNamespace )
delete

◆ prepend()

string DDNamespace::prepend ( const std::string &  ) const

◆ realName()

string DDNamespace::realName ( const std::string &  ) const

Definition at line 73 of file DDNamespace.cc.

73  {
74  size_t idx, idq, idp;
75  string val = v;
76  while ((idx = val.find('[')) != string::npos) {
77  val.erase(idx, 1);
78  idp = val.find(NAMESPACE_SEP, idx);
79  idq = val.find(']', idx);
80  val.erase(idq, 1);
81  if (idp == string::npos || idp > idq)
82  val.insert(idx, m_name);
83  else if (idp != string::npos && idp < idq)
84  val[idp] = NAMESPACE_SEP;
85  }
86  return val;
87 }

References training_settings::idx, m_name, NAMESPACE_SEP, findQualityFiles::v, and heppy_batch::val.

Referenced by algorithm(), attr(), material(), cms::DDAlgoArguments::resolved_scalar_arg(), and solid().

◆ rotation()

const dd4hep::Rotation3D & DDNamespace::rotation ( const std::string &  name) const

Definition at line 130 of file DDNamespace.cc.

130  {
131  static const dd4hep::Rotation3D s_null;
132  size_t idx;
133  auto i = m_context->rotations.find(nam);
134  if (i != m_context->rotations.end())
135  return (*i).second;
136  else if (nam == "NULL")
137  return s_null;
138  else if (nam.find(":NULL") == nam.length() - 5)
139  return s_null;
140  string n = nam;
141  if ((idx = nam.find(NAMESPACE_SEP)) != string::npos) {
142  n[idx] = NAMESPACE_SEP;
143  i = m_context->rotations.find(n);
144  if (i != m_context->rotations.end())
145  return (*i).second;
146  }
147  throw runtime_error("Unknown rotation identifier:" + nam);
148 }

References mps_fire::i, training_settings::idx, m_context, dqmiodumpmetadata::n, NAMESPACE_SEP, and cms::DDParsingContext::rotations.

Referenced by algorithm(), HCalEndcapModuleAlgo::getRotation(), HCalEndcapAlgo::getRotation(), and HcalBarrelAlgo::getRotation().

◆ setContext()

DDParsingContext* cms::DDNamespace::setContext ( )
inline

Definition at line 66 of file DDNamespace.h.

66 { return m_context; }

References m_context.

◆ solid()

dd4hep::Solid DDNamespace::solid ( const std::string &  name) const

Definition at line 225 of file DDNamespace.cc.

225  {
226  size_t idx;
227  string n = m_name + nam;
228  auto i = m_context->shapes.find(n);
229  if (i != m_context->shapes.end())
230  return (*i).second;
231  if ((idx = nam.find(NAMESPACE_SEP)) != string::npos) {
232  n = realName(nam);
233  n[idx] = NAMESPACE_SEP;
234  i = m_context->shapes.find(n);
235  if (i != m_context->shapes.end())
236  return (*i).second;
237  }
238  i = m_context->shapes.find(nam);
239  if (i != m_context->shapes.end())
240  return (*i).second;
241  // Register a temporary shape
242  auto tmpShape = m_context->shapes.emplace(nam, dd4hep::Solid(nullptr));
243  return (*tmpShape.first).second;
244 }

References mps_fire::i, training_settings::idx, m_context, m_name, dqmiodumpmetadata::n, NAMESPACE_SEP, realName(), and cms::DDParsingContext::shapes.

Referenced by addSolidNS(), algorithm(), DDHGCalGeom::constructLayers(), and convert_boolean().

◆ vecDbl()

std::vector< double > DDNamespace::vecDbl ( const std::string &  name) const

Definition at line 246 of file DDNamespace.cc.

246  {
247  cms::DDVectorsMap* registry = m_context->description.load()->extension<cms::DDVectorsMap>();
248  auto it = registry->find(name);
249  if (it != registry->end()) {
250  std::vector<double> result;
251  for (auto in : it->second)
252  result.emplace_back(in);
253  return result;
254  } else
255  return std::vector<double>();
256 }

References cms::DDParsingContext::description, recoMuon::in, m_context, name(), and mps_fire::result.

Referenced by algorithm().

◆ volume()

dd4hep::Volume DDNamespace::volume ( const std::string &  name,
bool  exc = true 
) const

Definition at line 190 of file DDNamespace.cc.

190  {
191  auto i = m_context->volumes.find(name);
192  if (i != m_context->volumes.end()) {
193  return (*i).second;
194  }
195  if (name.front() == NAMESPACE_SEP) {
196  i = m_context->volumes.find(name.substr(1, name.size()));
197  if (i != m_context->volumes.end())
198  return (*i).second;
199  }
200  if (exc) {
201  throw runtime_error("Unknown volume identifier:" + name);
202  }
203  return nullptr;
204 }

References mps_fire::i, m_context, name(), NAMESPACE_SEP, and cms::DDParsingContext::volumes.

Referenced by algorithm(), DDHGCalGeom::constructLayers(), HcalBarrelAlgo::HcalBarrelAlgo(), HCalEndcapAlgo::HCalEndcapAlgo(), HCalEndcapModuleAlgo::HCalEndcapModuleAlgo(), HGCalEEAlgo::HGCalEEAlgo(), HGCalHEAlgo::HGCalHEAlgo(), load_dddefinition(), HGCalEEAlgo::PositionSensitive(), and HGCalHEAlgo::positionSensitive().

Member Data Documentation

◆ m_context

DDParsingContext* cms::DDNamespace::m_context = nullptr
private

◆ m_name

std::string cms::DDNamespace::m_name
private

Definition at line 74 of file DDNamespace.h.

Referenced by DDNamespace(), name(), prepend(), realName(), solid(), and ~DDNamespace().

◆ m_pop

bool cms::DDNamespace::m_pop = false
private

Definition at line 75 of file DDNamespace.h.

Referenced by DDNamespace(), and ~DDNamespace().

cms::DDParsingContext::debug_namespaces
bool debug_namespaces
Definition: DDParsingContext.h:83
cms::DDNamespace::realName
std::string realName(const std::string &) const
Definition: DDNamespace.cc:73
mps_fire.i
i
Definition: mps_fire.py:355
cms::DDNamespace::m_context
DDParsingContext * m_context
Definition: DDNamespace.h:73
g4SimHits_cfi.Material
Material
Definition: g4SimHits_cfi.py:547
funct::Constant
Polynomial< 0 > Constant
Definition: Constant.h:6
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
cms::DDNamespace::solid
dd4hep::Solid solid(const std::string &name) const
Definition: DDNamespace.cc:225
cms::DDNamespace::m_pop
bool m_pop
Definition: DDNamespace.h:75
cms::DDVectorsMap
tbb::concurrent_unordered_map< std::string, tbb::concurrent_vector< double > > DDVectorsMap
Definition: DDNamespace.h:14
cms::DDNamespace::addConstantNS
void addConstantNS(const std::string &name, const std::string &value, const std::string &type) const
Definition: DDNamespace.cc:107
findQualityFiles.v
v
Definition: findQualityFiles.py:179
training_settings.idx
idx
Definition: training_settings.py:16
cms::DDParsingContext::description
std::atomic< dd4hep::Detector * > description
Definition: DDParsingContext.h:36
alignCSCRings.s
s
Definition: alignCSCRings.py:92
cms::DDParsingContext::volumes
tbb::concurrent_unordered_map< std::string, dd4hep::Volume > volumes
Definition: DDParsingContext.h:39
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
cms::DDParsingContext::rotations
tbb::concurrent_unordered_map< std::string, dd4hep::Rotation3D > rotations
Definition: DDParsingContext.h:37
cms::DDNamespace::prepend
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:66
DEBUG
#define DEBUG
Definition: GeneralPurposeTrackAnalyzer.cc:79
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
recoMuon::in
Definition: RecoMuonEnumerators.h:6
cms::DDNamespace::addSolidNS
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
Definition: DDNamespace.cc:206
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
mps_fire.Path
Path
Definition: mps_fire.py:290
heppy_batch.val
val
Definition: heppy_batch.py:351
cms::DDParsingContext::debug_constants
bool debug_constants
Definition: DDParsingContext.h:77
T
long double T
Definition: Basic3DVectorLD.h:48
cms::DDNamespace::context
DDParsingContext *const context() const
Definition: DDNamespace.h:65
cms::DDParsingContext::shapes
tbb::concurrent_unordered_map< std::string, dd4hep::Solid > shapes
Definition: DDParsingContext.h:38
cms::DDParsingContext::namespaces
tbb::concurrent_queue< std::string > namespaces
Definition: DDParsingContext.h:41
makeMuonMisalignmentScenario.rot
rot
Definition: makeMuonMisalignmentScenario.py:322
NAMESPACE_SEP
#define NAMESPACE_SEP
Definition: DDNamespace.h:79
cms::DDNamespace::m_name
std::string m_name
Definition: DDNamespace.h:74
mps_fire.result
result
Definition: mps_fire.py:303
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
cms::DDParsingContext::debug_volumes
bool debug_volumes
Definition: DDParsingContext.h:81
cms::DDNamespace::name
std::string_view name() const
Definition: DDNamespace.h:68
cms::DDParsingContext::debug_shapes
bool debug_shapes
Definition: DDParsingContext.h:80
cms::DDParsingContext::ns
const bool ns(std::string &result)
Definition: DDParsingContext.h:26