ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataCont/interface/Ref.h
(Generate patch)

Comparing UserCode/MitAna/DataCont/interface/Ref.h (file contents):
Revision 1.2 by bendavid, Tue Feb 17 21:54:35 2009 UTC vs.
Revision 1.8 by paus, Wed Jul 25 03:08:40 2012 UTC

# Line 3 | Line 3
3   //
4   // Ref
5   //
6 < // Templated reimplimentation of TRef
6 > // Templated implementation of our own TRef.
7   //
8   // Authors: J.Bendavid
9   //--------------------------------------------------------------------------------------------------
# Line 15 | Line 15
15   #include <TRefTable.h>
16   #include <TProcessID.h>
17   #include <TError.h>
18 < #include "MitAna/TAM/interface/TAMSelector.h"
18 > #include "MitAna/DataCont/interface/RefResolver.h"
19   #include "MitAna/DataCont/interface/ProcIDRef.h"
20  
21   namespace mithep
# Line 24 | Line 24 | namespace mithep
24    class Ref
25    {
26      public:
27 <      Ref() : fPID(0), fUID(0) {}
27 >      Ref() : fPID(0), fUID(0)    {}
28        Ref(const ArrayElement *ae) { SetObject(ae); }
29 <      virtual ~Ref() {}
29 >      virtual ~Ref()              {}
30  
31        Bool_t                       IsNull()        const { return fUID==0 ? kTRUE : kFALSE; }
32 <      Bool_t                       IsValid()       const { return !IsNull(); }
32 >      Bool_t                       IsValid()       const { return !IsNull();                }
33        const ArrayElement          *Obj()           const;
34        ArrayElement                *Obj();
35        Bool_t                       RefsObject(const ArrayElement *ae) const;
36        void                         SetObject(const ArrayElement *ae);
37        
38 <      void                         operator= (const ArrayElement *ae) { SetObject(ae); }
38 >      void                         operator= (const ArrayElement *ae) { SetObject(ae);         }
39        Bool_t                       operator==(const ArrayElement *ae) { return RefsObject(ae); }
40  
41      protected:
42        TObject                     *GetObject()     const;
43    
44      static Bool_t                fOptimizedLoading;
45      ProcIDRef                    fPID;//||
46      UInt_t                       fUID;
43  
44 <    ClassDef(Ref, 1) // Base class of all our collections
44 >      ProcIDRef                    fPID;     //||process id corresponding to referenced object
45 >      UInt_t                       fUID;     //unique id of the referenced object
46 >
47 >    ClassDef(Ref, 1) // Templated implementation of our own TRef
48    };
49   }
50  
# Line 53 | Line 52 | namespace mithep
52   template<class ArrayElement>
53   TObject *mithep::Ref<ArrayElement>::GetObject() const
54   {
55 <  // Return entry at given index. Code adapted from TRef::GetObject().
55 >  // Return pointer to object. Code adapted from TRef::GetObject().
56  
57    if (IsNull())
58      return 0;
59    
60 <  TProcessID *pid= fPID.Pid();
62 <  
60 >  TProcessID *pid = fPID.Pid();
61    if (!pid) {
62      Fatal("GetObject","Process id pointer is null!");
63      return 0;
# Line 70 | Line 68 | TObject *mithep::Ref<ArrayElement>::GetO
68      return 0;
69    }
70  
71 <  //try to autoload from TAM
72 <  TAMSelector *tSel = TAMSelector::GetEvtSelector();
73 <  if (tSel) {
76 <    return tSel->GetObjectWithID(fUID,pid);
77 <  }
78 <  
79 <  //no TAM proxy present, fall back to standard Root calls
80 <  
81 <  //the reference may be in the TRefTable
82 <  TRefTable *table = TRefTable::GetRefTable();
83 <  if (table) {
84 <    table->SetUID(fUID, pid);
85 <    table->Notify();
71 >  TObject *obj = RefResolver::GetObjectWithID(fUID,pid);
72 >  if (!obj) {
73 >    Fatal("Ref::GetObject","Null pointer for valid ref!");
74    }
87
88  return pid->GetObjectWithID(fUID);
75    
76 +  return obj;
77   }
78  
79   //--------------------------------------------------------------------------------------------------
# Line 95 | Line 82 | const ArrayElement *mithep::Ref<ArrayEle
82   {
83    // Return entry at given index. Code adapted from TRef::GetObject().
84  
85 <  return static_cast<const ArrayElement*>(GetObject());
85 >  return reinterpret_cast<const ArrayElement*>(GetObject());
86   }
87  
88   //--------------------------------------------------------------------------------------------------
# Line 104 | Line 91 | ArrayElement *mithep::Ref<ArrayElement>:
91   {
92    // Return entry at given index. Code adapted from TRef::GetObject().
93  
94 <  return static_cast<ArrayElement*>(GetObject());
94 >  return reinterpret_cast<ArrayElement*>(GetObject());
95   }
96  
97   //--------------------------------------------------------------------------------------------------
98   template<class ArrayElement>
99   Bool_t mithep::Ref<ArrayElement>::RefsObject(const ArrayElement *ae) const
100   {
101 <  // check whether RefArray contains a given object
101 >  // Check whether Ref points to given object.
102  
103    if (IsNull())
104      return kFALSE;
105 +
106 +  const TObject *oe = reinterpret_cast<const TObject*>(ae);
107    
108 <  if (!ae->TestBit(kIsReferenced))
108 >  if (!oe->TestBit(kIsReferenced))
109      return kFALSE;
110  
111 <  UInt_t oUid = ae->GetUniqueID();
112 <  TProcessID *oPid = TProcessID::GetProcessWithUID(oUid, const_cast<ArrayElement*>(ae));
113 <
125 <  if ( (fUID&0xffffff)==(oUid&0xffffff) && fPID.Pid()->GetUniqueID()==oPid->GetUniqueID())
126 <    return kTRUE;
127 <  else
111 >  UInt_t oUid = oe->GetUniqueID();
112 >  TProcessID *oPid = TProcessID::GetProcessWithUID(oUid, const_cast<TObject*>(oe));
113 >  if (!oPid)
114      return kFALSE;
115  
116 +  if ( (fUID&0xffffff)!=(oUid&0xffffff) || fPID.Pid()->GetUniqueID()!=oPid->GetUniqueID())
117 +    return kFALSE;
118 +  return kTRUE;
119   }
120  
121   //--------------------------------------------------------------------------------------------------
122   template<class ArrayElement>
123   void mithep::Ref<ArrayElement>::SetObject(const ArrayElement *ae)
124   {
125 <  // Add new reference to object.
125 >  // Set reference to object.
126 >
127 >  if (!ae)
128 >    return;
129 >
130 >  const TObject *oe = reinterpret_cast<const TObject*>(ae);
131 >
132  
133    // check if the object can belong here and assign or get its uid
134 <  if (ae->TestBit(kHasUUID)) {
135 <    Fatal("Add", "Object can not be added as it has not UUID!");
134 >  if (oe->TestBit(kHasUUID)) {
135 >    Fatal("Add", "Object cannot be added as it has not UUID!");
136      return;
137    }
138  
139 <  if (ae->TestBit(kIsReferenced)) {
140 <    fUID = ae->GetUniqueID();
141 <    fPID.SetPid(TProcessID::GetProcessWithUID(fUID, const_cast<ArrayElement*>(ae)));
139 >  if (oe->TestBit(kIsReferenced)) {
140 >    fUID = oe->GetUniqueID();
141 >    fPID.SetPid(TProcessID::GetProcessWithUID(fUID, const_cast<TObject*>(oe)));
142    } else {
143      fPID.SetPid(TProcessID::GetSessionProcessID());
144 <    fUID = TProcessID::AssignID(const_cast<ArrayElement*>(ae));
144 >    fUID = TProcessID::AssignID(const_cast<TObject*>(oe));
145    }
151
146   }
153
147   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines