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