89 class 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)
224 while ((cnt >= 0) && (cnt < fIndicies.
GetSize())) {
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]]);
255 class 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);
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);
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();
1164 if (stack->fValues.GetLast() < 0) {
1167 Error(
"JsonWriteObject",
"With empty stack fValue!=0");
1171 Int_t size =
TString(stack->fValues.At(0)->GetName()).Atoi();
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(
"multimap<") == 0)
1197 pairtype.
Replace(0, 9,
"pair<");
1198 else if (pairtype.
Index(
"map<") == 0)
1199 pairtype.
Replace(0, 4,
"pair<");
1203 for (
Int_t k = 1; k < stack->fValues.GetLast(); k += 2) {
1223 for (
Int_t k = 1; k <= stack->fValues.GetLast(); k++) {
1231 stack->fValues.Delete();
1239 if ((special_kind == 0) && ((stack->fValues.GetLast() >= 0) || (
fValue.
Length() > 0))) {
1241 Info(
"JsonWriteObject",
"Create blob value for class %s", cl->
GetName());
1246 const char *separ =
"[";
1248 for (
Int_t k = 0; k <= stack->fValues.GetLast(); k++) {
1262 stack->fValues.Delete();
1267 if (special_kind <= 0) {
1276 if ((special_kind <= 0) || (special_kind >
json_TArray))
1278 else if (fObjectOutput.
Length() != 0)
1279 Error(
"JsonWriteObject",
"Non-empty object output for special class %s", cl->
GetName());
1299 TMap *map =
nullptr;
1301 map = dynamic_cast<TMap *>(col);
1312 while ((obj = iter()) !=
nullptr) {
1364 TList *lst =
nullptr;
1365 TMap *map =
nullptr;
1368 lst = dynamic_cast<TList *>(col);
1370 map = dynamic_cast<TMap *>(col);
1372 clones = dynamic_cast<TClonesArray *>(col);
1376 std::string
name = json->
at(
"name");
1380 int size = arr.
size();
1382 for (
int n = 0;
n < size; ++
n) {
1386 subelem = &subelem->
at(
"first");
1390 TClass *readClass =
nullptr, *objClass =
nullptr;
1391 void *subobj =
nullptr;
1396 clones->
SetClass(subelem->
at(
"_typename").
get<std::string>().c_str(), size);
1397 }
else if (size > clones->
GetSize()) {
1398 Error(
"JsonReadCollection",
"TClonesArray size %d smaller than required %d\n", clones->
GetSize(), size);
1413 if (!subobj || !readClass) {
1416 Error(
"JsonReadCollection",
"Try to add object %s not derived from TObject", readClass->
GetName());
1425 readClass =
nullptr;
1430 if (!subobj2 || !readClass) {
1432 }
else if (readClass->GetBaseClassOffset(
TObject::Class()) != 0) {
1433 Error(
"JsonReadCollection",
"Try to add object %s not derived from TObject", readClass->GetName());
1437 map->
Add(tobj, static_cast<TObject *>(subobj2));
1439 std::string opt = json->
at(
"opt").
at(
n).
get<std::string>();
1440 lst->
Add(tobj, opt.c_str());
1454 *readClass =
nullptr;
1456 TJSONStackObj *stack =
Stack();
1458 Bool_t process_stl = stack->IsStl();
1469 unsigned refid = json->
at(
"$ref").
get<
unsigned>();
1471 void *ref_obj =
nullptr;
1472 TClass *ref_cl =
nullptr;
1476 if (!ref_obj || !ref_cl) {
1477 Error(
"JsonReadObject",
"Fail to find object for reference %u", refid);
1482 *readClass = ref_cl;
1485 Info(
"JsonReadObject",
"Extract object reference %u %p cl:%s expects:%s", refid, ref_obj, ref_cl->
GetName(),
1486 (objClass ? objClass->
GetName() :
"---"));
1494 obj = objClass->
New();
1497 Info(
"JsonReadObject",
"Read string from %s", json->
dump().c_str());
1500 *((std::string *)obj) = json->
get<std::string>();
1502 *((
TString *)obj) = json->
get<std::string>().c_str();
1505 *readClass = (
TClass *)objClass;
1510 Bool_t isBase = (stack->fElem && objClass) ? stack->fElem->IsBase() :
kFALSE;
1512 if (isBase && (!obj || !objClass)) {
1513 Error(
"JsonReadObject",
"No object when reading base class");
1522 TClass *jsonClass =
nullptr;
1526 jsonClass = (
TClass *)objClass;
1529 obj = jsonClass->
New();
1531 Int_t len = stack->IsJsonArray(json);
1533 stack->PushIntValue(len > 0 ? len : 0);
1536 Error(
"JsonReadObject",
"Not array when expecting such %s", json->
dump().c_str());
1539 Info(
"JsonReadObject",
"Reading special kind %d %s ptr %p", special_kind, objClass->
GetName(), obj);
1541 }
else if (isBase) {
1544 jsonClass = (
TClass *)objClass;
1547 Info(
"JsonReadObject",
"Reading baseclass %s ptr %p", objClass->
GetName(), obj);
1550 std::string clname = json->
at(
"_typename").
get<std::string>();
1555 Error(
"JsonReadObject",
"Cannot find class %s", clname.c_str());
1561 if (objClass && (jsonClass != objClass)) {
1562 Error(
"JsonReadObject",
"Class mismatch between provided %s and in JSON %s", objClass->
GetName(),
1563 jsonClass->GetName());
1567 obj = jsonClass->New();
1570 Info(
"JsonReadObject",
"Reading object of class %s refid %u ptr %p", clname.c_str(),
fJsonrCnt, obj);
1596 stack->fStlIndx = 0;
1606 Info(
"JsonReadObject",
"Calling streamer of class %s", jsonClass->
GetName());
1608 if (isBase && (special_kind == 0))
1609 Error(
"JsonReadObject",
"Should not be used for reading of base class %s", jsonClass->
GetName());
1611 jsonClass->
Streamer((
void *)obj, *
this);
1613 stack->fClVersion = 0;
1615 stack->fStlIndx = -1;
1616 stack->fStlMap = -1;
1624 Info(
"JsonReadObject",
"Reading object of class %s done", jsonClass->
GetName());
1627 *readClass = jsonClass;
1636 UInt_t uid = json->
at(
"fUniqueID").
get<
unsigned>();
1642 for (
unsigned n = 0;
n < 32;
n++)
1646 Info(
"JsonReadTObjectMembers",
"Reading TObject part bits %u kMustCleanup %d", bits, tobj->
TestBit(
kMustCleanup));
1675 Info(
"WorkWithClass",
"Class: %s", cl->
GetName());
1677 TJSONStackObj *stack =
Stack();
1681 }
else if (stack && stack->IsStreamerElement() && !stack->fIsObjStarted &&
1685 stack->fIsObjStarted =
kTRUE;
1699 stack->fInfo = sinfo;
1700 stack->fIsStreamerInfo =
kTRUE;
1712 TJSONStackObj *stack =
Stack();
1714 if (stack->IsStreamerElement()) {
1718 Info(
"DecrementLevel",
" Perform post-processing elem: %s", stack->fElem->GetName());
1727 Error(
"DecrementLevel",
" Mismatch of streamer info");
1732 Info(
"DecrementLevel",
"Class: %s done", (info ? info->
GetClass()->
GetName() :
"custom"));
1740 return Stack()->fInfo;
1751 Info(
"SetStreamerElementNumber",
"Element name %s", elem->
GetName());
1763 TJSONStackObj *stack =
Stack();
1765 Error(
"WorkWithElement",
"stack is empty");
1770 Info(
"WorkWithElement",
" Start element %s type %d typename %s", elem ? elem->
GetName() :
"---",
1773 if (stack->IsStreamerElement()) {
1778 Info(
"WorkWithElement",
" Perform post-processing elem: %s", stack->fElem->GetName());
1788 Error(
"WorkWithElement",
"Lost of stack");
1793 if (!stack->IsStreamerInfo()) {
1794 Error(
"WorkWithElement",
"Problem in Inc/Dec level");
1801 Error(
"WorkWithElement",
"streamer info returns elem = 0");
1809 stack->fIsElemOwner = (number < 0);
1826 stack->PushIntValue(stack->IsJsonString() || (stack->IsJsonArray() > 0) ? 1 : 0);
1896 if (!name || (strlen(name) == 0)) {
1897 Error(
"ClassMember",
"Invalid member name");
1905 if (strcmp(typeName,
"raw:data") == 0)
1915 if (strcmp(name, typeName) == 0) {
1923 if (tname[tname.
Length() - 1] ==
'*') {
1929 Error(
"ClassMember",
"Invalid class specifier %s", typeName);
1953 }
else if ((typ_id > 0) && (typ_id < 20)) {
1969 Error(
"ClassMember",
"Invalid combination name = %s type = %s", name, typeName);
1989 if (stack->fIsPostProcessed)
1994 if (!elem && !obj_cl)
1997 stack->fIsPostProcessed =
kTRUE;
2000 if (stack->fIsObjStarted) {
2021 isTArray = (strncmp(
"TArray", typname, 6) == 0);
2024 if (isTString || isSTLstring) {
2028 Info(
"PerformPostProcessing",
"reformat string value = '%s'",
fValue.
Data());
2030 stack->fValues.Delete();
2031 }
else if (isOffsetPArray) {
2034 if ((stack->fValues.GetLast() < 0) && (
fValue ==
"0")) {
2036 }
else if ((stack->fValues.GetLast() == 0) && (strcmp(stack->fValues.Last()->GetName(),
"1") == 0)) {
2037 stack->fValues.Delete();
2039 Error(
"PerformPostProcessing",
"Wrong values for kOffsetP element %s", (elem ? elem->
GetName() :
"---"));
2040 stack->fValues.Delete();
2043 }
else if (isTObject || isTRef) {
2048 Int_t cnt = stack->fValues.GetLast() + 1;
2052 if (cnt < 2 || cnt > 3) {
2054 Error(
"PerformPostProcessing",
"When storing TObject/TRef, strange number of items %d", cnt);
2070 stack->fValues.Delete();
2075 }
else if (isTArray) {
2077 stack->fValues.Delete();
2085 if (stack->fValues.GetLast() >= 0) {
2088 for (
Int_t n = 0;
n <= stack->fValues.GetLast();
n++) {
2101 if (stack->fValues.GetLast() >= 0)
2132 if (!cl &&
Stack()->fClVersion) {
2133 res =
Stack()->fClVersion;
2134 Stack()->fClVersion = 0;
2138 Info(
"ReadVersion",
"Result: %d Class: %s", res, (cl ? cl->
GetName() :
"---"));
2157 Info(
"ReadObjectAny",
"From current JSON node");
2175 Info(
"WriteObjectClass",
"Class %s", (actualClass ? actualClass->
GetName() :
" null"));
2296 template <
typename T>
2299 Info(
"ReadArray",
"Not implemented");
2300 return value ? 1 : 0;
2410 template <
typename T>
2413 if (!arr || (arrsize <= 0))
2417 Info(
"ReadFastArray",
"Reading array sz %d from JSON %s", arrsize, json->
dump().substr(0, 30).c_str());
2418 TArrayIndexProducer *indexes =
Stack()->MakeReadIndexes();
2420 TArrayI &indx = indexes->GetIndices();
2422 if (indexes->TotalLength() != arrsize)
2423 Error(
"ReadFastArray",
"Mismatch %d-dim array sizes %d %d", lastdim + 1, arrsize, (
int)indexes->TotalLength());
2424 for (
int cnt = 0;
cnt < arrsize; ++
cnt) {
2426 for (
int k = 1; k < lastdim; ++k)
2427 elem = &((*elem)[indx[k]]);
2428 arr[
cnt] = asstring ? elem->
get<std::string>()[indx[lastdim]] : (*elem)[indx[lastdim]].
get<
T>();
2429 indexes->NextSeparator();
2432 }
else if (asstring) {
2433 std::string str = json->
get<std::string>();
2435 arr[
cnt] = (
cnt < (
int)str.length()) ? str[
cnt] : 0;
2437 if (json->
at(
"len").
get<
int>() != arrsize)
2438 Error(
"ReadFastArray",
"Mismatch compressed array size %d %d", arrsize, json->
at(
"len").
get<
int>());
2442 std::string
idname =
"", pname, vname, nname;
2443 while (p < arrsize) {
2444 pname = std::string(
"p") +
idname;
2445 if (json->
count(pname) == 1)
2446 p = json->
at(pname).
get<
int>();
2447 vname = std::string(
"v") +
idname;
2448 if (json->
count(vname) != 1)
2452 for (
unsigned sub = 0; sub < v.
size(); ++sub)
2453 arr[p++] = v[sub].get<T>();
2455 nname = std::string(
"n") +
idname;
2456 unsigned ncopy = (json->
count(nname) == 1) ? json->
at(nname).
get<
unsigned>() : 1;
2457 for (
unsigned sub = 0; sub < ncopy; ++sub)
2458 arr[p++] = v.
get<
T>();
2460 idname = std::to_string(++
id);
2463 if ((
int)json->
size() != arrsize)
2464 Error(
"ReadFastArray",
"Mismatch array sizes %d %d", arrsize, (
int)json->
size());
2592 Info(
"ReadFastArray",
"void* n:%d cl:%s", n, cl->
GetName());
2601 int objectSize = cl->
Size();
2602 char *obj = (
char *)start;
2604 TJSONStackObj *stack =
Stack();
2607 subnode = stack->fIndx->ExtractNode(topnode);
2609 TArrayIndexProducer indexes(stack->fElem, n,
"");
2612 Info(
"ReadFastArray",
"Indexes ndim:%d totallen:%d", indexes.NumDimensions(), indexes.TotalLength());
2614 for (
Int_t j = 0; j <
n; j++, obj += objectSize) {
2616 stack->fNode = indexes.ExtractNode(subnode);
2622 stack->fNode = topnode;
2632 Info(
"ReadFastArray",
"void** n:%d cl:%s prealloc:%s", n, cl->
GetName(), (isPreAlloc ?
"true" :
"false"));
2647 TJSONStackObj *stack =
Stack();
2650 subnode = stack->fIndx->ExtractNode(topnode);
2652 TArrayIndexProducer indexes(stack->fElem, n,
"");
2654 for (
Int_t j = 0; j <
n; j++) {
2656 stack->fNode = indexes.ExtractNode(subnode);
2659 void *old = start[j];
2665 start[j] = ((
TClass *)cl)->New();
2670 stack->fNode = topnode;
2673 template <
typename T>
2676 if ((
fCompact < 10) || (arrsize < 6)) {
2678 for (
Int_t indx = 0; indx < arrsize; indx++) {
2687 Int_t aindx(0), bindx(arrsize);
2688 while ((aindx < arrsize) && (vname[aindx] == 0))
2690 while ((aindx < bindx) && (vname[bindx - 1] == 0))
2692 if (aindx < bindx) {
2694 Int_t p(aindx), suffixcnt(-1), lastp(0);
2696 if (vname[p] == 0) {
2700 Int_t p0(p++), pp(0), nsame(1);
2706 for (; p <= bindx; ++p) {
2707 if ((p < bindx) && (vname[p] == vname[p - 1])) {
2711 if (vname[p - 1] == 0) {
2716 }
else if (nsame > 5) {
2729 if (++suffixcnt > 0)
2730 suffix.
Form(
"%d", suffixcnt);
2735 if ((nsame > 1) || (pp - p0 == 1)) {
2741 for (
Int_t indx = p0; indx < pp; indx++) {
2876 template <
typename T>
2900 if (++cnt == indexes.GetSize()) {
2901 (*this.*method)((arr + shift), len, typname);
2907 (*this.*method)(arr, arrsize, typname);
3029 Info(
"WriteFastArray",
"void *start cl:%s n:%d", cl ? cl->
GetName() :
"---",
n);
3043 char *obj = (
char *)start;
3046 int size = cl->
Size();
3050 if (indexes.IsArray()) {
3055 for (
Int_t j = 0; j <
n; j++, obj += size) {
3068 if (indexes.IsArray())
3083 Info(
"WriteFastArray",
"void **startp cl:%s n:%d", cl->
GetName(),
n);
3098 if (indexes.IsArray()) {
3103 for (
Int_t j = 0; j <
n; j++) {
3112 start[j] = ((
TClass *)cl)->New();
3123 if (indexes.IsArray())
3138 Info(
"StreamObject",
"Class: %s", (cl ? cl->
GetName() :
"none"));
3149 template <
typename T>
3152 value =
Stack()->GetStlNode()->get<
T>();
3168 if (
Stack()->fValues.GetLast() >= 0)
3203 if (
Stack()->fValues.GetLast() >= 0)
3204 val =
Stack()->PopIntValue();
3256 val = std::numeric_limits<Float_t>::quiet_NaN();
3268 val = std::numeric_limits<Double_t>::quiet_NaN();
3278 Error(
"ReadCharP",
"Not implemented");
3312 std::size_t nch = str.length();
3314 s =
new char[nch + 1];
3315 memcpy(s, str.c_str(), nch);
3486 snprintf(buf,
sizeof(buf),
"%d", value);
3496 snprintf(buf,
sizeof(buf),
"%hd", value);
3506 snprintf(buf,
sizeof(buf),
"%d", value);
3516 snprintf(buf,
sizeof(buf),
"%ld", value);
3535 strcpy(buf,
"null");
3548 strcpy(buf,
"null");
3568 snprintf(buf,
sizeof(buf),
"%u", value);
3578 snprintf(buf,
sizeof(buf),
"%hu", value);
3588 snprintf(buf,
sizeof(buf),
"%u", value);
3598 snprintf(buf,
sizeof(buf),
"%lu", value);
3624 len = strlen(value);
3640 if ((c > 31) && (c < 127))
Abstract array base class.
Describe Streamer information for one class version.
void WorkWithClass(TStreamerInfo *info, const TClass *cl=nullptr)
Prepares buffer to stream data of specified class.
virtual const char * GetName() const
Returns name of object.
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)
Ignored in TBufferJSON.
static Bool_t CanDelete()
static function returning true if ReadBuffer can delete object
static const char * ConvertFloat(Float_t v, char *buf, unsigned len, Bool_t not_optimize=kFALSE)
convert float to string with configured format
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 Info(const char *method, const char *msgfmt,...) const
Issue info message.
static TString Itoa(Int_t value, Int_t base)
Converts an Int_t to a TString with respect to the base specified (2-36).
virtual Int_t ReadStaticArray(Bool_t *b)
Read array of Bool_t from buffer.
static TObject * ConvertFromJSON(const char *str)
Read TObject-based class from JSON, produced by ConvertToJSON() method.
virtual Int_t ReadArray(Bool_t *&b)
Read array of Bool_t from buffer.
void JsonDisablePostprocessing()
disable post-processing of the code
virtual void ReadShort(Short_t &s)
Reads Short_t value from buffer.
virtual void WriteLong64(Long64_t l)
Writes Long64_t value to buffer.
virtual TClass * GetClass() const =0
Collectable string class.
virtual void ReadFloat(Float_t &f)
Reads Float_t value from buffer.
All ROOT classes may have RTTI (run time type identification) support added.
TString fSemicolon
! depending from compression level, " : " or ":"
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.
R__ALWAYS_INLINE void JsonReadBasic(T &value)
Template function to read basic value from JSON.
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 ","
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.
a class to store JSON values
Int_t fCompact
! 0 - no any compression, 1 - no spaces in the begin, 2 - no new lines, 3 - no spaces at all ...
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.
void Add(TObject *obj)
This function may not be used (but we need to provide it since it is a pure virtual in TCollection)...
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
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
size_type count(typename object_t::key_type key) const
returns the number of occurrences of a key in a JSON object
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
R__ALWAYS_INLINE void JsonReadFastArray(T *arr, Int_t arrsize, bool asstring=false)
Template method to read array from the JSON.
virtual void InitMap()
Create the fMap container and initialize them with the null object.
iterator end() noexcept
returns an iterator to one past the last element
virtual void ReadLong(Long_t &l)
Reads Long_t value from buffer.
virtual void WriteLong(Long_t l)
Writes Long_t value to buffer.
Option_t * GetOption() const
virtual void SetArrayDim(Int_t dim)
Set number of array dimensions.
Int_t GetArrayDim() const
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...
virtual Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)
read version value from buffer
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.
constexpr bool is_object() const noexcept
return whether value is an object
virtual void WriteInt(Int_t i)
Writes Int_t value to buffer.
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
virtual TVirtualStreamerInfo * GetInfo()
Return current streamer info element.
virtual TClass * ReadClass(const TClass *cl=nullptr, UInt_t *objTag=nullptr)
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 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...
constexpr bool is_null() const noexcept
return whether value is null
TObject * ConstructedAt(Int_t idx)
Get an object at index 'idx' that is guaranteed to have been constructed.
TString fOutBuffer
! main output buffer for json code
reference at(size_type idx)
access specified array element with bounds checking
basic_json get() const
get special-case overload
virtual void ReadUShort(UShort_t &s)
Reads UShort_t value from buffer.
void Clear()
Clear string without changing its capacity.
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 ReadDouble(Double_t &d)
Reads Double_t value from buffer.
void JsonReadTObjectMembers(TObject *obj, void *node=nullptr)
void JsonWriteCollection(TCollection *obj, const TClass *objClass)
store content of ROOT collection
TString & Append(const char *cs)
Long_t GetThisOffset() const
static void * ConvertFromJSONChecked(const char *str, const TClass *expectedClass)
Read objects from JSON, one can reuse existing object.
unsigned fJsonrCnt
! counter for all objects, used for referencing
virtual void ReadCharStar(char *&s)
Reads a char* string.
TDataType * GetDataType() const
R__ALWAYS_INLINE void JsonWriteArrayCompress(const T *vname, Int_t arrsize, const char *typname)
virtual void ReadUChar(UChar_t &c)
Reads UChar_t value from buffer.
void Set(Int_t n)
Set size of this array to n ints.
size_type size() const noexcept
returns the number of elements
void Error(const char *location, const char *msgfmt,...)
void SetCompact(int level)
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Int_t GetMaxIndex(Int_t dim) const
Return maximum index for array dimension "dim".
TString fNumericLocale
! stored value of setlocale(LC_NUMERIC), which should be recovered at the end
virtual void ReadInt(Int_t &i)
Reads Int_t value from buffer.
TString fValue
! buffer for current value
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.
std::deque< TJSONStackObj * > fStack
! hierarchy of currently streamed element
virtual void IncrementLevel(TVirtualStreamerInfo *)
Function is called from TStreamerInfo WriteBuffer and ReadBuffer functions and indent new level in js...
virtual void WriteObjectClass(const void *actualObjStart, const TClass *actualClass, Bool_t cacheReuse)
Write object to buffer. Only used from TBuffer.
constexpr bool is_string() const noexcept
return whether value is a string
void SetClass(const char *classname, Int_t size=1000)
see TClonesArray::SetClass(const TClass*)
TClass * GetClass() const
virtual void ReadULong(ULong_t &l)
Reads ULong_t value from buffer.
virtual void MapObject(const TObject *obj, UInt_t offset=1)
Add object to the fMap container.
Basic data type descriptor (datatype information is obtained from CINT).
virtual Int_t WriteObjectAny(const void *obj, const TClass *ptrClass, Bool_t cacheReuse=kTRUE)
Write object to I/O buffer.
TClass * GetActualClass(const void *object) const
Return a pointer the the real class of the object.
virtual void ClassBegin(const TClass *, Version_t=-1)
Should be called in the beginning of custom class streamer.
TString * fOutput
! current 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 Destructor(void *obj, Bool_t dtorOnly=kFALSE)
Explicitly call destructor for object.
Int_t GetMaxIndex(Int_t i) const
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
char * Form(const char *fmt,...)
Int_t Size() const
Return size of object of this class.
void JsonWriteConstChar(const char *value, Int_t len=-1, const char *=nullptr)
writes string value, processing all kind of special characters
void AppendOutput(const char *line0, const char *line1=nullptr)
Append two string to the output JSON, normally separate by line break.
The TRealData class manages the effective list of all data members for a given 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...
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.
virtual void WriteUShort(UShort_t s)
Writes UShort_t value to buffer.
void WorkWithElement(TStreamerElement *elem, Int_t)
This is call-back from streamer which indicates that class member will be streamed Name of element us...
TJSONStackObj * PushStack(Int_t inclevel=0, void *readnode=nullptr)
add new level to the structures stack
void SetName(const char *name)
virtual void WriteBool(Bool_t b)
Writes Bool_t value to buffer.
bool IsStdClass(const char *type)
return true if the class belongs to the std namespace
void Streamer(void *obj, TBuffer &b, const TClass *onfile_class=0) const
virtual void ReadTString(TString &s)
Reads a TString.
if object destructor must call RecursiveRemove()
virtual void WriteFloat(Float_t f)
Writes Float_t value to buffer.
static const char * ConvertDouble(Double_t v, char *buf, unsigned len, Bool_t not_optimize=kFALSE)
convert float to string with configured format
static basic_json parse(T(&array)[N], const parser_callback_t cb=nullptr)
deserialize from an array
void * JsonReadObject(void *obj, const TClass *objClass=nullptr, TClass **readClass=nullptr)
Read object from current JSON node.
const char * GetTrueTypeName() const
Get full type description of data member, e,g.: "class TDirectory*".
Version_t GetClassVersion() const
void JsonPushValue()
If value exists, push in the current stack for post-processing.
virtual void WriteTString(const TString &s)
Writes a TString.
Base class for text-based streamers like TBufferJSON or TBufferXML Special actions list will use meth...
virtual void WriteShort(Short_t s)
Writes Short_t value to buffer.
Class for serializing object to and from JavaScript Object Notation (JSON) format.
virtual void WriteUInt(UInt_t i)
Writes UInt_t value to 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 WriteULong(ULong_t l)
Writes ULong_t value 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
static RooMathCoreReg dummy
virtual Bool_t IsBase() const
Return kTRUE if the element represent a base class.
virtual void * ReadObjectAny(const TClass *clCast)
Read object from buffer. Only used from TBuffer.
static constexpr double s
virtual void WriteCharStar(char *s)
Writes a char*.
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 Add(TObject *obj)=0
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.
constexpr bool is_array() const noexcept
return whether value is an array
virtual void StreamObject(void *obj, const TClass *cl, const TClass *onFileClass=nullptr)
stream object to/from buffer
virtual void ClassEnd(const TClass *)
Should be called at the end of custom streamer See TBufferJSON::ClassBegin for more details...
TClass * GetClass() const
void JsonStartElement(const TStreamerElement *elem, const TClass *base_class=nullptr)
Start new class member in JSON structures.
Mother of all ROOT objects.
TObjArray * GetElements() const
Int_t IsSTLContainer()
The return type is defined in TDictionary (kVector, kList, etc.)
TJSONStackObj * PopStack()
remove one level from stack
R__ALWAYS_INLINE Int_t JsonReadArray(T *value)
Read static array from JSON - not used.
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 void Add(TObject *obj)
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...
basic_json<> json
default JSON class
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
void PerformPostProcessing(TJSONStackObj *stack, const TClass *obj_cl=nullptr)
Function is converts TObject and TString structures to more compact representation.
void JsonReadCollection(TCollection *obj, const TClass *objClass)
read content of ROOT collection
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
virtual void ReadBaseClass(void *start, TStreamerBase *elem)
Read data of base class.
Int_t Atoi() const
Return integer value of string.
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...
void SetBaseVersion(Int_t v)
static void * ConvertFromJSONAny(const char *str, TClass **cl=nullptr)
Read object from JSON, produced by ConvertToJSON() method.
virtual ~TBufferJSON()
destroy buffer
virtual TClass * GetClassPointer() const
Returns a pointer to the TClass of this element.
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
iterator find(typename object_t::key_type key)
find an element in a JSON object
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Abstract Interface class describing Streamer information for one class.
virtual void ReadBaseClass(void *start, TStreamerBase *elem)
Read data of base class.
Bool_t IsaPointer() const
Return true if data member is a pointer.
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 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 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.
string_t dump(const int indent=-1) const
serialization
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
virtual void ReadUInt(UInt_t &i)
Reads UInt_t value from buffer.
TBufferJSON(TBuffer::EMode mode=TBuffer::kWrite)
Creates buffer object to serialize data into json.
const char * Data() const