CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/DetectorDescription/OnlineDBLoader/bin/stubs/MaterialForOnline.cc

Go to the documentation of this file.
00001 // Original Author:  Jie Chen
00002 //         Created:  Thu Apr  5 10:36:22 CDT 2007
00003 // $Id: MaterialForOnline.cc,v 1.8 2010/03/25 21:55:36 case Exp $
00004 //
00005 //
00006 
00007 
00008 // system include files
00009 #include <memory>
00010 
00011 // user include files
00012 #include "FWCore/Framework/interface/EDAnalyzer.h"
00013 #include "FWCore/Framework/interface/EventSetup.h"
00014 #include "FWCore/Framework/interface/ESTransientHandle.h"
00015 #include <FWCore/Framework/interface/ESHandle.h>
00016 #include "FWCore/Framework/interface/MakerMacros.h"
00017 
00018 #include <DetectorDescription/Core/interface/DDCompactView.h>
00019 #include "DetectorDescription/Core/interface/DDName.h"
00020 #include "DetectorDescription/Core/interface/DDMaterial.h"
00021 #include <Geometry/Records/interface/IdealGeometryRecord.h>
00022 
00023 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00024 
00025 #include <iostream>
00026 #include <istream>
00027 #include <fstream>
00028 #include <string>
00029 
00030 
00031 
00032 //
00033 // class decleration
00034 //
00035 
00036 class MaterialForOnline : public edm::EDAnalyzer {
00037    public:
00038       explicit MaterialForOnline(const edm::ParameterSet&);
00039       ~MaterialForOnline();
00040       virtual void beginRun(const edm::Run&, const edm::EventSetup&) ;
00041       virtual void analyze(const edm::Event&, const edm::EventSetup&);
00042       virtual void endJob() ;
00043 
00044    private:
00045 
00046       // ----------member data ---------------------------
00047 };
00048 
00049 //
00050 // constants, enums and typedefs
00051 //
00052 
00053 //
00054 // static data member definitions
00055 //
00056 
00057 //
00058 // constructors and destructor
00059 //
00060 MaterialForOnline::MaterialForOnline(const edm::ParameterSet& iConfig)
00061 {
00062    //now do what ever initialization is needed
00063 
00064 }
00065 
00066 
00067 MaterialForOnline::~MaterialForOnline()
00068 {
00069  
00070    // do anything here that needs to be done at desctruction time
00071    // (e.g. close files, deallocate resources etc.)
00072 
00073 }
00074 
00075 
00076 //
00077 // member functions
00078 //
00079 
00080 // ------------ method called to for each event  ------------
00081 void
00082 MaterialForOnline::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00083 {
00084   std::cout << "analyze does nothing" << std::endl;
00085 
00086 }
00087 
00088 
00089 // ------------ method called once each job just before starting event loop  ------------
00090 void 
00091 MaterialForOnline::beginRun(const edm::Run&, const edm::EventSetup& iSetup)
00092 {
00093   std::string materialFileName("MATERIALS.dat");
00094   std::string elementaryMaterialFileName("ELEMENTARYMATERIALS.dat");
00095   std::string compositeMaterialFileName("COMPOSITEMATERIALS.dat");
00096   std::string materialFractionFileName("MATERIALFRACTIONS.dat");
00097 
00098   std::ofstream materialOS(materialFileName.c_str());
00099   std::ofstream elementaryMaterialOS(elementaryMaterialFileName.c_str());
00100   std::ofstream compositeMaterialOS(compositeMaterialFileName.c_str());
00101   std::ofstream materialFractionOS(materialFractionFileName.c_str());
00102 
00103 
00104   std::cout << "MaterialForOnline Analyzer..." << std::endl;
00105   edm::ESTransientHandle<DDCompactView> pDD;
00106 
00107   iSetup.get<IdealGeometryRecord>().get( "", pDD );
00108 
00109   //  const DDCompactView & cpv = *pDD;
00110   //DDCompactView::graph_type gra = cpv.graph();
00111   DDMaterial::iterator<DDMaterial> mit(DDMaterial::begin()), 
00112     med(DDMaterial::end());
00113   // PMaterial* pm;
00114   for (; mit != med; ++mit) {
00115     if (! mit->isDefined().second) continue;
00116     const DDMaterial& material = *mit;
00117     materialOS<<material.name()<<","<<material.density()/g*cm3
00118               << std::endl;
00119     
00120     if(material.noOfConstituents()==0){//0 for elementary materials 
00121      elementaryMaterialOS<<material.name()<<","<<material.z()
00122                          <<","<<material.a()/g*mole
00123                          << std::endl;
00124     }
00125     else{//compound materials.  
00126       compositeMaterialOS<<material.name()
00127                          << std::endl;
00128       for (int i=0; i<material.noOfConstituents(); ++i) {
00129         DDMaterial::FractionV::value_type f = material.constituent(i);
00130         materialFractionOS<<material.name()<<","<<f.first.name()
00131                           <<","<< f.second
00132                           << std::endl;
00133       }                
00134 
00135     }
00136 
00137   }
00138   elementaryMaterialOS.close();
00139   compositeMaterialOS.close();
00140   materialFractionOS.close();
00141   materialOS.close();
00142 }
00143 
00144 // ------------ method called once each job just after ending the event loop  ------------
00145 void 
00146 MaterialForOnline::endJob() {
00147 }
00148 
00149 //define this as a plug-in
00150 DEFINE_FWK_MODULE(MaterialForOnline);