ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataTree/interface/DataObject.h
Revision: 1.17
Committed: Tue Dec 9 17:46:59 2008 UTC (16 years, 4 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.16: +5 -2 lines
Log Message:
Added ObjType to retrieve type of object.

File Contents

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