BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
HepMcParticleLink.h
Go to the documentation of this file.
1#ifndef GENERATOROBJECTS_HEPMCPARTICLELINK_H
2#define GENERATOROBJECTS_HEPMCPARTICLELINK_H
3/** @class HepMcParticleLink
4 * @brief a link optimized in size for a GenParticle in a McEventCollection
5 *
6 * @see McEventCollection, GenEvent, ElementLink
7 * @author Paolo Calafiura
8 * $Id: HepMcParticleLink.h,v 1.1.1.1 2004/09/28 06:40:36 liwd Exp $
9 **/
10#include <cassert>
11
12namespace HepMC {
13 class GenParticle;
14 class GenEvent;
15}
16
18public:
19 typedef unsigned int index_type;
20
21 /// \name structors
22 //@{
23 HepMcParticleLink() : m_particle(0), m_extBarcode() {}
25 m_particle(0), m_extBarcode(barCode, eventIndex) {}
26 HepMcParticleLink(const HepMC::GenParticle* p, index_type eventIndex = 0);
28 m_particle(rhs.m_particle),
29 m_extBarcode(rhs.m_extBarcode) {}
30 HepMcParticleLink(const HepMC::GenParticle* part,
31 const HepMC::GenEvent* pevt); //FIXME NOT YET
32 //@}
33
34 /// \name pointer interface
35 //@{
36 /// @throws std::runtime_error when the element is not found
37 const HepMC::GenParticle& operator* () const { return *cptr(); }//FIXME
38 const HepMC::GenParticle* operator->() const { return cptr(); }
39 operator const HepMC::GenParticle* () const { return cptr(); }
40 bool operator!() const {return !isValid();}
41 //@}
42
43 /// \name indexing accessors (e.g. for writing)
44 //@{
45 int barcode() const { return m_extBarcode.barcode(); }
46 index_type eventIndex() const { return m_extBarcode.eventIndex(); }
47 //@}
48
49 bool isValid() const { return (0 != cptr()); }
50 const HepMC::GenParticle* cptr() const;
51
52private:
53 class ExtendedBarCode {
54 public:
55 ExtendedBarCode() : m_extBC(0) {}
56 ExtendedBarCode(index_type barcode, index_type eventIndex) {
57 assert(barcode < 0x1FFFFF); // this is (1 << 21) - 1
58 assert(eventIndex < 0x7FF); // this is (1 << 11) - 1
59 m_extBC = barcode + (eventIndex << 21);
60 }
61 ExtendedBarCode(const ExtendedBarCode& rhs) :
62 m_extBC(rhs.m_extBC) {}
63
64 int barcode() const { return m_extBC & 0x1FFFFF; }
65 index_type eventIndex() const { return m_extBC >> 21; }
66 private:
67 // mutable int m_barcode : 21; //FIXME HepMC
68 // unsigned int m_eventIndex: 11;
69 unsigned int m_extBC;
70 };
71 mutable HepMC::GenParticle* m_particle; /* transient */
72 ExtendedBarCode m_extBarcode;
73};
74
75#endif