Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <memory>
00010
00011
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
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
00047 };
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 MaterialForOnline::MaterialForOnline(const edm::ParameterSet& iConfig)
00061 {
00062
00063
00064 }
00065
00066
00067 MaterialForOnline::~MaterialForOnline()
00068 {
00069
00070
00071
00072
00073 }
00074
00075
00076
00077
00078
00079
00080
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
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
00110
00111 DDMaterial::iterator<DDMaterial> mit(DDMaterial::begin()),
00112 med(DDMaterial::end());
00113
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){
00121 elementaryMaterialOS<<material.name()<<","<<material.z()
00122 <<","<<material.a()/g*mole
00123 << std::endl;
00124 }
00125 else{
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
00145 void
00146 MaterialForOnline::endJob() {
00147 }
00148
00149
00150 DEFINE_FWK_MODULE(MaterialForOnline);