CMS 3D CMS Logo

HepPDTESSource.cc
Go to the documentation of this file.
1 #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, const HepPDT::ParticleDataTable &table) final {
9  // HeavyIonUnknownID constructs a new particle but does not delete it
10  // we need to do that ourselves
11  std::unique_ptr<HepPDT::ParticleData> p{wrapped_.processUnknownID(id, table)};
12  auto *pPtr = p.get();
13  if (p) {
14  particles_.emplace_back(std::move(p));
15  }
16  return pPtr;
17  }
18 
19  HepPDT::HeavyIonUnknownID wrapped_;
20  tbb::concurrent_vector<std::unique_ptr<HepPDT::ParticleData>> particles_;
21  };
22 
23 } // namespace
24 
26  : pdtFileName(cfg.getParameter<edm::FileInPath>("pdtFileName")) {
27  setWhatProduced(this);
28  findingRecord<PDTRecord>();
29 }
30 
32 
34  using namespace edm::es;
35  auto pdt = std::make_unique<PDT>("PDG table", new CachingHeavyIonUnknownID);
36  std::ifstream pdtFile(pdtFileName.fullPath().c_str());
37  if (!pdtFile)
38  throw cms::Exception("FileNotFound", "can't open pdt file") << "cannot open " << pdtFileName.fullPath();
39  { // notice: the builder has to be destroyed
40  // in order to fill the table!
41  HepPDT::TableBuilder builder(*pdt);
42  if (!addParticleTable(pdtFile, builder)) {
43  throw cms::Exception("ConfigError", "can't read pdt file") << "wrong format of " << pdtFileName.fullPath();
44  }
45  }
46  return pdt;
47 }
48 
50  const edm::IOVSyncValue &,
51  edm::ValidityInterval &oInterval) {
52  // the same PDT is valid for any time
54 }
55 
56 // define this as a plug-in
57 // DEFINE_FWK_EVENTSETUP_SOURCE( HepPDTESSource );
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:124
HepPDT::ParticleDataTable ParticleDataTable
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
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()
Definition: IOVSyncValue.cc:88
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:163
def move(src, dest)
Definition: eostools.py:511