BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Event/GeneratorObject/include/GeneratorObject/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} // namespace HepMC
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 ), m_extBarcode( rhs.m_extBarcode ) {}
29 HepMcParticleLink( const HepMC::GenParticle* part,
30 const HepMC::GenEvent* pevt ); // FIXME NOT YET
31 //@}
32
33 /// \name pointer interface
34 //@{
35 /// @throws std::runtime_error when the element is not found
36 const HepMC::GenParticle& operator*() const { return *cptr(); } // FIXME
37 const HepMC::GenParticle* operator->() const { return cptr(); }
38 operator const HepMC::GenParticle*() const { return cptr(); }
39 bool operator!() const { return !isValid(); }
40 //@}
41
42 /// \name indexing accessors (e.g. for writing)
43 //@{
44 int barcode() const { return m_extBarcode.barcode(); }
45 index_type eventIndex() const { return m_extBarcode.eventIndex(); }
46 //@}
47
48 bool isValid() const { return ( 0 != cptr() ); }
49 const HepMC::GenParticle* cptr() const;
50
51private:
52 class ExtendedBarCode {
53 public:
54 ExtendedBarCode() : m_extBC( 0 ) {}
55 ExtendedBarCode( index_type barcode, index_type eventIndex ) {
56 assert( barcode < 0x1FFFFF ); // this is (1 << 21) - 1
57 assert( eventIndex < 0x7FF ); // this is (1 << 11) - 1
58 m_extBC = barcode + ( eventIndex << 21 );
59 }
60 ExtendedBarCode( const ExtendedBarCode& rhs ) : m_extBC( rhs.m_extBC ) {}
61
62 int barcode() const { return m_extBC & 0x1FFFFF; }
63 index_type eventIndex() const { return m_extBC >> 21; }
64
65 private:
66 // mutable int m_barcode : 21; //FIXME HepMC
67 // unsigned int m_eventIndex: 11;
68 unsigned int m_extBC;
69 };
70 mutable HepMC::GenParticle* m_particle; /* transient */
71 ExtendedBarCode m_extBarcode;
72};
73
74#endif