Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-28 03:10:21

0001 #ifndef Utilities_PdtEntry_h
0002 #define Utilities_PdtEntry_h
0003 /* \class PdtEntry
0004  *
0005  * \author Luca Lista, INFN
0006  *
0007  */
0008 #include <iterator>
0009 #include <string>
0010 #include <vector>
0011 
0012 namespace edm {
0013   class EventSetup;
0014 }
0015 namespace HepPDT {
0016   class ParticleData;
0017   class ParticleDataTable;
0018 }  // namespace HepPDT
0019 
0020 class PdtEntry {
0021 public:
0022   /// default construct
0023   explicit PdtEntry() : pdgId_(0), data_(nullptr) {}
0024   /// construct from PDG id
0025   explicit PdtEntry(int pdgId) : pdgId_(pdgId), data_(nullptr) {}
0026   /// construct from particle name
0027   explicit PdtEntry(const std::string &name) : pdgId_(0), name_(name), data_(nullptr) {}
0028   /// PDG id
0029   int pdgId() const;
0030   /// particle name
0031   const std::string &name() const;
0032   /// particle data
0033   const HepPDT::ParticleData &data() const;
0034   /// fill data from Event Setup
0035   void setup(const HepPDT::ParticleDataTable &);
0036 
0037 private:
0038   /// PDG id
0039   int pdgId_;
0040   /// particle name
0041   std::string name_;
0042   /// particle data
0043   const HepPDT::ParticleData *data_;
0044 };
0045 
0046 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0047 
0048 namespace edm {
0049   namespace pdtentry {
0050     PdtEntry getPdtEntry(Entry const &e, char const *name);
0051     std::vector<PdtEntry> getPdtEntryVector(Entry const &e, char const *name);
0052   }  // namespace pdtentry
0053 
0054   template <>
0055   inline PdtEntry ParameterSet::getParameter<PdtEntry>(std::string const &name) const {
0056     Entry const &e = retrieve(name);
0057     return pdtentry::getPdtEntry(e, name.c_str());
0058   }
0059 
0060   template <>
0061   inline PdtEntry ParameterSet::getUntrackedParameter<PdtEntry>(std::string const &name) const {
0062     Entry const *e = getEntryPointerOrThrow_(name);
0063     return pdtentry::getPdtEntry(*e, name.c_str());
0064   }
0065 
0066   template <>
0067   inline PdtEntry ParameterSet::getUntrackedParameter<PdtEntry>(std::string const &name,
0068                                                                 PdtEntry const &defaultValue) const {
0069     Entry const *e = retrieveUntracked(name);
0070     if (e == nullptr)
0071       return defaultValue;
0072     return pdtentry::getPdtEntry(*e, name.c_str());
0073   }
0074 
0075   template <>
0076   inline PdtEntry ParameterSet::getParameter<PdtEntry>(char const *name) const {
0077     Entry const &e = retrieve(name);
0078     return pdtentry::getPdtEntry(e, name);
0079   }
0080 
0081   template <>
0082   inline PdtEntry ParameterSet::getUntrackedParameter<PdtEntry>(char const *name) const {
0083     Entry const *e = getEntryPointerOrThrow_(name);
0084     return pdtentry::getPdtEntry(*e, name);
0085   }
0086 
0087   template <>
0088   inline PdtEntry ParameterSet::getUntrackedParameter<PdtEntry>(char const *name, PdtEntry const &defaultValue) const {
0089     Entry const *e = retrieveUntracked(name);
0090     if (e == nullptr)
0091       return defaultValue;
0092     return pdtentry::getPdtEntry(*e, name);
0093   }
0094 
0095   template <>
0096   inline std::vector<PdtEntry> ParameterSet::getParameter<std::vector<PdtEntry>>(std::string const &name) const {
0097     Entry const &e = retrieve(name);
0098     return pdtentry::getPdtEntryVector(e, name.c_str());
0099   }
0100 
0101   template <>
0102   inline std::vector<PdtEntry> ParameterSet::getUntrackedParameter<std::vector<PdtEntry>>(
0103       std::string const &name) const {
0104     Entry const *e = getEntryPointerOrThrow_(name);
0105     return pdtentry::getPdtEntryVector(*e, name.c_str());
0106   }
0107 
0108   template <>
0109   inline std::vector<PdtEntry> ParameterSet::getUntrackedParameter<std::vector<PdtEntry>>(
0110       std::string const &name, std::vector<PdtEntry> const &defaultValue) const {
0111     Entry const *e = retrieveUntracked(name);
0112     if (e == nullptr)
0113       return defaultValue;
0114     return pdtentry::getPdtEntryVector(*e, name.c_str());
0115   }
0116 
0117   template <>
0118   inline std::vector<PdtEntry> ParameterSet::getParameter<std::vector<PdtEntry>>(char const *name) const {
0119     Entry const &e = retrieve(name);
0120     return pdtentry::getPdtEntryVector(e, name);
0121   }
0122 
0123   template <>
0124   inline std::vector<PdtEntry> ParameterSet::getUntrackedParameter<std::vector<PdtEntry>>(char const *name) const {
0125     Entry const *e = getEntryPointerOrThrow_(name);
0126     return pdtentry::getPdtEntryVector(*e, name);
0127   }
0128 
0129   template <>
0130   inline std::vector<PdtEntry> ParameterSet::getUntrackedParameter<std::vector<PdtEntry>>(
0131       char const *name, std::vector<PdtEntry> const &defaultValue) const {
0132     Entry const *e = retrieveUntracked(name);
0133     if (e == nullptr)
0134       return defaultValue;
0135     return pdtentry::getPdtEntryVector(*e, name);
0136   }
0137 
0138   template <>
0139   inline std::vector<std::string> ParameterSet::getParameterNamesForType<PdtEntry>(bool trackiness) const {
0140     std::vector<std::string> ints = getParameterNamesForType<int>(trackiness);
0141     std::vector<std::string> strings = getParameterNamesForType<std::string>(trackiness);
0142     std::copy(strings.begin(), strings.end(), std::back_insert_iterator<std::vector<std::string>>(ints));
0143     return ints;
0144   }
0145 
0146   template <>
0147   inline std::vector<std::string> ParameterSet::getParameterNamesForType<std::vector<PdtEntry>>(bool trackiness) const {
0148     std::vector<std::string> ints = getParameterNamesForType<std::vector<int>>(trackiness);
0149     std::vector<std::string> strings = getParameterNamesForType<std::vector<std::string>>(trackiness);
0150     std::copy(strings.begin(), strings.end(), std::back_insert_iterator<std::vector<std::string>>(ints));
0151     return ints;
0152   }
0153 
0154 }  // namespace edm
0155 #endif