ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | List of all members
TConvertingStreamerInfo Class Reference

Variant of TStreamerInfo to handle conversions. More...

#include <TConvertingStreamerInfo.h>

Inheritance diagram for TConvertingStreamerInfo:
Collaboration diagram for TConvertingStreamerInfo:

Public Member Functions

 TConvertingStreamerInfo ()
 Constructor. More...
 
virtual void BuildOld ()
 Compare with class definition to handle schema evolution. More...
 

Static Public Member Functions

static void Initialize ()
 Set up conversions. More...
 

Private Member Functions

bool errhand (int level, Bool_t abort, const char *location, const char *msg)
 Error message interceptor. More...
 
bool parse (const std::string &msg)
 Error message parser. More...
 
bool patch (const std::string &field, const std::string &from, const std::string &to)
 
TConvertingStreamerInfooperator= (const TConvertingStreamerInfo &)=delete
 
 TConvertingStreamerInfo (const TConvertingStreamerInfo &)=delete
 

Static Private Member Functions

static void * new_TConvertingStreamerInfo (void *p)
 new() method for this object. More...
 

Detailed Description

Variant of TStreamerInfo to handle conversions.

Definition at line 34 of file TConvertingStreamerInfo.h.

Constructor & Destructor Documentation

◆ TConvertingStreamerInfo() [1/2]

TConvertingStreamerInfo::TConvertingStreamerInfo ( )

Constructor.

Definition at line 31 of file TConvertingStreamerInfo.cxx.

32 {
33 }

◆ TConvertingStreamerInfo() [2/2]

TConvertingStreamerInfo::TConvertingStreamerInfo ( const TConvertingStreamerInfo )
privatedelete

Member Function Documentation

◆ BuildOld()

void TConvertingStreamerInfo::BuildOld ( )
virtual

Compare with class definition to handle schema evolution.

This is a standard TStreamerInfo method. We override this to intercept warning messages that it produces. If we see a warning related to one of the conversions that we handle, we patch up the TStreamerElement and swallow the warning.

Definition at line 93 of file TConvertingStreamerInfo.cxx.

94 {
95  using namespace std::placeholders;
97  this,
98  _1, _2, _3, _4));
99  TStreamerInfo::BuildOld();
100 }

◆ errhand()

bool TConvertingStreamerInfo::errhand ( int  level,
Bool_t  abort,
const char *  location,
const char *  msg 
)
private

Error message interceptor.

Parameters
levelError message level.
abortAbort flag.
locationFunction that raised the error.
msgError message.

We interpose this in front of the default error handler while BuildOld is running. If we see a message corresponding to a conversion that we handle, we fix up the TStreamerElement and swallow the message.

Definition at line 194 of file TConvertingStreamerInfo.cxx.

198 {
199  return !parse (msg);
200 }

◆ Initialize()

void TConvertingStreamerInfo::Initialize ( )
static

Set up conversions.

Definition at line 39 of file TConvertingStreamerInfo.cxx.

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.
65 }

◆ new_TConvertingStreamerInfo()

void * TConvertingStreamerInfo::new_TConvertingStreamerInfo ( void *  p)
staticprivate

new() method for this object.

Parameters
pAddress for placement new, or 0.
Returns
Address of the new object.

This is installed as the New method in TStreamerInfo's TClass. Thus, when we read from a file a TBranchElement, we actually make an instance of this class.

Parameters
pAddress for placement new, or 0.
Returns
Address of the new object.

This is installed as the New method in TStreamerInfo's TClass. Thus, when we read from a file a TStreamerInfo, we actually make an instance of this class.

Definition at line 77 of file TConvertingStreamerInfo.cxx.

78 {
79  if (p)
80  return new (p) TConvertingStreamerInfo;
81  return new TConvertingStreamerInfo;
82 }

◆ operator=()

TConvertingStreamerInfo& TConvertingStreamerInfo::operator= ( const TConvertingStreamerInfo )
privatedelete

◆ parse()

bool TConvertingStreamerInfo::parse ( const std::string &  smsg)
private

Error message parser.

Parameters
msgThe error message.
Returns
True if the message was handled; false otherwise.

If this is an error message corresponding to a conversion that we handle, we fix up the TStreamerElement and return true. Otherwise, return false.

Definition at line 150 of file TConvertingStreamerInfo.cxx.

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 }

◆ patch()

bool TConvertingStreamerInfo::patch ( const std::string &  field,
const std::string &  from,
const std::string &  to 
)
private
Parameters
Streamerpatcher.
fieldName of the field to patch.
fromOriginal (persistent) type.
toTarget (transient) type.
Returns
True if the conversion was handled; false otherwise.

This is called after an error message for a type mismatch has been successfully parsed. Fix up the TStreamerElement and return true if this is a conversion we handle; return false otherwise.

Definition at line 115 of file TConvertingStreamerInfo.cxx.

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 }

The documentation for this class was generated from the following files:
TConvertingStreamerInfo::errhand
bool errhand(int level, Bool_t abort, const char *location, const char *msg)
Error message interceptor.
Definition: TConvertingStreamerInfo.cxx:194
TConvertingStreamerInfo::TConvertingStreamerInfo
TConvertingStreamerInfo()
Constructor.
Definition: TConvertingStreamerInfo.cxx:31
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
ReadOfcFromCool.field
field
Definition: ReadOfcFromCool.py:48
TConvertingStreamerInfo
Variant of TStreamerInfo to handle conversions.
Definition: TConvertingStreamerInfo.h:42
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
TConvertingStreamerInfo::patch
bool patch(const std::string &field, const std::string &from, const std::string &to)
Definition: TConvertingStreamerInfo.cxx:115
RootUtils::WithRootErrorHandler
Run a MT piece of code with an alternate root error handler.
Definition: WithRootErrorHandler.h:56
TConvertingStreamerInfo::new_TConvertingStreamerInfo
static void * new_TConvertingStreamerInfo(void *p)
new() method for this object.
Definition: TConvertingStreamerInfo.cxx:77
CxxUtils::to
CONT to(RANGE &&r)
Definition: ranges.h:39
TConverterRegistry::Instance
static TConverterRegistry * Instance()
Return a pointer to the global registry instance.
Definition: TConverterRegistry.cxx:143
TConvertingStreamerInfo::parse
bool parse(const std::string &msg)
Error message parser.
Definition: TConvertingStreamerInfo.cxx:150
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
pdg_comparison.conv
conv
Definition: pdg_comparison.py:321