Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TChain tests successful #5

Closed
wants to merge 11 commits into from
2 changes: 1 addition & 1 deletion tree/treeplayer/inc/TTreeReaderUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace ROOT {
public:
TNamedBranchProxy(): fDict(0) {}
TNamedBranchProxy(TBranchProxyDirector* boss, TBranch* branch, const char* membername):
fProxy(boss, branch, membername), fDict(0) {}
fProxy(boss, branch, membername), fDict(0), fContentDict(0) {}

const char* GetName() const { return fProxy.GetBranchName(); }
const ROOT::TBranchProxy* GetProxy() const { return &fProxy; }
Expand Down
18 changes: 5 additions & 13 deletions tree/treeplayer/inc/TTreeReaderValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,9 @@ namespace ROOT {
ESetupStatus GetSetupStatus() const { return fSetupStatus; }
virtual EReadStatus GetReadStatus() const { return fReadStatus; }

TLeaf* GetLeaf() const { return fLeaf; }

void* GetAddress() {
if (ProxyRead() != kReadSuccess) return 0;
if (fLeafOffset == -1){
if (fLeaf)
fLeafOffset = (Byte_t*)fProxy->GetWhere() - (Byte_t*)fLeaf->GetValuePointer();
else
fLeafOffset = 0;
}
return fProxy ? (Byte_t*)fProxy->GetWhere() - fLeafOffset : 0;
}
TLeaf* GetLeaf();

void* GetAddress();

protected:
TTreeReaderValueBase(TTreeReader* reader = 0, const char* branchname = 0, TDictionary* dict = 0);
Expand All @@ -109,8 +100,9 @@ namespace ROOT {
ROOT::TBranchProxy* fProxy; // proxy for this branch, owned by TTreeReader
ESetupStatus fSetupStatus; // setup status of this data access
EReadStatus fReadStatus; // read status of this data access
Int_t fLeafOffset;
TLeaf* fLeaf;
Long64_t fTreeLastOffset;
TString fLeafName;

ClassDef(TTreeReaderValueBase, 0);//Base class for accessors to data via TTreeReader

Expand Down
72 changes: 42 additions & 30 deletions tree/treeplayer/src/TTreeReaderArray.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ namespace {
private:
TVirtualCollectionProxy *localCollection;
Bool_t proxySet;
void *lastWhere;
public:
TCollectionLessSTLReader(TVirtualCollectionProxy *proxy) : localCollection(proxy), proxySet(false) {}
TCollectionLessSTLReader(TVirtualCollectionProxy *proxy) : localCollection(proxy), proxySet(false), lastWhere(0) {}

TVirtualCollectionProxy* GetCP(ROOT::TBranchProxy* proxy) {
if (!proxy->Read()){
Expand Down Expand Up @@ -151,11 +152,12 @@ namespace {

Bool_t CheckProxy(ROOT::TBranchProxy *proxy) {
if (!proxy->Read()) return false;
if (!proxySet) {
if (!proxySet || lastWhere != proxy->GetWhere()) {
TVirtualCollectionProxy *myCollectionProxy = GetCP(proxy);
if (proxy->GetWhere() && myCollectionProxy){
myCollectionProxy->PushProxy(proxy->GetWhere());
proxySet = true;
lastWhere = proxy->GetWhere();
}
else return false;
}
Expand Down Expand Up @@ -199,11 +201,11 @@ namespace {

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

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

class TArrayFixedSizeReader : public TObjectArrayReader {
Expand Down Expand Up @@ -259,17 +261,19 @@ namespace {
class TLeafReader : public ROOT::TVirtualCollectionReader {
private:
ROOT::TTreeReaderValueBase *valueReader;
Int_t elementSize;
public:
TLeafReader(ROOT::TTreeReaderValueBase *valueReaderArg) : valueReader(valueReaderArg) {}
TLeafReader(ROOT::TTreeReaderValueBase *valueReaderArg) : valueReader(valueReaderArg), elementSize(-1) {}

virtual size_t GetSize(ROOT::TBranchProxy* /*proxy*/){
return valueReader->GetLeaf()->GetLen();
}

virtual void* At(ROOT::TBranchProxy* /*proxy*/, size_t idx){
ProxyRead();
void *address = valueReader->GetAddress();
Int_t offset = valueReader->GetLeaf()->GetLenType();
return (Byte_t*)address + (offset * idx);
if (elementSize == -1) elementSize = valueReader->GetLeaf()->GetLenType();
return (Byte_t*)address + (elementSize * idx);
}

protected:
Expand All @@ -280,13 +284,13 @@ namespace {

class TLeafParameterSizeReader : public TLeafReader {
private:
TLeaf *sizeReader;
TTreeReaderValue<Int_t> sizeReader;
public:
TLeafParameterSizeReader(TLeaf *sizeReaderArg, ROOT::TTreeReaderValueBase *valueReaderArg) : TLeafReader(valueReaderArg), sizeReader(sizeReaderArg) {}
TLeafParameterSizeReader(TTreeReader *treeReader, const char *leafName, ROOT::TTreeReaderValueBase *valueReaderArg) : TLeafReader(valueReaderArg), sizeReader(*treeReader, leafName) {}

virtual size_t GetSize(ROOT::TBranchProxy* /*proxy*/){
ProxyRead();
return *(Int_t*)sizeReader->GetValuePointer();
return *sizeReader;
}
};
}
Expand Down Expand Up @@ -341,6 +345,9 @@ void ROOT::TTreeReaderArrayBase::CreateProxy()
ROOT::TNamedBranchProxy* namedProxy = fTreeReader->FindProxy(fBranchName);
if (namedProxy && namedProxy->GetContentDict() == fDict) {
fProxy = namedProxy->GetProxy();
if (!fImpl){
Fatal("CreateProxy()", "No fImpl set!");
}
return;
}

Expand Down Expand Up @@ -377,6 +384,8 @@ void ROOT::TTreeReaderArrayBase::CreateProxy()
//fLeafOffset = myLeaf->GetOffset() / 4;
branchActualType = fDict;
fLeaf = myLeaf;
fBranchName = branchName;
fLeafName = leafName(1, leafName.Length());
}
else {
Error("CreateProxy()", "Leaf of type %s cannot be read by TTreeReaderValue<%s>.", myLeaf->GetTypeName(), fDict->GetName());
Expand All @@ -393,18 +402,25 @@ void ROOT::TTreeReaderArrayBase::CreateProxy()
}
}

TString membername;
// Update named proxy's dictionary
if (namedProxy && !namedProxy->GetContentDict()) {
namedProxy->SetContentDict(fDict);
fProxy = namedProxy->GetProxy();
}
else {
TString membername;

bool isTopLevel = branch->GetMother() == branch;
if (!isTopLevel) {
membername = strrchr(branch->GetName(), '.');
if (membername.IsNull()) {
membername = branch->GetName();
bool isTopLevel = branch->GetMother() == branch;
if (!isTopLevel) {
membername = strrchr(branch->GetName(), '.');
if (membername.IsNull()) {
membername = branch->GetName();
}
}
namedProxy = new ROOT::TNamedBranchProxy(fTreeReader->fDirector, branch, membername);
fTreeReader->GetProxies()->Add(namedProxy);
fProxy = namedProxy->GetProxy();
}
namedProxy = new ROOT::TNamedBranchProxy(fTreeReader->fDirector, branch, membername);
fTreeReader->GetProxies()->Add(namedProxy);
fProxy = namedProxy->GetProxy();

if (!myLeaf){
TString branchActualTypeName;
Expand Down Expand Up @@ -441,12 +457,7 @@ void ROOT::TTreeReaderArrayBase::CreateProxy()
}
}

// Update named proxy's dictionary
if (namedProxy && !namedProxy->GetContentDict()) {
namedProxy->SetContentDict(fDict);
fProxy = namedProxy->GetProxy();
return;
}


// Access a branch's collection content (not the collection itself)
// through a proxy.
Expand All @@ -460,7 +471,10 @@ void ROOT::TTreeReaderArrayBase::CreateProxy()
fImpl = new TLeafReader(this);
}
else {
fImpl = new TLeafParameterSizeReader(myLeaf->GetLeafCount(), this);
TString leafFullName = myLeaf->GetBranch()->GetName();
leafFullName += ".";
leafFullName += myLeaf->GetLeafCount()->GetName();
fImpl = new TLeafParameterSizeReader(fTreeReader, leafFullName.Data(), this);
}
}
else if (branch->IsA() == TBranchElement::Class()) {
Expand Down Expand Up @@ -489,9 +503,7 @@ void ROOT::TTreeReaderArrayBase::CreateProxy()
}
}
else if (element->IsA() == TStreamerLoop::Class()) {
//fImpl = new TObjectArrayReader(); // BStarArray[num]
TTreeReaderValue<Int_t> *indexReader = new TTreeReaderValue<Int_t>(*fTreeReader, branchElement->GetBranchCount()->GetName());
fImpl = new TArrayParameterSizeReader(indexReader);
fImpl = new TArrayParameterSizeReader(fTreeReader, branchElement->GetBranchCount()->GetName());
}
else if (element->IsA() == TStreamerBasicType::Class()){
if (branchElement->GetType() == TBranchElement::kSTLMemberNode){
Expand Down
40 changes: 38 additions & 2 deletions tree/treeplayer/src/TTreeReaderValue.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ ROOT::TTreeReaderValueBase::TTreeReaderValueBase(TTreeReader* reader /*= 0*/,
fProxy(0),
fSetupStatus(kSetupNotSetup),
fReadStatus(kReadNothingYet),
fLeafOffset(-1),
fLeaf(NULL)
fLeaf(NULL),
fTreeLastOffset(-1)
{
// Construct a tree value reader and register it with the reader object.
if (fTreeReader) fTreeReader->RegisterValueReader(this);
Expand All @@ -78,6 +78,40 @@ ROOT::TTreeReaderValueBase::ProxyRead() {
return fReadStatus;
}

//______________________________________________________________________________
TLeaf* ROOT::TTreeReaderValueBase::GetLeaf() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add //______________________________________________________________________________ in front?

if (fLeafName.Length() > 0){

Long64_t newChainOffset = fTreeReader->GetTree()->GetChainOffset();

if (newChainOffset != fTreeLastOffset){
fTreeLastOffset = newChainOffset;
fLeaf = fTreeReader->GetTree()->GetBranch(fBranchName)->GetLeaf(fLeafName);
}
return fLeaf;
}
else {
Error("GetLeaf()", "We are not reading a leaf");
return 0;
}
}

//______________________________________________________________________________
void* ROOT::TTreeReaderValueBase::GetAddress() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add //______________________________________________________________________________ in front?

if (ProxyRead() != kReadSuccess) return 0;

if (fLeafName.Length() > 0){
Long64_t newChainOffset = fTreeReader->GetTree()->GetChainOffset();

if (newChainOffset != fTreeLastOffset){
fTreeLastOffset = newChainOffset;
fLeaf = fTreeReader->GetTree()->GetBranch(fBranchName)->GetLeaf(fLeafName);
}
return fLeaf->GetValuePointer();
}
return fProxy ? (Byte_t*)fProxy->GetWhere() : 0;
}

//______________________________________________________________________________
void ROOT::TTreeReaderValueBase::CreateProxy() {
// Create the proxy object for our branch.
Expand Down Expand Up @@ -137,6 +171,8 @@ void ROOT::TTreeReaderValueBase::CreateProxy() {
//fLeafOffset = myLeaf->GetOffset() / 4;
branchActualType = fDict;
fLeaf = myLeaf;
fBranchName = branchName;
fLeafName = leafName(1, leafName.Length());
}
else {
Error("CreateProxy()", "Leaf of type %s cannot be read by TTreeReaderValue<%s>.", myLeaf->GetTypeName(), fDict->GetName());
Expand Down
15 changes: 9 additions & 6 deletions tree/treeplayer/test/hardTreeReaderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ void readLeafFloatX(Bool_t printOut = true, Bool_t testValues = false, const cha
Bool_t read = false;
for (int i = 1; myTreeReader.SetNextEntry(); ++i){
read = true;
if (testValues && *myFloat - (Float_t)i > 0.0001f) success = false;
if (printOut) printf("MyLeafList.x: %f\n", *myFloat);
}

Expand All @@ -623,6 +624,7 @@ void readLeafFloatY(Bool_t printOut = true, Bool_t testValues = false, const cha
Bool_t read = false;
for (int i = 1; myTreeReader.SetNextEntry(); ++i){
read = true;
if (testValues && *myFloat - ((Float_t)i / 10.0f) > 0.0001f) success = false;
if (printOut) printf("MyLeafList.y: %f\n", *myFloat);
}

Expand All @@ -641,6 +643,7 @@ void readLeafIntN(Bool_t printOut = true, Bool_t testValues = false, const char*
Bool_t read = false;
for (int i = 1; myTreeReader.SetNextEntry(); ++i){
read = true;
if (testValues && *myInt != MYDOUBLEARRAY_SIZE) success = false;
if (printOut) printf("MyLeafList.n: %i\n", *myInt);
}

Expand All @@ -661,7 +664,7 @@ void readLeafDoubleAArray(Bool_t printOut = true, Bool_t testValues = false, con
read = true;
if (printOut) printf("MyLeafList.a(%lu):", myDoubles.GetSize());

for (int j = 0; j < myDoubles.GetSize(); ++j){
for (int j = 0; j < myDoubles.GetSize() && j < 10; ++j){
if (testValues && fabs(myDoubles.At(j) - (i * j) / 10.0f) > 0.0001f) success = false;
if (printOut) printf(" %f", myDoubles.At(j));
}
Expand All @@ -678,17 +681,17 @@ void readLeafBoolBArray(Bool_t printOut = true, Bool_t testValues = false, const

TString branchName = "MyLeafList.b";

TTreeReaderArray<Bool_t> myDoubles (myTreeReader, branchName);
TTreeReaderArray<Bool_t> myBools (myTreeReader, branchName);

Bool_t success = true;
Bool_t read = false;
for (int i = 1; myTreeReader.SetNextEntry(); ++i){
read = true;
if (printOut) printf("MyLeafList.b(%lu):", myDoubles.GetSize());
if (printOut) printf("MyLeafList.b(%lu):", myBools.GetSize());

for (int j = 0; j < myDoubles.GetSize(); ++j){
if (testValues && myDoubles.At(j) != j % 2) success = false;
if (printOut) printf(" %s", myDoubles.At(j) ? "true" : "false" );
for (int j = 0; j < myBools.GetSize() && j < 10; ++j){
if (testValues && myBools.At(j) != j % 2) success = false;
if (printOut) printf(" %s", myBools.At(j) ? "true" : "false" );
}

if (printOut) printf("\n");
Expand Down