CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDCheckMaterials.cc
Go to the documentation of this file.
1 //
2 #include <vector>
4 
5 // Message logger.
6 
7 // internal usage
8 bool DDCheckMaterial(DDMaterial& mip, std::pair<std::string,DDName> & result)
9 {
10  std::string no_composites = " NO-COMPOSITES ";
11  std::string no_density = " NO-DENSITY ";
12  std::string costit_nok = " CONSTITUENT NOK ";
13  std::string no_z = " NO-Z ";
14  std::string no_a = " NO-A ";
15  static int rlevel = 0;
16 
17  std::string curr_err = "";
18  bool err = false;
19 
20  if (mip.isDefined().first == 0) {
21  err=true;
22  curr_err += "material not declared; unknown material!";
23  //edm::LogError("DDCheckMaterials") << "material not declared!" << std::endl; //exit(1);
24  result.first = curr_err;
25  return err;
26  }
27 
28  if (mip.isDefined().second == 0) {
29  err=true;
30  curr_err += "material name=" + mip.name().ns() + ":" + mip.name().name()
31  + " is declared but not defined";
32  result.first = curr_err;
33  return err;
34  }
35 /*
36  else {
37  edm::LogInfo << " material name=" << flush
38  << *mip.isDefined().first << std::endl;
39  }
40 */
41  DDMaterial & mp = mip;
42  result.second=mp.ddname();
43 
44  if (!mp.density()) {
45  err=true;
46  curr_err += no_density;
47  }
48 
49  if ( ( !mp.z() || !mp.a() ) && !mp.noOfConstituents() ) {
50  err=true;
51  curr_err += no_z;
52  curr_err += "or";
53  curr_err += no_a;
54  }
55 
56  if ( ( !mp.z() && !mp.a() ) && !mp.noOfConstituents() ) {
57  err=true;
58  curr_err += no_composites;
59  }
60 
61  if ( !mp.z() && !mp.a() && !mp.density() && !mp.noOfConstituents() ){
62  err=true;
63  curr_err = " NOT-DEFINED ";
64  }
65 
66  if (err) {
67  result.first=curr_err;
68  }
69 
70  // recursive checking of constituents
71  // the composite material is not ok if only one constituent is not ok
72  int loop = mp.noOfConstituents() - 1;
73 
74  for (; loop>=0; --loop) {
75  std::pair<std::string,DDName> res("","");
76  DDMaterial mat(mp.ddname()); // bit slow but comfortable ...
77  DDMaterial mimpl = mat.constituent(loop).first;
78  ++rlevel; // recursion level
79  bool c_err = DDCheckMaterial(mimpl,res);
80  if (c_err) {
81  err = err | c_err;
82  curr_err = curr_err + std::string(" constituents have errors:\n") + std::string(4*rlevel,' ')
83  //+ res.second.ns() + std::string(":") + res.second.name()
84  + std::string(" ") + res.first;
85  result.first=curr_err;
86  }
87  --rlevel;
88  }
89 
90  return err;
91 }
92 
93 
95 bool DDCheckMaterials(std::ostream & os, std::vector<std::pair<std::string,DDName> > * res)
96 {
97  bool result = false;
98  std::vector<std::pair<std::string,DDName> > errors;
99 
100 
101  //DDMaterialReg::instance_t& mr = DDMaterialReg::instance();
102  //DDMaterialReg::instance_t::iterator i = mr.begin();
104  RegT::value_type& mr = RegT::instance();
105  RegT::value_type::iterator i = mr.begin();
106  //edm::LogError("DDCheckMaterials") << " material checking, registry access, exiting! " << std::endl; exit(1);
107  for(; i != mr.end(); ++i) {
108  std::pair<std::string,DDName> error("","");
109  DDMaterial tmat(i->first);
110  //exit(1);
111  if (DDCheckMaterial(tmat,error)) {
112  errors.push_back(error);
113  }
114  }
115 
116  std::string s(" ");
117  os << "[DDCore:Report] Materials " << std::endl;
118  os << s << mr.size() << " Materials declared" << std::endl;
119  os << s << "detected errors:" << errors.size() << std::endl;
120  std::vector<std::pair<std::string,DDName> >::iterator j = errors.begin();
121  for (;j!=errors.end();++j) {
122  os << std::endl << s << j->second << " " << j->first << std::endl;
123  result = true;
124  }
125  if(res) *res = errors;
126  return result;
127 }
Definition: DDBase.h:18
double a() const
returns the atomic mass
Definition: DDMaterial.cc:103
int i
Definition: DBlmapReader.cc:9
def_type isDefined() const
Definition: DDBase.h:121
const N & name() const
Definition: DDBase.h:88
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:45
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:109
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:95
int j
Definition: DBlmapReader.cc:9
Container::value_type value_type
double density() const
returns the density
Definition: DDMaterial.cc:115
int noOfConstituents() const
returns the number of compound materials or 0 for elementary materials
Definition: DDMaterial.cc:89
string s
Definition: asciidump.py:422
bool DDCheckMaterials(std::ostream &, std::vector< std::pair< std::string, DDName > > *=0)
Checks all registered materials and sends a report /p os.
const std::string & name() const
Returns the name.
Definition: DDName.cc:87
const N & ddname() const
Definition: DDBase.h:90