Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TTreeReaderArray.cxx
Go to the documentation of this file.
1// @(#)root/treeplayer:$Id$
2// Author: Axel Naumann, 2011-09-28
3
4/*************************************************************************
5 * Copyright (C) 1995-2013, Rene Brun and Fons Rademakers and al. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TTreeReaderArray.h"
13
14#include "TBranchClones.h"
15#include "TBranchElement.h"
16#include "TBranchRef.h"
17#include "TBranchSTL.h"
18#include "TBranchObject.h"
20#include "TClassEdit.h"
21#include "TEnum.h"
22#include "TFriendElement.h"
23#include "TFriendProxy.h"
24#include "TLeaf.h"
25#include "TList.h"
26#include "TROOT.h"
27#include "TStreamerInfo.h"
28#include "TStreamerElement.h"
29#include "TTreeReader.h"
30#include "TGenCollectionProxy.h"
31#include "TRegexp.h"
32
33#include <memory>
34#include <optional>
35#include <iostream>
36
37// pin vtable
39
40namespace {
41using namespace ROOT::Internal;
42
43// Reader interface for clones arrays
44class TClonesReader : public TVirtualCollectionReader {
45public:
46 TClonesReader() = default;
47 ~TClonesReader() override = default;
48 TClonesReader(const TClonesReader &) = delete;
49 TClonesReader &operator=(const TClonesReader &) = delete;
50 TClonesReader(TClonesReader &&) = delete;
51 TClonesReader &operator=(TClonesReader &&) = delete;
52
54 {
55 if (!proxy->Read()) {
58 Error("TClonesReader::GetCA()", "Read error in TBranchProxy.");
59 return nullptr;
60 }
62 return (TClonesArray *)proxy->GetWhere();
63 }
64 size_t GetSize(ROOT::Detail::TBranchProxy *proxy) override
65 {
66 TClonesArray *myClonesArray = GetCA(proxy);
67 if (myClonesArray) {
68 return myClonesArray->GetEntries();
69 } else
70 return 0;
71 }
72 void *At(ROOT::Detail::TBranchProxy *proxy, size_t idx) override
73 {
74 TClonesArray *myClonesArray = GetCA(proxy);
75 if (myClonesArray) {
76 return myClonesArray->UncheckedAt(idx);
77 } else
78 return nullptr;
79 }
80
81 bool IsContiguous(ROOT::Detail::TBranchProxy *) override { return false; }
82
83 std::size_t GetValueSize(ROOT::Detail::TBranchProxy *proxy) override
84 {
85 if (!proxy->Read()) {
88 Error("TClonesReader::GetValueSize()", "Read error in TBranchProxy.");
89 return 0;
90 }
92 return proxy->GetValueSize();
93 }
94};
95
96bool IsCPContiguous(const TVirtualCollectionProxy &cp)
97{
99 return true;
100
101 switch (cp.GetCollectionType()) {
102 case ROOT::kSTLvector:
103 case ROOT::kROOTRVec: return true;
104 default: return false;
105 }
106}
107
108UInt_t GetCPValueSize(const TVirtualCollectionProxy &cp)
109{
110 if (auto cl = cp.GetValueClass())
111 return cl->Size();
112
113 auto &&eDataType = cp.GetType();
114 auto *tDataType = TDataType::GetDataType(eDataType);
115 return tDataType ? tDataType->Size() : 0;
116}
117
118// Reader interface for STL
119class TSTLReader final : public TVirtualCollectionReader {
120public:
121 ~TSTLReader() override {}
123 {
124 if (!proxy->Read()) {
127 Error("TSTLReader::GetCP()", "Read error in TBranchProxy.");
128 return nullptr;
129 }
130 if (!proxy->GetWhere()) {
131 Error("TSTLReader::GetCP()", "Logic error, proxy object not set in TBranchProxy.");
132 return nullptr;
133 }
135 return (TVirtualCollectionProxy *)proxy->GetCollection();
136 }
137
138 size_t GetSize(ROOT::Detail::TBranchProxy *proxy) override
139 {
140 TVirtualCollectionProxy *myCollectionProxy = GetCP(proxy);
141 if (!myCollectionProxy)
142 return 0;
143 return myCollectionProxy->Size();
144 }
145
146 void *At(ROOT::Detail::TBranchProxy *proxy, size_t idx) override
147 {
148 TVirtualCollectionProxy *myCollectionProxy = GetCP(proxy);
149 if (!myCollectionProxy)
150 return nullptr;
151 if (myCollectionProxy->HasPointers()) {
152 return *(void **)myCollectionProxy->At(idx);
153 } else {
154 return myCollectionProxy->At(idx);
155 }
156 }
157
158 bool IsContiguous(ROOT::Detail::TBranchProxy *proxy) override
159 {
160 auto cp = GetCP(proxy);
161 return IsCPContiguous(*cp);
162 }
163
164 std::size_t GetValueSize(ROOT::Detail::TBranchProxy *proxy) override
165 {
166 auto cp = GetCP(proxy);
167 return GetCPValueSize(*cp);
168 }
169};
170
171class TCollectionLessSTLReader final : public TVirtualCollectionReader {
172private:
173 TVirtualCollectionProxy *fLocalCollection;
174
175public:
176 TCollectionLessSTLReader(TVirtualCollectionProxy *proxy) : fLocalCollection(proxy) {}
177
179 {
180 if (!proxy->Read()) {
183 Error("TCollectionLessSTLReader::GetCP()", "Read error in TBranchProxy.");
184 return nullptr;
185 }
186 if (!proxy->GetWhere()) {
187 Error("TCollectionLessSTLReader::GetCP()", "Logic error, proxy object not set in TBranchProxy.");
188 return nullptr;
189 }
191 return fLocalCollection;
192 }
193
194 size_t GetSize(ROOT::Detail::TBranchProxy *proxy) override
195 {
196 TVirtualCollectionProxy *myCollectionProxy = GetCP(proxy);
197 if (!myCollectionProxy)
198 return 0;
199 /// In the case of std::vector<bool> `PushProxy` also creates a temporary bool variable the address of which
200 /// is returned from these calls.
201 myCollectionProxy->PopProxy();
202 myCollectionProxy->PushProxy(proxy->GetWhere());
203 return myCollectionProxy->Size();
204 }
205
206 void *At(ROOT::Detail::TBranchProxy *proxy, size_t idx) override
207 {
208 TVirtualCollectionProxy *myCollectionProxy = GetCP(proxy);
209 if (!myCollectionProxy)
210 return nullptr;
211 // Here we do not use a RAII but we empty the proxy to then fill it.
212 // This is done because we are returning a pointer and we need to keep
213 // alive the memory it points to.
214 myCollectionProxy->PopProxy();
215 myCollectionProxy->PushProxy(proxy->GetWhere());
216 if (myCollectionProxy->HasPointers()) {
217 return *(void **)myCollectionProxy->At(idx);
218 } else {
219 return myCollectionProxy->At(idx);
220 }
221 }
222
223 bool IsContiguous(ROOT::Detail::TBranchProxy *proxy) override
224 {
225 auto cp = GetCP(proxy);
226 return IsCPContiguous(*cp);
227 }
228
229 std::size_t GetValueSize(ROOT::Detail::TBranchProxy *proxy) override
230 {
231 auto cp = GetCP(proxy);
232 return GetCPValueSize(*cp);
233 }
234};
235
236// Reader interface for leaf list
237// SEE TTreeProxyGenerator.cxx:1319: '//We have a top level raw type'
238class TObjectArrayReader : public TVirtualCollectionReader {
239private:
240 Int_t fBasicTypeSize;
241
242public:
243 TObjectArrayReader() : fBasicTypeSize(-1) {}
244 ~TObjectArrayReader() override {}
246 {
247 if (!proxy->Read()) {
250 Error("TObjectArrayReader::GetCP()", "Read error in TBranchProxy.");
251 return nullptr;
252 }
254 return (TVirtualCollectionProxy *)proxy->GetCollection();
255 }
256 size_t GetSize(ROOT::Detail::TBranchProxy *proxy) override
257 {
258 TVirtualCollectionProxy *myCollectionProxy = GetCP(proxy);
259 if (!myCollectionProxy)
260 return 0;
261 return myCollectionProxy->Size();
262 }
263 void *At(ROOT::Detail::TBranchProxy *proxy, size_t idx) override
264 {
265 if (!proxy->Read())
266 return nullptr;
267
268 Int_t objectSize;
269 void *array = (void *)proxy->GetStart();
270
271 if (fBasicTypeSize == -1) {
272 TClass *myClass = proxy->GetClass();
273 if (!myClass) {
274 Error("TObjectArrayReader::At()", "Cannot get class info from branch proxy.");
275 return nullptr;
276 }
277 objectSize = myClass->GetClassSize();
278 } else {
279 objectSize = fBasicTypeSize;
280 }
281 return (void *)((Byte_t *)array + (objectSize * idx));
282 }
283
284 void SetBasicTypeSize(Int_t size) { fBasicTypeSize = size; }
285
286 bool IsContiguous(ROOT::Detail::TBranchProxy *) override { return true; }
287
288 std::size_t GetValueSize(ROOT::Detail::TBranchProxy *proxy) override
289 {
290 auto cp = GetCP(proxy);
291 if (cp)
292 return GetCPValueSize(*cp);
293 else
294 return proxy->GetValueSize();
295 }
296};
297
298template <class BASE>
299class TDynamicArrayReader : public BASE {
300
301 // TVirtualSizeReaderImpl and TSizeReaderImpl type-erase the reading of the size leaf.
302 class TVirtualSizeReaderImpl {
303 public:
304 virtual ~TVirtualSizeReaderImpl() = default;
305 virtual size_t GetSize() = 0;
306 };
307
308 template <typename T>
309 class TSizeReaderImpl final : public TVirtualSizeReaderImpl {
310 TTreeReaderValue<T> fSizeReader;
311
312 public:
313 TSizeReaderImpl(TTreeReader &r, const char *leafName) : fSizeReader(r, leafName) {}
314 size_t GetSize() final { return *fSizeReader; }
315 };
316
317 std::unique_ptr<TVirtualSizeReaderImpl> fSizeReader;
318
319public:
320 template <class... ARGS>
321 TDynamicArrayReader(TTreeReader *treeReader, const char *leafName, ARGS &&...args)
322 : BASE(std::forward<ARGS>(args)...)
323 {
324 std::string foundLeafName = leafName;
325 TLeaf *sizeLeaf = treeReader->GetTree()->FindLeaf(foundLeafName.c_str());
326
327 if (!sizeLeaf) {
328 // leafName might be "top.currentParent.N". But "N" might really be "top.N"!
329 // Strip parents until we find the leaf.
330 std::string leafNameNoParent = leafName;
331 std::string parent;
332 auto posLastDot = leafNameNoParent.rfind('.');
333 if (posLastDot != leafNameNoParent.npos) {
334 parent = leafNameNoParent.substr(0, posLastDot);
335 leafNameNoParent.erase(0, posLastDot + 1);
336 }
337
338 do {
339 if (!sizeLeaf && !parent.empty()) {
340 auto posLastDotParent = parent.rfind('.');
341 if (posLastDotParent != parent.npos)
342 parent = parent.substr(0, posLastDot);
343 else
344 parent.clear();
345 }
346
347 foundLeafName = parent;
348 if (!parent.empty())
349 foundLeafName += ".";
350 foundLeafName += leafNameNoParent;
351 sizeLeaf = treeReader->GetTree()->FindLeaf(foundLeafName.c_str());
352 } while (!sizeLeaf && !parent.empty());
353 }
354
355 if (!sizeLeaf) {
356 Error("TDynamicArrayReader ", "Cannot find leaf count for %s or any parent branch!", leafName);
357 return;
358 }
359
360 SetSizeReader(*treeReader, *sizeLeaf, foundLeafName.c_str());
361 }
362
363 /// Read the size from the given size leaf. `sizeBranchName` is the full name of the size branch, used to
364 /// create the size reader; unlike the constructor above, this does not search the tree for the leaf by name.
365 template <class... ARGS>
366 TDynamicArrayReader(TTreeReader *treeReader, TLeaf *sizeLeaf, const char *sizeBranchName, ARGS &&...args)
367 : BASE(std::forward<ARGS>(args)...)
368 {
369 SetSizeReader(*treeReader, *sizeLeaf, sizeBranchName);
370 }
371
372private:
373 void SetSizeReader(TTreeReader &treeReader, TLeaf &sizeLeaf, const char *sizeBranchName)
374 {
375 const std::string leafType = sizeLeaf.GetTypeName();
376 if (leafType == "Int_t") {
377 fSizeReader.reset(new TSizeReaderImpl<Int_t>(treeReader, sizeBranchName));
378 } else if (leafType == "UInt_t") {
379 fSizeReader.reset(new TSizeReaderImpl<UInt_t>(treeReader, sizeBranchName));
380 } else if (leafType == "Short_t") {
381 fSizeReader.reset(new TSizeReaderImpl<Short_t>(treeReader, sizeBranchName));
382 } else if (leafType == "UShort_t") {
383 fSizeReader.reset(new TSizeReaderImpl<UShort_t>(treeReader, sizeBranchName));
384 } else if (leafType == "Long_t") {
385 fSizeReader.reset(new TSizeReaderImpl<Long_t>(treeReader, sizeBranchName));
386 } else if (leafType == "ULong_t") {
387 fSizeReader.reset(new TSizeReaderImpl<ULong_t>(treeReader, sizeBranchName));
388 } else if (leafType == "Long64_t") {
389 fSizeReader.reset(new TSizeReaderImpl<Long64_t>(treeReader, sizeBranchName));
390 } else if (leafType == "ULong64_t") {
391 fSizeReader.reset(new TSizeReaderImpl<ULong64_t>(treeReader, sizeBranchName));
392 } else {
393 Error("TDynamicArrayReader ",
394 "Unsupported size type for leaf %s. Supported types are int, short int, long int, long long int and "
395 "their unsigned counterparts.",
396 sizeBranchName);
397 }
398 }
399
400public:
401 size_t GetSize(ROOT::Detail::TBranchProxy * /*proxy*/) override { return fSizeReader->GetSize(); }
402};
403
404class TArrayParameterSizeReader : public TDynamicArrayReader<TObjectArrayReader> {
405public:
406 TArrayParameterSizeReader(TTreeReader *treeReader, const char *branchName)
407 : TDynamicArrayReader<TObjectArrayReader>(treeReader, branchName)
408 {
409 }
410
411 /// Use the counter branch directly: its short name ("fN") can match the counter of another
412 /// top-level branch when the top-level branch names have no trailing dot.
413 TArrayParameterSizeReader(TTreeReader *treeReader, TBranchElement *sizeBranch)
414 : TDynamicArrayReader<TObjectArrayReader>(treeReader, static_cast<TLeaf *>(sizeBranch->GetListOfLeaves()->At(0)),
415 sizeBranch->GetFullName().Data())
416 {
417 }
418};
419
420// Reader interface for fixed size arrays
421class TArrayFixedSizeReader : public TObjectArrayReader {
422private:
423 Int_t fSize;
424
425public:
426 TArrayFixedSizeReader(Int_t sizeArg) : fSize(sizeArg) {}
427
428 size_t GetSize(ROOT::Detail::TBranchProxy * /*proxy*/) override { return fSize; }
429};
430
431class TBasicTypeArrayReader final : public TVirtualCollectionReader {
432public:
433 ~TBasicTypeArrayReader() override {}
434
436 {
437 if (!proxy->Read()) {
440 Error("TBasicTypeArrayReader::GetCP()", "Read error in TBranchProxy.");
441 return nullptr;
442 }
444 return (TVirtualCollectionProxy *)proxy->GetCollection();
445 }
446
447 size_t GetSize(ROOT::Detail::TBranchProxy *proxy) override
448 {
449 TVirtualCollectionProxy *myCollectionProxy = GetCP(proxy);
450 if (!myCollectionProxy)
451 return 0;
452 return myCollectionProxy->Size();
453 }
454
455 void *At(ROOT::Detail::TBranchProxy *proxy, size_t idx) override
456 {
457 TVirtualCollectionProxy *myCollectionProxy = GetCP(proxy);
458 if (!myCollectionProxy)
459 return nullptr;
460 return (Byte_t *)myCollectionProxy->At(idx) + proxy->GetOffset();
461 }
462
463 bool IsContiguous(ROOT::Detail::TBranchProxy *) override { return false; }
464
465 std::size_t GetValueSize(ROOT::Detail::TBranchProxy *proxy) override
466 {
467 if (!proxy->Read()) {
470 Error("TBasicTypeArrayReader::GetValueSize()", "Read error in TBranchProxy.");
471 return 0;
472 }
474 return proxy->GetValueSize();
475 }
476};
477
478class TBasicTypeClonesReader final : public TClonesReader {
479private:
480 Int_t fOffset;
481
482public:
483 TBasicTypeClonesReader(Int_t offsetArg) : fOffset(offsetArg) {}
484
485 ~TBasicTypeClonesReader() final = default;
486 TBasicTypeClonesReader(const TBasicTypeClonesReader &) = delete;
487 TBasicTypeClonesReader &operator=(const TBasicTypeClonesReader &) = delete;
488 TBasicTypeClonesReader(TBasicTypeClonesReader &&) = delete;
489 TBasicTypeClonesReader &operator=(TBasicTypeClonesReader &&) = delete;
490
491 void *At(ROOT::Detail::TBranchProxy *proxy, size_t idx) override
492 {
493 TClonesArray *myClonesArray = GetCA(proxy);
494 if (!myClonesArray)
495 return nullptr;
496 return (Byte_t *)myClonesArray->At(idx) + fOffset;
497 }
498};
499
500class TLeafReader : public TVirtualCollectionReader {
501private:
502 TTreeReaderValueBase *fValueReader;
503 Int_t fElementSize;
504
505public:
506 TLeafReader(TTreeReaderValueBase *valueReaderArg) : fValueReader(valueReaderArg), fElementSize(-1) {}
507
508 size_t GetSize(ROOT::Detail::TBranchProxy * /*proxy*/) override
509 {
510 TLeaf *myLeaf = fValueReader->GetLeaf();
511 return myLeaf ? myLeaf->GetLen() : 0; // Error will be printed by GetLeaf
512 }
513
514 void *At(ROOT::Detail::TBranchProxy * /*proxy*/, size_t idx) override
515 {
516 ProxyRead();
517 void *address = fValueReader->GetAddress();
518 if (fElementSize == -1) {
519 TLeaf *myLeaf = fValueReader->GetLeaf();
520 if (!myLeaf)
521 return nullptr; // Error will be printed by GetLeaf
522 fElementSize = myLeaf->GetLenType();
523 }
524 return (Byte_t *)address + (fElementSize * idx);
525 }
526
527 bool IsContiguous(ROOT::Detail::TBranchProxy *) override { return true; }
528
529 std::size_t GetValueSize(ROOT::Detail::TBranchProxy *) override
530 {
531 auto *leaf = fValueReader->GetLeaf();
532 return leaf ? leaf->GetLenType() : 0;
533 }
534
535protected:
536 void ProxyRead() { fValueReader->ProxyRead(); }
537};
538
539class TLeafParameterSizeReader : public TDynamicArrayReader<TLeafReader> {
540public:
541 TLeafParameterSizeReader(TTreeReader *treeReader, const char *leafName, TTreeReaderValueBase *valueReaderArg)
542 : TDynamicArrayReader<TLeafReader>(treeReader, leafName, valueReaderArg)
543 {
544 }
545
546 size_t GetSize(ROOT::Detail::TBranchProxy *proxy) override
547 {
548 ProxyRead();
549 return TDynamicArrayReader<TLeafReader>::GetSize(proxy);
550 }
551};
552} // namespace
553
554
555////////////////////////////////////////////////////////////////////////////////
556/// Create the proxy object for our branch.
557
559{
560 if (fProxy) {
561 return;
562 }
563
564 fSetupStatus = kSetupInternalError; // Fallback; set to something concrete below.
565 if (!fTreeReader) {
566 Error("TTreeReaderArrayBase::CreateProxy()", "TTreeReader object not set / available for branch %s!",
567 fBranchName.Data());
568 fSetupStatus = kSetupTreeDestructed;
569 return;
570 }
571 if (!fDict) {
572 TBranch *br = fTreeReader->GetTree()->GetBranch(fBranchName);
573 const char *brDataType = "{UNDETERMINED}";
574 if (br) {
575 TDictionary *dictUnused = nullptr;
576 brDataType = GetBranchDataType(br, dictUnused, fDict);
577 }
578 Error("TTreeReaderArrayBase::CreateProxy()",
579 "The template argument type T of %s accessing branch %s (which contains data of type %s) is not known to "
580 "ROOT. You will need to create a dictionary for it.",
581 GetDerivedTypeName(), fBranchName.Data(), brDataType);
582 fSetupStatus = kSetupMissingDictionary;
583 return;
584 }
585
586 // Access a branch's collection content (not the collection itself)
587 // through a proxy.
588 // Search for the branchname, determine what it contains, and wire the
589 // TBranchProxy representing it to us so we can access its data.
590
591 // Tell the branch proxy to suppress the errors for missing branch if this
592 // branch name is found in the list of suppressions
593 const bool suppressErrorsForThisBranch = (fTreeReader->fSuppressErrorsForMissingBranches.find(fBranchName.Data()) !=
594 fTreeReader->fSuppressErrorsForMissingBranches.cend());
595
596 TDictionary *branchActualType = nullptr;
597 TBranch *branch = nullptr;
598 TLeaf *myLeaf = nullptr;
599 if (!GetBranchAndLeaf(branch, myLeaf, branchActualType, suppressErrorsForThisBranch))
600 return;
601
602 if (!fDict) {
603 Error("TTreeReaderArrayBase::CreateProxy()", "No dictionary for branch %s.", fBranchName.Data());
604 return;
605 }
606
607 TNamedBranchProxy *namedProxy = fTreeReader->FindProxy(fBranchName);
608 if (namedProxy) {
609 if (namedProxy->GetContentDict() == fDict) {
610 fSetupStatus = kSetupMatch;
611 fProxy = namedProxy->GetProxy();
612 SetImpl(branch, myLeaf);
613 return;
614 }
615
616 // Update named proxy's dictionary
617 if (!namedProxy->GetContentDict()) {
618 namedProxy->SetContentDict(fDict);
619 fProxy = namedProxy->GetProxy();
620 if (fProxy)
621 fSetupStatus = kSetupMatch;
622 } else {
623 Error("TTreeReaderArrayBase::CreateProxy()", "Type ambiguity (want %s, have %s) for branch %s.",
624 fDict->GetName(), namedProxy->GetContentDict()->GetName(), fBranchName.Data());
625 }
626 } else {
627 TString membername;
628
629 bool isTopLevel = branch->GetMother() == branch;
630 if (!isTopLevel) {
631 membername = strrchr(branch->GetName(), '.');
632 if (membername.IsNull()) {
633 membername = branch->GetName();
634 }
635 }
636 auto *director = fTreeReader->fDirector.get();
637 // Determine if the branch is actually in a Friend TTree and if so which.
638 if (branch->GetTree() != fTreeReader->GetTree()->GetTree()) {
639 // It is in a friend, let's find the 'index' in the list of friend ...
640 std::optional<std::size_t> index;
641 std::size_t current{};
642 auto &&friends = fTreeReader->GetTree()->GetTree()->GetListOfFriends();
643 for (auto fe : TRangeDynCast<TFriendElement>(friends)) {
644 if (branch->GetTree() == fe->GetTree()) {
645 index = current;
646 break;
647 }
648 ++current;
649 }
650 if (!index.has_value()) {
651 Error("TTreeReaderArrayBase::CreateProxy()",
652 "The branch %s is contained in a Friend TTree that is not directly attached to the main.\n"
653 "This is not yet supported by TTreeReader.",
654 fBranchName.Data());
655 return;
656 }
657
658 auto &&friendProxy = fTreeReader->AddFriendProxy(index.value());
659 director = friendProxy.GetDirector();
660 }
661 fTreeReader->AddProxy(
662 std::make_unique<TNamedBranchProxy>(director, branch, fBranchName, membername, suppressErrorsForThisBranch));
663
664 namedProxy = fTreeReader->FindProxy(fBranchName);
665 fProxy = namedProxy->GetProxy();
666 if (fProxy)
667 fSetupStatus = kSetupMatch;
668 else
669 fSetupStatus = kSetupMismatch;
670 }
671
672 if (!myLeaf) {
673 TString branchActualTypeName;
675 const char *nonCollTypeName = GetBranchContentDataType(branch, branchActualTypeName, branchActualType, arrInfo);
676 if (nonCollTypeName) {
677 Error("TTreeReaderArrayBase::CreateContentProxy()",
678 "The branch %s contains data of type %s, which should be accessed through a TTreeReaderValue< %s >.",
679 fBranchName.Data(), nonCollTypeName, nonCollTypeName);
680 if (fSetupStatus == kSetupInternalError)
681 fSetupStatus = kSetupNotACollection;
682 fProxy = nullptr;
683 return;
684 }
685 if (!branchActualType) {
686 if (branchActualTypeName.IsNull()) {
687 Error("TTreeReaderArrayBase::CreateContentProxy()",
688 "Cannot determine the type contained in the collection of branch %s. That's weird - please report!",
689 fBranchName.Data());
690 } else {
691 Error("TTreeReaderArrayBase::CreateContentProxy()",
692 "The branch %s contains data of type %s, which does not have a dictionary.", fBranchName.Data(),
693 branchActualTypeName.Data());
694 if (fSetupStatus == kSetupInternalError)
695 fSetupStatus = kSetupMissingDictionary;
696 }
697 fProxy = nullptr;
698 return;
699 }
700
701 auto matchingArrayInfo = [](TDictionary *requestedDict, const StreamerElementArrayInfo &info) {
702 // Support the case of a data member of a class being a std::array (or generally an n-dim fixed size array)
703 // In this case the 'left' TDictionary has been requested as a TClass (e.g. std::array<int, 3>) and thus
704 // will not be a TDataType, but the 'right' TDictionary will be retrieved as a TDataType (e.g. int), because
705 // of how the fixed-size array data member is streamed.
706 // The 'right' TDictionary in this case refers to a TBranchElement representing the data member. We already
707 // gathered the array info by accessing the TStreamerElement of the TBranchElement, now we need to do the same
708 // for the 'left' TDictionary, which represents what the user requested.
709 auto cl = dynamic_cast<TClass *>(requestedDict);
710 if (!cl)
711 return false;
712 auto streamerInfo = cl->GetStreamerInfo();
713 if (!streamerInfo)
714 return false;
715
716 auto streamerElements = streamerInfo->GetElements();
717 if (!streamerElements)
718 return false;
719
720 // This part of the logic currently supports the specific use cases where there is only one streamer element
721 // corresponding to the array data member that we are trying to partially read into a collection. Without
722 // further use cases surfacing, we do not support more than one streamer element
723 if (streamerElements->GetEntries() > 1)
724 return false;
725
726 auto streamerElement = dynamic_cast<TStreamerElement *>(streamerElements->At(0));
727 if (!streamerElement)
728 return false;
729
730 int dataTypeCode{};
731 if (auto *dataType = gROOT->GetType(streamerElement->GetTypeNameBasic()))
732 dataTypeCode = dataType->GetType();
733
734 auto checkArrayDims = [&]() {
735 for (int i = 0; i < info.fArrayNDims; i++) {
736 if (info.fArrayDims[i] != streamerElement->GetMaxIndex(i))
737 return false;
738 }
739 return true;
740 };
741
742 return streamerElement->GetArrayDim() == info.fArrayNDims &&
743 streamerElement->GetArrayLength() == info.fArrayCumulativeLength && checkArrayDims() &&
744 dataTypeCode == info.fTDataTypeCode;
745 };
746
747 auto matchingDataType = [&matchingArrayInfo](TDictionary *left, TDictionary *right,
748 const StreamerElementArrayInfo &info) -> bool {
749 if (left == right)
750 return true;
751 if (!left || !right)
752 return false;
753 auto left_datatype = dynamic_cast<TDataType *>(left);
754 auto right_datatype = dynamic_cast<TDataType *>(right);
755 auto left_enum = dynamic_cast<TEnum *>(left);
756 auto right_enum = dynamic_cast<TEnum *>(right);
757
758 if ((left_datatype && left_datatype->GetType() == kInt_t && right_enum) ||
759 (right_datatype && right_datatype->GetType() == kInt_t && left_enum))
760 return true;
761 if ((left_datatype && right_enum && left_datatype->GetType() == right_enum->GetUnderlyingType()) ||
762 (right_datatype && left_enum && right_datatype->GetType() == left_enum->GetUnderlyingType()))
763 return true;
764
765 // Allow reading nested std::array data members of top-level std::vector<Class> types. The user has requested
766 // e.g. TTreeReaderArray<std::array<int, 3>> and we allow partial reading of the std::vector<Class> as a
767 // collection of std::array<int, 3>
768 if (matchingArrayInfo(left, info))
769 return true;
770
771 // Allow reading a std::array data member of a top-level class branch when requesting a TTreeReaderArray
772 // of the same type as the std::array data type (e.g. branch contains std::array<int, 3> and user requests
773 // TTreeReaderArray<int>). In this case the 'left' dictionary is going to be a TDataType of int.
774 if (left_datatype) {
775 auto typeCode = left_datatype->GetType();
776 if (typeCode > 0 && typeCode == info.fTDataTypeCode)
777 return true;
778 }
779
780 if (!left_datatype || !right_datatype)
781 return false;
782 auto l = left_datatype->GetType();
783 auto r = right_datatype->GetType();
784 if (l > 0 && l == r)
785 return true;
786 else
787 return ((l == kDouble32_t && r == kDouble_t) || (l == kDouble_t && r == kDouble32_t) ||
788 (l == kFloat16_t && r == kFloat_t) || (l == kFloat_t && r == kFloat16_t));
789 };
790
791 if (!matchingDataType(fDict, branchActualType, arrInfo)) {
792 Error("TTreeReaderArrayBase::CreateContentProxy()",
793 "The branch %s contains data of type %s. It cannot be accessed by a TTreeReaderArray<%s>",
794 fBranchName.Data(), branchActualType->GetName(), fDict->GetName());
795 if (fSetupStatus == kSetupInternalError || fSetupStatus >= 0)
796 fSetupStatus = kSetupMismatch;
797
798 // Update named proxy's dictionary
799 if (!namedProxy->GetContentDict()) {
800 namedProxy->SetContentDict(fDict);
801 }
802
803 // fProxy = 0;
804 // return;
805 }
806 }
807
808 SetImpl(branch, myLeaf);
809}
810
811////////////////////////////////////////////////////////////////////////////////
812/// Determine the branch / leaf and its type; reset fProxy / fSetupStatus on error.
813
815 TDictionary *&branchActualType,
816 bool suppressErrorsForMissingBranch)
817{
818 myLeaf = nullptr;
819 branch = fTreeReader->GetTree()->GetBranch(fBranchName);
820 if (branch)
821 return true;
822
823 if (!fBranchName.Contains(".")) {
824 if (!suppressErrorsForMissingBranch) {
825 Error("TTreeReaderArrayBase::GetBranchAndLeaf()",
826 "The tree does not have a branch called %s. You could check with TTree::Print() for available branches.",
827 fBranchName.Data());
828 }
829 fSetupStatus = kSetupMissingBranch;
830 fProxy = nullptr;
831 return false;
832 }
833
834 TRegexp leafNameExpression("\\.[a-zA-Z0-9_]+$");
835 TString leafName(fBranchName(leafNameExpression));
836 TString branchName = fBranchName(0, fBranchName.Length() - leafName.Length());
837 branch = fTreeReader->GetTree()->GetBranch(branchName);
838 if (!branch) {
839 if (!suppressErrorsForMissingBranch) {
840 Error("TTreeReaderArrayBase::GetBranchAndLeaf()",
841 "The tree does not have a branch called %s. You could check with TTree::Print() for available branches.",
842 fBranchName.Data());
843 }
844 fSetupStatus = kSetupMissingBranch;
845 fProxy = nullptr;
846 return false;
847 }
848
849 myLeaf = branch->GetLeaf(TString(leafName(1, leafName.Length())));
850 if (!myLeaf) {
851 if (!suppressErrorsForMissingBranch) {
852 Error("TTreeReaderArrayBase::GetBranchAndLeaf()",
853 "The tree does not have a branch, nor a sub-branch called %s. You could check with TTree::Print() for "
854 "available branches.",
855 fBranchName.Data());
856 }
857 fSetupStatus = kSetupMissingBranch;
858 fProxy = nullptr;
859 return false;
860 }
861
863 if (!tempDict) {
864 Error("TTreeReaderArrayBase::GetBranchAndLeaf()", "Failed to get the dictionary for %s.", myLeaf->GetTypeName());
865 fSetupStatus = kSetupMissingDictionary;
866 fProxy = nullptr;
867 return false;
868 }
869
870 if (tempDict->IsA() == TDataType::Class() && fDict->IsA() == TDataType::Class() &&
871 ((TDataType *)tempDict)->GetType() == ((TDataType *)fDict)->GetType()) {
872 // fLeafOffset = myLeaf->GetOffset() / 4;
873 branchActualType = fDict;
874 fLeaf = myLeaf;
875 fBranchName = branchName;
876 fLeafName = leafName(1, leafName.Length());
877 fHaveLeaf = (fLeafName.Length() > 0);
878 fSetupStatus = kSetupMatchLeaf;
879 } else {
880 Error("TTreeReaderArrayBase::GetBranchAndLeaf()", "Leaf of type %s cannot be read by TTreeReaderValue<%s>.",
881 myLeaf->GetTypeName(), fDict->GetName());
882 fProxy = nullptr;
883 fSetupStatus = kSetupMismatch;
884 return false;
885 }
886 return true;
887}
888
889////////////////////////////////////////////////////////////////////////////////
890/// Create the TVirtualCollectionReader object for our branch.
891
893{
894 if (fImpl)
895 return;
896
897 // Access a branch's collection content (not the collection itself)
898 // through a proxy.
899 // Search for the branchname, determine what it contains, and wire the
900 // TBranchProxy representing it to us so we can access its data.
901 // A proxy for branch must not have been created before (i.e. check
902 // fProxies before calling this function!)
903
904 if (myLeaf) {
905 if (!myLeaf->GetLeafCount()) {
906 fImpl = std::make_unique<TLeafReader>(this);
907 } else {
908 TString leafFullName = myLeaf->GetBranch()->GetName();
909 leafFullName += ".";
910 leafFullName += myLeaf->GetLeafCount()->GetName();
911 fImpl = std::make_unique<TLeafParameterSizeReader>(fTreeReader, leafFullName.Data(), this);
912 }
913 fSetupStatus = kSetupMatchLeaf;
914 } else if (branch->IsA() == TBranchElement::Class()) {
915 TBranchElement *branchElement = ((TBranchElement *)branch);
916
917 TStreamerInfo *streamerInfo = branchElement->GetInfo();
918 Int_t id = branchElement->GetID();
919
920 if (id >= 0) { // Not root node?
921 // Int_t offset = streamerInfo->GetOffsets()[id];
922 TStreamerElement *element = (TStreamerElement *)streamerInfo->GetElements()->At(id);
923 // bool isPointer = element->IsaPointer();
924 // TClass *classPointer = element->GetClassPointer();
925
926 if (fSetupStatus == kSetupInternalError)
927 fSetupStatus = kSetupMatch;
928 if (element->IsA() == TStreamerSTL::Class()) {
929 if (branchElement->GetType() == 31) {
930 Error("TTreeReaderArrayBase::SetImpl", "STL Collection nested in a TClonesArray not yet supported");
931 fSetupStatus = kSetupInternalError;
932 return;
933 }
934 fImpl = std::make_unique<TSTLReader>();
935 } else if (element->IsA() == TStreamerObject::Class()) {
936 // fImpl = new TObjectArrayReader(); // BArray[12]
937
938 if (element->GetClass() == TClonesArray::Class()) {
939 fImpl = std::make_unique<TClonesReader>();
940 } else if (branchElement->GetType() == TBranchElement::kSTLMemberNode) {
941 fImpl = std::make_unique<TBasicTypeArrayReader>();
942 } else if (branchElement->GetType() == TBranchElement::kClonesMemberNode) {
943 // TBasicTypeClonesReader should work for object
944 fImpl = std::make_unique<TBasicTypeClonesReader>(element->GetOffset());
945 } else {
946 fImpl = std::make_unique<TArrayFixedSizeReader>(element->GetArrayLength());
947 }
948 } else if (element->IsA() == TStreamerLoop::Class()) {
949 fImpl = std::make_unique<TArrayParameterSizeReader>(fTreeReader, branchElement->GetBranchCount());
950 } else if (element->IsA() == TStreamerBasicType::Class()) {
951 if (branchElement->GetType() == TBranchElement::kSTLMemberNode) {
952 fImpl = std::make_unique<TBasicTypeArrayReader>();
953 } else if (branchElement->GetType() == TBranchElement::kClonesMemberNode) {
954 fImpl = std::make_unique<TBasicTypeClonesReader>(element->GetOffset());
955 } else if (fDict->IsA() == TEnum::Class()) {
956 fImpl = std::make_unique<TArrayFixedSizeReader>(element->GetArrayLength());
957 ((TObjectArrayReader *)fImpl.get())->SetBasicTypeSize(sizeof(Int_t));
958 } else {
959 fImpl = std::make_unique<TArrayFixedSizeReader>(element->GetArrayLength());
960 ((TObjectArrayReader *)fImpl.get())->SetBasicTypeSize(((TDataType *)fDict)->Size());
961 }
962 } else if (element->IsA() == TStreamerBasicPointer::Class()) {
963 fImpl = std::make_unique<TArrayParameterSizeReader>(fTreeReader, branchElement->GetBranchCount());
964 ((TArrayParameterSizeReader *)fImpl.get())->SetBasicTypeSize(((TDataType *)fDict)->Size());
965 } else if (element->IsA() == TStreamerBase::Class()) {
966 fImpl = std::make_unique<TClonesReader>();
967 } else {
968 Error("TTreeReaderArrayBase::SetImpl()", "Cannot read branch %s: unhandled streamer element type %s",
969 fBranchName.Data(), element->IsA()->GetName());
970 fSetupStatus = kSetupInternalError;
971 }
972 } else { // We are at root node?
973 if (branchElement->GetClass()->GetCollectionProxy()) {
974 fImpl = std::make_unique<TCollectionLessSTLReader>(branchElement->GetClass()->GetCollectionProxy());
975 }
976 }
977 } else if (branch->IsA() == TBranch::Class()) {
978 auto topLeaf = branch->GetLeaf(branch->GetName());
979 if (!topLeaf) {
980 Error("TTreeReaderArrayBase::SetImpl", "Failed to get the top leaf from the branch");
981 fSetupStatus = kSetupMissingBranch;
982 return;
983 }
984 // We could have used GetLeafCounter, but it does not work well with Double32_t and Float16_t: ROOT-10149
985 auto sizeLeaf = topLeaf->GetLeafCount();
986 if (fSetupStatus == kSetupInternalError)
987 fSetupStatus = kSetupMatch;
988 if (!sizeLeaf) {
989 fImpl = std::make_unique<TArrayFixedSizeReader>(topLeaf->GetLenStatic());
990 } else {
991 fImpl = std::make_unique<TArrayParameterSizeReader>(fTreeReader, sizeLeaf->GetName());
992 }
993 ((TObjectArrayReader *)fImpl.get())->SetBasicTypeSize(((TDataType *)fDict)->Size());
994 } else if (branch->IsA() == TBranchClones::Class()) {
995 Error("TTreeReaderArrayBase::SetImpl", "Support for branches of type TBranchClones not implemented");
996 fSetupStatus = kSetupInternalError;
997 } else if (branch->IsA() == TBranchObject::Class()) {
998 Error("TTreeReaderArrayBase::SetImpl", "Support for branches of type TBranchObject not implemented");
999 fSetupStatus = kSetupInternalError;
1000 } else if (branch->IsA() == TBranchSTL::Class()) {
1001 Error("TTreeReaderArrayBase::SetImpl", "Support for branches of type TBranchSTL not implemented");
1002 fImpl = std::make_unique<TSTLReader>();
1003 fSetupStatus = kSetupInternalError;
1004 } else if (branch->IsA() == TBranchRef::Class()) {
1005 Error("TTreeReaderArrayBase::SetImpl", "Support for branches of type TBranchRef not implemented");
1006 fSetupStatus = kSetupInternalError;
1007 }
1008}
1009
1012{
1013 StreamerElementArrayInfo arrInfo{};
1014 if (!element)
1015 return arrInfo;
1016
1017 arrInfo.fArrayNDims = element->GetArrayDim();
1018 arrInfo.fArrayCumulativeLength = element->GetArrayLength();
1019 if (auto *datatype = gROOT->GetType(element->GetTypeNameBasic())) {
1020 arrInfo.fTDataTypeCode = datatype->GetType();
1021 }
1022 for (int i = 0; i < arrInfo.fArrayNDims; ++i)
1023 arrInfo.fArrayDims[i] = element->GetMaxIndex(i);
1024
1025 return arrInfo;
1026}
1027
1028////////////////////////////////////////////////////////////////////////////////
1029/// Access a branch's collection content (not the collection itself)
1030/// through a proxy.
1031/// Retrieve the type of data contained in the collection stored by branch;
1032/// put its dictionary into dict, If there is no dictionary, put its type
1033/// name into contentTypeName.
1034/// The contentTypeName is set to NULL if the branch does not
1035/// contain a collection; in that case, the type of the branch is returned.
1036/// In all other cases, NULL is returned.
1037
1039 TDictionary *&dict,
1040 StreamerElementArrayInfo &arrInfo)
1041{
1042 dict = nullptr;
1043 contentTypeName = "";
1044 if (branch->IsA() == TBranchElement::Class()) {
1045 TBranchElement *brElement = (TBranchElement *)branch;
1046 if (brElement->GetType() == 4 || brElement->GetType() == 3) {
1047 TVirtualCollectionProxy *collProxy = brElement->GetCollectionProxy();
1048 if (collProxy) {
1049 TClass *myClass = collProxy->GetValueClass();
1050 if (!myClass) {
1051 Error("TTreeReaderArrayBase::GetBranchContentDataType()", "Could not get value class.");
1052 return nullptr;
1053 }
1054 dict = TDictionary::GetDictionary(myClass->GetName());
1055 if (!dict)
1056 dict = TDataType::GetDataType(collProxy->GetType());
1057 }
1058 if (!dict) {
1059 // We don't know the dictionary, thus we need the content's type name.
1060 // Determine it.
1061 if (brElement->GetType() == 3) {
1062 contentTypeName = brElement->GetClonesName();
1063 dict = TDictionary::GetDictionary(brElement->GetClonesName());
1064 return nullptr;
1065 }
1066 // STL:
1067 TClassEdit::TSplitType splitType(brElement->GetClassName());
1068 int isSTLCont = splitType.IsSTLCont();
1069 if (!isSTLCont) {
1070 Error("TTreeReaderArrayBase::GetBranchContentDataType()",
1071 "Cannot determine STL collection type of %s stored in branch %s", brElement->GetClassName(),
1072 branch->GetName());
1073 return brElement->GetClassName();
1074 }
1075 bool isMap = isSTLCont == ROOT::kSTLmap || isSTLCont == ROOT::kSTLmultimap;
1076 if (isMap)
1077 contentTypeName = "std::pair< ";
1078 contentTypeName += splitType.fElements[1];
1079 if (isMap) {
1080 contentTypeName += splitType.fElements[2];
1081 contentTypeName += " >";
1082 }
1083 return nullptr;
1084 }
1085 return nullptr;
1086 } else if (brElement->GetType() == 31 || brElement->GetType() == 41) {
1087 // it's a member, extract from GetClass()'s streamer info
1088 TClass *clData = nullptr;
1089 EDataType dtData = kOther_t;
1090 int ExpectedTypeRet = brElement->GetExpectedType(clData, dtData);
1091 if (ExpectedTypeRet == 0) {
1092 dict = clData;
1093 if (!dict) {
1094 if (dtData == kFloat16_t) {
1095 dtData = kFloat_t;
1096 }
1097 if (dtData == kDouble32_t) {
1098 dtData = kDouble_t;
1099 }
1100 dict = TDataType::GetDataType(dtData);
1101 }
1102 if (!dict) {
1103 Error("TTreeReaderArrayBase::GetBranchContentDataType()",
1104 "The branch %s contains a data type %d for which the dictionary cannot be retrieved.",
1105 branch->GetName(), (int)dtData);
1106 contentTypeName = TDataType::GetTypeName(dtData);
1107 return nullptr;
1108 }
1109 // Fill information about the data member being an n-dim array
1110 arrInfo = FillStreamerElementArrayInfo(brElement->GetInfo()->GetElement(brElement->GetID()));
1111 return nullptr;
1112 } else if (ExpectedTypeRet == 1) {
1113 int brID = brElement->GetID();
1114 if (brID == -1) {
1115 // top
1116 Error("TTreeReaderArrayBase::GetBranchContentDataType()",
1117 "The branch %s contains data of type %s for which the dictionary does not exist. It's needed.",
1118 branch->GetName(), brElement->GetClassName());
1119 contentTypeName = brElement->GetClassName();
1120 return nullptr;
1121 }
1122 // Either the data type name doesn't have an EDataType entry
1123 // or the streamer info doesn't have a TClass* attached.
1124 TStreamerElement *element = (TStreamerElement *)brElement->GetInfo()->GetElement(brID);
1125 contentTypeName = element->GetTypeName();
1126 return nullptr;
1127 }
1128 /* else (ExpectedTypeRet == 2)*/
1129 // The streamer info entry cannot be found.
1130 // TBranchElement::GetExpectedType() has already complained.
1131 return "{CANNOT DETERMINE TBranchElement DATA TYPE}";
1132 } else if (brElement->GetType() == TBranchElement::kLeafNode) {
1133 TStreamerInfo *streamerInfo = brElement->GetInfo();
1134 Int_t id = brElement->GetID();
1135
1136 if (id >= 0) {
1137 TStreamerElement *element = (TStreamerElement *)streamerInfo->GetElements()->At(id);
1138 // Fill information about the data member being an n-dim array
1139 arrInfo = FillStreamerElementArrayInfo(element);
1140 if (element->IsA() == TStreamerSTL::Class()) {
1141 TClass *myClass = brElement->GetCurrentClass();
1142 if (!myClass) {
1143 Error("TTreeReaderArrayBase::GetBranchDataType()", "Could not get class from branch element.");
1144 return nullptr;
1145 }
1146 TVirtualCollectionProxy *myCollectionProxy = myClass->GetCollectionProxy();
1147 if (!myCollectionProxy) {
1148 Error("TTreeReaderArrayBase::GetBranchDataType()", "Could not get collection proxy from STL class");
1149 return nullptr;
1150 }
1151 // Try getting the contained class
1152 dict = myCollectionProxy->GetValueClass();
1153 // If it fails, try to get the contained type as a primitive type
1154 if (!dict)
1155 dict = TDataType::GetDataType(myCollectionProxy->GetType());
1156 if (!dict) {
1157 Error("TTreeReaderArrayBase::GetBranchDataType()", "Could not get valueClass from collectionProxy.");
1158 return nullptr;
1159 }
1160 contentTypeName = dict->GetName();
1161 return nullptr;
1162 } else if (element->IsA() == TStreamerObject::Class() && !strcmp(element->GetTypeName(), "TClonesArray")) {
1163 if (!fProxy->Setup() || !fProxy->Read()) {
1164 Error("TTreeReaderArrayBase::GetBranchContentDataType()",
1165 "Failed to get type from proxy, unable to check type");
1166 contentTypeName = "UNKNOWN";
1167 dict = nullptr;
1168 return contentTypeName;
1169 }
1170 TClonesArray *myArray = (TClonesArray *)fProxy->GetWhere();
1171 dict = myArray->GetClass();
1172 contentTypeName = dict->GetName();
1173 return nullptr;
1174 } else {
1175 dict = brElement->GetCurrentClass();
1176 if (!dict) {
1177 TDictionary *myDataType = TDictionary::GetDictionary(brElement->GetTypeName());
1178 dict = TDataType::GetDataType((EDataType)((TDataType *)myDataType)->GetType());
1179 }
1180 contentTypeName = brElement->GetTypeName();
1181 return nullptr;
1182 }
1183 }
1184 if (brElement->GetCurrentClass() == TClonesArray::Class()) {
1185 contentTypeName = "TClonesArray";
1186 Warning("TTreeReaderArrayBase::GetBranchContentDataType()",
1187 "Not able to check type correctness, ignoring check");
1188 dict = fDict;
1189 fSetupStatus = kSetupNoCheck;
1190 } else if (!dict && (branch->GetSplitLevel() == 0 || brElement->GetClass()->GetCollectionProxy())) {
1191 // Try getting the contained class
1192 dict = brElement->GetClass()->GetCollectionProxy()->GetValueClass();
1193 // If it fails, try to get the contained type as a primitive type
1194 if (!dict)
1195 dict = TDataType::GetDataType(brElement->GetClass()->GetCollectionProxy()->GetType());
1196 if (dict)
1197 contentTypeName = dict->GetName();
1198 return nullptr;
1199 } else if (!dict) {
1200 dict = brElement->GetClass();
1201 contentTypeName = dict->GetName();
1202 return nullptr;
1203 }
1204
1205 return nullptr;
1206 }
1207 return nullptr;
1208 } else if (branch->IsA() == TBranch::Class() || branch->IsA() == TBranchObject::Class() ||
1209 branch->IsA() == TBranchSTL::Class()) {
1210 const char *dataTypeName = branch->GetClassName();
1211 if ((!dataTypeName || !dataTypeName[0]) && branch->IsA() == TBranch::Class()) {
1212 auto myLeaf = branch->GetLeaf(branch->GetName());
1213 if (myLeaf) {
1214 auto myDataType = TDictionary::GetDictionary(myLeaf->GetTypeName());
1215 if (myDataType && myDataType->IsA() == TDataType::Class()) {
1216 auto typeEnumConstant = EDataType(((TDataType *)myDataType)->GetType());
1217 // We need to consider Double32_t and Float16_t as dounle and float respectively
1218 // since this is the type the user uses to instantiate the TTreeReaderArray template.
1219 if (typeEnumConstant == kDouble32_t)
1220 typeEnumConstant = kDouble_t;
1221 else if (typeEnumConstant == kFloat16_t)
1222 typeEnumConstant = kFloat_t;
1223 dict = TDataType::GetDataType(typeEnumConstant);
1224 contentTypeName = myLeaf->GetTypeName();
1225 return nullptr;
1226 }
1227 }
1228
1229 // leaflist. Can't represent.
1230 Error("TTreeReaderArrayBase::GetBranchContentDataType()",
1231 "The branch %s was created using a leaf list and cannot be represented as a C++ type. Please access one "
1232 "of its siblings using a TTreeReaderArray:",
1233 branch->GetName());
1234 TIter iLeaves(branch->GetListOfLeaves());
1235 TLeaf *leaf = nullptr;
1236 while ((leaf = (TLeaf *)iLeaves())) {
1237 Error("TTreeReaderArrayBase::GetBranchContentDataType()", " %s.%s", branch->GetName(), leaf->GetName());
1238 }
1239 return nullptr;
1240 }
1241 if (dataTypeName)
1242 dict = TDictionary::GetDictionary(dataTypeName);
1243 if (branch->IsA() == TBranchSTL::Class()) {
1244 Warning("TTreeReaderArrayBase::GetBranchContentDataType()",
1245 "Not able to check type correctness, ignoring check");
1246 dict = fDict;
1247 fSetupStatus = kSetupNoCheck;
1248 return nullptr;
1249 }
1250 return dataTypeName;
1251 } else if (branch->IsA() == TBranchClones::Class()) {
1252 dict = TClonesArray::Class();
1253 return "TClonesArray";
1254 } else if (branch->IsA() == TBranchRef::Class()) {
1255 // Can't represent.
1256 Error("TTreeReaderArrayBase::GetBranchContentDataType()",
1257 "The branch %s is a TBranchRef and cannot be represented as a C++ type.", branch->GetName());
1258 return nullptr;
1259 } else {
1260 Error("TTreeReaderArrayBase::GetBranchContentDataType()",
1261 "The branch %s is of type %s - something that is not handled yet.", branch->GetName(),
1262 branch->IsA()->GetName());
1263 return nullptr;
1264 }
1265
1266 return nullptr;
1267}
dim_t fSize
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
unsigned char Byte_t
Byte (8 bits) (unsigned char)
Definition RtypesCore.h:79
EDataType
Definition TDataType.h:28
@ kFloat_t
Definition TDataType.h:31
@ kInt_t
Definition TDataType.h:30
@ kDouble32_t
Definition TDataType.h:31
@ kDouble_t
Definition TDataType.h:31
@ kFloat16_t
Definition TDataType.h:33
@ kOther_t
Definition TDataType.h:32
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:252
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
#define gROOT
Definition TROOT.h:417
Base class for all the proxy object.
virtual void * GetStart(UInt_t=0)
std::size_t GetValueSize() const
bool GetSuppressErrorsForMissingBranch() const
TVirtualCollectionProxy * GetCollection()
const Detail::TBranchProxy * GetProxy() const
TDictionary * GetContentDict() const
void SetContentDict(TDictionary *dict)
void CreateProxy() override
Create the proxy object for our branch.
bool GetBranchAndLeaf(TBranch *&branch, TLeaf *&myLeaf, TDictionary *&branchActualType, bool suppressErrorsForMissingBranch=false)
Determine the branch / leaf and its type; reset fProxy / fSetupStatus on error.
StreamerElementArrayInfo FillStreamerElementArrayInfo(TStreamerElement *elem)
const char * GetBranchContentDataType(TBranch *branch, TString &contentTypeName, TDictionary *&dict, StreamerElementArrayInfo &arrInfo)
Access a branch's collection content (not the collection itself) through a proxy.
void SetImpl(TBranch *branch, TLeaf *myLeaf)
Create the TVirtualCollectionReader object for our branch.
Base class of TTreeReaderValue.
void * GetAddress()
Returns the memory address of the object being read.
TLeaf * GetLeaf()
If we are reading a leaf, return the corresponding TLeaf.
static TClass * Class()
A Branch for the case of an object.
TBranchElement * GetBranchCount() const
static TClass * Class()
Int_t GetID() const
const char * GetClassName() const override
Return the name of the user class whose content is stored in this branch, if any.
TStreamerInfo * GetInfo() const
Get streamer info for the branch class.
TVirtualCollectionProxy * GetCollectionProxy()
Return the collection proxy describing the branch content, if any.
TClass * GetCurrentClass()
Return a pointer to the current type of the data member corresponding to branch element.
virtual const char * GetTypeName() const
Return type name of element in the branch.
virtual const char * GetClonesName() const
virtual TClass * GetClass() const
Int_t GetType() const
Int_t GetExpectedType(TClass *&clptr, EDataType &type) override
Fill expectedClass and expectedType with information on the data type of the object/values contained ...
static TClass * Class()
static TClass * Class()
static TClass * Class()
A TTree is a list of TBranches.
Definition TBranch.h:93
virtual TLeaf * GetLeaf(const char *name) const
Return pointer to the 1st Leaf named name in thisBranch.
Definition TBranch.cxx:2053
virtual const char * GetClassName() const
Return the name of the user class whose content is stored in this branch, if any.
Definition TBranch.cxx:1322
TTree * GetTree() const
Definition TBranch.h:261
static TClass * Class()
Int_t GetSplitLevel() const
Definition TBranch.h:259
TClass * IsA() const override
Definition TBranch.h:304
TObjArray * GetListOfLeaves()
Definition TBranch.h:256
TBranch * GetMother() const
Get our top-level parent branch in the tree.
Definition TBranch.cxx:2125
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
TVirtualStreamerInfo * GetStreamerInfo(Int_t version=0, Bool_t isTransient=kFALSE) const
returns a pointer to the TVirtualStreamerInfo object for version If the object does not exist,...
Definition TClass.cxx:4716
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
Definition TClass.cxx:2923
Int_t GetClassSize() const
Definition TClass.h:439
TClass * IsA() const override
Definition TClass.h:638
An array of clone (identical) objects.
TClass * GetClass() const
static TClass * Class()
Basic data type descriptor (datatype information is obtained from CINT).
Definition TDataType.h:44
static TClass * Class()
TString GetTypeName()
Get basic type of typedef, e,g.: "class TDirectory*" -> "TDirectory".
static TDataType * GetDataType(EDataType type)
Given a EDataType type, get the TDataType* that represents it.
This class defines an abstract interface that must be implemented by all classes that contain diction...
TClass * IsA() const override
static TDictionary * GetDictionary(const char *name)
Retrieve the type (class, fundamental type, typedef etc) named "name".
The TEnum class implements the enum type.
Definition TEnum.h:33
static TClass * Class()
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition TLeaf.h:57
virtual Int_t GetLenType() const
Definition TLeaf.h:136
virtual const char * GetTypeName() const
Definition TLeaf.h:142
virtual Int_t GetLen() const
Return the number of effective elements of this leaf, for the current entry.
Definition TLeaf.cxx:407
virtual TLeaf * GetLeafCount() const
If this leaf stores a variable-sized array or a multi-dimensional array whose last dimension has vari...
Definition TLeaf.h:124
TBranch * GetBranch() const
Definition TLeaf.h:119
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
Int_t GetEntries() const override
Return the number of objects in array (i.e.
TObject * At(Int_t idx) const override
Definition TObjArray.h:170
TObject * UncheckedAt(Int_t i) const
Definition TObjArray.h:90
Regular expression class.
Definition TRegexp.h:31
static TClass * Class()
static TClass * Class()
static TClass * Class()
Describe one element (data member) to be Streamed.
Int_t GetType() const
Int_t GetArrayDim() const
Int_t GetArrayLength() const
Int_t GetMaxIndex(Int_t i) const
const char * GetTypeName() const
TClass * GetClass() const
TClass * IsA() const override
Int_t GetOffset() const
const char * GetTypeNameBasic() const
Return type name of this element in case the type name is not a standard basic type,...
Describes a persistent version of a class.
TStreamerElement * GetElement(Int_t id) const override
TObjArray * GetElements() const override
static TClass * Class()
static TClass * Class()
static TClass * Class()
Basic string class.
Definition TString.h:137
Ssiz_t Length() const
Definition TString.h:426
const char * Data() const
Definition TString.h:385
Bool_t IsNull() const
Definition TString.h:423
An interface for reading values stored in ROOT columnar datasets.
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
Definition TTreeReader.h:46
TTree * GetTree() const
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
Definition TTree.cxx:5459
virtual TTree * GetTree() const
Definition TTree.h:618
virtual TLeaf * FindLeaf(const char *name)
Find first leaf containing searchname.
Definition TTree.cxx:4994
Defines a common interface to inspect/change the contents of an object that represents a collection.
virtual Int_t GetProperties() const
Return miscallenous properties of the proxy (see TVirtualCollectionProxy::EProperty)
virtual void PushProxy(void *objectstart)=0
Set the address of the container being proxied and keep track of the previous one.
virtual EDataType GetType() const =0
If the value type is a fundamental data type, return its type (see enumeration EDataType).
virtual void PopProxy()=0
Reset the address of the container being proxied to the previous container.
virtual TClass * GetValueClass() const =0
If the value type is a user-defined class, return a pointer to the TClass representing the value type...
virtual void * At(UInt_t idx)=0
Return the address of the value at index idx
virtual Int_t GetCollectionType() const =0
Return the type of the proxied collection (see enumeration TClassEdit::ESTLType)
virtual UInt_t Size() const =0
Return the current number of elements in the container.
virtual Bool_t HasPointers() const =0
Return true if the content is of type 'pointer to'.
virtual TObjArray * GetElements() const =0
@ kSTLmap
Definition ESTLType.h:33
@ kROOTRVec
Definition ESTLType.h:46
@ kSTLvector
Definition ESTLType.h:30
@ kSTLmultimap
Definition ESTLType.h:34
void forward(const LAYERDATA &prevLayerData, LAYERDATA &currLayerData)
apply the weights (and functions) in forward direction of the DNN
std::string GetFullName(TCppScope_t)
int IsSTLCont(int testAlloc=0) const
type : type name: vector<list<classA,allocator>,allocator> testAlloc: if true, we test allocator,...
std::vector< std::string > fElements
Definition TClassEdit.h:143
TLine l
Definition textangle.C:4