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
38
39const char *TBufferText::fgFloatFmt = "%e";
40const char *TBufferText::fgDoubleFmt = "%.14e";
41
42////////////////////////////////////////////////////////////////////////////////
43/// Default constructor
44
48
49////////////////////////////////////////////////////////////////////////////////
50/// Normal constructor
51
59
60////////////////////////////////////////////////////////////////////////////////
61/// destructor
62
66
67////////////////////////////////////////////////////////////////////////////////
68/// Read one collection of objects from the buffer using the StreamerInfoLoopAction.
69/// The collection needs to be a split TClonesArray or a split vector of pointers.
70
72{
73 TVirtualStreamerInfo *info = sequence.fStreamerInfo;
75
76 if (gDebug) {
77 // loop on all active members
78 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
79 for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin(); iter != end;
80 ++iter) {
81 // Idea: Try to remove this function call as it is really needed only for JSON streaming.
82 SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem, (*iter).fConfiguration->fCompInfo->fType);
83 (*iter).PrintDebug(*this, obj);
84 (*iter)(*this, obj);
85 }
86 } else {
87 // loop on all active members
88 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
89 for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin(); iter != end;
90 ++iter) {
91 // Idea: Try to remove this function call as it is really needed only for JSON streaming.
92 SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem, (*iter).fConfiguration->fCompInfo->fType);
93 (*iter)(*this, obj);
94 }
95 }
97 return 0;
98}
99
100////////////////////////////////////////////////////////////////////////////////
101/// Read one collection of objects from the buffer using the StreamerInfoLoopAction.
102/// The collection needs to be a split TClonesArray or a split vector of pointers.
103
105 void *end_collection)
106{
107 TVirtualStreamerInfo *info = sequence.fStreamerInfo;
109
110 if (gDebug) {
111 // loop on all active members
112 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
113 for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin(); iter != end;
114 ++iter) {
115 // Idea: Try to remove this function call as it is really needed only for JSON streaming.
116 SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem, (*iter).fConfiguration->fCompInfo->fType);
117 (*iter).PrintDebug(
118 *this, *(char **)start_collection); // Warning: This limits us to TClonesArray and vector of pointers.
119 (*iter)(*this, start_collection, end_collection);
120 }
121 } else {
122 // loop on all active members
123 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
124 for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin(); iter != end;
125 ++iter) {
126 // Idea: Try to remove this function call as it is really needed only for JSON streaming.
127 SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem, (*iter).fConfiguration->fCompInfo->fType);
128 (*iter)(*this, start_collection, end_collection);
129 }
130 }
132 return 0;
133}
134
135////////////////////////////////////////////////////////////////////////////////
136/// Read one collection of objects from the buffer using the StreamerInfoLoopAction.
137
139 void *end_collection)
140{
141 TVirtualStreamerInfo *info = sequence.fStreamerInfo;
143
145 if (gDebug) {
146
147 // Get the address of the first item for the PrintDebug.
148 // (Performance is not essential here since we are going to print to
149 // the screen anyway).
150 void *arr0 = loopconfig->GetFirstAddress(start_collection, end_collection);
151 // loop on all active members
152 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
153 for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin(); iter != end;
154 ++iter) {
155 // Idea: Try to remove this function call as it is really needed only for JSON streaming.
156 SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem, (*iter).fConfiguration->fCompInfo->fType);
157 (*iter).PrintDebug(*this, arr0);
159 }
160 } else {
161 // loop on all active members
162 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
163 for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin(); iter != end;
164 ++iter) {
165 // Idea: Try to remove this function call as it is really needed only for JSON streaming.
166 SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem, (*iter).fConfiguration->fCompInfo->fType);
168 }
169 }
171 return 0;
172}
173
174////////////////////////////////////////////////////////////////////////////////
175/// Function called by the Streamer functions to serialize object at p
176/// to buffer b. The optional argument info may be specified to give an
177/// alternative StreamerInfo instead of using the default StreamerInfo
178/// automatically built from the class definition.
179/// For more information, see class TStreamerInfo.
180
182{
183 // build the StreamerInfo if first time for the class
185 if (!sinfo) {
186 // Have to be sure between the check and the taking of the lock if the current streamer has changed
188 sinfo = (TStreamerInfo *)const_cast<TClass *>(cl)->GetCurrentStreamerInfo();
189 if (!sinfo) {
190 const_cast<TClass *>(cl)->BuildRealData(pointer);
191 sinfo = new TStreamerInfo(const_cast<TClass *>(cl));
192 const_cast<TClass *>(cl)->SetCurrentStreamerInfo(sinfo);
193 const_cast<TClass *>(cl)->RegisterStreamerInfo(sinfo);
194 if (gDebug > 0)
195 Info("WriteClassBuffer", "Creating StreamerInfo for class: %s, version: %d", cl->GetName(),
196 cl->GetClassVersion());
197 sinfo->Build();
198 }
199 } else if (!sinfo->IsCompiled()) {
201 // Redo the test in case we have been victim of a data race on fIsCompiled.
202 if (!sinfo->IsCompiled()) {
203 const_cast<TClass *>(cl)->BuildRealData(pointer);
204 sinfo->BuildOld();
205 }
206 }
207
208 // write the class version number and reserve space for the byte count
210
211 // NOTE: In the future Philippe wants this to happen via a custom action
213 ApplySequence(*(sinfo->GetWriteTextActions()), (char *)pointer);
214
215 // write the byte count at the start of the buffer
217
218 if (gDebug > 2)
219 Info("WriteClassBuffer", "class: %s version %d has written %d bytes", cl->GetName(), cl->GetClassVersion(),
220 UInt_t(fBufCur - fBuffer) - R__c - (UInt_t)sizeof(UInt_t));
221 return 0;
222}
223
224////////////////////////////////////////////////////////////////////////////////
225/// Deserialize information from a buffer into an object.
226///
227/// Note: This function is called by the xxx::Streamer() functions in
228/// rootcint-generated dictionaries.
229/// This function assumes that the class version and the byte count
230/// information have been read.
231///
232/// \param[in] cl pointer to the local TClass
233/// \param[out] pointer void pointer to object
234/// \param[in] version The version number of the class
235/// \param[in] start The starting position in the buffer b
236/// \param[in] count The number of bytes for this object in the buffer
237/// \param[in] onFileClass pointer to TClass object on file
238///
239
240Int_t TBufferText::ReadClassBuffer(const TClass *cl, void *pointer, Int_t version, UInt_t start, UInt_t count,
241 const TClass *onFileClass)
242{
243
244 //---------------------------------------------------------------------------
245 // The ondisk class has been specified so get foreign streamer info
246 /////////////////////////////////////////////////////////////////////////////
247
248 TStreamerInfo *sinfo = nullptr;
249 if (onFileClass) {
251 if (!sinfo) {
252 Error("ReadClassBuffer",
253 "Could not find the right streamer info to convert %s version %d into a %s, object skipped at offset %d",
254 onFileClass->GetName(), version, cl->GetName(), Length());
255 CheckByteCount(start, count, onFileClass);
256 return 0;
257 }
258 }
259 //---------------------------------------------------------------------------
260 // Get local streamer info
261 /////////////////////////////////////////////////////////////////////////////
262 /// The StreamerInfo should exist at this point.
263
264 else {
266 auto infos = cl->GetStreamerInfos();
267 auto ninfos = infos->GetSize();
269 Error("ReadBuffer1", "class: %s, attempting to access a wrong version: %d, object skipped at offset %d",
270 cl->GetName(), version, Length());
271 CheckByteCount(start, count, cl);
272 return 0;
273 }
275 if (!sinfo) {
276 // Unless the data is coming via a socket connection from with schema evolution
277 // (tracking) was not enabled. So let's create the StreamerInfo if it is the
278 // one for the current version, otherwise let's complain ...
279 // We could also get here if there old class version was '1' and the new class version is higher than 1
280 // AND the checksum is the same.
281 if (version == cl->GetClassVersion() || version == 1) {
282 const_cast<TClass *>(cl)->BuildRealData(pointer);
283 // This creation is alright since we just checked within the
284 // current 'locked' section.
285 sinfo = new TStreamerInfo(const_cast<TClass *>(cl));
286 const_cast<TClass *>(cl)->RegisterStreamerInfo(sinfo);
287 if (gDebug > 0)
288 Info("ReadClassBuffer", "Creating StreamerInfo for class: %s, version: %d", cl->GetName(), version);
289 sinfo->Build();
290 } else if (version == 0) {
291 // When the object was written the class was version zero, so
292 // there is no StreamerInfo to be found.
293 // Check that the buffer position corresponds to the byte count.
294 CheckByteCount(start, count, cl);
295 return 0;
296 } else {
297 Error("ReadClassBuffer",
298 "Could not find the StreamerInfo for version %d of the class %s, object skipped at offset %d",
299 version, cl->GetName(), Length());
300 CheckByteCount(start, count, cl);
301 return 0;
302 }
303 } else if (!sinfo->IsCompiled()) { // Note this read is protected by the above lock.
304 // Streamer info has not been compiled, but exists.
305 // Therefore it was read in from a file and we have to do schema evolution.
306 const_cast<TClass *>(cl)->BuildRealData(pointer);
307 sinfo->BuildOld();
308 }
309 }
310
311 // Deserialize the object.
312 ApplySequence(*(sinfo->GetReadTextActions()), (char *)pointer);
313 if (sinfo->IsRecovered())
314 count = 0;
315
316 // Check that the buffer position corresponds to the byte count.
317 CheckByteCount(start, count, cl);
318 return 0;
319}
320
321////////////////////////////////////////////////////////////////////////////////
322/// Deserialize information from a buffer into an object.
323///
324/// Note: This function is called by the xxx::Streamer()
325/// functions in rootcint-generated dictionaries.
326///
327
329{
330 // Read the class version from the buffer.
331 UInt_t R__s = 0; // Start of object.
332 UInt_t R__c = 0; // Count of bytes.
334
335 if (onFileClass)
337 else
338 version = ReadVersion(&R__s, &R__c, cl);
339
341 TFile *file = (TFile *)GetParent();
342 if (file && file->GetVersion() < 30000) {
343 version = -1; // This is old file
344 v2file = kTRUE;
345 }
346
347 //---------------------------------------------------------------------------
348 // The ondisk class has been specified so get foreign streamer info
349 /////////////////////////////////////////////////////////////////////////////
350
351 TStreamerInfo *sinfo = nullptr;
352 if (onFileClass) {
354 if (!sinfo) {
355 Error("ReadClassBuffer",
356 "Could not find the right streamer info to convert %s version %d into a %s, object skipped at offset %d",
357 onFileClass->GetName(), version, cl->GetName(), Length());
359 return 0;
360 }
361 }
362 //---------------------------------------------------------------------------
363 // Get local streamer info
364 /////////////////////////////////////////////////////////////////////////////
365 /// The StreamerInfo should exist at this point.
366
367 else {
369 if (guess && guess->GetClassVersion() == version) {
370 sinfo = guess;
371 } else {
372 // The last one is not the one we are looking for.
373 {
375
376 const TObjArray *infos = cl->GetStreamerInfos();
377 Int_t infocapacity = infos->Capacity();
378 if (infocapacity) {
380 Error("ReadClassBuffer",
381 "class: %s, attempting to access a wrong version: %d, object skipped at offset %d",
382 cl->GetName(), version, Length());
384 return 0;
385 }
386 sinfo = (TStreamerInfo *)infos->UncheckedAt(version);
387 if (sinfo) {
388 if (!sinfo->IsCompiled()) {
389 // Streamer info has not been compiled, but exists.
390 // Therefore it was read in from a file and we have to do schema evolution?
392 const_cast<TClass *>(cl)->BuildRealData(pointer);
393 sinfo->BuildOld();
394 }
395 // If the compilation succeeded, remember this StreamerInfo.
396 // const_cast okay because of the lock on gInterpreterMutex.
397 if (sinfo->IsCompiled())
398 const_cast<TClass *>(cl)->SetLastReadInfo(sinfo);
399 }
400 }
401 }
402
403 if (!sinfo) {
404 // Unless the data is coming via a socket connection from with schema evolution
405 // (tracking) was not enabled. So let's create the StreamerInfo if it is the
406 // one for the current version, otherwise let's complain ...
407 // We could also get here when reading a file prior to the introduction of StreamerInfo.
408 // We could also get here if there old class version was '1' and the new class version is higher than 1
409 // AND the checksum is the same.
410 if (v2file || version == cl->GetClassVersion() || version == 1) {
412
413 // We need to check if another thread did not get here first
414 // and did the StreamerInfo creation already.
415 auto infos = cl->GetStreamerInfos();
416 auto ninfos = infos->GetSize();
419 }
420 if (!sinfo) {
421 const_cast<TClass *>(cl)->BuildRealData(pointer);
422 sinfo = new TStreamerInfo(const_cast<TClass *>(cl));
423 sinfo->SetClassVersion(version);
424 const_cast<TClass *>(cl)->RegisterStreamerInfo(sinfo);
425 if (gDebug > 0)
426 Info("ReadClassBuffer", "Creating StreamerInfo for class: %s, version: %d", cl->GetName(),
427 version);
428 if (v2file) {
429 sinfo->Build(); // Get the elements.
430 sinfo->Clear("build"); // Undo compilation.
431 sinfo->BuildEmulated(file); // Fix the types and redo compilation.
432 } else {
433 sinfo->Build();
434 }
435 }
436 } else if (version == 0) {
437 // When the object was written the class was version zero, so
438 // there is no StreamerInfo to be found.
439 // Check that the buffer position corresponds to the byte count.
441 return 0;
442 } else {
443 Error("ReadClassBuffer",
444 "Could not find the StreamerInfo for version %d of the class %s, object skipped at offset %d",
445 version, cl->GetName(), Length());
447 return 0;
448 }
449 }
450 }
451 }
452
453 // deserialize the object
454 ApplySequence(*(sinfo->GetReadTextActions()), (char *)pointer);
455 if (sinfo->TStreamerInfo::IsRecovered())
456 R__c = 0; // 'TStreamerInfo::' avoids going via a virtual function.
457
458 // Check that the buffer position corresponds to the byte count.
460
461 if (gDebug > 2)
462 Info("ReadClassBuffer", "for class: %s has read %d bytes", cl->GetName(), R__c);
463
464 return 0;
465}
466
467////////////////////////////////////////////////////////////////////////////////
468/// stream object to/from buffer
469
470void TBufferText::StreamObject(void *obj, const std::type_info &typeinfo, const TClass * /* onFileClass */)
471{
473}
474
475////////////////////////////////////////////////////////////////////////////////
476/// stream object to/from buffer
477
478void TBufferText::StreamObject(void *obj, const char *className, const TClass * /* onFileClass */)
479{
480 StreamObject(obj, TClass::GetClass(className));
481}
482
484{
485 // stream object to/from buffer
486
487 StreamObject(obj, obj ? obj->IsA() : TObject::Class());
488}
489
490////////////////////////////////////////////////////////////////////////////////
491/// read a Float16_t from the buffer
492
497
498////////////////////////////////////////////////////////////////////////////////
499/// read a Double32_t from the buffer
500
505
506////////////////////////////////////////////////////////////////////////////////
507/// Read a Double32_t from the buffer when the factor and minimun value have
508/// been specified
509/// see comments about Double32_t encoding at TBufferFile::WriteDouble32().
510/// Currently TBufferText does not optimize space in this case.
511
512void TBufferText::ReadWithFactor(Float_t *f, Double_t /* factor */, Double_t /* minvalue */)
513{
514 ReadFloat(*f);
515}
516
517////////////////////////////////////////////////////////////////////////////////
518/// Read a Float16_t from the buffer when the number of bits is specified
519/// (explicitly or not)
520/// see comments about Float16_t encoding at TBufferFile::WriteFloat16().
521/// Currently TBufferText does not optimize space in this case.
522
524{
525 ReadFloat(*f);
526}
527
528////////////////////////////////////////////////////////////////////////////////
529/// Read a Double32_t from the buffer when the factor and minimun value have
530/// been specified
531/// see comments about Double32_t encoding at TBufferFile::WriteDouble32().
532/// Currently TBufferText does not optimize space in this case.
533
534void TBufferText::ReadWithFactor(Double_t *d, Double_t /* factor */, Double_t /* minvalue */)
535{
536 ReadDouble(*d);
537}
538
539////////////////////////////////////////////////////////////////////////////////
540/// Read a Double32_t from the buffer when the number of bits is specified
541/// (explicitly or not)
542/// see comments about Double32_t encoding at TBufferFile::WriteDouble32().
543/// Currently TBufferText does not optimize space in this case.
544
546{
547 ReadDouble(*d);
548}
549
550////////////////////////////////////////////////////////////////////////////////
551/// write a Float16_t to the buffer
552
557
558////////////////////////////////////////////////////////////////////////////////
559/// write a Double32_t to the buffer
560
565
566////////////////////////////////////////////////////////////////////////////////
567/// Read array of Float16_t from buffer
568
573
574////////////////////////////////////////////////////////////////////////////////
575/// Read array of Double32_t from buffer
576
581
582////////////////////////////////////////////////////////////////////////////////
583/// Read array of Float16_t from buffer
584
589
590////////////////////////////////////////////////////////////////////////////////
591/// Read array of Double32_t from buffer
592
597
598////////////////////////////////////////////////////////////////////////////////
599/// read array of Float16_t from buffer
600
605
606////////////////////////////////////////////////////////////////////////////////
607/// read array of Float16_t from buffer
608
610{
611 ReadFastArray(f, n);
612}
613
614////////////////////////////////////////////////////////////////////////////////
615/// read array of Float16_t from buffer
616
621
622////////////////////////////////////////////////////////////////////////////////
623/// read array of Double32_t from buffer
624
629
630////////////////////////////////////////////////////////////////////////////////
631/// read array of Double32_t from buffer
632
634{
635 ReadFastArray(d, n);
636}
637
638////////////////////////////////////////////////////////////////////////////////
639/// read array of Double32_t from buffer
640
645////////////////////////////////////////////////////////////////////////////////
646/// Write array of Float16_t to buffer
647
649{
650 WriteArray(f, n);
651}
652
653////////////////////////////////////////////////////////////////////////////////
654/// Write array of Double32_t to buffer
655
660
661////////////////////////////////////////////////////////////////////////////////
662/// Write array of Float16_t to buffer
663
668
669////////////////////////////////////////////////////////////////////////////////
670/// Write array of Double32_t to buffer
671
676
677////////////////////////////////////////////////////////////////////////////////
678/// Skip class version from I/O buffer.
679
681{
682 ReadVersion(nullptr, nullptr, cl);
683}
684
685////////////////////////////////////////////////////////////////////////////////
686/// Write data of base class.
687
689{
690 elem->WriteBuffer(*this, (char *)start);
691}
692
693////////////////////////////////////////////////////////////////////////////////
694/// Read data of base class.
695
697{
698 elem->ReadBuffer(*this, (char *)start);
699}
700
701////////////////////////////////////////////////////////////////////////////////
702/// method compress float string, excluding exp and/or move float point
703/// - 1.000000e-01 -> 0.1
704/// - 3.750000e+00 -> 3.75
705/// - 3.750000e-03 -> 0.00375
706/// - 3.750000e-04 -> 3.75e-4
707/// - 1.100000e-10 -> 1.1e-10
708
710{
711 char *pnt = nullptr, *exp = nullptr, *lastdecimal = nullptr, *s = sbuf;
712 bool negative_exp = false;
713 int power = 0;
714 while (*s && --len) {
715 switch (*s) {
716 case '.': pnt = s; break;
717 case 'E':
718 case 'e': exp = s; break;
719 case '-':
720 if (exp)
721 negative_exp = true;
722 break;
723 case '+': break;
724 default: // should be digits from '0' to '9'
725 if ((*s < '0') || (*s > '9'))
726 return;
727 if (exp)
728 power = power * 10 + (*s - '0');
729 else if (pnt && *s != '0')
730 lastdecimal = s;
731 break;
732 }
733 ++s;
734 }
735 if (*s)
736 return; // if end-of-string was not found
737
738 if (!exp) {
739 // value without exponent like 123.4569000
740 if (pnt) {
741 if (lastdecimal)
742 *(lastdecimal + 1) = 0;
743 else
744 *pnt = 0;
745 }
746 } else if (power == 0) {
747 if (lastdecimal)
748 *(lastdecimal + 1) = 0;
749 else if (pnt)
750 *pnt = 0;
751 } else if (!negative_exp && pnt && exp && (exp - pnt > power)) {
752 // this is case of value 1.23000e+02
753 // we can move point and exclude exponent easily
754 for (int cnt = 0; cnt < power; ++cnt) {
755 char tmp = *pnt;
756 *pnt = *(pnt + 1);
757 *(++pnt) = tmp;
758 }
759 if (lastdecimal && (pnt < lastdecimal))
760 *(lastdecimal + 1) = 0;
761 else
762 *pnt = 0;
763 } else if (negative_exp && pnt && exp && (power < (s - exp))) {
764 // this is small negative exponent like 1.2300e-02
765 if (!lastdecimal)
767 *(lastdecimal + 1) = 0;
768 // copy most significant digit on the point place
769 *pnt = *(pnt - 1);
770
771 for (char *pos = lastdecimal + 1; pos >= pnt; --pos)
772 *(pos + power) = *pos;
773 *(pnt - 1) = '0';
774 *pnt = '.';
775 for (int cnt = 1; cnt < power; ++cnt)
776 *(pnt + cnt) = '0';
777 } else if (pnt && exp) {
778 // keep exponent, but non-significant zeros
779 if (lastdecimal)
780 pnt = lastdecimal + 1;
781 // copy exponent sign
782 *pnt++ = *exp++;
783 if (*exp == '+')
784 ++exp;
785 else if (*exp == '-')
786 *pnt++ = *exp++;
787 // exclude zeros in the begin of exponent
788 while (*exp == '0')
789 ++exp;
790 while (*exp)
791 *pnt++ = *exp++;
792 *pnt = 0;
793 }
794}
795
796////////////////////////////////////////////////////////////////////////////////
797/// set printf format for float/double members, default "%e"
798/// to change format only for doubles, use SetDoubleFormat
799
801{
802 if (!fmt)
803 fmt = "%e";
804 fgFloatFmt = fmt;
806}
807
808////////////////////////////////////////////////////////////////////////////////
809/// return current printf format for float members, default "%e"
810
812{
813 return fgFloatFmt;
814}
815
816////////////////////////////////////////////////////////////////////////////////
817/// set printf format for double members, default "%.14e"
818/// use it after SetFloatFormat, which also overwrites format for doubles
819
821{
822 if (!fmt)
823 fmt = "%.14e";
825}
826
827////////////////////////////////////////////////////////////////////////////////
828/// return current printf format for double members, default "%.14e"
829
831{
832 return fgDoubleFmt;
833}
834
835////////////////////////////////////////////////////////////////////////////////
836/// convert float to string with configured format
837
839{
840 if (not_optimize) {
842 } else if ((value == std::nearbyint(value)) && (std::abs(value) < 1e15)) {
843 snprintf(buf, len, "%1.0f", value);
844 } else {
847 }
848 return buf;
849}
850
851////////////////////////////////////////////////////////////////////////////////
852/// convert float to string with configured format
853
855{
856 if (not_optimize) {
858 } else if ((value == std::nearbyint(value)) && (std::abs(value) < 1e25)) {
859 snprintf(buf, len, "%1.0f", value);
860 } else {
863 }
864 return buf;
865}
#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
#define ClassImp(name)
Definition Rtypes.h:376
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.
Base class for text-based streamers like TBufferJSON or TBufferXML Special actions list will use meth...
Definition TBufferText.h:20
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:270
TObject * GetParent() const
Return pointer to parent of this buffer.
Definition TBuffer.cxx:262
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:7150
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:2974
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:865
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1072
virtual TClass * IsA() const
Definition TObject.h:246
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1046
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