PartPropSvc Class Reference

#include <src/PartPropSvc.h>

Inheritance diagram for PartPropSvc:
Collaboration diagram for PartPropSvc:

Public Member Functions

 PartPropSvc (const std::string &name, ISvcLocator *svc)
 
StatusCode initialize () override
 
StatusCode finalize () override
 
HepPDT::ParticleDataTable * PDT () override
 
void setUnknownParticleHandler (HepPDT::ProcessUnknownID *, const std::string &) override
 
 ~PartPropSvc () override=default
 
- Public Member Functions inherited from extends< BASE, Interfaces >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. More...
 
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Private Types

using inputFunPtr = bool(*)(std::istream &, HepPDT::TableBuilder &)
 

Private Member Functions

StatusCode createTable ()
 
inputFunPtr parseTableType (const std::string &)
 

Private Attributes

std::vector< std::pair< std::string, inputFunPtr > > m_inputs
 
StringProperty m_pdtFiles
 
HepPDT::ProcessUnknownID * m_upid = nullptr
 
std::string m_upid_name
 
std::unique_ptr< HepPDT::ParticleDataTable > m_pdt
 
MsgStream m_log
 
bool m_upid_local = false
 

Additional Inherited Members

- Public Types inherited from extends< BASE, Interfaces >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
- Public Types inherited from extend_interfaces< Interfaces...>
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 

Detailed Description

Definition at line 28 of file PartPropSvc.h.

Member Typedef Documentation

using PartPropSvc::inputFunPtr = bool(*)(std::istream&,HepPDT::TableBuilder&)
private

Definition at line 47 of file PartPropSvc.h.

Constructor & Destructor Documentation

PartPropSvc::PartPropSvc ( const std::string &  name,
ISvcLocator svc 
)

Definition at line 25 of file PartPropSvc.cpp.

26  : base_class( name_, svc ), m_log(msgSvc(), name()) {
27 
28  declareProperty( "InputFile", m_pdtFiles="PDGTABLE.MeV");
29 
30 }
extends base_class
Typedef to this class.
Definition: extends.h:14
MsgStream m_log
Definition: PartPropSvc.h:60
StringProperty m_pdtFiles
Definition: PartPropSvc.h:52
PartPropSvc::~PartPropSvc ( )
overridedefault

Member Function Documentation

StatusCode PartPropSvc::createTable ( )
private

Definition at line 158 of file PartPropSvc.cpp.

158  {
159 
160  // use a handler for unknown heavy ions
161  if ( !m_upid ) {
162  setUnknownParticleHandler(new HepPDT::HeavyIonUnknownID,
163  "Default Heavy Ion Handler");
164  m_upid_local = true;
165  }
166 
167  m_pdt.reset( new HepPDT::ParticleDataTable(m_upid_name, m_upid) );
168 
169  HepPDT::TableBuilder tb( *m_pdt );
170 
171  for (const auto& itr : m_inputs ) {
172  const auto& f = itr.first;
173  const auto& pF = itr.second;
174 
175  m_log << MSG::DEBUG << "Reading PDT file \"" << f << "\""
176  << endmsg;
177 
178  std::ifstream pdfile{ f };
179  // build a table from the file
180  if ( ! pF(pdfile,tb) ) {
181  m_log << MSG::ERROR << "Error reading PDT file: \"" << f
182  << "\"" << endmsg;
183  return StatusCode::FAILURE;
184  }
185 
186  }
187 
188  return StatusCode::SUCCESS;
189 
190 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
std::unique_ptr< HepPDT::ParticleDataTable > m_pdt
Definition: PartPropSvc.h:56
MsgStream m_log
Definition: PartPropSvc.h:60
HepPDT::ProcessUnknownID * m_upid
Definition: PartPropSvc.h:53
bool m_upid_local
Definition: PartPropSvc.h:62
std::vector< std::pair< std::string, inputFunPtr > > m_inputs
Definition: PartPropSvc.h:50
void setUnknownParticleHandler(HepPDT::ProcessUnknownID *, const std::string &) override
std::string m_upid_name
Definition: PartPropSvc.h:54
StatusCode PartPropSvc::finalize ( )
override

Definition at line 111 of file PartPropSvc.cpp.

111  {
112 
113  m_pdt.reset();
114 
115  if (m_upid_local && m_upid ) {
116  m_upid_local = false;
117  // This will cause a memory leak, but we can't delete it as the
118  // destructor of HepPDT::processUnknownID is protected.
119  // We need this though to call reinitialize successfully.
120  m_upid = nullptr;
121  }
122 
123  MsgStream m_log( msgSvc(), name() );
124  StatusCode status = Service::finalize();
125 
126  if ( status.isSuccess() ) {
127  m_log << MSG::DEBUG << "Service finalised successfully" << endmsg;
128  }
129 
130  return status;
131 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatusCode finalize() override
Definition: Service.cpp:188
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
std::unique_ptr< HepPDT::ParticleDataTable > m_pdt
Definition: PartPropSvc.h:56
MsgStream m_log
Definition: PartPropSvc.h:60
HepPDT::ProcessUnknownID * m_upid
Definition: PartPropSvc.h:53
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
bool m_upid_local
Definition: PartPropSvc.h:62
StatusCode PartPropSvc::initialize ( )
override

Definition at line 35 of file PartPropSvc.cpp.

35  {
36 
38  m_log.setLevel( m_outputLevel.value() );
39 
40  if ( status.isFailure() ) {
41  m_log << MSG::ERROR << "Could not initialize main svc" << endmsg;
42  return StatusCode::FAILURE;
43  }
44 
45 
46  std::string key = m_pdtFiles.value();
47 
48  typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
49  boost::char_separator<char> sep(", ");
50  boost::char_separator<char> sep_eq("=");
51 
52  tokenizer tokens(key, sep);
53  for (auto it = tokens.begin(); it != tokens.end(); ++it) {
54 
55  tokenizer tok2(*it, sep_eq);
56  int nToks(distance(tok2.begin(), tok2.end()));
57 
58  auto it2 = tok2.begin();
59  const std::string fname = *it2;
60  std::string fmt;
61  if (nToks == 1) {
62  m_log << MSG::INFO << "No table format type specified for \"" << fname
63  << "\". Assuming PDG" << endmsg;
64  fmt = "PDG";
65  } else {
66  ++it2;
67  fmt = *it2;
68  }
69 
70  // see if input file exists in $DATAPATH
71  std::string rfile = System::PathResolver::find_file(fname,"DATAPATH");
72  if (rfile.empty()) {
73  m_log << MSG::ERROR << "Could not find PDT file: \"" << fname
74  << "\" in $DATAPATH" << endmsg;
75  return StatusCode::FAILURE;
76  }
77 
78  // is the file readable?
79  std::ifstream pdfile{ rfile };
80  if (!pdfile) {
81  m_log << MSG::ERROR << "Could not open PDT file: \"" << rfile
82  << "\"" << endmsg;
83  return StatusCode::FAILURE;
84  }
85 
86  std::string FMT = boost::algorithm::to_upper_copy(fmt);
87 
88  inputFunPtr pF = nullptr;
89  try {
90  pF = parseTableType(FMT);
91  } catch (...) {
92  m_log << MSG::ERROR
93  << "Could not determine Particle Property table type: \""
94  << FMT << "\" for file \"" << fname << "\"" << endmsg;
95  return StatusCode::FAILURE;
96  }
97 
98  m_log << MSG::DEBUG << "Adding PDT file \"" << rfile << "\" type "
99  << FMT << endmsg;
100 
101  m_inputs.emplace_back( rfile, pF );
102 
103  }
104 
105 
106  return status;
107 }
StatusCode initialize() override
Definition: Service.cpp:63
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
inputFunPtr parseTableType(const std::string &)
MsgStream m_log
Definition: PartPropSvc.h:60
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
bool(*)(std::istream &, HepPDT::TableBuilder &) inputFunPtr
Definition: PartPropSvc.h:47
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
const TYPE & value() const
explicit conversion
Definition: Property.h:341
void setLevel(int level)
Update outputlevel.
Definition: MsgStream.h:106
std::vector< std::pair< std::string, inputFunPtr > > m_inputs
Definition: PartPropSvc.h:50
StringProperty m_pdtFiles
Definition: PartPropSvc.h:52
PartPropSvc::inputFunPtr PartPropSvc::parseTableType ( const std::string &  typ)
private

Definition at line 136 of file PartPropSvc.cpp.

137 {
138  static const auto table = { std::make_pair( "PDG" , &HepPDT::addPDGParticles ),
139  std::make_pair( "PYTHIA" , &HepPDT::addPythiaParticles ),
140  std::make_pair( "EVTGEN" , &HepPDT::addEvtGenParticles ),
141  std::make_pair( "HERWIG" , &HepPDT::addHerwigParticles ),
142  std::make_pair( "ISAJET" , &HepPDT::addIsajetParticles ),
143  std::make_pair( "QQ" , &HepPDT::addQQParticles ) };
144  auto i = std::find_if( std::begin(table), std::end(table),
145  [&](const std::pair<const char*,inputFunPtr>& p)
146  { return typ == p.first; } );
147  if ( i == std::end(table) ) {
148  m_log << MSG::ERROR << "Unknown Particle Data file type: \""
149  << typ << "\"" << endmsg;
150  throw std::runtime_error("error parsing particle table type");
151  }
152  return i->second;
153 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
MsgStream m_log
Definition: PartPropSvc.h:60
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
list i
Definition: ana.py:128
HepPDT::ParticleDataTable * PartPropSvc::PDT ( )
override

Definition at line 195 of file PartPropSvc.cpp.

195  {
196 
197  if (!m_pdt ) {
198  m_log << MSG::DEBUG << "creating ParticleDataTable" << endmsg;
199  if (createTable().isFailure()) {
200  m_log << MSG::FATAL << "Could not create ParticleDataTable" << endmsg;
201  m_pdt.reset(nullptr);
202  }
203  }
204 
205  return m_pdt.get();
206 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
std::unique_ptr< HepPDT::ParticleDataTable > m_pdt
Definition: PartPropSvc.h:56
MsgStream m_log
Definition: PartPropSvc.h:60
StatusCode createTable()
void PartPropSvc::setUnknownParticleHandler ( HepPDT::ProcessUnknownID *  puid,
const std::string &  n 
)
override

Definition at line 211 of file PartPropSvc.cpp.

212  {
213  if (m_pdt) {
214  m_log << MSG::ERROR << "not setting Unknown Particle Handler \"" << n
215  << "\" as ParticleDataTable already instantiated" << endmsg;
216  return;
217  }
218 
219  m_log << MSG::DEBUG << "setting Unknown Particle Handler \"" << n
220  << "\" at " << puid << endmsg;
221 
222  if (m_upid) {
224  << "overriding previously selected Unknown Particle Handler \""
225  << m_upid_name << "\" with \"" << n << "\"" << endmsg;
226  }
227 
228  m_upid = puid;
229  m_upid_name = n;
230 
231 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
std::unique_ptr< HepPDT::ParticleDataTable > m_pdt
Definition: PartPropSvc.h:56
MsgStream m_log
Definition: PartPropSvc.h:60
HepPDT::ProcessUnknownID * m_upid
Definition: PartPropSvc.h:53
std::string m_upid_name
Definition: PartPropSvc.h:54

Member Data Documentation

std::vector<std::pair<std::string,inputFunPtr> > PartPropSvc::m_inputs
private

Definition at line 50 of file PartPropSvc.h.

MsgStream PartPropSvc::m_log
mutableprivate

Definition at line 60 of file PartPropSvc.h.

std::unique_ptr<HepPDT::ParticleDataTable> PartPropSvc::m_pdt
private

Definition at line 56 of file PartPropSvc.h.

StringProperty PartPropSvc::m_pdtFiles
private

Definition at line 52 of file PartPropSvc.h.

HepPDT::ProcessUnknownID* PartPropSvc::m_upid = nullptr
private

Definition at line 53 of file PartPropSvc.h.

bool PartPropSvc::m_upid_local = false
private

Definition at line 62 of file PartPropSvc.h.

std::string PartPropSvc::m_upid_name
private

Definition at line 54 of file PartPropSvc.h.


The documentation for this class was generated from the following files: