CMS 3D CMS Logo

PdtEntry.h
Go to the documentation of this file.
1 #ifndef Utilities_PdtEntry_h
2 #define Utilities_PdtEntry_h
3 /* \class PdtEntry
4  *
5  * \author Luca Lista, INFN
6  *
7  */
8 #include <iterator>
9 #include <string>
10 #include <vector>
11 
12 namespace edm {
13  class EventSetup;
14 }
15 namespace HepPDT {
16  class ParticleData;
17  class ParticleDataTable;
18 } // namespace HepPDT
19 
20 class PdtEntry {
21 public:
23  explicit PdtEntry() : pdgId_(0), data_(nullptr) {}
25  explicit PdtEntry(int pdgId) : pdgId_(pdgId), data_(nullptr) {}
27  explicit PdtEntry(const std::string &name) : pdgId_(0), name_(name), data_(nullptr) {}
29  int pdgId() const;
31  const std::string &name() const;
33  const HepPDT::ParticleData &data() const;
35  void setup(const HepPDT::ParticleDataTable &);
36 
37 private:
39  int pdgId_;
44 };
45 
47 
48 namespace edm {
49  namespace pdtentry {
50  PdtEntry getPdtEntry(Entry const &e, char const *name);
51  std::vector<PdtEntry> getPdtEntryVector(Entry const &e, char const *name);
52  } // namespace pdtentry
53 
54  template <>
55  inline PdtEntry ParameterSet::getParameter<PdtEntry>(std::string const &name) const {
56  Entry const &e = retrieve(name);
57  return pdtentry::getPdtEntry(e, name.c_str());
58  }
59 
60  template <>
61  inline PdtEntry ParameterSet::getUntrackedParameter<PdtEntry>(std::string const &name) const {
62  Entry const *e = getEntryPointerOrThrow_(name);
63  return pdtentry::getPdtEntry(*e, name.c_str());
64  }
65 
66  template <>
67  inline PdtEntry ParameterSet::getUntrackedParameter<PdtEntry>(std::string const &name,
68  PdtEntry const &defaultValue) const {
69  Entry const *e = retrieveUntracked(name);
70  if (e == nullptr)
71  return defaultValue;
72  return pdtentry::getPdtEntry(*e, name.c_str());
73  }
74 
75  template <>
76  inline PdtEntry ParameterSet::getParameter<PdtEntry>(char const *name) const {
77  Entry const &e = retrieve(name);
78  return pdtentry::getPdtEntry(e, name);
79  }
80 
81  template <>
82  inline PdtEntry ParameterSet::getUntrackedParameter<PdtEntry>(char const *name) const {
83  Entry const *e = getEntryPointerOrThrow_(name);
84  return pdtentry::getPdtEntry(*e, name);
85  }
86 
87  template <>
88  inline PdtEntry ParameterSet::getUntrackedParameter<PdtEntry>(char const *name, PdtEntry const &defaultValue) const {
89  Entry const *e = retrieveUntracked(name);
90  if (e == nullptr)
91  return defaultValue;
92  return pdtentry::getPdtEntry(*e, name);
93  }
94 
95  template <>
96  inline std::vector<PdtEntry> ParameterSet::getParameter<std::vector<PdtEntry>>(std::string const &name) const {
97  Entry const &e = retrieve(name);
98  return pdtentry::getPdtEntryVector(e, name.c_str());
99  }
100 
101  template <>
102  inline std::vector<PdtEntry> ParameterSet::getUntrackedParameter<std::vector<PdtEntry>>(
103  std::string const &name) const {
104  Entry const *e = getEntryPointerOrThrow_(name);
105  return pdtentry::getPdtEntryVector(*e, name.c_str());
106  }
107 
108  template <>
109  inline std::vector<PdtEntry> ParameterSet::getUntrackedParameter<std::vector<PdtEntry>>(
110  std::string const &name, std::vector<PdtEntry> const &defaultValue) const {
111  Entry const *e = retrieveUntracked(name);
112  if (e == nullptr)
113  return defaultValue;
114  return pdtentry::getPdtEntryVector(*e, name.c_str());
115  }
116 
117  template <>
118  inline std::vector<PdtEntry> ParameterSet::getParameter<std::vector<PdtEntry>>(char const *name) const {
119  Entry const &e = retrieve(name);
121  }
122 
123  template <>
124  inline std::vector<PdtEntry> ParameterSet::getUntrackedParameter<std::vector<PdtEntry>>(char const *name) const {
125  Entry const *e = getEntryPointerOrThrow_(name);
127  }
128 
129  template <>
130  inline std::vector<PdtEntry> ParameterSet::getUntrackedParameter<std::vector<PdtEntry>>(
131  char const *name, std::vector<PdtEntry> const &defaultValue) const {
132  Entry const *e = retrieveUntracked(name);
133  if (e == nullptr)
134  return defaultValue;
136  }
137 
138  template <>
139  inline std::vector<std::string> ParameterSet::getParameterNamesForType<PdtEntry>(bool trackiness) const {
140  std::vector<std::string> ints = getParameterNamesForType<int>(trackiness);
141  std::vector<std::string> strings = getParameterNamesForType<std::string>(trackiness);
142  std::copy(strings.begin(), strings.end(), std::back_insert_iterator<std::vector<std::string>>(ints));
143  return ints;
144  }
145 
146  template <>
147  inline std::vector<std::string> ParameterSet::getParameterNamesForType<std::vector<PdtEntry>>(bool trackiness) const {
148  std::vector<std::string> ints = getParameterNamesForType<std::vector<int>>(trackiness);
149  std::vector<std::string> strings = getParameterNamesForType<std::vector<std::string>>(trackiness);
150  std::copy(strings.begin(), strings.end(), std::back_insert_iterator<std::vector<std::string>>(ints));
151  return ints;
152  }
153 
154 } // namespace edm
155 #endif
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
PdtEntry(int pdgId)
construct from PDG id
Definition: PdtEntry.h:25
void setup(const HepPDT::ParticleDataTable &)
fill data from Event Setup
Definition: PdtEntry.cc:26
HepPDT::ParticleDataTable ParticleDataTable
std::string name_
particle name
Definition: PdtEntry.h:41
std::vector< PdtEntry > getPdtEntryVector(Entry const &e, char const *name)
Definition: PdtEntry.cc:56
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
PdtEntry()
default construct
Definition: PdtEntry.h:23
HLT enums.
ROOT::VecOps::RVec< int > ints
Definition: Resolutions.cc:4
PdtEntry(const std::string &name)
construct from particle name
Definition: PdtEntry.h:27