Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TIsAProxy.h
Go to the documentation of this file.
1// @(#)root/meta:$Id$
2// Author: Markus Frank 20/05/2005
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_TIsAProxy
13#define ROOT_TIsAProxy
14
15#include "TVirtualIsAProxy.h"
16#include "RtypesCore.h"
17#include <atomic>
18#include <typeinfo>
19
20class TClass;
21
22//////////////////////////////////////////////////////////////////////////
23// //
24// TIsAProxy implementation class. //
25// //
26//////////////////////////////////////////////////////////////////////////
28private:
29 template <typename T> using Atomic_t = std::atomic<T>;
30
31 // On testing with the data from the 250202_181_RECO.root and doing "just" serializing
32 // the value 8 was the sweet spot of performance. With more slots, too much time is
33 // spent scanning the array of "last" seen and with less slots then the
34 // serialization induced by and/or the cost of executed `++fSubTypesReaders is slow
35 // down (noticeably) the streaming of branches with polymorphic containers.
36 static constexpr UInt_t fgMaxLastSlot = 8;
37
38 const std::type_info *fType; //Actual typeid of the proxy
39 TClass *fClass; //Actual TClass
40 Atomic_t<void*> fLasts[fgMaxLastSlot]; // points into fSubTypes map for last used values
41 Char_t fSubTypes[72]; //map of known sub-types
42 mutable Atomic_t<UInt_t> fSubTypesReaders; //number of readers of fSubTypes
43 Atomic_t<Bool_t> fSubTypesWriteLockTaken; //True if there is a writer
44 Atomic_t<UChar_t> fNextLastSlot; // Next slot in fLasts to use for update (ring buffer)
45 Atomic_t<Bool_t> fInit; //Initialization flag
46 Bool_t fVirtual; //Flag if class is virtual
47
48 void* FindSubType(const std::type_info*) const;
49 void* CacheSubType(const std::type_info*, TClass*);
50protected:
51 TIsAProxy(const TIsAProxy&) = delete;
52 TIsAProxy& operator=(const TIsAProxy&) = delete;
53
54public:
55 // Standard initializing constructor
56 TIsAProxy(const std::type_info &typ);
57 // Standard destructor
58 virtual ~TIsAProxy();
59 // Callbacl to set the class
60 virtual void SetClass(TClass *cl);
61 // IsA callback
62 virtual TClass* operator()(const void *obj);
63};
64
65//////////////////////////////////////////////////////////////////////////
66// //
67// TInstrumentedIsAProxy implementation class. //
68// //
69//////////////////////////////////////////////////////////////////////////
70template <class T> class TInstrumentedIsAProxy : public TVirtualIsAProxy {
71
72private:
73 TClass *fClass; //Actual TClass
74
75protected:
77 TVirtualIsAProxy(iip), fClass(iip.fClass) { }
79 {if(this!=&iip) {TVirtualIsAProxy::operator=(iip); fClass=iip.fClass;}
80 return *this;}
81
82public:
83 // Standard initializing constructor
85 // Standard destructor
87 // Callbacl to set the class
88 virtual void SetClass(TClass *cl) { fClass = cl; }
89 // IsA callback
90 virtual TClass* operator()(const void *obj) {
91 return obj==0 ? fClass : ((const T*)obj)->IsA();
92 }
93};
94
95#endif // ROOT_TIsAProxy
char Char_t
Definition RtypesCore.h:37
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:80
virtual TClass * operator()(const void *obj)
Definition TIsAProxy.h:90
virtual ~TInstrumentedIsAProxy()
Definition TIsAProxy.h:86
TInstrumentedIsAProxy(const TInstrumentedIsAProxy &iip)
Definition TIsAProxy.h:76
virtual void SetClass(TClass *cl)
Definition TIsAProxy.h:88
TInstrumentedIsAProxy(TClass *cl)
Definition TIsAProxy.h:84
TInstrumentedIsAProxy & operator=(const TInstrumentedIsAProxy &iip)
Definition TIsAProxy.h:78
TIsAProxy implementation class.
Definition TIsAProxy.h:27
Atomic_t< UInt_t > fSubTypesReaders
Definition TIsAProxy.h:42
TClass * fClass
Definition TIsAProxy.h:39
void * CacheSubType(const std::type_info *, TClass *)
Record the TClass found for a std::type_info, so that we can retrieved it faster.
virtual void SetClass(TClass *cl)
Set class pointer This method is not thread safe.
Definition TIsAProxy.cxx:74
virtual ~TIsAProxy()
Standard destructor.
Definition TIsAProxy.cxx:63
std::atomic< T > Atomic_t
Definition TIsAProxy.h:29
TIsAProxy & operator=(const TIsAProxy &)=delete
Atomic_t< UChar_t > fNextLastSlot
Definition TIsAProxy.h:44
Char_t fSubTypes[72]
Definition TIsAProxy.h:41
virtual TClass * operator()(const void *obj)
IsA callback.
Definition TIsAProxy.cxx:85
const std::type_info * fType
Definition TIsAProxy.h:38
Atomic_t< Bool_t > fSubTypesWriteLockTaken
Definition TIsAProxy.h:43
Bool_t fVirtual
Definition TIsAProxy.h:46
Atomic_t< void * > fLasts[fgMaxLastSlot]
Definition TIsAProxy.h:40
void * FindSubType(const std::type_info *) const
See if we have already cached the TClass that correspond to this std::type_info.
Atomic_t< Bool_t > fInit
Definition TIsAProxy.h:45
static constexpr UInt_t fgMaxLastSlot
Definition TIsAProxy.h:36
TIsAProxy(const TIsAProxy &)=delete