CMS 3D CMS Logo

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 "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
00005 
00006 using namespace std;
00007 using namespace edm;
00008 
00009 int PdtEntry::pdgId() const {
00010   if ( pdgId_ == 0 )
00011     throw cms::Exception( "ConfigError" )
00012       << "PdtEntry::pdgId was not set.\n"
00013       << "please, call PdtEntry::setup( const edm::EventSetup & es )";
00014   return pdgId_;
00015 }
00016 
00017 const string & PdtEntry::name() const {
00018   if ( name_.empty() )
00019     throw cms::Exception( "ConfigError" )
00020       << "PdtEntry::name was not set."
00021       << "please, call PdtEntry::setup( const edm::EventSetup & es )";
00022   return name_;
00023 }
00024 
00025 const HepPDT::ParticleData & PdtEntry::data() const { 
00026   if( data_ == 0 )
00027     throw cms::Exception( "ConfigError" )
00028       << "PdtEntry::name was not set."
00029       << "please, call PdtEntry::setup( const edm::EventSetup & es )";
00030   return * data_; 
00031 } 
00032 
00033 void PdtEntry::setup( const edm::EventSetup & es ) {
00034   ESHandle<HepPDT::ParticleDataTable> pdt;
00035   es.getData( pdt );
00036   const HepPDT::ParticleData * p = 0;
00037   if ( pdgId_ == 0 ) {
00038     p = pdt->particle( name_ );
00039     if ( p == 0 ) 
00040       throw cms::Exception( "ConfigError" )
00041         << "PDT has no entry for " << name_ << "."
00042         << "PdtEntry can't be set.";
00043     pdgId_ = p->pid();
00044   } else {
00045     p = pdt->particle( pdgId_ );
00046     if ( p == 0 ) 
00047       throw cms::Exception( "ConfigError" )
00048         << "PDT has no entry for " << pdgId_ << "."
00049         << "PdtEntry can't be set.";
00050     name_ = p->name();
00051   }
00052   data_ = p;
00053 }

Generated on Tue Jun 9 17:47:27 2009 for CMSSW by  doxygen 1.5.4