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 ()
 
void setUnknownParticleHandler (HepPDT::ProcessUnknownID *, const std::string &)
 
 ~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 >
typedef extends base_class
 Typedef to this class. More...
 
typedef extend_interfaces< Interfaces...> extend_interfaces_base
 Typedef to the base of this class. More...
 
typedef extends base_class
 Typedef to this class. More...
 
typedef extend_interfaces< Interfaces...> extend_interfaces_base
 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 }
MsgStream m_log
Definition: PartPropSvc.h:60
extends base_class
Typedef to this class.
Definition: extends.h:14
StringProperty m_pdtFiles
Definition: PartPropSvc.h:52
PartPropSvc::~PartPropSvc ( )
overridedefault

Member Function Documentation

StatusCode PartPropSvc::createTable ( )
private

Definition at line 150 of file PartPropSvc.cpp.

150  {
151 
152  // use a handler for unknown heavy ions
153  if ( !m_upid ) {
154  setUnknownParticleHandler(new HepPDT::HeavyIonUnknownID,
155  "Default Heavy Ion Handler");
156  m_upid_local = true;
157  }
158 
159  m_pdt.reset( new HepPDT::ParticleDataTable(m_upid_name, m_upid) );
160 
161  HepPDT::TableBuilder tb( *m_pdt );
162 
163  for (const auto& itr : m_inputs ) {
164  const auto& f = itr.first;
165  const auto& pF = itr.second;
166 
167  m_log << MSG::DEBUG << "Reading PDT file \"" << f << "\""
168  << endmsg;
169 
170  std::ifstream pdfile{ f };
171  // build a table from the file
172  if ( ! pF(pdfile,tb) ) {
173  m_log << MSG::ERROR << "Error reading PDT file: \"" << f
174  << "\"" << endmsg;
175  return StatusCode::FAILURE;
176  }
177 
178  }
179 
180  return StatusCode::SUCCESS;
181 
182 }
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
void setUnknownParticleHandler(HepPDT::ProcessUnknownID *, const std::string &)
std::vector< std::pair< std::string, inputFunPtr > > m_inputs
Definition: PartPropSvc.h:50
std::string m_upid_name
Definition: PartPropSvc.h:54
StatusCode PartPropSvc::finalize ( )
override

Definition at line 104 of file PartPropSvc.cpp.

104  {
105 
106  m_pdt.reset();
107 
108  if (m_upid_local && m_upid ) {
109  m_upid_local = false;
110  // This will cause a memory leak, but we can't delete it as the
111  // destructor of HepPDT::processUnknownID is protected.
112  // We need this though to call reinitialize successfully.
113  m_upid = nullptr;
114  }
115 
116  MsgStream m_log( msgSvc(), name() );
117  StatusCode status = Service::finalize();
118 
119  if ( status.isSuccess() )
120  m_log << MSG::DEBUG << "Service finalised successfully" << endmsg;
121 
122  return status;
123 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode finalize() override
Definition: Service.cpp:187
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
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  static const boost::regex exp{"[[:space:]]*([^[:space:]]+)[[:space:]]*=[[:space:]]*([^[:space:]]+)"};
49  static const auto tok_end = boost::sregex_iterator();
50  for (auto tok_iter = boost::sregex_iterator(begin(key), end(key), exp);
51  tok_iter != tok_end; ++tok_iter)
52  {
53  const std::string fname = (*tok_iter)[1];
54 
55  // see if input file exists in $DATAPATH
56  std::string rfile = System::PathResolver::find_file(fname,"DATAPATH");
57  if (rfile.empty()) {
58  m_log << MSG::ERROR << "Could not find PDT file: \"" << fname
59  << "\" in $DATAPATH" << endmsg;
60  return StatusCode::FAILURE;
61  }
62 
63  // is the file readable?
64  std::ifstream pdfile{ rfile };
65  if (!pdfile) {
66  m_log << MSG::ERROR << "Could not open PDT file: \"" << rfile
67  << "\"" << endmsg;
68  return StatusCode::FAILURE;
69  }
70 
71  std::string val = (*tok_iter)[1];
72  std::string VAL = boost::algorithm::to_upper_copy(val);
73 
74  // default: no type specified, assume PDG
75  if (val == fname) {
76  m_log << MSG::INFO << "No table format type specified for \"" << fname
77  << "\". Assuming PDG" << endmsg;
78  VAL = "PDG";
79  }
80 
81  inputFunPtr pF = nullptr;
82  try {
83  pF = parseTableType(VAL);
84  } catch (...) {
85  m_log << MSG::ERROR
86  << "Could not determine Particle Property table type: \""
87  << val << "\" for file \"" << fname << "\"" << endmsg;
88  return StatusCode::FAILURE;
89  }
90 
91  m_log << MSG::DEBUG << "Adding PDT file \"" << rfile << "\" type "
92  << VAL << endmsg;
93 
94  m_inputs.emplace_back( rfile, pF );
95 
96  }
97 
98 
99  return status;
100 }
StatusCode initialize() override
Definition: Service.cpp:62
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
inputFunPtr parseTableType(const std::string &)
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
MsgStream m_log
Definition: PartPropSvc.h:60
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
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 128 of file PartPropSvc.cpp.

129 {
130  static const auto table = { std::make_pair( "PDG" , &HepPDT::addPDGParticles ),
131  std::make_pair( "PYTHIA" , &HepPDT::addPythiaParticles ),
132  std::make_pair( "EVTGEN" , &HepPDT::addEvtGenParticles ),
133  std::make_pair( "HERWIG" , &HepPDT::addHerwigParticles ),
134  std::make_pair( "ISAJET" , &HepPDT::addIsajetParticles ),
135  std::make_pair( "QQ" , &HepPDT::addQQParticles ) };
136  auto i = std::find_if( std::begin(table), std::end(table),
137  [&](const std::pair<const char*,inputFunPtr>& p)
138  { return typ == p.first; } );
139  if ( i == std::end(table) ) {
140  m_log << MSG::ERROR << "Unknown Particle Data file type: \""
141  << typ << "\"" << endmsg;
142  throw std::runtime_error("error parsing particle table type");
143  }
144  return i->second;
145 }
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 ( )

Definition at line 187 of file PartPropSvc.cpp.

187  {
188 
189  if (!m_pdt ) {
190  m_log << MSG::DEBUG << "creating ParticleDataTable" << endmsg;
191  if (createTable().isFailure()) {
192  m_log << MSG::FATAL << "Could not create ParticleDataTable" << endmsg;
193  m_pdt.reset(nullptr);
194  }
195  }
196 
197  return m_pdt.get();
198 }
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 
)

Definition at line 203 of file PartPropSvc.cpp.

204  {
205  if (m_pdt) {
206  m_log << MSG::ERROR << "not setting Unknown Particle Handler \"" << n
207  << "\" as ParticleDataTable already instantiated" << endmsg;
208  return;
209  }
210 
211  m_log << MSG::DEBUG << "setting Unknown Particle Handler \"" << n
212  << "\" at " << puid << endmsg;
213 
214  if (m_upid) {
216  << "overriding previously selected Unknown Particle Handler \""
217  << m_upid_name << "\" with \"" << n << "\"" << endmsg;
218  }
219 
220  m_upid = puid;
221  m_upid_name = n;
222 
223 }
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: