<commit_before>// @(#)root/treeplayer:$Id$
// Author: <NAME>, 2011-09-28

/*************************************************************************
 * Copyright (C) 1995-2013, <NAME> and <NAME> and al.        *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TTreeReaderArray.h"

#include "TBranchClones.h"
#include "TBranchElement.h"
#include "TBranchRef.h"
#include "TBranchSTL.h"
#include "TBranchProxyDirector.h"
#include "TClassEdit.h"
#include "TLeaf.h"
#include "TROOT.h"
#include "TStreamerInfo.h"
#include "TStreamerElement.h"
#include "TTreeReader.h"
#include "TGenCollectionProxy.h"
#include "TRegexp.h"

// pin vtable
ROOT::Internal::TVirtualCollectionReader::~TVirtualCollectionReader() {}

namespace {
   using namespace ROOT::Internal;

   // Reader interface for clones arrays
   class TClonesReader: public TVirtualCollectionReader {
   public:
      ~TClonesReader() {}
      TClonesArray* GetCA(ROOT::Detail::TBranchProxy* proxy) {
         if (!proxy->Read()){
            fReadStatus = TTreeReaderValueBase::kReadError;
            Error("TClonesReader::GetCA()", "Read error in TBranchProxy.");
            return 0;
         }
         fReadStatus = TTreeReaderValueBase::kReadSuccess;
         return (TClonesArray*) proxy->GetWhere();
      }
      virtual size_t GetSize(ROOT::Detail::TBranchProxy* proxy) {
         TClonesArray *myClonesArray = GetCA(proxy);
         if (myClonesArray){
            return myClonesArray->GetEntries();
         }
         else return 0;
      }
      virtual void* At(ROOT::Detail::TBranchProxy* proxy, size_t idx) {
         TClonesArray *myClonesArray = GetCA(proxy);
         if (myClonesArray){
            return myClonesArray->UncheckedAt(idx);
         }
         else return 0;
      }
   };

   // Reader interface for STL
   class TSTLReader: public TVirtualCollectionReader {
   public:
      ~TSTLReader() {}
      TVirtualCollectionProxy* GetCP(ROOT::Detail::TBranchProxy* proxy) {
         if (!proxy->Read()) {
            fReadStatus = TTreeReaderValueBase::kReadError;
            Error("TSTLReader::GetCP()", "Read error in TBranchProxy.");
            return 0;
         }
         if (!proxy->GetWhere()) {
            Error("TSTLReader::GetCP()", "Logic error, proxy object not set in TBranchProxy.");
            return 0;
         }
         if (proxy->IsaPointer()) {
            if (proxy->GetWhere() && *(void**)proxy->GetWhere()){
               ((TGenCollectionProxy*)proxy->GetCollection())->PopProxy();
               ((TGenCollectionProxy*)proxy->GetCollection())->PushProxy(*(void**)proxy->GetWhere());
            }
            else return 0;
         }
         fReadStatus = TTreeReaderValueBase::kReadSuccess;
         return (TVirtualCollectionProxy*) proxy->GetCollection();
      }

      virtual size_t GetSize(ROOT::Detail::TBranchProxy* proxy) {
         TVirtualCollectionProxy *myCollectionProxy = GetCP(proxy);
         if (!myCollectionProxy) return 0;
         return myCollectionProxy->Size();
      }

      virtual void* At(ROOT::Detail::TBranchProxy* proxy, size_t idx) {
         TVirtualCollectionProxy *myCollectionProxy = GetCP(proxy);
         if (!myCollectionProxy) return 0;
         if (myCollectionProxy->HasPointers()){
            return *(void**)myCollectionProxy->At(idx);
         }
         else {
            return myCollectionProxy->At(idx);
         }
      }
   };

   class TCollectionLessSTLReader : public TVirtualCollectionReader {
   private:
      TVirtualCollectionProxy *localCollection;
   public:
      TCollectionLessSTLReader(TVirtualCollectionProxy *proxy) : localCollection(proxy) {}

      TVirtualCollectionProxy* GetCP(ROOT::Detail::TBranchProxy* proxy) {
         if (!proxy->Read()) {
            fReadStatus = TTreeReaderValueBase::kReadError;
            Error("TCollectionLessSTLReader::GetCP()", "Read error in TBranchProxy.");
            return 0;
         }
         if (!proxy->GetWhere()) {
            Error("TCollectionLessSTLReader::GetCP()", "Logic error, proxy object not set in TBranchProxy.");
            return 0;
         }
         fReadStatus = TTreeReaderValueBase::kReadSuccess;
         return localCollection;
      }

      virtual size_t GetSize(ROOT::Detail::TBranchProxy* proxy) {
         TVirtualCollectionProxy *myCollectionProxy = GetCP(proxy);
         if (!myCollectionProxy) return 0;
         TVirtualCollectionProxy::TPushPop ppRaii(myCollectionProxy, proxy->GetWhere());
         return myCollectionProxy->Size();
      }

      virtual void* At(ROOT::Detail::TBranchProxy* proxy, size_t idx) {
         TVirtualCollectionProxy *myCollectionProxy = GetCP(proxy);
         if (!myCollectionProxy) return 0;
         TVirtualCollectionProxy::TPushPop ppRaii(myCollectionProxy, proxy->GetWhere());
         if (myCollectionProxy->HasPointers()){
            return *(void**)myCollectionProxy->At(idx);
         } else {
            return myCollectionProxy->At(idx);
         }
      }
   };


   // Reader interface for leaf list
   // SEE TTreeProxyGenerator.cxx:1319: '//We have a top level raw type'
   class TObjectArrayReader: public TVirtualCollectionReader {
   private:
      Int_t basicTypeSize;
   public:
      TObjectArrayReader() : basicTypeSize(-1) { }
      ~TObjectArrayReader() {}
      TVirtualCollectionProxy* GetCP(ROOT::Detail::TBranchProxy* proxy) {
         if (!proxy->Read()){
            fReadStatus = TTreeReaderValueBase::kReadError;
            Error("TObjectArrayReader::GetCP()", "Read error in TBranchProxy.");
            return 0;
         }
         fReadStatus = TTreeReaderValueBase::kReadSuccess;
         return (TVirtualCollectionProxy*) proxy->GetCollection();
      }
      virtual size_t GetSize(ROOT::Detail::TBranchProxy* proxy) {
         TVirtualCollectionProxy *myCollectionProxy = GetCP(proxy);
         if (!myCollectionProxy) return 0;
         return myCollectionProxy->Size();
      }
      virtual void* At(ROOT::Detail::TBranchProxy* proxy, size_t idx) {
         if (!proxy->Read()) return 0;

         Int_t objectSize;
         void *array = (void*)proxy->GetStart();

         if (basicTypeSize == -1){
            TClass *myClass = proxy->GetClass();
            if (!myClass){
               Error("TObjectArrayReader::At()", "Cannot get class info from branch proxy.");
               return 0;
            }
            objectSize = myClass->GetClassSize();
         }
         else {
            objectSize = basicTypeSize;
         }
         return (void*)((Byte_t*)array + (objectSize * idx));
      }

      void SetBasicTypeSize(Int_t size){
         basicTypeSize = size;
      }
   };

   class TArrayParameterSizeReader : public TObjectArrayReader {
   private:
      TTreeReaderValue<Int_t> indexReader;
   public:
      TArrayParameterSizeReader(TTreeReader *treeReader, const char *branchName) : indexReader(*treeReader, branchName) {}

      virtual size_t GetSize(ROOT::Detail::TBranchProxy* /*proxy*/){ return *indexReader; }
   };

   // Reader interface for fixed size arrays
   class TArrayFixedSizeReader : public TObjectArrayReader {
   private:
      Int_t size;

   public:
      TArrayFixedSizeReader(Int_t sizeArg) : size(sizeArg) {}<commit_msg>Allow UInt_t as leaf size.<commit_after>// @(#)root/treeplayer:$Id$
// Author: <NAME>, 2011-09-28

/*************************************************************************
 * Copyright (C) 1995-2013, <NAME> and <NAME> and al.        *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TTreeReaderArray.h"

#include "TBranchClones.h"
#include "TBranchElement.h"
#include "TBranchRef.h"
#include "TBranchSTL.h"
#include "TBranchProxyDirector.h"
#include "TClassEdit.h"
#include "TLeaf.h"
#include "TROOT.h"
#include "TStreamerInfo.h"
#include "TStreamerElement.h"
#include "TTreeReader.h"
#include "TGenCollectionProxy.h"
#include "TRegexp.h"

// pin vtable
ROOT::Internal::TVirtualCollectionReader::~TVirtualCollectionReader() {}

namespace {
   using namespace ROOT::Internal;

   // Reader interface for clones arrays
   class TClonesReader: public TVirtualCollectionReader {
   public:
      ~TClonesReader() {}
      TClonesArray* GetCA(ROOT::Detail::TBranchProxy* proxy) {
         if (!proxy->Read()){
            fReadStatus = TTreeReaderValueBase::kReadError;
            Error("TClonesReader::GetCA()", "Read error in TBranchProxy.");
            return 0;
         }
         fReadStatus = TTreeReaderValueBase::kReadSuccess;
         return (TClonesArray*) proxy->GetWhere();
      }
      virtual size_t GetSize(ROOT::Detail::TBranchProxy* proxy) {
         TClonesArray *myClonesArray = GetCA(proxy);
         if (myClonesArray){
            return myClonesArray->GetEntries();
         }
         else return 0;
      }
      virtual void* At(ROOT::Detail::TBranchProxy* proxy, size_t idx) {
         TClonesArray *myClonesArray = GetCA(proxy);
         if (myClonesArray){
            return myClonesArray->UncheckedAt(idx);
         }
         else return 0;
      }
   };

   // Reader interface for STL
   class TSTLReader: public TVirtualCollectionReader {
   public:
      ~TSTLReader() {}
      TVirtualCollectionProxy* GetCP(ROOT::Detail::TBranchProxy* proxy) {
         if (!proxy->Read()) {
            fReadStatus = TTreeReaderValueBase::kReadError;
            Error("TSTLReader::GetCP()", "Read error in TBranchProxy.");
            return 0;
         }
         if (!proxy->GetWhere()) {
            Error("TSTLReader::GetCP()", "Logic error, proxy object not set in TBranchProxy.");
            return 0;
         }
         if (proxy->IsaPointer()) {
            if (proxy->GetWhere() && *(void**)proxy->GetWhere()){
               ((TGenCollectionProxy*)proxy->GetCollection())->PopProxy();
               ((TGenCollectionProxy*)proxy->GetCollection())->PushProxy(*(void**)proxy->GetWhere());
            }
            else return 0;
         }
         fReadStatus = TTreeReaderValueBase::kReadSuccess;
         return (TVirtualCollectionProxy*) proxy->GetCollection();
      }

      virtual size_t GetSize(ROOT::Detail::TBranchProxy* proxy) {
         TVirtualCollectionProxy *myCollectionProxy = GetCP(proxy);
         if (!myCollectionProxy) return 0;
         return myCollectionProxy->Size();
      }

      virtual void* At(ROOT::Detail::TBranchProxy* proxy, size_t idx) {
         TVirtualCollectionProxy *myCollectionProxy = GetCP(proxy);
         if (!myCollectionProxy) return 0;
         if (myCollectionProxy->HasPointers()){
            return *(void**)myCollectionProxy->At(idx);
         }
         else {
            return myCollectionProxy->At(idx);
         }
      }
   };

   class TCollectionLessSTLReader : public TVirtualCollectionReader {
   private:
      TVirtualCollectionProxy *localCollection;
   public:
      TCollectionLessSTLReader(TVirtualCollectionProxy *proxy) : localCollection(proxy) {}

      TVirtualCollectionProxy* GetCP(ROOT::Detail::TBranchProxy* proxy) {
         if (!proxy->Read()) {
            fReadStatus = TTreeReaderValueBase::kReadError;
            Error("TCollectionLessSTLReader::GetCP()", "Read error in TBranchProxy.");
            return 0;
         }
         if (!proxy->GetWhere()) {
            Error("TCollectionLessSTLReader::GetCP()", "Logic error, proxy object not set in TBranchProxy.");
            return 0;
         }
         fReadStatus = TTreeReaderValueBase::kReadSuccess;
         return localCollection;
      }

      virtual size_t GetSize(ROOT::Detail::TBranchProxy* proxy) {
         TVirtualCollectionProxy *myCollectionProxy = GetCP(proxy);
         if (!myCollectionProxy) return 0;
         TVirtualCollectionProxy::TPushPop ppRaii(myCollectionProxy, proxy->GetWhere());
         return myCollectionProxy->Size();
      }

      virtual void* At(ROOT::Detail::TBranchProxy* proxy, size_t idx) {
         TVirtualCollectionProxy *myCollectionProxy = GetCP(proxy);
         if (!myCollectionProxy) return 0;
         TVirtualCollectionProxy::TPushPop ppRaii(myCollectionProxy, proxy->GetWhere());
         if (myCollectionProxy->HasPointers()){
            return *(void**)myCollectionProxy->At(idx);
         } else {
            return myCollectionProxy->At(idx);
         }
      }
   };


   // Reader interface for leaf list
   // SEE TTreeProxyGenerator.cxx:1319: '//We have a top level raw type'
   class TObjectArrayReader: public TVirtualCollectionReader {
   private:
      Int_t basicTypeSize;
   public:
      TObjectArrayReader() : basicTypeSize(-1) { }
      ~TObjectArrayReader() {}
      TVirtualCollectionProxy* GetCP(ROOT::Detail::TBranchProxy* proxy) {
         if (!proxy->Read()){
            fReadStatus = TTreeReaderValueBase::kReadError;
            Error("TObjectArrayReader::GetCP()", "Read error in TBranchProxy.");
            return 0;
         }
         fReadStatus = TTreeReaderValueBase::kReadSuccess;
         return (TVirtualCollectionProxy*) proxy->GetCollection();
      }
      virtual size_t GetSize(ROOT::Detail::TBranchProxy* proxy) {
         TVirtualCollectionProxy *myCollectionProxy = GetCP(proxy);
         if (!myCollectionProxy) return 0;
         return myCollectionProxy->Size();
      }
      virtual void* At(ROOT::Detail::TBranchProxy* proxy, size_t idx) {
         if (!proxy->Read()) return 0;

         Int_t objectSize;
         void *array = (void*)proxy->GetStart();

         if (basicTypeSize == -1){
            TClass *myClass = proxy->GetClass();
            if (!myClass){
               Error("TObjectArrayReader::At()", "Cannot get class info from branch proxy.");
               return 0;
            }
            objectSize = myClass->GetClassSize();
         }
         else {
            objectSize = basicTypeSize;
         }
         return (void*)((Byte_t*)array + (objectSize * idx));
      }

      void SetBasicTypeSize(Int_t size){
         basicTypeSize = size;
      }
   };

   class TArrayParameterSizeReader : public TObjectArrayReader {
   private:
      // The index can be of type int or unsigned int.
      std::pair<TTreeReaderValue<Int_t>, TTreeReaderValue<UInt_t>> fIndexReader;
   public:
      TArrayParameterSizeReader(TTreeReader *treeReader, const char *branchName)
         {
            if (TLeaf* sizeLeaf = treeReader->GetTree()->FindLeaf(branchName)) {
               if (sizeLeaf->IsUnsigned()) {
                  fIndexReader.second = TTreeReaderValue<UInt_t>(*treeReader, branchName);
               } else {
                  fIndexReader.first = TTreeReaderValue<Int_t>(*treeReader, branchName);
               }
            }
         }

      virtual size_t GetSize(ROOT::Detail::TBranchProxy* /*proxy*/) {
         if (fIndexReader.first.IsValid())
            return *fIndexReader.first;
         return *fIndexReader.second;
      }
   };

   // Reader interface for fixed size arrays
   class TArrayFixedSizeReader : public TObjectArrayReader {
   private:
      Int_t size;

   public:
      TArrayFixedSizeReader(Int_t sizeArg) : size(sizeArg) {}
{'fraction_non_alphanumeric': 0.13292511799974485, 'fraction_numerical': 0.004847557086363056, 'mean_word_length': 2.5281278127812783, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 86, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7378851', 'n_tokens_mistral': 4384, 'n_tokens_neox': 4295, 'n_words': 896}