ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Database
AthenaPOOL
RootConversions
src
TConverterRegistry.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
13
14
#include "
RootConversions/TConverterRegistry.h
"
15
#include "
RootConversions/TConverterStreamer.h
"
16
#include "
RootConversions/TVirtualConverter.h
"
17
#include "
CxxUtils/checker_macros.h
"
18
#include "TClass.h"
19
#include "TMemberStreamer.h"
20
#include "TROOT.h"
21
22
23
void
TConvertingBranchElement_init
();
24
25
35
void
TConverterRegistry::AddConverter
(
TVirtualConverter
* conv)
36
{
37
AddConverter
(conv,
false
);
38
}
39
40
49
void
TConverterRegistry::AddConverter
(
TVirtualConverter
* conv,
50
bool
takeown)
51
{
52
lock_t
lock
(
fMutex
);
53
// Make sure the branch element is properly initialized.
54
TConvertingBranchElement_init
();
55
56
// Look up the checksum->converter map.
57
// (This will make an empty one if this is the first time we've
58
// seen this name.)
59
TClass* cls = conv->GetTransClass();
60
CheckSumMap
& cmap =
fMap
[cls->GetName()];
61
62
// If this is the first converter for this transient class,
63
// set up a streamer for non-split mode conversions.
64
if
(cmap.size() == 0)
65
cls->AdoptStreamer (
new
TConverterStreamer
(cmap, cls));
66
67
// Add this converter to the map.
68
cmap[conv->GetCheckSum()] = std::make_pair (conv, takeown);
69
}
70
71
80
bool
TConverterRegistry::AddConverter
(
const
char
* convname)
81
{
82
TClass* cl = gROOT->GetClass (convname);
83
if
(!cl)
return
false
;
84
TClass* basecl = gROOT->GetClass (
"TVirtualConverter"
);
85
int
offs = cl->GetBaseClassOffset (basecl);
86
if
(offs < 0)
return
false
;
87
char
* cnv =
reinterpret_cast<
char
*
>
(cl->New());
88
AddConverter
(
reinterpret_cast<
TVirtualConverter
*
>
(cnv + offs),
true
);
89
return
true
;
90
}
91
92
99
TVirtualConverter
*
TConverterRegistry::GetConverter
(
const
char
* name,
100
int
checksum)
const
101
{
102
lock_t
lock
(
fMutex
);
103
auto
i =
fMap
.find (name);
104
if
(i !=
fMap
.end()) {
105
auto
i2 = i->second.find (checksum);
106
if
(i2 != i->second.end())
107
return
i2->second.first;
108
}
109
return
nullptr
;
110
}
111
112
113
void
TConverterRegistry::AddStreamerConverter
(
const
std::string& from_type,
114
const
std::string& to_type,
115
TMemberStreamer* streamer)
116
{
117
lock_t
lock
(
fMutex
);
118
std::string key = from_type +
"-"
+ to_type;
119
auto
i =
fSMap
.find (key);
120
if
(i !=
fSMap
.end())
121
delete
i->second;
122
fSMap
[key] = streamer;
123
}
124
125
126
TMemberStreamer*
127
TConverterRegistry::GetStreamerConverter
(
const
std::string& from_type,
128
const
std::string& to_type)
const
129
{
130
lock_t
lock
(
fMutex
);
131
std::string key = from_type +
"-"
+ to_type;
132
auto
i =
fSMap
.find (key);
133
if
(i !=
fSMap
.end())
134
return
i->second;
135
return
nullptr
;
136
}
137
138
142
TConverterRegistry
*
TConverterRegistry::Instance
()
143
{
144
// Do it like this so that the object gets destroyed automatically
145
// at program termination.
146
static
TConverterRegistry
instance
ATLAS_THREAD_SAFE
;
147
return
&
instance
;
148
}
149
150
156
TConverterRegistry::~TConverterRegistry
()
157
{
158
for
(
auto
& [name, checksum_map] :
fMap
) {
159
for
(
auto
& [checksum, payload] : checksum_map) {
160
if
(payload.second)
161
delete
payload.first;
162
}
163
}
164
165
for
(
auto
& [key, streamer] :
fSMap
)
166
delete
streamer;
167
}
lock
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
instance
std::map< std::string, double > instance
Definition
Run_To_Get_Tags.h:8
TConvertingBranchElement_init
void TConvertingBranchElement_init()
TConverterRegistry.h
Registry for Root converters.
TConverterStreamer.h
Root streamer that calls our converters when reading in non-split mode.
TVirtualConverter.h
Base class for Root converters.
checker_macros.h
Define macros for attributes used to control the static checker.
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition
checker_macros.h:211
TConverterRegistry
Registry for Root converters.
Definition
TConverterRegistry.h:41
TConverterRegistry::fMap
MapType fMap
Map of registered converters.
Definition
TConverterRegistry.h:116
TConverterRegistry::GetStreamerConverter
TMemberStreamer * GetStreamerConverter(const std::string &from_type, const std::string &to_type) const
Definition
TConverterRegistry.cxx:127
TConverterRegistry::CheckSumMap
std::map< UInt_t, Payload > CheckSumMap
Definition
TConverterRegistry.h:112
TConverterRegistry::fSMap
SMapType fSMap
Definition
TConverterRegistry.h:125
TConverterRegistry::lock_t
std::lock_guard< std::mutex > lock_t
Definition
TConverterRegistry.h:120
TConverterRegistry::Instance
static TConverterRegistry * Instance()
Return a pointer to the global registry instance.
Definition
TConverterRegistry.cxx:142
TConverterRegistry::~TConverterRegistry
~TConverterRegistry()
Destructor.
Definition
TConverterRegistry.cxx:156
TConverterRegistry::AddConverter
void AddConverter(TVirtualConverter *conv)
Add a new converter to the registry.
Definition
TConverterRegistry.cxx:35
TConverterRegistry::fMutex
std::mutex fMutex
Protect access to the map.
Definition
TConverterRegistry.h:119
TConverterRegistry::AddStreamerConverter
void AddStreamerConverter(const std::string &from_type, const std::string &to_type, TMemberStreamer *streamer)
Definition
TConverterRegistry.cxx:113
TConverterRegistry::GetConverter
TVirtualConverter * GetConverter(const char *name, int checksum) const
Look up a converter in the registry by name and checksum.
Definition
TConverterRegistry.cxx:99
TConverterStreamer
Root streamer that calls our converter when reading in non-split mode.
Definition
TConverterStreamer.h:46
TVirtualConverter
Base class for converters for Root schema evolution.
Definition
TVirtualConverter.h:110
Generated on
for ATLAS Offline Software by
1.17.0