CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/DetectorDescription/Core/src/DDCheckMaterials.cc

Go to the documentation of this file.
00001 #include <vector>
00002 #include "DetectorDescription/Core/interface/DDMaterial.h"
00003 #include "DetectorDescription/Core/src/Material.h"
00004 
00005 // internal usage
00006 bool DDCheckMaterial(DDMaterial& mip, std::pair<std::string,DDName> & result)
00007 {
00008    std::string no_composites = " NO-COMPOSITES ";
00009    std::string no_density    = " NO-DENSITY ";
00010    std::string costit_nok    = " CONSTITUENT NOK ";
00011    std::string no_z = " NO-Z ";
00012    std::string no_a = " NO-A "; 
00013    static int rlevel = 0;
00014       
00015       std::string curr_err = "";
00016       bool err = false;
00017       
00018       if (mip.isDefined().first == 0) {
00019         err=true;
00020         curr_err += "material not declared; unknown material!";
00021         //edm::LogError("DDCheckMaterials") << "material not declared!" << std::endl; //exit(1);
00022         result.first = curr_err;
00023         return err;
00024       }
00025       
00026       if (mip.isDefined().second == 0) {
00027         err=true;
00028         curr_err += "material name=" + mip.name().ns() + ":" + mip.name().name() 
00029                     + " is declared but not defined";
00030         result.first = curr_err;
00031         return err;         
00032       }
00033 /*
00034      else {
00035         edm::LogInfo << " material name=" << flush 
00036              << *mip.isDefined().first << std::endl;
00037       }
00038 */      
00039       DDMaterial & mp = mip;
00040       result.second=mp.ddname();         
00041       
00042       if (!mp.density()) {
00043         err=true;
00044         curr_err += no_density;
00045       }
00046       
00047       if ( ( !mp.z() || !mp.a() ) && !mp.noOfConstituents() ) {
00048         err=true;
00049         curr_err += no_z;
00050         curr_err += "or";
00051         curr_err += no_a;
00052       } 
00053       
00054       if ( ( !mp.z() && !mp.a() ) && !mp.noOfConstituents() ) {
00055         err=true;
00056         curr_err += no_composites;
00057       }
00058       
00059       if ( !mp.z() && !mp.a() && !mp.density() && !mp.noOfConstituents() ){
00060         err=true;
00061         curr_err = " NOT-DEFINED ";
00062       }         
00063       
00064       if (err) {
00065         result.first=curr_err;
00066       } 
00067       
00068       // recursive checking of constituents
00069       // the composite material is not ok if only one constituent is not ok
00070       int loop = mp.noOfConstituents() - 1; 
00071       
00072       for (; loop>=0; --loop) { 
00073         std::pair<std::string,DDName> res("","");
00074         DDMaterial mat(mp.ddname()); // bit slow but comfortable ...
00075         DDMaterial mimpl = mat.constituent(loop).first;
00076         ++rlevel; // recursion level
00077         bool c_err = DDCheckMaterial(mimpl,res);
00078         if (c_err) {
00079           err = err | c_err;
00080           curr_err = curr_err + std::string(" constituents have errors:\n") + std::string(4*rlevel,' ') 
00081                    //+ res.second.ns() + std::string(":") + res.second.name() 
00082                    + std::string(" ") + res.first;
00083           result.first=curr_err;           
00084         }
00085         --rlevel;
00086       }
00087       
00088       return err;
00089 }
00090 
00091 
00093 bool DDCheckMaterials(std::ostream & os, std::vector<std::pair<std::string,DDName> > * res)
00094 {
00095    bool result = false;
00096    std::vector<std::pair<std::string,DDName> > errors;
00097    
00098    
00099    //DDMaterialReg::instance_t& mr = DDMaterialReg::instance();
00100    //DDMaterialReg::instance_t::iterator i = mr.begin();
00101    typedef DDBase<DDName,DDI::Material*>::StoreT RegT;
00102    RegT::value_type& mr = RegT::instance();
00103    RegT::value_type::iterator i = mr.begin();
00104    //edm::LogError("DDCheckMaterials") << " material checking, registry access, exiting! " << std::endl; exit(1);
00105    for(; i != mr.end(); ++i) {
00106         std::pair<std::string,DDName> error("","");
00107         DDMaterial tmat(i->first); 
00108         //exit(1);
00109         if (DDCheckMaterial(tmat,error)) {
00110            errors.push_back(error);
00111         }             
00112    }
00113 
00114    std::string s(" ");   
00115    os << "[DDCore:Report] Materials " << std::endl;
00116    os << s << mr.size() << " Materials declared" << std::endl;
00117    os << s << "detected errors:" << errors.size() << std::endl;
00118    std::vector<std::pair<std::string,DDName> >::iterator j = errors.begin();
00119    for (;j!=errors.end();++j) {
00120      os << std::endl << s << j->second << "  " << j->first << std::endl;
00121      result = true;
00122    }
00123    if(res) *res = errors;
00124    return result;
00125 }