CMS 3D CMS Logo

HepPDTESSource.cc
Go to the documentation of this file.
2 #include "HepPDT/HeavyIonUnknownID.hh"
3 #include "tbb/concurrent_vector.h"
4 
5 namespace {
6 
7  class CachingHeavyIonUnknownID : public HepPDT::ProcessUnknownID {
8  HepPDT::ParticleData * processUnknownID( HepPDT::ParticleID id,
9  const HepPDT::ParticleDataTable & table) final {
10  //HeavyIonUnknownID constructs a new particle but does not delete it
11  // we need to do that ourselves
12  std::unique_ptr<HepPDT::ParticleData> p{ wrapped_.processUnknownID(id, table) };
13  auto* pPtr = p.get();
14  if(p) {
15  particles_.emplace_back(std::move(p));
16  }
17  return pPtr;
18  }
19 
20  HepPDT::HeavyIonUnknownID wrapped_;
21  tbb::concurrent_vector<std::unique_ptr<HepPDT::ParticleData>> particles_;
22  };
23 
24 }
25 
27  pdtFileName( cfg.getParameter<edm::FileInPath>( "pdtFileName" ) ) {
28  setWhatProduced( this );
29  findingRecord<PDTRecord>();
30 }
31 
33 }
34 
36 HepPDTESSource::produce( const PDTRecord & iRecord ) {
37  using namespace edm::es;
38  auto pdt = std::make_unique<PDT>( "PDG table" , new CachingHeavyIonUnknownID );
39  std::ifstream pdtFile( pdtFileName.fullPath().c_str() );
40  if( ! pdtFile )
41  throw cms::Exception( "FileNotFound", "can't open pdt file" )
42  << "cannot open " << pdtFileName.fullPath();
43  { // notice: the builder has to be destroyed
44  // in order to fill the table!
45  HepPDT::TableBuilder builder( * pdt );
46  if( ! addParticleTable( pdtFile, builder ) ) {
47  throw cms::Exception( "ConfigError", "can't read pdt file" )
48  << "wrong format of " << pdtFileName.fullPath();
49  }
50  }
51  return pdt;
52 }
53 
55  const edm::IOVSyncValue&,
56  edm::ValidityInterval& oInterval ) {
57  // the same PDT is valid for any time
59 }
60 
61 //define this as a plug-in
62 //DEFINE_FWK_EVENTSETUP_SOURCE( HepPDTESSource );
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:116
HepPDT::ParticleDataTable ParticleDataTable
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:97
edm::FileInPath pdtFileName
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
HepPDTESSource(const edm::ParameterSet &)
constructor from parameter set
~HepPDTESSource() override
destructor
std::unique_ptr< PDT > ReturnType
define the return type
static const IOVSyncValue & beginOfTime()
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
set validity interval
HepPDT::ParticleData ParticleData
HLT enums.
ReturnType produce(const PDTRecord &)
return the particle table
std::string fullPath() const
Definition: FileInPath.cc:197
def move(src, dest)
Definition: eostools.py:511