8 #include "boost/algorithm/string/split.hpp"
9 #include "boost/algorithm/string/trim.hpp"
10 #include "boost/algorithm/string/classification.hpp"
11 namespace ba = boost::algorithm;
15 #include "GaudiKernel/ISvcLocator.h"
16 #include "GaudiKernel/MsgStream.h"
17 #include "GaudiKernel/ParticleProperty.h"
18 #include "GaudiKernel/PhysicalConstants.h"
19 #include "GaudiKernel/IFileAccess.h"
20 #include "GaudiKernel/System.h"
30 template <
typename T,
class... Args>
31 std::unique_ptr<T> make_unique_(Args&&...
args) {
32 return std::unique_ptr<T>(
new T(std::forward<Args>(
args)...));
53 ParticlePropertySvc::ParticlePropertySvc
62 m_filename +=
"/data/ParticleTable.txt";
65 declareProperty (
"ParticlePropertiesFile" , m_filename ) ;
66 declareProperty (
"OtherFiles" , m_other ) ;
67 declareProperty (
"Particles" , m_particles ) ;
126 <<
"Properties have been redefined for "
143 <<
"Additional Properties have been read from files: "
152 <<
"Properties have been redefined for "
167 (
const std::string& particle ,
173 const std::string& evtName ,
178 auto i = m_owned.insert(
179 make_unique_<ParticleProperty>( particle , geantId , jetsetId ,
180 charge , mass , tlife ,
181 evtName , pythiaId , maxWidth )
196 auto ifind =
m_idmap.find( ID ) ;
199 diff ( ifind->second , pp ) ;
207 const std::string& particle = pp->
particle() ;
209 auto ifind =
m_namemap.find( particle ) ;
210 if ( ifind !=
m_namemap.end() && ifind->second )
212 diff ( ifind->second , pp ) ;
213 m_replaced.insert( ifind->second->particle() ) ;
228 diff ( ifind->second , pp ) ;
229 m_replaced.insert( ifind->second->particle() ) ;
246 diff ( ifind->second , pp ) ;
247 m_replaced.insert( ifind->second ->particle() ) ;
263 auto i = std::find_if( m.begin(), m.end(),
264 [&](
typename MAP::const_reference
i) {
return i.second ==
pp; } );
265 if (
i != m.end() ) { m.erase (
i ) ; }
303 <<
"Format of input file inconsistent with what expected"
304 <<
" - Check you are using ParticleData.txt" <<
endmsg;
318 log <<
MSG::ERROR <<
"Unable to open properties file : " << file
325 <<
"Opened particle properties file : " << file <<
endmsg;
327 std::vector<std::string> tokens; tokens.reserve(9);
329 while( std::getline( *infile, line ) )
333 if ( line.front() ==
'#' )
continue;
336 ba::trim_left_if( line, ba::is_space() );
337 ba::split( tokens, line, ba::is_space() , boost::token_compress_on );
338 if (tokens.size()!=9)
continue;
340 auto gid = std::stoi( tokens[1] );
341 auto jid = std::stoi( tokens[2] );
343 if ( jid == 0 ) jid = 10000000*gid;
347 std::stod( tokens[3] ),
351 std::stoi( tokens[7] ),
352 std::stod( tokens[8] ) * Gaudi::Units::GeV ) ;
357 <<
"Error from ParticlePropertySvc::push_back for particle='"
358 << tokens[0] <<
"'" <<
endmsg ;
373 if ( !pp ) {
return nullptr ; }
374 const int ID = pp->
pdgID() ;
375 const int antiID = -1 * ID ;
378 if ( ap && antiID == ap->pdgID() ) {
return ap ; }
394 if ( !pp ) { continue ; }
406 template <
typename MAP,
typename SET>
407 void _load_ ( MAP& m ,
SET& result )
409 for (
auto i = m.begin() ; m.end() !=
i ; ++
i )
410 { result.insert (
i->second ); }
416 std::set<mapped_type> local ;
438 std::istringstream input(
item ) ;
446 std::string p_evtgen ;
461 <<
" Add/Modify the particle: "
462 <<
" name='" << p_name <<
"'"
463 <<
" geant=" << p_geant
464 <<
" jetset=" << p_jetset
465 <<
" charge=" << p_charge
466 <<
" mass=" << p_mass
467 <<
" ltime=" << p_ltime
468 <<
" evtgen='" << p_evtgen <<
"'"
469 <<
" pythia=" << p_pythia
470 <<
" maxwid=" << p_maxwid <<
endmsg ;
481 p_maxwid * Gaudi::Units::GeV ) ;
487 <<
" could not parse '" <<
item <<
"'" <<
endmsg ;
498 #pragma warning(push)
499 #pragma warning(disable:1572)
507 if ( o == n ) {
return false ; }
517 bool result = false ;
518 if ( o -> particle () != n -> particle () )
521 log <<
" Name:'" << o -> particle () <<
"'/'" << n -> particle () <<
"'" ;
523 if ( o -> geantID () != n -> geantID () )
526 log <<
" G3ID:" << o -> geantID () <<
"/" << n -> geantID () <<
"'" ;
528 if ( o -> pdgID () != n -> pdgID () )
531 log <<
" PDGID:" << o -> pdgID () <<
"/" << n -> pdgID () <<
"'" ;
533 if ( o -> pythiaID () != n -> pythiaID () )
536 log <<
" PYID:" << o -> pythiaID () <<
"/" << n -> pythiaID () <<
"'" ;
538 if ( o -> charge () != n -> charge () )
541 log <<
" Q:" << o -> charge () <<
"/" << n -> charge () <<
"'" ;
543 if ( o -> mass () != n -> mass () )
546 log <<
" M:" << o -> mass () <<
"/" << n -> mass () <<
"'" ;
548 if ( o -> lifetime () != n -> lifetime () )
551 log <<
" T:" << o -> lifetime () <<
"/" << n -> lifetime () <<
"'" ;
553 if ( o -> evtGenName () != n -> evtGenName () )
556 log <<
" EvtGen:" << o -> evtGenName () <<
"/" << n -> evtGenName () <<
"'" ;
558 if ( o -> maxWidth () != n -> maxWidth () )
561 log <<
" WMAX:" << o -> maxWidth () <<
"/" << n -> maxWidth () <<
"'" ;
563 if ( result ) { log <<
endmsg ; }
int pdgID() const
Get the PDG (= JETSET) ID.
StatusCode rebuild()
rebuild "the linear container" from the map
Definition of the MsgStream class used to transmit messages.
StatusCode initialize() override
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
int geantID() const
Get the GEANT3 ID.
StatusCode finalize() override
auto begin(reverse_wrapper< T > &w)
A trivial class to hold information about a single particle properties.
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
StatusCode erase(int geantId) override
Erase a property by geant3 id.
StatusCode finalize() override
Finalise the service.
StatusCode initialize() override
Initialise the service.
MapName m_namemap
Map for particle names.
StatusCode parse()
Parses the file and fill all the maps.
Files m_other
additional file names
SmartIF< IFileAccess > m_fileAccess
bool isFailure() const
Test for a status code of FAILURE.
StatusCode push_back(const std::string &particle, int geantId, int jetsetId, double charge, double mass, double tlife, const std::string &evtName, int pythiaId, double maxWidth) override
Create a new particle property.
std::set< std::string > m_replaced
auto end(reverse_wrapper< T > &w)
int jetsetID() const
Get the JETSET(StdHep) ID.
This class is used for returning status codes from appropriate routines.
#define DECLARE_COMPONENT(type)
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
std::string m_filename
Filename of the particle properties file.
MapStdHepID m_stdhepidmap
Map for StdHep Ids.
const ParticleProperty * anti(const ParticleProperty *pp) const
helper (protected) function to find an antiparticle for the given particle ID (StdHepID) ...
Base class used to extend a class implementing other interfaces.
bool diff(const ParticleProperty *o, const ParticleProperty *n, const MSG::Level l=MSG::DEBUG) const
StatusCode addParticles()
MapID m_idmap
Map for geant IDs.
void setAntiParticle(const ParticleProperty *p)
set the pointer to the antiparticle
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
StatusCode setAntiParticles()
helper (protected) function to set the valid particle<–>antiparticle relations
VectPP m_vectpp
Vector of all particle properties.
const std::string & particle() const
Get the particle name.
int pythiaID() const
Get the Pythia ID.
virtual std::unique_ptr< std::istream > open(const std::string &url)=0
Find the URL and returns a unique_ptr to an input stream interface of an object that can be used to r...
Helper functions to set/get the application return code.
MapPythiaID m_pythiaidmap
Map for Pythia Ids.