ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataTree/interface/DataObject.h
Revision: 1.21
Committed: Fri Jun 19 07:41:34 2009 UTC (15 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.20: +2 -1 lines
Log Message:
Introduced ObjId which returns an integer as a specific reco id for ntupeling purposes.

File Contents

# User Rev Content
1 loizides 1.1 //--------------------------------------------------------------------------------------------------
2 loizides 1.21 // $Id: DataObject.h,v 1.20 2009/03/03 17:04:09 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 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 loizides 1.6
32 loizides 1.18 Bool_t Is(EObjType t) const { return (ObjType()==t); }
33     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 loizides 1.18 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     protected:
42 loizides 1.20 void ResetCacheBit() { SetBit(23,0); }
43     void SetCacheBit() { SetBit(23); }
44     void SetClearBit() { SetBit(14); }
45     void SetDeleteBit() { SetBit(15); }
46 loizides 1.6
47 loizides 1.19 ClassDef(DataObject, 1) // Common base for objects that do get referenced
48 loizides 1.1 };
49 loizides 1.2 }
50 bendavid 1.10
51     //--------------------------------------------------------------------------------------------------
52     template <class Col>
53 bendavid 1.11 const Col* mithep::DataObject::ParentCol() const
54 bendavid 1.10 {
55 loizides 1.15 // Return pointer to parent collection. SLOW, but faster than looping over collections!
56     // Also note this function will only work for objects which were referenced prior to being
57     // written. Otherwise a null pointer will be returned.
58 bendavid 1.10
59 loizides 1.19 if (!this->TestBit(kIsReferenced))
60     return 0;
61 bendavid 1.16
62 bendavid 1.10 TRefTable *table = TRefTable::GetRefTable();
63     if (!table)
64 loizides 1.19 return 0;
65 bendavid 1.16
66     UInt_t uid = this->GetUniqueID();
67 loizides 1.19 //cast away const is a hack, this is fixed in newer ROOT versions
68 bendavid 1.16 TProcessID *pid = TProcessID::GetProcessWithUID(uid, const_cast<DataObject*>(this));
69 loizides 1.19 if (!pid)
70     return 0;
71 bendavid 1.16 table->SetUID(uid, pid);
72     table->Notify();
73 loizides 1.19
74 loizides 1.15 TBranchElement *trackParent =
75 bendavid 1.16 static_cast<TBranchElement*>(table->GetParent(uid, pid));
76 loizides 1.19 if (!trackParent)
77     return 0;
78    
79     const Col *colObj=0;
80    
81 bendavid 1.10 while (!colObj) {
82     if (!trackParent)
83     return colObj;
84 loizides 1.15 colObj = dynamic_cast<Col*>
85 bendavid 1.16 (reinterpret_cast<TObject*>(static_cast<TBranchElement*>(trackParent)->GetObject()));
86 loizides 1.15 if (colObj)
87     break;
88     trackParent = static_cast<TBranchElement*>(trackParent->GetMother());
89 bendavid 1.10 }
90 loizides 1.15 return colObj;
91 bendavid 1.10 }
92 loizides 1.3 #endif