ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataTree/interface/DataObject.h
Revision: 1.16
Committed: Tue Dec 2 14:17:54 2008 UTC (16 years, 5 months ago) by bendavid
Content type: text/plain
Branch: MAIN
Changes since 1.15: +13 -7 lines
Log Message:
Fix broken casts

File Contents

# User Rev Content
1 loizides 1.1 //--------------------------------------------------------------------------------------------------
2 bendavid 1.16 // $Id: DataObject.h,v 1.15 2008/12/02 09:30:11 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.16
57     if ( !this->TestBit(kIsReferenced) )
58     return colObj;
59    
60 bendavid 1.10 TRefTable *table = TRefTable::GetRefTable();
61     if (!table)
62     return colObj;
63 bendavid 1.16
64     UInt_t uid = this->GetUniqueID();
65     //cast away const is a hack, this is fixed in newer root versions
66     TProcessID *pid = TProcessID::GetProcessWithUID(uid, const_cast<DataObject*>(this));
67     table->SetUID(uid, pid);
68     table->Notify();
69 loizides 1.15 TBranchElement *trackParent =
70 bendavid 1.16 static_cast<TBranchElement*>(table->GetParent(uid, pid));
71 bendavid 1.10 while (!colObj) {
72     if (!trackParent)
73     return colObj;
74 loizides 1.15 colObj = dynamic_cast<Col*>
75 bendavid 1.16 (reinterpret_cast<TObject*>(static_cast<TBranchElement*>(trackParent)->GetObject()));
76 loizides 1.15 if (colObj)
77     break;
78     trackParent = static_cast<TBranchElement*>(trackParent->GetMother());
79 bendavid 1.10 }
80 loizides 1.15 return colObj;
81 bendavid 1.10 }
82 loizides 1.3 #endif