Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TBufferText.cxx
Go to the documentation of this file.
1// $Id$
2// Author: Sergey Linev 21.12.2017
3
4/*************************************************************************
5 * Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/**
13\class TBufferText
14\ingroup IO
15
16Base class for text-based streamers like TBufferJSON or TBufferXML
17Special actions list will use methods, introduced in this class.
18
19Idea to have equivalent methods names in TBufferFile and TBufferText, that
20actions list for both are the same.
21*/
22
23#include "TBufferText.h"
24
25#include "TStreamerInfo.h"
26#include "TStreamerElement.h"
28#include "TFile.h"
29#include "TVirtualMutex.h"
30#include "TInterpreter.h"
31#include "TExMap.h"
32#include "TError.h"
33#include "snprintf.h"
34
35#include <cmath>
36
37
38const char *TBufferText::fgFloatFmt = "%e";
39const char *TBufferText::fgDoubleFmt = "%.14e";
40
41////////////////////////////////////////////////////////////////////////////////
42/// Default constructor
43
47
48////////////////////////////////////////////////////////////////////////////////
49/// Normal constructor
50
58
59////////////////////////////////////////////////////////////////////////////////
60/// destructor
61
65
66////////////////////////////////////////////////////////////////////////////////
67/// Read one collection of objects from the buffer using the StreamerInfoLoopAction.
68/// The collection needs to be a split TClonesArray or a split vector of pointers.
69
71{
72 TVirtualStreamerInfo *info = sequence.fStreamerInfo;
74
75 if (gDebug) {
76 // loop on all active members
77 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
78 for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin(); iter != end;
79 ++iter) {
80 // Idea: Try to remove this function call as it is really needed only for JSON streaming.
81 SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem, (*iter).fConfiguration->fCompInfo->fType);
82 (*iter).PrintDebug(*this, obj);
83 (*iter)(*this, obj);
84 }
85 } else {
86 // loop on all active members
87 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
88 for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin(); iter != end;
89 ++iter) {
90 // Idea: Try to remove this function call as it is really needed only for JSON streaming.
91 SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem, (*iter).fConfiguration->fCompInfo->fType);
92 (*iter)(*this, obj);
93 }
94 }
96 return 0;
97}
98
99////////////////////////////////////////////////////////////////////////////////
100/// Read one collection of objects from the buffer using the StreamerInfoLoopAction.
101/// The collection needs to be a split TClonesArray or a split vector of pointers.
102
104 void *end_collection)
105{
106 TVirtualStreamerInfo *info = sequence.fStreamerInfo;
108
109 if (gDebug) {
110 // loop on all active members
111 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
112 for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin(); iter != end;
113 ++iter) {
114 // Idea: Try to remove this function call as it is really needed only for JSON streaming.
115 SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem, (*iter).fConfiguration->fCompInfo->fType);
116 (*iter).PrintDebug(
117 *this, *(char **)start_collection); // Warning: This limits us to TClonesArray and vector of pointers.
118 (*iter)(*this, start_collection, end_collection);
119 }
120 } else {
121 // loop on all active members
122 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
123 for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin(); iter != end;
124 ++iter) {
125 // Idea: Try to remove this function call as it is really needed only for JSON streaming.
126 SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem, (*iter).fConfiguration->fCompInfo->fType);
127 (*iter)(*this, start_collection, end_collection);
128 }
129 }
131 return 0;
132}
133
134////////////////////////////////////////////////////////////////////////////////
135/// Read one collection of objects from the buffer using the StreamerInfoLoopAction.
136
138 void *end_collection)
139{
140 TVirtualStreamerInfo *info = sequence.fStreamerInfo;
142
144 if (gDebug) {
145
146 // Get the address of the first item for the PrintDebug.
147 // (Performance is not essential here since we are going to print to
148 // the screen anyway).
149 void *arr0 = loopconfig->GetFirstAddress(start_collection, end_collection);
150 // loop on all active members
151 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
152 for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin(); iter != end;
153 ++iter) {
154 // Idea: Try to remove this function call as it is really needed only for JSON streaming.
155 SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem, (*iter).fConfiguration->fCompInfo->fType);
156 (*iter).PrintDebug(*this, arr0);
158 }
159 } else {
160 // loop on all active members
161 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
162 for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin(); iter != end;
163 ++iter) {
164 // Idea: Try to remove this function call as it is really needed only for JSON streaming.
165 SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem, (*iter).fConfiguration->fCompInfo->fType);
167 }
168 }
170 return 0;
171}
172
173////////////////////////////////////////////////////////////////////////////////
174/// Function called by the Streamer functions to serialize object at p
175/// to buffer b. The optional argument info may be specified to give an
176/// alternative StreamerInfo instead of using the default StreamerInfo
177/// automatically built from the class definition.
178/// For more information, see class TStreamerInfo.
179
181{
182 // build the StreamerInfo if first time for the class
184 if (!sinfo) {
185 // Have to be sure between the check and the taking of the lock if the current streamer has changed
187 sinfo = (TStreamerInfo *)const_cast<TClass *>(cl)->GetCurrentStreamerInfo();
188 if (!sinfo) {
189 const_cast<TClass *>(cl)->BuildRealData(pointer);
190 sinfo = new TStreamerInfo(const_cast<TClass *>(cl));
191 const_cast<TClass *>(cl)->SetCurrentStreamerInfo(sinfo);
192 const_cast<TClass *>(cl)->RegisterStreamerInfo(sinfo);
193 if (gDebug > 0)
194 Info("WriteClassBuffer", "Creating StreamerInfo for class: %s, version: %d", cl->GetName(),
195 cl->GetClassVersion());
196 sinfo->Build();
197 }
198 } else if (!sinfo->IsCompiled()) {
200 // Redo the test in case we have been victim of a data race on fIsCompiled.
201 if (!sinfo->IsCompiled()) {
202 const_cast<TClass *>(cl)->BuildRealData(pointer);
203 sinfo->BuildOld();
204 }
205 }
206
207 // write the class version number and reserve space for the byte count
209
210 // NOTE: In the future Philippe wants this to happen via a custom action
212 ApplySequence(*(sinfo->GetWriteTextActions()), (char *)pointer);
213
214 // write the byte count at the start of the buffer
216
217 if (gDebug > 2)
218 Info("WriteClassBuffer", "class: %s version %d has written %d bytes", cl->GetName(), cl->GetClassVersion(),
219 UInt_t(fBufCur - fBuffer) - R__c - (UInt_t)sizeof(UInt_t));
220 return 0;
221}
222
223////////////////////////////////////////////////////////////////////////////////
224/// Deserialize information from a buffer into an object.
225///
226/// Note: This function is called by the xxx::Streamer() functions in
227/// rootcint-generated dictionaries.
228/// This function assumes that the class version and the byte count
229/// information have been read.
230///
231/// \param[in] cl pointer to the local TClass
232/// \param[out] pointer void pointer to object
233/// \param[in] version The version number of the class
234/// \param[in] start The starting position in the buffer b
235/// \param[in] count The number of bytes for this object in the buffer
236/// \param[in] onFileClass pointer to TClass object on file
237///
238
239Int_t TBufferText::ReadClassBuffer(const TClass *cl, void *pointer, Int_t version, UInt_t start, UInt_t count,
240 const TClass *onFileClass)
241{
242
243 //---------------------------------------------------------------------------
244 // The ondisk class has been specified so get foreign streamer info
245 /////////////////////////////////////////////////////////////////////////////
246
247 TStreamerInfo *sinfo = nullptr;
248 if (onFileClass) {
250 if (!sinfo) {
251 Error("ReadClassBuffer",
252 "Could not find the right streamer info to convert %s version %d into a %s, object skipped at offset %d",
253 onFileClass->GetName(), version, cl->GetName(), Length());
254 CheckByteCount(start, count, onFileClass);
255 return 0;
256 }
257 }
258 //---------------------------------------------------------------------------
259 // Get local streamer info
260 /////////////////////////////////////////////////////////////////////////////
261 /// The StreamerInfo should exist at this point.
262
263 else {
265 auto infos = cl->GetStreamerInfos();
266 auto ninfos = infos->GetSize();
268 Error("ReadBuffer1", "class: %s, attempting to access a wrong version: %d, object skipped at offset %d",
269 cl->GetName(), version, Length());
270 CheckByteCount(start, count, cl);
271 return 0;
272 }
274 if (!sinfo) {
275 // Unless the data is coming via a socket connection from with schema evolution
276 // (tracking) was not enabled. So let's create the StreamerInfo if it is the
277 // one for the current version, otherwise let's complain ...
278 // We could also get here if there old class version was '1' and the new class version is higher than 1
279 // AND the checksum is the same.
280 if (version == cl->GetClassVersion() || version == 1) {
281 const_cast<TClass *>(cl)->BuildRealData(pointer);
282 // This creation is alright since we just checked within the
283 // current 'locked' section.
284 sinfo = new TStreamerInfo(const_cast<TClass *>(cl));
285 const_cast<TClass *>(cl)->RegisterStreamerInfo(sinfo);
286 if (gDebug > 0)
287 Info("ReadClassBuffer", "Creating StreamerInfo for class: %s, version: %d", cl->GetName(), version);
288 sinfo->Build();
289 } else if (version == 0) {
290 // When the object was written the class was version zero, so
291 // there is no StreamerInfo to be found.
292 // Check that the buffer position corresponds to the byte count.
293 CheckByteCount(start, count, cl);
294 return 0;
295 } else {
296 Error("ReadClassBuffer",
297 "Could not find the StreamerInfo for version %d of the class %s, object skipped at offset %d",
298 version, cl->GetName(), Length());
299 CheckByteCount(start, count, cl);
300 return 0;
301 }
302 } else if (!sinfo->IsCompiled()) { // Note this read is protected by the above lock.
303 // Streamer info has not been compiled, but exists.
304 // Therefore it was read in from a file and we have to do schema evolution.
305 const_cast<TClass *>(cl)->BuildRealData(pointer);
306 sinfo->BuildOld();
307 }
308 }
309
310 // Deserialize the object.
311 ApplySequence(*(sinfo->GetReadTextActions()), (char *)pointer);
312 if (sinfo->IsRecovered())
313 count = 0;
314
315 // Check that the buffer position corresponds to the byte count.
316 CheckByteCount(start, count, cl);
317 return 0;
318}
319
320////////////////////////////////////////////////////////////////////////////////
321/// Deserialize information from a buffer into an object.
322///
323/// Note: This function is called by the xxx::Streamer()
324/// functions in rootcint-generated dictionaries.
325///
326
328{
329 // Read the class version from the buffer.
330 UInt_t R__s = 0; // Start of object.
331 UInt_t R__c = 0; // Count of bytes.
333
334 if (onFileClass)
336 else
337 version = ReadVersion(&R__s, &R__c, cl);
338
340 TFile *file = (TFile *)GetParent();
341 if (file && file->GetVersion() < 30000) {
342 version = -1; // This is old file
343 v2file = kTRUE;
344 }
345
346 //---------------------------------------------------------------------------
347 // The ondisk class has been specified so get foreign streamer info
348 /////////////////////////////////////////////////////////////////////////////
349
350 TStreamerInfo *sinfo = nullptr;
351 if (onFileClass) {
353 if (!sinfo) {
354 Error("ReadClassBuffer",
355 "Could not find the right streamer info to convert %s version %d into a %s, object skipped at offset %d",
356 onFileClass->GetName(), version, cl->GetName(), Length());
358 return 0;
359 }
360 }
361 //---------------------------------------------------------------------------
362 // Get local streamer info
363 /////////////////////////////////////////////////////////////////////////////
364 /// The StreamerInfo should exist at this point.
365
366 else {
368 if (guess && guess->GetClassVersion() == version) {
369 sinfo = guess;
370 } else {
371 // The last one is not the one we are looking for.
372 {
374
375 const TObjArray *infos = cl->GetStreamerInfos();
376 Int_t infocapacity = infos->Capacity();
377 if (infocapacity) {
379 Error("ReadClassBuffer",
380 "class: %s, attempting to access a wrong version: %d, object skipped at offset %d",
381 cl->GetName(), version, Length());
383 return 0;
384 }
385 sinfo = (TStreamerInfo *)infos->UncheckedAt(version);
386 if (sinfo) {
387 if (!sinfo->IsCompiled()) {
388 // Streamer info has not been compiled, but exists.
389 // Therefore it was read in from a file and we have to do schema evolution?
391 const_cast<TClass *>(cl)->BuildRealData(pointer);
392 sinfo->BuildOld();
393 }
394 // If the compilation succeeded, remember this StreamerInfo.
395 // const_cast okay because of the lock on gInterpreterMutex.
396 if (sinfo->IsCompiled())
397 const_cast<TClass *>(cl)->SetLastReadInfo(sinfo);
398 }
399 }
400 }
401
402 if (!sinfo) {
403 // Unless the data is coming via a socket connection from with schema evolution
404 // (tracking) was not enabled. So let's create the StreamerInfo if it is the
405 // one for the current version, otherwise let's complain ...
406 // We could also get here when reading a file prior to the introduction of StreamerInfo.
407 // We could also get here if there old class version was '1' and the new class version is higher than 1
408 // AND the checksum is the same.
409 if (v2file || version == cl->GetClassVersion() || version == 1) {
411
412 // We need to check if another thread did not get here first
413 // and did the StreamerInfo creation already.
414 auto infos = cl->GetStreamerInfos();
415 auto ninfos = infos->GetSize();
418 }
419 if (!sinfo) {
420 const_cast<TClass *>(cl)->BuildRealData(pointer);
421 sinfo = new TStreamerInfo(const_cast<TClass *>(cl));
422 sinfo->SetClassVersion(version);
423 const_cast<TClass *>(cl)->RegisterStreamerInfo(sinfo);
424 if (gDebug > 0)
425 Info("ReadClassBuffer", "Creating StreamerInfo for class: %s, version: %d", cl->GetName(),
426 version);
427 if (v2file) {
428 sinfo->Build(); // Get the elements.
429 sinfo->Clear("build"); // Undo compilation.
430 sinfo->BuildEmulated(file); // Fix the types and redo compilation.
431 } else {
432 sinfo->Build();
433 }
434 }
435 } else if (version == 0) {
436 // When the object was written the class was version zero, so
437 // there is no StreamerInfo to be found.
438 // Check that the buffer position corresponds to the byte count.
440 return 0;
441 } else {
442 Error("ReadClassBuffer",
443 "Could not find the StreamerInfo for version %d of the class %s, object skipped at offset %d",
444 version, cl->GetName(), Length());
446 return 0;
447 }
448 }
449 }
450 }
451
452 // deserialize the object
453 ApplySequence(*(sinfo->GetReadTextActions()), (char *)pointer);
454 if (sinfo->TStreamerInfo::IsRecovered())
455 R__c = 0; // 'TStreamerInfo::' avoids going via a virtual function.
456
457 // Check that the buffer position corresponds to the byte count.
459
460 if (gDebug > 2)
461 Info("ReadClassBuffer", "for class: %s has read %d bytes", cl->GetName(), R__c);
462
463 return 0;
464}
465
466////////////////////////////////////////////////////////////////////////////////
467/// stream object to/from buffer
468
469void TBufferText::StreamObject(void *obj, const std::type_info &typeinfo, const TClass * /* onFileClass */)
470{
472}
473
474////////////////////////////////////////////////////////////////////////////////
475/// stream object to/from buffer
476
477void TBufferText::StreamObject(void *obj, const char *className, const TClass * /* onFileClass */)
478{
479 StreamObject(obj, TClass::GetClass(className));
480}
481
483{
484 // stream object to/from buffer
485
486 StreamObject(obj, obj ? obj->IsA() : TObject::Class());
487}
488
489////////////////////////////////////////////////////////////////////////////////
490/// read a Float16_t from the buffer
491
496
497////////////////////////////////////////////////////////////////////////////////
498/// read a Double32_t from the buffer
499
504
505////////////////////////////////////////////////////////////////////////////////
506/// Read a Double32_t from the buffer when the factor and minimun value have
507/// been specified
508/// see comments about Double32_t encoding at TBufferFile::WriteDouble32().
509/// Currently TBufferText does not optimize space in this case.
510
511void TBufferText::ReadWithFactor(Float_t *f, Double_t /* factor */, Double_t /* minvalue */)
512{
513 ReadFloat(*f);
514}
515
516////////////////////////////////////////////////////////////////////////////////
517/// Read a Float16_t from the buffer when the number of bits is specified
518/// (explicitly or not)
519/// see comments about Float16_t encoding at TBufferFile::WriteFloat16().
520/// Currently TBufferText does not optimize space in this case.
521
523{
524 ReadFloat(*f);
525}
526
527////////////////////////////////////////////////////////////////////////////////
528/// Read a Double32_t from the buffer when the factor and minimun value have
529/// been specified
530/// see comments about Double32_t encoding at TBufferFile::WriteDouble32().
531/// Currently TBufferText does not optimize space in this case.
532
533void TBufferText::ReadWithFactor(Double_t *d, Double_t /* factor */, Double_t /* minvalue */)
534{
535 ReadDouble(*d);
536}
537
538////////////////////////////////////////////////////////////////////////////////
539/// Read a Double32_t from the buffer when the number of bits is specified
540/// (explicitly or not)
541/// see comments about Double32_t encoding at TBufferFile::WriteDouble32().
542/// Currently TBufferText does not optimize space in this case.
543
545{
546 ReadDouble(*d);
547}
548
549////////////////////////////////////////////////////////////////////////////////
550/// write a Float16_t to the buffer
551
556
557////////////////////////////////////////////////////////////////////////////////
558/// write a Double32_t to the buffer
559
564
565////////////////////////////////////////////////////////////////////////////////
566/// Read array of Float16_t from buffer
567
572
573////////////////////////////////////////////////////////////////////////////////
574/// Read array of Double32_t from buffer
575
580
581////////////////////////////////////////////////////////////////////////////////
582/// Read array of Float16_t from buffer
583
588
589////////////////////////////////////////////////////////////////////////////////
590/// Read array of Double32_t from buffer
591
596
597////////////////////////////////////////////////////////////////////////////////
598/// read array of Float16_t from buffer
599
604
605////////////////////////////////////////////////////////////////////////////////
606/// read array of Float16_t from buffer
607
609{
610 ReadFastArray(f, n);
611}
612
613////////////////////////////////////////////////////////////////////////////////
614/// read array of Float16_t from buffer
615
620
621////////////////////////////////////////////////////////////////////////////////
622/// read array of Double32_t from buffer
623
628
629////////////////////////////////////////////////////////////////////////////////
630/// read array of Double32_t from buffer
631
633{
634 ReadFastArray(d, n);
635}
636
637////////////////////////////////////////////////////////////////////////////////
638/// read array of Double32_t from buffer
639
644////////////////////////////////////////////////////////////////////////////////
645/// Write array of Float16_t to buffer
646
648{
649 WriteArray(f, n);
650}
651
652////////////////////////////////////////////////////////////////////////////////
653/// Write array of Double32_t to buffer
654
659
660////////////////////////////////////////////////////////////////////////////////
661/// Write array of Float16_t to buffer
662
667
668////////////////////////////////////////////////////////////////////////////////
669/// Write array of Double32_t to buffer
670
675
676////////////////////////////////////////////////////////////////////////////////
677/// Skip class version from I/O buffer.
678
680{
681 ReadVersion(nullptr, nullptr, cl);
682}
683
684////////////////////////////////////////////////////////////////////////////////
685/// Write data of base class.
686
688{
689 elem->WriteBuffer(*this, (char *)start);
690}
691
692////////////////////////////////////////////////////////////////////////////////
693/// Read data of base class.
694
696{
697 elem->ReadBuffer(*this, (char *)start);
698}
699
700////////////////////////////////////////////////////////////////////////////////
701/// method compress float string, excluding exp and/or move float point
702/// - 1.000000e-01 -> 0.1
703/// - 3.750000e+00 -> 3.75
704/// - 3.750000e-03 -> 0.00375
705/// - 3.750000e-04 -> 3.75e-4
706/// - 1.100000e-10 -> 1.1e-10
707
709{
710 char *pnt = nullptr, *exp = nullptr, *lastdecimal = nullptr, *s = sbuf;
711 bool negative_exp = false;
712 int power = 0;
713 while (*s && --len) {
714 switch (*s) {
715 case '.': pnt = s; break;
716 case 'E':
717 case 'e': exp = s; break;
718 case '-':
719 if (exp)
720 negative_exp = true;
721 break;
722 case '+': break;
723 default: // should be digits from '0' to '9'
724 if ((*s < '0') || (*s > '9'))
725 return;
726 if (exp)
727 power = power * 10 + (*s - '0');
728 else if (pnt && *s != '0')
729 lastdecimal = s;
730 break;
731 }
732 ++s;
733 }
734 if (*s)
735 return; // if end-of-string was not found
736
737 if (!exp) {
738 // value without exponent like 123.4569000
739 if (pnt) {
740 if (lastdecimal)
741 *(lastdecimal + 1) = 0;
742 else
743 *pnt = 0;
744 }
745 } else if (power == 0) {
746 if (lastdecimal)
747 *(lastdecimal + 1) = 0;
748 else if (pnt)
749 *pnt = 0;
750 } else if (!negative_exp && pnt && exp && (exp - pnt > power)) {
751 // this is case of value 1.23000e+02
752 // we can move point and exclude exponent easily
753 for (int cnt = 0; cnt < power; ++cnt) {
754 char tmp = *pnt;
755 *pnt = *(pnt + 1);
756 *(++pnt) = tmp;
757 }
758 if (lastdecimal && (pnt < lastdecimal))
759 *(lastdecimal + 1) = 0;
760 else
761 *pnt = 0;
762 } else if (negative_exp && pnt && exp && (power < (s - exp))) {
763 // this is small negative exponent like 1.2300e-02
764 if (!lastdecimal)
766 *(lastdecimal + 1) = 0;
767 // copy most significant digit on the point place
768 *pnt = *(pnt - 1);
769
770 for (char *pos = lastdecimal + 1; pos >= pnt; --pos)
771 *(pos + power) = *pos;
772 *(pnt - 1) = '0';
773 *pnt = '.';
774 for (int cnt = 1; cnt < power; ++cnt)
775 *(pnt + cnt) = '0';
776 } else if (pnt && exp) {
777 // keep exponent, but non-significant zeros
778 if (lastdecimal)
779 pnt = lastdecimal + 1;
780 // copy exponent sign
781 *pnt++ = *exp++;
782 if (*exp == '+')
783 ++exp;
784 else if (*exp == '-')
785 *pnt++ = *exp++;
786 // exclude zeros in the begin of exponent
787 while (*exp == '0')
788 ++exp;
789 while (*exp)
790 *pnt++ = *exp++;
791 *pnt = 0;
792 }
793}
794
795////////////////////////////////////////////////////////////////////////////////
796/// set printf format for float/double members, default "%e"
797/// to change format only for doubles, use SetDoubleFormat
798
800{
801 if (!fmt)
802 fmt = "%e";
803 fgFloatFmt = fmt;
805}
806
807////////////////////////////////////////////////////////////////////////////////
808/// return current printf format for float members, default "%e"
809
811{
812 return fgFloatFmt;
813}
814
815////////////////////////////////////////////////////////////////////////////////
816/// set printf format for double members, default "%.14e"
817/// use it after SetFloatFormat, which also overwrites format for doubles
818
820{
821 if (!fmt)
822 fmt = "%.14e";
824}
825
826////////////////////////////////////////////////////////////////////////////////
827/// return current printf format for double members, default "%.14e"
828
830{
831 return fgDoubleFmt;
832}
833
834////////////////////////////////////////////////////////////////////////////////
835/// convert float to string with configured format
836
838{
839 if (not_optimize) {
841 } else if ((value == std::nearbyint(value)) && (std::abs(value) < 1e15)) {
842 snprintf(buf, len, "%1.0f", value);
843 } else {
846 }
847 return buf;
848}
849
850////////////////////////////////////////////////////////////////////////////////
851/// convert float to string with configured format
852
854{
855 if (not_optimize) {
857 } else if ((value == std::nearbyint(value)) && (std::abs(value) < 1e25)) {
858 snprintf(buf, len, "%1.0f", value);
859 } else {
862 }
863 return buf;
864}
#define d(i)
Definition RSha256.hxx:102
#define f(i)
Definition RSha256.hxx:104
short Version_t
Class version identifier (short)
Definition RtypesCore.h:79
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char mode
R__EXTERN TVirtualMutex * gInterpreterMutex
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Definition TROOT.cxx:627
#define R__LOCKGUARD(mutex)
#define snprintf
Definition civetweb.c:1579
const_iterator begin() const
const_iterator end() const
Direct subclass of TBuffer, implements common methods for TBufferFile and TBufferText classes.
Definition TBufferIO.h:30
void TagStreamerInfo(TVirtualStreamerInfo *info) override
Mark the classindex of the current file as using this TStreamerInfo.
Int_t CheckByteCount(UInt_t, UInt_t, const TClass *) final
Definition TBufferText.h:78
static const char * ConvertFloat(Float_t v, char *buf, unsigned len, Bool_t not_optimize=kFALSE)
convert float to string with configured format
void WriteFastArrayDouble32(const Double_t *d, Long64_t n, TStreamerElement *ele=nullptr) final
Write array of Double32_t to buffer.
static const char * GetFloatFormat()
return current printf format for float members, default "%e"
Int_t ReadArrayDouble32(Double_t *&d, TStreamerElement *ele=nullptr) override
Read array of Double32_t from buffer.
void ReadFastArrayFloat16(Float_t *f, Int_t n, TStreamerElement *ele=nullptr) final
read array of Float16_t from buffer
void ReadFastArrayDouble32(Double_t *d, Int_t n, TStreamerElement *ele=nullptr) final
read array of Double32_t from buffer
Int_t ReadArrayFloat16(Float_t *&f, TStreamerElement *ele=nullptr) override
Read array of Float16_t from buffer.
void ReadWithNbits(Float_t *ptr, Int_t nbits) final
Read a Float16_t from the buffer when the number of bits is specified (explicitly or not) see comment...
TBufferText()
Default constructor.
void WriteArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele=nullptr) final
Write array of Double32_t to buffer.
Int_t WriteClassBuffer(const TClass *cl, void *pointer) override
Function called by the Streamer functions to serialize object at p to buffer b.
static void CompactFloatString(char *buf, unsigned len)
method compress float string, excluding exp and/or move float point
void ReadFastArrayWithFactor(Float_t *ptr, Int_t n, Double_t factor, Double_t minvalue) final
read array of Float16_t from buffer
static const char * ConvertDouble(Double_t v, char *buf, unsigned len, Bool_t not_optimize=kFALSE)
convert float to string with configured format
void StreamObject(void *obj, const std::type_info &typeinfo, const TClass *onFileClass=nullptr) override
stream object to/from buffer
Int_t ApplySequenceVecPtr(const TStreamerInfoActions::TActionSequence &sequence, void *start_collection, void *end_collection) final
Read one collection of objects from the buffer using the StreamerInfoLoopAction.
void WriteArrayFloat16(const Float_t *f, Int_t n, TStreamerElement *ele=nullptr) final
Write array of Float16_t to buffer.
void ReadFastArrayWithNbits(Float_t *ptr, Int_t n, Int_t nbits) final
read array of Float16_t from buffer
void ReadFloat16(Float_t *f, TStreamerElement *ele=nullptr) final
read a Float16_t from the buffer
Int_t ApplySequence(const TStreamerInfoActions::TActionSequence &sequence, void *object) final
Read one collection of objects from the buffer using the StreamerInfoLoopAction.
void SkipVersion(const TClass *cl=nullptr) final
Skip class version from I/O buffer.
virtual void WriteBaseClass(void *start, TStreamerBase *elem)
Write data of base class.
~TBufferText() override
destructor
void SetByteCount(UInt_t, Bool_t=kFALSE) final
Definition TBufferText.h:80
Int_t ReadStaticArrayFloat16(Float_t *f, TStreamerElement *ele=nullptr) final
Read array of Float16_t from buffer.
Int_t ReadStaticArrayDouble32(Double_t *d, TStreamerElement *ele=nullptr) final
Read array of Double32_t from buffer.
static const char * fgDoubleFmt
! printf argument for doubles, either "%f" or "%e" or "%10f" and so on
virtual void ReadBaseClass(void *start, TStreamerBase *elem)
Read data of base class.
static void SetFloatFormat(const char *fmt="%e")
set printf format for float/double members, default "%e" to change format only for doubles,...
Int_t ReadClassBuffer(const TClass *, void *, const TClass *=nullptr) override
Deserialize information from a buffer into an object.
void WriteFloat16(Float_t *f, TStreamerElement *ele=nullptr) final
write a Float16_t to the buffer
static const char * GetDoubleFormat()
return current printf format for double members, default "%.14e"
void ReadDouble32(Double_t *d, TStreamerElement *ele=nullptr) final
read a Double32_t from the buffer
void WriteFastArrayFloat16(const Float_t *d, Long64_t n, TStreamerElement *ele=nullptr) final
Write array of Float16_t to buffer.
void ReadWithFactor(Float_t *ptr, Double_t factor, Double_t minvalue) final
Read a Double32_t from the buffer when the factor and minimun value have been specified see comments ...
void WriteDouble32(Double_t *d, TStreamerElement *ele=nullptr) final
write a Double32_t to the buffer
static const char * fgFloatFmt
! printf argument for floats, either "%f" or "%e" or "%10f" and so on
static void SetDoubleFormat(const char *fmt="%.14e")
set printf format for double members, default "%.14e" use it after SetFloatFormat,...
virtual Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=0
virtual void ReadDouble(Double_t &d)=0
Int_t fBufSize
Definition TBuffer.h:50
virtual void WriteDouble(Double_t d)=0
void SetParent(TObject *parent)
Set parent owning this buffer.
Definition TBuffer.cxx:269
TObject * GetParent() const
Return pointer to parent of this buffer.
Definition TBuffer.cxx:261
virtual void ReadFloat(Float_t &f)=0
@ kCannotHandleMemberWiseStreaming
Definition TBuffer.h:76
virtual void SetStreamerElementNumber(TStreamerElement *elem, Int_t comp_type)=0
virtual void WriteArray(const Bool_t *b, Int_t n)=0
virtual Int_t ReadArray(Bool_t *&b)=0
char * fBufCur
Definition TBuffer.h:52
virtual void ReadFastArray(Bool_t *b, Int_t n)=0
virtual void IncrementLevel(TVirtualStreamerInfo *info)=0
virtual void DecrementLevel(TVirtualStreamerInfo *)=0
char * fBuffer
Definition TBuffer.h:51
virtual Int_t ReadStaticArray(Bool_t *b)=0
virtual void WriteFastArray(const Bool_t *b, Long64_t n)=0
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=0
virtual void WriteFloat(Float_t f)=0
Int_t Length() const
Definition TBuffer.h:100
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
TVirtualStreamerInfo * GetCurrentStreamerInfo()
Definition TClass.h:451
void SetLastReadInfo(TVirtualStreamerInfo *info)
Definition TClass.h:457
TVirtualStreamerInfo * GetLastReadInfo() const
Definition TClass.h:456
const TObjArray * GetStreamerInfos() const
Definition TClass.h:505
TVirtualStreamerInfo * GetConversionStreamerInfo(const char *onfile_classname, Int_t version) const
Return a Conversion StreamerInfo from the class 'classname' for version number 'version' to this clas...
Definition TClass.cxx:7149
Version_t GetClassVersion() const
Definition TClass.h:432
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:2973
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:131
Int_t GetVersion() const
Definition TFile.h:324
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
An array of TObjects.
Definition TObjArray.h:31
Mother of all ROOT objects.
Definition TObject.h:41
static TClass * Class()
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:864
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
virtual TClass * IsA() const
Definition TObject.h:246
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1045
Describe one element (data member) to be Streamed.
Base class of the Configurations for the member wise looping routines.
Describes a persistent version of a class.
Abstract Interface class describing Streamer information for one class.
const Int_t n
Definition legend1.C:16