CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/DetectorDescription/Core/src/DDMaterial.cc

Go to the documentation of this file.
00001 
00002 #include "DetectorDescription/Base/interface/DDdebug.h"
00003 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00004 #include "DetectorDescription/Core/interface/DDMaterial.h"
00005 #include "DetectorDescription/Core/src/Material.h"
00006 #include "DetectorDescription/Base/interface/DDException.h"
00007 
00008 
00009 using DDI::Material;
00010 
00011 
00012 //DDBase<DDName,Material*>::StoreT::pointer_type 
00013 //  DDBase<DDName,Material*>::StoreT::instance_ = 0;
00014 
00015 
00016 DDMaterial::DDMaterial() : DDBase<DDName,Material*>() { }
00017 
00018 
00027 DDMaterial::DDMaterial(const DDName & name) : DDBase<DDName,Material*>()
00028 { 
00029   prep_ = StoreT::instance().create(name);
00030 }
00031  
00032 
00046 DDMaterial::DDMaterial(const DDName & name, double z, double a, double d)
00047  : DDBase<DDName,Material*>()
00048 { 
00049   prep_ = StoreT::instance().create(name, new Material(z, a, d));
00050 }
00051               
00052 
00065 DDMaterial::DDMaterial(const DDName & name, double density)
00066  : DDBase<DDName,Material*>()
00067 { 
00068   prep_ = StoreT::instance().create(name, new Material(0,0,density));
00069 }
00070 
00071 
00075 int DDMaterial::addMaterial(const DDMaterial & m, double fm)
00076 {  
00077   if (m.ddname() == ddname()) {
00078     std::string s = std::string("DDMaterial::addMaterial(..): name-clash ") 
00079              + std::string("\n        trying to add material ") + m.toString() 
00080              + std::string(" to itself! ");
00081     throw DDException( s );
00082   }  
00083   rep().addMaterial(m,fm);
00084   DCOUT('c', std::string(" -> ADDED MATERIAL=") + m.toString() );
00085   return rep().noOfConstituents();
00086 }
00087 
00088 
00089 int DDMaterial::noOfConstituents() const
00090 {
00091    return rep().noOfConstituents();
00092 }
00093 
00094 
00095 DDMaterial::FractionV::value_type DDMaterial::constituent(int i) const 
00096 { 
00097   //const DDMaterialImpl::Fraction & f(rep().constituent(i));
00098   //return std::make_pair(DDMaterial(f.first,true), f.second);  
00099   return rep().constituent(i);
00100 }
00101 
00102 
00103 double DDMaterial::a() const
00104 {
00105   return rep().a(); 
00106 }
00107 
00108 
00109 double DDMaterial::z() const
00110 {
00111   return rep().z(); 
00112 }
00113 
00114 
00115 double DDMaterial::density() const
00116 {
00117   return rep().density(); 
00118 }
00119 
00120 // void DDMaterial::clear()
00121 // {
00122 //   StoreT::instance().clear();
00123 // }
00124 // private ctor for internal use
00125 //DDMaterial::DDMaterial(DDRedirect<DDMaterialImpl>* p, bool dummy)
00126 // : DDRegistered<DDMaterialImpl>(p,true)
00127 //{ 
00128 //  DCOUT_V('C',"DC: (redir) init=" << rep_ ); 
00129 //}   
00130 
00131 
00132 std::ostream & operator<<(std::ostream & os, const DDMaterial & mat)
00133 { 
00134   static int level=0;
00135   ++level; 
00136   if (mat) {
00137     os << '[' << mat.name() <<']' << " z=" << mat.z() 
00138                      << " a=" << mat.a()/g*mole << "*g/mole" 
00139                      << " d=" << mat.density()/g*cm3 << "*g/cm3";
00140     std::string s(2*level,' ');              
00141     for (int i=0; i<mat.noOfConstituents(); ++i) {
00142        DDMaterial::FractionV::value_type f = mat.constituent(i);
00143        os << std::endl << s << i+1 << " : fm=" << f.second 
00144                   << " : " << f.first;
00145     }                
00146     //--level;
00147   } 
00148   else
00149     os << "* material not declared * ";  
00150   --level;   
00151   return os;
00152 }
00153