Logo ROOT   6.10/00
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TProcessID.h
Go to the documentation of this file.
1 // @(#)root/cont:$Id$
2 // Author: Rene Brun 28/09/2001
3 
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  *************************************************************************/
11 
12 #ifndef ROOT_TProcessID
13 #define ROOT_TProcessID
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TProcessID //
19 // //
20 // Process Identifier object //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 
25 #include "TNamed.h"
26 #include "TObjArray.h"
27 
28 #include <atomic>
29 #include <type_traits>
30 
31 class TExMap;
32 
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;
46 
47  public:
48  TAtomicPointer() : fAtomic(nullptr)
49  {
50  static_assert(std::is_pointer<T>::value, "Only pointer types supported");
51  }
52 
53  ~TAtomicPointer() { delete fAtomic.load(); }
54 
55  T operator->() const { return fAtomic; }
56 
57  operator T() const { return fAtomic; }
58 
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
67 
68 
69 class TProcessID : public TNamed {
70 
71 private:
72  TProcessID(const TProcessID &ref); // TProcessID are not copiable.
73  TProcessID& operator=(const TProcessID &ref); // TProcessID are not copiable.
74 
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
79 
80  static TProcessID *fgPID; //Pointer to current session ProcessID
81  static TObjArray *fgPIDs; //Table of ProcessIDs
82  static TExMap *fgObjPIDs; //Table pointer to pids
83  static UInt_t fgNumber; //Referenced objects count
84 
85 public:
86  TProcessID();
87  virtual ~TProcessID();
88  void CheckInit();
89  virtual void Clear(Option_t *option="");
92  Int_t GetCount() const {return fCount;}
93  TObjArray *GetObjects() const {return fObjects;}
95  void PutObjectWithID(TObject *obj, UInt_t uid=0);
96  virtual void RecursiveRemove(TObject *obj);
97 
98  static TProcessID *AddProcessID();
99  static UInt_t AssignID(TObject *obj);
100  static void Cleanup();
101  static UInt_t GetNProcessIDs();
102  static TProcessID *GetPID();
103  static TObjArray *GetPIDs();
104  static TProcessID *GetProcessID(UShort_t pid);
105  static TProcessID *GetProcessWithUID(const TObject *obj);
106  static TProcessID *GetProcessWithUID(UInt_t uid,const void *obj);
108  static UInt_t GetObjectCount();
109  static Bool_t IsValid(TProcessID *pid);
110  static void SetObjectCount(UInt_t number);
111 
112  ClassDef(TProcessID,1) //Process Unique Identifier in time and space
113 };
114 
115 #endif
static TProcessID * GetPID()
static: returns pointer to current TProcessID
Definition: TProcessID.cxx:313
static TProcessID * GetProcessID(UShort_t pid)
static function returning a pointer to TProcessID number pid in fgPIDs
Definition: TProcessID.cxx:232
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:373
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:344
An array of TObjects.
Definition: TObjArray.h:37
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:240
unsigned short UShort_t
Definition: RtypesCore.h:36
std::atomic< T > fAtomic
Definition: TProcessID.h:45
virtual ~TProcessID()
Destructor.
Definition: TProcessID.cxx:89
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:321
static TObjArray * fgPIDs
Definition: TProcessID.h:81
#define ClassDef(name, id)
Definition: Rtypes.h:297
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 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:392
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:188
TProcessID & operator=(const TProcessID &ref)
TObjArray * GetObjects() const
Definition: TProcessID.h:93
static TProcessID * GetProcessWithUID(const TObject *obj)
static function returning a pointer to TProcessID with its pid encoded in the highest byte of obj-&gt;Ge...
Definition: TProcessID.cxx:267
TProcessID()
Default constructor.
Definition: TProcessID.cxx:71
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:283
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:222
static TProcessID * AddProcessID()
Static function to add a new TProcessID to the list of PIDs.
Definition: TProcessID.cxx:100
TObject * GetObjectWithID(UInt_t uid)
returns the TObject with unique identifier uid in the table of objects
Definition: TProcessID.cxx:302
void CheckInit()
Initialize fObjects.
Definition: TProcessID.cxx:176
static UInt_t fgNumber
Definition: TProcessID.h:83
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(&quot;R&quot;) ...
Definition: TProcessID.cxx:202
static TProcessID * GetSessionProcessID()
static function returning the pointer to the session TProcessID
Definition: TProcessID.cxx:275
std::atomic_int fCount
Definition: TProcessID.h:76
Mother of all ROOT objects.
Definition: TObject.h:37
Int_t GetCount() const
Definition: TProcessID.h:92
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:139
static UInt_t GetObjectCount()
Return the current referenced object count fgNumber is incremented every time a new object is referen...
Definition: TProcessID.cxx:294
static Bool_t IsValid(TProcessID *pid)
static function. return kTRUE if pid is a valid TProcessID
Definition: TProcessID.cxx:330
This class stores a (key,value) pair using an external hash.
Definition: TExMap.h:33