ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Database
AthenaPOOL
RootConversions
src
TConvertingStreamerInfo.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3
*/
10
11
12
#include "
RootConversions/TConvertingStreamerInfo.h
"
13
#include "
RootConversions/TConverterRegistry.h
"
14
#include "
RootUtils/WithRootErrorHandler.h
"
15
#include "
CxxUtils/checker_macros.h
"
16
#include "TStreamerElement.h"
17
#include "TMemberStreamer.h"
18
#include "TROOT.h"
19
#include "TClass.h"
20
#include "TError.h"
21
#include <string>
22
#include <vector>
23
#include <cassert>
24
#include <memory>
25
#include <mutex>
26
27
31
TConvertingStreamerInfo::TConvertingStreamerInfo
()
32
{
33
}
34
35
39
void
TConvertingStreamerInfo::Initialize
()
40
{
41
static
bool
initialized
ATLAS_THREAD_SAFE
=
false
;
42
static
std::mutex initmutex;
43
std::lock_guard<std::mutex>
lock
(initmutex);
44
45
if
(initialized)
46
return
;
47
initialized =
true
;
48
49
TClass* cl = gROOT->GetClass (
"TStreamerInfo"
,
true
);
50
51
// Make sure the I/O plugin has been loaded.
52
// This will change the new hook for the TStreamerInfo class,
53
// so we need to make sure that this is done before we change
54
// it ourselves.
55
TVirtualStreamerInfo::Factory ();
56
if
(!cl) {
57
::Error (
"TConvertingStreamerInfo"
,
58
"Can't find TClass for TStreamerInfo"
);
59
return
;
60
}
61
62
// Change the @c New() method for @c TStreamerInfo to make
63
// an instance of this class instead.
64
cl->SetNew (
TConvertingStreamerInfo::new_TConvertingStreamerInfo
);
65
}
66
67
77
void
*
TConvertingStreamerInfo::new_TConvertingStreamerInfo
(
void
*p)
78
{
79
if
(p)
80
return
new
(p)
TConvertingStreamerInfo
;
81
return
new
TConvertingStreamerInfo
;
82
}
83
84
93
void
TConvertingStreamerInfo::BuildOld
()
94
{
95
using namespace
std::placeholders;
96
RootUtils::WithRootErrorHandler
errHand (std::bind (&
TConvertingStreamerInfo::errhand
,
97
this
,
98
_1, _2, _3, _4));
99
TStreamerInfo::BuildOld();
100
}
101
102
115
bool
TConvertingStreamerInfo::patch
(
const
std::string& field,
116
const
std::string& from,
117
const
std::string& to)
118
{
119
static
std::mutex
mutex
;
120
std::lock_guard<std::mutex>
lock
(
mutex
);
121
122
if
(TMemberStreamer* conv =
123
TConverterRegistry::Instance
()->GetStreamerConverter (from, to))
124
{
125
Int_t offset;
126
TStreamerElement* elem = GetStreamerElement (field.c_str(), offset);
127
TClass* cl = gROOT->GetClass (to.c_str());
128
if
(elem && cl) {
129
elem->SetTypeName (to.c_str());
130
elem->Update (elem->GetClass(), cl);
131
elem->SetNewType (elem->GetType());
132
elem->SetStreamer (conv);
133
return
true
;
134
}
135
}
136
137
return
false
;
138
}
139
140
150
bool
TConvertingStreamerInfo::parse
(
const
std::string& smsg)
151
{
152
if
(smsg.substr (0, 15) !=
"Cannot convert "
)
return
false
;
153
154
std::string::size_type ifrom = smsg.find (
" from type:"
);
155
if
(ifrom == std::string::npos)
return
false
;
156
157
std::string::size_type ifield = smsg.rfind (
"::"
, ifrom);
158
if
(ifield == std::string::npos)
return
false
;
159
160
std::string field (smsg, ifield+2, ifrom - (ifield+2));
161
162
std::string::size_type ito = smsg.find (
" to type:"
);
163
if
(ito == std::string::npos)
return
false
;
164
165
ifrom += 11;
166
while
(ifrom < ito && smsg[ifrom] ==
' '
)
167
++ifrom;
168
std::string from (smsg, ifrom, ito - ifrom);
169
170
std::string::size_type iskip = smsg.find (
", skip element"
);
171
if
(iskip == std::string::npos)
return
false
;
172
173
ito += 9;
174
while
(ito < iskip && smsg[ito] ==
' '
)
175
++ito;
176
std::string to (smsg, ito, iskip - ito);
177
178
return
patch
(field, from, to);
179
}
180
181
194
bool
TConvertingStreamerInfo::errhand
(
int
/*level*/
,
195
Bool_t
/*abort*/
,
196
const
char
*
/*location*/
,
197
const
char
*
msg
)
198
{
199
return
!
parse
(
msg
);
200
}
201
202
lock
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
TConverterRegistry.h
Registry for Root converters.
TConvertingStreamerInfo.h
Variant of TStreamerInfo to handle conversions.
WithRootErrorHandler.h
Run a MT piece of code with an alternate root error handler.
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
RootUtils::WithRootErrorHandler
Run a MT piece of code with an alternate root error handler.
Definition
WithRootErrorHandler.h:56
TConverterRegistry::Instance
static TConverterRegistry * Instance()
Return a pointer to the global registry instance.
Definition
TConverterRegistry.cxx:142
TConvertingStreamerInfo::errhand
bool errhand(int level, Bool_t abort, const char *location, const char *msg)
Error message interceptor.
Definition
TConvertingStreamerInfo.cxx:194
TConvertingStreamerInfo::patch
bool patch(const std::string &field, const std::string &from, const std::string &to)
Definition
TConvertingStreamerInfo.cxx:115
TConvertingStreamerInfo::new_TConvertingStreamerInfo
static void * new_TConvertingStreamerInfo(void *p)
new() method for this object.
Definition
TConvertingStreamerInfo.cxx:77
TConvertingStreamerInfo::BuildOld
virtual void BuildOld()
Compare with class definition to handle schema evolution.
Definition
TConvertingStreamerInfo.cxx:93
TConvertingStreamerInfo::TConvertingStreamerInfo
TConvertingStreamerInfo()
Constructor.
Definition
TConvertingStreamerInfo.cxx:31
TConvertingStreamerInfo::Initialize
static void Initialize()
Set up conversions.
Definition
TConvertingStreamerInfo.cxx:39
TConvertingStreamerInfo::parse
bool parse(const std::string &msg)
Error message parser.
Definition
TConvertingStreamerInfo.cxx:150
mutex
STL class.
msg
MsgStream & msg
Definition
testRead.cxx:32
Generated on
for ATLAS Offline Software by
1.17.0