00001
00005 #ifndef __NTBASECUT_H
00006 #define __NTBASECUT_H
00007
00008 #include "jbltools/sfh/BaseCut.h"
00009 #include "jbltools/sfh/IntFun.h"
00010 #include "jbltools/sfh/IntFunPoR.h"
00011
00012 #include <TTree.h>
00013 #include <TBranch.h>
00014 #include <cstring>
00015
00016
00017
00019
00028 class NTBaseCut: public BaseCut {
00029 public:
00031 NTBaseCut (const std::string& name_
00032 );
00033
00035 NTBaseCut (const std::string& name_,
00036 const IntFun *iter_
00037 );
00039 NTBaseCut (const std::string& name_,
00040 int offset_
00041 );
00042
00044 virtual NTBaseCut& operator[] (const IntFunPoR& iter_
00045 ) const = 0;
00046
00048 virtual NTBaseCut& operator[] (int offset_
00049 ) const = 0;
00050
00052 virtual const FillIterator *getIterator() const {
00053 return iter ? iter->getIterator() : 0;
00054 }
00055
00056 protected:
00058 virtual ~NTBaseCut() {}
00059
00061 std::string getBaseName() const;
00062
00063
00064 const IntFun *iter;
00065 int offset;
00066 };
00067
00068
00070
00093 template<class Ntuple, class T = bool>
00094 class NTBaseCutT: public NTBaseCut {
00095 public:
00097 NTBaseCutT (const Ntuple& nt,
00098 const char *branchname,
00099 const IntFunPoR& iter_ = 0
00100 )
00101 : NTBaseCut (branchname, iter_.pif)
00102 {
00103 TTree *t = nt.fChain;
00104 assert (t);
00105 TBranch *b = t->GetBranch (branchname);
00106 assert (b);
00107 branchAddress = reinterpret_cast<T *>(b->GetAddress());
00108 assert (branchAddress);
00109 }
00110
00112 NTBaseCutT (const Ntuple& nt,
00113 T Ntuple::* p_mem,
00114 const char *name_ = "?",
00115 const IntFunPoR& iter_ = 0
00116 )
00117 : NTBaseCut (name_, iter_.pif)
00118 {
00119 branchAddress = &(nt.*p_mem);
00120 assert (branchAddress);
00121 }
00122
00124 NTBaseCutT (const Ntuple& nt,
00125 const char *branchname,
00126 int offset_
00127 )
00128 : NTBaseCut (branchname, offset_)
00129 {
00130 TTree *t = nt.fChain;
00131 assert (t);
00132 TBranch *b = t->GetBranch (branchname);
00133 assert (b);
00134 branchAddress = reinterpret_cast<T *>(b->GetAddress());
00135 assert (branchAddress);
00136 }
00137
00139 NTBaseCutT (const Ntuple& nt,
00140 T Ntuple::* p_mem,
00141 const char *name_,
00142 int offset_
00143 )
00144 : NTBaseCut (name_, offset_)
00145 {
00146 branchAddress = &(nt.*p_mem);
00147 assert (branchAddress);
00148 }
00149
00151 NTBaseCutT (const NTBaseCutT<Ntuple, T>& source,
00152 const IntFunPoR& iter_
00153 )
00154 : NTBaseCut (source.getBaseName(), iter_.pif),
00155 branchAddress (source.branchAddress)
00156 {}
00158 NTBaseCutT (const NTBaseCutT<Ntuple, T>& source,
00159 const int offset_
00160 )
00161 : NTBaseCut (source.getBaseName(), offset_),
00162 branchAddress (source.branchAddress)
00163 {}
00164
00165
00167 virtual bool operator() () const {
00168 int i = (iter) ? (*iter)() : offset;
00169 return branchAddress[i];
00170 }
00171
00173 NTBaseCutT<Ntuple, T>& operator[] (const IntFunPoR& iter_
00174 ) const {
00175 return *new NTBaseCutT<Ntuple, T> (*this, iter_);
00176 }
00177
00179 NTBaseCutT<Ntuple, T>& operator[] (int offset_
00180 ) const {
00181 return *new NTBaseCutT<Ntuple, T> (*this, offset_);
00182 }
00183
00184 protected:
00186 virtual ~NTBaseCutT() {}
00187
00188
00189 const T *branchAddress;
00190 };
00191
00196 template<class Ntuple, class T>
00197 NTBaseCutT<Ntuple, T>& ntbasecut (const Ntuple& nt,
00198 T Ntuple::* p_mem,
00199 const char *name_ = "?",
00200 const IntFunPoR& iter_ = 0
00201 ) {
00202 return *new NTBaseCutT<Ntuple, T> (nt, p_mem, name_, iter_);
00203 }
00204
00209 template<class Ntuple, class T>
00210 NTBaseCutT<Ntuple, T>& ntbasecut (const Ntuple& nt,
00211 T Ntuple::* p_mem,
00212 const char *name_ = "?",
00213 int offset_
00214 ) {
00215 return *new NTBaseCutT<Ntuple, T> (nt, p_mem, name_, offset_);
00216 }
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227 template<class Ntuple, class T, unsigned int n>
00228 NTBaseCutT<Ntuple, T>& ntbasecut (const Ntuple& nt,
00229 T (Ntuple::* p_mem)[n],
00230 const char *name_ = "?",
00231 const IntFunPoR& iter_ = 0
00232 ) {
00233
00234
00235 T (Ntuple::* p_mem0) = reinterpret_cast<T Ntuple::*>(p_mem);
00236 return *new NTBaseCutT<Ntuple, T> (nt, p_mem0, name_, iter_);
00237 }
00238
00239 template<class Ntuple, class T, unsigned int n>
00240 NTBaseCutT<Ntuple, T>& ntbasecut (const Ntuple& nt,
00241 T (Ntuple::* p_mem)[n],
00242 const char *name_ = "?",
00243 int offset_
00244 ) {
00245
00246
00247 T (Ntuple::* p_mem0) = reinterpret_cast<T Ntuple::*>(p_mem);
00248 return *new NTBaseCutT<Ntuple, T> (nt, p_mem0, name_, offset_);
00249 }
00250
00251
00252 #endif