46 TClonesReader() =
default;
48 TClonesReader(
const TClonesReader &) =
delete;
49 TClonesReader &
operator=(
const TClonesReader &) =
delete;
50 TClonesReader(TClonesReader &&) =
delete;
51 TClonesReader &
operator=(TClonesReader &&) =
delete;
57 if (!
proxy->GetSuppressErrorsForMissingBranch())
58 Error(
"TClonesReader::GetCA()",
"Read error in TBranchProxy.");
87 if (!
proxy->GetSuppressErrorsForMissingBranch())
88 Error(
"TClonesReader::GetValueSize()",
"Read error in TBranchProxy.");
92 return proxy->GetValueSize();
101 switch (
cp.GetCollectionType()) {
104 default:
return false;
110 if (
auto cl =
cp.GetValueClass())
124 if (!
proxy->Read()) {
126 if (!
proxy->GetSuppressErrorsForMissingBranch())
127 Error(
"TSTLReader::GetCP()",
"Read error in TBranchProxy.");
130 if (!
proxy->GetWhere()) {
131 Error(
"TSTLReader::GetCP()",
"Logic error, proxy object not set in TBranchProxy.");
180 if (!
proxy->Read()) {
182 if (!
proxy->GetSuppressErrorsForMissingBranch())
183 Error(
"TCollectionLessSTLReader::GetCP()",
"Read error in TBranchProxy.");
186 if (!
proxy->GetWhere()) {
187 Error(
"TCollectionLessSTLReader::GetCP()",
"Logic error, proxy object not set in TBranchProxy.");
191 return fLocalCollection;
240 Int_t fBasicTypeSize;
243 TObjectArrayReader() : fBasicTypeSize(-1) {}
247 if (!
proxy->Read()) {
249 if (!
proxy->GetSuppressErrorsForMissingBranch())
250 Error(
"TObjectArrayReader::GetCP()",
"Read error in TBranchProxy.");
269 void *array = (
void *)
proxy->GetStart();
271 if (fBasicTypeSize == -1) {
274 Error(
"TObjectArrayReader::At()",
"Cannot get class info from branch proxy.");
294 return proxy->GetValueSize();
299class TDynamicArrayReader :
public BASE {
302 class TVirtualSizeReaderImpl {
305 virtual size_t GetSize() = 0;
308 template <
typename T>
309 class TSizeReaderImpl
final :
public TVirtualSizeReaderImpl {
314 size_t GetSize()
final {
return *fSizeReader; }
317 std::unique_ptr<TVirtualSizeReaderImpl> fSizeReader;
320 template <
class...
ARGS>
352 }
while (!
sizeLeaf && !parent.empty());
356 Error(
"TDynamicArrayReader ",
"Cannot find leaf count for %s or any parent branch!",
leafName);
367 }
else if (
leafType ==
"UShort_t") {
373 }
else if (
leafType ==
"Long64_t") {
375 }
else if (
leafType ==
"ULong64_t") {
378 Error(
"TDynamicArrayReader ",
379 "Unsupported size type for leaf %s. Supported types are int, short int, long int, long long int and "
380 "their unsigned counterparts.",
388class TArrayParameterSizeReader :
public TDynamicArrayReader<TObjectArrayReader> {
391 : TDynamicArrayReader<TObjectArrayReader>(
treeReader, branchName)
397class TArrayFixedSizeReader :
public TObjectArrayReader {
413 if (!
proxy->Read()) {
415 if (!
proxy->GetSuppressErrorsForMissingBranch())
416 Error(
"TBasicTypeArrayReader::GetCP()",
"Read error in TBranchProxy.");
443 if (!
proxy->Read()) {
445 if (!
proxy->GetSuppressErrorsForMissingBranch())
446 Error(
"TBasicTypeArrayReader::GetValueSize()",
"Read error in TBranchProxy.");
450 return proxy->GetValueSize();
454class TBasicTypeClonesReader
final :
public TClonesReader {
462 TBasicTypeClonesReader(
const TBasicTypeClonesReader &) =
delete;
464 TBasicTypeClonesReader(TBasicTypeClonesReader &&) =
delete;
465 TBasicTypeClonesReader &
operator=(TBasicTypeClonesReader &&) =
delete;
494 if (fElementSize == -1) {
498 fElementSize =
myLeaf->GetLenType();
500 return (
Byte_t *)address + (fElementSize * idx);
508 return leaf ?
leaf->GetLenType() : 0;
512 void ProxyRead() { fValueReader->
ProxyRead(); }
515class TLeafParameterSizeReader :
public TDynamicArrayReader<TLeafReader> {
525 return TDynamicArrayReader<TLeafReader>::GetSize(
proxy);
540 fSetupStatus = kSetupInternalError;
542 Error(
"TTreeReaderArrayBase::CreateProxy()",
"TTreeReader object not set / available for branch %s!",
544 fSetupStatus = kSetupTreeDestructed;
548 TBranch *
br = fTreeReader->GetTree()->GetBranch(fBranchName);
554 Error(
"TTreeReaderArrayBase::CreateProxy()",
555 "The template argument type T of %s accessing branch %s (which contains data of type %s) is not known to "
556 "ROOT. You will need to create a dictionary for it.",
557 GetDerivedTypeName(), fBranchName.Data(),
brDataType);
558 fSetupStatus = kSetupMissingDictionary;
570 fTreeReader->fSuppressErrorsForMissingBranches.cend());
579 Error(
"TTreeReaderArrayBase::CreateProxy()",
"No dictionary for branch %s.", fBranchName.Data());
586 fSetupStatus = kSetupMatch;
597 fSetupStatus = kSetupMatch;
599 Error(
"TTreeReaderArrayBase::CreateProxy()",
"Type ambiguity (want %s, have %s) for branch %s.",
600 fDict->GetName(),
namedProxy->GetContentDict()->GetName(), fBranchName.Data());
612 auto *
director = fTreeReader->fDirector.get();
614 if (
branch->GetTree() != fTreeReader->GetTree()->GetTree()) {
616 std::optional<std::size_t>
index;
617 std::size_t current{};
618 auto &&
friends = fTreeReader->GetTree()->GetTree()->GetListOfFriends();
620 if (
branch->GetTree() ==
fe->GetTree()) {
626 if (!
index.has_value()) {
627 Error(
"TTreeReaderArrayBase::CreateProxy()",
628 "The branch %s is contained in a Friend TTree that is not directly attached to the main.\n"
629 "This is not yet supported by TTreeReader.",
637 fTreeReader->AddProxy(
640 namedProxy = fTreeReader->FindProxy(fBranchName);
643 fSetupStatus = kSetupMatch;
645 fSetupStatus = kSetupMismatch;
653 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
654 "The branch %s contains data of type %s, which should be accessed through a TTreeReaderValue< %s >.",
656 if (fSetupStatus == kSetupInternalError)
657 fSetupStatus = kSetupNotACollection;
663 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
664 "Cannot determine the type contained in the collection of branch %s. That's weird - please report!",
667 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
668 "The branch %s contains data of type %s, which does not have a dictionary.", fBranchName.Data(),
670 if (fSetupStatus == kSetupInternalError)
671 fSetupStatus = kSetupMissingDictionary;
711 for (
int i = 0; i <
info.fArrayNDims; i++) {
768 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
769 "The branch %s contains data of type %s. It cannot be accessed by a TTreeReaderArray<%s>",
771 if (fSetupStatus == kSetupInternalError || fSetupStatus >= 0)
772 fSetupStatus = kSetupMismatch;
795 branch = fTreeReader->GetTree()->GetBranch(fBranchName);
799 if (!fBranchName.Contains(
".")) {
801 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
802 "The tree does not have a branch called %s. You could check with TTree::Print() for available branches.",
805 fSetupStatus = kSetupMissingBranch;
812 TString branchName = fBranchName(0, fBranchName.Length() -
leafName.Length());
813 branch = fTreeReader->GetTree()->GetBranch(branchName);
816 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
817 "The tree does not have a branch called %s. You could check with TTree::Print() for available branches.",
820 fSetupStatus = kSetupMissingBranch;
828 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
829 "The tree does not have a branch, nor a sub-branch called %s. You could check with TTree::Print() for "
830 "available branches.",
833 fSetupStatus = kSetupMissingBranch;
840 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"Failed to get the dictionary for %s.",
myLeaf->GetTypeName());
841 fSetupStatus = kSetupMissingDictionary;
851 fBranchName = branchName;
853 fHaveLeaf = (fLeafName.Length() > 0);
854 fSetupStatus = kSetupMatchLeaf;
856 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"Leaf of type %s cannot be read by TTreeReaderValue<%s>.",
857 myLeaf->GetTypeName(), fDict->GetName());
859 fSetupStatus = kSetupMismatch;
881 if (!
myLeaf->GetLeafCount()) {
882 fImpl = std::make_unique<TLeafReader>(
this);
887 fImpl = std::make_unique<TLeafParameterSizeReader>(fTreeReader,
leafFullName.Data(),
this);
889 fSetupStatus = kSetupMatchLeaf;
902 if (fSetupStatus == kSetupInternalError)
903 fSetupStatus = kSetupMatch;
906 Error(
"TTreeReaderArrayBase::SetImpl",
"STL Collection nested in a TClonesArray not yet supported");
907 fSetupStatus = kSetupInternalError;
910 fImpl = std::make_unique<TSTLReader>();
915 fImpl = std::make_unique<TClonesReader>();
917 fImpl = std::make_unique<TBasicTypeArrayReader>();
920 fImpl = std::make_unique<TBasicTypeClonesReader>(
element->GetOffset());
922 fImpl = std::make_unique<TArrayFixedSizeReader>(
element->GetArrayLength());
926 std::make_unique<TArrayParameterSizeReader>(fTreeReader,
branchElement->GetBranchCount()->GetName());
929 fImpl = std::make_unique<TBasicTypeArrayReader>();
931 fImpl = std::make_unique<TBasicTypeClonesReader>(
element->GetOffset());
933 fImpl = std::make_unique<TArrayFixedSizeReader>(
element->GetArrayLength());
936 fImpl = std::make_unique<TArrayFixedSizeReader>(
element->GetArrayLength());
941 std::make_unique<TArrayParameterSizeReader>(fTreeReader,
branchElement->GetBranchCount()->GetName());
944 fImpl = std::make_unique<TClonesReader>();
946 Error(
"TTreeReaderArrayBase::SetImpl()",
"Cannot read branch %s: unhandled streamer element type %s",
947 fBranchName.Data(),
element->IsA()->GetName());
948 fSetupStatus = kSetupInternalError;
952 fImpl = std::make_unique<TCollectionLessSTLReader>(
branchElement->GetClass()->GetCollectionProxy());
958 Error(
"TTreeReaderArrayBase::SetImpl",
"Failed to get the top leaf from the branch");
959 fSetupStatus = kSetupMissingBranch;
964 if (fSetupStatus == kSetupInternalError)
965 fSetupStatus = kSetupMatch;
967 fImpl = std::make_unique<TArrayFixedSizeReader>(
topLeaf->GetLenStatic());
969 fImpl = std::make_unique<TArrayParameterSizeReader>(fTreeReader,
sizeLeaf->GetName());
973 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchClones not implemented");
974 fSetupStatus = kSetupInternalError;
976 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchObject not implemented");
977 fSetupStatus = kSetupInternalError;
979 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchSTL not implemented");
980 fImpl = std::make_unique<TSTLReader>();
981 fSetupStatus = kSetupInternalError;
983 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchRef not implemented");
984 fSetupStatus = kSetupInternalError;
1000 for (
int i = 0; i <
arrInfo.fArrayNDims; ++i)
1029 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Could not get value class.");
1048 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
1049 "Cannot determine STL collection type of %s stored in branch %s",
brElement->GetClassName(),
1081 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
1082 "The branch %s contains a data type %d for which the dictionary cannot be retrieved.",
1094 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
1095 "The branch %s contains data of type %s for which the dictionary does not exist. It's needed.",
1109 return "{CANNOT DETERMINE TBranchElement DATA TYPE}";
1121 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get class from branch element.");
1126 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get collection proxy from STL class");
1135 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get valueClass from collectionProxy.");
1141 if (!fProxy->Setup() || !fProxy->Read()) {
1142 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
1143 "Failed to get type from proxy, unable to check type");
1164 Warning(
"TTreeReaderArrayBase::GetBranchContentDataType()",
1165 "Not able to check type correctness, ignoring check");
1167 fSetupStatus = kSetupNoCheck;
1168 }
else if (!dict && (
branch->GetSplitLevel() == 0 ||
brElement->GetClass()->GetCollectionProxy())) {
1170 dict =
brElement->GetClass()->GetCollectionProxy()->GetValueClass();
1208 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
1209 "The branch %s was created using a leaf list and cannot be represented as a C++ type. Please access one "
1210 "of its siblings using a TTreeReaderArray:",
1215 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
" %s.%s",
branch->GetName(),
leaf->GetName());
1222 Warning(
"TTreeReaderArrayBase::GetBranchContentDataType()",
1223 "Not able to check type correctness, ignoring check");
1225 fSetupStatus = kSetupNoCheck;
1231 return "TClonesArray";
1234 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
1235 "The branch %s is a TBranchRef and cannot be represented as a C++ type.",
branch->GetName());
1238 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
1239 "The branch %s is of type %s - something that is not handled yet.",
branch->GetName(),
1240 branch->IsA()->GetName());
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
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
Binding & operator=(OUT(*fun)(void))
Base class for all the proxy object.
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.
@ kReadError
Problem reading data.
@ kReadSuccess
Data read okay.
TLeaf * GetLeaf()
If we are reading a leaf, return the corresponding TLeaf.
virtual ~TVirtualCollectionReader()
A Branch for the case of an object.
A TTree is a list of TBranches.
TClass instances represent classes, structs and namespaces in the ROOT type system.
An array of clone (identical) objects.
Basic data type descriptor (datatype information is obtained from CINT).
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...
static TDictionary * GetDictionary(const char *name)
Retrieve the type (class, fundamental type, typedef etc) named "name".
The TEnum class implements the enum type.
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
const char * GetName() const override
Returns name of object.
Regular expression class.
Describe one element (data member) to be Streamed.
Describes a persistent version of a class.
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
Defines a common interface to inspect/change the contents of an object that represents a collection.
void forward(const LAYERDATA &prevLayerData, LAYERDATA &currLayerData)
apply the weights (and functions) in forward direction of the DNN