1 |
bendavid |
1.1 |
//--------------------------------------------------------------------------------------------------
|
2 |
bendavid |
1.2 |
// $Id: Ref.h,v 1.1 2009/02/17 14:57:29 bendavid Exp $
|
3 |
bendavid |
1.1 |
//
|
4 |
|
|
// Ref
|
5 |
|
|
//
|
6 |
|
|
// Templated reimplimentation of TRef
|
7 |
|
|
//
|
8 |
|
|
// Authors: J.Bendavid
|
9 |
|
|
//--------------------------------------------------------------------------------------------------
|
10 |
|
|
|
11 |
|
|
#ifndef MITANA_DATACONT_REF_H
|
12 |
|
|
#define MITANA_DATACONT_REF_H
|
13 |
|
|
|
14 |
|
|
#include <TObject.h>
|
15 |
|
|
#include <TRefTable.h>
|
16 |
|
|
#include <TProcessID.h>
|
17 |
|
|
#include <TError.h>
|
18 |
bendavid |
1.2 |
#include "MitAna/TAM/interface/TAMSelector.h"
|
19 |
bendavid |
1.1 |
#include "MitAna/DataCont/interface/ProcIDRef.h"
|
20 |
|
|
|
21 |
|
|
namespace mithep
|
22 |
|
|
{
|
23 |
|
|
template<class ArrayElement>
|
24 |
|
|
class Ref
|
25 |
|
|
{
|
26 |
|
|
public:
|
27 |
|
|
Ref() : fPID(0), fUID(0) {}
|
28 |
|
|
Ref(const ArrayElement *ae) { SetObject(ae); }
|
29 |
|
|
virtual ~Ref() {}
|
30 |
|
|
|
31 |
|
|
Bool_t IsNull() const { return fUID==0 ? kTRUE : kFALSE; }
|
32 |
|
|
Bool_t IsValid() const { return !IsNull(); }
|
33 |
|
|
const ArrayElement *Obj() const;
|
34 |
|
|
ArrayElement *Obj();
|
35 |
|
|
Bool_t RefsObject(const ArrayElement *ae) const;
|
36 |
|
|
void SetObject(const ArrayElement *ae);
|
37 |
|
|
|
38 |
|
|
void operator= (const ArrayElement *ae) { SetObject(ae); }
|
39 |
|
|
Bool_t operator==(const ArrayElement *ae) { return RefsObject(ae); }
|
40 |
|
|
|
41 |
|
|
protected:
|
42 |
|
|
TObject *GetObject() const;
|
43 |
|
|
|
44 |
bendavid |
1.2 |
static Bool_t fOptimizedLoading;
|
45 |
bendavid |
1.1 |
ProcIDRef fPID;//||
|
46 |
|
|
UInt_t fUID;
|
47 |
|
|
|
48 |
|
|
ClassDef(Ref, 1) // Base class of all our collections
|
49 |
|
|
};
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
//--------------------------------------------------------------------------------------------------
|
53 |
|
|
template<class ArrayElement>
|
54 |
|
|
TObject *mithep::Ref<ArrayElement>::GetObject() const
|
55 |
|
|
{
|
56 |
|
|
// Return entry at given index. Code adapted from TRef::GetObject().
|
57 |
|
|
|
58 |
|
|
if (IsNull())
|
59 |
|
|
return 0;
|
60 |
|
|
|
61 |
|
|
TProcessID *pid= fPID.Pid();
|
62 |
|
|
|
63 |
|
|
if (!pid) {
|
64 |
|
|
Fatal("GetObject","Process id pointer is null!");
|
65 |
|
|
return 0;
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
if (!TProcessID::IsValid(pid)) {
|
69 |
|
|
Fatal("GetObject","Process id is invalid!");
|
70 |
|
|
return 0;
|
71 |
|
|
}
|
72 |
|
|
|
73 |
bendavid |
1.2 |
//try to autoload from TAM
|
74 |
|
|
TAMSelector *tSel = TAMSelector::GetEvtSelector();
|
75 |
|
|
if (tSel) {
|
76 |
|
|
return tSel->GetObjectWithID(fUID,pid);
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
//no TAM proxy present, fall back to standard Root calls
|
80 |
|
|
|
81 |
bendavid |
1.1 |
//the reference may be in the TRefTable
|
82 |
|
|
TRefTable *table = TRefTable::GetRefTable();
|
83 |
|
|
if (table) {
|
84 |
|
|
table->SetUID(fUID, pid);
|
85 |
|
|
table->Notify();
|
86 |
|
|
}
|
87 |
|
|
|
88 |
bendavid |
1.2 |
return pid->GetObjectWithID(fUID);
|
89 |
bendavid |
1.1 |
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
//--------------------------------------------------------------------------------------------------
|
93 |
|
|
template<class ArrayElement>
|
94 |
|
|
const ArrayElement *mithep::Ref<ArrayElement>::Obj() const
|
95 |
|
|
{
|
96 |
|
|
// Return entry at given index. Code adapted from TRef::GetObject().
|
97 |
|
|
|
98 |
|
|
return static_cast<const ArrayElement*>(GetObject());
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
//--------------------------------------------------------------------------------------------------
|
102 |
|
|
template<class ArrayElement>
|
103 |
|
|
ArrayElement *mithep::Ref<ArrayElement>::Obj()
|
104 |
|
|
{
|
105 |
|
|
// Return entry at given index. Code adapted from TRef::GetObject().
|
106 |
|
|
|
107 |
|
|
return static_cast<ArrayElement*>(GetObject());
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
//--------------------------------------------------------------------------------------------------
|
111 |
|
|
template<class ArrayElement>
|
112 |
|
|
Bool_t mithep::Ref<ArrayElement>::RefsObject(const ArrayElement *ae) const
|
113 |
|
|
{
|
114 |
|
|
// check whether RefArray contains a given object
|
115 |
|
|
|
116 |
|
|
if (IsNull())
|
117 |
|
|
return kFALSE;
|
118 |
|
|
|
119 |
|
|
if (!ae->TestBit(kIsReferenced))
|
120 |
|
|
return kFALSE;
|
121 |
|
|
|
122 |
|
|
UInt_t oUid = ae->GetUniqueID();
|
123 |
|
|
TProcessID *oPid = TProcessID::GetProcessWithUID(oUid, const_cast<ArrayElement*>(ae));
|
124 |
|
|
|
125 |
|
|
if ( (fUID&0xffffff)==(oUid&0xffffff) && fPID.Pid()->GetUniqueID()==oPid->GetUniqueID())
|
126 |
|
|
return kTRUE;
|
127 |
|
|
else
|
128 |
|
|
return kFALSE;
|
129 |
|
|
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
//--------------------------------------------------------------------------------------------------
|
133 |
|
|
template<class ArrayElement>
|
134 |
|
|
void mithep::Ref<ArrayElement>::SetObject(const ArrayElement *ae)
|
135 |
|
|
{
|
136 |
|
|
// Add new reference to object.
|
137 |
|
|
|
138 |
|
|
// check if the object can belong here and assign or get its uid
|
139 |
|
|
if (ae->TestBit(kHasUUID)) {
|
140 |
|
|
Fatal("Add", "Object can not be added as it has not UUID!");
|
141 |
|
|
return;
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
if (ae->TestBit(kIsReferenced)) {
|
145 |
|
|
fUID = ae->GetUniqueID();
|
146 |
|
|
fPID.SetPid(TProcessID::GetProcessWithUID(fUID, const_cast<ArrayElement*>(ae)));
|
147 |
|
|
} else {
|
148 |
|
|
fPID.SetPid(TProcessID::GetSessionProcessID());
|
149 |
|
|
fUID = TProcessID::AssignID(const_cast<ArrayElement*>(ae));
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
}
|
153 |
|
|
|
154 |
|
|
#endif
|