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(), cmsHarvester::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  DDMaterial & mp = mip;
34  result.second=mp.ddname();
35 
36  if (!mp.density()) {
37  err=true;
38  curr_err += no_density;
39  }
40 
41  if ( ( !mp.z() || !mp.a() ) && !mp.noOfConstituents() ) {
42  err=true;
43  curr_err += no_z;
44  curr_err += "or";
45  curr_err += no_a;
46  }
47 
48  if ( ( !mp.z() && !mp.a() ) && !mp.noOfConstituents() ) {
49  err=true;
50  curr_err += no_composites;
51  }
52 
53  if ( !mp.z() && !mp.a() && !mp.density() && !mp.noOfConstituents() ){
54  err=true;
55  curr_err = " NOT-DEFINED ";
56  }
57 
58  if (err) {
59  result.first=curr_err;
60  }
61 
62  // recursive checking of constituents
63  // the composite material is not ok if only one constituent is not ok
64  int loop = mp.noOfConstituents() - 1;
65 
66  for (; loop>=0; --loop) {
67  std::pair<std::string,DDName> res("","");
68  DDMaterial mat(mp.ddname()); // bit slow but comfortable ...
69  DDMaterial mimpl = mat.constituent(loop).first;
70  ++rlevel; // recursion level
71  bool c_err = DDCheckMaterial(mimpl,res, rlevel);
72  if (c_err) {
73  err = err | c_err;
74  curr_err = curr_err + std::string(" constituents have errors:\n") + std::string(4*rlevel,' ')
75  + std::string(" ") + res.first;
76  result.first=curr_err;
77  }
78  --rlevel;
79  }
80 
81  return err;
82 }
double a() const
returns the atomic mass
Definition: DDMaterial.cc:97
def_type isDefined() const
Definition: DDBase.h:110
const N & name() const
Definition: DDBase.h:78
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
int loop
CMSSW
tuple result
Definition: mps_fire.py:95
double z() const
retruns the atomic number
Definition: DDMaterial.cc:103
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:80
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 86 of file DDCheckMaterials.cc.

References DDCheckMaterial(), relativeConstraints::error, benchmark_cfg::errors, i, DDI::Singleton< I >::instance(), j, mps_fire::result, alignCSCRings::s, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by DDErrorDetection::ma().

87 {
88  bool result = false;
89  std::vector<std::pair<std::string,DDName> > errors;
90 
92 
93  for( const auto& i : mr ) {
94  std::pair<std::string,DDName> error("","");
95  DDMaterial tmat(i.first);
96 
97  if (DDCheckMaterial(tmat,error)) {
98  errors.push_back(error);
99  }
100  }
101 
102  std::string s(" ");
103  os << "[DDCore:Report] Materials " << std::endl;
104  os << s << mr.size() << " Materials declared" << std::endl;
105  os << s << "detected errors:" << errors.size() << std::endl;
106  for( auto j : errors ) {
107  os << std::endl << s << j.second << " " << j.first << std::endl;
108  result = true;
109  }
110  if(res) *res = errors;
111  return result;
112 }
int i
Definition: DBlmapReader.cc:9
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:41
tuple result
Definition: mps_fire.py:95
static value_type & instance()
int j
Definition: DBlmapReader.cc:9
bool DDCheckMaterial(DDMaterial &mip, std::pair< std::string, DDName > &result, int rlevel=0)