| # Gaudi Framework, version v20r3
Generated: 24 Nov 2008

# PartPropSvc.cpp

Go to the documentation of this file.

    00001 //Include files
    00002 #include "GaudiKernel/SvcFactory.h"
    00003 #include "GaudiKernel/ISvcLocator.h"
    00004 #include "GaudiKernel/MsgStream.h"
    00005 #include "GaudiKernel/PathResolver.h"
    00006
    00007 #include "PartPropSvc.h"
    00008
    00009 #include "HepPDT/TableBuilder.hh"
    00010
    00011 #include <iostream>
    00012 #include <cstdlib>
    00013 #include <fstream>
    00014
    00015 // Instantiation of a static factory class used by clients to create
    00016 //  instances of this service
    00017 DECLARE_SERVICE_FACTORY(PartPropSvc)
    00018
    00019 //*************************************************************************//
    00020
    00021 PartPropSvc::PartPropSvc( const std::string& name, ISvcLocator* svc )
    00022   : Service( name, svc ), m_pdt(0) {
    00023
    00024   declareProperty( "InputType", m_inputType="PDG");
    00025   declareProperty( "InputFile", m_pdtFiles);
    00026
    00027   if (m_pdtFiles.empty() ) {
    00028     m_pdtFiles.push_back("PDGTABLE.MeV");
    00029   }
    00030
    00031 }
    00032
    00033 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
    00034
    00035 PartPropSvc::~PartPropSvc() {
    00036   if (m_pdt != 0) {
    00037     delete m_pdt;
    00038     m_pdt = 0;
    00039   }
    00040 }
    00041
    00042 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
    00043
    00044 const InterfaceID& PartPropSvc::type() const {
    00045   return IID_IPartPropSvc;
    00046 }
    00047
    00048 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
    00049
    00050 StatusCode PartPropSvc::initialize() {
    00051
    00052   MsgStream log( msgSvc(), name() );
    00053   std::vector<std::string>::const_iterator itr;
    00054
    00055   StatusCode status = Service::initialize();
    00056
    00057   log << MSG::INFO << "PDT file(s): " << endreq;
    00058   for (itr=m_pdtFiles.begin(); itr!=m_pdtFiles.end(); ++itr) {
    00059     log << MSG::INFO << "    " << *itr << endreq;
    00060   }
    00061   log << MSG::INFO << "Type:     " << m_inputType << endreq;
    00062
    00063   if ( status.isFailure() ) {
    00064     log << MSG::ERROR << "Could not initialize main svc" << endreq;
    00065     return StatusCode::FAILURE;
    00066   }
    00067
    00068   bool (*pF)  (std::istream &,
    00069                HepPDT::TableBuilder &);
    00070
    00071
    00072   // Determine type of input
    00073   if (m_inputType == "PDG") {
    00074     pF = &HepPDT::addPDGParticles;
    00075   } else if (m_inputType == "Pythia") {
    00076     pF = &HepPDT::addPythiaParticles;
    00077   } else if (m_inputType == "EvtGen") {
    00078     pF = &HepPDT::addEvtGenParticles;
    00079   } else if (m_inputType == "Herwig") {
    00080     pF = &HepPDT::addHerwigParticles;
    00081   } else if (m_inputType == "IsaJet") {
    00082     pF = &HepPDT::addIsajetParticles;
    00083   } else if (m_inputType == "QQ") {
    00084     pF = &HepPDT::addQQParticles;
    00085   } else {
    00086     log << MSG::ERROR << "Unknown Particle Data file type: \""
    00087         << m_inputType << "\"" << endreq;
    00088     return StatusCode::FAILURE;
    00089   }
    00090
    00091   // Make sure we have at least one file
    00092   if (m_pdtFiles.size() == 0) {
    00093     log << MSG::ERROR << "Need at least 1 PDT file" << endreq;
    00094     log << MSG::ERROR << "Check value of property \"InputFile\"" << endreq;
    00095     return StatusCode::FAILURE;
    00096   }
    00097
    00098   m_pdt = new HepPDT::ParticleDataTable;
    00099
    00100   {
    00101     // Construct table builder
    00102     HepPDT::TableBuilder  tb( *m_pdt );
    00103
    00104     // read the input
    00105     int good(0);
    00106     for (itr=m_pdtFiles.begin(); itr!=m_pdtFiles.end(); ++itr) {
    00107
    00108       std::string rfile = System::PathResolver::find_file(*itr,"DATAPATH");
    00109       if (rfile == "") {
    00110         log << MSG::ERROR << "Could not find PDT file: \"" << *itr
    00111             << "\" in $DATAPATH" << endreq;
    00112         continue;
    00113       }
    00114
    00115       std::ifstream pdfile( rfile.c_str() );
    00116       if (!pdfile) {
    00117         log << MSG::ERROR << "Could not open PDT file: \"" << rfile
    00118             << "\"" << endreq;
    00119         continue;
    00120       }
    00121
    00122       if ( ! pF(pdfile,tb) ) {
    00123         log << MSG::ERROR << "Error reading PDT file: \"" << rfile
    00124             << "\"" << endreq;
    00125         return StatusCode::FAILURE;
    00126       }
    00127       ++good;
    00128     }
    00129     if (0 == good) {
    00130       log << MSG::ERROR << "Unable to access any PDT file" <<endreq;
    00131       return StatusCode::FAILURE;
    00132     }
    00133
    00134   }   // the tb destructor fills datacol
    00135
    00136
    00137
    00138   return status;
    00139 }
    00140
    00141 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
    00142
    00143 StatusCode PartPropSvc::finalize() {
    00144
    00145   MsgStream log( msgSvc(), name() );
    00146   StatusCode status = Service::finalize();
    00147
    00148   if ( status.isSuccess() )
    00149     log << MSG::INFO << "Service finalised successfully" << endreq;
    00150
    00151   return status;
    00152 }
    00153
    00154 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
    00155
    00156 StatusCode PartPropSvc::queryInterface( const InterfaceID& riid,
    00157                                         void** ppvInterface ) {
    00158   StatusCode sc = StatusCode::FAILURE;
    00159   if ( ppvInterface ) {
    00160     *ppvInterface = 0;
    00161
    00162     if ( riid == IID_IPartPropSvc ) {
    00163       *ppvInterface = static_cast<IPartPropSvc*>(this);
    00164       sc = StatusCode::SUCCESS;
    00165       addRef();
    00166     }
    00167     else
    00168       sc = Service::queryInterface( riid, ppvInterface );
    00169   }
    00170   return sc;
    00171 }
    00172
    00173 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
    00174 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//