Logo ROOT   6.19/01
Reference Guide
Go to the documentation of this file.
1 // @(#)root/cont:$Id$
2 // Author: Rene Brun 28/09/2001
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
12 #ifndef ROOT_TProcessID
13 #define ROOT_TProcessID
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TProcessID //
19 // //
20 // Process Identifier object //
21 // //
22 //////////////////////////////////////////////////////////////////////////
25 #include "TNamed.h"
26 #include "TObjArray.h"
28 #include <atomic>
29 #include <type_traits>
31 class TExMap;
33 namespace ROOT {
34  namespace Internal {
35  /**
36  * \class ROOT::Internal::TAtomicPointer
37  * \brief Helper class to manage atomic pointers.
38  * \tparam T Pointer type to be made atomic
39  *
40  * Helper class to manage atomic pointers. The class enforces that the templated type
41  * is a pointer.
42  */
43  template <typename T> class TAtomicPointer {
44  private:
45  std::atomic<T> fAtomic;
47  public:
48  TAtomicPointer() : fAtomic(nullptr)
49  {
50  static_assert(std::is_pointer<T>::value, "Only pointer types supported");
51  }
53  ~TAtomicPointer() { delete fAtomic.load(); }
55  T operator->() const { return fAtomic; }
57  operator T() const { return fAtomic; }
59  T operator=(const T& t)
60  {
61  fAtomic = t;
62  return t;
63  }
64  };
65  } // End of namespace Internal
66 } // End of namespace ROOT
69 class TProcessID : public TNamed {
71 private:
72  TProcessID(const TProcessID &ref); // TProcessID are not copiable.
73  TProcessID& operator=(const TProcessID &ref); // TProcessID are not copiable.
75 protected:
76  std::atomic_int fCount; //!Reference count to this object (from TFile)
77  ROOT::Internal::TAtomicPointer<TObjArray*> fObjects; //!Array pointing to the referenced objects
78  std::atomic_flag fLock; //!Spin lock for initialization of fObjects
80  static TProcessID *fgPID; //Pointer to current session ProcessID
81  static TObjArray *fgPIDs; //Table of ProcessIDs
82  static TExMap *fgObjPIDs; //Table pointer to pids
84  static std::atomic_uint fgNumber; //Referenced objects count
86 public:
87  TProcessID();
88  virtual ~TProcessID();
89  void CheckInit();
90  virtual void Clear(Option_t *option="");
93  Int_t GetCount() const {return fCount;}
94  TObjArray *GetObjects() const {return fObjects;}
96  void PutObjectWithID(TObject *obj, UInt_t uid=0);
97  virtual void RecursiveRemove(TObject *obj);
99  static TProcessID *AddProcessID();
100  static UInt_t AssignID(TObject *obj);
101  static void Cleanup();
102  static UInt_t GetNProcessIDs();
103  static TProcessID *GetPID();
104  static TObjArray *GetPIDs();
105  static TProcessID *GetProcessID(UShort_t pid);
106  static TProcessID *GetProcessWithUID(const TObject *obj);
107  static TProcessID *GetProcessWithUID(UInt_t uid,const void *obj);
109  static UInt_t GetObjectCount();
110  static Bool_t IsValid(TProcessID *pid);
111  static void SetObjectCount(UInt_t number);
113  ClassDef(TProcessID,1) //Process Unique Identifier in time and space
114 };
116 #endif
static TProcessID * GetPID()
static: returns pointer to current TProcessID
Definition: TProcessID.cxx:341
static TProcessID * GetProcessID(UShort_t pid)
static function returning a pointer to TProcessID number pid in fgPIDs
Definition: TProcessID.cxx:246
ROOT::Internal::TAtomicPointer< TObjArray * > fObjects
Reference count to this object (from TFile)
Definition: TProcessID.h:77
virtual void RecursiveRemove(TObject *obj)
called by the object destructor remove reference to obj from the current table if it is referenced ...
Definition: TProcessID.cxx:410
void PutObjectWithID(TObject *obj, UInt_t uid=0)
stores the object at the uid th slot in the table of objects The object uniqued is set as well as its...
Definition: TProcessID.cxx:381
An array of TObjects.
Definition: TObjArray.h:37
VSD Structures.
Definition: StringConv.hxx:21
Int_t GetCount() const
Definition: TProcessID.h:93
const char Option_t
Definition: RtypesCore.h:62
double T(double x)
Definition: ChebyshevPol.h:34
static UInt_t GetNProcessIDs()
Return the (static) number of process IDs.
Definition: TProcessID.cxx:254
unsigned short UShort_t
Definition: RtypesCore.h:36
std::atomic< T > fAtomic
Definition: TProcessID.h:45
virtual ~TProcessID()
Definition: TProcessID.cxx:93
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
static TObjArray * GetPIDs()
static: returns array of TProcessIDs
Definition: TProcessID.cxx:349
static TObjArray * fgPIDs
Definition: TProcessID.h:81
#define ClassDef(name, id)
Definition: Rtypes.h:326
static TProcessID * fgPID
Spin lock for initialization of fObjects.
Definition: TProcessID.h:80
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
static std::atomic_uint fgNumber
Definition: TProcessID.h:84
static void SetObjectCount(UInt_t number)
static function to set the current referenced object count fgNumber is incremented every time a new o...
Definition: TProcessID.cxx:430
TObjArray * GetObjects() const
Definition: TProcessID.h:94
A TProcessID identifies a ROOT job in a unique way in time and space.
Definition: TProcessID.h:69
Helper class to manage atomic pointers.
Definition: TProcessID.h:43
static void Cleanup()
static function (called by TROOT destructor) to delete all TProcessIDs
Definition: TProcessID.cxx:202
TProcessID & operator=(const TProcessID &ref)
static TProcessID * GetProcessWithUID(const TObject *obj)
static function returning a pointer to TProcessID with its pid encoded in the highest byte of obj->Ge...
Definition: TProcessID.cxx:295
Default constructor.
Definition: TProcessID.cxx:75
std::atomic_flag fLock
Array pointing to the referenced objects.
Definition: TProcessID.h:78
Int_t IncrementCount()
Increase the reference count to this object.
Definition: TProcessID.cxx:311
unsigned int UInt_t
Definition: RtypesCore.h:42
Int_t DecrementCount()
The reference fCount is used to delete the TProcessID in the TFile destructor when fCount = 0...
Definition: TProcessID.cxx:236
static TProcessID * AddProcessID()
Static function to add a new TProcessID to the list of PIDs.
Definition: TProcessID.cxx:114
TObject * GetObjectWithID(UInt_t uid)
returns the TObject with unique identifier uid in the table of objects
Definition: TProcessID.cxx:330
void CheckInit()
Initialize fObjects.
Definition: TProcessID.cxx:190
static TExMap * fgObjPIDs
Definition: TProcessID.h:82
virtual void Clear(Option_t *option="")
delete the TObjArray pointing to referenced objects this function is called by TFile::Close("R") ...
Definition: TProcessID.cxx:216
static TProcessID * GetSessionProcessID()
static function returning the pointer to the session TProcessID
Definition: TProcessID.cxx:303
std::atomic_int fCount
Definition: TProcessID.h:76
Mother of all ROOT objects.
Definition: TObject.h:37
static UInt_t AssignID(TObject *obj)
static function returning the ID assigned to obj If the object is not yet referenced, its kIsReferenced bit is set and its fUniqueID set to the current number of referenced objects so far.
Definition: TProcessID.cxx:153
static UInt_t GetObjectCount()
Return the current referenced object count fgNumber is incremented every time a new object is referen...
Definition: TProcessID.cxx:322
static Bool_t IsValid(TProcessID *pid)
static function. return kTRUE if pid is a valid TProcessID
Definition: TProcessID.cxx:358
This class stores a (key,value) pair using an external hash.
Definition: TExMap.h:33