forked from cms-sw/cmssw
/
HepPDTESSource.cc
executable file
·62 lines (53 loc) · 2.12 KB
/
HepPDTESSource.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "SimGeneral/HepPDTESSource/interface/HepPDTESSource.h"
#include "HepPDT/HeavyIonUnknownID.hh"
#include "tbb/concurrent_vector.h"
namespace {
class CachingHeavyIonUnknownID : public HepPDT::ProcessUnknownID {
HepPDT::ParticleData * processUnknownID( HepPDT::ParticleID id,
const HepPDT::ParticleDataTable & table) final {
//HeavyIonUnknownID constructs a new particle but does not delete it
// we need to do that ourselves
std::unique_ptr<HepPDT::ParticleData> p{ wrapped_.processUnknownID(id, table) };
auto* pPtr = p.get();
if(p) {
particles_.emplace_back(std::move(p));
}
return pPtr;
}
HepPDT::HeavyIonUnknownID wrapped_;
tbb::concurrent_vector<std::unique_ptr<HepPDT::ParticleData>> particles_;
};
}
HepPDTESSource::HepPDTESSource( const edm::ParameterSet& cfg ) :
pdtFileName( cfg.getParameter<edm::FileInPath>( "pdtFileName" ) ) {
setWhatProduced( this );
findingRecord<PDTRecord>();
}
HepPDTESSource::~HepPDTESSource() {
}
HepPDTESSource::ReturnType
HepPDTESSource::produce( const PDTRecord & iRecord ) {
using namespace edm::es;
auto pdt = std::make_unique<PDT>( "PDG table" , new CachingHeavyIonUnknownID );
std::ifstream pdtFile( pdtFileName.fullPath().c_str() );
if( ! pdtFile )
throw cms::Exception( "FileNotFound", "can't open pdt file" )
<< "cannot open " << pdtFileName.fullPath();
{ // notice: the builder has to be destroyed
// in order to fill the table!
HepPDT::TableBuilder builder( * pdt );
if( ! addParticleTable( pdtFile, builder ) ) {
throw cms::Exception( "ConfigError", "can't read pdt file" )
<< "wrong format of " << pdtFileName.fullPath();
}
}
return pdt;
}
void HepPDTESSource::setIntervalFor( const edm::eventsetup::EventSetupRecordKey&,
const edm::IOVSyncValue&,
edm::ValidityInterval& oInterval ) {
// the same PDT is valid for any time
oInterval = edm::ValidityInterval( edm::IOVSyncValue::beginOfTime(), edm::IOVSyncValue::endOfTime() );
}
//define this as a plug-in
//DEFINE_FWK_EVENTSETUP_SOURCE( HepPDTESSource );