ATLAS Offline Software
Loading...
Searching...
No Matches
TConverterStreamer Class Reference

Root streamer that calls our converter when reading in non-split mode. More...

#include <TConverterStreamer.h>

Inheritance diagram for TConverterStreamer:
Collaboration diagram for TConverterStreamer:

Public Types

using Payload = std::pair<TVirtualConverter*, bool>
using CheckSumMap = std::map<UInt_t, Payload>

Public Member Functions

 TConverterStreamer (const CheckSumMap &convmap, TClass *cls)
 Constructor.
virtual void operator() (TBuffer &b, void *obj)
 Standard Root streamer interface.

Private Member Functions

void FindVersion (TBuffer &buf, UInt_t &startpos, UInt_t &bcnt, Version_t &version)
 Read the initial byte count/version from an object.
Version_t R__FindStreamerInfoVersion (const TClass *cl, UInt_t checksum)
 Translate a Root checksum to a class version number.

Private Attributes

const CheckSumMapfConvmap
 The checksum -> converter map passed to the constructor.
TClass * fClass
 The transient class we're reading.
UInt_t fStreamerChecksum
 Cached checksum for the last object read.
TFile * fLastFile
 Cached file for the last object read.

Detailed Description

Root streamer that calls our converter when reading in non-split mode.

Definition at line 44 of file TConverterStreamer.h.

Member Typedef Documentation

◆ CheckSumMap

using TConverterStreamer::CheckSumMap = std::map<UInt_t, Payload>

Definition at line 49 of file TConverterStreamer.h.

◆ Payload

Definition at line 48 of file TConverterStreamer.h.

Constructor & Destructor Documentation

◆ TConverterStreamer()

TConverterStreamer::TConverterStreamer ( const CheckSumMap & convmap,
TClass * cls )

Constructor.

Parameters
convmapMap from checksums to converter instances.
clsThe transient class that we're reading.

Definition at line 24 of file TConverterStreamer.cxx.

26 : fConvmap (convmap),
27 fClass (cls),
29 fLastFile (nullptr)
30{
31}
const CheckSumMap & fConvmap
The checksum -> converter map passed to the constructor.
UInt_t fStreamerChecksum
Cached checksum for the last object read.
TFile * fLastFile
Cached file for the last object read.
TClass * fClass
The transient class we're reading.

Member Function Documentation

◆ FindVersion()

void TConverterStreamer::FindVersion ( TBuffer & buf,
UInt_t & startpos,
UInt_t & bcnt,
Version_t & version )
private

Read the initial byte count/version from an object.

Parameters
bufThe Root I/O buffer.
[out]startposThe starting position of the object.
[out]bcntThe length of the object, in bytes.
[out]versionThe version of the object being read.

As a side effect, this sets fStreamerChecksum.

Definition at line 75 of file TConverterStreamer.cxx.

79{
80 const UInt_t kByteCountMask = 0x40000000; // OR the byte count with this
81
82 // before reading object save start position
83 startpos = buf.Length();
84
85 // read byte count (older files don't have byte count)
86 // byte count is packed in two individual shorts, this to be
87 // backward compatible with old files that have at this location
88 // only a single short (i.e. the version)
89 union {
90 UInt_t cnt;
91 Version_t vers[2];
92 } v;
93#ifdef R__BYTESWAP
94 // cppcheck-suppress uninitvar
95 buf >> v.vers[1];
96 buf >> v.vers[0];
97#else
98 // cppcheck-suppress uninitvar
99 buf >> v.vers[0];
100 buf >> v.vers[1];
101#endif
102 if (!(v.cnt & kByteCountMask)) {
103 // no bytecount, go back before reading version
104 buf.SetBufferOffset(buf.Length() - sizeof(UInt_t));
105 v.cnt = 0;
106 }
107 bcnt = (v.cnt & ~kByteCountMask);
108 buf >> version;
109
110 TFile* parent = (TFile*)buf.GetParent();
111 if (fLastFile != parent) {
112 // new file, reset
114 }
115 if (fClass && fClass->GetClassVersion() != 0) {
116 if (version <= 0) {
120 } else if (version == 1) {
121 // hand made streamer list caching,
122 // change that when TFile::GetStreamerInfoCache() is out
123 if (fLastFile == parent) {
124 // the same file, nothing changed?
125 }
126 else if (parent && parent->GetVersion() < 40000)
127 {
128 // We could have a file created using a Foreign class before
129 // the introduction of the CheckSum. We need to check
130 if ((!fClass->IsLoaded() || fClass->IsForeign()) &&
131 fClass->GetStreamerInfos()->GetLast() > 1)
132 {
133 const TList* list = parent->GetStreamerInfoList();
134 const TStreamerInfo* local = (TStreamerInfo*)list->FindObject(fClass->GetName());
135 if (local) {
136 fStreamerChecksum = local->GetCheckSum();
139 }
140 else {
141 version = 0;
142 }
143 }
144 }
145 }
146 }
148}
Version_t R__FindStreamerInfoVersion(const TClass *cl, UInt_t checksum)
Translate a Root checksum to a class version number.
list(name, path='/')
Definition histSizes.py:38

◆ operator()()

void TConverterStreamer::operator() ( TBuffer & b,
void * obj )
virtual

Standard Root streamer interface.

Parameters
bBuffer for Root I/O.
objObject being read or written.

Definition at line 39 of file TConverterStreamer.cxx.

40{
41 if (b.IsReading()) {
42 // Reading --- do we need to convert?
43 UInt_t startpos, bcnt;
44 Version_t version;
45 FindVersion (b, startpos, bcnt, version);
46 // find converter for the object shape checksum
47 // (checksum is read from the file in FindVersion)
48 auto i = fConvmap.find (fStreamerChecksum);
49
50 if (i != fConvmap.end()) {
51 // Found a converter --- call it.
52 i->second.first->ReadBuffer (b, obj, version, startpos, bcnt);
53 }
54 else {
55 // No converter --- read normally.
56 fClass->ReadBuffer(b, obj, version, startpos, bcnt);
57 }
58 }
59 else {
60 // Writing --- just do the standard thing.
61 fClass->WriteBuffer(b, obj);
62 }
63}
void FindVersion(TBuffer &buf, UInt_t &startpos, UInt_t &bcnt, Version_t &version)
Read the initial byte count/version from an object.

◆ R__FindStreamerInfoVersion()

Version_t TConverterStreamer::R__FindStreamerInfoVersion ( const TClass * cl,
UInt_t checksum )
private

Translate a Root checksum to a class version number.

Parameters
clThe class being examined.
checksumThe checksum to translate.
Returns
The class version number of cl with checksum checksum, or 0 if there's no match.

Definition at line 158 of file TConverterStreamer.cxx.

160{
161 //FIXME
162 // use TBuffer::R__FindStreamerInfoVersion() instead of this function
163 // with the next ROOT release
164
165 //find the version number in the StreamerInfos corresponding to checksum
166 Version_t version = 0;
167 Int_t ninfos = cl->GetStreamerInfos()->GetEntriesFast();
168 for (Int_t i = 1; i < ninfos; i++) {
169 // TClass::fStreamerInfos has a lower bound not equal to 0,
170 // so we should use At and not use UncheckedAt
171 TStreamerInfo* info = (TStreamerInfo*)cl->GetStreamerInfos()->At(i);
172 if (!info) {
173 continue;
174 }
175 if (info->GetCheckSum() == checksum) {
176 version = i;
177 break;
178 }
179 }
180 return(version);
181}
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]

Member Data Documentation

◆ fClass

TClass* TConverterStreamer::fClass
private

The transient class we're reading.

Definition at line 94 of file TConverterStreamer.h.

◆ fConvmap

const CheckSumMap& TConverterStreamer::fConvmap
private

The checksum -> converter map passed to the constructor.

Definition at line 91 of file TConverterStreamer.h.

◆ fLastFile

TFile* TConverterStreamer::fLastFile
private

Cached file for the last object read.

Definition at line 100 of file TConverterStreamer.h.

◆ fStreamerChecksum

UInt_t TConverterStreamer::fStreamerChecksum
private

Cached checksum for the last object read.

Definition at line 97 of file TConverterStreamer.h.


The documentation for this class was generated from the following files: