ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataTree/interface/DataObject.h
Revision: 1.23
Committed: Wed Mar 28 12:15:34 2012 UTC (13 years, 1 month ago) by paus
Content type: text/plain
Branch: MAIN
Changes since 1.22: +18 -10 lines
Log Message:
Enable skimming.

File Contents

# User Rev Content
1 loizides 1.1 //--------------------------------------------------------------------------------------------------
2 paus 1.23 // $Id: DataObject.h,v 1.22 2009/07/13 11:00:25 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 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 paus 1.23 #include "MitAna/DataCont/interface/CacheFlag.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 paus 1.23 DataObject() : fMarker(0) {}
31 loizides 1.6
32 loizides 1.18 Bool_t Is(EObjType t) const { return (ObjType()==t); }
33 paus 1.23 Bool_t IsCached() const { return TestBit(23); }
34     Bool_t MustClear() const { return TestBit(14); }
35     Bool_t MustDelete() const { return TestBit(15); }
36 loizides 1.21 virtual Int_t ObjId() const { return ObjType()*1000; }
37 paus 1.23 virtual EObjType ObjType() const { return kDataObject; }
38 loizides 1.15 template <class Col>
39 loizides 1.18 const Col *ParentCol() const;
40 loizides 1.6
41 paus 1.23 // Object marking
42     Bool_t IsMarked() const { return TestBit(16); }
43     void Mark() const { const_cast<DataObject*>(this)->SetBit(16); }
44     void Unmark() const { const_cast<DataObject*>(this)->SetBit(16,0); }
45    
46 loizides 1.6 protected:
47 paus 1.23 void ResetCacheBit() { SetBit(23,0); }
48     void SetCacheBit() { SetBit(23); }
49     void SetClearBit() { SetBit(14); }
50     void SetDeleteBit() { SetBit(15); }
51    
52     mutable UInt_t fMarker; //! marker uses custom streamer
53 loizides 1.6
54 loizides 1.19 ClassDef(DataObject, 1) // Common base for objects that do get referenced
55 loizides 1.1 };
56 loizides 1.2 }
57 bendavid 1.10
58     //--------------------------------------------------------------------------------------------------
59     template <class Col>
60 bendavid 1.11 const Col* mithep::DataObject::ParentCol() const
61 bendavid 1.10 {
62 loizides 1.15 // Return pointer to parent collection. SLOW, but faster than looping over collections!
63     // Also note this function will only work for objects which were referenced prior to being
64     // written. Otherwise a null pointer will be returned.
65 bendavid 1.10
66 loizides 1.19 if (!this->TestBit(kIsReferenced))
67     return 0;
68 bendavid 1.16
69 bendavid 1.10 TRefTable *table = TRefTable::GetRefTable();
70     if (!table)
71 loizides 1.19 return 0;
72 bendavid 1.16
73     UInt_t uid = this->GetUniqueID();
74 loizides 1.19 //cast away const is a hack, this is fixed in newer ROOT versions
75 bendavid 1.16 TProcessID *pid = TProcessID::GetProcessWithUID(uid, const_cast<DataObject*>(this));
76 loizides 1.19 if (!pid)
77     return 0;
78 bendavid 1.16 table->SetUID(uid, pid);
79     table->Notify();
80 loizides 1.19
81 loizides 1.15 TBranchElement *trackParent =
82 bendavid 1.16 static_cast<TBranchElement*>(table->GetParent(uid, pid));
83 loizides 1.19 if (!trackParent)
84     return 0;
85    
86     const Col *colObj=0;
87    
88 bendavid 1.10 while (!colObj) {
89     if (!trackParent)
90     return colObj;
91 loizides 1.15 colObj = dynamic_cast<Col*>
92 bendavid 1.16 (reinterpret_cast<TObject*>(static_cast<TBranchElement*>(trackParent)->GetObject()));
93 loizides 1.15 if (colObj)
94     break;
95     trackParent = static_cast<TBranchElement*>(trackParent->GetMother());
96 bendavid 1.10 }
97 loizides 1.15 return colObj;
98 bendavid 1.10 }
99 loizides 1.3 #endif