CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
DDCheckMaterials.cc File Reference
#include <vector>
#include "DetectorDescription/Core/interface/DDMaterial.h"
#include "DetectorDescription/Core/src/Material.h"

Go to the source code of this file.

Functions

bool DDCheckMaterial (DDMaterial &mip, std::pair< std::string, DDName > &result)
 
bool DDCheckMaterials (std::ostream &os, std::vector< std::pair< std::string, DDName > > *res)
 Checks all registered materials and sends a report /p os. More...
 

Function Documentation

bool DDCheckMaterial ( DDMaterial mip,
std::pair< std::string, DDName > &  result 
)

Definition at line 6 of file DDCheckMaterials.cc.

References DDMaterial::a(), DDMaterial::constituent(), DDBase< N, C >::ddname(), DDMaterial::density(), DDBase< N, C >::isDefined(), python.cmstools::loop(), DDName::name(), DDBase< N, C >::name(), DDMaterial::noOfConstituents(), DDName::ns(), and DDMaterial::z().

Referenced by DDCheckMaterials().

7 {
8  std::string no_composites = " NO-COMPOSITES ";
9  std::string no_density = " NO-DENSITY ";
10  std::string costit_nok = " CONSTITUENT NOK ";
11  std::string no_z = " NO-Z ";
12  std::string no_a = " NO-A ";
13  static int rlevel = 0;
14 
15  std::string curr_err = "";
16  bool err = false;
17 
18  if (mip.isDefined().first == 0) {
19  err=true;
20  curr_err += "material not declared; unknown material!";
21  //edm::LogError("DDCheckMaterials") << "material not declared!" << std::endl; //exit(1);
22  result.first = curr_err;
23  return err;
24  }
25 
26  if (mip.isDefined().second == 0) {
27  err=true;
28  curr_err += "material name=" + mip.name().ns() + ":" + mip.name().name()
29  + " is declared but not defined";
30  result.first = curr_err;
31  return err;
32  }
33 /*
34  else {
35  edm::LogInfo << " material name=" << flush
36  << *mip.isDefined().first << std::endl;
37  }
38 */
39  DDMaterial & mp = mip;
40  result.second=mp.ddname();
41 
42  if (!mp.density()) {
43  err=true;
44  curr_err += no_density;
45  }
46 
47  if ( ( !mp.z() || !mp.a() ) && !mp.noOfConstituents() ) {
48  err=true;
49  curr_err += no_z;
50  curr_err += "or";
51  curr_err += no_a;
52  }
53 
54  if ( ( !mp.z() && !mp.a() ) && !mp.noOfConstituents() ) {
55  err=true;
56  curr_err += no_composites;
57  }
58 
59  if ( !mp.z() && !mp.a() && !mp.density() && !mp.noOfConstituents() ){
60  err=true;
61  curr_err = " NOT-DEFINED ";
62  }
63 
64  if (err) {
65  result.first=curr_err;
66  }
67 
68  // recursive checking of constituents
69  // the composite material is not ok if only one constituent is not ok
70  int loop = mp.noOfConstituents() - 1;
71 
72  for (; loop>=0; --loop) {
73  std::pair<std::string,DDName> res("","");
74  DDMaterial mat(mp.ddname()); // bit slow but comfortable ...
75  DDMaterial mimpl = mat.constituent(loop).first;
76  ++rlevel; // recursion level
77  bool c_err = DDCheckMaterial(mimpl,res);
78  if (c_err) {
79  err = err | c_err;
80  curr_err = curr_err + std::string(" constituents have errors:\n") + std::string(4*rlevel,' ')
81  //+ res.second.ns() + std::string(":") + res.second.name()
82  + std::string(" ") + res.first;
83  result.first=curr_err;
84  }
85  --rlevel;
86  }
87 
88  return err;
89 }
double a() const
returns the atomic mass
Definition: DDMaterial.cc:97
def_type isDefined() const
Definition: DDBase.h:115
const N & name() const
Definition: DDBase.h:82
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:41
bool DDCheckMaterial(DDMaterial &mip, std::pair< std::string, DDName > &result)
const std::string & ns() const
Returns the namespace.
Definition: DDName.cc:101
double z() const
retruns the atomic number
Definition: DDMaterial.cc:103
tuple result
Definition: query.py:137
FractionV::value_type constituent(int i) const
returns the i-th compound material and its fraction-mass
Definition: DDMaterial.cc:89
double density() const
returns the density
Definition: DDMaterial.cc:109
int noOfConstituents() const
returns the number of compound materials or 0 for elementary materials
Definition: DDMaterial.cc:83
const std::string & name() const
Returns the name.
Definition: DDName.cc:87
const N & ddname() const
Definition: DDBase.h:84
bool DDCheckMaterials ( std::ostream &  os,
std::vector< std::pair< std::string, DDName > > *  res 
)

Checks all registered materials and sends a report /p os.

Definition at line 93 of file DDCheckMaterials.cc.

References DDCheckMaterial(), error, benchmark_cfg::errors, i, instance, j, query::result, and alignCSCRings::s.

Referenced by DDErrorDetection::ma().

94 {
95  bool result = false;
96  std::vector<std::pair<std::string,DDName> > errors;
97 
98 
99  //DDMaterialReg::instance_t& mr = DDMaterialReg::instance();
100  //DDMaterialReg::instance_t::iterator i = mr.begin();
103  RegT::value_type::iterator i = mr.begin();
104  //edm::LogError("DDCheckMaterials") << " material checking, registry access, exiting! " << std::endl; exit(1);
105  for(; i != mr.end(); ++i) {
106  std::pair<std::string,DDName> error("","");
107  DDMaterial tmat(i->first);
108  //exit(1);
109  if (DDCheckMaterial(tmat,error)) {
110  errors.push_back(error);
111  }
112  }
113 
114  std::string s(" ");
115  os << "[DDCore:Report] Materials " << std::endl;
116  os << s << mr.size() << " Materials declared" << std::endl;
117  os << s << "detected errors:" << errors.size() << std::endl;
118  std::vector<std::pair<std::string,DDName> >::iterator j = errors.begin();
119  for (;j!=errors.end();++j) {
120  os << std::endl << s << j->second << " " << j->first << std::endl;
121  result = true;
122  }
123  if(res) *res = errors;
124  return result;
125 }
Definition: DDBase.h:14
int i
Definition: DBlmapReader.cc:9
static PFTauRenderPlugin instance
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:41
bool DDCheckMaterial(DDMaterial &mip, std::pair< std::string, DDName > &result)
tuple result
Definition: query.py:137
int j
Definition: DBlmapReader.cc:9
Container::value_type value_type