Logo ROOT  
Reference Guide
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 
27 #ifdef R__LESS_INCLUDES
28 class TObjArray;
29 #else
30 #include "TObjArray.h"
31 #endif
32 
33 #include <atomic>
34 #include <type_traits>
35 
36 class TExMap;
37 
38 namespace ROOT {
39  namespace Internal {
40  /**
41  * \class ROOT::Internal::TAtomicPointer
42  * \brief Helper class to manage atomic pointers.
43  * \tparam T Pointer type to be made atomic
44  *
45  * Helper class to manage atomic pointers. The class enforces that the templated type
46  * is a pointer.
47  */
48  template <typename T> class TAtomicPointer {
49  private:
50  std::atomic<T> fAtomic;
51 
52  public:
53  TAtomicPointer() : fAtomic(nullptr)
54  {
55  static_assert(std::is_pointer<T>::value, "Only pointer types supported");
56  }
57 
58  ~TAtomicPointer() { delete fAtomic.load(); }
59 
60  T operator->() const { return fAtomic; }
61 
62  operator T() const { return fAtomic; }
63 
64  T operator=(const T& t)
65  {
66  fAtomic = t;
67  return t;
68  }
69  };
70  } // End of namespace Internal
71 } // End of namespace ROOT
72 
73 
74 class TProcessID : public TNamed {
75 
76 private:
77  TProcessID(const TProcessID &ref); // TProcessID are not copiable.
78  TProcessID& operator=(const TProcessID &ref); // TProcessID are not copiable.
79 
80 protected:
81  std::atomic_int fCount; //!Reference count to this object (from TFile)
82  ROOT::Internal::TAtomicPointer<TObjArray*> fObjects; //!Array pointing to the referenced objects
83  std::atomic_flag fLock; //!Spin lock for initialization of fObjects
84 
85  static TProcessID *fgPID; //Pointer to current session ProcessID
86  static TObjArray *fgPIDs; //Table of ProcessIDs
87  static TExMap *fgObjPIDs; //Table pointer to pids
88 
89  static std::atomic_uint fgNumber; //Referenced objects count
90 
91 public:
92  TProcessID();
93  virtual ~TProcessID();
94  void CheckInit();
95  virtual void Clear(Option_t *option="");
98  Int_t GetCount() const {return fCount;}
99  TObjArray *GetObjects() const {return fObjects;}
101  void PutObjectWithID(TObject *obj, UInt_t uid=0);
102  virtual void RecursiveRemove(TObject *obj);
103 
104  static TProcessID *AddProcessID();
105  static UInt_t AssignID(TObject *obj);
106  static void Cleanup();
107  static UInt_t GetNProcessIDs();
108  static TProcessID *GetPID();
109  static TObjArray *GetPIDs();
110  static TProcessID *GetProcessID(UShort_t pid);
111  static TProcessID *GetProcessWithUID(const TObject *obj);
112  static TProcessID *GetProcessWithUID(UInt_t uid,const void *obj);
114  static UInt_t GetObjectCount();
115  static Bool_t IsValid(TProcessID *pid);
116  static void SetObjectCount(UInt_t number);
117 
118  ClassDef(TProcessID,1) //Process Unique Identifier in time and space
119 };
120 
121 #endif
TProcessID::PutObjectWithID
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:383
TProcessID::GetObjectCount
static UInt_t GetObjectCount()
Return the current referenced object count fgNumber is incremented every time a new object is referen...
Definition: TProcessID.cxx:324
TObjArray
An array of TObjects.
Definition: TObjArray.h:37
TProcessID::GetProcessID
static TProcessID * GetProcessID(UShort_t pid)
static function returning a pointer to TProcessID number pid in fgPIDs
Definition: TProcessID.cxx:248
Option_t
const char Option_t
Definition: RtypesCore.h:66
UShort_t
unsigned short UShort_t
Definition: RtypesCore.h:40
TProcessID::IsValid
static Bool_t IsValid(TProcessID *pid)
static function. return kTRUE if pid is a valid TProcessID
Definition: TProcessID.cxx:360
TProcessID::TProcessID
TProcessID(const TProcessID &ref)
TNamed.h
TProcessID::GetPIDs
static TObjArray * GetPIDs()
static: returns array of TProcessIDs
Definition: TProcessID.cxx:351
ROOT::Internal::TAtomicPointer::fAtomic
std::atomic< T > fAtomic
Definition: TProcessID.h:50
TProcessID
A TProcessID identifies a ROOT job in a unique way in time and space.
Definition: TProcessID.h:74
TProcessID::IncrementCount
Int_t IncrementCount()
Increase the reference count to this object.
Definition: TProcessID.cxx:313
TProcessID::SetObjectCount
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:436
TProcessID::operator=
TProcessID & operator=(const TProcessID &ref)
TProcessID::fObjects
ROOT::Internal::TAtomicPointer< TObjArray * > fObjects
Reference count to this object (from TFile)
Definition: TProcessID.h:82
TProcessID::AssignID
static UInt_t AssignID(TObject *obj)
static function returning the ID assigned to obj If the object is not yet referenced,...
Definition: TProcessID.cxx:155
TProcessID::TProcessID
TProcessID()
Default constructor.
Definition: TProcessID.cxx:77
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TProcessID::GetObjects
TObjArray * GetObjects() const
Definition: TProcessID.h:99
TProcessID::Cleanup
static void Cleanup()
static function (called by TROOT destructor) to delete all TProcessIDs
Definition: TProcessID.cxx:204
TProcessID::fgNumber
static std::atomic_uint fgNumber
Definition: TProcessID.h:89
TProcessID::fLock
std::atomic_flag fLock
Array pointing to the referenced objects.
Definition: TProcessID.h:83
TProcessID::Clear
virtual void Clear(Option_t *option="")
delete the TObjArray pointing to referenced objects this function is called by TFile::Close("R")
Definition: TProcessID.cxx:218
TProcessID::fgPID
static TProcessID * fgPID
Spin lock for initialization of fObjects.
Definition: TProcessID.h:85
TProcessID::GetNProcessIDs
static UInt_t GetNProcessIDs()
Return the (static) number of process IDs.
Definition: TProcessID.cxx:256
TNamed
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
TProcessID::~TProcessID
virtual ~TProcessID()
Destructor.
Definition: TProcessID.cxx:95
TProcessID::GetProcessWithUID
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:297
ROOT::Internal::TAtomicPointer::TAtomicPointer
TAtomicPointer()
Definition: TProcessID.h:53
TProcessID::fgPIDs
static TObjArray * fgPIDs
Definition: TProcessID.h:86
ROOT::Internal::TAtomicPointer::operator->
T operator->() const
Definition: TProcessID.h:60
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TProcessID::DecrementCount
Int_t DecrementCount()
The reference fCount is used to delete the TProcessID in the TFile destructor when fCount = 0.
Definition: TProcessID.cxx:238
TProcessID::GetSessionProcessID
static TProcessID * GetSessionProcessID()
static function returning the pointer to the session TProcessID
Definition: TProcessID.cxx:305
TProcessID::fgObjPIDs
static TExMap * fgObjPIDs
Definition: TProcessID.h:87
TProcessID::CheckInit
void CheckInit()
Initialize fObjects.
Definition: TProcessID.cxx:192
TProcessID::RecursiveRemove
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:412
ROOT::Internal::TAtomicPointer
Helper class to manage atomic pointers.
Definition: TProcessID.h:48
TObjArray.h
TProcessID::fCount
std::atomic_int fCount
Definition: TProcessID.h:81
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
ROOT::Math::Chebyshev::T
double T(double x)
Definition: ChebyshevPol.h:34
TProcessID::GetPID
static TProcessID * GetPID()
static: returns pointer to current TProcessID
Definition: TProcessID.cxx:343
TExMap
This class stores a (key,value) pair using an external hash.
Definition: TExMap.h:33
TProcessID::GetCount
Int_t GetCount() const
Definition: TProcessID.h:98
ROOT::Internal::TAtomicPointer::~TAtomicPointer
~TAtomicPointer()
Definition: TProcessID.h:58
TProcessID::GetObjectWithID
TObject * GetObjectWithID(UInt_t uid)
returns the TObject with unique identifier uid in the table of objects
Definition: TProcessID.cxx:332
ROOT::Internal::TAtomicPointer::operator=
T operator=(const T &t)
Definition: TProcessID.h:64
ROOT
VSD Structures.
Definition: StringConv.hxx:21
TProcessID::AddProcessID
static TProcessID * AddProcessID()
Static function to add a new TProcessID to the list of PIDs.
Definition: TProcessID.cxx:116
int