Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:30:36

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 if (e.typeCode() == 'Z')
0051         return PdtEntry(e.getString());
0052       else
0053         throw Exception(errors::Configuration, "EntryError")
0054             << "can not convert representation of " << name << " to value of type PdtEntry. "
0055             << "Please, provide a parameter either of type int32 or string.";
0056     }
0057 
0058     std::vector<PdtEntry> getPdtEntryVector(Entry const &e, char const *name) {
0059       std::vector<PdtEntry> ret;
0060       if (e.typeCode() == 'i') {
0061         std::vector<int> v(e.getVInt32());
0062         for (std::vector<int>::const_iterator i = v.begin(); i != v.end(); ++i)
0063           ret.push_back(PdtEntry(*i));
0064         return ret;
0065       } else if (e.typeCode() == 's') {
0066         std::vector<std::string> v(e.getVString());
0067         for (std::vector<std::string>::const_iterator i = v.begin(); i != v.end(); ++i)
0068           ret.push_back(PdtEntry(*i));
0069         return ret;
0070       } else if (e.typeCode() == 'z') {
0071         std::vector<std::string> v(e.getVString());
0072         for (std::vector<std::string>::const_iterator i = v.begin(); i != v.end(); ++i)
0073           ret.push_back(PdtEntry(*i));
0074         return ret;
0075       } else
0076         throw Exception(errors::Configuration, "EntryError")
0077             << "can not convert representation of " << name << " to value of type PdtEntry. "
0078             << "Please, provide a parameter either of type int32 or string.";
0079     }
0080   }  // namespace pdtentry
0081 }  // namespace edm