CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/SimGeneral/HepPDTRecord/src/PdtEntry.cc

Go to the documentation of this file.
00001 #include "SimGeneral/HepPDTRecord/interface/PdtEntry.h"
00002 #include "FWCore/Framework/interface/ESHandle.h"
00003 #include "FWCore/Framework/interface/EventSetup.h"
00004 #include "FWCore/Utilities/interface/EDMException.h"
00005 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
00006 
00007 int PdtEntry::pdgId() const {
00008   if (pdgId_ == 0)
00009     throw cms::Exception("ConfigError")
00010       << "PdtEntry::pdgId was not set.\n"
00011       << "please, call PdtEntry::setup(const EventSetup & es)";
00012   return pdgId_;
00013 }
00014 
00015 std::string const& PdtEntry::name() const {
00016   if (name_.empty())
00017     throw cms::Exception("ConfigError")
00018       << "PdtEntry::name was not set."
00019       << "please, call PdtEntry::setup(const EventSetup & es)";
00020   return name_;
00021 }
00022 
00023 HepPDT::ParticleData const& PdtEntry::data() const { 
00024   if(data_ == 0)
00025     throw cms::Exception("ConfigError")
00026       << "PdtEntry::name was not set."
00027       << "please, call PdtEntry::setup(const EventSetup & es)";
00028   return * data_; 
00029 } 
00030 
00031 void PdtEntry::setup(edm::EventSetup const& es) {
00032   edm::ESHandle<HepPDT::ParticleDataTable> pdt;
00033   es.getData(pdt);
00034   HepPDT::ParticleData const* p = 0;
00035   if (pdgId_ == 0) {
00036     p = pdt->particle(name_);
00037     if (p == 0) 
00038       throw cms::Exception("ConfigError")
00039         << "PDT has no entry for " << name_ << "."
00040         << "PdtEntry can't be set.";
00041     pdgId_ = p->pid();
00042   } else {
00043     p = pdt->particle(pdgId_);
00044     if (p == 0) 
00045       throw cms::Exception("ConfigError")
00046         << "PDT has no entry for " << pdgId_ << "."
00047         << "PdtEntry can't be set.";
00048     name_ = p->name();
00049   }
00050   data_ = p;
00051 }
00052 namespace edm {
00053   namespace pdtentry {
00054     PdtEntry getPdtEntry(Entry const& e, char const* name) {
00055       if (e.typeCode() == 'I')
00056         return PdtEntry(e.getInt32());
00057       else if(e.typeCode() == 'S') 
00058         return PdtEntry(e.getString());
00059       else 
00060         throw Exception(errors::Configuration, "EntryError")
00061           << "can not convert representation of " << name 
00062           << " to value of type PdtEntry. "
00063           << "Please, provide a parameter either of type int32 or string.";
00064     }
00065 
00066     std::vector<PdtEntry> getPdtEntryVector(Entry const& e, char const* name) {
00067       std::vector<PdtEntry> ret;
00068       if (e.typeCode() == 'i') { 
00069         std::vector<int> v(e.getVInt32());
00070         for(std::vector<int>::const_iterator i = v.begin(); i != v.end(); ++ i)
00071           ret.push_back(PdtEntry(*i));
00072         return ret;
00073       }
00074       else if(e.typeCode() == 's') {
00075         std::vector<std::string> v(e.getVString());
00076         for(std::vector<std::string>::const_iterator i = v.begin(); i != v.end(); ++i)
00077           ret.push_back(PdtEntry(*i));
00078         return ret;
00079       }
00080       else 
00081         throw Exception(errors::Configuration, "EntryError")
00082         << "can not convert representation of " << name 
00083         << " to value of type PdtEntry. "
00084         << "Please, provide a parameter either of type int32 or string.";
00085     }
00086   }
00087 }