Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TTreeReaderValueFast.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 
13 
14 #include "TTreeReader.h"
15 #include "TBranchClones.h"
16 #include "TBranchElement.h"
17 #include "TBranchRef.h"
18 #include "TBranchSTL.h"
19 #include "TBranchProxyDirector.h"
20 #include "TLeaf.h"
21 #include "TTreeProxyGenerator.h"
22 #include "TTreeReaderValue.h"
23 #include "TRegexp.h"
24 #include "TStreamerInfo.h"
25 #include "TStreamerElement.h"
26 #include "TNtuple.h"
27 #include <vector>
28 
29 /** \class TTreeReaderValueFast
30 
31 Extracts data from a TTree.
32 */
33 
34 ////////////////////////////////////////////////////////////////////////////////
35 /// Unregister from tree reader, cleanup.
36 
37 ROOT::Experimental::Internal::TTreeReaderValueFastBase::~TTreeReaderValueFastBase()
38 {
39  if (fTreeReader) fTreeReader->DeregisterValueReader(this);
40 }
41 
42 ////////////////////////////////////////////////////////////////////////////////
43 /// Attach this value to the appropriate branch on the tree. For now, we don't
44 /// support the complex branch lookup of the TTreeReader -- only a fixed leaf!
45 
46 void ROOT::Experimental::Internal::TTreeReaderValueFastBase::CreateProxy() {
47  fReadStatus = ROOT::Internal::TTreeReaderValueBase::kReadError;
48  fSetupStatus = ROOT::Internal::TTreeReaderValueBase::kSetupMissingBranch;
49  if (fLeafName.size() > 0){
50 
51  Long64_t newChainOffset = fTreeReader->GetTree()->GetChainOffset();
52 
53  if (newChainOffset != fLastChainOffset){
54  fLastChainOffset = newChainOffset;
55 
56  TTree *myTree = fTreeReader->GetTree();
57 
58  if (!myTree) {
59  Error("TTreeReaderValueBase::GetLeaf()", "Unable to get the tree from the TTreeReader");
60  return;
61  }
62 
63  TBranch *myBranch = myTree->GetBranch(fBranchName.c_str());
64 
65  if (!myBranch) {
66  Error("TTreeReaderValueBase::GetLeaf()", "Unable to get the branch from the tree");
67  return;
68  }
69 
70  fLeaf = myBranch->GetLeaf(fLeafName.c_str());
71  if (!fLeaf) {
72  Error("TTreeReaderValueBase::GetLeaf()", "Failed to get the leaf from the branch");
73  }
74  fBranch = myBranch;
75  }
76  }
77  else {
78  Error("TTreeReaderValueBase::GetLeaf()", "We are not reading a leaf");
79  }
80  fReadStatus = ROOT::Internal::TTreeReaderValueBase::kReadSuccess;
81  fSetupStatus = ROOT::Internal::TTreeReaderValueBase::kSetupMatch;
82 }
83