41 #include "Compression.h" 48 #include "TClassEdit.h" 69 #ifdef R__VISUAL_CPLUSPLUS 70 #define FLong64 "%I64d" 71 #define FULong64 "%I64u" 73 #define FLong64 "%lld" 74 #define FULong64 "%llu" 88 class TArrayIndexProducer {
109 if (usearrayindx && (arraylen > 0)) {
114 printf(
"Problem with JSON coding of element %s type %d \n", elem->
GetName(), elem->
GetType());
125 fTotalLen = arraylen;
127 fMaxIndex[0] = arraylen;
136 TArrayIndexProducer(
TDataMember* member,
Int_t extradim,
const char* separ) :
145 if (extradim > 0) ndim++;
158 fMaxIndex[ndim-1] = extradim;
159 fTotalLen *= extradim;
164 Int_t ReduceDimension()
168 if (fMaxIndex.
GetSize() == 0)
return 0;
170 Int_t len = fMaxIndex[ndim];
173 fTotalLen = fTotalLen/len;
180 return (fTotalLen>1);
186 return !IsArray() || (fCnt >= fTotalLen);
189 const char* GetBegin()
206 const char* NextSeparator()
210 if (++fCnt >= fTotalLen)
return GetEnd();
217 while ((cnt >= 0) && (cnt < fIndicies.
GetSize())) {
218 if (fIndicies[cnt] >= fMaxIndex[cnt]) {
220 fIndicies[cnt--] = 0;
221 if (cnt >= 0) fIndicies[
cnt]++;
224 fRes.
Append(fIndicies[cnt] == 0 ?
"[" : fSepar);
237 class TJSONStackObj :
public TObject {
249 TArrayIndexProducer *fIndx;
268 virtual ~TJSONStackObj()
270 if (fIsElemOwner)
delete fElem;
271 if (fIndx)
delete fIndx;
274 Bool_t IsStreamerInfo()
const 276 return fIsStreamerInfo;
278 Bool_t IsStreamerElement()
const 280 return !fIsStreamerInfo && (fElem != 0);
321 char* loc = setlocale(LC_NUMERIC, 0);
322 if ((loc!=0) && (strcmp(loc,
"C")!=0)) {
324 setlocale(LC_NUMERIC,
"C");
356 void *ptr = (
void *) obj;
404 Int_t compact,
const char *member_name)
406 if ((member_name!=0) && (obj!=0)) {
411 while ((rdata = dynamic_cast<TRealData*>(iter())) != 0) {
413 if (member && strcmp(member->
GetName(), member_name)==0)
break;
416 if (member==0)
return TString();
423 arraylen = *((
int *) ((
char *) obj + idata->
GetThisOffset()));
428 if (member->
IsaPointer()) ptr = *((
char **) ptr);
451 if ((ptr == 0) || (member == 0))
return TString(
"null");
459 if ((mcl != 0) && (mcl !=
TString::Class()) && !stlstring && !isstl &&
477 if (!obj || !filename || (*filename==0))
return 0;
479 Int_t compact = strstr(filename,
".json.gz") ? 3 : 0;
480 if (option && (*option >=
'0') && (*option <=
'3')) compact =
TString(option).
Atoi();
484 std::ofstream ofs(filename);
486 if (strstr(filename,
".json.gz")) {
487 const char *objbuf = json.
Data();
490 unsigned long objcrc = R__crc32(0,
NULL, 0);
491 objcrc = R__crc32(objcrc, (
const unsigned char *) objbuf, objlen);
494 Int_t buflen = 10 + objlen + 8;
495 if (buflen < 512) buflen = 512;
497 char *buffer = (
char *)
malloc(buflen);
498 if (buffer == 0)
return 0;
500 char *bufcur = buffer;
516 memcpy(dummy, bufcur - 6, 6);
519 unsigned long ziplen = R__memcompress(bufcur - 6, objlen + 6, (
char *) objbuf, objlen);
521 memcpy(bufcur - 6, dummy, 6);
523 bufcur += (ziplen - 6);
525 *bufcur++ = objcrc & 0xff;
526 *bufcur++ = (objcrc >> 8) & 0xff;
527 *bufcur++ = (objcrc >> 16) & 0xff;
528 *bufcur++ = (objcrc >> 24) & 0xff;
530 *bufcur++ = objlen & 0xff;
531 *bufcur++ = (objlen >> 8) & 0xff;
532 *bufcur++ = (objlen >> 16) & 0xff;
533 *bufcur++ = (objlen >> 24) & 0xff;
535 ofs.write(buffer, bufcur - buffer);
553 if (!obj || !cl || !filename || (*filename==0))
return 0;
555 Int_t compact = strstr(filename,
".json.gz") ? 3 : 0;
556 if (option && (*option >=
'0') && (*option <=
'3')) compact =
TString(option).
Atoi();
560 std::ofstream ofs (filename);
562 if (strstr(filename,
".json.gz")) {
563 const char *objbuf = json.
Data();
566 unsigned long objcrc = R__crc32(0,
NULL, 0);
567 objcrc = R__crc32(objcrc, (
const unsigned char *) objbuf, objlen);
570 Int_t buflen = 10 + objlen + 8;
571 if (buflen < 512) buflen = 512;
573 char *buffer = (
char *)
malloc(buflen);
574 if (buffer == 0)
return 0;
576 char *bufcur = buffer;
592 memcpy(dummy, bufcur - 6, 6);
595 unsigned long ziplen = R__memcompress(bufcur - 6, objlen + 6, (
char *) objbuf, objlen);
597 memcpy(bufcur - 6, dummy, 6);
599 bufcur += (ziplen - 6);
601 *bufcur++ = objcrc & 0xff;
602 *bufcur++ = (objcrc >> 8) & 0xff;
603 *bufcur++ = (objcrc >> 16) & 0xff;
604 *bufcur++ = (objcrc >> 24) & 0xff;
606 *bufcur++ = objlen & 0xff;
607 *bufcur++ = (objlen >> 8) & 0xff;
608 *bufcur++ = (objlen >> 16) & 0xff;
609 *bufcur++ = (objlen >> 24) & 0xff;
611 ofs.write(buffer, bufcur - buffer);
630 if (member == 0)
return "null";
633 Info(
"JsonWriteMember",
"Write member %s type %s ndim %d",
640 if (ptr==0)
return (tid ==
kCharStar) ?
"\"\"" :
"null";
651 if (indx.IsArray() && (tid==
kChar_t))
652 shift = indx.ReduceDimension();
654 char* ppp = (
char*) ptr;
732 }
while (!indx.IsDone());
744 ((
TClass *)memberClass)->Streamer((
void *)ptr, *
this);
752 if ((arr != 0) && (arr->
GetSize() > 0)) {
753 arr->Streamer(*
this);
755 if (
Stack()->fValues.GetLast() > 0) {
756 Warning(
"TBufferJSON",
"When streaming TArray, more than 1 object in the stack, use second item");
761 }
else if (memberClass && !strcmp(memberClass->
GetName(),
"string")) {
763 ((
TClass *)memberClass)->Streamer((
void *)ptr, *
this);
769 if ((memberClass == 0) || (member->
GetArrayDim() > 0) || (arraylen > 0))
return "<not supported>";
780 if (obj == 0)
return kTRUE;
790 if (ptr == 0)
return kTRUE;
804 Info(
"WriteObject",
"Object %p", obj);
814 TJSONStackObj *curr =
Stack();
815 TJSONStackObj *stack =
new TJSONStackObj();
816 stack->fLevel = (curr ? curr->fLevel : 0) + inclevel;
832 return dynamic_cast<TJSONStackObj *
>(
fStack.
Last());
840 TJSONStackObj *stack = 0;
856 if (strlen(line1) > 0) {
858 TJSONStackObj *stack =
Stack();
859 if ((stack != 0) && (stack->fLevel > 0))
871 const char *elem_name = 0;
873 if (base_class == 0) {
877 case TClassEdit::kVector :
878 elem_name =
"fVector";
880 case TClassEdit::kList :
883 case TClassEdit::kForwardlist :
884 elem_name =
"fForwardlist";
886 case TClassEdit::kDeque :
887 elem_name =
"fDeque";
889 case TClassEdit::kMap :
892 case TClassEdit::kMultiMap :
893 elem_name =
"fMultiMap";
895 case TClassEdit::kSet :
898 case TClassEdit::kMultiSet :
899 elem_name =
"fMultiSet";
901 case TClassEdit::kUnorderedSet :
902 elem_name =
"fUnorderedSet";
904 case TClassEdit::kUnorderedMultiSet :
905 elem_name =
"fUnorderedMultiSet";
907 case TClassEdit::kUnorderedMap :
908 elem_name =
"fUnorderedMap";
910 case TClassEdit::kUnorderedMultiMap :
911 elem_name =
"fUnorderedMultiMap";
913 case TClassEdit::kBitSet :
914 elem_name =
"fBitSet";
917 elem_name =
"fArray";
921 elem_name =
"fString";
926 if (elem_name != 0) {
938 TJSONStackObj *stack =
Stack();
939 if (stack != 0) stack->fIsPostProcessed =
kTRUE;
948 if (cl == 0)
return 0;
952 if (isarray)
return 100;
960 bool isstd = TClassEdit::IsStdClass(cl->
GetName());
961 int isstlcont(ROOT::kNotSTL);
963 if (isstlcont > 0)
return isstlcont;
966 if (isstd && !strcmp(cl->
GetName(),
"string"))
return 120;
985 Info(
"JsonWriteObject",
"Object %p class %s check_map %s", obj, cl ? cl->
GetName() :
"null", check_map ?
"true" :
"false");
989 TString fObjectOutput, *fPrevOutput(0);
991 TJSONStackObj *stack =
Stack();
993 if (stack && stack->fAccObjects && ((
fValue.
Length() > 0) || (stack->fValues.GetLast() >= 0))) {
1004 }
else if ((special_kind <= 0) || (special_kind > 100)) {
1014 if (special_kind <= 0) {
1017 std::map<const void *, unsigned>::const_iterator iter =
fJsonrMap.find(obj);
1043 Info(
"JsonWriteObject",
"Starting object %p write for class: %s",
1046 stack->fAccObjects = special_kind < 10;
1048 if (special_kind == -130)
1051 ((
TClass *)cl)->Streamer((
void *)obj, *
this);
1054 Info(
"JsonWriteObject",
"Done object %p write for class: %s",
1057 if (special_kind == 100) {
1058 if (stack->fValues.GetLast() != 0)
1059 Error(
"JsonWriteObject",
"Problem when writing array");
1060 stack->fValues.Delete();
1061 }
else if ((special_kind == 110) || (special_kind == 120)) {
1062 if (stack->fValues.GetLast() > 1)
1063 Error(
"JsonWriteObject",
"Problem when writing TString or std::string");
1064 stack->fValues.Delete();
1067 }
else if ((special_kind > 0) && (special_kind <= TClassEdit::kBitSet)) {
1070 if (stack->fValues.GetLast() < 0) {
1072 if (
fValue !=
"0")
Error(
"JsonWriteObject",
"With empty stack fValue!=0");
1074 }
else if (stack->fValues.GetLast() == 0) {
1076 stack->fValues.Delete();
1078 Error(
"JsonWriteObject",
"Empty value when it should contain something");
1083 const char *separ =
"[";
1090 Int_t size =
TString(stack->fValues.At(0)->GetName()).Atoi();
1092 if ((size * 2 == stack->fValues.GetLast()) &&
1093 ((special_kind == TClassEdit::kMap) || (special_kind == TClassEdit::kMultiMap) ||
1094 (special_kind == TClassEdit::kUnorderedMap) || (special_kind == TClassEdit::kUnorderedMultiMap))) {
1098 if (pairtype.
Index(
"multimap<")==0) pairtype.
Replace(0, 9,
"pair<");
else 1099 if (pairtype.
Index(
"map<")==0) pairtype.
Replace(0, 4,
"pair<");
else pairtype =
"TPair";
1101 for (
Int_t k = 1; k < stack->fValues.GetLast(); k += 2) {
1121 for (
Int_t k = 1; k <= stack->fValues.GetLast(); k++) {
1129 stack->fValues.Delete();
1133 if ((special_kind == 0) &&
1134 ((stack->fValues.GetLast() >= 0) || (
fValue.
Length() > 0))) {
1136 Info(
"JsonWriteObject",
"Create blob value for class %s", cl->
GetName());
1141 const char *separ =
"[";
1143 for (
Int_t k = 0; k <= stack->fValues.GetLast(); k++) {
1157 stack->fValues.Delete();
1162 if (special_kind <= 0) {
1168 if (fPrevOutput != 0) {
1171 if ((special_kind <= 0) || (special_kind > 100))
1173 else if (fObjectOutput.
Length() != 0)
1174 Error(
"JsonWriteObject",
"Non-empty object output for special class %s", cl->
GetName());
1198 if (islist) { sopt.
Capacity(500); sopt =
"["; }
1203 while ((obj = iter()) != 0) {
1267 if (sinfo != 0) cl = sinfo->
GetClass();
1269 if (cl == 0)
return;
1273 TJSONStackObj *stack =
Stack();
1275 if ((stack != 0) && stack->IsStreamerElement() && !stack->fIsObjStarted &&
1279 stack->fIsObjStarted =
kTRUE;
1293 stack->fInfo = sinfo;
1294 stack->fIsStreamerInfo =
kTRUE;
1306 Info(
"DecrementLevel",
"Class: %s",
1309 TJSONStackObj *stack =
Stack();
1311 if (stack->IsStreamerElement()) {
1313 Info(
"DecrementLevel",
" Perform post-processing elem: %s",
1314 stack->fElem->GetName());
1322 Error(
"DecrementLevel",
" Mismatch of streamer info");
1327 Info(
"DecrementLevel",
"Class: %s done",
1339 Info(
"SetStreamerElementNumber",
"Element name %s", elem->
GetName());
1353 TJSONStackObj *stack =
Stack();
1355 Error(
"WorkWithElement",
"stack is empty");
1360 Info(
"WorkWithElement",
" Start element %s type %d typename %s",
1363 if (stack->IsStreamerElement()) {
1367 Info(
"WorkWithElement",
" Perform post-processing elem: %s",
1368 stack->fElem->GetName());
1378 Error(
"WorkWithElement",
"Lost of stack");
1383 if (!stack->IsStreamerInfo()) {
1384 Error(
"WorkWithElement",
"Problem in Inc/Dec level");
1391 Error(
"WorkWithElement",
"streamer info returns elem = 0");
1400 Info(
"WorkWithElement",
" Expects chain for elem %s number %d",
1407 stack->fElemNumber = number;
1408 stack->fIsElemOwner = (number < 0);
1472 if (typeName == 0) typeName =
name;
1474 if ((name == 0) || (strlen(name) == 0)) {
1475 Error(
"ClassMember",
"Invalid member name");
1483 if (strcmp(typeName,
"raw:data") == 0)
1494 if (strcmp(name, typeName) == 0) {
1501 if (tname[tname.
Length() - 1] ==
'*') {
1507 Error(
"ClassMember",
"Invalid class specifier %s", typeName);
1531 }
else if ((typ_id > 0) && (typ_id < 20)) {
1548 Error(
"ClassMember",
"Invalid combination name = %s type = %s",
1570 if ((elem == 0) && stack->fIsPostProcessed)
return;
1571 if (elem == 0) elem = stack->fElem;
1572 if (elem == 0)
return;
1575 Info(
"PerformPostProcessing",
"Element %s type %s",
1578 stack->fIsPostProcessed =
kTRUE;
1581 if (stack->fIsObjStarted) {
1592 Bool_t isTArray = (strncmp(
"TArray", typname, 6) == 0);
1594 if (isTString || isSTLstring) {
1598 Info(
"PerformPostProcessing",
"reformat string value = '%s'",
fValue.
Data());
1600 stack->fValues.Delete();
1601 }
else if (isOffsetPArray) {
1604 if ((stack->fValues.GetLast() < 0) && (
fValue ==
"0")) {
1606 }
else if ((stack->fValues.GetLast() == 0) &&
1607 (strcmp(stack->fValues.Last()->GetName(),
"1") == 0)) {
1608 stack->fValues.Delete();
1610 Error(
"PerformPostProcessing",
"Wrong values for kOffsetP type %s name %s",
1611 typname, (elem ? elem->
GetName() :
"---"));
1612 stack->fValues.Delete();
1615 }
else if (isTObject) {
1616 if (stack->fValues.GetLast() != 0) {
1618 Error(
"PerformPostProcessing",
"When storing TObject, number of items %d not equal to 2", stack->fValues.GetLast());
1629 stack->fValues.Delete();
1630 }
else if (isTArray) {
1632 stack->fValues.Delete();
1640 if (stack->fValues.GetLast() >= 0) {
1643 for (
Int_t n = 0;
n <= stack->fValues.GetLast();
n++) {
1656 if (stack->fValues.GetLast() >= 0)
1715 if (start) *start = 0;
1716 if (bcnt) *bcnt = 0;
1718 if (
gDebug > 3)
Info(
"ReadVersion",
"Version = %d", res);
1750 const TClass *actualClass)
1753 Info(
"WriteObjectClass",
"Class %s", (actualClass ? actualClass->
GetName() :
" null"));
1758 #define TJSONPushValue() \ 1759 if (fValue.Length() > 0) Stack()->PushValue(fValue); 1763 #define TBufferJSON_ReadArray(tname, vname) \ 1765 if (!vname) return 0; \ 1966 #define TBufferJSON_ReadStaticArray(vname) \ 1968 if (!vname) return 0; \ 2095 #define TBufferJSON_ReadFastArray(vname) \ 2097 if (n <= 0) return; \ 2098 if (!vname) return; \ 2286 #define TJSONWriteArrayCompress(vname, arrsize, typname) \ 2288 if ((fCompact < 10) || (arrsize < 6)) { \ 2289 fValue.Append("["); \ 2290 for (Int_t indx=0;indx<arrsize;indx++) { \ 2291 if (indx>0) fValue.Append(fArraySepar.Data()); \ 2292 JsonWriteBasic(vname[indx]); \ 2294 fValue.Append("]"); \ 2296 fValue.Append("{"); \ 2297 fValue.Append(TString::Format("\"$arr\":\"%s\"%s\"len\":%d",typname,fArraySepar.Data(),arrsize)); \ 2298 Int_t aindx(0), bindx(arrsize); \ 2299 while ((aindx<arrsize) && (vname[aindx]==0)) aindx++; \ 2300 while ((aindx<bindx) && (vname[bindx-1]==0)) bindx--; \ 2301 if (aindx<bindx) { \ 2302 TString suffix(""); \ 2303 Int_t p(aindx), suffixcnt(-1), lastp(0); \ 2305 if (vname[p]==0) { p++; continue; } \ 2306 Int_t p0(p++), pp(0), nsame(1); \ 2307 if (fCompact < 20) { pp = bindx; p = bindx+1; nsame = 0; } \ 2308 for(;p<=bindx;++p) { \ 2309 if ((p<bindx) && (vname[p]==vname[p-1])) { nsame++; continue; } \ 2310 if (vname[p-1]==0) { \ 2311 if (nsame>9) { nsame = 0; break; } \ 2314 if (pp) { p = pp; nsame = 0; } else pp = p; \ 2317 pp = p; nsame = 1; \ 2319 if (pp<=p0) continue; \ 2320 if (++suffixcnt > 0) suffix.Form("%d",suffixcnt); \ 2321 if (p0!=lastp) fValue.Append(TString::Format("%s\"p%s\":%d", fArraySepar.Data(), suffix.Data(), p0)); \ 2323 fValue.Append(TString::Format("%s\"v%s\":", fArraySepar.Data(), suffix.Data())); \ 2324 if ((nsame > 1) || (pp-p0 == 1)) { \ 2325 JsonWriteBasic(vname[p0]); \ 2326 if (nsame>1) fValue.Append(TString::Format("%s\"n%s\":%d", fArraySepar.Data(), suffix.Data(), nsame)); \ 2328 fValue.Append("["); \ 2329 for (Int_t indx=p0;indx<pp;indx++) { \ 2330 if (indx>p0) fValue.Append(fArraySepar.Data()); \ 2331 JsonWriteBasic(vname[indx]); \ 2333 fValue.Append("]"); \ 2337 fValue.Append("}"); \ 2342 #define TJSONWriteConstChar(vname,arrsize,typname) \ 2344 JsonWriteConstChar(vname, arrsize); \ 2349 #define TBufferJSON_WriteArray(vname, typname) \ 2352 TJSONWriteArrayCompress(vname, n, typname); \ 2482 #define TBufferJSON_WriteFastArray(vname,method,typname) \ 2485 if (n <= 0) { fValue.Append("[]"); return; } \ 2486 TStreamerElement* elem = Stack(0)->fElem; \ 2487 if ((elem != 0) && (elem->GetType()>TStreamerInfo::kOffsetL) && \ 2488 (elem->GetType() < TStreamerInfo::kOffsetP) && \ 2489 (elem->GetArrayLength() != n)) fExpectedChain = kTRUE; \ 2490 if (fExpectedChain) { \ 2491 TStreamerInfo* info = Stack(1)->fInfo; \ 2492 Int_t startnumber = Stack(0)->fElemNumber; \ 2493 fExpectedChain = kFALSE; \ 2496 elem = (TStreamerElement*)info->GetElements()->At(startnumber++);\ 2497 if (index>0) JsonStartElement(elem); \ 2498 if (elem->GetType()<TStreamerInfo::kOffsetL) { \ 2499 JsonWriteBasic(vname[index]); \ 2502 method((vname+index), elem->GetArrayLength(),typname); \ 2503 index+=elem->GetArrayLength(); \ 2505 PerformPostProcessing(Stack(0), elem); \ 2508 if ((elem!=0) && (elem->GetArrayDim()>1) && (elem->GetArrayLength()==n)) { \ 2509 TArrayI indexes(elem->GetArrayDim() - 1); \ 2511 Int_t cnt = 0, shift = 0, len = elem->GetMaxIndex(indexes.GetSize()); \ 2512 while (cnt >= 0) { \ 2513 if (indexes[cnt] >= elem->GetMaxIndex(cnt)) { \ 2514 fValue.Append("]"); \ 2515 indexes[cnt--] = 0; \ 2516 if (cnt >= 0) indexes[cnt]++; \ 2519 fValue.Append(indexes[cnt] == 0 ? "[" : fArraySepar.Data()); \ 2520 if (++cnt == indexes.GetSize()) { \ 2521 method((vname+shift), len, typname); \ 2527 method(vname, n, typname); \ 2669 Info(
"WriteFastArray",
"void *start cl %s n %d streamer %p",
2670 cl ? cl->
GetName() :
"---",
n, streamer);
2674 (*streamer)(*
this, start, 0);
2678 char *obj = (
char *)start;
2680 int size = cl->
Size();
2684 if (indexes.IsArray()) {
2689 for (
Int_t j = 0; j <
n; j++, obj += size) {
2701 if (indexes.IsArray())
2704 if (
Stack(0)->fIndx)
2715 Info(
"WriteFastArray",
"void **startp cl %s n %d streamer %p",
2720 (*streamer)(*
this, (
void *)start, 0);
2730 if (indexes.IsArray()) {
2735 for (
Int_t j = 0; j <
n; j++) {
2742 if (!start[j]) start[j] = ((
TClass *)cl)->New();
2753 if (indexes.IsArray())
2756 if (
Stack(0)->fIndx)
2794 Info(
"StreamObject",
"Class: %s", (cl ? cl->
GetName() :
"none"));
3096 snprintf(buf,
sizeof(buf),
"%d", value);
3106 snprintf(buf,
sizeof(buf),
"%hd", value);
3116 snprintf(buf,
sizeof(buf),
"%d", value);
3126 snprintf(buf,
sizeof(buf),
"%ld", value);
3150 char* pnt = 0, *
exp = 0, *lastdecimal = 0, *s = sbuf;
3151 bool negative_exp =
false;
3153 while(*s && --len) {
3155 case '.': pnt = s;
break;
3157 case 'e':
exp = s;
break;
3158 case '-':
if (
exp) negative_exp =
true;
break;
3161 if ((*s <
'0') || (*s >
'9'))
return;
3162 if (
exp) power = power*10 + (*s -
'0');
else 3163 if (pnt && *s!=
'0') lastdecimal = s;
3173 if (lastdecimal) *(lastdecimal+1) = 0;
3178 if (lastdecimal) *(lastdecimal+1) = 0;
else 3181 if (!negative_exp && pnt &&
exp && (
exp-pnt > power)) {
3189 if (lastdecimal && (pnt<lastdecimal)) *(lastdecimal+1) = 0;
3192 if (negative_exp && pnt &&
exp && (power < (s-
exp))) {
3194 if (!lastdecimal) lastdecimal = pnt;
3195 *(lastdecimal+1) = 0;
3199 for (
char* pos = lastdecimal+1; pos>=pnt; --pos)
3200 *(pos+power) = *pos;
3208 if (lastdecimal) pnt = lastdecimal+1;
3211 if (*
exp==
'+') ++
exp;
else 3212 if (*
exp==
'-') *pnt++ = *
exp++;
3215 while (*
exp) *pnt++ = *
exp++;
3226 if (value ==
floor(value)) {
3227 snprintf(buf,
sizeof(buf),
"%1.0f", value);
3241 if (value ==
floor(value)) {
3242 snprintf(buf,
sizeof(buf),
"%1.0f", value);
3264 snprintf(buf,
sizeof(buf),
"%u", value);
3274 snprintf(buf,
sizeof(buf),
"%hu", value);
3284 snprintf(buf,
sizeof(buf),
"%u", value);
3294 snprintf(buf,
sizeof(buf),
"%lu", value);
3321 if (len<0) len = strlen(value);
3352 if ((c > 31) && (c < 127))
3370 if (fmt == 0) fmt =
"%e";
3389 if (fmt == 0) fmt =
"%.14e";
3413 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.
fActions.end();
3414 for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.
fActions.begin();
3415 iter != end; ++iter) {
3418 (*iter).PrintDebug(*
this, obj);
3419 (*iter)(*
this, obj);
3423 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.
fActions.end();
3424 for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.
fActions.begin();
3425 iter != end; ++iter) {
3428 (*iter)(*
this, obj);
3440 void *start_collection,
void *end_collection)
3447 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.
fActions.end();
3448 for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.
fActions.begin();
3449 iter != end; ++iter) {
3452 (*iter).PrintDebug(*
this, *(
char **)start_collection);
3453 (*iter)(*
this, start_collection, end_collection);
3457 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.
fActions.end();
3458 for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.
fActions.begin();
3459 iter != end; ++iter) {
3462 (*iter)(*
this, start_collection, end_collection);
3473 void *start_collection,
void *end_collection)
3484 void *arr0 = loopconfig->
GetFirstAddress(start_collection, end_collection);
3486 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.
fActions.end();
3487 for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.
fActions.begin();
3488 iter != end; ++iter) {
3491 (*iter).PrintDebug(*
this, arr0);
3492 (*iter)(*
this, start_collection, end_collection, loopconfig);
3496 TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.
fActions.end();
3497 for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.
fActions.begin();
3498 iter != end; ++iter) {
3501 (*iter)(*
this, start_collection, end_collection, loopconfig);
3514 Info(
"WriteClones",
"Not yet tested");
3523 struct DynamicType {
3527 virtual ~DynamicType() {}
3549 Error(
"WriteObjectAny",
"ptrClass argument may not be 0");
3555 if (clActual == 0) {
3559 DynamicType *d_ptr = (DynamicType *)obj;
3561 "An object of type %s (from type_info) passed through a %s pointer was truncated (due a missing dictionary)!!!",
3562 typeid(*d_ptr).name(), ptrClass->
GetName());
3565 }
else if (clActual && (clActual != ptrClass)) {
3566 const char *temp = (
const char *) obj;
3591 sinfo = (
TStreamerInfo *)const_cast<TClass *>(cl)->GetCurrentStreamerInfo();
3593 const_cast<TClass *
>(cl)->BuildRealData(pointer);
3595 const_cast<TClass *
>(cl)->SetCurrentStreamerInfo(sinfo);
3596 const_cast<TClass *
>(cl)->RegisterStreamerInfo(sinfo);
3598 printf(
"Creating StreamerInfo for class: %s, version: %d\n",
3606 const_cast<TClass *
>(cl)->BuildRealData(pointer);
Abstract array base class.
Describe Streamer information for one class version.
virtual const char * GetName() const
Returns name of object.
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)
Ignored in TBufferJSON.
TStreamerInfoActions::TActionSequence * GetWriteObjectWiseActions()
TString JsonWriteMember(const void *ptr, TDataMember *member, TClass *memberClass, Int_t arraylen)
Convert single data member to JSON structures Returns string with converted member.
virtual void WriteUChar(UChar_t c)
Writes UChar_t value to buffer.
virtual void WriteArrayFloat16(const Float_t *f, Int_t n, TStreamerElement *ele=0)
Write array of Float16_t to buffer.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
virtual Int_t WriteClones(TClonesArray *a, Int_t nobjects)
Interface to TStreamerInfo::WriteBufferClones.
void WorkWithElement(TStreamerElement *elem, Int_t comp_type)
This is call-back from streamer which indicates that class member will be streamed Name of element us...
virtual TClass * ReadClass(const TClass *cl=0, UInt_t *objTag=0)
suppressed function of TBuffer
virtual Int_t ReadStaticArray(Bool_t *b)
Read array of Bool_t from buffer.
ActionContainer_t fActions
virtual Int_t ReadArray(Bool_t *&b)
Read array of Bool_t from buffer.
void JsonDisablePostprocessing()
virtual void ReadShort(Short_t &s)
Reads Short_t value from buffer.
virtual Int_t WriteObjectAny(const void *obj, const TClass *ptrClass)
Write object to I/O buffer.
virtual Int_t ReadStaticArrayFloat16(Float_t *f, TStreamerElement *ele=0)
Read array of Float16_t from buffer.
virtual void WriteLong64(Long64_t l)
Writes Long64_t value to buffer.
#define TBufferJSON_ReadArray(tname, vname)
virtual TClass * GetClass() const =0
TLoopConfiguration * fLoopConfig
If this is a bundle of memberwise streaming action, this configures the looping.
Collectable string class.
virtual void ReadFloat(Float_t &f)
Reads Float_t value from buffer.
virtual void ReadWithFactor(Float_t *ptr, Double_t factor, Double_t minvalue)
Read a Double32_t from the buffer when the factor and minimun value have been specified see comments ...
virtual void Delete(Option_t *option="")
Remove all objects from the array AND delete all heap based objects.
All ROOT classes may have RTTI (run time type identification) support added.
R__EXTERN TVirtualMutex * gInterpreterMutex
virtual void ReadWithNbits(Float_t *ptr, Int_t nbits)
Read a Float16_t from the buffer when the number of bits is specified (explicitly or not) see comment...
TString fSemicolon
0 - no any compression, 1 - no spaces in the begin, 2 - no new lines, 3 - no spaces at all ...
virtual void SkipObjectAny()
Skip any kind of object from buffer.
Int_t GetUnitSize() const
Get the sizeof the underlying type of the data member (i.e.
virtual void ReadCharP(Char_t *c)
Reads array of characters from buffer.
virtual TClass * GetClassPointer() const
Returns a pointer to the TClass of this element.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual void DecrementLevel(TVirtualStreamerInfo *)
Function is called from TStreamerInfo WriteBuffer and ReadBuffer functions and decrease level in json...
TString fArraySepar
depending from compression level, " : " or ":"
virtual void ReadFastArrayWithFactor(Float_t *ptr, Int_t n, Double_t factor, Double_t minvalue)
read array of Float16_t from buffer
const char * GetTypeName() const
Get type of data member, e,g.: "class TDirectory*" -> "TDirectory".
virtual void ReadBool(Bool_t &b)
Reads Bool_t value from buffer.
Int_t fCompact
flag to resolve situation when several elements of same basic type stored as FastArray ...
virtual void WriteDouble(Double_t d)
Writes Double_t value to buffer.
virtual void ReadLong64(Long64_t &l)
Reads Long64_t value from buffer.
virtual void ReadStdString(std::string *s)
Reads a std::string.
Buffer base class used for serializing objects.
void JsonWriteBasic(Char_t value)
converts Char_t to string and add to json value buffer
virtual TObject * Remove(TObject *obj)
Remove object from array.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
static void SetDoubleFormat(const char *fmt="%.14e")
set printf format for double members, default "%.14e" use it after SetFloatFormat, which also overwrites format for doubles
virtual void ReadFastArrayFloat16(Float_t *f, Int_t n, TStreamerElement *ele=0)
read array of Float16_t from buffer
virtual void WriteULong64(ULong64_t l)
Writes ULong64_t value to buffer.
Int_t JsonSpecialClass(const TClass *cl) const
return non-zero value when class has special handling in JSON it is TCollection (-130), TArray (100), TString (110), std::string (120) and STL containers (1..6)
Int_t GetArrayLength() const
virtual void ReadFastArray(Bool_t *b, Int_t n)
read array of Bool_t from buffer
#define TJSONWriteConstChar(vname, arrsize, typname)
static const char * fgDoubleFmt
printf argument for floats, either "%f" or "%e" or "%10f" and so on
virtual void ReadLong(Long_t &l)
Reads Long_t value from buffer.
virtual void WriteLong(Long_t l)
Writes Long_t value to buffer.
virtual Int_t ApplySequence(const TStreamerInfoActions::TActionSequence &sequence, void *object)
Read one collection of objects from the buffer using the StreamerInfoLoopAction.
void SetParent(TObject *parent)
Set parent owning this buffer.
Option_t * GetOption() const
virtual void SetArrayDim(Int_t dim)
Set number of array dimensions.
TObject * At(Int_t idx) const
Int_t GetArrayDim() const
virtual void WriteFastArrayString(const Char_t *c, Int_t n)
Write array of Char_t to buffer.
virtual void SetMaxIndex(Int_t dim, Int_t max)
set maximum index for array with dimension dim
Array of integers (32 bits per element).
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
#define TBufferJSON_WriteFastArray(vname, method, typname)
virtual void WriteInt(Int_t i)
Writes Int_t value to buffer.
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)
suppressed function of TBuffer
Int_t GetBaseClassOffset(const TClass *toBase, void *address=0, bool isDerivedObject=true)
TObject * Last() const
Return the object in the last filled slot. Returns 0 if no entries.
virtual void ReadChar(Char_t &c)
Reads Char_t value from buffer.
Bool_t IsBasic() const
Return true if data member is a basic type, e.g. char, int, long...
virtual void ReadFastArrayDouble32(Double_t *d, Int_t n, TStreamerElement *ele=0)
read array of Double32_t from buffer
virtual void * GetFirstAddress(void *start, const void *end) const =0
virtual void WriteFastArray(const Bool_t *b, Int_t n)
Write array of Bool_t to buffer.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
virtual void ReadUShort(UShort_t &s)
Reads UShort_t value from buffer.
void Clear()
Clear string without changing its capacity.
virtual void ReadDouble(Double_t &d)
Reads Double_t value from buffer.
virtual void WriteObject(const TObject *obj)
Convert object into json structures.
TJSONStackObj * Stack(Int_t depth=0)
return stack object of specified depth
TString & Append(const char *cs)
std::map< const void *, unsigned > fJsonrMap
buffer for current value
Long_t GetThisOffset() const
unsigned fJsonrCnt
map of recorded objects, used in JsonR to restore references
virtual void ReadCharStar(char *&s)
Reads a char* string.
TDataType * GetDataType() const
TObjArray fStack
counter for all objects and arrays
virtual void ReadUChar(UChar_t &c)
Reads UChar_t value from buffer.
#define TBufferJSON_ReadStaticArray(vname)
void Set(Int_t n)
Set size of this array to n ints.
Base class of the Configurations for the member wise looping routines.
void SetCompact(int level)
virtual void WriteFastArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele=0)
Write array of Double32_t to buffer.
void JsonWriteConstChar(const char *value, Int_t len=-1)
writes string value, processing all kind of special characters
Int_t GetMaxIndex(Int_t dim) const
Return maximum index for array dimension "dim".
virtual Int_t ReadStaticArrayDouble32(Double_t *d, TStreamerElement *ele=0)
Read array of Double32_t from buffer.
TString fNumericLocale
depending from compression level, ", " or ","
virtual void ReadInt(Int_t &i)
Reads Int_t value from buffer.
TString fValue
current output buffer for json code
virtual void SetStreamerElementNumber(TStreamerElement *elem, Int_t comp_type)
Function is called from TStreamerInfo WriteBuffer and Readbuffer functions and add/verify next elemen...
virtual void WriteStdString(const std::string *s)
Writes a std::string.
Bool_t IsCompiled() const
Int_t GetLast() const
Return index of last object in array.
virtual void IncrementLevel(TVirtualStreamerInfo *)
Function is called from TStreamerInfo WriteBuffer and ReadBuffer functions and indent new level in js...
virtual void SetByteCount(UInt_t cntpos, Bool_t packInVersion=kFALSE)
suppressed function of TBuffer
static Int_t ExportToFile(const char *filename, const TObject *obj, const char *option=0)
Convert object into JSON and store in text file Returns size of the produce file Used in TObject::Sav...
TClass * GetClass() const
void BuildOld()
rebuild the TStreamerInfo structure
virtual void TagStreamerInfo(TVirtualStreamerInfo *)
virtual void ReadULong(ULong_t &l)
Reads ULong_t value from buffer.
virtual void WriteObjectClass(const void *actualObjStart, const TClass *actualClass)
Write object to buffer. Only used from TBuffer.
Basic data type descriptor (datatype information is obtained from CINT).
TClass * GetActualClass(const void *object) const
Return a pointer the the real class of the object.
static const char * GetDoubleFormat()
return current printf format for double members, default "%.14e"
virtual void ClassBegin(const TClass *, Version_t=-1)
Should be called in the beginning of custom class streamer.
virtual Int_t ApplySequenceVecPtr(const TStreamerInfoActions::TActionSequence &sequence, void *start_collection, void *end_collection)
Read one collection of objects from the buffer using the StreamerInfoLoopAction.
TString * fOutput
main output buffer for json code
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
TDataMember * GetDataMember() const
Collection abstract base class.
void AppendOutput(const char *line0, const char *line1=0)
Info("AppendOutput"," '%s' '%s'", line0, line1?line1 : "---");.
virtual void ReadDouble32(Double_t *d, TStreamerElement *ele=0)
read a Double32_t from the buffer
Int_t GetMaxIndex(Int_t i) const
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
char * Form(const char *fmt,...)
virtual void SkipVersion(const TClass *cl=0)
Skip class version from I/O buffer.
Int_t Size() const
Return size of object of this class.
The TRealData class manages the effective list of all data members for a given class.
Int_t GetArrayDim() const
Return number of array dimensions.
The ROOT global object gROOT contains a list of all defined classes.
ROOT::ESTLType GetCollectionType() const
Return the 'type' of the STL the TClass is representing.
static const char * fgFloatFmt
stored value of setlocale(LC_NUMERIC), which should be recovered at the end
virtual void WriteUShort(UShort_t s)
Writes UShort_t value to buffer.
virtual void WriteBool(Bool_t b)
Writes Bool_t value to buffer.
virtual void WriteDouble32(Double_t *d, TStreamerElement *ele=0)
write a Double32_t to the buffer
void WorkWithClass(TStreamerInfo *info, const TClass *cl=0)
Prepares buffer to stream data of specified class.
void JsonStartElement(const TStreamerElement *elem, const TClass *base_class=0)
virtual void ReadTString(TString &s)
Reads a TString.
virtual void WriteFloat(Float_t f)
Writes Float_t value to buffer.
void PerformPostProcessing(TJSONStackObj *stack, const TStreamerElement *elem=0)
Function is converts TObject and TString structures to more compact representation.
const char * GetTrueTypeName() const
Get full type description of data member, e,g.: "class TDirectory*".
virtual void WriteFastArrayFloat16(const Float_t *d, Int_t n, TStreamerElement *ele=0)
Write array of Float16_t to buffer.
Version_t GetClassVersion() const
virtual void WriteTString(const TString &s)
Writes a TString.
void Build()
Build the I/O data structure for the current class version.
static const char * GetFloatFormat()
return current printf format for float members, default "%e"
virtual void WriteShort(Short_t s)
Writes Short_t value to buffer.
virtual void ReadFloat16(Float_t *f, TStreamerElement *ele=0)
read a Float16_t from the buffer
virtual Bool_t CheckObject(const TObject *)
Check that object already stored in the buffer.
virtual void WriteUInt(UInt_t i)
Writes UInt_t value to buffer.
virtual void WriteFloat16(Float_t *f, TStreamerElement *ele=0)
write a Float16_t to the buffer
virtual void WriteULong(ULong_t l)
Writes ULong_t value to buffer.
virtual void WriteArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele=0)
Write array of Double32_t to buffer.
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
Int_t IndexOf(const TObject *obj) const
unsigned long long ULong64_t
TList * GetListOfRealData() const
#define TJSONWriteArrayCompress(vname, arrsize, typname)
Bool_t fExpectedChain
stack of streamer infos
static RooMathCoreReg dummy
virtual Bool_t IsBase() const
Return kTRUE if the element represent a base class.
static TString ConvertToJSON(const TObject *obj, Int_t compact=0, const char *member_name=0)
Converts object, inherited from TObject class, to JSON string Lower digit of compact parameter define...
virtual void * ReadObjectAny(const TClass *clCast)
Read object from buffer. Only used from TBuffer.
virtual void WriteCharStar(char *s)
Writes a char*.
#define R__LOCKGUARD(mutex)
TBufferJSON()
Creates buffer object to serialize data into json.
void JsonWriteObject(const void *obj, const TClass *objClass, Bool_t check_map=kTRUE)
Write object to buffer If object was written before, only pointer will be stored If check_map==kFALSE...
virtual void ReadULong64(ULong64_t &l)
Reads ULong64_t value from buffer.
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.
virtual void ClassEnd(const TClass *)
Should be called at the end of custom streamer See TBufferJSON::ClassBegin for more details...
virtual Int_t ReadArrayDouble32(Double_t *&d, TStreamerElement *ele=0)
Read array of Double32_t from buffer.
Mother of all ROOT objects.
TObjArray * GetElements() const
static void SetFloatFormat(const char *fmt="%e")
set printf format for float/double members, default "%e" to change format only for doubles...
Int_t IsSTLContainer()
The return type is defined in TDictionary (kVector, kList, etc.)
TJSONStackObj * PopStack()
remove one level from stack
virtual void StreamObject(void *obj, const std::type_info &typeinfo, const TClass *onFileClass=0)
stream object to/from buffer
Bool_t IsTObject() const
Return kTRUE is the class inherits from TObject.
virtual void WriteChar(Char_t c)
Writes Char_t value to buffer.
An array of clone (identical) objects.
const char * GetTypeName() const
virtual Int_t ReadArrayFloat16(Float_t *&f, TStreamerElement *ele=0)
Read array of Float16_t from buffer.
virtual void WriteCharP(const Char_t *c)
Writes array of characters to buffer.
const char * GetArrayIndex() const
If the data member is pointer and has a valid array size in its comments GetArrayIndex returns a stri...
static void CompactFloatString(char *buf, unsigned len)
method compress float string, excluding exp and/or move float point 1.000000e-01 -> 0...
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
TJSONStackObj * PushStack(Int_t inclevel=0)
add new level to the structures stack
#define TBufferJSON_ReadFastArray(vname)
#define TBufferJSON_WriteArray(vname, typname)
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
Int_t Atoi() const
Return integer value of string.
void SetBaseVersion(Int_t v)
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)
Function called by the Streamer functions to serialize object at p to buffer b.
void JsonStreamCollection(TCollection *obj, const TClass *objClass)
store content of collection
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)
read version value from buffer
virtual ~TBufferJSON()
destroy buffer
virtual void WriteClass(const TClass *cl)
suppressed function of TBuffer
virtual void ReadFastArrayString(Char_t *c, Int_t n)
read array of Char_t from buffer
virtual void Compress()
Remove empty slots from array.
Abstract Interface class describing Streamer information for one class.
Bool_t IsaPointer() const
Return true if data member is a pointer.
virtual void WriteArray(const Bool_t *b, Int_t n)
Write array of Bool_t to buffer.
TRealData * GetRealData(const char *name) const
Return pointer to TRealData element with name "name".
virtual void ReadFastArrayWithNbits(Float_t *ptr, Int_t n, Int_t nbits)
read array of Float16_t from buffer
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual const char * GetName() const
Return name of this collection.
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
virtual void ReadUInt(UInt_t &i)
Reads UInt_t value from buffer.
virtual void ClassMember(const char *name, const char *typeName=0, Int_t arrsize1=-1, Int_t arrsize2=-1)
Method indicates name and typename of class member, which should be now streamed in custom streamer F...
const char * Data() const
TVirtualStreamerInfo * fStreamerInfo
StreamerInfo used to derive these actions.