CMS 3D CMS Logo

PdtEntry.cc
Go to the documentation of this file.
6 
7 int PdtEntry::pdgId() const {
8  if (pdgId_ == 0)
9  throw cms::Exception("ConfigError") << "PdtEntry::pdgId was not set.\n"
10  << "please, call PdtEntry::setup(const EventSetup & es)";
11  return pdgId_;
12 }
13 
14 std::string const &PdtEntry::name() const {
15  if (name_.empty())
16  throw cms::Exception("ConfigError") << "PdtEntry::name was not set."
17  << "please, call PdtEntry::setup(const EventSetup & es)";
18  return name_;
19 }
20 
22  if (data_ == nullptr)
23  throw cms::Exception("ConfigError") << "PdtEntry::name was not set."
24  << "please, call PdtEntry::setup(const EventSetup & es)";
25  return *data_;
26 }
27 
30  es.getData(pdt);
31  HepPDT::ParticleData const *p = nullptr;
32  if (pdgId_ == 0) {
33  p = pdt->particle(name_);
34  if (p == nullptr)
35  throw cms::Exception("ConfigError") << "PDT has no entry for " << name_ << "."
36  << "PdtEntry can't be set.";
37  pdgId_ = p->pid();
38  } else {
39  p = pdt->particle(pdgId_);
40  if (p == nullptr)
41  throw cms::Exception("ConfigError") << "PDT has no entry for " << pdgId_ << "."
42  << "PdtEntry can't be set.";
43  name_ = p->name();
44  }
45  data_ = p;
46 }
47 namespace edm {
48  namespace pdtentry {
49  PdtEntry getPdtEntry(Entry const &e, char const *name) {
50  if (e.typeCode() == 'I')
51  return PdtEntry(e.getInt32());
52  else if (e.typeCode() == 'S')
53  return PdtEntry(e.getString());
54  else
55  throw Exception(errors::Configuration, "EntryError")
56  << "can not convert representation of " << name << " to value of type PdtEntry. "
57  << "Please, provide a parameter either of type int32 or string.";
58  }
59 
60  std::vector<PdtEntry> getPdtEntryVector(Entry const &e, char const *name) {
61  std::vector<PdtEntry> ret;
62  if (e.typeCode() == 'i') {
63  std::vector<int> v(e.getVInt32());
64  for (std::vector<int>::const_iterator i = v.begin(); i != v.end(); ++i)
65  ret.push_back(PdtEntry(*i));
66  return ret;
67  } else if (e.typeCode() == 's') {
68  std::vector<std::string> v(e.getVString());
69  for (std::vector<std::string>::const_iterator i = v.begin(); i != v.end(); ++i)
70  ret.push_back(PdtEntry(*i));
71  return ret;
72  } else
73  throw Exception(errors::Configuration, "EntryError")
74  << "can not convert representation of " << name << " to value of type PdtEntry. "
75  << "Please, provide a parameter either of type int32 or string.";
76  }
77  } // namespace pdtentry
78 } // namespace edm
int pdgId_
PDG id.
Definition: PdtEntry.h:38
PdtEntry getPdtEntry(Entry const &e, char const *name)
Definition: PdtEntry.cc:49
int getInt32() const
Definition: Entry.cc:673
std::string name_
particle name
Definition: PdtEntry.h:40
bool getData(T &iHolder) const
Definition: EventSetup.h:111
std::vector< PdtEntry > getPdtEntryVector(Entry const &e, char const *name)
Definition: PdtEntry.cc:60
HepPDT::ParticleData ParticleData
void setup(const edm::EventSetup &)
fill data from Event Setup
Definition: PdtEntry.cc:28
const HepPDT::ParticleData * data_
particle data
Definition: PdtEntry.h:42
const std::string & name() const
particle name
Definition: PdtEntry.cc:14
std::vector< int > getVInt32() const
Definition: Entry.cc:685
PdtEntry()
default construct
Definition: PdtEntry.h:22
HLT enums.
char typeCode() const
Definition: Entry.h:176
std::vector< std::string > getVString() const
Definition: Entry.cc:805
std::string getString() const
Definition: Entry.cc:793
int pdgId() const
PDG id.
Definition: PdtEntry.cc:7
const HepPDT::ParticleData & data() const
particle data
Definition: PdtEntry.cc:21