89class TArrayIndexProducer {
101 : fTotalLen(0), fCnt(-1), fSepar(separ), fIndicies(), fMaxIndex(), fRes(), fIsArray(
kFALSE)
106 Bool_t usearraylen = (arraylen > (isloop ? 0 : 1));
108 if (usearrayindx && (arraylen > 0)) {
113 ::Error(
"TArrayIndexProducer",
"Problem with JSON coding of element %s type %d", elem->
GetName(),
121 for (
int dim = 0; dim < elem->
GetArrayDim(); dim++)
123 fIsArray = fTotalLen > 1;
124 }
else if (usearraylen) {
125 fTotalLen = arraylen;
127 fMaxIndex[0] = arraylen;
138 : fTotalLen(0), fCnt(-1), fSepar(separ), fIndicies(), fMaxIndex(), fRes(), fIsArray(
kFALSE)
149 for (
int dim = 0; dim < member->
GetArrayDim(); dim++) {
155 fMaxIndex[ndim - 1] = extradim;
156 fTotalLen *= extradim;
159 fIsArray = fTotalLen > 1;
163 Int_t NumDimensions()
const {
return fIndicies.
GetSize(); }
166 TArrayI &GetIndices() {
return fIndicies; };
169 Int_t TotalLength()
const {
return fTotalLen; }
171 Int_t ReduceDimension()
178 Int_t len = fMaxIndex[ndim];
181 fTotalLen = fTotalLen / len;
182 fIsArray = fTotalLen > 1;
186 Bool_t IsArray()
const {
return fIsArray; }
191 return !IsArray() || (fCnt >= fTotalLen);
194 const char *GetBegin()
214 const char *NextSeparator()
216 if (++fCnt >= fTotalLen)
225 if (fIndicies[
cnt] >= fMaxIndex[
cnt]) {
227 fIndicies[
cnt--] = 0;
232 fRes.
Append(fIndicies[
cnt] == 0 ?
"[" : fSepar);
243 for (
int k = 1; k < fIndicies.GetSize(); ++k)
244 subnode = &((*subnode)[fIndicies[k]]);
255class TJSONStackObj :
public TObject {
266 TArrayIndexProducer *fIndx;
274 :
TObject(), fInfo(nullptr), fElem(nullptr), fIsStreamerInfo(
kFALSE), fIsElemOwner(
kFALSE),
275 fIsPostProcessed(
kFALSE), fIsObjStarted(
kFALSE), fAccObjects(
kFALSE), fValues(), fLevel(0), fIndx(nullptr),
276 fNode(nullptr), fStlIndx(-1), fStlMap(-1), fClVersion(0)
281 virtual ~TJSONStackObj()
289 Bool_t IsStreamerInfo()
const {
return fIsStreamerInfo; }
291 Bool_t IsStreamerElement()
const {
return !fIsStreamerInfo && fElem; }
311 if (
json->is_array())
315 if (
json->is_object() && (
json->count(
"$arr") == 1))
316 return json->at(
"len").get<
int>();
330 TArrayIndexProducer *MakeReadIndexes()
336 TArrayIndexProducer *indx =
new TArrayIndexProducer(fElem, -1,
"");
338 if (!indx->IsArray() || (indx->NumDimensions() < 2)) {
346 Bool_t IsStl()
const {
return fStlIndx >= 0; }
357 return &(
json->at(
"second"));
361 return &(
json->at(
"first"));
369 :
TBufferText(mode), fOutBuffer(), fOutput(nullptr),
fValue(), fJsonrCnt(0), fStack(), fCompact(0),
370 fSemicolon(
" : "), fArraySepar(
", "), fNumericLocale()
379 char *loc = setlocale(LC_NUMERIC, 0);
380 if (loc && (strcmp(loc,
"C") != 0)) {
382 setlocale(LC_NUMERIC,
"C");
416 TClass *clActual =
nullptr;
417 void *ptr = (
void *)obj;
470 const void *actualStart = obj;
471 if (clActual && (clActual != cl)) {
476 clActual =
const_cast<TClass *
>(cl);
479 if (member_name && actualStart) {
484 while ((rdata =
dynamic_cast<TRealData *
>(iter())) !=
nullptr) {
486 if (member && strcmp(member->
GetName(), member_name) == 0)
498 arraylen = *((
int *)((
char *)actualStart + idata->
GetThisOffset()));
504 ptr = *((
char **)ptr);
559 if (!obj || !filename || (*filename == 0))
562 Int_t compact = strstr(filename,
".json.gz") ? 3 : 0;
563 if (option && (*option >=
'0') && (*option <=
'3'))
568 std::ofstream ofs(filename);
570 if (strstr(filename,
".json.gz")) {
571 const char *objbuf =
json.Data();
574 unsigned long objcrc = R__crc32(0, NULL, 0);
575 objcrc = R__crc32(objcrc, (
const unsigned char *)objbuf, objlen);
578 Int_t buflen = 10 + objlen + 8;
582 char *buffer = (
char *)
malloc(buflen);
586 char *bufcur = buffer;
602 memcpy(
dummy, bufcur - 6, 6);
605 unsigned long ziplen = R__memcompress(bufcur - 6, objlen + 6, (
char *)objbuf, objlen);
607 memcpy(bufcur - 6,
dummy, 6);
609 bufcur += (ziplen - 6);
611 *bufcur++ = objcrc & 0xff;
612 *bufcur++ = (objcrc >> 8) & 0xff;
613 *bufcur++ = (objcrc >> 16) & 0xff;
614 *bufcur++ = (objcrc >> 24) & 0xff;
616 *bufcur++ = objlen & 0xff;
617 *bufcur++ = (objlen >> 8) & 0xff;
618 *bufcur++ = (objlen >> 16) & 0xff;
619 *bufcur++ = (objlen >> 24) & 0xff;
621 ofs.write(buffer, bufcur - buffer);
630 return json.Length();
639 if (!obj || !cl || !filename || (*filename == 0))
642 Int_t compact = strstr(filename,
".json.gz") ? 3 : 0;
643 if (option && (*option >=
'0') && (*option <=
'3'))
648 std::ofstream ofs(filename);
650 if (strstr(filename,
".json.gz")) {
651 const char *objbuf =
json.Data();
654 unsigned long objcrc = R__crc32(0, NULL, 0);
655 objcrc = R__crc32(objcrc, (
const unsigned char *)objbuf, objlen);
658 Int_t buflen = 10 + objlen + 8;
662 char *buffer = (
char *)
malloc(buflen);
666 char *bufcur = buffer;
682 memcpy(
dummy, bufcur - 6, 6);
685 unsigned long ziplen = R__memcompress(bufcur - 6, objlen + 6, (
char *)objbuf, objlen);
687 memcpy(bufcur - 6,
dummy, 6);
689 bufcur += (ziplen - 6);
691 *bufcur++ = objcrc & 0xff;
692 *bufcur++ = (objcrc >> 8) & 0xff;
693 *bufcur++ = (objcrc >> 16) & 0xff;
694 *bufcur++ = (objcrc >> 24) & 0xff;
696 *bufcur++ = objlen & 0xff;
697 *bufcur++ = (objlen >> 8) & 0xff;
698 *bufcur++ = (objlen >> 16) & 0xff;
699 *bufcur++ = (objlen >> 24) & 0xff;
701 ofs.write(buffer, bufcur - buffer);
710 return json.Length();
732 return (
TObject *)(((
char *)obj) + delta);
742 TClass *objClass =
nullptr;
779 if (!res || !resClass)
782 if (resClass == expectedClass)
787 ::Error(
"TBufferJSON::ConvertFromJSONChecked",
"expected class %s is not base for read class %s",
793 return (
char *)res - offset;
816 return (tid ==
kCharStar) ?
"\"\"" :
"null";
827 if (indx.IsArray() && (tid ==
kChar_t))
828 shift = indx.ReduceDimension();
830 char *ppp = (
char *)ptr;
873 }
while (!indx.IsDone());
884 ((
TClass *)memberClass)->Streamer((
void *)ptr, *
this);
893 if (arr && (arr->
GetSize() > 0)) {
894 arr->Streamer(*
this);
896 if (
Stack()->fValues.GetLast() > 0) {
897 Warning(
"TBufferJSON",
"When streaming TArray, more than 1 object in the stack, use second item");
902 }
else if (memberClass && !strcmp(memberClass->
GetName(),
"string")) {
904 ((
TClass *)memberClass)->Streamer((
void *)ptr, *
this);
911 if (!memberClass || (member->
GetArrayDim() > 0) || (arraylen > 0))
912 return "<not supported>";
922 TJSONStackObj *next =
new TJSONStackObj();
923 next->fLevel = inclevel;
925 next->fLevel +=
Stack()->fLevel;
956 if (strlen(line1) > 0) {
958 if (
Stack()->fLevel > 0)
971 const char *elem_name =
nullptr;
974 switch (special_kind) {
1003 if (
json->count(elem_name) != 1) {
1004 Error(
"JsonStartElement",
"Missing JSON structure for element %s", elem_name);
1006 Stack()->fNode = &((*json)[elem_name]);
1009 Stack()->PushIntValue(len > 0 ? len : 0);
1011 Error(
"JsonStartElement",
"Missing array when reading TArray class for element %s", elem->
GetName());
1013 if ((
gDebug > 1) && base_class)
1014 Info(
"JsonStartElement",
"Reading baseclass %s from element %s", base_class->
GetName(), elem_name);
1063 if (isstd && !strcmp(cl->
GetName(),
"string"))
1080 Info(
"JsonWriteObject",
"Object %p class %s check_map %s", obj, cl ? cl->
GetName() :
"null",
1081 check_map ?
"true" :
"false");
1085 TString fObjectOutput, *fPrevOutput(
nullptr);
1087 TJSONStackObj *stack =
Stack();
1089 if (stack && stack->fAccObjects && ((
fValue.
Length() > 0) || (stack->fValues.GetLast() >= 0))) {
1100 }
else if ((special_kind <= 0) || (special_kind >
json_TArray)) {
1110 if (special_kind <= 0) {
1139 Info(
"JsonWriteObject",
"Starting object %p write for class: %s", obj, cl->
GetName());
1146 ((
TClass *)cl)->Streamer((
void *)obj, *
this);
1149 Info(
"JsonWriteObject",
"Done object %p write for class: %s", obj, cl->
GetName());
1152 if (stack->fValues.GetLast() != 0)
1153 Error(
"JsonWriteObject",
"Problem when writing array");
1154 stack->fValues.Delete();
1156 if (stack->fValues.GetLast() > 1)
1157 Error(
"JsonWriteObject",
"Problem when writing TString or std::string");
1158 stack->fValues.Delete();
1161 }
else if ((special_kind > 0) && (special_kind <
ROOT::kSTLend)) {
1164 if (stack->fValues.GetLast() < 0) {
1167 Error(
"JsonWriteObject",
"With empty stack fValue!=0");
1173 if ((stack->fValues.GetLast() == 0) && ((size > 1) || (
fValue.
Index(
"[") == 0))) {
1175 stack->fValues.Delete();
1177 Error(
"JsonWriteObject",
"Empty value when it should contain something");
1182 const char *separ =
"[";
1189 if ((size * 2 == stack->fValues.GetLast()) &&
1196 if (pairtype.
Index(
"unordered_map<") == 0)
1197 pairtype.
Replace(0, 14,
"pair<");
1198 else if (pairtype.
Index(
"unordered_multimap<") == 0)
1199 pairtype.
Replace(0, 19,
"pair<");
1200 else if (pairtype.
Index(
"multimap<") == 0)
1201 pairtype.
Replace(0, 9,
"pair<");
1202 else if (pairtype.
Index(
"map<") == 0)
1203 pairtype.
Replace(0, 4,
"pair<");
1207 for (
Int_t k = 1; k < stack->fValues.GetLast(); k += 2) {
1227 for (
Int_t k = 1; k <= stack->fValues.GetLast(); k++) {
1235 stack->fValues.Delete();
1243 if ((special_kind == 0) && ((stack->fValues.GetLast() >= 0) || (
fValue.
Length() > 0))) {
1245 Info(
"JsonWriteObject",
"Create blob value for class %s", cl->
GetName());
1250 const char *separ =
"[";
1252 for (
Int_t k = 0; k <= stack->fValues.GetLast(); k++) {
1266 stack->fValues.Delete();
1271 if (special_kind <= 0) {
1280 if ((special_kind <= 0) || (special_kind >
json_TArray))
1282 else if (fObjectOutput.
Length() != 0)
1283 Error(
"JsonWriteObject",
"Non-empty object output for special class %s", cl->
GetName());
1303 TMap *map =
nullptr;
1305 map =
dynamic_cast<TMap *
>(col);
1316 while ((obj = iter()) !=
nullptr) {
1368 TList *lst =
nullptr;
1369 TMap *map =
nullptr;
1372 lst =
dynamic_cast<TList *
>(col);
1374 map =
dynamic_cast<TMap *
>(col);
1380 std::string
name =
json->at(
"name");
1384 int size = arr.
size();
1386 for (
int n = 0;
n < size; ++
n) {
1390 subelem = &subelem->
at(
"first");
1394 TClass *readClass =
nullptr, *objClass =
nullptr;
1395 void *subobj =
nullptr;
1400 clones->
SetClass(subelem->
at(
"_typename").
get<std::string>().c_str(), size);
1401 }
else if (size > clones->
GetSize()) {
1402 Error(
"JsonReadCollection",
"TClonesArray size %d smaller than required %d\n", clones->
GetSize(), size);
1417 if (!subobj || !readClass) {
1420 Error(
"JsonReadCollection",
"Try to add object %s not derived from TObject", readClass->
GetName());
1429 readClass =
nullptr;
1434 if (!subobj2 || !readClass) {
1437 Error(
"JsonReadCollection",
"Try to add object %s not derived from TObject", readClass->
GetName());
1441 map->
Add(tobj,
static_cast<TObject *
>(subobj2));
1443 std::string opt =
json->at(
"opt").at(
n).get<std::string>();
1444 lst->
Add(tobj, opt.c_str());
1458 *readClass =
nullptr;
1460 TJSONStackObj *stack =
Stack();
1462 Bool_t process_stl = stack->IsStl();
1466 if (
json->is_null())
1472 if (
json->is_object() && (
json->size() == 1) && (
json->find(
"$ref") !=
json->end())) {
1473 unsigned refid =
json->at(
"$ref").get<
unsigned>();
1475 void *ref_obj =
nullptr;
1476 TClass *ref_cl =
nullptr;
1480 if (!ref_obj || !ref_cl) {
1481 Error(
"JsonReadObject",
"Fail to find object for reference %u", refid);
1486 *readClass = ref_cl;
1489 Info(
"JsonReadObject",
"Extract object reference %u %p cl:%s expects:%s", refid, ref_obj, ref_cl->
GetName(),
1490 (objClass ? objClass->
GetName() :
"---"));
1498 obj = objClass->
New();
1501 Info(
"JsonReadObject",
"Read string from %s",
json->dump().c_str());
1504 *((std::string *)obj) =
json->get<std::string>();
1506 *((
TString *)obj) =
json->get<std::string>().c_str();
1509 *readClass = (
TClass *)objClass;
1514 Bool_t isBase = (stack->fElem && objClass) ? stack->fElem->IsBase() :
kFALSE;
1516 if (isBase && (!obj || !objClass)) {
1517 Error(
"JsonReadObject",
"No object when reading base class");
1526 TClass *jsonClass =
nullptr;
1530 jsonClass = (
TClass *)objClass;
1533 obj = jsonClass->
New();
1537 stack->PushIntValue(len > 0 ? len : 0);
1540 Error(
"JsonReadObject",
"Not array when expecting such %s",
json->dump().c_str());
1543 Info(
"JsonReadObject",
"Reading special kind %d %s ptr %p", special_kind, objClass->
GetName(), obj);
1545 }
else if (isBase) {
1548 jsonClass = (
TClass *)objClass;
1551 Info(
"JsonReadObject",
"Reading baseclass %s ptr %p", objClass->
GetName(), obj);
1554 std::string clname =
json->at(
"_typename").get<std::string>();
1559 Error(
"JsonReadObject",
"Cannot find class %s", clname.c_str());
1565 if (objClass && (jsonClass != objClass)) {
1566 Error(
"JsonReadObject",
"Class mismatch between provided %s and in JSON %s", objClass->
GetName(),
1567 jsonClass->GetName());
1571 obj = jsonClass->New();
1574 Info(
"JsonReadObject",
"Reading object of class %s refid %u ptr %p", clname.c_str(),
fJsonrCnt, obj);
1600 stack->fStlIndx = 0;
1610 Info(
"JsonReadObject",
"Calling streamer of class %s", jsonClass->
GetName());
1612 if (isBase && (special_kind == 0))
1613 Error(
"JsonReadObject",
"Should not be used for reading of base class %s", jsonClass->
GetName());
1615 jsonClass->
Streamer((
void *)obj, *
this);
1617 stack->fClVersion = 0;
1619 stack->fStlIndx = -1;
1620 stack->fStlMap = -1;
1628 Info(
"JsonReadObject",
"Reading object of class %s done", jsonClass->
GetName());
1631 *readClass = jsonClass;
1640 UInt_t uid =
json->at(
"fUniqueID").get<
unsigned>();
1641 UInt_t bits =
json->at(
"fBits").get<
unsigned>();
1646 for (
unsigned n = 0;
n < 32;
n++)
1650 Info(
"JsonReadTObjectMembers",
"Reading TObject part bits %u kMustCleanup %d", bits, tobj->
TestBit(
kMustCleanup));
1679 Info(
"WorkWithClass",
"Class: %s", cl->
GetName());
1681 TJSONStackObj *stack =
Stack();
1685 }
else if (stack && stack->IsStreamerElement() && !stack->fIsObjStarted &&
1689 stack->fIsObjStarted =
kTRUE;
1703 stack->fInfo = sinfo;
1704 stack->fIsStreamerInfo =
kTRUE;
1716 TJSONStackObj *stack =
Stack();
1718 if (stack->IsStreamerElement()) {
1722 Info(
"DecrementLevel",
" Perform post-processing elem: %s", stack->fElem->GetName());
1731 Error(
"DecrementLevel",
" Mismatch of streamer info");
1736 Info(
"DecrementLevel",
"Class: %s done", (info ? info->
GetClass()->
GetName() :
"custom"));
1744 return Stack()->fInfo;
1755 Info(
"SetStreamerElementNumber",
"Element name %s", elem->
GetName());
1767 TJSONStackObj *stack =
Stack();
1769 Error(
"WorkWithElement",
"stack is empty");
1774 Info(
"WorkWithElement",
" Start element %s type %d typename %s", elem ? elem->
GetName() :
"---",
1777 if (stack->IsStreamerElement()) {
1782 Info(
"WorkWithElement",
" Perform post-processing elem: %s", stack->fElem->GetName());
1792 Error(
"WorkWithElement",
"Lost of stack");
1797 if (!stack->IsStreamerInfo()) {
1798 Error(
"WorkWithElement",
"Problem in Inc/Dec level");
1805 Error(
"WorkWithElement",
"streamer info returns elem = 0");
1813 stack->fIsElemOwner = (number < 0);
1830 stack->PushIntValue(stack->IsJsonString() || (stack->IsJsonArray() > 0) ? 1 : 0);
1900 if (!
name || (strlen(
name) == 0)) {
1901 Error(
"ClassMember",
"Invalid member name");
1909 if (strcmp(typeName,
"raw:data") == 0)
1919 if (strcmp(
name, typeName) == 0) {
1927 if (tname[tname.
Length() - 1] ==
'*') {
1933 Error(
"ClassMember",
"Invalid class specifier %s", typeName);
1957 }
else if ((typ_id > 0) && (typ_id < 20)) {
1973 Error(
"ClassMember",
"Invalid combination name = %s type = %s",
name, typeName);
1993 if (stack->fIsPostProcessed)
1998 if (!elem && !obj_cl)
2001 stack->fIsPostProcessed =
kTRUE;
2004 if (stack->fIsObjStarted) {
2025 isTArray = (strncmp(
"TArray", typname, 6) == 0);
2028 if (isTString || isSTLstring) {
2032 Info(
"PerformPostProcessing",
"reformat string value = '%s'",
fValue.
Data());
2034 stack->fValues.Delete();
2035 }
else if (isOffsetPArray) {
2038 if ((stack->fValues.GetLast() < 0) && (
fValue ==
"0")) {
2040 }
else if ((stack->fValues.GetLast() == 0) && (strcmp(stack->fValues.Last()->GetName(),
"1") == 0)) {
2041 stack->fValues.Delete();
2043 Error(
"PerformPostProcessing",
"Wrong values for kOffsetP element %s", (elem ? elem->
GetName() :
"---"));
2044 stack->fValues.Delete();
2047 }
else if (isTObject || isTRef) {
2052 Int_t cnt = stack->fValues.GetLast() + 1;
2056 if (cnt < 2 || cnt > 3) {
2058 Error(
"PerformPostProcessing",
"When storing TObject/TRef, strange number of items %d",
cnt);
2074 stack->fValues.Delete();
2079 }
else if (isTArray) {
2081 stack->fValues.Delete();
2089 if (stack->fValues.GetLast() >= 0) {
2092 for (
Int_t n = 0;
n <= stack->fValues.GetLast();
n++) {
2105 if (stack->fValues.GetLast() >= 0)
2136 if (!cl &&
Stack()->fClVersion) {
2137 res =
Stack()->fClVersion;
2138 Stack()->fClVersion = 0;
2142 Info(
"ReadVersion",
"Result: %d Class: %s", res, (cl ? cl->
GetName() :
"---"));
2161 Info(
"ReadObjectAny",
"From current JSON node");
2179 Info(
"WriteObjectClass",
"Class %s", (actualClass ? actualClass->
GetName() :
" null"));
2300template <
typename T>
2303 Info(
"ReadArray",
"Not implemented");
2304 return value ? 1 : 0;
2414template <
typename T>
2417 if (!arr || (arrsize <= 0))
2421 Info(
"ReadFastArray",
"Reading array sz %d from JSON %s", arrsize,
json->dump().substr(0, 30).c_str());
2422 TArrayIndexProducer *indexes =
Stack()->MakeReadIndexes();
2424 TArrayI &indx = indexes->GetIndices();
2426 if (indexes->TotalLength() != arrsize)
2427 Error(
"ReadFastArray",
"Mismatch %d-dim array sizes %d %d", lastdim + 1, arrsize, (
int)indexes->TotalLength());
2428 for (
int cnt = 0;
cnt < arrsize; ++
cnt) {
2430 for (
int k = 1; k < lastdim; ++k)
2431 elem = &((*elem)[indx[k]]);
2432 arr[
cnt] = asstring ? elem->
get<std::string>()[indx[lastdim]] : (*elem)[indx[lastdim]].
get<
T>();
2433 indexes->NextSeparator();
2436 }
else if (asstring) {
2437 std::string str =
json->get<std::string>();
2439 arr[
cnt] = (
cnt < (
int)str.length()) ? str[
cnt] : 0;
2440 }
else if (
json->is_object() && (
json->count(
"$arr") == 1)) {
2441 if (
json->at(
"len").get<
int>() != arrsize)
2442 Error(
"ReadFastArray",
"Mismatch compressed array size %d %d", arrsize,
json->at(
"len").get<
int>());
2446 std::string
idname =
"", pname, vname, nname;
2447 while (p < arrsize) {
2448 pname = std::string(
"p") +
idname;
2449 if (
json->count(pname) == 1)
2450 p =
json->at(pname).get<
int>();
2451 vname = std::string(
"v") +
idname;
2452 if (
json->count(vname) != 1)
2456 for (
unsigned sub = 0; sub <
v.size(); ++sub)
2457 arr[p++] =
v[sub].get<T>();
2459 nname = std::string(
"n") +
idname;
2460 unsigned ncopy = (
json->count(nname) == 1) ?
json->at(nname).get<
unsigned>() : 1;
2461 for (
unsigned sub = 0; sub < ncopy; ++sub)
2462 arr[p++] =
v.get<
T>();
2464 idname = std::to_string(++
id);
2467 if ((
int)
json->size() != arrsize)
2468 Error(
"ReadFastArray",
"Mismatch array sizes %d %d", arrsize, (
int)
json->size());
2596 Info(
"ReadFastArray",
"void* n:%d cl:%s",
n, cl->
GetName());
2605 int objectSize = cl->
Size();
2606 char *obj = (
char *)start;
2608 TJSONStackObj *stack =
Stack();
2611 subnode = stack->fIndx->ExtractNode(topnode);
2613 TArrayIndexProducer indexes(stack->fElem,
n,
"");
2616 Info(
"ReadFastArray",
"Indexes ndim:%d totallen:%d", indexes.NumDimensions(), indexes.TotalLength());
2618 for (
Int_t j = 0; j <
n; j++, obj += objectSize) {
2620 stack->fNode = indexes.ExtractNode(subnode);
2626 stack->fNode = topnode;
2636 Info(
"ReadFastArray",
"void** n:%d cl:%s prealloc:%s",
n, cl->
GetName(), (isPreAlloc ?
"true" :
"false"));
2651 TJSONStackObj *stack =
Stack();
2654 subnode = stack->fIndx->ExtractNode(topnode);
2656 TArrayIndexProducer indexes(stack->fElem,
n,
"");
2658 for (
Int_t j = 0; j <
n; j++) {
2660 stack->fNode = indexes.ExtractNode(subnode);
2663 void *old = start[j];
2669 start[j] = ((
TClass *)cl)->New();
2674 stack->fNode = topnode;
2677template <
typename T>
2680 if ((
fCompact < 10) || (arrsize < 6)) {
2682 for (
Int_t indx = 0; indx < arrsize; indx++) {
2691 Int_t aindx(0), bindx(arrsize);
2692 while ((aindx < arrsize) && (vname[aindx] == 0))
2694 while ((aindx < bindx) && (vname[bindx - 1] == 0))
2696 if (aindx < bindx) {
2698 Int_t p(aindx), suffixcnt(-1), lastp(0);
2700 if (vname[p] == 0) {
2704 Int_t p0(p++), pp(0), nsame(1);
2710 for (; p <= bindx; ++p) {
2711 if ((p < bindx) && (vname[p] == vname[p - 1])) {
2715 if (vname[p - 1] == 0) {
2720 }
else if (nsame > 5) {
2733 if (++suffixcnt > 0)
2734 suffix.
Form(
"%d", suffixcnt);
2739 if ((nsame > 1) || (pp - p0 == 1)) {
2745 for (
Int_t indx = p0; indx < pp; indx++) {
2880template <
typename T>
2905 (*this.*method)((arr + shift), len, typname);
2911 (*this.*method)(arr, arrsize, typname);
3033 Info(
"WriteFastArray",
"void *start cl:%s n:%d", cl ? cl->
GetName() :
"---",
n);
3047 char *obj = (
char *)start;
3050 int size = cl->
Size();
3054 if (indexes.IsArray()) {
3059 for (
Int_t j = 0; j <
n; j++, obj += size) {
3072 if (indexes.IsArray())
3087 Info(
"WriteFastArray",
"void **startp cl:%s n:%d", cl->
GetName(),
n);
3102 if (indexes.IsArray()) {
3107 for (
Int_t j = 0; j <
n; j++) {
3116 start[j] = ((
TClass *)cl)->New();
3127 if (indexes.IsArray())
3142 Info(
"StreamObject",
"Class: %s", (cl ? cl->
GetName() :
"none"));
3153template <
typename T>
3156 value =
Stack()->GetStlNode()->get<
T>();
3208 val =
Stack()->PopIntValue();
3259 if (
json->is_null())
3260 val = std::numeric_limits<Float_t>::quiet_NaN();
3271 if (
json->is_null())
3272 val = std::numeric_limits<Double_t>::quiet_NaN();
3282 Error(
"ReadCharP",
"Not implemented");
3316 std::size_t nch = str.length();
3318 s =
new char[nch + 1];
3319 memcpy(
s, str.c_str(), nch);
3490 snprintf(buf,
sizeof(buf),
"%d", value);
3500 snprintf(buf,
sizeof(buf),
"%hd", value);
3510 snprintf(buf,
sizeof(buf),
"%d", value);
3520 snprintf(buf,
sizeof(buf),
"%ld", value);
3537 if (std::isinf(value)) {
3553 if (std::isinf(value)) {
3578 snprintf(buf,
sizeof(buf),
"%u", value);
3588 snprintf(buf,
sizeof(buf),
"%hu", value);
3598 snprintf(buf,
sizeof(buf),
"%u", value);
3608 snprintf(buf,
sizeof(buf),
"%lu", value);
3634 len = strlen(value);
3650 if ((
c > 31) && (
c < 127))
static RooMathCoreReg dummy
unsigned long long ULong64_t
void Error(const char *location, const char *msgfmt,...)
char * Form(const char *fmt,...)
Array of integers (32 bits per element).
void Set(Int_t n)
Set size of this array to n ints.
Abstract array base class.
virtual void GetMappedObject(UInt_t tag, void *&ptr, TClass *&ClassPtr) const
Retrieve the object stored in the buffer's object map at 'tag' Set ptr and ClassPtr respectively to t...
virtual void MapObject(const TObject *obj, UInt_t offset=1)
Add object to the fMap container.
Long64_t GetObjectTag(const void *obj)
Returns tag for specified object from objects map (if exists) Returns 0 if object not included into o...
virtual Int_t WriteObjectAny(const void *obj, const TClass *ptrClass, Bool_t cacheReuse=kTRUE)
Write object to I/O buffer.
virtual void InitMap()
Create the fMap container and initialize them with the null object.
Class for serializing object to and from JavaScript Object Notation (JSON) format.
virtual void WriteLong64(Long64_t l)
Writes Long64_t value to buffer.
R__ALWAYS_INLINE void JsonWriteArrayCompress(const T *vname, Int_t arrsize, const char *typname)
virtual TClass * ReadClass(const TClass *cl=nullptr, UInt_t *objTag=nullptr)
suppressed function of TBuffer
void JsonWriteBasic(Char_t value)
converts Char_t to string and add to json value buffer
void JsonWriteCollection(TCollection *obj, const TClass *objClass)
store content of ROOT collection
virtual void WriteStdString(const std::string *s)
Writes a std::string.
TString fSemicolon
! depending from compression level, " : " or ":"
Int_t fCompact
! 0 - no any compression, 1 - no spaces in the begin, 2 - no new lines, 3 - no spaces at all
virtual void WriteUShort(UShort_t s)
Writes UShort_t value to buffer.
virtual void WriteUInt(UInt_t i)
Writes UInt_t value to buffer.
virtual Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)
read version value from buffer
void JsonStartElement(const TStreamerElement *elem, const TClass *base_class=nullptr)
Start new class member in JSON structures.
static TObject * ConvertFromJSON(const char *str)
Read TObject-based class from JSON, produced by ConvertToJSON() method.
virtual void ReadLong(Long_t &l)
Reads Long_t value from buffer.
TString fValue
! buffer for current value
std::deque< TJSONStackObj * > fStack
! hierarchy of currently streamed element
virtual void WriteChar(Char_t c)
Writes Char_t value to buffer.
virtual void ClassBegin(const TClass *, Version_t=-1)
Should be called in the beginning of custom class streamer.
virtual void WriteDouble(Double_t d)
Writes Double_t value to buffer.
static TString ConvertToJSON(const TObject *obj, Int_t compact=0, const char *member_name=nullptr)
Converts object, inherited from TObject class, to JSON string Lower digit of compact parameter define...
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)
Ignored in TBufferJSON.
void PerformPostProcessing(TJSONStackObj *stack, const TClass *obj_cl=nullptr)
Function is converts TObject and TString structures to more compact representation.
virtual void ReadUInt(UInt_t &i)
Reads UInt_t value from buffer.
virtual void WriteInt(Int_t i)
Writes Int_t value to buffer.
virtual void ReadFastArrayString(Char_t *c, Int_t n)
read array of Char_t from buffer
virtual void ReadShort(Short_t &s)
Reads Short_t value from buffer.
static Int_t ExportToFile(const char *filename, const TObject *obj, const char *option=nullptr)
Convert object into JSON and store in text file Returns size of the produce file Used in TObject::Sav...
R__ALWAYS_INLINE Int_t JsonReadArray(T *value)
Read static array from JSON - not used.
TString fNumericLocale
! stored value of setlocale(LC_NUMERIC), which should be recovered at the end
virtual Int_t ReadArray(Bool_t *&b)
Read array of Bool_t from buffer.
TJSONStackObj * PushStack(Int_t inclevel=0, void *readnode=nullptr)
add new level to the structures stack
TBufferJSON(TBuffer::EMode mode=TBuffer::kWrite)
Creates buffer object to serialize data into json.
void JsonDisablePostprocessing()
disable post-processing of the code
void WorkWithElement(TStreamerElement *elem, Int_t)
This is call-back from streamer which indicates that class member will be streamed Name of element us...
virtual void ReadDouble(Double_t &d)
Reads Double_t value from buffer.
virtual void ReadLong64(Long64_t &l)
Reads Long64_t value from buffer.
unsigned fJsonrCnt
! counter for all objects, used for referencing
void JsonReadCollection(TCollection *obj, const TClass *objClass)
read content of ROOT collection
virtual void ReadStdString(std::string *s)
Reads a std::string.
virtual ~TBufferJSON()
destroy buffer
virtual void ReadUChar(UChar_t &c)
Reads UChar_t value from buffer.
void JsonPushValue()
If value exists, push in the current stack for post-processing.
virtual void ReadCharP(Char_t *c)
Reads array of characters from buffer.
virtual void ReadFastArray(Bool_t *b, Int_t n)
read array of Bool_t from buffer
virtual void ReadULong64(ULong64_t &l)
Reads ULong64_t value from buffer.
virtual void ReadInt(Int_t &i)
Reads Int_t value from buffer.
virtual void WriteULong64(ULong64_t l)
Writes ULong64_t value to buffer.
virtual void WriteTString(const TString &s)
Writes a TString.
virtual void WriteUChar(UChar_t c)
Writes UChar_t value to buffer.
virtual void WriteClass(const TClass *cl)
suppressed function of TBuffer
virtual void ReadBool(Bool_t &b)
Reads Bool_t value from buffer.
TString * fOutput
! current output buffer for json code
virtual void StreamObject(void *obj, const TClass *cl, const TClass *onFileClass=nullptr)
stream object to/from buffer
static void * ConvertFromJSONAny(const char *str, TClass **cl=nullptr)
Read object from JSON, produced by ConvertToJSON() method.
virtual void ReadUShort(UShort_t &s)
Reads UShort_t value from buffer.
R__ALWAYS_INLINE void JsonWriteFastArray(const T *arr, Int_t arrsize, const char *typname, void(TBufferJSON::*method)(const T *, Int_t, const char *))
Template method to write array of arbitrary dimensions Different methods can be used for store last a...
virtual void ClassEnd(const TClass *)
Should be called at the end of custom streamer See TBufferJSON::ClassBegin for more details.
virtual void ReadBaseClass(void *start, TStreamerBase *elem)
Read data of base class.
virtual void ReadTString(TString &s)
Reads a TString.
static void * ConvertFromJSONChecked(const char *str, const TClass *expectedClass)
Read objects from JSON, one can reuse existing object.
virtual void WriteCharStar(char *s)
Writes a char*.
virtual void WriteULong(ULong_t l)
Writes ULong_t value to buffer.
virtual void WriteBool(Bool_t b)
Writes Bool_t value to buffer.
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 ClassMember(const char *name, const char *typeName=nullptr, 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...
virtual void ReadChar(Char_t &c)
Reads Char_t value from buffer.
TString fArraySepar
! depending from compression level, ", " or ","
R__ALWAYS_INLINE void JsonReadFastArray(T *arr, Int_t arrsize, bool asstring=false)
Template method to read array from the JSON.
virtual void DecrementLevel(TVirtualStreamerInfo *)
Function is called from TStreamerInfo WriteBuffer and ReadBuffer functions and decrease level in json...
virtual void WriteCharP(const Char_t *c)
Writes array of characters to buffer.
virtual void WriteFastArray(const Bool_t *b, Int_t n)
Write array of Bool_t to buffer.
virtual void WriteFastArrayString(const Char_t *c, Int_t n)
Write array of Char_t to buffer.
void AppendOutput(const char *line0, const char *line1=nullptr)
Append two string to the output JSON, normally separate by line break.
TString fOutBuffer
! main output buffer for json code
TJSONStackObj * PopStack()
remove one level from stack
virtual void WriteArray(const Bool_t *b, Int_t n)
Write array of Bool_t to buffer.
virtual void ReadFloat(Float_t &f)
Reads Float_t value from buffer.
virtual void ReadCharStar(char *&s)
Reads a char* string.
virtual void ReadULong(ULong_t &l)
Reads ULong_t value from buffer.
Int_t JsonSpecialClass(const TClass *cl) const
return non-zero value when class has special handling in JSON it is TCollection (-130),...
virtual Int_t ReadStaticArray(Bool_t *b)
Read array of Bool_t from buffer.
virtual void WriteObjectClass(const void *actualObjStart, const TClass *actualClass, Bool_t cacheReuse)
Write object to buffer. Only used from TBuffer.
void SetCompact(int level)
virtual void WriteShort(Short_t s)
Writes Short_t value to buffer.
virtual void * ReadObjectAny(const TClass *clCast)
Read object from buffer. Only used from TBuffer.
void JsonWriteConstChar(const char *value, Int_t len=-1, const char *=nullptr)
writes string value, processing all kind of special characters
virtual void IncrementLevel(TVirtualStreamerInfo *)
Function is called from TStreamerInfo WriteBuffer and ReadBuffer functions and indent new level in js...
void JsonReadTObjectMembers(TObject *obj, void *node=nullptr)
virtual TVirtualStreamerInfo * GetInfo()
Return current streamer info element.
virtual void SetStreamerElementNumber(TStreamerElement *elem, Int_t comp_type)
Function is called from TStreamerInfo WriteBuffer and ReadBuffer functions and add/verify next elemen...
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 SkipObjectAny()
Skip any kind of object from buffer.
void * JsonReadObject(void *obj, const TClass *objClass=nullptr, TClass **readClass=nullptr)
Read object from current JSON node.
void WorkWithClass(TStreamerInfo *info, const TClass *cl=nullptr)
Prepares buffer to stream data of specified class.
virtual void WriteFloat(Float_t f)
Writes Float_t value to buffer.
R__ALWAYS_INLINE void JsonReadBasic(T &value)
Template function to read basic value from JSON.
virtual void WriteLong(Long_t l)
Writes Long_t value to buffer.
Base class for text-based streamers like TBufferJSON or TBufferXML Special actions list will use meth...
static const char * ConvertFloat(Float_t v, char *buf, unsigned len, Bool_t not_optimize=kFALSE)
convert float to string with configured format
static const char * ConvertDouble(Double_t v, char *buf, unsigned len, Bool_t not_optimize=kFALSE)
convert float to string with configured format
virtual void ReadBaseClass(void *start, TStreamerBase *elem)
Read data of base class.
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.
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
void Destructor(void *obj, Bool_t dtorOnly=kFALSE)
Explicitly call destructor for object.
TList * GetListOfRealData() const
Int_t Size() const
Return size of object of this class.
Bool_t IsTObject() const
Return kTRUE is the class inherits from TObject.
Int_t GetBaseClassOffset(const TClass *toBase, void *address=0, bool isDerivedObject=true)
void Streamer(void *obj, TBuffer &b, const TClass *onfile_class=0) const
Version_t GetClassVersion() const
TClass * GetActualClass(const void *object) const
Return a pointer the the real class of the object.
TRealData * GetRealData(const char *name) const
Return pointer to TRealData element with name "name".
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.
An array of clone (identical) objects.
TClass * GetClass() const
void SetClass(const char *classname, Int_t size=1000)
see TClonesArray::SetClass(const TClass*)
TObject * ConstructedAt(Int_t idx)
Get an object at index 'idx' that is guaranteed to have been constructed.
Collection abstract base class.
virtual const char * GetName() const
Return name of this collection.
void SetName(const char *name)
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual void Add(TObject *obj)=0
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
All ROOT classes may have RTTI (run time type identification) support added.
Int_t GetMaxIndex(Int_t dim) const
Return maximum index for array dimension "dim".
const char * GetTrueTypeName() const
Get full type description of data member, e,g.: "class TDirectory*".
Int_t GetArrayDim() const
Return number of array dimensions.
Int_t GetUnitSize() const
Get the sizeof the underlying type of the data member (i.e.
Bool_t IsBasic() const
Return true if data member is a basic type, e.g. char, int, long...
Int_t IsSTLContainer()
The return type is defined in TDictionary (kVector, kList, etc.)
Bool_t IsaPointer() const
Return true if data member is a pointer.
TDataType * GetDataType() const
const char * GetTypeName() const
Get type of data member, e,g.: "class TDirectory*" -> "TDirectory".
const char * GetArrayIndex() const
If the data member is pointer and has a valid array size in its comments GetArrayIndex returns a stri...
Basic data type descriptor (datatype information is obtained from CINT).
Option_t * GetOption() const
virtual void Add(TObject *obj)
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
void Add(TObject *obj)
This function may not be used (but we need to provide it since it is a pure virtual in TCollection).
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
virtual const char * GetName() const
Returns name of object.
Int_t IndexOf(const TObject *obj) const
TObject * Last() const
Return the object in the last filled slot. Returns 0 if no entries.
Int_t GetLast() const
Return index of last object in array.
virtual TObject * Remove(TObject *obj)
Remove object from array.
Collectable string class.
Mother of all ROOT objects.
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
@ kMustCleanup
if object destructor must call RecursiveRemove()
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
The TRealData class manages the effective list of all data members for a given class.
TDataMember * GetDataMember() const
Long_t GetThisOffset() const
virtual TClass * GetClassPointer() const
Returns a pointer to the TClass of this element.
virtual TClass * GetClassPointer() const
Returns a pointer to the TClass of this element.
virtual void SetArrayDim(Int_t dim)
Set number of array dimensions.
Int_t GetArrayDim() const
Int_t GetArrayLength() const
Int_t GetMaxIndex(Int_t i) const
const char * GetTypeName() const
virtual Bool_t IsBase() const
Return kTRUE if the element represent a base class.
virtual void SetMaxIndex(Int_t dim, Int_t max)
set maximum index for array with dimension dim
Describe Streamer information for one class version.
TObjArray * GetElements() const
TClass * GetClass() const
Int_t Atoi() const
Return integer value of string.
void Clear()
Clear string without changing its capacity.
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
const char * Data() const
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
TString & Append(const char *cs)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
static TString Itoa(Int_t value, Int_t base)
Converts an Int_t to a TString with respect to the base specified (2-36).
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Abstract Interface class describing Streamer information for one class.
static Bool_t CanDelete()
static function returning true if ReadBuffer can delete object
virtual TClass * GetClass() const =0
a class to store JSON values
size_type size() const noexcept
returns the number of elements
constexpr bool is_string() const noexcept
return whether value is a string
basic_json get() const
get special-case overload
reference at(size_type idx)
access specified array element with bounds checking
static basic_json parse(T(&array)[N], const parser_callback_t cb=nullptr)
deserialize from an array
constexpr bool is_null() const noexcept
return whether value is null
constexpr bool is_array() const noexcept
return whether value is an array
constexpr bool is_object() const noexcept
return whether value is an object
bool IsStdClass(const char *type)
return true if the class belongs to the std namespace
static constexpr double s
basic_json<> json
default JSON class