00001 #ifndef GENERATOROBJECTS_HEPMCPARTICLELINK_H 00002 #define GENERATOROBJECTS_HEPMCPARTICLELINK_H 00003 00010 #include <cassert> 00011 00012 namespace HepMC { 00013 class GenParticle; 00014 class GenEvent; 00015 } 00016 00017 class HepMcParticleLink { 00018 public: 00019 typedef unsigned int index_type; 00020 00022 00023 HepMcParticleLink() : m_particle(0), m_extBarcode() {} 00024 HepMcParticleLink(index_type barCode, index_type eventIndex = 0) : 00025 m_particle(0), m_extBarcode(barCode, eventIndex) {} 00026 HepMcParticleLink(const HepMC::GenParticle* p, index_type eventIndex = 0); 00027 HepMcParticleLink(const HepMcParticleLink& rhs) : 00028 m_particle(rhs.m_particle), 00029 m_extBarcode(rhs.m_extBarcode) {} 00030 HepMcParticleLink(const HepMC::GenParticle* part, 00031 const HepMC::GenEvent* pevt); //FIXME NOT YET 00033 00035 00036 00037 const HepMC::GenParticle& operator* () const { return *cptr(); }//FIXME 00038 const HepMC::GenParticle* operator->() const { return cptr(); } 00039 operator const HepMC::GenParticle* () const { return cptr(); } 00040 bool operator!() const {return !isValid();} 00042 00044 00045 int barcode() const { return m_extBarcode.barcode(); } 00046 index_type eventIndex() const { return m_extBarcode.eventIndex(); } 00048 00049 bool isValid() const { return (0 != cptr()); } 00050 const HepMC::GenParticle* cptr() const; 00051 00052 private: 00053 class ExtendedBarCode { 00054 public: 00055 ExtendedBarCode() : m_extBC(0) {} 00056 ExtendedBarCode(index_type barcode, index_type eventIndex) { 00057 assert(barcode < 0x1FFFFF); // this is (1 << 21) - 1 00058 assert(eventIndex < 0x7FF); // this is (1 << 11) - 1 00059 m_extBC = barcode + (eventIndex << 21); 00060 } 00061 ExtendedBarCode(const ExtendedBarCode& rhs) : 00062 m_extBC(rhs.m_extBC) {} 00063 00064 int barcode() const { return m_extBC & 0x1FFFFF; } 00065 index_type eventIndex() const { return m_extBC >> 21; } 00066 private: 00067 // mutable int m_barcode : 21; //FIXME HepMC 00068 // unsigned int m_eventIndex: 11; 00069 unsigned int m_extBC; 00070 }; 00071 mutable HepMC::GenParticle* m_particle; /* transient */ 00072 ExtendedBarCode m_extBarcode; 00073 }; 00074 00075 #endif