CMS 3D CMS Logo

DDCheckMaterials.cc
Go to the documentation of this file.
1 #include <ostream>
2 #include <string>
3 #include <utility>
4 #include <vector>
5 
10 
11 namespace DDI {
12  class Material;
13 }
14 
15 // internal usage
16 bool
17 DDCheckMaterial( DDMaterial& mip, std::pair< std::string, std::string > & result, int rlevel = 0 )
18 {
19  std::string no_composites = " NO-COMPOSITES ";
20  std::string no_density = " NO-DENSITY ";
21  std::string costit_nok = " CONSTITUENT NOK ";
22  std::string no_z = " NO-Z ";
23  std::string no_a = " NO-A ";
24 
25  std::string curr_err = "";
26  bool err = false;
27 
28  if (mip.isDefined().first == nullptr) {
29  err=true;
30  curr_err += "material not declared; unknown material!";
31  result.first = curr_err;
32  return err;
33  }
34 
35  if (mip.isDefined().second == 0) {
36  err=true;
37  curr_err += "material name=" + mip.name().ns() + ":" + mip.name().name()
38  + " is declared but not defined";
39  result.first = curr_err;
40  return err;
41  }
42 
43  DDMaterial & mp = mip;
44  result.second=mp.ddname().fullname();
45 
46  if (!mp.density()) {
47  err=true;
48  curr_err += no_density;
49  }
50 
51  if ( ( !mp.z() || !mp.a() ) && !mp.noOfConstituents() ) {
52  err=true;
53  curr_err += no_z;
54  curr_err += "or";
55  curr_err += no_a;
56  }
57 
58  if ( ( !mp.z() && !mp.a() ) && !mp.noOfConstituents() ) {
59  err=true;
60  curr_err += no_composites;
61  }
62 
63  if ( !mp.z() && !mp.a() && !mp.density() && !mp.noOfConstituents() ){
64  err=true;
65  curr_err = " NOT-DEFINED ";
66  }
67 
68  if (err) {
69  result.first=curr_err;
70  }
71 
72  // recursive checking of constituents
73  // the composite material is not ok if only one constituent is not ok
74  for (int loop = mp.noOfConstituents() - 1; loop>=0; --loop) {
75  std::pair< std::string, std::string > 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, rlevel);
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  + std::string(" ") + res.first;
84  result.first=curr_err;
85  }
86  --rlevel;
87  }
88 
89  return err;
90 }
91 
93 bool
94 DDCheckMaterials( std::ostream & os, std::vector< std::pair< std::string, std::string >> * res )
95 {
96  bool result = false;
97  std::vector< std::pair< std::string, std::string > > errors;
98 
100 
101  for( const auto& i : mr ) {
102  std::pair<std::string, std::string> error("","");
103  DDMaterial tmat(i.first);
104 
105  if (DDCheckMaterial(tmat,error)) {
106  errors.emplace_back(error);
107  }
108  }
109 
110  std::string s(" ");
111  os << "[DDCore:Report] Materials " << std::endl;
112  os << s << mr.size() << " Materials declared" << std::endl;
113  os << s << "detected errors:" << errors.size() << std::endl;
114  for( auto j : errors ) {
115  os << std::endl << s << j.second << " " << j.first << std::endl;
116  result = true;
117  }
118  if(res) *res = errors;
119  return result;
120 }
Definition: DDBase.h:10
double a() const
returns the atomic mass
Definition: DDMaterial.cc:93
def_type isDefined() const
Definition: DDBase.h:107
const N & name() const
Definition: DDBase.h:74
static PFTauRenderPlugin instance
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:43
const std::string & ns() const
Returns the namespace.
Definition: DDName.cc:67
bool DDCheckMaterial(DDMaterial &mip, std::pair< std::string, std::string > &result, int rlevel=0)
Definition: Electron.h:6
double z() const
retruns the atomic number
Definition: DDMaterial.cc:99
const std::string fullname() const
Definition: DDName.h:43
FractionV::value_type constituent(int i) const
returns the i-th compound material and its fraction-mass
Definition: DDMaterial.cc:87
bool DDCheckMaterials(std::ostream &os, std::vector< std::pair< std::string, std::string >> *res)
Checks all registered materials and sends a report /p os.
double density() const
returns the density
Definition: DDMaterial.cc:104
int noOfConstituents() const
returns the number of compound materials or 0 for elementary materials
Definition: DDMaterial.cc:82
const std::string & name() const
Returns the name.
Definition: DDName.cc:53
const N & ddname() const
Definition: DDBase.h:76