Logo ROOT   6.16/01
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#include "TObjArray.h"
27
28#include <atomic>
29#include <type_traits>
30
31class TExMap;
32
33namespace 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:
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
69class TProcessID : public TNamed {
70
71private:
72 TProcessID(const TProcessID &ref); // TProcessID are not copiable.
73 TProcessID& operator=(const TProcessID &ref); // TProcessID are not copiable.
74
75protected:
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
84 static std::atomic_uint fgNumber; //Referenced objects count
85
86public:
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);
98
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);
112
113 ClassDef(TProcessID,1) //Process Unique Identifier in time and space
114};
115
116#endif
unsigned short UShort_t
Definition: RtypesCore.h:36
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
bool Bool_t
Definition: RtypesCore.h:59
const char Option_t
Definition: RtypesCore.h:62
#define ClassDef(name, id)
Definition: Rtypes.h:324
Helper class to manage atomic pointers.
Definition: TProcessID.h:43
std::atomic< T > fAtomic
Definition: TProcessID.h:45
This class stores a (key,value) pair using an external hash.
Definition: TExMap.h:33
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
An array of TObjects.
Definition: TObjArray.h:37
Mother of all ROOT objects.
Definition: TObject.h:37
A TProcessID identifies a ROOT job in a unique way in time and space.
Definition: TProcessID.h:69
Int_t IncrementCount()
Increase the reference count to this object.
Definition: TProcessID.cxx:311
void CheckInit()
Initialize fObjects.
Definition: TProcessID.cxx:190
static void Cleanup()
static function (called by TROOT destructor) to delete all TProcessIDs
Definition: TProcessID.cxx:202
static Bool_t IsValid(TProcessID *pid)
static function. return kTRUE if pid is a valid TProcessID
Definition: TProcessID.cxx:358
static UInt_t GetNProcessIDs()
Return the (static) number of process IDs.
Definition: TProcessID.cxx:254
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 TObjArray * fgPIDs
Definition: TProcessID.h:81
static TObjArray * GetPIDs()
static: returns array of TProcessIDs
Definition: TProcessID.cxx:349
TProcessID & operator=(const TProcessID &ref)
static UInt_t AssignID(TObject *obj)
static function returning the ID assigned to obj If the object is not yet referenced,...
Definition: TProcessID.cxx:153
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
static TProcessID * GetSessionProcessID()
static function returning the pointer to the session TProcessID
Definition: TProcessID.cxx:303
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
virtual ~TProcessID()
Destructor.
Definition: TProcessID.cxx:93
TProcessID(const TProcessID &ref)
static TExMap * fgObjPIDs
Definition: TProcessID.h:82
std::atomic_int fCount
Definition: TProcessID.h:76
static TProcessID * AddProcessID()
Static function to add a new TProcessID to the list of PIDs.
Definition: TProcessID.cxx:114
std::atomic_flag fLock
Array pointing to the referenced objects.
Definition: TProcessID.h:78
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
static TProcessID * GetProcessID(UShort_t pid)
static function returning a pointer to TProcessID number pid in fgPIDs
Definition: TProcessID.cxx:246
Int_t DecrementCount()
The reference fCount is used to delete the TProcessID in the TFile destructor when fCount = 0.
Definition: TProcessID.cxx:236
TObjArray * GetObjects() const
Definition: TProcessID.h:94
TObject * GetObjectWithID(UInt_t uid)
returns the TObject with unique identifier uid in the table of objects
Definition: TProcessID.cxx:330
static std::atomic_uint fgNumber
Definition: TProcessID.h:84
ROOT::Internal::TAtomicPointer< TObjArray * > fObjects
Reference count to this object (from TFile)
Definition: TProcessID.h:77
static TProcessID * fgPID
Spin lock for initialization of fObjects.
Definition: TProcessID.h:80
Int_t GetCount() const
Definition: TProcessID.h:93
TProcessID()
Default constructor.
Definition: TProcessID.cxx:75
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 TProcessID * GetPID()
static: returns pointer to current TProcessID
Definition: TProcessID.cxx:341
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
double T(double x)
Definition: ChebyshevPol.h:34
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21