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, int rlevel=0)
 
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,
int  rlevel = 0 
)

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(), AlCaHLTBitMon_QueryRunRegistry::string, 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 
14  std::string curr_err = "";
15  bool err = false;
16 
17  if (mip.isDefined().first == 0) {
18  err=true;
19  curr_err += "material not declared; unknown material!";
20  //edm::LogError("DDCheckMaterials") << "material not declared!" << std::endl; //exit(1);
21  result.first = curr_err;
22  return err;
23  }
24 
25  if (mip.isDefined().second == 0) {
26  err=true;
27  curr_err += "material name=" + mip.name().ns() + ":" + mip.name().name()
28  + " is declared but not defined";
29  result.first = curr_err;
30  return err;
31  }
32 /*
33  else {
34  edm::LogInfo << " material name=" << flush
35  << *mip.isDefined().first << std::endl;
36  }
37 */
38  DDMaterial & mp = mip;
39  result.second=mp.ddname();
40 
41  if (!mp.density()) {
42  err=true;
43  curr_err += no_density;
44  }
45 
46  if ( ( !mp.z() || !mp.a() ) && !mp.noOfConstituents() ) {
47  err=true;
48  curr_err += no_z;
49  curr_err += "or";
50  curr_err += no_a;
51  }
52 
53  if ( ( !mp.z() && !mp.a() ) && !mp.noOfConstituents() ) {
54  err=true;
55  curr_err += no_composites;
56  }
57 
58  if ( !mp.z() && !mp.a() && !mp.density() && !mp.noOfConstituents() ){
59  err=true;
60  curr_err = " NOT-DEFINED ";
61  }
62 
63  if (err) {
64  result.first=curr_err;
65  }
66 
67  // recursive checking of constituents
68  // the composite material is not ok if only one constituent is not ok
69  int loop = mp.noOfConstituents() - 1;
70 
71  for (; loop>=0; --loop) {
72  std::pair<std::string,DDName> res("","");
73  DDMaterial mat(mp.ddname()); // bit slow but comfortable ...
74  DDMaterial mimpl = mat.constituent(loop).first;
75  ++rlevel; // recursion level
76  bool c_err = DDCheckMaterial(mimpl,res, rlevel);
77  if (c_err) {
78  err = err | c_err;
79  curr_err = curr_err + std::string(" constituents have errors:\n") + std::string(4*rlevel,' ')
80  //+ res.second.ns() + std::string(":") + res.second.name()
81  + std::string(" ") + res.first;
82  result.first=curr_err;
83  }
84  --rlevel;
85  }
86 
87  return err;
88 }
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
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
bool DDCheckMaterial(DDMaterial &mip, std::pair< std::string, DDName > &result, int rlevel=0)
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 92 of file DDCheckMaterials.cc.

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

Referenced by DDErrorDetection::ma().

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