CMS 3D CMS Logo

Namespaces | Functions
DDCheckMaterials.cc File Reference
#include <ostream>
#include <string>
#include <utility>
#include <vector>
#include "DetectorDescription/Core/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, std::string > &result, int rlevel=0)
 
bool DDCheckMaterials (std::ostream &os, std::vector< std::pair< std::string, std::string >> *res)
 Checks all registered materials and sends a report /p os. More...
 

Function Documentation

◆ DDCheckMaterial()

bool DDCheckMaterial ( DDMaterial mip,
std::pair< std::string, std::string > &  result,
int  rlevel = 0 
)

Definition at line 16 of file DDCheckMaterials.cc.

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

Referenced by DDCheckMaterials().

16  {
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 }
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:45
bool DDCheckMaterial(DDMaterial &mip, std::pair< std::string, std::string > &result, int rlevel=0)
Definition: Electron.h:6
const std::string & name() const
Returns the name.
Definition: DDName.cc:41
double density() const
returns the density
Definition: DDMaterial.cc:80
double z() const
retruns the atomic number
Definition: DDMaterial.cc:78
const N & name() const
Definition: DDBase.h:59
FractionV::value_type constituent(int i) const
returns the i-th compound material and its fraction-mass
Definition: DDMaterial.cc:74
const N & ddname() const
Definition: DDBase.h:61
int noOfConstituents() const
returns the number of compound materials or 0 for elementary materials
Definition: DDMaterial.cc:72
const std::string fullname() const
Definition: DDName.h:43
double a() const
returns the atomic mass
Definition: DDMaterial.cc:76
def_type isDefined() const
Definition: DDBase.h:90
const std::string & ns() const
Returns the namespace.
Definition: DDName.cc:52

◆ 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 at line 90 of file DDCheckMaterials.cc.

References DDCheckMaterial(), relativeConstraints::error, nano_mu_digi_cff::errors, mps_fire::i, instance, dqmiolumiharvest::j, HLTObjectMonitor_cfi::mr, l1tGTMenu_BTagSeeds_cff::os, mps_fire::result, alignCSCRings::s, and AlCaHLTBitMon_QueryRunRegistry::string.

90  {
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 }
Definition: DDBase.h:10
static PFTauRenderPlugin instance
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:45
bool DDCheckMaterial(DDMaterial &mip, std::pair< std::string, std::string > &result, int rlevel=0)
Definition: Electron.h:6
Definition: errors.py:1