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
 
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
 
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(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
tbb::concurrent_queue< 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.emplace(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
tbb::concurrent_queue< 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::ns().

39  : m_context(ctx)
40 {
41  if(!m_context->ns(m_name)) m_name.clear();
42 }
std::string m_name
Definition: DDNamespace.h:72
bool const ns(std::string &result)
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::ns().

45  : m_context(&ctx)
46 {
47  if(!m_context->ns(m_name)) m_name.clear();
48 }
std::string m_name
Definition: DDNamespace.h:72
bool const ns(std::string &result)
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_name, m_pop, cms::DDParsingContext::namespaces, and mps_fire::result.

50  {
51  if(m_pop) {
52  string result("");
53  if(m_context->namespaces.try_pop(result))
54  m_name = result;
55  else
56  m_name.clear();
57  dd4hep::printout(m_context->debug_namespaces ? dd4hep::ALWAYS : dd4hep::DEBUG,
58  "DD4CMS","+++ Current namespace is now: %s", m_name.c_str());
59  }
60 }
#define DEBUG
tbb::concurrent_queue< std::string > namespaces
std::string m_name
Definition: DDNamespace.h:72
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 106 of file DDNamespace.cc.

References addConstantNS(), and prepend().

Referenced by attr().

107 {
108  addConstantNS( prepend( nam ), val, typ );
109 }
void addConstantNS(const std::string &name, const std::string &value, const std::string &type) const
Definition: DDNamespace.cc:112
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:63
void DDNamespace::addConstantNS ( const std::string &  name,
const std::string &  value,
const std::string &  type 
) const

Definition at line 112 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().

113 {
114  const string& v = val;
115  const string& n = nam;
116  dd4hep::printout( m_context->debug_constants ? dd4hep::ALWAYS : dd4hep::DEBUG,
117  "DD4CMS","+++ Add constant object: %-40s = %s [type:%s]",
118  n.c_str(), v.c_str(), typ.c_str());
119  dd4hep::_toDictionary( n, v, typ );
120  dd4hep::Constant c( n, v, typ );
121  m_context->description.load()->addConstant( c );
122 }
#define DEBUG
std::atomic< 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 131 of file DDNamespace.cc.

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

Referenced by attr().

132 {
133  string n = prepend( name );
134  m_context->rotations[n] = rot;
135 }
tbb::concurrent_unordered_map< std::string, dd4hep::Rotation3D > rotations
std::string_view name() const
Definition: DDNamespace.h:65
DDParsingContext * m_context
Definition: DDNamespace.h:71
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:63
dd4hep::Solid DDNamespace::addSolid ( const std::string &  name,
dd4hep::Solid  solid 
) const

Definition at line 222 of file DDNamespace.cc.

References addSolidNS(), and prepend().

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

223 {
224  return addSolidNS( prepend( name ), sol );
225 }
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
Definition: DDNamespace.cc:211
std::string_view name() const
Definition: DDNamespace.h:65
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:63
dd4hep::Solid DDNamespace::addSolidNS ( const std::string &  name,
dd4hep::Solid  solid 
) const

Definition at line 211 of file DDNamespace.cc.

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

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

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

Add rotation matrix to current namespace.

Definition at line 179 of file DDNamespace.cc.

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

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

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

Definition at line 164 of file DDNamespace.cc.

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

Referenced by algorithm(), and attr().

165 {
166  string n = vol.name();
167  dd4hep::Solid s = vol.solid();
168  dd4hep::Material m = vol.material();
169  vol->SetName(n.c_str());
170  m_context->volumes[n] = vol;
171  dd4hep::printout( m_context->debug_volumes ? dd4hep::ALWAYS : dd4hep::DEBUG, "DD4CMS",
172  "+++ Add volume:%-38s Solid:%-26s[%-16s] Material:%s",
173  vol.name(), s.name(), s.type(), m.name());
174  return vol;
175 }
#define DEBUG
DDParsingContext * m_context
Definition: DDNamespace.h:71
tbb::concurrent_unordered_map< std::string, dd4hep::Volume > volumes
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 for_each_token().

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_view name() const
Definition: DDNamespace.h:65
std::string realName(const std::string &) const
Definition: DDNamespace.cc:69
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, and 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_view name() const
Definition: DDNamespace.h:65
std::string realName(const std::string &) const
Definition: DDNamespace.cc:69
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 for_each_token().

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

Definition at line 125 of file DDNamespace.cc.

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

Referenced by algorithm(), and attr().

126 {
127  return m_context->description.load()->material( realName( name ));
128 }
std::atomic< dd4hep::Detector * > description
std::string_view name() const
Definition: DDNamespace.h:65
std::string realName(const std::string &) const
Definition: DDNamespace.cc:69
DDParsingContext * m_context
Definition: DDNamespace.h:71
std::string_view cms::DDNamespace::name ( void  ) const
inline
string DDNamespace::nsName ( const std::string &  )
static

Definition at line 88 of file DDNamespace.cc.

References training_settings::idx, and NAMESPACE_SEP.

Referenced by algorithm().

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

Definition at line 97 of file DDNamespace.cc.

References training_settings::idx, and NAMESPACE_SEP.

Referenced by algorithm().

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

Definition at line 63 of file DDNamespace.cc.

References m_name, and gen::n.

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

64 {
65  return m_name + n;
66 }
std::string m_name
Definition: DDNamespace.h:72
string DDNamespace::realName ( const std::string &  ) const

Definition at line 69 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().

70 {
71  size_t idx, idq, idp;
72  string val = v;
73  while(( idx = val.find('[')) != string::npos )
74  {
75  val.erase( idx, 1 );
76  idp = val.find( NAMESPACE_SEP, idx );
77  idq = val.find( ']', idx );
78  val.erase( idq, 1 );
79  if( idp == string::npos || idp > idq )
80  val.insert( idx, m_name );
81  else if ( idp != string::npos && idp < idq )
82  val[idp] = NAMESPACE_SEP;
83  }
84  return val;
85 }
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 138 of file DDNamespace.cc.

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

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

139 {
140  static const dd4hep::Rotation3D s_null;
141  size_t idx;
142  auto i = m_context->rotations.find( nam );
143  if( i != m_context->rotations.end())
144  return (*i).second;
145  else if( nam == "NULL" )
146  return s_null;
147  else if( nam.find(":NULL") == nam.length() - 5 )
148  return s_null;
149  string n = nam;
150  if(( idx = nam.find( NAMESPACE_SEP )) != string::npos )
151  {
152  n[idx] = NAMESPACE_SEP;
153  i = m_context->rotations.find(n);
154  if( i != m_context->rotations.end() )
155  return (*i).second;
156  }
157  for( const auto& r : m_context->rotations ) {
158  cout << r.first << endl;
159  }
160  throw runtime_error("Unknown rotation identifier:"+nam);
161 }
tbb::concurrent_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 for_each_token().

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

Definition at line 228 of file DDNamespace.cc.

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

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

229 {
230  size_t idx;
231  string n = m_name + nam;
232  auto i = m_context->shapes.find( n );
233  if( i != m_context->shapes.end())
234  return (*i).second;
235  if(( idx = nam.find( NAMESPACE_SEP )) != string::npos ) {
236  n = realName( nam );
237  n[idx] = NAMESPACE_SEP;
238  i = m_context->shapes.find( n );
239  if ( i != m_context->shapes.end() )
240  return (*i).second;
241  }
242  i = m_context->shapes.find(nam);
243  if( i != m_context->shapes.end()) return (*i).second;
244  throw runtime_error( "Unknown shape identifier:" + nam );
245 }
std::string m_name
Definition: DDNamespace.h:72
std::string realName(const std::string &) const
Definition: DDNamespace.cc:69
DDParsingContext * m_context
Definition: DDNamespace.h:71
tbb::concurrent_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 193 of file DDNamespace.cc.

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

Referenced by algorithm(), and attr().

194 {
195  auto i = m_context->volumes.find( name );
196  if( i != m_context->volumes.end()) {
197  return (*i).second;
198  }
199  if(name.front() == NAMESPACE_SEP) {
200  i = m_context->volumes.find(name.substr(1,name.size()));
201  if( i != m_context->volumes.end())
202  return (*i).second;
203  }
204  if( exc ) {
205  throw runtime_error( "Unknown volume identifier:" + name );
206  }
207  return nullptr;
208 }
std::string_view name() const
Definition: DDNamespace.h:65
DDParsingContext * m_context
Definition: DDNamespace.h:71
tbb::concurrent_unordered_map< std::string, dd4hep::Volume > volumes
#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(), realName(), solid(), and ~DDNamespace().

bool cms::DDNamespace::m_pop = false
private

Definition at line 73 of file DDNamespace.h.

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