CMS 3D CMS Logo

Namespaces | Functions
DDCheckMaterials.cc File Reference
#include <ostream>
#include <string>
#include <utility>
#include <vector>
#include "DetectorDescription/Base/interface/Store.h"
#include "DetectorDescription/Core/interface/DDBase.h"
#include "DetectorDescription/Core/interface/DDMaterial.h"
#include "DetectorDescription/Core/interface/DDName.h"

Go to the source code of this file.

Namespaces

 DDI
 

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 16 of file DDCheckMaterials.cc.

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

Referenced by DDCheckMaterials().

17 {
18  std::string no_composites = " NO-COMPOSITES ";
19  std::string no_density = " NO-DENSITY ";
20  std::string costit_nok = " CONSTITUENT NOK ";
21  std::string no_z = " NO-Z ";
22  std::string no_a = " NO-A ";
23 
24  std::string curr_err = "";
25  bool err = false;
26 
27  if (mip.isDefined().first == 0) {
28  err=true;
29  curr_err += "material not declared; unknown material!";
30  //edm::LogError("DDCheckMaterials") << "material not declared!" << std::endl; //exit(1);
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();
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  int loop = mp.noOfConstituents() - 1;
75 
76  for (; loop>=0; --loop) {
77  std::pair<std::string,DDName> res("","");
78  DDMaterial mat(mp.ddname()); // bit slow but comfortable ...
79  DDMaterial mimpl = mat.constituent(loop).first;
80  ++rlevel; // recursion level
81  bool c_err = DDCheckMaterial(mimpl,res, rlevel);
82  if (c_err) {
83  err = err | c_err;
84  curr_err = curr_err + std::string(" constituents have errors:\n") + std::string(4*rlevel,' ')
85  + std::string(" ") + res.first;
86  result.first=curr_err;
87  }
88  --rlevel;
89  }
90 
91  return err;
92 }
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:104
Definition: Electron.h:4
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:91
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:85
const std::string & name() const
Returns the name.
Definition: DDName.cc:90
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 96 of file DDCheckMaterials.cc.

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

Referenced by CompareDDCompactViews::beginRun(), and DDErrorDetection::ma().

97 {
98  bool result = false;
99  std::vector<std::pair<std::string,DDName> > errors;
100 
102 
103  for( const auto& i : mr ) {
104  std::pair<std::string,DDName> error("","");
105  DDMaterial tmat(i.first);
106 
107  if (DDCheckMaterial(tmat,error)) {
108  errors.push_back(error);
109  }
110  }
111 
112  std::string s(" ");
113  os << "[DDCore:Report] Materials " << std::endl;
114  os << s << mr.size() << " Materials declared" << std::endl;
115  os << s << "detected errors:" << errors.size() << std::endl;
116  for( auto j : errors ) {
117  os << std::endl << s << j.second << " " << j.first << std::endl;
118  result = true;
119  }
120  if(res) *res = errors;
121  return result;
122 }
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:41
Definition: Electron.h:4
static value_type & instance()
bool DDCheckMaterial(DDMaterial &mip, std::pair< std::string, DDName > &result, int rlevel=0)