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