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 {
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 {
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);
120  }
121 
122  template <>
123  inline std::vector<PdtEntry> ParameterSet::getUntrackedParameter<std::vector<PdtEntry>>(char const *name) const {
124  Entry const *e = getEntryPointerOrThrow_(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;
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
edm::ParameterSet::retrieve
Entry const & retrieve(char const *) const
Definition: ParameterSet.cc:226
PdtEntry::pdgId
int pdgId() const
PDG id.
Definition: PdtEntry.cc:7
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
edm
HLT enums.
Definition: AlignableModifier.h:19
PdtEntry::PdtEntry
PdtEntry()
default construct
Definition: PdtEntry.h:22
ParticleData
HepPDT::ParticleData ParticleData
Definition: ParticleDataTable.h:9
PdtEntry::PdtEntry
PdtEntry(const std::string &name)
construct from particle name
Definition: PdtEntry.h:26
nano_cff.strings
strings
Definition: nano_cff.py:25
PdtEntry::PdtEntry
PdtEntry(int pdgId)
construct from PDG id
Definition: PdtEntry.h:24
edm::ParameterSet::getEntryPointerOrThrow_
Entry const * getEntryPointerOrThrow_(std::string const &name) const
Definition: ParameterSet.cc:208
PdtEntry::data
const HepPDT::ParticleData & data() const
particle data
Definition: PdtEntry.cc:21
edm::ParameterSet::retrieveUntracked
Entry const * retrieveUntracked(char const *) const
Definition: ParameterSet.cc:247
PdtEntry::data_
const HepPDT::ParticleData * data_
particle data
Definition: PdtEntry.h:42
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HepPDT
Definition: ParticleManager.h:17
PdtEntry::setup
void setup(const edm::EventSetup &)
fill data from Event Setup
Definition: PdtEntry.cc:28
PdtEntry::name_
std::string name_
particle name
Definition: PdtEntry.h:40
edm::EventSetup
Definition: EventSetup.h:57
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
PdtEntry
Definition: PdtEntry.h:19
EventSetup
ParameterSet.h
PdtEntry::name
const std::string & name() const
particle name
Definition: PdtEntry.cc:14
PdtEntry::pdgId_
int pdgId_
PDG id.
Definition: PdtEntry.h:38
edm::Entry
Definition: Entry.h:40
edm::pdtentry::getPdtEntry
PdtEntry getPdtEntry(Entry const &e, char const *name)
Definition: PdtEntry.cc:49
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
edm::pdtentry::getPdtEntryVector
std::vector< PdtEntry > getPdtEntryVector(Entry const &e, char const *name)
Definition: PdtEntry.cc:60