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