Gaudi Framework, version v24r2

Home   Generated: Wed Dec 4 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PartPropSvc.cpp
Go to the documentation of this file.
1 #ifdef __ICC
2 // disable icc remark #1572: floating-point equality and inequality comparisons are unreliable
3 // TODO: should be removed because come from HepPDT
4 #pragma warning(disable:1572)
5 #endif
6 
7 //Include files
10 #include "GaudiKernel/MsgStream.h"
12 #include "GaudiKernel/Tokenizer.h"
13 
14 #include "PartPropSvc.h"
15 
16 //#include "HepPDT/TableBuilder.hh"
17 #include "HepPDT/HeavyIonUnknownID.hh"
18 
19 //#include <iostream>
20 #include <cstdlib>
21 #include <fstream>
22 
23 using namespace std;
24 
25 inline void toupper(std::string &s)
26 {
27  std::transform(s.begin(), s.end(), s.begin(),
28  (int(*)(int)) toupper);
29 }
30 
31 //*************************************************************************//
32 
34  : base_class( name, svc ), m_upid(0), m_pdt(0), m_log(msgSvc(), name),
35  m_upid_local(false) {
36 
37  declareProperty( "InputFile", m_pdtFiles="PDGTABLE.MeV");
38 
39 }
40 
41 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
42 
44 }
45 
46 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
47 
50 
52  m_log.setLevel( m_outputLevel.value() );
53 
54  if ( status.isFailure() ) {
55  m_log << MSG::ERROR << "Could not initialize main svc" << endmsg;
56  return StatusCode::FAILURE;
57  }
58 
59 
60  std::string key = m_pdtFiles.value();
61 
62  Tokenizer tok(true);
63 
64  tok.analyse( key, " ", "", "", "=", "", "");
65 
66  for ( Tokenizer::Items::iterator i = tok.items().begin();
67  i != tok.items().end(); i++) {
68  const std::string& fname = (*i).tag();
69 
70  // see if input file exists in $DATAPATH
71  std::string rfile = System::PathResolver::find_file(fname,"DATAPATH");
72  if (rfile == "") {
73  m_log << MSG::ERROR << "Could not find PDT file: \"" << fname
74  << "\" in $DATAPATH" << endmsg;
75  return StatusCode::FAILURE;
76  }
77 
78 
79  // is the file readable?
80  std::ifstream pdfile( rfile.c_str() );
81  if (!pdfile) {
82  m_log << MSG::ERROR << "Could not open PDT file: \"" << rfile
83  << "\"" << endmsg;
84  return StatusCode::FAILURE;
85  }
86 
87  std::string val,VAL;
88  val = (*i).value();
89  VAL = val;
90  toupper(VAL);
91 
92  // default: no type specified, assume PDG
93  if (val == fname) {
94  m_log << MSG::INFO << "No table format type specified for \"" << fname
95  << "\". Assuming PDG" << endmsg;
96  VAL = "PDG";
97  }
98 
99  bool (*pF) (std::istream &,
100  HepPDT::TableBuilder &);
101  try {
102  pF = parseTableType(VAL);
103  } catch (...) {
104  m_log << MSG::ERROR
105  << "Could not determine Particle Property table type: \""
106  << val << "\" for file \"" << fname << "\"" << endmsg;
107  return StatusCode::FAILURE;
108  }
109 
110  m_log << MSG::DEBUG << "Adding PDT file \"" << rfile << "\" type "
111  << VAL << endmsg;
112 
113  m_inputs.push_back( make_pair( rfile, pF ) );
114 
115  }
116 
117 
118  return status;
119 }
120 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
121 
124 
125  return StatusCode::SUCCESS;
126 
127 }
128 
129 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
130 
133 
134  if (m_pdt != 0) {
135  delete m_pdt;
136  m_pdt = 0;
137  }
138 
139  if (m_upid_local && m_upid != 0) {
140  m_upid_local = false;
141  // This will cause a memory leak, but we can't delete it as the
142  // destructor of HepPDT::processUnknownID is protected.
143  // We need this though to call reinitialize successfully.
144  m_upid = 0;
145  }
146 
147  MsgStream m_log( msgSvc(), name() );
148  StatusCode status = Service::finalize();
149 
150  if ( status.isSuccess() )
151  m_log << MSG::DEBUG << "Service finalised successfully" << endmsg;
152 
153  return status;
154 }
155 
156 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
157 
158 bool
160  HepPDT::TableBuilder&) {
161 
162  bool (*pF) (std::istream &,
163  HepPDT::TableBuilder &);
164 
165  if (typ == "PDG") {
166  pF = &HepPDT::addPDGParticles;
167  } else if (typ == "PYTHIA") {
168  pF = &HepPDT::addPythiaParticles;
169  } else if (typ == "EVTGEN") {
170  pF = &HepPDT::addEvtGenParticles;
171  } else if (typ == "HERWIG") {
172  pF = &HepPDT::addHerwigParticles;
173  } else if (typ == "ISAJET") {
174  pF = &HepPDT::addIsajetParticles;
175  } else if (typ == "QQ") {
176  pF = &HepPDT::addQQParticles;
177  } else {
178  m_log << MSG::ERROR << "Unknown Particle Data file type: \""
179  << typ << "\"" << endmsg;
180  throw( std::runtime_error("error parsing particle table type") );
181  }
182 
183  return pF;
184 
185 }
186 
187 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
188 
191 
192  // use a handler for unknown heavy ions
193  if ( m_upid == 0 ) {
194  setUnknownParticleHandler(new HepPDT::HeavyIonUnknownID,
195  "Default Heavy Ion Handler");
196  m_upid_local = true;
197  }
198 
199  m_pdt = new HepPDT::ParticleDataTable(m_upid_name, m_upid);
200 
201  HepPDT::TableBuilder tb( *m_pdt );
202 
204  bool(*) (std::istream&,HepPDT::TableBuilder&)> >::const_iterator itr;
205  for (itr = m_inputs.begin(); itr != m_inputs.end(); ++itr) {
206  string f = itr->first;
207  bool (*pF) (std::istream&,HepPDT::TableBuilder&) = itr->second;
208 
209  m_log << MSG::DEBUG << "Reading PDT file \"" << f << "\""
210  << endmsg;
211 
212  std::ifstream pdfile( f.c_str() );
213  // build a table from the file
214  if ( ! pF(pdfile,tb) ) {
215  m_log << MSG::ERROR << "Error reading PDT file: \"" << f
216  << "\"" << endmsg;
217  return StatusCode::FAILURE;
218  }
219 
220  }
221 
222  return StatusCode::SUCCESS;
223 
224 }
225 
226 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
227 
228 HepPDT::ParticleDataTable*
230 
231  if (m_pdt == 0) {
232  m_log << MSG::DEBUG << "creating ParticleDataTable" << endmsg;
233  if (createTable().isFailure()) {
234  m_log << MSG::FATAL << "Could not create ParticleDataTable" << endmsg;
235  m_pdt = 0;
236  }
237  }
238 
239  return m_pdt;
240 }
241 
242 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
243 
244 void
245 PartPropSvc::setUnknownParticleHandler(HepPDT::ProcessUnknownID* puid,
246  const std::string& n) {
247  if (m_pdt != 0) {
248  m_log << MSG::ERROR << "not setting Unknown Particle Handler \"" << n
249  << "\" as ParticleDataTable already instantiated" << endmsg;
250  return;
251  }
252 
253  m_log << MSG::DEBUG << "setting Unknown Particle Handler \"" << n
254  << "\" at " << puid << endmsg;
255 
256  if (m_upid != 0) {
257  m_log << MSG::WARNING
258  << "overriding previously selected Unknown Particle Handler \""
259  << m_upid_name << "\" with \"" << n << "\"" << endmsg;
260  }
261 
262  m_upid = puid;
263  m_upid_name = n;
264 
265 }
266 
267 // Instantiation of a static factory class used by clients to create
268 // instances of this service
269 DECLARE_SERVICE_FACTORY(PartPropSvc)
270 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
271 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//

Generated at Wed Dec 4 2013 14:33:12 for Gaudi Framework, version v24r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004