CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Public Attributes | 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
 
void addVector (const std::string &name, const std::vector< double > &value) 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
 
 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
 
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 &)
 

Public Attributes

DDParsingContextcontext = nullptr
 

Private Attributes

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, training_settings::idx, label, m_name, m_pop, NAMESPACE_SEP, cms::DDParsingContext::namespaces, callgraph::path, and mps_fire::Path.

13  : context( context )
14 {
15  xml_dim_t elt( element );
16  bool has_label = elt.hasAttr(_U(label));
17  m_name = has_label ? elt.labelStr() : "";
18  if( !has_label ) {
19  if( !context->namespaces.empty()) {
20  m_name = context->namespaces.back();
21  }
22  dd4hep::printout( context->debug_namespaces ? dd4hep::ALWAYS : dd4hep::DEBUG,
23  "MyDDCMS", "+++ Current namespace is now: %s", m_name.c_str());
24  return;
25  }
26  if( has_label ) {
27  size_t idx = m_name.find('.');
28  m_name = m_name.substr( 0, idx );
29  }
30  else {
31  dd4hep::Path path( xml_handler_t::system_path( element ));
32  m_name = path.filename().substr( 0, path.filename().rfind('.'));
33  }
34  if ( !m_name.empty()) m_name += NAMESPACE_SEP;
35  context->namespaces.push_back( m_name );
36  m_pop = true;
37  dd4hep::printout( context->debug_namespaces ? dd4hep::ALWAYS : dd4hep::DEBUG,
38  "MyDDCMS","+++ Current namespace is now: %s", m_name.c_str());
39  return;
40 }
#define DEBUG
std::string m_name
Definition: DDNamespace.h:70
char const * label
std::vector< std::string > namespaces
DDParsingContext * context
Definition: DDNamespace.h:63
#define NAMESPACE_SEP
Definition: DDNamespace.h:75
DDNamespace::DDNamespace ( DDParsingContext ctx,
xml_h  element,
bool   
)

Definition at line 42 of file DDNamespace.cc.

References context, DEBUG, cms::DDParsingContext::debug_namespaces, training_settings::idx, label, m_name, m_pop, NAMESPACE_SEP, cms::DDParsingContext::namespaces, callgraph::path, and mps_fire::Path.

43  : context(&ctx)
44 {
45  xml_dim_t elt(element);
46  bool has_label = elt.hasAttr(_U(label));
47  m_name = has_label ? elt.labelStr() : "";
48  if( has_label ) {
49  size_t idx = m_name.find('.');
50  m_name = m_name.substr(0,idx);
51  }
52  else {
53  dd4hep::Path path( xml_handler_t::system_path( element ));
54  m_name = path.filename().substr( 0, path.filename().rfind('.'));
55  }
56  if( !m_name.empty()) m_name += NAMESPACE_SEP;
57  context->namespaces.push_back( m_name );
58  m_pop = true;
59  dd4hep::printout( context->debug_namespaces ? dd4hep::ALWAYS : dd4hep::DEBUG,
60  "MyDDCMS","+++ Current namespace is now: %s", m_name.c_str());
61  return;
62 }
#define DEBUG
std::string m_name
Definition: DDNamespace.h:70
char const * label
std::vector< std::string > namespaces
DDParsingContext * context
Definition: DDNamespace.h:63
#define NAMESPACE_SEP
Definition: DDNamespace.h:75
DDNamespace::DDNamespace ( DDParsingContext ctx)

Definition at line 64 of file DDNamespace.cc.

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

65  : context( ctx )
66 {
67  m_name = context->namespaces.back();
68 }
std::string m_name
Definition: DDNamespace.h:70
std::vector< std::string > namespaces
DDParsingContext * context
Definition: DDNamespace.h:63
DDNamespace::DDNamespace ( DDParsingContext ctx)

Definition at line 70 of file DDNamespace.cc.

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

71  : context( &ctx )
72 {
73  m_name = context->namespaces.back();
74 }
std::string m_name
Definition: DDNamespace.h:70
std::vector< std::string > namespaces
DDParsingContext * context
Definition: DDNamespace.h:63
DDNamespace::~DDNamespace ( )

Definition at line 76 of file DDNamespace.cc.

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

76  {
77  if( m_pop ) {
78  context->namespaces.pop_back();
79  dd4hep::printout( context->debug_namespaces ? dd4hep::ALWAYS : dd4hep::DEBUG,
80  "MyDDCMS","+++ Current namespace is now: %s", context->ns().c_str());
81  }
82 }
#define DEBUG
const std::string & ns() const
std::vector< std::string > namespaces
DDParsingContext * context
Definition: DDNamespace.h:63
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 128 of file DDNamespace.cc.

References addConstantNS(), and prepend().

Referenced by attr().

129 {
130  addConstantNS( prepend( nam ), val, typ );
131 }
void addConstantNS(const std::string &name, const std::string &value, const std::string &type) const
Definition: DDNamespace.cc:134
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:85
void DDNamespace::addConstantNS ( const std::string &  name,
const std::string &  value,
const std::string &  type 
) const

Definition at line 134 of file DDNamespace.cc.

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

Referenced by addConstant(), and attr().

135 {
136  const string& v = val;
137  const string& n = nam;
138  dd4hep::printout( context->debug_constants ? dd4hep::ALWAYS : dd4hep::DEBUG,
139  "MyDDCMS","+++ Add constant object: %-40s = %s [type:%s]",
140  n.c_str(), v.c_str(), typ.c_str());
141  dd4hep::_toDictionary( n, v, typ );
142  dd4hep::Constant c( n, v, typ );
143  context->description->addConstant( c );
144 }
#define DEBUG
dd4hep::Detector * description
Polynomial< 0 > Constant
Definition: Constant.h:6
DDParsingContext * context
Definition: DDNamespace.h:63
void DDNamespace::addRotation ( const std::string &  name,
const dd4hep::Rotation3D &  rot 
) const

Definition at line 164 of file DDNamespace.cc.

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

Referenced by attr().

165 {
166  string n = prepend( name );
167  context->rotations[n] = rot;
168 }
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:85
DDParsingContext * context
Definition: DDNamespace.h:63
const std::string & name() const
Definition: DDNamespace.h:65
std::map< std::string, dd4hep::Rotation3D > rotations
dd4hep::Solid DDNamespace::addSolid ( const std::string &  name,
dd4hep::Solid  solid 
) const

Definition at line 257 of file DDNamespace.cc.

References addSolidNS(), and prepend().

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

258 {
259  return addSolidNS( prepend(nam), sol );
260 }
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
Definition: DDNamespace.cc:247
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:85
dd4hep::Solid DDNamespace::addSolidNS ( const std::string &  name,
dd4hep::Solid  solid 
) const

Definition at line 247 of file DDNamespace.cc.

References context, DEBUG, cms::DDParsingContext::debug_shapes, and cms::DDParsingContext::shapes.

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

248 {
249  dd4hep::printout(context->debug_shapes ? dd4hep::ALWAYS : dd4hep::DEBUG, "MyDDCMS",
250  "+++ Add shape of type %s : %s",sol->IsA()->GetName(), nam.c_str());
251  context->shapes[nam] = sol.setName(nam);
252 
253  return sol;
254 }
#define DEBUG
std::map< std::string, dd4hep::Solid > shapes
DDParsingContext * context
Definition: DDNamespace.h:63
void DDNamespace::addVector ( const std::string &  name,
const std::vector< double > &  value 
) const

Definition at line 147 of file DDNamespace.cc.

References cms::DDParsingContext::addVector(), context, DEBUG, cms::DDParsingContext::debug_constants, g4SimHits_cfi::Material, gen::n, name(), findQualityFiles::v, and relativeConstraints::value.

Referenced by attr().

148 {
149  const vector<double>& v = value;
150  const string& n = name;
151  dd4hep::printout( context->debug_constants ? dd4hep::ALWAYS : dd4hep::DEBUG,
152  "MyDDCMS","+++ Add constant object: %-40s = %s ",
153  n.c_str(), "vector<double>");
154  context->addVector( n, v );
155 }
#define DEBUG
void addVector(const std::string &name, const VecDouble &value)
DDParsingContext * context
Definition: DDNamespace.h:63
const std::string & name() const
Definition: DDNamespace.h:65
dd4hep::Volume DDNamespace::addVolume ( dd4hep::Volume  vol) const

Add rotation matrix to current namespace.

Definition at line 212 of file DDNamespace.cc.

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

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

213 {
214  string n = prepend(vol.name());
215  dd4hep::Solid s = vol.solid();
216  dd4hep::Material m = vol.material();
217  vol->SetName(n.c_str());
218  context->volumes[n] = vol;
219  dd4hep::printout(context->debug_volumes ? dd4hep::ALWAYS : dd4hep::DEBUG, "MyDDCMS",
220  "+++ Add volume:%-38s Solid:%-26s[%-16s] Material:%s",
221  vol.name(), s.name(), s.type(), m.name());
222  return vol;
223 }
#define DEBUG
std::map< std::string, dd4hep::Volume > volumes
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:85
DDParsingContext * context
Definition: DDNamespace.h:63
dd4hep::Volume DDNamespace::addVolumeNS ( dd4hep::Volume  vol) const

Definition at line 197 of file DDNamespace.cc.

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

Referenced by algorithm(), and attr().

198 {
199  string n = vol.name();
200  dd4hep::Solid s = vol.solid();
201  dd4hep::Material m = vol.material();
202  vol->SetName(n.c_str());
203  context->volumes[n] = vol;
204  dd4hep::printout(context->debug_volumes ? dd4hep::ALWAYS : dd4hep::DEBUG, "MyDDCMS",
205  "+++ Add volume:%-38s Solid:%-26s[%-16s] Material:%s",
206  vol.name(), s.name(), s.type(), m.name());
207  return vol;
208 }
#define DEBUG
std::map< std::string, dd4hep::Volume > volumes
DDParsingContext * context
Definition: DDNamespace.h:63
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:91
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(), addVector(), 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:91
const std::string & name() const
Definition: DDNamespace.h:65
long double T
dd4hep::Material DDNamespace::material ( const std::string &  name) const

Definition at line 158 of file DDNamespace.cc.

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

Referenced by algorithm(), and attr().

159 {
160  return context->description->material( realName( name ));
161 }
dd4hep::Detector * description
std::string realName(const std::string &) const
Definition: DDNamespace.cc:91
DDParsingContext * context
Definition: DDNamespace.h:63
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 110 of file DDNamespace.cc.

References training_settings::idx, and NAMESPACE_SEP.

Referenced by algorithm().

111 {
112  size_t idx;
113  if(( idx = nam.find( NAMESPACE_SEP )) != string::npos )
114  return nam.substr( 0, idx );
115  return "";
116 }
#define NAMESPACE_SEP
Definition: DDNamespace.h:75
string DDNamespace::objName ( const std::string &  )
static

Definition at line 119 of file DDNamespace.cc.

References training_settings::idx, and NAMESPACE_SEP.

Referenced by algorithm().

120 {
121  size_t idx;
122  if(( idx = nam.find( NAMESPACE_SEP )) != string::npos )
123  return nam.substr( idx + 1 );
124  return "";
125 }
#define NAMESPACE_SEP
Definition: DDNamespace.h:75
DDNamespace& cms::DDNamespace::operator= ( const DDNamespace )
delete
string DDNamespace::prepend ( const std::string &  ) const

Definition at line 85 of file DDNamespace.cc.

References m_name, and gen::n.

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

86 {
87  return m_name + n;
88 }
std::string m_name
Definition: DDNamespace.h:70
string DDNamespace::realName ( const std::string &  ) const

Definition at line 91 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(), convert_boolean(), material(), cms::DDAlgoArguments::parentName(), cms::DDAlgoArguments::resolved_scalar_arg(), and solid().

92 {
93  size_t idx, idq, idp;
94  string val = v;
95  while(( idx = val.find('[')) != string::npos )
96  {
97  val.erase( idx, 1 );
98  idp = val.find( NAMESPACE_SEP, idx );
99  idq = val.find( ']', idx );
100  val.erase( idq, 1 );
101  if( idp == string::npos || idp > idq )
102  val.insert( idx, m_name );
103  else if ( idp != string::npos && idp < idq )
104  val[idp] = NAMESPACE_SEP;
105  }
106  return val;
107 }
std::string m_name
Definition: DDNamespace.h:70
#define NAMESPACE_SEP
Definition: DDNamespace.h:75
const dd4hep::Rotation3D & DDNamespace::rotation ( const std::string &  name) const

Definition at line 171 of file DDNamespace.cc.

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

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

172 {
173  static dd4hep::Rotation3D s_null;
174  size_t idx;
175  auto i = context->rotations.find( nam );
176  if( i != context->rotations.end())
177  return (*i).second;
178  else if( nam == "NULL" )
179  return s_null;
180  else if( nam.find(":NULL") == nam.length() - 5 )
181  return s_null;
182  string n = nam;
183  if(( idx = nam.find( NAMESPACE_SEP )) != string::npos )
184  {
185  n[idx] = NAMESPACE_SEP;
186  i = context->rotations.find(n);
187  if( i != context->rotations.end() )
188  return (*i).second;
189  }
190  for( const auto& r : context->rotations ) {
191  cout << r.first << endl;
192  }
193  throw runtime_error("Unknown rotation identifier:"+nam);
194 }
DDParsingContext * context
Definition: DDNamespace.h:63
std::map< std::string, dd4hep::Rotation3D > rotations
#define NAMESPACE_SEP
Definition: DDNamespace.h:75
dd4hep::Solid DDNamespace::solid ( const std::string &  name) const

Definition at line 263 of file DDNamespace.cc.

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

Referenced by attr(), and convert_boolean().

264 {
265  size_t idx;
266  string n = context->namespaces.back() + nam;
267  auto i = context->shapes.find( n );
268  if( i != context->shapes.end())
269  return (*i).second;
270  if(( idx = nam.find( NAMESPACE_SEP )) != string::npos ) {
271  n = realName( nam );
272  n[idx] = NAMESPACE_SEP;
273  i = context->shapes.find( n );
274  if ( i != context->shapes.end() )
275  return (*i).second;
276  }
277  i = context->shapes.find(nam);
278  if( i != context->shapes.end()) return (*i).second;
279  throw runtime_error( "Unknown shape identifier:" + nam );
280 }
std::map< std::string, dd4hep::Solid > shapes
std::string realName(const std::string &) const
Definition: DDNamespace.cc:91
std::vector< std::string > namespaces
DDParsingContext * context
Definition: DDNamespace.h:63
#define NAMESPACE_SEP
Definition: DDNamespace.h:75
dd4hep::Volume DDNamespace::volume ( const std::string &  name,
bool  exc = true 
) const

Definition at line 226 of file DDNamespace.cc.

References context, mps_fire::i, training_settings::idx, gen::n, NAMESPACE_SEP, and cms::DDParsingContext::volumes.

Referenced by algorithm(), and attr().

227 {
228  size_t idx;
229  auto i = context->volumes.find(nam);
230  if ( i != context->volumes.end() ) {
231  return (*i).second;
232  }
233  if(( idx = nam.find( NAMESPACE_SEP )) != string::npos ) {
234  string n = nam;
235  n[idx] = NAMESPACE_SEP;
236  i = context->volumes.find( n );
237  if( i != context->volumes.end())
238  return (*i).second;
239  }
240  if( exc ) {
241  throw runtime_error("Unknown volume identifier:"+nam);
242  }
243  return nullptr;
244 }
std::map< std::string, dd4hep::Volume > volumes
DDParsingContext * context
Definition: DDNamespace.h:63
#define NAMESPACE_SEP
Definition: DDNamespace.h:75

Member Data Documentation

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

Definition at line 70 of file DDNamespace.h.

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

bool cms::DDNamespace::m_pop = false
private

Definition at line 71 of file DDNamespace.h.

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