39 #if (defined(__linux) || defined(__APPLE__)) && defined(__i386__) && \
49 const UInt_t kNewClassTag = 0xFFFFFFFF;
50 const UInt_t kClassMask = 0x80000000;
51 const UInt_t kByteCountMask = 0x40000000;
52 const UInt_t kMaxMapCount = 0x3FFFFFFE;
53 const Version_t kByteCountVMask = 0x4000;
54 const Version_t kMaxVersion = 0x3FFF;
55 const Int_t kMapOffset = 2;
58 ClassImp(TBufferFile);
63 static inline bool Class_Has_StreamerInfo(
const TClass* cl)
68 R__LOCKGUARD(gInterpreterMutex);
69 return cl->GetStreamerInfos()->GetLast()>1;
77 TBufferFile::TBufferFile(TBuffer::EMode mode)
79 fInfo(nullptr), fInfoStack()
87 TBufferFile::TBufferFile(TBuffer::EMode mode, Int_t bufsiz)
88 :TBufferIO(mode,bufsiz),
89 fInfo(nullptr), fInfoStack()
104 TBufferFile::TBufferFile(TBuffer::EMode mode, Int_t bufsiz,
void *buf, Bool_t adopt, ReAllocCharFun_t reallocfunc) :
105 TBufferIO(mode,bufsiz,buf,adopt,reallocfunc),
106 fInfo(nullptr), fInfoStack()
113 TBufferFile::~TBufferFile()
120 void TBufferFile::IncrementLevel(TVirtualStreamerInfo* info)
122 fInfoStack.push_back(fInfo);
123 fInfo = (TStreamerInfo*)info;
129 void TBufferFile::DecrementLevel(TVirtualStreamerInfo* )
131 fInfo = fInfoStack.back();
132 fInfoStack.pop_back();
144 static void frombufOld(
char *&buf, Long_t *x)
148 char *sw = (
char *)x;
158 char *sw = (
char *)x;
165 memcpy(x, buf,
sizeof(Long_t));
167 buf +=
sizeof(Long_t);
173 void TBufferFile::ReadLong(Long_t &l)
175 TFile *file = (TFile*)fParent;
176 if (file && file->GetVersion() < 30006) {
177 frombufOld(fBufCur, &l);
179 frombuf(fBufCur, &l);
186 void TBufferFile::ReadTString(TString &s)
201 char *data = s.GetPointer();
204 ReadFastArray(data, nbig);
211 void TBufferFile::WriteTString(
const TString &s)
213 Int_t nbig = s.Length();
223 const char *data = s.GetPointer();
224 WriteFastArray(data, nbig);
230 void TBufferFile::ReadStdString(std::string *obj)
232 if (obj ==
nullptr) {
233 Error(
"TBufferFile::ReadStdString",
"The std::string address is nullptr but should not");
248 obj->resize(nbig,
'\0');
249 ReadFastArray((
char*)obj->data(),nbig);
252 obj->resize(nwh,
'\0');
253 ReadFastArray((
char*)obj->data(),nwh);
261 void TBufferFile::WriteStdString(
const std::string *obj)
265 WriteFastArray(
"",0);
270 Int_t nbig = obj->length();
279 WriteFastArray(obj->data(),nbig);
285 void TBufferFile::ReadCharStar(
char* &s)
294 ReadFastArray(s, nch);
302 void TBufferFile::WriteCharStar(
char *s)
308 WriteFastArray(s,nch);
319 void TBufferFile::SetByteCount(UInt_t cntpos, Bool_t packInVersion)
321 UInt_t cnt = UInt_t(fBufCur - fBuffer) - cntpos -
sizeof(UInt_t);
322 char *buf = (
char *)(fBuffer + cntpos);
333 tobuf(buf, Version_t(v.vers[1] | kByteCountVMask));
334 tobuf(buf, v.vers[0]);
336 tobuf(buf, Version_t(v.vers[0] | kByteCountVMask));
337 tobuf(buf, v.vers[1]);
340 tobuf(buf, cnt | kByteCountMask);
342 if (cnt >= kMaxMapCount) {
343 Error(
"WriteByteCount",
"bytecount too large (more than %d)", kMaxMapCount);
356 Int_t TBufferFile::CheckByteCount(UInt_t startpos, UInt_t bcnt,
const TClass *clss,
const char *classname)
362 Long_t endpos = Long_t(fBuffer) + startpos + bcnt +
sizeof(UInt_t);
364 if (Long_t(fBufCur) != endpos) {
365 offset = Int_t(Long_t(fBufCur) - endpos);
367 const char *name = clss ? clss->GetName() : classname ? classname : 0;
371 Error(
"CheckByteCount",
"object of class %s read too few bytes: %d instead of %d",
372 name,bcnt+offset,bcnt);
375 Error(
"CheckByteCount",
"object of class %s read too many bytes: %d instead of %d",
376 name,bcnt+offset,bcnt);
378 Warning(
"CheckByteCount",
"%s::Streamer() not in sync with data on file %s, fix Streamer()",
379 name, fParent->GetName());
381 Warning(
"CheckByteCount",
"%s::Streamer() not in sync with data, fix Streamer()",
385 if ( ((
char *)endpos) > fBufMax ) {
386 offset = fBufMax-fBufCur;
387 Error(
"CheckByteCount",
388 "Byte count probably corrupted around buffer position %d:\n\t%d for a possible maximum of %d",
389 startpos, bcnt, offset);
394 fBufCur = (
char *) endpos;
409 Int_t TBufferFile::CheckByteCount(UInt_t startpos, UInt_t bcnt,
const TClass *clss)
412 return CheckByteCount( startpos, bcnt, clss,
nullptr);
423 Int_t TBufferFile::CheckByteCount(UInt_t startpos, UInt_t bcnt,
const char *classname)
426 return CheckByteCount( startpos, bcnt,
nullptr, classname);
433 void TBufferFile::ReadFloat16(Float_t *f, TStreamerElement *ele)
435 if (ele && ele->GetFactor() != 0) {
436 ReadWithFactor(f, ele->GetFactor(), ele->GetXmin());
439 if (ele) nbits = (Int_t)ele->GetXmin();
440 if (!nbits) nbits = 12;
441 ReadWithNbits(f, nbits);
449 void TBufferFile::ReadDouble32(Double_t *d, TStreamerElement *ele)
451 if (ele && ele->GetFactor() != 0) {
452 ReadWithFactor(d, ele->GetFactor(), ele->GetXmin());
455 if (ele) nbits = (Int_t)ele->GetXmin();
460 d[0] = (Double_t)afloat;
462 ReadWithNbits(d, nbits);
471 void TBufferFile::ReadWithFactor(Float_t *ptr, Double_t factor, Double_t minvalue)
475 frombuf(this->fBufCur,&aint);
476 ptr[0] = (Float_t)(aint/factor + minvalue);
483 void TBufferFile::ReadWithNbits(Float_t *ptr, Int_t nbits)
493 frombuf(this->fBufCur,&theExp);
494 frombuf(this->fBufCur,&theMan);
495 temp.fIntValue = theExp;
496 temp.fIntValue <<= 23;
497 temp.fIntValue |= (theMan & ((1<<(nbits+1))-1)) <<(23-nbits);
498 if(1<<(nbits+1) & theMan) temp.fFloatValue = -temp.fFloatValue;
499 ptr[0] = temp.fFloatValue;
506 void TBufferFile::ReadWithFactor(Double_t *ptr, Double_t factor, Double_t minvalue)
510 frombuf(this->fBufCur,&aint);
511 ptr[0] = (Double_t)(aint/factor + minvalue);
518 void TBufferFile::ReadWithNbits(Double_t *ptr, Int_t nbits)
528 frombuf(this->fBufCur,&theExp);
529 frombuf(this->fBufCur,&theMan);
530 temp.fIntValue = theExp;
531 temp.fIntValue <<= 23;
532 temp.fIntValue |= (theMan & ((1<<(nbits+1))-1)) <<(23-nbits);
533 if(1<<(nbits+1) & theMan) temp.fFloatValue = -temp.fFloatValue;
534 ptr[0] = (Double_t)temp.fFloatValue;
590 void TBufferFile::WriteFloat16(Float_t *f, TStreamerElement *ele)
593 if (ele && ele->GetFactor() != 0) {
598 Double_t xmin = ele->GetXmin();
599 Double_t xmax = ele->GetXmax();
600 if (x < xmin) x = xmin;
601 if (x > xmax) x = xmax;
602 UInt_t aint = UInt_t(0.5+ele->GetFactor()*(x-xmin)); *
this << aint;
606 if (ele) nbits = (Int_t)ele->GetXmin();
607 if (!nbits) nbits = 12;
616 UChar_t theExp = (UChar_t)(0x000000ff & ((fIntValue<<1)>>24));
617 UShort_t theMan = ((1<<(nbits+1))-1) & (fIntValue>>(23-nbits-1));
620 if (theMan&1<<nbits) theMan = (1<<nbits) - 1;
621 if (fFloatValue < 0) theMan |= 1<<(nbits+1);
654 void TBufferFile::WriteDouble32(Double_t *d, TStreamerElement *ele)
657 if (ele && ele->GetFactor() != 0) {
662 Double_t xmin = ele->GetXmin();
663 Double_t xmax = ele->GetXmax();
664 if (x < xmin) x = xmin;
665 if (x > xmax) x = xmax;
666 UInt_t aint = UInt_t(0.5+ele->GetFactor()*(x-xmin)); *
this << aint;
670 if (ele) nbits = (Int_t)ele->GetXmin();
673 Float_t afloat = (Float_t)d[0];
683 fFloatValue = (Float_t)d[0];
684 UChar_t theExp = (UChar_t)(0x000000ff & ((fIntValue<<1)>>24));
685 UShort_t theMan = ((1<<(nbits+1))-1) & (fIntValue>>(23-nbits-1)) ;
688 if (theMan&1<<nbits) theMan = (1<<nbits)-1 ;
689 if (fFloatValue < 0) theMan |= 1<<(nbits+1);
701 Int_t TBufferFile::ReadArray(Bool_t *&b)
703 R__ASSERT(IsReading());
708 if (n <= 0 || n > fBufSize)
return 0;
710 if (!b) b =
new Bool_t[n];
712 if (
sizeof(Bool_t) > 1) {
713 for (
int i = 0; i < n; i++)
714 frombuf(fBufCur, &b[i]);
716 Int_t l =
sizeof(Bool_t)*n;
717 memcpy(b, fBufCur, l);
729 Int_t TBufferFile::ReadArray(Char_t *&c)
731 R__ASSERT(IsReading());
735 Int_t l =
sizeof(Char_t)*n;
737 if (l <= 0 || l > fBufSize)
return 0;
739 if (!c) c =
new Char_t[n];
741 memcpy(c, fBufCur, l);
752 Int_t TBufferFile::ReadArray(Short_t *&h)
754 R__ASSERT(IsReading());
758 Int_t l =
sizeof(Short_t)*n;
760 if (l <= 0 || l > fBufSize)
return 0;
762 if (!h) h =
new Short_t[n];
766 bswapcpy16(h, fBufCur, n);
769 for (
int i = 0; i < n; i++)
770 frombuf(fBufCur, &h[i]);
773 memcpy(h, fBufCur, l);
785 Int_t TBufferFile::ReadArray(Int_t *&ii)
787 R__ASSERT(IsReading());
791 Int_t l =
sizeof(Int_t)*n;
793 if (l <= 0 || l > fBufSize)
return 0;
795 if (!ii) ii =
new Int_t[n];
799 bswapcpy32(ii, fBufCur, n);
802 for (
int i = 0; i < n; i++)
803 frombuf(fBufCur, &ii[i]);
806 memcpy(ii, fBufCur, l);
818 Int_t TBufferFile::ReadArray(Long_t *&ll)
820 R__ASSERT(IsReading());
824 Int_t l =
sizeof(Long_t)*n;
826 if (l <= 0 || l > fBufSize)
return 0;
828 if (!ll) ll =
new Long_t[n];
830 TFile *file = (TFile*)fParent;
831 if (file && file->GetVersion() < 30006) {
832 for (
int i = 0; i < n; i++) frombufOld(fBufCur, &ll[i]);
834 for (
int i = 0; i < n; i++) frombuf(fBufCur, &ll[i]);
844 Int_t TBufferFile::ReadArray(Long64_t *&ll)
846 R__ASSERT(IsReading());
850 Int_t l =
sizeof(Long64_t)*n;
852 if (l <= 0 || l > fBufSize)
return 0;
854 if (!ll) ll =
new Long64_t[n];
857 for (
int i = 0; i < n; i++)
858 frombuf(fBufCur, &ll[i]);
860 memcpy(ll, fBufCur, l);
872 Int_t TBufferFile::ReadArray(Float_t *&f)
874 R__ASSERT(IsReading());
878 Int_t l =
sizeof(Float_t)*n;
880 if (l <= 0 || l > fBufSize)
return 0;
882 if (!f) f =
new Float_t[n];
886 bswapcpy32(f, fBufCur, n);
889 for (
int i = 0; i < n; i++)
890 frombuf(fBufCur, &f[i]);
893 memcpy(f, fBufCur, l);
905 Int_t TBufferFile::ReadArray(Double_t *&d)
907 R__ASSERT(IsReading());
911 Int_t l =
sizeof(Double_t)*n;
913 if (l <= 0 || l > fBufSize)
return 0;
915 if (!d) d =
new Double_t[n];
918 for (
int i = 0; i < n; i++)
919 frombuf(fBufCur, &d[i]);
921 memcpy(d, fBufCur, l);
934 Int_t TBufferFile::ReadArrayFloat16(Float_t *&f, TStreamerElement *ele)
936 R__ASSERT(IsReading());
941 if (n <= 0 || 3*n > fBufSize)
return 0;
943 if (!f) f =
new Float_t[n];
945 ReadFastArrayFloat16(f,n,ele);
956 Int_t TBufferFile::ReadArrayDouble32(Double_t *&d, TStreamerElement *ele)
958 R__ASSERT(IsReading());
963 if (n <= 0 || 3*n > fBufSize)
return 0;
965 if (!d) d =
new Double_t[n];
967 ReadFastArrayDouble32(d,n,ele);
976 Int_t TBufferFile::ReadStaticArray(Bool_t *b)
978 R__ASSERT(IsReading());
983 if (n <= 0 || n > fBufSize)
return 0;
987 if (
sizeof(Bool_t) > 1) {
988 for (
int i = 0; i < n; i++)
989 frombuf(fBufCur, &b[i]);
991 Int_t l =
sizeof(Bool_t)*n;
992 memcpy(b, fBufCur, l);
1003 Int_t TBufferFile::ReadStaticArray(Char_t *c)
1005 R__ASSERT(IsReading());
1009 Int_t l =
sizeof(Char_t)*n;
1011 if (l <= 0 || l > fBufSize)
return 0;
1015 memcpy(c, fBufCur, l);
1025 Int_t TBufferFile::ReadStaticArray(Short_t *h)
1027 R__ASSERT(IsReading());
1031 Int_t l =
sizeof(Short_t)*n;
1033 if (l <= 0 || l > fBufSize)
return 0;
1038 # ifdef USE_BSWAPCPY
1039 bswapcpy16(h, fBufCur, n);
1042 for (
int i = 0; i < n; i++)
1043 frombuf(fBufCur, &h[i]);
1046 memcpy(h, fBufCur, l);
1057 Int_t TBufferFile::ReadStaticArray(Int_t *ii)
1059 R__ASSERT(IsReading());
1063 Int_t l =
sizeof(Int_t)*n;
1065 if (l <= 0 || l > fBufSize)
return 0;
1070 # ifdef USE_BSWAPCPY
1071 bswapcpy32(ii, fBufCur, n);
1072 fBufCur +=
sizeof(Int_t)*n;
1074 for (
int i = 0; i < n; i++)
1075 frombuf(fBufCur, &ii[i]);
1078 memcpy(ii, fBufCur, l);
1089 Int_t TBufferFile::ReadStaticArray(Long_t *ll)
1091 R__ASSERT(IsReading());
1095 Int_t l =
sizeof(Long_t)*n;
1097 if (l <= 0 || l > fBufSize)
return 0;
1101 TFile *file = (TFile*)fParent;
1102 if (file && file->GetVersion() < 30006) {
1103 for (
int i = 0; i < n; i++) frombufOld(fBufCur, &ll[i]);
1105 for (
int i = 0; i < n; i++) frombuf(fBufCur, &ll[i]);
1114 Int_t TBufferFile::ReadStaticArray(Long64_t *ll)
1116 R__ASSERT(IsReading());
1120 Int_t l =
sizeof(Long64_t)*n;
1122 if (l <= 0 || l > fBufSize)
return 0;
1127 for (
int i = 0; i < n; i++)
1128 frombuf(fBufCur, &ll[i]);
1130 memcpy(ll, fBufCur, l);
1141 Int_t TBufferFile::ReadStaticArray(Float_t *f)
1143 R__ASSERT(IsReading());
1147 Int_t l =
sizeof(Float_t)*n;
1149 if (n <= 0 || l > fBufSize)
return 0;
1154 # ifdef USE_BSWAPCPY
1155 bswapcpy32(f, fBufCur, n);
1156 fBufCur +=
sizeof(Float_t)*n;
1158 for (
int i = 0; i < n; i++)
1159 frombuf(fBufCur, &f[i]);
1162 memcpy(f, fBufCur, l);
1173 Int_t TBufferFile::ReadStaticArray(Double_t *d)
1175 R__ASSERT(IsReading());
1179 Int_t l =
sizeof(Double_t)*n;
1181 if (n <= 0 || l > fBufSize)
return 0;
1186 for (
int i = 0; i < n; i++)
1187 frombuf(fBufCur, &d[i]);
1189 memcpy(d, fBufCur, l);
1201 Int_t TBufferFile::ReadStaticArrayFloat16(Float_t *f, TStreamerElement *ele)
1203 R__ASSERT(IsReading());
1208 if (n <= 0 || 3*n > fBufSize)
return 0;
1212 ReadFastArrayFloat16(f,n,ele);
1222 Int_t TBufferFile::ReadStaticArrayDouble32(Double_t *d, TStreamerElement *ele)
1224 R__ASSERT(IsReading());
1229 if (n <= 0 || 3*n > fBufSize)
return 0;
1233 ReadFastArrayDouble32(d,n,ele);
1241 void TBufferFile::ReadFastArray(Bool_t *b, Int_t n)
1243 if (n <= 0 || n > fBufSize)
return;
1245 if (
sizeof(Bool_t) > 1) {
1246 for (
int i = 0; i < n; i++)
1247 frombuf(fBufCur, &b[i]);
1249 Int_t l =
sizeof(Bool_t)*n;
1250 memcpy(b, fBufCur, l);
1258 void TBufferFile::ReadFastArray(Char_t *c, Int_t n)
1260 if (n <= 0 || n > fBufSize)
return;
1262 Int_t l =
sizeof(Char_t)*n;
1263 memcpy(c, fBufCur, l);
1270 void TBufferFile::ReadFastArrayString(Char_t *c, Int_t n)
1275 if (lenchar < 255) {
1281 if (len <= 0 || len > fBufSize)
return;
1283 if (len >= n) len = n-1;
1285 Int_t l =
sizeof(Char_t)*len;
1286 memcpy(c, fBufCur, l);
1298 void TBufferFile::ReadFastArray(Short_t *h, Int_t n)
1300 Int_t l =
sizeof(Short_t)*n;
1301 if (n <= 0 || l > fBufSize)
return;
1304 # ifdef USE_BSWAPCPY
1305 bswapcpy16(h, fBufCur, n);
1306 fBufCur +=
sizeof(Short_t)*n;
1308 for (
int i = 0; i < n; i++)
1309 frombuf(fBufCur, &h[i]);
1312 memcpy(h, fBufCur, l);
1320 void TBufferFile::ReadFastArray(Int_t *ii, Int_t n)
1322 Int_t l =
sizeof(Int_t)*n;
1323 if (l <= 0 || l > fBufSize)
return;
1326 # ifdef USE_BSWAPCPY
1327 bswapcpy32(ii, fBufCur, n);
1328 fBufCur +=
sizeof(Int_t)*n;
1330 for (
int i = 0; i < n; i++)
1331 frombuf(fBufCur, &ii[i]);
1334 memcpy(ii, fBufCur, l);
1342 void TBufferFile::ReadFastArray(Long_t *ll, Int_t n)
1344 Int_t l =
sizeof(Long_t)*n;
1345 if (l <= 0 || l > fBufSize)
return;
1347 TFile *file = (TFile*)fParent;
1348 if (file && file->GetVersion() < 30006) {
1349 for (
int i = 0; i < n; i++) frombufOld(fBufCur, &ll[i]);
1351 for (
int i = 0; i < n; i++) frombuf(fBufCur, &ll[i]);
1358 void TBufferFile::ReadFastArray(Long64_t *ll, Int_t n)
1360 Int_t l =
sizeof(Long64_t)*n;
1361 if (l <= 0 || l > fBufSize)
return;
1364 for (
int i = 0; i < n; i++)
1365 frombuf(fBufCur, &ll[i]);
1367 memcpy(ll, fBufCur, l);
1375 void TBufferFile::ReadFastArray(Float_t *f, Int_t n)
1377 Int_t l =
sizeof(Float_t)*n;
1378 if (l <= 0 || l > fBufSize)
return;
1381 # ifdef USE_BSWAPCPY
1382 bswapcpy32(f, fBufCur, n);
1383 fBufCur +=
sizeof(Float_t)*n;
1385 for (
int i = 0; i < n; i++)
1386 frombuf(fBufCur, &f[i]);
1389 memcpy(f, fBufCur, l);
1397 void TBufferFile::ReadFastArray(Double_t *d, Int_t n)
1399 Int_t l =
sizeof(Double_t)*n;
1400 if (l <= 0 || l > fBufSize)
return;
1403 for (
int i = 0; i < n; i++)
1404 frombuf(fBufCur, &d[i]);
1406 memcpy(d, fBufCur, l);
1415 void TBufferFile::ReadFastArrayFloat16(Float_t *f, Int_t n, TStreamerElement *ele)
1417 if (n <= 0 || 3*n > fBufSize)
return;
1419 if (ele && ele->GetFactor() != 0) {
1421 Double_t xmin = ele->GetXmin();
1422 Double_t factor = ele->GetFactor();
1423 for (
int j=0;j < n; j++) {
1424 UInt_t aint; *
this >> aint; f[j] = (Float_t)(aint/factor + xmin);
1429 if (ele) nbits = (Int_t)ele->GetXmin();
1430 if (!nbits) nbits = 12;
1434 Float_t fFloatValue;
1439 for (i = 0; i < n; i++) {
1444 fIntValue |= (theMan & ((1<<(nbits+1))-1)) <<(23-nbits);
1445 if(1<<(nbits+1) & theMan) fFloatValue = -fFloatValue;
1455 void TBufferFile::ReadFastArrayWithFactor(Float_t *ptr, Int_t n, Double_t factor, Double_t minvalue)
1457 if (n <= 0 || 3*n > fBufSize)
return;
1460 for (
int j=0;j < n; j++) {
1461 UInt_t aint; *
this >> aint; ptr[j] = (Float_t)(aint/factor + minvalue);
1469 void TBufferFile::ReadFastArrayWithNbits(Float_t *ptr, Int_t n, Int_t nbits)
1471 if (n <= 0 || 3*n > fBufSize)
return;
1473 if (!nbits) nbits = 12;
1477 Float_t fFloatValue;
1482 for (Int_t i = 0; i < n; i++) {
1487 fIntValue |= (theMan & ((1<<(nbits+1))-1)) <<(23-nbits);
1488 if(1<<(nbits+1) & theMan) fFloatValue = -fFloatValue;
1489 ptr[i] = fFloatValue;
1497 void TBufferFile::ReadFastArrayDouble32(Double_t *d, Int_t n, TStreamerElement *ele)
1499 if (n <= 0 || 3*n > fBufSize)
return;
1501 if (ele && ele->GetFactor() != 0) {
1503 Double_t xmin = ele->GetXmin();
1504 Double_t factor = ele->GetFactor();
1505 for (
int j=0;j < n; j++) {
1506 UInt_t aint; *
this >> aint; d[j] = (Double_t)(aint/factor + xmin);
1511 if (ele) nbits = (Int_t)ele->GetXmin();
1515 for (i = 0; i < n; i++) {
1517 d[i] = (Double_t)afloat;
1523 Float_t fFloatValue;
1528 for (i = 0; i < n; i++) {
1533 fIntValue |= (theMan & ((1<<(nbits+1))-1)) <<(23-nbits);
1534 if (1<<(nbits+1) & theMan) fFloatValue = -fFloatValue;
1535 d[i] = (Double_t)fFloatValue;
1545 void TBufferFile::ReadFastArrayWithFactor(Double_t *d, Int_t n, Double_t factor, Double_t minvalue)
1547 if (n <= 0 || 3*n > fBufSize)
return;
1550 for (
int j=0;j < n; j++) {
1551 UInt_t aint; *
this >> aint; d[j] = (Double_t)(aint/factor + minvalue);
1559 void TBufferFile::ReadFastArrayWithNbits(Double_t *d, Int_t n, Int_t nbits)
1561 if (n <= 0 || 3*n > fBufSize)
return;
1566 for (Int_t i = 0; i < n; i++) {
1568 d[i] = (Double_t)afloat;
1574 Float_t fFloatValue;
1579 for (Int_t i = 0; i < n; i++) {
1584 fIntValue |= (theMan & ((1<<(nbits+1))-1)) <<(23-nbits);
1585 if (1<<(nbits+1) & theMan) fFloatValue = -fFloatValue;
1586 d[i] = (Double_t)fFloatValue;
1596 void TBufferFile::ReadFastArray(
void *start,
const TClass *cl, Int_t n,
1597 TMemberStreamer *streamer,
const TClass* onFileClass )
1600 streamer->SetOnFileClass(onFileClass);
1601 (*streamer)(*
this,start,0);
1605 int objectSize = cl->Size();
1606 char *obj = (
char*)start;
1607 char *end = obj + n*objectSize;
1609 for(; obj<end; obj+=objectSize) ((TClass*)cl)->Streamer(obj,*
this, onFileClass);
1619 void TBufferFile::ReadFastArray(
void **start,
const TClass *cl, Int_t n,
1620 Bool_t isPreAlloc, TMemberStreamer *streamer,
const TClass* onFileClass)
1627 for (Int_t j=0;j<n;j++) {
1628 if (!start[j]) start[j] = cl->New();
1631 streamer->SetOnFileClass(onFileClass);
1632 (*streamer)(*
this,(
void*)start,0);
1638 for (Int_t j=0; j<n; j++){
1640 void *old = start[j];
1641 start[j] = ReadObjectAny(cl);
1642 if (old && old!=start[j] &&
1643 TStreamerInfo::CanDelete()
1660 ((TClass*)cl)->Destructor(old,kFALSE);
1667 for (Int_t j=0; j<n; j++){
1668 if (!start[j]) start[j] = ((TClass*)cl)->New();
1669 ((TClass*)cl)->Streamer(start[j],*
this,onFileClass);
1678 void TBufferFile::WriteArray(
const Bool_t *b, Int_t n)
1680 R__ASSERT(IsWriting());
1688 Int_t l =
sizeof(UChar_t)*n;
1689 if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
1691 if (
sizeof(Bool_t) > 1) {
1692 for (
int i = 0; i < n; i++)
1693 tobuf(fBufCur, b[i]);
1695 memcpy(fBufCur, b, l);
1703 void TBufferFile::WriteArray(
const Char_t *c, Int_t n)
1705 R__ASSERT(IsWriting());
1713 Int_t l =
sizeof(Char_t)*n;
1714 if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
1716 memcpy(fBufCur, c, l);
1723 void TBufferFile::WriteArray(
const Short_t *h, Int_t n)
1725 R__ASSERT(IsWriting());
1733 Int_t l =
sizeof(Short_t)*n;
1734 if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
1737 # ifdef USE_BSWAPCPY
1738 bswapcpy16(fBufCur, h, n);
1741 for (
int i = 0; i < n; i++)
1742 tobuf(fBufCur, h[i]);
1745 memcpy(fBufCur, h, l);
1753 void TBufferFile::WriteArray(
const Int_t *ii, Int_t n)
1755 R__ASSERT(IsWriting());
1763 Int_t l =
sizeof(Int_t)*n;
1764 if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
1767 # ifdef USE_BSWAPCPY
1768 bswapcpy32(fBufCur, ii, n);
1771 for (
int i = 0; i < n; i++)
1772 tobuf(fBufCur, ii[i]);
1775 memcpy(fBufCur, ii, l);
1783 void TBufferFile::WriteArray(
const Long_t *ll, Int_t n)
1785 R__ASSERT(IsWriting());
1794 if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
1795 for (
int i = 0; i < n; i++) tobuf(fBufCur, ll[i]);
1803 void TBufferFile::WriteArray(
const ULong_t *ll, Int_t n)
1805 R__ASSERT(IsWriting());
1814 if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
1815 for (
int i = 0; i < n; i++) tobuf(fBufCur, ll[i]);
1821 void TBufferFile::WriteArray(
const Long64_t *ll, Int_t n)
1823 R__ASSERT(IsWriting());
1831 Int_t l =
sizeof(Long64_t)*n;
1832 if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
1835 for (
int i = 0; i < n; i++)
1836 tobuf(fBufCur, ll[i]);
1838 memcpy(fBufCur, ll, l);
1846 void TBufferFile::WriteArray(
const Float_t *f, Int_t n)
1848 R__ASSERT(IsWriting());
1856 Int_t l =
sizeof(Float_t)*n;
1857 if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
1860 # ifdef USE_BSWAPCPY
1861 bswapcpy32(fBufCur, f, n);
1864 for (
int i = 0; i < n; i++)
1865 tobuf(fBufCur, f[i]);
1868 memcpy(fBufCur, f, l);
1876 void TBufferFile::WriteArray(
const Double_t *d, Int_t n)
1878 R__ASSERT(IsWriting());
1886 Int_t l =
sizeof(Double_t)*n;
1887 if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
1890 for (
int i = 0; i < n; i++)
1891 tobuf(fBufCur, d[i]);
1893 memcpy(fBufCur, d, l);
1902 void TBufferFile::WriteArrayFloat16(
const Float_t *f, Int_t n, TStreamerElement *ele)
1904 R__ASSERT(IsWriting());
1912 Int_t l =
sizeof(Float_t)*n;
1913 if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
1915 WriteFastArrayFloat16(f,n,ele);
1922 void TBufferFile::WriteArrayDouble32(
const Double_t *d, Int_t n, TStreamerElement *ele)
1924 R__ASSERT(IsWriting());
1932 Int_t l =
sizeof(Float_t)*n;
1933 if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
1935 WriteFastArrayDouble32(d,n,ele);
1941 void TBufferFile::WriteFastArray(
const Bool_t *b, Int_t n)
1945 Int_t l =
sizeof(UChar_t)*n;
1946 if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
1948 if (
sizeof(Bool_t) > 1) {
1949 for (
int i = 0; i < n; i++)
1950 tobuf(fBufCur, b[i]);
1952 memcpy(fBufCur, b, l);
1960 void TBufferFile::WriteFastArray(
const Char_t *c, Int_t n)
1964 Int_t l =
sizeof(Char_t)*n;
1965 if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
1967 memcpy(fBufCur, c, l);
1974 void TBufferFile::WriteFastArrayString(
const Char_t *c, Int_t n)
1977 *
this << (UChar_t)n;
1979 *
this << (UChar_t)255;
1985 Int_t l =
sizeof(Char_t)*n;
1986 if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
1988 memcpy(fBufCur, c, l);
1995 void TBufferFile::WriteFastArray(
const Short_t *h, Int_t n)
1999 Int_t l =
sizeof(Short_t)*n;
2000 if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
2003 # ifdef USE_BSWAPCPY
2004 bswapcpy16(fBufCur, h, n);
2007 for (
int i = 0; i < n; i++)
2008 tobuf(fBufCur, h[i]);
2011 memcpy(fBufCur, h, l);
2019 void TBufferFile::WriteFastArray(
const Int_t *ii, Int_t n)
2023 Int_t l =
sizeof(Int_t)*n;
2024 if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
2027 # ifdef USE_BSWAPCPY
2028 bswapcpy32(fBufCur, ii, n);
2031 for (
int i = 0; i < n; i++)
2032 tobuf(fBufCur, ii[i]);
2035 memcpy(fBufCur, ii, l);
2043 void TBufferFile::WriteFastArray(
const Long_t *ll, Int_t n)
2048 if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
2050 for (
int i = 0; i < n; i++) tobuf(fBufCur, ll[i]);
2058 void TBufferFile::WriteFastArray(
const ULong_t *ll, Int_t n)
2063 if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
2065 for (
int i = 0; i < n; i++) tobuf(fBufCur, ll[i]);
2071 void TBufferFile::WriteFastArray(
const Long64_t *ll, Int_t n)
2075 Int_t l =
sizeof(Long64_t)*n;
2076 if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
2079 for (
int i = 0; i < n; i++)
2080 tobuf(fBufCur, ll[i]);
2082 memcpy(fBufCur, ll, l);
2090 void TBufferFile::WriteFastArray(
const Float_t *f, Int_t n)
2094 Int_t l =
sizeof(Float_t)*n;
2095 if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
2098 # ifdef USE_BSWAPCPY
2099 bswapcpy32(fBufCur, f, n);
2102 for (
int i = 0; i < n; i++)
2103 tobuf(fBufCur, f[i]);
2106 memcpy(fBufCur, f, l);
2114 void TBufferFile::WriteFastArray(
const Double_t *d, Int_t n)
2118 Int_t l =
sizeof(Double_t)*n;
2119 if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
2122 for (
int i = 0; i < n; i++)
2123 tobuf(fBufCur, d[i]);
2125 memcpy(fBufCur, d, l);
2134 void TBufferFile::WriteFastArrayFloat16(
const Float_t *f, Int_t n, TStreamerElement *ele)
2138 Int_t l =
sizeof(Float_t)*n;
2139 if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
2141 if (ele && ele->GetFactor()) {
2145 Double_t factor = ele->GetFactor();
2146 Double_t xmin = ele->GetXmin();
2147 Double_t xmax = ele->GetXmax();
2148 for (
int j = 0; j < n; j++) {
2150 if (x < xmin) x = xmin;
2151 if (x > xmax) x = xmax;
2152 UInt_t aint = UInt_t(0.5+factor*(x-xmin)); *
this << aint;
2157 if (ele) nbits = (Int_t)ele->GetXmin();
2158 if (!nbits) nbits = 12;
2164 Float_t fFloatValue;
2167 for (i = 0; i < n; i++) {
2169 UChar_t theExp = (UChar_t)(0x000000ff & ((fIntValue<<1)>>24));
2170 UShort_t theMan = ((1<<(nbits+1))-1) & (fIntValue>>(23-nbits-1));
2173 if (theMan&1<<nbits) theMan = (1<<nbits) - 1;
2174 if (fFloatValue < 0) theMan |= 1<<(nbits+1);
2185 void TBufferFile::WriteFastArrayDouble32(
const Double_t *d, Int_t n, TStreamerElement *ele)
2189 Int_t l =
sizeof(Float_t)*n;
2190 if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
2192 if (ele && ele->GetFactor()) {
2196 Double_t factor = ele->GetFactor();
2197 Double_t xmin = ele->GetXmin();
2198 Double_t xmax = ele->GetXmax();
2199 for (
int j = 0; j < n; j++) {
2201 if (x < xmin) x = xmin;
2202 if (x > xmax) x = xmax;
2203 UInt_t aint = UInt_t(0.5+factor*(x-xmin)); *
this << aint;
2208 if (ele) nbits = (Int_t)ele->GetXmin();
2212 for (i = 0; i < n; i++) {
2213 Float_t afloat = (Float_t)d[i];
2221 Float_t fFloatValue;
2224 for (i = 0; i < n; i++) {
2225 fFloatValue = (Float_t)d[i];
2226 UChar_t theExp = (UChar_t)(0x000000ff & ((fIntValue<<1)>>24));
2227 UShort_t theMan = ((1<<(nbits+1))-1) & (fIntValue>>(23-nbits-1));
2230 if(theMan&1<<nbits) theMan = (1<<nbits) - 1;
2231 if (fFloatValue < 0) theMan |= 1<<(nbits+1);
2243 void TBufferFile::WriteFastArray(
void *start,
const TClass *cl, Int_t n,
2244 TMemberStreamer *streamer)
2247 (*streamer)(*
this, start, 0);
2251 char *obj = (
char*)start;
2253 int size = cl->Size();
2255 for(Int_t j=0; j<n; j++,obj+=size) {
2256 ((TClass*)cl)->Streamer(obj,*
this);
2268 Int_t TBufferFile::WriteFastArray(
void **start,
const TClass *cl, Int_t n,
2269 Bool_t isPreAlloc, TMemberStreamer *streamer)
2275 (*streamer)(*
this,(
void*)start,0);
2285 for (Int_t j=0;j<n;j++) {
2287 if (!strInfo && !start[j]) {
2288 if (cl->Property() & kIsAbstract) {
2291 TStreamerInfo *info = (TStreamerInfo*)((TClass*)cl)->GetStreamerInfo();
2292 ForceWriteInfo(info,kFALSE);
2296 res |= WriteObjectAny(start[j],cl);
2302 for (Int_t j=0;j<n;j++) {
2303 if (!start[j]) start[j] = ((TClass*)cl)->New();
2304 ((TClass*)cl)->Streamer(start[j],*
this);
2321 TObject *TBufferFile::ReadObject(
const TClass * )
2323 return (TObject*) ReadObjectAny(
nullptr);
2329 void TBufferFile::SkipObjectAny()
2331 UInt_t start, count;
2332 ReadVersion(&start, &count);
2333 SetBufferOffset(start+count+
sizeof(UInt_t));
2349 void *TBufferFile::ReadObjectAny(
const TClass *clCast)
2351 R__ASSERT(IsReading());
2357 UInt_t startpos = UInt_t(fBufCur-fBuffer);
2361 TClass *clRef = ReadClass(clCast, &tag);
2362 TClass *clOnfile =
nullptr;
2363 Int_t baseOffset = 0;
2364 if (clRef && (clRef!=(TClass*)(-1)) && clCast) {
2366 baseOffset = clRef->GetBaseClassOffset(clCast);
2367 if (baseOffset == -1) {
2370 if (!clCast->GetSchemaRules() ||
2371 !clCast->GetSchemaRules()->HasRuleWithSourceClass(clRef->GetName()))
2374 Error(
"ReadObject",
"got object of wrong class! requested %s but got %s",
2375 clCast->GetName(), clRef->GetName());
2377 CheckByteCount(startpos, tag, (TClass *)
nullptr);
2382 Info(
"ReadObjectAny",
"Using Converter StreamerInfo from %s to %s",clRef->GetName(),clCast->GetName());
2383 clRef =
const_cast<TClass*
>(clCast);
2386 if (clCast->GetState() > TClass::kEmulated && clRef->GetState() <= TClass::kEmulated) {
2388 Error(
"ReadObject",
"trying to read an emulated class (%s) to store in a compiled pointer (%s)",
2389 clRef->GetName(),clCast->GetName());
2390 CheckByteCount(startpos, tag, (TClass *)
nullptr);
2399 obj = (
char *) (Long_t)fMap->GetValue(startpos+kMapOffset);
2400 if (obj == (
void*) -1) obj =
nullptr;
2402 CheckByteCount(startpos, tag, (TClass *)
nullptr);
2403 return (obj + baseOffset);
2408 if (clRef == (TClass*) -1) {
2409 if (fBufCur >= fBufMax)
return 0;
2411 MapObject((TObject*) -1, startpos+kMapOffset);
2413 MapObject((
void*)
nullptr,
nullptr, fMapCount);
2414 CheckByteCount(startpos, tag, (TClass *)
nullptr);
2422 tag += fDisplacement;
2423 tag = CheckObject(tag, clCast);
2425 if (tag > (UInt_t)fMap->GetSize()) {
2426 Error(
"ReadObject",
"object tag too large, I/O buffer corrupted");
2431 obj = (
char *) (Long_t)fMap->GetValue(tag);
2432 clRef = (TClass*) (Long_t)fClassMap->GetValue(tag);
2434 if (clRef && (clRef!=(TClass*)(-1)) && clCast) {
2436 baseOffset = clRef->GetBaseClassOffset(clCast);
2437 if (baseOffset == -1) {
2438 Error(
"ReadObject",
"Got object of wrong class (Got %s while expecting %s)",
2439 clRef->GetName(),clCast->GetName());
2456 obj = (
char*)clRef->New();
2458 Error(
"ReadObject",
"could not create object of class %s",
2466 MapObject(obj, clRef, startpos+kMapOffset);
2468 MapObject(obj, clRef, fMapCount);
2471 clRef->Streamer( obj, *
this, clOnfile );
2473 CheckByteCount(startpos, tag, clRef);
2476 return obj+baseOffset;
2489 void TBufferFile::WriteObjectClass(
const void *actualObjectStart,
const TClass *actualClass, Bool_t cacheReuse)
2491 R__ASSERT(IsWriting());
2493 if (!actualObjectStart) {
2496 *
this << (UInt_t) kNullTag;
2505 ULong_t hash = Void_Hash(actualObjectStart);
2507 if ((idx = (ULong_t)fMap->GetValue(hash, (Long_t)actualObjectStart, slot)) != 0) {
2511 UInt_t objIdx = UInt_t(idx);
2520 if (!actualClass->HasDefaultConstructor()) {
2521 Warning(
"WriteObjectAny",
"since %s has no public constructor\n"
2522 "\twhich can be called without argument, objects of this class\n"
2523 "\tcan not be read with the current library. You will need to\n"
2524 "\tadd a default constructor before attempting to read it.",
2525 actualClass->GetName());
2529 UInt_t cntpos = UInt_t(fBufCur-fBuffer);
2530 fBufCur +=
sizeof(UInt_t);
2533 Int_t mapsize = fMap->Capacity();
2534 WriteClass(actualClass);
2540 UInt_t offset = cntpos+kMapOffset;
2541 if (mapsize == fMap->Capacity()) {
2542 fMap->AddAt(slot, hash, (Long_t)actualObjectStart, offset);
2545 fMap->Add(hash, (Long_t)actualObjectStart, offset);
2552 ((TClass*)actualClass)->Streamer((
void*)actualObjectStart,*
this);
2555 SetByteCount(cntpos);
2566 TClass *TBufferFile::ReadClass(
const TClass *clReq, UInt_t *objTag)
2568 R__ASSERT(IsReading());
2572 if (fBufCur < fBuffer || fBufCur > fBufMax) {
2577 UInt_t bcnt, tag, startpos = 0;
2579 if (!(bcnt & kByteCountMask) || bcnt == kNewClassTag) {
2584 startpos = UInt_t(fBufCur-fBuffer);
2589 if (!(tag & kClassMask)) {
2590 if (objTag) *objTag = tag;
2594 if (tag == kNewClassTag) {
2599 cl = TClass::Load(*
this);
2604 TClass *cl1 = (TClass *)(Long_t)fMap->GetValue(startpos+kMapOffset);
2606 MapObject(cl ? cl : (TObject*) -1, startpos+kMapOffset);
2608 MapObject(cl, fMapCount);
2613 UInt_t clTag = (tag & ~kClassMask);
2616 clTag += fDisplacement;
2617 clTag = CheckObject(clTag, clReq, kTRUE);
2619 if (clTag == 0 || clTag > (UInt_t)fMap->GetSize()) {
2620 Error(
"ReadClass",
"illegal class tag=%d (0<tag<=%d), I/O buffer corrupted",
2621 clTag, fMap->GetSize());
2627 cl = (TClass *)(Long_t)fMap->GetValue(clTag);
2631 (!cl->InheritsFrom(clReq) &&
2632 !(clReq->GetSchemaRules() &&
2633 clReq->GetSchemaRules()->HasRuleWithSourceClass(cl->GetName()) )
2635 Error(
"ReadClass",
"The on-file class is \"'%s\" which is not compatible with the requested class: \"%s\"",
2636 cl->GetName(), clReq->GetName());
2641 if (objTag) *objTag = (bcnt & ~kByteCountMask);
2644 if (!cl) cl = (TClass*)-1;
2652 void TBufferFile::WriteClass(
const TClass *cl)
2654 R__ASSERT(IsWriting());
2657 ULong_t hash = Void_Hash(cl);
2660 if ((idx = (ULong_t)fMap->GetValue(hash, (Long_t)cl,slot)) != 0) {
2664 UInt_t clIdx = UInt_t(idx);
2667 *
this << (clIdx | kClassMask);
2672 UInt_t offset = UInt_t(fBufCur-fBuffer);
2675 *
this << kNewClassTag;
2681 CheckCount(offset+kMapOffset);
2682 fMap->AddAt(slot, hash, (Long_t)cl, offset+kMapOffset);
2690 void TBufferFile::SkipVersion(
const TClass *cl)
2695 frombuf(this->fBufCur,&version);
2698 if (version & kByteCountVMask) {
2699 frombuf(this->fBufCur,&version);
2700 frombuf(this->fBufCur,&version);
2703 if (cl && cl->GetClassVersion() != 0 && version<=1) {
2705 UInt_t checksum = 0;
2707 frombuf(this->fBufCur,&checksum);
2708 TStreamerInfo *vinfo = (TStreamerInfo*)cl->FindStreamerInfo(checksum);
2716 if (checksum==cl->GetCheckSum() || cl->MatchLegacyCheckSum(checksum)) {
2717 version = cl->GetClassVersion();
2720 Error(
"SkipVersion",
"Could not find the StreamerInfo with a checksum of %d for the class \"%s\" in %s.",
2721 checksum, cl->GetName(), ((TFile*)fParent)->GetName());
2723 Error(
"SkipVersion",
"Could not find the StreamerInfo with a checksum of %d for the class \"%s\" (buffer with no parent)",
2724 checksum, cl->GetName());
2729 }
else if (version == 1 && fParent && ((TFile*)fParent)->GetVersion()<40000 ) {
2732 if ((!cl->IsLoaded() || cl->IsForeign()) &&
2733 Class_Has_StreamerInfo(cl) ) {
2735 const TList *list = ((TFile*)fParent)->GetStreamerInfoCache();
2736 const TStreamerInfo *local = list ? (TStreamerInfo*)list->FindObject(cl->GetName()) : 0;
2738 UInt_t checksum = local->GetCheckSum();
2739 TStreamerInfo *vinfo = (TStreamerInfo*)cl->FindStreamerInfo(checksum);
2741 version = vinfo->GetClassVersion();
2743 Error(
"SkipVersion",
"Could not find the StreamerInfo with a checksum of %d for the class \"%s\" in %s.",
2744 checksum, cl->GetName(), ((TFile*)fParent)->GetName());
2749 Error(
"SkipVersion",
"Class %s not known to file %s.",
2750 cl->GetName(), ((TFile*)fParent)->GetName());
2761 Version_t TBufferFile::ReadVersion(UInt_t *startpos, UInt_t *bcnt,
const TClass *cl)
2767 *startpos = UInt_t(fBufCur-fBuffer);
2779 frombuf(this->fBufCur,&v.vers[1]);
2780 frombuf(this->fBufCur,&v.vers[0]);
2782 frombuf(this->fBufCur,&v.vers[0]);
2783 frombuf(this->fBufCur,&v.vers[1]);
2787 if (!(v.cnt & kByteCountMask)) {
2788 fBufCur -=
sizeof(UInt_t);
2791 if (bcnt) *bcnt = (v.cnt & ~kByteCountMask);
2792 frombuf(this->fBufCur,&version);
2797 if (cl->GetClassVersion() != 0
2799 && (v.cnt && v.cnt >= 6)
2801 UInt_t checksum = 0;
2803 frombuf(this->fBufCur,&checksum);
2804 TStreamerInfo *vinfo = (TStreamerInfo*)cl->FindStreamerInfo(checksum);
2806 return vinfo->TStreamerInfo::GetClassVersion();
2812 if (checksum==cl->GetCheckSum() || cl->MatchLegacyCheckSum(checksum)) {
2813 version = cl->GetClassVersion();
2816 Error(
"ReadVersion",
"Could not find the StreamerInfo with a checksum of 0x%x for the class \"%s\" in %s.",
2817 checksum, cl->GetName(), ((TFile*)fParent)->GetName());
2819 Error(
"ReadVersion",
"Could not find the StreamerInfo with a checksum of 0x%x for the class \"%s\" (buffer with no parent)",
2820 checksum, cl->GetName());
2827 UInt_t checksum = 0;
2830 if (v.cnt && v.cnt >= 6)
2831 frombuf(this->fBufCur,&checksum);
2833 }
else if (version == 1 && fParent && ((TFile*)fParent)->GetVersion()<40000 && cl && cl->GetClassVersion() != 0) {
2836 if ((!cl->IsLoaded() || cl->IsForeign()) &&
2837 Class_Has_StreamerInfo(cl) ) {
2839 const TList *list = ((TFile*)fParent)->GetStreamerInfoCache();
2840 const TStreamerInfo *local = list ? (TStreamerInfo*)list->FindObject(cl->GetName()) : 0;
2842 UInt_t checksum = local->GetCheckSum();
2843 TStreamerInfo *vinfo = (TStreamerInfo*)cl->FindStreamerInfo(checksum);
2845 version = vinfo->GetClassVersion();
2847 Error(
"ReadVersion",
"Could not find the StreamerInfo with a checksum of 0x%x for the class \"%s\" in %s.",
2848 checksum, cl->GetName(), ((TFile*)fParent)->GetName());
2853 Error(
"ReadVersion",
"Class %s not known to file %s.",
2854 cl->GetName(), ((TFile*)fParent)->GetName());
2867 Version_t TBufferFile::ReadVersionNoCheckSum(UInt_t *startpos, UInt_t *bcnt)
2873 *startpos = UInt_t(fBufCur-fBuffer);
2885 frombuf(this->fBufCur,&v.vers[1]);
2886 frombuf(this->fBufCur,&v.vers[0]);
2888 frombuf(this->fBufCur,&v.vers[0]);
2889 frombuf(this->fBufCur,&v.vers[1]);
2893 if (!(v.cnt & kByteCountMask)) {
2894 fBufCur -=
sizeof(UInt_t);
2897 if (bcnt) *bcnt = (v.cnt & ~kByteCountMask);
2898 frombuf(this->fBufCur,&version);
2910 Version_t TBufferFile::ReadVersionForMemberWise(
const TClass *cl)
2915 frombuf(this->fBufCur,&version);
2920 if (cl->GetClassVersion() != 0) {
2921 UInt_t checksum = 0;
2922 frombuf(this->fBufCur,&checksum);
2923 TStreamerInfo *vinfo = (TStreamerInfo*)cl->FindStreamerInfo(checksum);
2925 return vinfo->TStreamerInfo::GetClassVersion();
2931 if (checksum==cl->GetCheckSum() || cl->MatchLegacyCheckSum(checksum)) {
2932 version = cl->GetClassVersion();
2942 UInt_t checksum = 0;
2943 frombuf(this->fBufCur,&checksum);
2945 }
else if (version == 1 && fParent && ((TFile*)fParent)->GetVersion()<40000 && cl && cl->GetClassVersion() != 0) {
2948 if ((!cl->IsLoaded() || cl->IsForeign()) && Class_Has_StreamerInfo(cl) ) {
2950 const TList *list = ((TFile*)fParent)->GetStreamerInfoCache();
2951 const TStreamerInfo *local = list ? (TStreamerInfo*)list->FindObject(cl->GetName()) : 0;
2953 UInt_t checksum = local->GetCheckSum();
2954 TStreamerInfo *vinfo = (TStreamerInfo*)cl->FindStreamerInfo(checksum);
2956 version = vinfo->GetClassVersion();
2965 Error(
"ReadVersion",
"Class %s not known to file %s.",
2966 cl->GetName(), ((TFile*)fParent)->GetName());
2978 UInt_t TBufferFile::WriteVersion(
const TClass *cl, Bool_t useBcnt)
2983 cntpos = UInt_t(fBufCur-fBuffer);
2984 fBufCur +=
sizeof(UInt_t);
2987 Version_t version = cl->GetClassVersion();
2988 if (version<=1 && cl->IsForeign()) {
2989 *
this << Version_t(0);
2990 *
this << cl->GetCheckSum();
2992 if (version > kMaxVersion) {
2993 Error(
"WriteVersion",
"version number cannot be larger than %hd)",
2995 version = kMaxVersion;
3008 UInt_t TBufferFile::WriteVersionMemberWise(
const TClass *cl, Bool_t useBcnt)
3013 cntpos = UInt_t(fBufCur-fBuffer);
3014 fBufCur +=
sizeof(UInt_t);
3017 Version_t version = cl->GetClassVersion();
3018 if (version<=1 && cl->IsForeign()) {
3019 Error(
"WriteVersionMemberWise",
"Member-wise streaming of foreign collection not yet implemented!");
3020 *
this << Version_t(0);
3021 *
this << cl->GetCheckSum();
3023 if (version > kMaxVersion) {
3024 Error(
"WriteVersionMemberWise",
"version number cannot be larger than %hd)",
3026 version = kMaxVersion;
3028 version |= kStreamedMemberWise;
3039 void TBufferFile::StreamObject(
void *obj,
const std::type_info &typeinfo,
const TClass* onFileClass )
3041 TClass *cl = TClass::GetClass(typeinfo);
3042 if (cl) cl->Streamer(obj, *
this, (TClass*)onFileClass );
3043 else Warning(
"StreamObject",
"No TClass for the type %s is available, the object was not read.", typeinfo.name());
3049 void TBufferFile::StreamObject(
void *obj,
const char *className,
const TClass* onFileClass)
3051 TClass *cl = TClass::GetClass(className);
3052 if (cl) cl->Streamer(obj, *
this, (TClass*)onFileClass );
3053 else Warning(
"StreamObject",
"No TClass for the type %s is available, the object was not read.", className);
3059 void TBufferFile::StreamObject(
void *obj,
const TClass *cl,
const TClass* onFileClass )
3061 ((TClass*)cl)->Streamer(obj, *
this, (TClass*)onFileClass );
3067 void TBufferFile::StreamObject(TObject *obj)
3069 obj->Streamer(*
this);
3075 void TBufferFile::CheckCount(UInt_t offset)
3078 if (offset >= kMaxMapCount) {
3079 Error(
"CheckCount",
"buffer offset too large (larger than %d)", kMaxMapCount);
3091 UInt_t TBufferFile::CheckObject(UInt_t offset,
const TClass *cl, Bool_t readClass)
3094 if (!offset)
return offset;
3099 if ((cli = fMap->GetValue(offset)) == 0) {
3104 char *bufsav = fBufCur;
3105 fBufCur = (
char *)(fBuffer + offset-kMapOffset-
sizeof(UInt_t));
3107 TClass *c = ReadClass(cl);
3108 if (c == (TClass*) -1) {
3110 fMap->Remove(offset);
3111 fMap->Add(offset, -1);
3114 Warning(
"CheckObject",
"reference to unavailable class %s,"
3115 " pointers of this type will be 0", cl->GetName());
3117 Warning(
"CheckObject",
"reference to an unavailable class,"
3118 " pointers of that type will be 0");
3123 }
else if (cli == -1) {
3131 if ((cli = fMap->GetValue(offset)) == 0) {
3136 char *bufsav = fBufCur;
3137 fBufCur = (
char *)(fBuffer + offset-kMapOffset);
3139 TObject *obj = ReadObject(cl);
3142 fMap->Remove(offset);
3143 fMap->Add(offset, -1);
3144 Warning(
"CheckObject",
"reference to object of unavailable class %s, offset=%d"
3145 " pointer will be 0", cl ? cl->GetName() :
"TObject",offset);
3151 }
else if (cli == -1) {
3167 Int_t TBufferFile::ReadBuf(
void *buf, Int_t max)
3169 R__ASSERT(IsReading());
3171 if (max == 0)
return 0;
3173 Int_t n = TMath::Min(max, (Int_t)(fBufMax - fBufCur));
3175 memcpy(buf, fBufCur, n);
3184 void TBufferFile::WriteBuf(
const void *buf, Int_t max)
3186 R__ASSERT(IsWriting());
3188 if (max == 0)
return;
3190 if (fBufCur + max > fBufMax) AutoExpand(fBufSize+max);
3192 memcpy(fBufCur, buf, max);
3202 char *TBufferFile::ReadString(
char *s, Int_t max)
3204 R__ASSERT(IsReading());
3209 if (max == -1) max = kMaxInt;
3211 while (nr < max-1) {
3229 void TBufferFile::WriteString(
const char *s)
3231 WriteBuf(s, (strlen(s)+1)*
sizeof(
char));
3237 Int_t TBufferFile::ReadClassEmulated(
const TClass *cl,
void *
object,
const TClass *onFileClass)
3242 Version_t v = ReadVersion(&start,&count);
3245 TStreamerInfo *sinfo =
nullptr;
3247 sinfo = (TStreamerInfo*)cl->GetConversionStreamerInfo( onFileClass, v );
3252 sinfo = (TStreamerInfo*)cl->GetStreamerInfo(v);
3253 ApplySequence(*(sinfo->GetReadObjectWiseActions()),
object);
3254 if (sinfo->IsRecovered()) count=0;
3255 CheckByteCount(start,count,cl);
3257 SetBufferOffset(start);
3258 TStreamerInfo *sinfo = ((TStreamerInfo*)cl->GetStreamerInfo());
3259 ApplySequence(*(sinfo->GetReadObjectWiseActions()),
object);
3277 Int_t TBufferFile::ReadClassBuffer(
const TClass *cl,
void *pointer, Int_t version, UInt_t start, UInt_t count,
const TClass *onFileClass)
3284 TStreamerInfo *sinfo =
nullptr;
3286 sinfo = (TStreamerInfo*)cl->GetConversionStreamerInfo( onFileClass, version );
3288 Error(
"ReadClassBuffer",
3289 "Could not find the right streamer info to convert %s version %d into a %s, object skipped at offset %d",
3290 onFileClass->GetName(), version, cl->GetName(), Length() );
3291 CheckByteCount(start, count, onFileClass);
3301 R__LOCKGUARD(gInterpreterMutex);
3302 auto infos = cl->GetStreamerInfos();
3303 auto ninfos = infos->GetSize();
3304 if (version < -1 || version >= ninfos) {
3305 Error(
"ReadClassBuffer",
"class: %s, attempting to access a wrong version: %d, object skipped at offset %d",
3306 cl->GetName(), version, Length() );
3307 CheckByteCount(start, count, cl);
3310 sinfo = (TStreamerInfo*)infos->At(version);
3311 if (sinfo ==
nullptr) {
3317 if ( version == cl->GetClassVersion() || version == 1 ) {
3318 const_cast<TClass*
>(cl)->BuildRealData(pointer);
3321 sinfo =
new TStreamerInfo(const_cast<TClass*>(cl));
3322 const_cast<TClass*
>(cl)->RegisterStreamerInfo(sinfo);
3323 if (gDebug > 0) Info(
"ReadClassBuffer",
"Creating StreamerInfo for class: %s, version: %d", cl->GetName(), version);
3325 }
else if (version==0) {
3329 CheckByteCount(start, count, cl);
3332 Error(
"ReadClassBuffer",
"Could not find the StreamerInfo for version %d of the class %s, object skipped at offset %d",
3333 version, cl->GetName(), Length() );
3334 CheckByteCount(start, count, cl);
3337 }
else if (!sinfo->IsCompiled()) {
3340 const_cast<TClass*
>(cl)->BuildRealData(pointer);
3346 ApplySequence(*(sinfo->GetReadObjectWiseActions()), (
char*)pointer);
3347 if (sinfo->IsRecovered()) count=0;
3350 CheckByteCount(start, count, cl);
3361 Int_t TBufferFile::ReadClassBuffer(const TClass *cl,
void *pointer, const TClass *onFileClass)
3369 version = ReadVersion(&R__s, &R__c, onFileClass);
3371 version = ReadVersion(&R__s, &R__c, cl);
3373 Bool_t v2file = kFALSE;
3374 TFile *file = (TFile*)GetParent();
3375 if (file && file->GetVersion() < 30000) {
3384 TStreamerInfo *sinfo =
nullptr;
3386 sinfo = (TStreamerInfo*)cl->GetConversionStreamerInfo( onFileClass, version );
3388 Error(
"ReadClassBuffer",
3389 "Could not find the right streamer info to convert %s version %d into a %s, object skipped at offset %d",
3390 onFileClass->GetName(), version, cl->GetName(), Length() );
3391 CheckByteCount(R__s, R__c, onFileClass);
3401 TStreamerInfo *guess = (TStreamerInfo*)cl->GetLastReadInfo();
3402 if (guess && guess->GetClassVersion() == version) {
3407 R__LOCKGUARD(gInterpreterMutex);
3409 const TObjArray *infos = cl->GetStreamerInfos();
3410 Int_t infocapacity = infos->Capacity();
3412 if (version < -1 || version >= infocapacity) {
3413 Error(
"ReadClassBuffer",
"class: %s, attempting to access a wrong version: %d, object skipped at offset %d",
3414 cl->GetName(), version, Length());
3415 CheckByteCount(R__s, R__c, cl);
3418 sinfo = (TStreamerInfo*) infos->UncheckedAt(version);
3420 if (!sinfo->IsCompiled())
3424 R__LOCKGUARD(gInterpreterMutex);
3425 const_cast<TClass*
>(cl)->BuildRealData(pointer);
3430 if (sinfo->IsCompiled()) const_cast<TClass*>(cl)->SetLastReadInfo(sinfo);
3435 if (sinfo ==
nullptr) {
3442 if (v2file || version == cl->GetClassVersion() || version == 1 ) {
3443 R__LOCKGUARD(gInterpreterMutex);
3447 auto infos = cl->GetStreamerInfos();
3448 auto ninfos = infos->GetSize();
3449 if (!(version < -1 || version >= ninfos)) {
3450 sinfo = (TStreamerInfo *) infos->At(version);
3453 const_cast<TClass *
>(cl)->BuildRealData(pointer);
3454 sinfo =
new TStreamerInfo(const_cast<TClass *>(cl));
3455 sinfo->SetClassVersion(version);
3456 const_cast<TClass *
>(cl)->RegisterStreamerInfo(sinfo);
3458 Info(
"ReadClassBuffer",
"Creating StreamerInfo for class: %s, version: %d",
3459 cl->GetName(), version);
3462 sinfo->Clear(
"build");
3463 sinfo->BuildEmulated(file);
3468 }
else if (version==0) {
3472 CheckByteCount(R__s, R__c, cl);
3475 Error(
"ReadClassBuffer",
"Could not find the StreamerInfo for version %d of the class %s, object skipped at offset %d",
3476 version, cl->GetName(), Length() );
3477 CheckByteCount(R__s, R__c, cl);
3485 ApplySequence(*(sinfo->GetReadObjectWiseActions()), (
char*)pointer );
3486 if (sinfo->TStreamerInfo::IsRecovered()) R__c=0;
3489 CheckByteCount(R__s, R__c, cl);
3491 if (gDebug > 2) Info("ReadClassBuffer", "For class: %s has read %d bytes", cl->GetName(), R__c);
3503 Int_t TBufferFile::WriteClassBuffer(const TClass *cl,
void *pointer)
3506 TStreamerInfo *sinfo = (TStreamerInfo*)const_cast<TClass*>(cl)->GetCurrentStreamerInfo();
3507 if (sinfo ==
nullptr) {
3509 R__LOCKGUARD(gInterpreterMutex);
3510 sinfo = (TStreamerInfo*)const_cast<TClass*>(cl)->GetCurrentStreamerInfo();
3511 if (sinfo ==
nullptr) {
3512 const_cast<TClass*
>(cl)->BuildRealData(pointer);
3513 sinfo =
new TStreamerInfo(const_cast<TClass*>(cl));
3514 const_cast<TClass*
>(cl)->SetCurrentStreamerInfo(sinfo);
3515 const_cast<TClass*
>(cl)->RegisterStreamerInfo(sinfo);
3516 if (gDebug > 0) Info(
"WritedClassBuffer",
"Creating StreamerInfo for class: %s, version: %d",cl->GetName(),cl->GetClassVersion());
3519 }
else if (!sinfo->IsCompiled()) {
3520 R__LOCKGUARD(gInterpreterMutex);
3522 if (!sinfo->IsCompiled()) {
3523 const_cast<TClass*
>(cl)->BuildRealData(pointer);
3529 UInt_t R__c = WriteVersion(cl, kTRUE);
3532 TagStreamerInfo(sinfo);
3533 ApplySequence(*(sinfo->GetWriteObjectWiseActions()), (
char*)pointer);
3536 SetByteCount(R__c, kTRUE);
3538 if (gDebug > 2) Info("WritedClassBuffer", "For class: %s version %d has written %d bytes",cl->GetName(),cl->GetClassVersion(),UInt_t(fBufCur - fBuffer) - R__c - (UInt_t)sizeof(UInt_t));
3546 Int_t TBufferFile::ApplySequence(const TStreamerInfoActions::TActionSequence &sequence,
void *obj)
3550 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
3551 for(TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin();
3554 (*iter).PrintDebug(*
this,obj);
3560 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
3561 for(TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin();
3575 Int_t TBufferFile::ApplySequenceVecPtr(
const TStreamerInfoActions::TActionSequence &sequence,
void *start_collection,
void *end_collection)
3579 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
3580 for(TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin();
3583 if (!start_collection || start_collection == end_collection)
3584 (*iter).PrintDebug(*
this,
nullptr);
3586 (*iter).PrintDebug(*
this, *(
char**)start_collection);
3587 (*iter)(*
this, start_collection, end_collection);
3592 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
3593 for(TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin();
3596 (*iter)(*
this,start_collection,end_collection);
3606 Int_t TBufferFile::ApplySequence(
const TStreamerInfoActions::TActionSequence &sequence,
void *start_collection,
void *end_collection)
3608 TStreamerInfoActions::TLoopConfiguration *loopconfig = sequence.fLoopConfig;
3614 void *arr0 = start_collection ? loopconfig->GetFirstAddress(start_collection,end_collection) : 0;
3616 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
3617 for(TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin();
3620 (*iter).PrintDebug(*
this,arr0);
3621 (*iter)(*
this,start_collection,end_collection,loopconfig);
3626 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
3627 for(TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin();
3630 (*iter)(*
this,start_collection,end_collection,loopconfig);