Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "FWCore/Utilities/interface/EDMException.h"
0002 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
0003 #include "SimGeneral/HepPDTRecord/interface/PdtEntry.h"
0004 
0005 int PdtEntry::pdgId() const {
0006   if (pdgId_ == 0)
0007     throw cms::Exception("ConfigError") << "PdtEntry::pdgId was not set.\n"
0008                                         << "please, call PdtEntry::setup(const EventSetup & es)";
0009   return pdgId_;
0010 }
0011 
0012 std::string const &PdtEntry::name() const {
0013   if (name_.empty())
0014     throw cms::Exception("ConfigError") << "PdtEntry::name was not set."
0015                                         << "please, call PdtEntry::setup(const EventSetup & es)";
0016   return name_;
0017 }
0018 
0019 HepPDT::ParticleData const &PdtEntry::data() const {
0020   if (data_ == nullptr)
0021     throw cms::Exception("ConfigError") << "PdtEntry::name was not set."
0022                                         << "please, call PdtEntry::setup(const EventSetup & es)";
0023   return *data_;
0024 }
0025 
0026 void PdtEntry::setup(HepPDT::ParticleDataTable const &pdt) {
0027   HepPDT::ParticleData const *p = nullptr;
0028   if (pdgId_ == 0) {
0029     p = pdt.particle(name_);
0030     if (p == nullptr)
0031       throw cms::Exception("ConfigError") << "PDT has no entry for " << name_ << "."
0032                                           << "PdtEntry can't be set.";
0033     pdgId_ = p->pid();
0034   } else {
0035     p = pdt.particle(pdgId_);
0036     if (p == nullptr)
0037       throw cms::Exception("ConfigError") << "PDT has no entry for " << pdgId_ << "."
0038                                           << "PdtEntry can't be set.";
0039     name_ = p->name();
0040   }
0041   data_ = p;
0042 }
0043 namespace edm {
0044   namespace pdtentry {
0045     PdtEntry getPdtEntry(Entry const &e, char const *name) {
0046       if (e.typeCode() == 'I')
0047         return PdtEntry(e.getInt32());
0048       else if (e.typeCode() == 'S')
0049         return PdtEntry(e.getString());
0050       else
0051         throw Exception(errors::Configuration, "EntryError")
0052             << "can not convert representation of " << name << " to value of type PdtEntry. "
0053             << "Please, provide a parameter either of type int32 or string.";
0054     }
0055 
0056     std::vector<PdtEntry> getPdtEntryVector(Entry const &e, char const *name) {
0057       std::vector<PdtEntry> ret;
0058       if (e.typeCode() == 'i') {
0059         std::vector<int> v(e.getVInt32());
0060         for (std::vector<int>::const_iterator i = v.begin(); i != v.end(); ++i)
0061           ret.push_back(PdtEntry(*i));
0062         return ret;
0063       } else if (e.typeCode() == 's') {
0064         std::vector<std::string> v(e.getVString());
0065         for (std::vector<std::string>::const_iterator i = v.begin(); i != v.end(); ++i)
0066           ret.push_back(PdtEntry(*i));
0067         return ret;
0068       } else
0069         throw Exception(errors::Configuration, "EntryError")
0070             << "can not convert representation of " << name << " to value of type PdtEntry. "
0071             << "Please, provide a parameter either of type int32 or string.";
0072     }
0073   }  // namespace pdtentry
0074 }  // namespace edm