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 (DDParsingContext *, xml_h)
 
 DDNamespace (DDParsingContext &, xml_h, bool)
 
 DDNamespace (DDParsingContext *)
 
 DDNamespace (DDParsingContext &)
 
 DDNamespace ()=delete
 
 DDNamespace (const DDNamespace &)=delete
 
dd4hep::Material material (const std::string &name) const
 
const std::string & 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
 
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 13 of file DDNamespace.h.

Constructor & Destructor Documentation

DDNamespace::DDNamespace ( DDParsingContext context,
xml_h  element 
)

Definition at line 12 of file DDNamespace.cc.

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

13  : m_context( context )
14 {
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()) m_name += NAMESPACE_SEP;
18  m_context->namespaces.emplace_back( m_name );
19  m_pop = true;
20  dd4hep::printout( m_context->debug_namespaces ? dd4hep::ALWAYS : dd4hep::DEBUG,
21  "DD4CMS","+++ Current namespace is now: %s", m_name.c_str());
22  return;
23 }
#define DEBUG
std::vector< std::string > namespaces
std::string m_name
Definition: DDNamespace.h:72
DDParsingContext * m_context
Definition: DDNamespace.h:71
#define NAMESPACE_SEP
Definition: DDNamespace.h:77
DDNamespace::DDNamespace ( DDParsingContext ctx,
xml_h  element,
bool   
)

Definition at line 25 of file DDNamespace.cc.

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

26  : m_context( &ctx )
27 {
28  dd4hep::Path path( xml_handler_t::system_path( element ));
29  m_name = path.filename().substr( 0, path.filename().rfind('.'));
30  if( !m_name.empty()) m_name += NAMESPACE_SEP;
31  m_context->namespaces.push_back( m_name );
32  m_pop = true;
33  dd4hep::printout( m_context->debug_namespaces ? dd4hep::ALWAYS : dd4hep::DEBUG,
34  "DD4CMS","+++ Current namespace is now: %s", m_name.c_str());
35  return;
36 }
#define DEBUG
std::vector< std::string > namespaces
std::string m_name
Definition: DDNamespace.h:72
DDParsingContext * m_context
Definition: DDNamespace.h:71
#define NAMESPACE_SEP
Definition: DDNamespace.h:77
DDNamespace::DDNamespace ( DDParsingContext ctx)

Definition at line 38 of file DDNamespace.cc.

References m_context, m_name, and cms::DDParsingContext::namespaces.

39  : m_context( ctx )
40 {
41  m_name = m_context->namespaces.back();
42 }
std::vector< std::string > namespaces
std::string m_name
Definition: DDNamespace.h:72
DDParsingContext * m_context
Definition: DDNamespace.h:71
DDNamespace::DDNamespace ( DDParsingContext ctx)

Definition at line 44 of file DDNamespace.cc.

References m_context, m_name, and cms::DDParsingContext::namespaces.

45  : m_context( &ctx )
46 {
47  m_name = m_context->namespaces.back();
48 }
std::vector< std::string > namespaces
std::string m_name
Definition: DDNamespace.h:72
DDParsingContext * m_context
Definition: DDNamespace.h:71
DDNamespace::~DDNamespace ( )

Definition at line 50 of file DDNamespace.cc.

References DEBUG, cms::DDParsingContext::debug_namespaces, m_context, m_pop, cms::DDParsingContext::namespaces, and cms::DDParsingContext::ns().

50  {
51  if( m_pop ) {
52  m_context->namespaces.pop_back();
53  dd4hep::printout( m_context->debug_namespaces ? dd4hep::ALWAYS : dd4hep::DEBUG,
54  "DD4CMS","+++ Current namespace is now: %s", m_context->ns().c_str());
55  }
56 }
#define DEBUG
const std::string & ns() const
std::vector< std::string > namespaces
DDParsingContext * m_context
Definition: DDNamespace.h:71
cms::DDNamespace::DDNamespace ( )
delete
cms::DDNamespace::DDNamespace ( const DDNamespace )
delete

Member Function Documentation

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

Definition at line 102 of file DDNamespace.cc.

References addConstantNS(), and prepend().

Referenced by attr().

103 {
104  addConstantNS( prepend( nam ), val, typ );
105 }
void addConstantNS(const std::string &name, const std::string &value, const std::string &type) const
Definition: DDNamespace.cc:108
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:59
void DDNamespace::addConstantNS ( const std::string &  name,
const std::string &  value,
const std::string &  type 
) const

Definition at line 108 of file DDNamespace.cc.

References EnergyCorrector::c, DEBUG, cms::DDParsingContext::debug_constants, cms::DDParsingContext::description, m_context, g4SimHits_cfi::Material, gen::n, findQualityFiles::v, and heppy_batch::val.

Referenced by addConstant(), attr(), and load_dddefinition().

109 {
110  const string& v = val;
111  const string& n = nam;
112  dd4hep::printout( m_context->debug_constants ? dd4hep::ALWAYS : dd4hep::DEBUG,
113  "DD4CMS","+++ Add constant object: %-40s = %s [type:%s]",
114  n.c_str(), v.c_str(), typ.c_str());
115  dd4hep::_toDictionary( n, v, typ );
116  dd4hep::Constant c( n, v, typ );
117  m_context->description->addConstant( c );
118 }
#define DEBUG
dd4hep::Detector * description
DDParsingContext * m_context
Definition: DDNamespace.h:71
Polynomial< 0 > Constant
Definition: Constant.h:6
void DDNamespace::addRotation ( const std::string &  name,
const dd4hep::Rotation3D &  rot 
) const

Definition at line 127 of file DDNamespace.cc.

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

Referenced by attr().

128 {
129  string n = prepend( name );
130  m_context->rotations[n] = rot;
131 }
std::unordered_map< std::string, dd4hep::Rotation3D > rotations
DDParsingContext * m_context
Definition: DDNamespace.h:71
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:59
const std::string & name() const
Definition: DDNamespace.h:65
dd4hep::Solid DDNamespace::addSolid ( const std::string &  name,
dd4hep::Solid  solid 
) const

Definition at line 221 of file DDNamespace.cc.

References addSolidNS(), and prepend().

Referenced by algorithm(), attr(), and convert_boolean().

222 {
223  return addSolidNS( prepend( name ), sol );
224 }
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
Definition: DDNamespace.cc:210
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:59
const std::string & name() const
Definition: DDNamespace.h:65
dd4hep::Solid DDNamespace::addSolidNS ( const std::string &  name,
dd4hep::Solid  solid 
) const

Definition at line 210 of file DDNamespace.cc.

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

Referenced by addSolid(), algorithm(), and attr().

211 {
212  dd4hep::printout( m_context->debug_shapes ? dd4hep::ALWAYS : dd4hep::DEBUG, "DD4CMS",
213  "+++ Add shape of type %s : %s", solid->IsA()->GetName(), name.c_str());
214 
215  m_context->shapes.try_emplace( name, solid.setName( name ));
216 
217  return solid;
218 }
#define DEBUG
dd4hep::Solid solid(const std::string &name) const
Definition: DDNamespace.cc:227
DDParsingContext * m_context
Definition: DDNamespace.h:71
const std::string & name() const
Definition: DDNamespace.h:65
std::unordered_map< std::string, dd4hep::Solid > shapes
dd4hep::Volume DDNamespace::addVolume ( dd4hep::Volume  vol) const

Add rotation matrix to current namespace.

Definition at line 175 of file DDNamespace.cc.

References DEBUG, cms::DDParsingContext::debug_volumes, funct::m, m_context, g4SimHits_cfi::Material, gen::n, prepend(), alignCSCRings::s, g4SimHits_cfi::Volume, and cms::DDParsingContext::volumes.

Referenced by algorithm(), attr(), and load_dddefinition().

176 {
177  string n = prepend(vol.name());
178  dd4hep::Solid s = vol.solid();
179  dd4hep::Material m = vol.material();
180  vol->SetName(n.c_str());
181  m_context->volumes[n] = vol;
182  dd4hep::printout( m_context->debug_volumes ? dd4hep::ALWAYS : dd4hep::DEBUG, "DD4CMS",
183  "+++ Add volume:%-38s Solid:%-26s[%-16s] Material:%s",
184  vol.name(), s.name(), s.type(), m.name());
185  return vol;
186 }
#define DEBUG
std::unordered_map< std::string, dd4hep::Volume > volumes
DDParsingContext * m_context
Definition: DDNamespace.h:71
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:59
dd4hep::Volume DDNamespace::addVolumeNS ( dd4hep::Volume  vol) const

Definition at line 160 of file DDNamespace.cc.

References DEBUG, cms::DDParsingContext::debug_volumes, funct::m, m_context, g4SimHits_cfi::Material, gen::n, alignCSCRings::s, g4SimHits_cfi::Volume, and cms::DDParsingContext::volumes.

Referenced by algorithm(), and attr().

161 {
162  string n = vol.name();
163  dd4hep::Solid s = vol.solid();
164  dd4hep::Material m = vol.material();
165  vol->SetName(n.c_str());
166  m_context->volumes[n] = vol;
167  dd4hep::printout( m_context->debug_volumes ? dd4hep::ALWAYS : dd4hep::DEBUG, "DD4CMS",
168  "+++ Add volume:%-38s Solid:%-26s[%-16s] Material:%s",
169  vol.name(), s.name(), s.type(), m.name());
170  return vol;
171 }
#define DEBUG
std::unordered_map< std::string, dd4hep::Volume > volumes
DDParsingContext * m_context
Definition: DDNamespace.h:71
template<typename T >
T cms::DDNamespace::attr ( xml_elt_t  element,
const xml_tag_t &  name 
) const
inline

Definition at line 32 of file DDNamespace.h.

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

Referenced by convert_boolean(), and splitString().

32  {
33  std::string val = realName( element.attr<std::string>( name ));
34  element.setAttr( name, val );
35  return element.attr<T>( name );
36  }
std::string realName(const std::string &) const
Definition: DDNamespace.cc:65
const std::string & name() const
Definition: DDNamespace.h:65
long double T
template<typename T >
T cms::DDNamespace::attr ( xml_elt_t  element,
const xml_tag_t &  name,
T  defaultValue 
) const
inline

Definition at line 38 of file DDNamespace.h.

References addConstant(), addConstantNS(), addRotation(), addSolid(), addSolidNS(), addVolume(), addVolumeNS(), material(), g4SimHits_cfi::Material, name(), realName(), makeMuonMisalignmentScenario::rot, rotation(), solid(), AlCaHLTBitMon_QueryRunRegistry::string, heppy_batch::val, volume(), and g4SimHits_cfi::Volume.

38  {
39  if( element.hasAttr( name )) {
40  std::string val = realName( element.attr<std::string>( name ));
41  element.setAttr( name, val );
42  return element.attr<T>( name );
43  }
44  return defaultValue;
45  }
std::string realName(const std::string &) const
Definition: DDNamespace.cc:65
const std::string & name() const
Definition: DDNamespace.h:65
long double T
DDParsingContext* const cms::DDNamespace::context ( ) const
inline

Definition at line 62 of file DDNamespace.h.

References m_context.

Referenced by convert_boolean(), and splitString().

62 { return m_context; }
DDParsingContext * m_context
Definition: DDNamespace.h:71
dd4hep::Material DDNamespace::material ( const std::string &  name) const

Definition at line 121 of file DDNamespace.cc.

References cms::DDParsingContext::description, m_context, and realName().

Referenced by algorithm(), and attr().

122 {
123  return m_context->description->material( realName( name ));
124 }
dd4hep::Detector * description
std::string realName(const std::string &) const
Definition: DDNamespace.cc:65
DDParsingContext * m_context
Definition: DDNamespace.h:71
const std::string & name() const
Definition: DDNamespace.h:65
const std::string& cms::DDNamespace::name ( void  ) const
inline
string DDNamespace::nsName ( const std::string &  )
static

Definition at line 84 of file DDNamespace.cc.

References training_settings::idx, and NAMESPACE_SEP.

Referenced by algorithm().

85 {
86  size_t idx;
87  if(( idx = nam.find( NAMESPACE_SEP )) != string::npos )
88  return nam.substr( 0, idx );
89  return "";
90 }
#define NAMESPACE_SEP
Definition: DDNamespace.h:77
string DDNamespace::objName ( const std::string &  )
static

Definition at line 93 of file DDNamespace.cc.

References training_settings::idx, and NAMESPACE_SEP.

Referenced by algorithm().

94 {
95  size_t idx;
96  if(( idx = nam.find( NAMESPACE_SEP )) != string::npos )
97  return nam.substr( idx + 1 );
98  return "";
99 }
#define NAMESPACE_SEP
Definition: DDNamespace.h:77
DDNamespace& cms::DDNamespace::operator= ( const DDNamespace )
delete
string DDNamespace::prepend ( const std::string &  ) const

Definition at line 59 of file DDNamespace.cc.

References m_name, and gen::n.

Referenced by addConstant(), addRotation(), addSolid(), addVolume(), and algorithm().

60 {
61  return m_name + n;
62 }
std::string m_name
Definition: DDNamespace.h:72
string DDNamespace::realName ( const std::string &  ) const

Definition at line 65 of file DDNamespace.cc.

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

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

66 {
67  size_t idx, idq, idp;
68  string val = v;
69  while(( idx = val.find('[')) != string::npos )
70  {
71  val.erase( idx, 1 );
72  idp = val.find( NAMESPACE_SEP, idx );
73  idq = val.find( ']', idx );
74  val.erase( idq, 1 );
75  if( idp == string::npos || idp > idq )
76  val.insert( idx, m_name );
77  else if ( idp != string::npos && idp < idq )
78  val[idp] = NAMESPACE_SEP;
79  }
80  return val;
81 }
std::string m_name
Definition: DDNamespace.h:72
#define NAMESPACE_SEP
Definition: DDNamespace.h:77
const dd4hep::Rotation3D & DDNamespace::rotation ( const std::string &  name) const

Definition at line 134 of file DDNamespace.cc.

References gather_cfg::cout, mps_fire::i, training_settings::idx, m_context, gen::n, NAMESPACE_SEP, alignCSCRings::r, cms::DDParsingContext::rotations, and g4SimHits_cfi::Volume.

Referenced by algorithm(), attr(), and doPos().

135 {
136  static dd4hep::Rotation3D s_null;
137  size_t idx;
138  auto i = m_context->rotations.find( nam );
139  if( i != m_context->rotations.end())
140  return (*i).second;
141  else if( nam == "NULL" )
142  return s_null;
143  else if( nam.find(":NULL") == nam.length() - 5 )
144  return s_null;
145  string n = nam;
146  if(( idx = nam.find( NAMESPACE_SEP )) != string::npos )
147  {
148  n[idx] = NAMESPACE_SEP;
149  i = m_context->rotations.find(n);
150  if( i != m_context->rotations.end() )
151  return (*i).second;
152  }
153  for( const auto& r : m_context->rotations ) {
154  cout << r.first << endl;
155  }
156  throw runtime_error("Unknown rotation identifier:"+nam);
157 }
std::unordered_map< std::string, dd4hep::Rotation3D > rotations
DDParsingContext * m_context
Definition: DDNamespace.h:71
#define NAMESPACE_SEP
Definition: DDNamespace.h:77
DDParsingContext* cms::DDNamespace::setContext ( )
inline

Definition at line 63 of file DDNamespace.h.

References m_context.

Referenced by splitString().

63 { return m_context; }
DDParsingContext * m_context
Definition: DDNamespace.h:71
dd4hep::Solid DDNamespace::solid ( const std::string &  name) const

Definition at line 227 of file DDNamespace.cc.

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

Referenced by addSolidNS(), attr(), and convert_boolean().

228 {
229  size_t idx;
230  string n = m_context->namespaces.back() + nam;
231  auto i = m_context->shapes.find( n );
232  if( i != m_context->shapes.end())
233  return (*i).second;
234  if(( idx = nam.find( NAMESPACE_SEP )) != string::npos ) {
235  n = realName( nam );
236  n[idx] = NAMESPACE_SEP;
237  i = m_context->shapes.find( n );
238  if ( i != m_context->shapes.end() )
239  return (*i).second;
240  }
241  i = m_context->shapes.find(nam);
242  if( i != m_context->shapes.end()) return (*i).second;
243  throw runtime_error( "Unknown shape identifier:" + nam );
244 }
std::vector< std::string > namespaces
std::string realName(const std::string &) const
Definition: DDNamespace.cc:65
DDParsingContext * m_context
Definition: DDNamespace.h:71
std::unordered_map< std::string, dd4hep::Solid > shapes
#define NAMESPACE_SEP
Definition: DDNamespace.h:77
dd4hep::Volume DDNamespace::volume ( const std::string &  name,
bool  exc = true 
) const

Definition at line 189 of file DDNamespace.cc.

References mps_fire::i, training_settings::idx, m_context, gen::n, name(), NAMESPACE_SEP, and cms::DDParsingContext::volumes.

Referenced by algorithm(), and attr().

190 {
191  size_t idx;
192  auto i = m_context->volumes.find( name );
193  if( i != m_context->volumes.end()) {
194  return (*i).second;
195  }
196  if(( idx = name.find( NAMESPACE_SEP )) != string::npos ) {
197  string n = name;
198  n[idx] = NAMESPACE_SEP;
199  i = m_context->volumes.find( n );
200  if( i != m_context->volumes.end())
201  return (*i).second;
202  }
203  if( exc ) {
204  throw runtime_error( "Unknown volume identifier:" + name );
205  }
206  return nullptr;
207 }
std::unordered_map< std::string, dd4hep::Volume > volumes
DDParsingContext * m_context
Definition: DDNamespace.h:71
const std::string & name() const
Definition: DDNamespace.h:65
#define NAMESPACE_SEP
Definition: DDNamespace.h:77

Member Data Documentation

DDParsingContext* cms::DDNamespace::m_context = nullptr
private
std::string cms::DDNamespace::m_name
private

Definition at line 72 of file DDNamespace.h.

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

bool cms::DDNamespace::m_pop = false
private

Definition at line 73 of file DDNamespace.h.

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