CMS 3D CMS Logo

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