Gaudi Framework, version v21r7

Home   Generated: 22 Jan 2010

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   : base_class( 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 StatusCode PartPropSvc::initialize() {
00045 
00046   MsgStream log( msgSvc(), name() );
00047   std::vector<std::string>::const_iterator itr;
00048 
00049   StatusCode status = Service::initialize();
00050 
00051   log << MSG::INFO << "PDT file(s): " << endmsg;
00052   for (itr=m_pdtFiles.begin(); itr!=m_pdtFiles.end(); ++itr) {
00053     log << MSG::INFO << "    " << *itr << endmsg;
00054   }
00055   log << MSG::INFO << "Type:     " << m_inputType << endmsg;
00056 
00057   if ( status.isFailure() ) {
00058     log << MSG::ERROR << "Could not initialize main svc" << endmsg;
00059     return StatusCode::FAILURE;
00060   }
00061 
00062   bool (*pF)  (std::istream &,
00063                HepPDT::TableBuilder &);
00064 
00065 
00066   // Determine type of input
00067   if (m_inputType == "PDG") {
00068     pF = &HepPDT::addPDGParticles;
00069   } else if (m_inputType == "Pythia") {
00070     pF = &HepPDT::addPythiaParticles;
00071   } else if (m_inputType == "EvtGen") {
00072     pF = &HepPDT::addEvtGenParticles;
00073   } else if (m_inputType == "Herwig") {
00074     pF = &HepPDT::addHerwigParticles;
00075   } else if (m_inputType == "IsaJet") {
00076     pF = &HepPDT::addIsajetParticles;
00077   } else if (m_inputType == "QQ") {
00078     pF = &HepPDT::addQQParticles;
00079   } else {
00080     log << MSG::ERROR << "Unknown Particle Data file type: \""
00081         << m_inputType << "\"" << endmsg;
00082     return StatusCode::FAILURE;
00083   }
00084 
00085   // Make sure we have at least one file
00086   if (m_pdtFiles.size() == 0) {
00087     log << MSG::ERROR << "Need at least 1 PDT file" << endmsg;
00088     log << MSG::ERROR << "Check value of property \"InputFile\"" << endmsg;
00089     return StatusCode::FAILURE;
00090   }
00091 
00092   m_pdt = new HepPDT::ParticleDataTable;
00093 
00094   {
00095     // Construct table builder
00096     HepPDT::TableBuilder  tb( *m_pdt );
00097 
00098     // read the input
00099     int good(0);
00100     for (itr=m_pdtFiles.begin(); itr!=m_pdtFiles.end(); ++itr) {
00101 
00102       std::string rfile = System::PathResolver::find_file(*itr,"DATAPATH");
00103       if (rfile == "") {
00104         log << MSG::ERROR << "Could not find PDT file: \"" << *itr
00105             << "\" in $DATAPATH" << endmsg;
00106         continue;
00107       }
00108 
00109       std::ifstream pdfile( rfile.c_str() );
00110       if (!pdfile) {
00111         log << MSG::ERROR << "Could not open PDT file: \"" << rfile
00112             << "\"" << endmsg;
00113         continue;
00114       }
00115 
00116       if ( ! pF(pdfile,tb) ) {
00117         log << MSG::ERROR << "Error reading PDT file: \"" << rfile
00118             << "\"" << endmsg;
00119         return StatusCode::FAILURE;
00120       }
00121       ++good;
00122     }
00123     if (0 == good) {
00124       log << MSG::ERROR << "Unable to access any PDT file" <<endmsg;
00125       return StatusCode::FAILURE;
00126     }
00127 
00128   }   // the tb destructor fills datacol
00129 
00130 
00131 
00132   return status;
00133 }
00134 
00135 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
00136 
00137 StatusCode PartPropSvc::finalize() {
00138 
00139   MsgStream log( msgSvc(), name() );
00140   StatusCode status = Service::finalize();
00141 
00142   if ( status.isSuccess() )
00143     log << MSG::INFO << "Service finalised successfully" << endmsg;
00144 
00145   return status;
00146 }
00147 
00148 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
00149 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//

Generated at Fri Jan 22 20:28:12 2010 for Gaudi Framework, version v21r7 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004