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 }
18 
19 class PdtEntry {
20 public:
22  explicit PdtEntry() : pdgId_(0), data_(nullptr) {}
24  explicit PdtEntry(int pdgId) : pdgId_(pdgId), data_(nullptr) {}
26  explicit PdtEntry(const std::string &name) : pdgId_(0), name_(name), data_(nullptr) {}
28  int pdgId() const;
30  const std::string &name() const;
32  const HepPDT::ParticleData &data() const;
34  void setup(const edm::EventSetup &);
35 
36 private:
38  int pdgId_;
43 };
44 
46 
47 namespace edm {
48  namespace pdtentry {
49  PdtEntry getPdtEntry(Entry const &e, char const *name);
50  std::vector<PdtEntry> getPdtEntryVector(Entry const &e, char const *name);
51  } // namespace pdtentry
52 
53  template <>
54  inline PdtEntry ParameterSet::getParameter<PdtEntry>(std::string const &name) const {
55  Entry const &e = retrieve(name);
56  return pdtentry::getPdtEntry(e, name.c_str());
57  }
58 
59  template <>
60  inline PdtEntry ParameterSet::getUntrackedParameter<PdtEntry>(std::string const &name) const {
61  Entry const *e = getEntryPointerOrThrow_(name);
62  return pdtentry::getPdtEntry(*e, name.c_str());
63  }
64 
65  template <>
66  inline PdtEntry ParameterSet::getUntrackedParameter<PdtEntry>(std::string const &name,
67  PdtEntry const &defaultValue) const {
68  Entry const *e = retrieveUntracked(name);
69  if (e == nullptr)
70  return defaultValue;
71  return pdtentry::getPdtEntry(*e, name.c_str());
72  }
73 
74  template <>
75  inline PdtEntry ParameterSet::getParameter<PdtEntry>(char const *name) const {
76  Entry const &e = retrieve(name);
77  return pdtentry::getPdtEntry(e, name);
78  }
79 
80  template <>
81  inline PdtEntry ParameterSet::getUntrackedParameter<PdtEntry>(char const *name) const {
82  Entry const *e = getEntryPointerOrThrow_(name);
83  return pdtentry::getPdtEntry(*e, name);
84  }
85 
86  template <>
87  inline PdtEntry ParameterSet::getUntrackedParameter<PdtEntry>(char const *name, PdtEntry const &defaultValue) const {
88  Entry const *e = retrieveUntracked(name);
89  if (e == nullptr)
90  return defaultValue;
91  return pdtentry::getPdtEntry(*e, name);
92  }
93 
94  template <>
95  inline std::vector<PdtEntry> ParameterSet::getParameter<std::vector<PdtEntry>>(std::string const &name) const {
96  Entry const &e = retrieve(name);
97  return pdtentry::getPdtEntryVector(e, name.c_str());
98  }
99 
100  template <>
101  inline std::vector<PdtEntry> ParameterSet::getUntrackedParameter<std::vector<PdtEntry>>(
102  std::string const &name) const {
103  Entry const *e = getEntryPointerOrThrow_(name);
104  return pdtentry::getPdtEntryVector(*e, name.c_str());
105  }
106 
107  template <>
108  inline std::vector<PdtEntry> ParameterSet::getUntrackedParameter<std::vector<PdtEntry>>(
109  std::string const &name, std::vector<PdtEntry> const &defaultValue) const {
110  Entry const *e = retrieveUntracked(name);
111  if (e == nullptr)
112  return defaultValue;
113  return pdtentry::getPdtEntryVector(*e, name.c_str());
114  }
115 
116  template <>
117  inline std::vector<PdtEntry> ParameterSet::getParameter<std::vector<PdtEntry>>(char const *name) const {
118  Entry const &e = retrieve(name);
119  return pdtentry::getPdtEntryVector(e, name);
120  }
121 
122  template <>
123  inline std::vector<PdtEntry> ParameterSet::getUntrackedParameter<std::vector<PdtEntry>>(char const *name) const {
124  Entry const *e = getEntryPointerOrThrow_(name);
125  return pdtentry::getPdtEntryVector(*e, name);
126  }
127 
128  template <>
129  inline std::vector<PdtEntry> ParameterSet::getUntrackedParameter<std::vector<PdtEntry>>(
130  char const *name, std::vector<PdtEntry> const &defaultValue) const {
131  Entry const *e = retrieveUntracked(name);
132  if (e == nullptr)
133  return defaultValue;
134  return pdtentry::getPdtEntryVector(*e, name);
135  }
136 
137  template <>
138  inline std::vector<std::string> ParameterSet::getParameterNamesForType<PdtEntry>(bool trackiness) const {
139  std::vector<std::string> ints = getParameterNamesForType<int>(trackiness);
140  std::vector<std::string> strings = getParameterNamesForType<std::string>(trackiness);
141  std::copy(strings.begin(), strings.end(), std::back_insert_iterator<std::vector<std::string>>(ints));
142  return ints;
143  }
144 
145  template <>
146  inline std::vector<std::string> ParameterSet::getParameterNamesForType<std::vector<PdtEntry>>(bool trackiness) const {
147  std::vector<std::string> ints = getParameterNamesForType<std::vector<int>>(trackiness);
148  std::vector<std::string> strings = getParameterNamesForType<std::vector<std::string>>(trackiness);
149  std::copy(strings.begin(), strings.end(), std::back_insert_iterator<std::vector<std::string>>(ints));
150  return ints;
151  }
152 
153 } // namespace edm
154 #endif
int pdgId_
PDG id.
Definition: PdtEntry.h:38
PdtEntry getPdtEntry(Entry const &e, char const *name)
Definition: PdtEntry.cc:49
PdtEntry(int pdgId)
construct from PDG id
Definition: PdtEntry.h:24
def copy(args, dbName)
#define nullptr
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
std::string name_
particle name
Definition: PdtEntry.h:40
std::vector< PdtEntry > getPdtEntryVector(Entry const &e, char const *name)
Definition: PdtEntry.cc:60
HepPDT::ParticleData ParticleData
const HepPDT::ParticleData * data_
particle data
Definition: PdtEntry.h:42
PdtEntry()
default construct
Definition: PdtEntry.h:22
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
PdtEntry(const std::string &name)
construct from particle name
Definition: PdtEntry.h:26