1 |
loizides |
1.1 |
//--------------------------------------------------------------------------------------------------
|
2 |
loizides |
1.14 |
// $Id: DataObject.h,v 1.13 2008/09/10 03:33:26 loizides Exp $
|
3 |
loizides |
1.1 |
//
|
4 |
|
|
// DataObject
|
5 |
|
|
//
|
6 |
loizides |
1.2 |
// This is the common base class for all objects in the tree.
|
7 |
|
|
//
|
8 |
bendavid |
1.11 |
// Authors: C.Loizides, J.Bendavid
|
9 |
loizides |
1.1 |
//--------------------------------------------------------------------------------------------------
|
10 |
|
|
|
11 |
loizides |
1.13 |
#ifndef MITANA_DATATREE_DATAOBJECT_H
|
12 |
|
|
#define MITANA_DATATREE_DATAOBJECT_H
|
13 |
loizides |
1.4 |
|
14 |
|
|
#include <TObject.h>
|
15 |
bendavid |
1.10 |
#include <TROOT.h>
|
16 |
|
|
#include <TClass.h>
|
17 |
|
|
#include <TBranchElement.h>
|
18 |
|
|
#include <TRefTable.h>
|
19 |
|
|
#include <TProcessID.h>
|
20 |
loizides |
1.4 |
#include "MitAna/DataTree/interface/Types.h"
|
21 |
|
|
|
22 |
paus |
1.12 |
namespace mithep
|
23 |
loizides |
1.1 |
{
|
24 |
|
|
class DataObject : public TObject
|
25 |
|
|
{
|
26 |
|
|
public:
|
27 |
|
|
DataObject() {}
|
28 |
|
|
~DataObject() {}
|
29 |
loizides |
1.6 |
|
30 |
loizides |
1.9 |
Bool_t MustClear() const { return TestBit(14); }
|
31 |
|
|
Bool_t MustDelete() const { return TestBit(15); }
|
32 |
|
|
Bool_t IsCached() const { return TestBit(23); }
|
33 |
bendavid |
1.11 |
template <class Col> const Col* ParentCol() const;
|
34 |
loizides |
1.6 |
|
35 |
|
|
protected:
|
36 |
|
|
void SetClearBit() { SetBit(14); }
|
37 |
loizides |
1.8 |
void SetDeleteBit() { SetBit(15); }
|
38 |
|
|
void SetCacheBit() { SetBit(23); }
|
39 |
|
|
void ResetCacheBit() { SetBit(23,0); }
|
40 |
loizides |
1.6 |
|
41 |
loizides |
1.14 |
ClassDef(DataObject, 1)
|
42 |
loizides |
1.1 |
};
|
43 |
loizides |
1.2 |
}
|
44 |
bendavid |
1.10 |
|
45 |
|
|
//--------------------------------------------------------------------------------------------------
|
46 |
|
|
template <class Col>
|
47 |
bendavid |
1.11 |
const Col* mithep::DataObject::ParentCol() const
|
48 |
bendavid |
1.10 |
{
|
49 |
bendavid |
1.11 |
// Return pointer to parent collection. SLOW! (But faster than looping over collections.)
|
50 |
|
|
// Also note this function will only work for objects which were reference prior to being written.
|
51 |
|
|
// Otherwise a null pointer will be returned.
|
52 |
bendavid |
1.10 |
|
53 |
bendavid |
1.11 |
const Col* colObj=0;
|
54 |
bendavid |
1.10 |
TRefTable *table = TRefTable::GetRefTable();
|
55 |
|
|
if (!table)
|
56 |
|
|
return colObj;
|
57 |
|
|
table->SetUID(this->GetUniqueID(), (TProcessID*)gROOT->GetUUIDs());
|
58 |
|
|
table->Notify();
|
59 |
bendavid |
1.11 |
//cast away const is a hack, this is fixed in newer root versions
|
60 |
|
|
TProcessID* pID = TProcessID::GetProcessWithUID(this->GetUniqueID(),(void*)this);
|
61 |
|
|
TBranchElement *trackParent = (TBranchElement*)(table->GetParent(this->GetUniqueID(), pID));
|
62 |
bendavid |
1.10 |
while (!colObj) {
|
63 |
|
|
if (!trackParent)
|
64 |
|
|
return colObj;
|
65 |
|
|
colObj = dynamic_cast<Col*>((TObject*)((TBranchElement*)trackParent)->GetObject());
|
66 |
|
|
if (!colObj)
|
67 |
|
|
trackParent = dynamic_cast<TBranchElement*>(trackParent->GetMother());
|
68 |
|
|
}
|
69 |
|
|
return colObj;
|
70 |
|
|
}
|
71 |
loizides |
1.3 |
#endif
|