From b78cd2a0eab90c009b18821c1cea0072c417a746 Mon Sep 17 00:00:00 2001
From: Philippe Canal <pcanal@fnal.gov>
Date: Thu, 10 Jul 2014 17:30:43 -0500
Subject: [PATCH] Update SetStreamerElementNumber since the number is no longer
 as well defined.

SetStreamerElementNumber nows received the StreamerElement and actually 'Type' used
for I/O.

Update the code of TBufferXML, TBufferSQL2 and TBufferJSON accordingly.

Mark GetStreamerElementReal as obsolete.
---
 core/base/inc/TBuffer.h                |  2 +-
 io/io/inc/TBufferFile.h                |  2 +-
 io/io/src/TStreamerInfo.cxx            |  5 +++
 io/io/src/TStreamerInfoReadBuffer.cxx  |  3 +-
 io/io/src/TStreamerInfoWriteBuffer.cxx |  3 +-
 io/sql/inc/TBufferSQL2.h               |  6 +--
 io/sql/src/TBufferSQL2.cxx             | 39 ++++++++---------
 io/xml/inc/TBufferXML.h                |  4 +-
 io/xml/src/TBufferXML.cxx              | 60 +++++++++++---------------
 net/http/inc/TBufferJSON.h             |  4 +-
 net/http/src/TBufferJSON.cxx           | 44 ++++++++-----------
 11 files changed, 78 insertions(+), 94 deletions(-)

diff --git a/core/base/inc/TBuffer.h b/core/base/inc/TBuffer.h
index 7d06fa86b93..903652e5bce 100644
--- a/core/base/inc/TBuffer.h
+++ b/core/base/inc/TBuffer.h
@@ -131,7 +131,7 @@ public:
 
    virtual void       TagStreamerInfo(TVirtualStreamerInfo* info) = 0;
    virtual void       IncrementLevel(TVirtualStreamerInfo* info) = 0;
-   virtual void       SetStreamerElementNumber(Int_t) = 0;
+   virtual void       SetStreamerElementNumber(TStreamerElement *elem, Int_t comp_type) = 0;
    virtual void       DecrementLevel(TVirtualStreamerInfo*) = 0;
 
    virtual void       ClassBegin(const TClass*, Version_t = -1) = 0;
diff --git a/io/io/inc/TBufferFile.h b/io/io/inc/TBufferFile.h
index ee6734a1d96..c3f40081801 100644
--- a/io/io/inc/TBufferFile.h
+++ b/io/io/inc/TBufferFile.h
@@ -121,7 +121,7 @@ public:
 
    virtual void       TagStreamerInfo(TVirtualStreamerInfo* info);
    virtual void       IncrementLevel(TVirtualStreamerInfo* info);
-   virtual void       SetStreamerElementNumber(Int_t) {}
+   virtual void       SetStreamerElementNumber(TStreamerElement*,Int_t) {}
    virtual void       DecrementLevel(TVirtualStreamerInfo*);
    TVirtualStreamerInfo  *GetInfo() {return (TVirtualStreamerInfo*)fInfo;}
    virtual void       ClassBegin(const TClass*, Version_t = -1) {}
diff --git a/io/io/src/TStreamerInfo.cxx b/io/io/src/TStreamerInfo.cxx
index f52e554ca3c..1ad86836c66 100644
--- a/io/io/src/TStreamerInfo.cxx
+++ b/io/io/src/TStreamerInfo.cxx
@@ -3877,6 +3877,9 @@ TStreamerElement* TStreamerInfo::GetStreamerElement(const char* datamember, Int_
 //______________________________________________________________________________
 TStreamerElement* TStreamerInfo::GetStreamerElementReal(Int_t i, Int_t j) const
 {
+   //
+   //  This routine is obsolete and should not longer be used.
+   //
    //  TStreamerInfo  holds two types of data structures
    //    -TObjArray* fElements; containing the list of all TStreamerElement
    //       objects for this class version.
@@ -3908,6 +3911,8 @@ TStreamerElement* TStreamerInfo::GetStreamerElementReal(Int_t i, Int_t j) const
    //     const char* membername = el->GetName();
    //  This function is typically called from TBuffer, TXmlBuffer
 
+   ::Obsolete("TStreamerInfo::GetStreamerElementReal", "v5-34-20", "v6-00-02");
+
    if (i < 0 || i >= fNdata) return 0;
    if (j < 0) return 0;
    if (!fElements) return 0;
diff --git a/io/io/src/TStreamerInfoReadBuffer.cxx b/io/io/src/TStreamerInfoReadBuffer.cxx
index 9787187eba6..6883af31829 100644
--- a/io/io/src/TStreamerInfoReadBuffer.cxx
+++ b/io/io/src/TStreamerInfoReadBuffer.cxx
@@ -753,10 +753,11 @@ Int_t TStreamerInfo::ReadBuffer(TBuffer &b, const T &arr,
    TMemberStreamer *pstreamer=0;
    Int_t isPreAlloc = 0;
    for (Int_t i=first;i<last;i++) {
-      if (needIncrement) b.SetStreamerElementNumber(i);
       TStreamerElement * aElement  = (TStreamerElement*)compinfo[i]->fElem;
       fgElement = aElement;
 
+      if (needIncrement) b.SetStreamerElementNumber(aElement,compinfo[i]->fType);
+   
       if (aElement->TestBit(TStreamerElement::kWrite)) continue;
 
       if (R__TestUseCache<T>(aElement)) {
diff --git a/io/io/src/TStreamerInfoWriteBuffer.cxx b/io/io/src/TStreamerInfoWriteBuffer.cxx
index 7d1a1ad2628..eac6e35aef8 100644
--- a/io/io/src/TStreamerInfoWriteBuffer.cxx
+++ b/io/io/src/TStreamerInfoWriteBuffer.cxx
@@ -138,9 +138,10 @@ Int_t TStreamerInfo::WriteBufferAux(TBuffer &b, const T &arr,
 
    for (Int_t i=first;i<last;i++) {
 
-      if (needIncrement) b.SetStreamerElementNumber(i);
       TStreamerElement *aElement = (TStreamerElement*)compinfo[i]->fElem;
 
+      if (needIncrement) b.SetStreamerElementNumber(aElement,compinfo[i]->fType);
+
       Int_t ioffset = eoffset+compinfo[i]->fOffset;
 
       if (R__TestUseCache<T>(aElement)) {
diff --git a/io/sql/inc/TBufferSQL2.h b/io/sql/inc/TBufferSQL2.h
index e65a99b4d74..297e6e275f8 100644
--- a/io/sql/inc/TBufferSQL2.h
+++ b/io/sql/inc/TBufferSQL2.h
@@ -1,4 +1,4 @@
-// @(#)root/sql:$Id$
+// @(#)root/sql
 // Author: Sergey Linev  20/11/2005
 
 
@@ -82,7 +82,7 @@ protected:
    TSQLStructure*   Stack(Int_t depth = 0);
 
    void             WorkWithClass(const char* classname, Version_t classversion); 
-   void             WorkWithElement(TStreamerElement* elem, Int_t number);
+   void             WorkWithElement(TStreamerElement* elem, Int_t comp_type);
 
    Int_t            SqlReadArraySize();
    Bool_t           SqlObjectInfo(Long64_t objid, TString& clname, Version_t& version);
@@ -160,7 +160,7 @@ public:
    virtual void     SkipObjectAny();
 
    virtual void     IncrementLevel(TVirtualStreamerInfo*);
-   virtual void     SetStreamerElementNumber(Int_t);
+   virtual void     SetStreamerElementNumber(TStreamerElement *elem, Int_t comp_type);
    virtual void     DecrementLevel(TVirtualStreamerInfo*);
    
    virtual void     ClassBegin(const TClass*, Version_t = -1);
diff --git a/io/sql/src/TBufferSQL2.cxx b/io/sql/src/TBufferSQL2.cxx
index 45e466133c7..8a91fa48d4f 100644
--- a/io/sql/src/TBufferSQL2.cxx
+++ b/io/sql/src/TBufferSQL2.cxx
@@ -565,7 +565,7 @@ void  TBufferSQL2::DecrementLevel(TVirtualStreamerInfo* info)
    // and decrease level in sql structure.
 
    TSQLStructure* curr = Stack();
-   if (curr->GetType()==TSQLStructure::kSqlElement) PopStack(); // for element
+   if (curr->GetElement()) PopStack(); // for element
    PopStack();  // for streamerinfo
 
    // restore value of object data
@@ -578,13 +578,13 @@ void  TBufferSQL2::DecrementLevel(TVirtualStreamerInfo* info)
 }
 
 //______________________________________________________________________________
-void TBufferSQL2::SetStreamerElementNumber(Int_t number)
+void TBufferSQL2::SetStreamerElementNumber(TStreamerElement *elem, Int_t comp_type)
 {
    // Function is called from TStreamerInfo WriteBuffer and Readbuffer functions
    // and add/verify next element in sql tables
    // This calls allows separate data, correspondent to one class member, from another
 
-   if (number>0) PopStack();
+   if (Stack()->GetElement()) PopStack(); // was with if (number > 0), i.e. not first element.
    TSQLStructure* curr = Stack();
 
    TStreamerInfo* info = curr->GetStreamerInfo();
@@ -592,16 +592,13 @@ void TBufferSQL2::SetStreamerElementNumber(Int_t number)
       Error("SetStreamerElementNumber","Error in structures stack");
       return;
    }
-   TStreamerElement* elem = info->GetStreamerElementReal(number, 0);
-
-   Int_t comp_type = info->GetType(number);
 
    Int_t elem_type = elem->GetType();
 
    fExpectedChain = ((elem_type>0) && (elem_type<20)) &&
       (comp_type - elem_type == TStreamerInfo::kOffsetL);
 
-   WorkWithElement(elem, number);
+   WorkWithElement(elem, comp_type);
 }
 
 //______________________________________________________________________________
@@ -856,7 +853,7 @@ void TBufferSQL2::WorkWithClass(const char* classname, Version_t classversion)
 }
 
 //______________________________________________________________________________
-void TBufferSQL2::WorkWithElement(TStreamerElement* elem, Int_t number)
+void TBufferSQL2::WorkWithElement(TStreamerElement* elem, Int_t /* comp_type */)
 {
    // This function is a part of SetStreamerElementNumber method.
    // It is introduced for reading of data for specified data memeber of class.
@@ -866,6 +863,10 @@ void TBufferSQL2::WorkWithElement(TStreamerElement* elem, Int_t number)
    if (gDebug>2)
       Info("WorkWithElement","elem = %s",elem->GetName());
 
+   TSQLStructure* stack = Stack(1);
+   TStreamerInfo* info = stack->GetStreamerInfo();
+   Int_t number = info->GetElements()->IndexOf(elem);
+   
    if (number>=0)
       PushStack()->SetStreamerElement(elem, number);
    else
@@ -1402,11 +1403,10 @@ Int_t TBufferSQL2::ReadStaticArrayDouble32(Double_t  *d, TStreamerElement * /*el
          fExpectedChain = kFALSE;                                       \
          Int_t startnumber = Stack(0)->GetElementNumber();              \
          TStreamerInfo* info = Stack(1)->GetStreamerInfo();             \
-         Int_t number = 0;                                              \
          Int_t index = 0;                                               \
          while (index<n) {                                              \
-            elem = info->GetStreamerElementReal(startnumber, number++); \
-            if (number>1) { PopStack(); WorkWithElement(elem, startnumber); } \
+            elem = (TStreamerElement*)info->GetElements()->At(startnumber++); \
+            if (index>1) { PopStack(); WorkWithElement(elem, elem->GetType()); } \
             if (elem->GetType()<TStreamerInfo::kOffsetL) {              \
                SqlReadBasic(vname[index]);                              \
                index++;                                                 \
@@ -1835,11 +1835,10 @@ void TBufferSQL2::WriteArrayDouble32(const Double_t  *d, Int_t n, TStreamerEleme
       if (fExpectedChain) {                                             \
          TStreamerInfo* info = Stack(1)->GetStreamerInfo();             \
          Int_t startnumber = Stack(0)->GetElementNumber();              \
-         Int_t number = 0;                                              \
          Int_t index = 0;                                               \
          while (index<n) {                                              \
-            elem = info->GetStreamerElementReal(startnumber, number++); \
-            if (number>1) { PopStack(); WorkWithElement(elem, startnumber + number); } \
+            elem = (TStreamerElement*)info->GetElements()->At(startnumber++); \
+            if (index>0) { PopStack(); WorkWithElement(elem, elem->GetType()); } \
             if (elem->GetType()<TStreamerInfo::kOffsetL) {              \
                SqlWriteBasic(vname[index]);                             \
                index++;                                                 \
@@ -2785,7 +2784,7 @@ Int_t TBufferSQL2::ApplySequence(const TStreamerInfoActions::TActionSequence &se
           iter != end;
           ++iter) {      
          // Idea: Try to remove this function call as it is really needed only for XML streaming.
-         SetStreamerElementNumber((*iter).fConfiguration->fElemId);
+         SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem,(*iter).fConfiguration->fCompInfo->fType);
          (*iter).PrintDebug(*this,obj);
          (*iter)(*this,obj);
       }
@@ -2797,7 +2796,7 @@ Int_t TBufferSQL2::ApplySequence(const TStreamerInfoActions::TActionSequence &se
           iter != end;
           ++iter) {      
          // Idea: Try to remove this function call as it is really needed only for XML streaming.
-         SetStreamerElementNumber((*iter).fConfiguration->fElemId);
+         SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem,(*iter).fConfiguration->fCompInfo->fType);
          (*iter)(*this,obj);
       }
    }
@@ -2822,7 +2821,7 @@ Int_t TBufferSQL2::ApplySequenceVecPtr(const TStreamerInfoActions::TActionSequen
           iter != end;
           ++iter) {      
          // Idea: Try to remove this function call as it is really needed only for XML streaming.
-         SetStreamerElementNumber((*iter).fConfiguration->fElemId);
+         SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem,(*iter).fConfiguration->fCompInfo->fType);
          (*iter).PrintDebug(*this,*(char**)start_collection);  // Warning: This limits us to TClonesArray and vector of pointers.
          (*iter)(*this,start_collection,end_collection);
       }
@@ -2834,7 +2833,7 @@ Int_t TBufferSQL2::ApplySequenceVecPtr(const TStreamerInfoActions::TActionSequen
           iter != end;
           ++iter) {      
          // Idea: Try to remove this function call as it is really needed only for XML streaming.
-         SetStreamerElementNumber((*iter).fConfiguration->fElemId);
+         SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem,(*iter).fConfiguration->fCompInfo->fType);
          (*iter)(*this,start_collection,end_collection);
       }
    }
@@ -2864,7 +2863,7 @@ Int_t TBufferSQL2::ApplySequence(const TStreamerInfoActions::TActionSequence &se
           iter != end;
           ++iter) {      
          // Idea: Try to remove this function call as it is really needed only for XML streaming.
-         SetStreamerElementNumber((*iter).fConfiguration->fElemId);
+         SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem,(*iter).fConfiguration->fCompInfo->fType);
          (*iter).PrintDebug(*this,arr0);
          (*iter)(*this,start_collection,end_collection,loopconfig);
       }
@@ -2876,7 +2875,7 @@ Int_t TBufferSQL2::ApplySequence(const TStreamerInfoActions::TActionSequence &se
           iter != end;
           ++iter) {      
          // Idea: Try to remove this function call as it is really needed only for XML streaming.
-         SetStreamerElementNumber((*iter).fConfiguration->fElemId);
+         SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem,(*iter).fConfiguration->fCompInfo->fType);
          (*iter)(*this,start_collection,end_collection,loopconfig);
       }
    }
diff --git a/io/xml/inc/TBufferXML.h b/io/xml/inc/TBufferXML.h
index 25ef96850fb..193e780d630 100644
--- a/io/xml/inc/TBufferXML.h
+++ b/io/xml/inc/TBufferXML.h
@@ -74,7 +74,7 @@ public:
    virtual void     SkipObjectAny();
 
    virtual void     IncrementLevel(TVirtualStreamerInfo*);
-   virtual void     SetStreamerElementNumber(Int_t);
+   virtual void     SetStreamerElementNumber(TStreamerElement *elem, Int_t comp_type);
    virtual void     DecrementLevel(TVirtualStreamerInfo*);
    
    virtual void     ClassBegin(const TClass*, Version_t = -1);
@@ -260,7 +260,7 @@ protected:
    TXMLStackObj*    Stack(Int_t depth = 0);
 
    void             WorkWithClass(TStreamerInfo* info, const TClass* cl = 0);
-   void             WorkWithElement(TStreamerElement* elem, Int_t number);
+   void             WorkWithElement(TStreamerElement* elem, Int_t comp_type);
    Bool_t           VerifyNode(XMLNodePointer_t node, const char* name, const char* errinfo = 0);
    Bool_t           VerifyStackNode(const char* name, const char* errinfo = 0);
    
diff --git a/io/xml/src/TBufferXML.cxx b/io/xml/src/TBufferXML.cxx
index faf1c1357b6..e265ceb922c 100644
--- a/io/xml/src/TBufferXML.cxx
+++ b/io/xml/src/TBufferXML.cxx
@@ -992,17 +992,17 @@ void TBufferXML::DecrementLevel(TVirtualStreamerInfo* info)
 }
 
 //______________________________________________________________________________
-void TBufferXML::SetStreamerElementNumber(Int_t number)
+void TBufferXML::SetStreamerElementNumber(TStreamerElement *elem, Int_t comptype)
 {
    // Function is called from TStreamerInfo WriteBuffer and Readbuffer functions
    // and add/verify next element of xml structure
    // This calls allows separate data, correspondent to one class member, from another
 
-   WorkWithElement(0, number);
+   WorkWithElement(elem, comptype);
 }
 
 //______________________________________________________________________________
-void TBufferXML::WorkWithElement(TStreamerElement* elem, Int_t number)
+void TBufferXML::WorkWithElement(TStreamerElement* elem, Int_t comp_type)
 {
    //to be documented by Sergey
    CheckVersionBuf();
@@ -1029,27 +1029,16 @@ void TBufferXML::WorkWithElement(TStreamerElement* elem, Int_t number)
       return;
    }
 
-   Int_t comp_type = 0;
-
-   if ((number>=0) && (elem==0)) {
-
-      TStreamerInfo* info = stack->fInfo;
-      if (!stack->IsStreamerInfo()) {
-         Error("SetStreamerElementNumber", "Problem in Inc/Dec level");
-         return;
-      }
-
-      comp_type = info->GetType(number);
-
-      elem = info->GetStreamerElementReal(number, 0);
-   } else if (elem) {
-      comp_type = elem->GetType();
+   if (!elem) {
+      Error("SetStreamerElementNumber", "Problem in Inc/Dec level");
+      return;
    }
-
-   if (elem==0) {
-      Error("SetStreamerElementNumber", "streamer info returns elem = 0");
+   TStreamerInfo* info = stack->fInfo;
+   if (!stack->IsStreamerInfo()) {
+      Error("SetStreamerElementNumber", "Problem in Inc/Dec level");
       return;
    }
+   Int_t number = info->GetElements()->IndexOf(elem);
 
    if (gDebug>4) Info("SetStreamerElementNumber", "    Next element %s", elem->GetName());
 
@@ -1057,10 +1046,11 @@ void TBufferXML::WorkWithElement(TStreamerElement* elem, Int_t number)
 
    fExpectedChain = isBasicType && (comp_type - elem->GetType() == TStreamerInfo::kOffsetL);
 
-   if (fExpectedChain && (gDebug>3))
+   if (fExpectedChain && (gDebug>3)) {
       Info("SetStreamerElementNumber",
            "    Expects chain for elem %s number %d",
             elem->GetName(), number);
+   }
 
    fCanUseCompact = isBasicType && ((elem->GetType()==comp_type) ||
                                     (elem->GetType()==comp_type-TStreamerInfo::kConv) ||
@@ -1915,17 +1905,16 @@ Int_t TBufferXML::ReadStaticArrayDouble32(Double_t  *d, TStreamerElement * /*ele
       fExpectedChain = kFALSE;                                            \
       Int_t startnumber = Stack(0)->fElemNumber;                          \
       TStreamerInfo* info = Stack(1)->fInfo;                              \
-      Int_t number = 0;                                                   \
       Int_t index = 0;                                                    \
       while (index<n) {                                                   \
-        elem = info->GetStreamerElementReal(startnumber, number++);       \
+        elem = (TStreamerElement*)info->GetElements()->At(startnumber++); \
         if (elem->GetType()<TStreamerInfo::kOffsetL) {                    \
            if (index>0) { PopStack(); ShiftStack("chainreader"); VerifyElemNode(elem); }  \
            fCanUseCompact = kTRUE;                                        \
            XmlReadBasic(vname[index]);                                    \
            index++;                                                       \
         } else {                                                          \
-           if (!VerifyItemNode(xmlio::Array,"ReadFastArray")) return;   \
+           if (!VerifyItemNode(xmlio::Array,"ReadFastArray")) return;     \
            PushStack(StackNode());                                        \
            Int_t elemlen = elem->GetArrayLength();                        \
            TXMLReadArrayContent((vname+index), elemlen);                  \
@@ -1935,7 +1924,7 @@ Int_t TBufferXML::ReadStaticArrayDouble32(Double_t  *d, TStreamerElement * /*ele
         }                                                                 \
       }                                                                   \
    } else {                                                               \
-      if (!VerifyItemNode(xmlio::Array,"ReadFastArray")) return;        \
+      if (!VerifyItemNode(xmlio::Array,"ReadFastArray")) return;          \
       PushStack(StackNode());                                             \
       TXMLReadArrayContent(vname, n);                                     \
       PopStack();                                                         \
@@ -2295,17 +2284,16 @@ void TBufferXML::WriteArrayDouble32(const Double_t  *d, Int_t n, TStreamerElemen
       TStreamerInfo* info = Stack(1)->fInfo;                              \
       Int_t startnumber = Stack(0)->fElemNumber;                          \
       fExpectedChain = kFALSE;                                            \
-      Int_t number = 0;                                                   \
       Int_t index = 0;                                                    \
       while (index<n) {                                                   \
-        elem = info->GetStreamerElementReal(startnumber, number++);       \
+        elem =(TStreamerElement*)info->GetElements()->At(startnumber++);  \
         if (elem->GetType()<TStreamerInfo::kOffsetL) {                    \
           if(index>0) { PopStack(); CreateElemNode(elem); }               \
           fCanUseCompact = kTRUE;                                         \
           XmlWriteBasic(vname[index]);                                    \
           index++;                                                        \
         } else {                                                          \
-          XMLNodePointer_t arrnode = CreateItemNode(xmlio::Array);      \
+          XMLNodePointer_t arrnode = CreateItemNode(xmlio::Array);        \
           Int_t elemlen = elem->GetArrayLength();                         \
           PushStack(arrnode);                                             \
           TXMLWriteArrayContent((vname+index), elemlen);                  \
@@ -2314,7 +2302,7 @@ void TBufferXML::WriteArrayDouble32(const Double_t  *d, Int_t n, TStreamerElemen
         }                                                                 \
       }                                                                   \
    } else {                                                               \
-      XMLNodePointer_t arrnode = CreateItemNode(xmlio::Array);          \
+      XMLNodePointer_t arrnode = CreateItemNode(xmlio::Array);            \
       PushStack(arrnode);                                                 \
       TXMLWriteArrayContent(vname, n);                                    \
       PopStack();                                                         \
@@ -3143,7 +3131,7 @@ Int_t TBufferXML::ApplySequence(const TStreamerInfoActions::TActionSequence &seq
           iter != end;
           ++iter) {
          // Idea: Try to remove this function call as it is really needed only for XML streaming.
-         SetStreamerElementNumber((*iter).fConfiguration->fElemId);
+         SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem,(*iter).fConfiguration->fCompInfo->fType);
          (*iter).PrintDebug(*this,obj);
          (*iter)(*this,obj);
       }
@@ -3155,7 +3143,7 @@ Int_t TBufferXML::ApplySequence(const TStreamerInfoActions::TActionSequence &seq
           iter != end;
           ++iter) {
          // Idea: Try to remove this function call as it is really needed only for XML streaming.
-         SetStreamerElementNumber((*iter).fConfiguration->fElemId);
+         SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem,(*iter).fConfiguration->fCompInfo->fType);
          (*iter)(*this,obj);
       }
    }
@@ -3180,7 +3168,7 @@ Int_t TBufferXML::ApplySequenceVecPtr(const TStreamerInfoActions::TActionSequenc
           iter != end;
           ++iter) {
          // Idea: Try to remove this function call as it is really needed only for XML streaming.
-         SetStreamerElementNumber((*iter).fConfiguration->fElemId);
+         SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem,(*iter).fConfiguration->fCompInfo->fType);
          (*iter).PrintDebug(*this,*(char**)start_collection);  // Warning: This limits us to TClonesArray and vector of pointers.
          (*iter)(*this,start_collection,end_collection);
       }
@@ -3192,7 +3180,7 @@ Int_t TBufferXML::ApplySequenceVecPtr(const TStreamerInfoActions::TActionSequenc
           iter != end;
           ++iter) {
          // Idea: Try to remove this function call as it is really needed only for XML streaming.
-         SetStreamerElementNumber((*iter).fConfiguration->fElemId);
+         SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem,(*iter).fConfiguration->fCompInfo->fType);
          (*iter)(*this,start_collection,end_collection);
       }
    }
@@ -3222,7 +3210,7 @@ Int_t TBufferXML::ApplySequence(const TStreamerInfoActions::TActionSequence &seq
           iter != end;
           ++iter) {
          // Idea: Try to remove this function call as it is really needed only for XML streaming.
-         SetStreamerElementNumber((*iter).fConfiguration->fElemId);
+         SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem,(*iter).fConfiguration->fCompInfo->fType);
          (*iter).PrintDebug(*this,arr0);
          (*iter)(*this,start_collection,end_collection,loopconfig);
       }
@@ -3234,7 +3222,7 @@ Int_t TBufferXML::ApplySequence(const TStreamerInfoActions::TActionSequence &seq
           iter != end;
           ++iter) {
          // Idea: Try to remove this function call as it is really needed only for XML streaming.
-         SetStreamerElementNumber((*iter).fConfiguration->fElemId);
+         SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem,(*iter).fConfiguration->fCompInfo->fType);
          (*iter)(*this,start_collection,end_collection,loopconfig);
       }
    }
diff --git a/net/http/inc/TBufferJSON.h b/net/http/inc/TBufferJSON.h
index 4beb49e3e09..0e5ad9a9cf8 100644
--- a/net/http/inc/TBufferJSON.h
+++ b/net/http/inc/TBufferJSON.h
@@ -145,7 +145,7 @@ public:
 
    // these methods used in streamer info to indicate currently streamed element,
    virtual void     IncrementLevel(TVirtualStreamerInfo *);
-   virtual void     SetStreamerElementNumber(Int_t);
+   virtual void     SetStreamerElementNumber(TStreamerElement *elem, Int_t comp_type);
    virtual void     DecrementLevel(TVirtualStreamerInfo *);
 
    virtual void     ClassBegin(const TClass *, Version_t = -1);
@@ -496,7 +496,7 @@ protected:
    TJSONStackObj   *Stack(Int_t depth = 0);
 
    void             WorkWithClass(TStreamerInfo *info, const TClass *cl = 0);
-   void             WorkWithElement(TStreamerElement *elem, Int_t number);
+   void             WorkWithElement(TStreamerElement *elem, Int_t comp_type);
 
    void             PerformPostProcessing(TJSONStackObj *stack, const TStreamerElement *elem = 0);
 
diff --git a/net/http/src/TBufferJSON.cxx b/net/http/src/TBufferJSON.cxx
index 2897e6f697a..d55b37812ea 100644
--- a/net/http/src/TBufferJSON.cxx
+++ b/net/http/src/TBufferJSON.cxx
@@ -1,4 +1,4 @@
-// $Id$
+//
 // Author: Sergey Linev  4.03.2014
 
 /*************************************************************************
@@ -854,7 +854,7 @@ void TBufferJSON::DecrementLevel(TVirtualStreamerInfo *info)
 }
 
 //______________________________________________________________________________
-void TBufferJSON::SetStreamerElementNumber(Int_t number)
+void TBufferJSON::SetStreamerElementNumber(TStreamerElement *elem, Int_t comp_type)
 {
    // Function is called from TStreamerInfo WriteBuffer and Readbuffer functions
    // and add/verify next element of xml structure
@@ -863,11 +863,11 @@ void TBufferJSON::SetStreamerElementNumber(Int_t number)
    if (gDebug > 3)
       Info("SetStreamerElementNumber", "Number %d", number);
 
-   WorkWithElement(0, number);
+   WorkWithElement(elem, comp_type);
 }
 
 //______________________________________________________________________________
-void TBufferJSON::WorkWithElement(TStreamerElement *elem, Int_t number)
+void TBufferJSON::WorkWithElement(TStreamerElement *elem, Int_t comp_type)
 {
    // This is call-back from streamer which indicates
    // that class member will be streamed
@@ -905,22 +905,12 @@ void TBufferJSON::WorkWithElement(TStreamerElement *elem, Int_t number)
       return;
    }
 
-   Int_t comp_type = 0;
-
-   if ((number >= 0) && (elem == 0)) {
-
-      TStreamerInfo *info = stack->fInfo;
-      if (!stack->IsStreamerInfo()) {
-         Error("WorkWithElement", "Problem in Inc/Dec level");
-         return;
-      }
-
-      comp_type = info->GetTypes()[number];
-
-      elem = info->GetStreamerElementReal(number, 0);
-   } else if (elem) {
-      comp_type = elem->GetType();
+   TStreamerInfo *info = stack->fInfo;
+   if (!stack->IsStreamerInfo()) {
+      Error("WorkWithElement", "Problem in Inc/Dec level");
+      return;
    }
+   Int_t number = info->GetElements()->IndexOf(elem);
 
    if (gDebug > 3)
       Info("WorkWithElement", "    Start element %s type %d",
@@ -1981,9 +1971,9 @@ void TBufferJSON::WriteArrayDouble32(const Double_t *d, Int_t n,
          TStreamerInfo* info = Stack(1)->fInfo;                              \
          Int_t startnumber = Stack(0)->fElemNumber;                          \
          fExpectedChain = kFALSE;                                            \
-         Int_t number(0), index(0);                                          \
+         Int_t index(0);                                          \
          while (index<n) {                                                   \
-            elem = info->GetStreamerElementReal(startnumber, number++);       \
+            elem = (TStreamerElement*)info->GetElements()->At(startnumber++); \
             if (elem->GetType()<TStreamerInfo::kOffsetL) {                    \
                JsonWriteBasic(vname[index]);                                   \
                PerformPostProcessing(Stack(0), elem);                          \
@@ -2688,7 +2678,7 @@ Int_t TBufferJSON::ApplySequence(const TStreamerInfoActions::TActionSequence &se
       for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin();
             iter != end; ++iter) {
          // Idea: Try to remove this function call as it is really needed only for XML streaming.
-         SetStreamerElementNumber((*iter).fConfiguration->fElemId);
+         SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem,(*iter).fConfiguration->fCompInfo->fType);
          (*iter).PrintDebug(*this, obj);
          (*iter)(*this, obj);
       }
@@ -2698,7 +2688,7 @@ Int_t TBufferJSON::ApplySequence(const TStreamerInfoActions::TActionSequence &se
       for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin();
             iter != end;  ++iter) {
          // Idea: Try to remove this function call as it is really needed only for XML streaming.
-         SetStreamerElementNumber((*iter).fConfiguration->fElemId);
+         SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem,(*iter).fConfiguration->fCompInfo->fType);
          (*iter)(*this, obj);
       }
    }
@@ -2722,7 +2712,7 @@ Int_t TBufferJSON::ApplySequenceVecPtr(const TStreamerInfoActions::TActionSequen
       for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin();
             iter != end; ++iter) {
          // Idea: Try to remove this function call as it is really needed only for XML streaming.
-         SetStreamerElementNumber((*iter).fConfiguration->fElemId);
+         SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem,(*iter).fConfiguration->fCompInfo->fType);
          (*iter).PrintDebug(*this, *(char **)start_collection); // Warning: This limits us to TClonesArray and vector of pointers.
          (*iter)(*this, start_collection, end_collection);
       }
@@ -2732,7 +2722,7 @@ Int_t TBufferJSON::ApplySequenceVecPtr(const TStreamerInfoActions::TActionSequen
       for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin();
             iter != end; ++iter) {
          // Idea: Try to remove this function call as it is really needed only for XML streaming.
-         SetStreamerElementNumber((*iter).fConfiguration->fElemId);
+         SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem,(*iter).fConfiguration->fCompInfo->fType);
          (*iter)(*this, start_collection, end_collection);
       }
    }
@@ -2761,7 +2751,7 @@ Int_t TBufferJSON::ApplySequence(const TStreamerInfoActions::TActionSequence &se
       for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin();
             iter != end; ++iter) {
          // Idea: Try to remove this function call as it is really needed only for XML streaming.
-         SetStreamerElementNumber((*iter).fConfiguration->fElemId);
+         SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem,(*iter).fConfiguration->fCompInfo->fType);
          (*iter).PrintDebug(*this, arr0);
          (*iter)(*this, start_collection, end_collection, loopconfig);
       }
@@ -2771,7 +2761,7 @@ Int_t TBufferJSON::ApplySequence(const TStreamerInfoActions::TActionSequence &se
       for (TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin();
             iter != end; ++iter) {
          // Idea: Try to remove this function call as it is really needed only for XML streaming.
-         SetStreamerElementNumber((*iter).fConfiguration->fElemId);
+         SetStreamerElementNumber((*iter).fConfiguration->fCompInfo->fElem,(*iter).fConfiguration->fCompInfo->fType);
          (*iter)(*this, start_collection, end_collection, loopconfig);
       }
    }
-- 
GitLab