Gaudi Framework, version v21r10p1

Home   Generated: 29 Jul 2010

PartPropSvc.cpp

Go to the documentation of this file.
00001 #ifdef __ICC
00002 // disable icc remark #1572: floating-point equality and inequality comparisons are unreliable
00003 //  TODO: should be removed because come from HepPDT
00004 #pragma warning(disable:1572)
00005 #endif
00006 
00007 //Include files
00008 #include "GaudiKernel/SvcFactory.h"
00009 #include "GaudiKernel/ISvcLocator.h"
00010 #include "GaudiKernel/MsgStream.h"
00011 #include "GaudiKernel/PathResolver.h"
00012 
00013 #include "PartPropSvc.h"
00014 
00015 #include "HepPDT/TableBuilder.hh"
00016 
00017 #include <iostream>
00018 #include <cstdlib>
00019 #include <fstream>
00020 
00021 // Instantiation of a static factory class used by clients to create
00022 //  instances of this service
00023 DECLARE_SERVICE_FACTORY(PartPropSvc)
00024 
00025 //*************************************************************************//
00026 
00027 PartPropSvc::PartPropSvc( const std::string& name, ISvcLocator* svc )
00028   : base_class( name, svc ), m_pdt(0) {
00029 
00030   declareProperty( "InputType", m_inputType="PDG");
00031   declareProperty( "InputFile", m_pdtFiles);
00032 
00033   if (m_pdtFiles.empty() ) {
00034     m_pdtFiles.push_back("PDGTABLE.MeV");
00035   }
00036 
00037 }
00038 
00039 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
00040 
00041 PartPropSvc::~PartPropSvc() {
00042   if (m_pdt != 0) {
00043     delete m_pdt;
00044     m_pdt = 0;
00045   }
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): " << endmsg;
00058   for (itr=m_pdtFiles.begin(); itr!=m_pdtFiles.end(); ++itr) {
00059     log << MSG::INFO << "    " << *itr << endmsg;
00060   }
00061   log << MSG::INFO << "Type:     " << m_inputType << endmsg;
00062 
00063   if ( status.isFailure() ) {
00064     log << MSG::ERROR << "Could not initialize main svc" << endmsg;
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 << "\"" << endmsg;
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" << endmsg;
00094     log << MSG::ERROR << "Check value of property \"InputFile\"" << endmsg;
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" << endmsg;
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             << "\"" << endmsg;
00119         continue;
00120       }
00121 
00122       if ( ! pF(pdfile,tb) ) {
00123         log << MSG::ERROR << "Error reading PDT file: \"" << rfile
00124             << "\"" << endmsg;
00125         return StatusCode::FAILURE;
00126       }
00127       ++good;
00128     }
00129     if (0 == good) {
00130       log << MSG::ERROR << "Unable to access any PDT file" <<endmsg;
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" << endmsg;
00150 
00151   return status;
00152 }
00153 
00154 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
00155 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//

Generated at Thu Jul 29 10:12:55 2010 for Gaudi Framework, version v21r10p1 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004