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 14 of file DDNamespace.cc.

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

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

Definition at line 44 of file DDNamespace.cc.

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

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

Definition at line 66 of file DDNamespace.cc.

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

67  : context( ctx )
68 {
69  m_name = context->namespaces.back();
70 }
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 72 of file DDNamespace.cc.

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

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

Definition at line 78 of file DDNamespace.cc.

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

78  {
79  if( m_pop ) {
80  context->namespaces.pop_back();
81  dd4hep::printout( context->debug_namespaces ? dd4hep::ALWAYS : dd4hep::DEBUG,
82  "MyDDCMS","+++ Current namespace is now: %s", context->ns().c_str());
83  }
84 }
#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 135 of file DDNamespace.cc.

References addConstantNS(), and prepend().

Referenced by attr().

136 {
137  addConstantNS( prepend( nam ), val, typ );
138 }
void addConstantNS(const std::string &name, const std::string &value, const std::string &type) const
Definition: DDNamespace.cc:141
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:87
void DDNamespace::addConstantNS ( const std::string &  name,
const std::string &  value,
const std::string &  type 
) const

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

142 {
143  const string& v = val;
144  const string& n = nam;
145  dd4hep::printout( context->debug_constants ? dd4hep::ALWAYS : dd4hep::DEBUG,
146  "MyDDCMS","+++ Add constant object: %-40s = %s [type:%s]",
147  n.c_str(), v.c_str(), typ.c_str());
148  dd4hep::_toDictionary( n, v, typ );
149  dd4hep::Constant c( n, v, typ );
150  context->description->addConstant( c );
151 }
#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 171 of file DDNamespace.cc.

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

Referenced by attr().

172 {
173  string n = prepend( name );
174  context->rotations[n] = rot;
175 }
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:87
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 264 of file DDNamespace.cc.

References addSolidNS(), and prepend().

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

265 {
266  return addSolidNS( prepend(nam), sol );
267 }
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
Definition: DDNamespace.cc:254
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:87
dd4hep::Solid DDNamespace::addSolidNS ( const std::string &  name,
dd4hep::Solid  solid 
) const

Definition at line 254 of file DDNamespace.cc.

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

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

255 {
256  dd4hep::printout(context->debug_shapes ? dd4hep::ALWAYS : dd4hep::DEBUG, "MyDDCMS",
257  "+++ Add shape of type %s : %s",sol->IsA()->GetName(), nam.c_str());
258  context->shapes[nam] = sol.setName(nam);
259 
260  return sol;
261 }
#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 154 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().

155 {
156  const vector<double>& v = value;
157  const string& n = name;
158  dd4hep::printout( context->debug_constants ? dd4hep::ALWAYS : dd4hep::DEBUG,
159  "MyDDCMS","+++ Add constant object: %-40s = %s ",
160  n.c_str(), "vector<double>");
161  context->addVector( n, v );
162 }
#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 219 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().

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

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

205 {
206  string n = vol.name();
207  dd4hep::Solid s = vol.solid();
208  dd4hep::Material m = vol.material();
209  vol->SetName(n.c_str());
210  context->volumes[n] = vol;
211  dd4hep::printout(context->debug_volumes ? dd4hep::ALWAYS : dd4hep::DEBUG, "MyDDCMS",
212  "+++ Add volume:%-38s Solid:%-26s[%-16s] Material:%s",
213  vol.name(), s.name(), s.type(), m.name());
214  return vol;
215 }
#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:93
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:93
const std::string & name() const
Definition: DDNamespace.h:65
long double T
dd4hep::Material DDNamespace::material ( const std::string &  name) const

Definition at line 165 of file DDNamespace.cc.

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

Referenced by algorithm(), and attr().

166 {
167  return context->description->material( realName( name ));
168 }
dd4hep::Detector * description
std::string realName(const std::string &) const
Definition: DDNamespace.cc:93
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 113 of file DDNamespace.cc.

References training_settings::idx.

Referenced by algorithm().

114 {
115  size_t idx;
116  if(( idx = nam.find(':')) != string::npos )
117  return nam.substr( 0, idx );
118  else if(( idx=nam.find('_')) != string::npos )
119  return nam.substr( 0, idx );
120  return "";
121 }
string DDNamespace::objName ( const std::string &  )
static

Definition at line 124 of file DDNamespace.cc.

References training_settings::idx.

Referenced by algorithm().

125 {
126  size_t idx;
127  if(( idx = nam.find(':')) != string::npos )
128  return nam.substr( idx + 1 );
129  else if (( idx=nam.find('_')) != string::npos )
130  return nam.substr( idx + 1 );
131  return "";
132 }
DDNamespace& cms::DDNamespace::operator= ( const DDNamespace )
delete
string DDNamespace::prepend ( const std::string &  ) const

Definition at line 87 of file DDNamespace.cc.

References m_name, and gen::n.

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

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

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

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

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

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

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

271 {
272  size_t idx;
273  string n = context->namespaces.back() + nam;
274  auto i = context->shapes.find(n);
275  if ( i != context->shapes.end() )
276  return (*i).second;
277  if ( (idx=nam.find(':')) != string::npos ) {
278  n = realName(nam);
279  n[idx] = NAMESPACE_SEP;
280  i = context->shapes.find(n);
281  if ( i != context->shapes.end() )
282  return (*i).second;
283  }
284  i = context->shapes.find(nam);
285  if ( i != context->shapes.end() ) return (*i).second;
286  throw runtime_error( "Unknown shape identifier:" + nam );
287 }
std::map< std::string, dd4hep::Solid > shapes
#define NAMESPACE_SEP
Definition: DDNamespace.cc:12
std::string realName(const std::string &) const
Definition: DDNamespace.cc:93
std::vector< std::string > namespaces
DDParsingContext * context
Definition: DDNamespace.h:63
dd4hep::Volume DDNamespace::volume ( const std::string &  name,
bool  exc = true 
) const

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

234 {
235  size_t idx;
236  auto i = context->volumes.find(nam);
237  if ( i != context->volumes.end() ) {
238  return (*i).second;
239  }
240  if ( (idx=nam.find(':')) != string::npos ) {
241  string n = nam;
242  n[idx] = NAMESPACE_SEP;
243  i = context->volumes.find(n);
244  if ( i != context->volumes.end() )
245  return (*i).second;
246  }
247  if ( exc ) {
248  throw runtime_error("Unknown volume identifier:"+nam);
249  }
250  return nullptr;
251 }
#define NAMESPACE_SEP
Definition: DDNamespace.cc:12
std::map< std::string, dd4hep::Volume > volumes
DDParsingContext * context
Definition: DDNamespace.h:63

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().