00001
00019 #ifndef __H1FUNS_H
00020 #define __H1FUNS_H
00021
00022 #include "jbltools/sfh/FillIterator.h"
00023 #include "jbltools/sfh/FloatFun.h"
00024 #include "jbltools/sfh/IntFun.h"
00025 #include "jbltools/sfh/BaseCut.h"
00026
00027 #include "H1Pointers/H1ClonesArrayPtr.h"
00028 #include "H1Mods/H1Part.h"
00029
00030 #include <cassert>
00031 #include <string>
00032 #include <cmath>
00033 #include <iostream>
00034
00035
00036 class JBLH1Ptr: public H1Ptr {
00037 public:
00038 const char *getBranchName() const {return fBranchName;}
00039 };
00040
00041 static std::string getH1PtrName (const H1Ptr& ptr) {
00042 const char *name = reinterpret_cast<const JBLH1Ptr&>(ptr).getBranchName();
00043 return std::string(name ? name : "");
00044 }
00045
00046
00048
00054 template <class H1SomePtr>
00055 class JBLH1FloatFunIter: public FloatFun {
00056 public:
00058 JBLH1FloatFunIter (const char *branchname_,
00059 const FillIterator& iter_
00060 )
00061 : FloatFun (std::string(branchname_)+'['+iter_.getName()+']'),
00062 ptr (*new H1SomePtr(branchname_)),
00063 iter (iter_)
00064 {
00065 assert (&ptr);
00066 assert (&iter);
00067 }
00069 JBLH1FloatFunIter (const H1SomePtr& ptr_,
00070 const FillIterator& iter_,
00071 const char *pointername_ = 0
00072 )
00073 : FloatFun (getH1PtrName(ptr_)+'['+iter_.getName()+']'),
00074 ptr (ptr_),
00075 iter (iter_)
00076 {
00077 assert (&ptr);
00078 assert (&iter);
00079 makeName (pointername_);
00080 }
00082 Float_FF operator() () const {
00083 assert (ptr.GetPointer());
00084 assert (iter() >= 0);
00085 assert (iter() < ptr.GetEntries());
00086 return ptr[iter()];
00087 }
00089 virtual const FillIterator *getIterator() const { return &iter; }
00090
00091 protected:
00093 virtual ~JBLH1FloatFunIter() {}
00094
00095 private:
00096
00097 const H1SomePtr& ptr;
00098 const FillIterator& iter;
00099 };
00100
00102
00111 template <class H1SomePtr>
00112 class JBLH1FloatFun: public FloatFun {
00113 public:
00115 explicit JBLH1FloatFun (const char *branchname_,
00116 int index_ = -1
00117 )
00118 : FloatFun (std::string(branchname_)+(index_>=0 ? (str('[')+str(index_)+']') : std::string(""))),
00119 ptr (*new H1SomePtr (branchname_)),
00120 index (index_ >= 0 ? index_ : 0),
00121 branchname (branchname_)
00122 {
00123 assert (&ptr);
00124 }
00126 explicit JBLH1FloatFun (const H1SomePtr& ptr_,
00127 int index_ = -1,
00128 const char *pointername_ = 0
00129 )
00130 : FloatFun (getH1PtrName(ptr_)
00131 +(index_>=0 ? (str('[')+str(index_)+']') : std::string(""))),
00132 ptr (ptr_),
00133 index (index_ >= 0 ? index_ : 0),
00134 branchname (getH1PtrName(ptr_))
00135
00136 {
00137 assert (&ptr);
00138 }
00139
00141 Float_FF operator() () const {
00142 assert (ptr.GetPointer());
00143 return ptr[index];
00144 }
00145
00147 JBLH1FloatFun<H1SomePtr>& operator[] (int index_) {
00148 return *new JBLH1FloatFun<H1SomePtr> (ptr, index_, branchname.c_str());
00149 }
00150
00152 JBLH1FloatFunIter<H1SomePtr>& operator[] (const FillIterator& iter_) {
00153 return *new JBLH1FloatFunIter<H1SomePtr> (ptr, iter_, branchname.c_str());
00154 }
00155
00156 protected:
00158 virtual ~JBLH1FloatFun() {}
00159
00160 private:
00161
00162 const H1SomePtr& ptr;
00163 int index;
00164 std::string branchname;
00165 };
00166
00167
00169
00175 template <class H1SomePtr>
00176 class JBLH1IntFunIter: public IntFun {
00177 public:
00179 JBLH1IntFunIter (const char *branchname_,
00180 const FillIterator& iter_
00181 )
00182 : IntFun (std::string(branchname_)+'['+iter_.getName()+']'),
00183 ptr (*new H1SomePtr (branchname_)),
00184 iter (iter_)
00185 {
00186 assert (&ptr);
00187 assert (&iter);
00188 }
00190 JBLH1IntFunIter (const H1SomePtr& ptr_,
00191 const FillIterator& iter_
00192 )
00193 : IntFun (getH1PtrName(ptr_)
00194 +'['+iter_.getName()+']'),
00195 ptr (ptr_),
00196 iter (iter_)
00197 {
00198 assert (&ptr);
00199 assert (&iter);
00200 }
00202 int operator() () const {
00203 assert (ptr.GetPointer());
00204 assert (iter() >= 0);
00205
00206 return ptr[iter()];
00207 }
00208
00210 virtual const FillIterator *getIterator() const { return &iter; }
00211
00212 protected:
00214 virtual ~JBLH1IntFunIter() {}
00215
00216 private:
00217
00218 const H1SomePtr& ptr;
00219 const FillIterator& iter;
00220 };
00221
00223
00232 template <class H1SomePtr>
00233 class JBLH1IntFun: public IntFun {
00234 public:
00236 explicit JBLH1IntFun (const char *branchname_,
00237 int index_ = -1
00238 )
00239 : IntFun (std::string(branchname_)+(index_>=0 ? (str('[')+str(index_)+']') : std::string(""))),
00240 ptr (*new H1SomePtr (branchname_)),
00241 index (index_ >= 0 ? index_ : 0)
00242 { assert (&ptr); }
00244 explicit JBLH1IntFun (const H1SomePtr& ptr_,
00245 int index_ = -1
00246 )
00247 : IntFun (getH1PtrName(ptr_)
00248 +(index_>= 0 ? (str('[')+str(index_)+']') : std::string(""))),
00249 ptr (ptr_),
00250 index (index_ >= 0 ? index_ : 0)
00251 {
00252 assert (&ptr);
00253 }
00254
00256 int operator() () const {
00257 assert (ptr.GetPointer());
00258 return ptr[index];
00259 }
00260
00262 JBLH1IntFun<H1SomePtr>& operator[] (int index_) {
00263 return *new JBLH1IntFun<H1SomePtr> (ptr, index_);
00264 }
00265
00267 JBLH1IntFunIter<H1SomePtr>& operator[] (const FillIterator& iter_) {
00268 return *new JBLH1IntFunIter<H1SomePtr> (ptr, iter_);
00269 }
00270
00272 FloatFun& Float () const {
00273 return *new JBLH1FloatFun<H1SomePtr> (ptr, index);
00274 }
00275
00276 protected:
00278 virtual ~JBLH1IntFun() {};
00279
00280 private:
00281 H1SomePtr ptr;
00282 int index;
00283 };
00284
00286
00296 template<class H1SomeArrayPtr = H1ClonesArrayPtr, class ArrayRow = H1Part>
00297 class JBLH1SomeArrayIterator: public FillIterator {
00298 public:
00300 JBLH1SomeArrayIterator ()
00301 : FillIterator(),
00302 ptr (*new H1SomeArrayPtr),
00303 index (0)
00304 {
00305 assert (&ptr);
00306 setName (reinterpret_cast<const JBLH1Ptr&>(ptr).getBranchName());
00307 std::cout << "JBLH1SomeArrayIterator: created '" << getName()
00308 << "' from new pointer\n";
00309 }
00311 explicit JBLH1SomeArrayIterator (const char *branchname_
00312 )
00313 : FillIterator(branchname_),
00314 ptr (*new H1SomeArrayPtr (branchname_)),
00315 index (0)
00316 {
00317 assert (&ptr);
00318 std::cout << "JBLH1SomeArrayIterator: created '" << getName()
00319 << "' from branch " << branchname_ << "\n";
00320 }
00322 explicit JBLH1SomeArrayIterator (const H1SomeArrayPtr& ptr_,
00323 const char *pointername_ = 0
00324 )
00325 : FillIterator(reinterpret_cast<const JBLH1Ptr&>(ptr).getBranchName()),
00326 ptr (ptr_), index (0)
00327 {
00328 assert (&ptr);
00329 std::cerr << "JBLH1SomeArrayIterator: created '" << getName()
00330 << "' from a pointer, pointername_='" << pointername_ << "'\n";
00331 }
00333 virtual int operator() () const {
00334
00335 assert (index >= 0);
00336
00337
00338
00339
00340
00341
00342 assert (index < ptr.GetEntries());
00343 return index;
00344 }
00346 virtual bool next() {
00347 return (++index < ptr.GetEntries());
00348 }
00350 virtual bool reset() {
00351 return ((index=0) < ptr.GetEntries());
00352 }
00354 virtual bool isValid() const {
00355 return index>=0 && index < ptr.GetEntries();
00356 }
00357
00359 inline virtual FloatFun& GetP() const;
00361 inline virtual FloatFun& GetPt() const;
00363 inline virtual FloatFun& GetPz() const;
00365 inline virtual FloatFun& GetE() const;
00367 inline virtual FloatFun& GetPhi() const;
00369 inline virtual FloatFun& GetTheta() const;
00371 inline virtual FloatFun& GetMass() const;
00373 inline virtual FloatFun& GetCharge() const;
00374
00375 inline const char *getBranchName() const {
00376 return reinterpret_cast<const JBLH1Ptr&>(ptr).getBranchName();
00377 }
00378
00380 template <class H1PartSome, class TM>
00381 inline FloatFun& Float(TM (H1PartSome::* p_mem)() const,
00382 const char *attribname = "?"
00383 ) const;
00385 template <class H1PartSome, class TM>
00386 inline FloatFun& GetFloatFun(TM (H1PartSome::* p_mem)() const,
00387 const char *attribname = "?"
00388 ) const;
00389
00391 template <class H1PartSome, class TM>
00392 inline IntFun& Int(TM (H1PartSome::* p_mem)() const,
00393 const char *attribname = "?"
00394 ) const;
00396 template <class H1PartSome, class TM>
00397 inline IntFun& GetIntFun(TM (H1PartSome::* p_mem)() const,
00398 const char *attribname = "?"
00399 ) const;
00400
00402 template <class H1PartSome, class TM>
00403 inline BaseCut& Bool(TM (H1PartSome::* p_mem)() const,
00404 const char *attribname = "?"
00405 ) const;
00407 template <class H1PartSome, class TM>
00408 inline BaseCut& GetBaseCut(TM (H1PartSome::* p_mem)() const,
00409 const char *attribname = "?"
00410 ) const;
00411
00413 const H1SomeArrayPtr& getBranchPointer() const {
00414 return ptr;
00415 }
00416
00417 protected:
00419 virtual ~JBLH1SomeArrayIterator() {}
00420
00421 private:
00422
00423 const H1SomeArrayPtr& ptr;
00424 int index;
00425 };
00426 typedef JBLH1SomeArrayIterator<H1ClonesArrayPtr> JBLH1ClonesArrayIterator;
00427
00429 class JBLH1ClonesArrayEntries: public IntFun {
00430 public:
00432 explicit JBLH1ClonesArrayEntries (const char *branchname_
00433 )
00434 : IntFun(branchname_),
00435 ptr (*new H1ClonesArrayPtr (branchname_))
00436 {
00437 assert (&ptr);
00438 }
00440 explicit JBLH1ClonesArrayEntries (const H1ClonesArrayPtr& ptr_
00441 )
00442 : IntFun(getH1PtrName(ptr_)),
00443 ptr (ptr_)
00444 {
00445 assert (&ptr);
00446 }
00448 virtual int operator() () const {return ptr.GetEntries();}
00449
00450 protected:
00452 virtual ~JBLH1ClonesArrayEntries() {};
00453
00454 private:
00455 const H1ClonesArrayPtr& ptr;
00456 };
00457
00458
00459
00460 template <class H1TObject=H1Part, class TM=Double_t>
00461 class JBLH1TObjectFloatFun: public FloatFun {
00462 public:
00464 JBLH1TObjectFloatFun(const char *branchname_,
00465 const FillIterator& iter_,
00466 TM (H1TObject::* p_mem_)() const = 0,
00467 const char *attribname_ = "?"
00468 )
00469 : FloatFun (std::string(branchname_)+'['+iter_.getName()+"]."+ (attribname_ ? attribname_ : "")),
00470 ptr (*new H1ClonesArrayPtr (branchname_)),
00471 iter (iter_),
00472 p_mem (p_mem_)
00473 {
00474 assert (&ptr);
00475 assert (&iter);
00476 }
00478 JBLH1TObjectFloatFun(const H1ClonesArrayPtr& ptr_,
00479 const FillIterator& iter_ ,
00480 TM (H1TObject::* p_mem_)() const = 0,
00481 const char *attribname_ = "?"
00482 )
00483 : FloatFun (getH1PtrName(ptr_)
00484 +'['+iter_.getName()+"]."+ (attribname_ ? attribname_ : "")),
00485 ptr (ptr_),
00486 iter (iter_),
00487 p_mem (p_mem_)
00488 {
00489 assert (&ptr);
00490 assert (&iter);
00491 }
00493 template <class H1SomeArrayPtr, class ArrayRow>
00494 JBLH1TObjectFloatFun (const JBLH1SomeArrayIterator<H1SomeArrayPtr, ArrayRow>& iter_,
00495 TM (H1TObject::* p_mem_)() const,
00496 const char *attribname_ = "?"
00497 )
00498 : FloatFun (std::string(iter_.getBranchName())+'['+iter_.getName()+"]."+ (attribname_ ? attribname_ : "")),
00499 ptr (iter_.getBranchPointer()),
00500 iter (iter_),
00501 p_mem (p_mem_)
00502 {
00503 assert (&ptr);
00504 assert (&iter);
00505 }
00507 virtual const FillIterator *getIterator() const { return &iter; }
00508
00509 virtual Float_FF operator() () const {
00510 assert (p_mem);
00511 if (H1TObject *h1part = dynamic_cast<H1TObject *>(ptr[iter()])) {
00512 return (h1part->*p_mem)();
00513 }
00514
00515
00516
00517 assert (0);
00518 return 0;
00519 }
00520
00521 protected:
00523 virtual ~JBLH1TObjectFloatFun() {}
00524
00525 protected:
00526
00527 const H1ClonesArrayPtr& ptr;
00528 const FillIterator& iter;
00529 TM (H1TObject::* p_mem)() const;
00530 };
00531
00532
00533 template <class H1TObject=H1Part, class TM=Int_t>
00534 class JBLH1TObjectIntFun: public IntFun {
00535 public:
00537 JBLH1TObjectIntFun(const char *branchname_,
00538 const FillIterator& iter_,
00539 TM (H1TObject::* p_mem_)() const = 0,
00540 const char *attribname_ = "?"
00541 )
00542 : IntFun (std::string(branchname_)+'['+iter_.getName()+"]."+ (attribname_ ? attribname_ : "")),
00543 ptr (*new H1ClonesArrayPtr (branchname_)),
00544 iter (iter_),
00545 p_mem (p_mem_)
00546 {}
00548 JBLH1TObjectIntFun(const H1ClonesArrayPtr& ptr_,
00549 const FillIterator& iter_ ,
00550 TM (H1TObject::* p_mem_)() const = 0,
00551 const char *attribname_ = "?"
00552 )
00553 : IntFun (getH1PtrName(ptr_)+'['+iter_.getName()+"]."+ (attribname_ ? attribname_ : "")),
00554 ptr (ptr_),
00555 iter (iter_),
00556 p_mem (p_mem_)
00557 {}
00559 template <class H1SomeArrayPtr, class ArrayRow>
00560 JBLH1TObjectIntFun (const JBLH1SomeArrayIterator<H1SomeArrayPtr, ArrayRow>& iter_,
00561 TM (H1TObject::* p_mem_)() const,
00562 const char *attribname_ = "?"
00563 )
00564 : IntFun (std::string(iter_.getBranchName())+'['+iter_.getName()+"]."+ (attribname_ ? attribname_ : "")),
00565 ptr (iter_.getBranchPointer()), iter (iter_), p_mem (p_mem_)
00566 {}
00568 virtual const FillIterator *getIterator() const { return &iter; }
00569
00570 virtual int operator() () const {
00571 assert (p_mem);
00572 if (H1TObject *h1part = dynamic_cast<H1TObject *>(ptr[iter()])) {
00573 return (h1part->*p_mem)();
00574 }
00575
00576
00577
00578 assert (0);
00579 return 0;
00580 }
00581 protected:
00583 virtual ~JBLH1TObjectIntFun() {};
00584
00585 protected:
00586
00587 const H1ClonesArrayPtr& ptr;
00588 const FillIterator& iter;
00589 TM (H1TObject::* p_mem)() const;
00590 };
00591
00592
00593 template <class H1TObject=H1Part, class TM=Bool_t>
00594 class JBLH1TObjectBaseCut: public BaseCut {
00595 public:
00597 JBLH1TObjectBaseCut(const char *branchname_,
00598 const FillIterator& iter_,
00599 TM (H1TObject::* p_mem_)() const = 0,
00600 const char *attribname_ = "?"
00601 )
00602 : BaseCut (std::string(branchname_)+'['+iter_.getName()+"]."+ (attribname_ ? attribname_ : "")),
00603 ptr (*new H1ClonesArrayPtr (branchname_)),
00604 iter (iter_),
00605 p_mem (p_mem_)
00606 {}
00608 JBLH1TObjectBaseCut (const H1ClonesArrayPtr& ptr_,
00609 const FillIterator& iter_ ,
00610 TM (H1TObject::* p_mem_)() const = 0,
00611 const char *attribname_ = "?"
00612 )
00613 : IntFun (getH1PtrName(ptr_)+'['+iter_.getName()+"]."+ (attribname_ ? attribname_ : "")),
00614 ptr (ptr_),
00615 iter (iter_),
00616 p_mem (p_mem_)
00617 {}
00619 template <class H1SomeArrayPtr>
00620 JBLH1TObjectBaseCut (const JBLH1SomeArrayIterator<H1SomeArrayPtr>& iter_,
00621 TM (H1TObject::* p_mem_)() const,
00622 const char *attribname_ = "?"
00623 )
00624 : FloatFun (std::string(iter_.getBranchName())+'['+iter_.getName()+"]."+ (attribname_ ? attribname_ : "")),
00625 ptr (iter_.getBranchPointer()),
00626 iter (iter_),
00627 p_mem (p_mem_)
00628 {}
00630 virtual const FillIterator *getIterator() const { return &iter; }
00631
00632 virtual bool operator() () const {
00633 assert (p_mem);
00634 if (H1TObject *h1part = dynamic_cast<H1TObject *>(ptr[iter()])) {
00635 return (h1part->*p_mem)();
00636 }
00637
00638
00639
00640 assert (0);
00641 return 0;
00642 }
00643 protected:
00645 virtual ~JBLH1TObjectBaseCut() {};
00646
00647 protected:
00648
00649 const H1ClonesArrayPtr& ptr;
00650 const FillIterator& iter;
00651 TM (H1TObject::* p_mem)() const;
00652 };
00653
00654
00655
00656 template<class H1SomeArrayPtr, class ArrayRow>
00657 FloatFun& JBLH1SomeArrayIterator<H1SomeArrayPtr, ArrayRow>::GetP() const {
00658 return *new JBLH1TObjectFloatFun<ArrayRow> (*this, &ArrayRow::GetP, "P");
00659 }
00660
00661 template<class H1SomeArrayPtr, class ArrayRow>
00662 FloatFun& JBLH1SomeArrayIterator<H1SomeArrayPtr, ArrayRow>::GetPt() const {
00663 return *new JBLH1TObjectFloatFun<ArrayRow> (*this, &ArrayRow::GetPt, "Pt");
00664 }
00665
00666 template<class H1SomeArrayPtr, class ArrayRow>
00667 FloatFun& JBLH1SomeArrayIterator<H1SomeArrayPtr, ArrayRow>::GetPz() const {
00668 return *new JBLH1TObjectFloatFun<ArrayRow> (*this, &ArrayRow::GetPz, "Pz");
00669 }
00670
00671 template<class H1SomeArrayPtr, class ArrayRow>
00672 FloatFun& JBLH1SomeArrayIterator<H1SomeArrayPtr, ArrayRow>::GetE() const {
00673 return *new JBLH1TObjectFloatFun<ArrayRow> (*this, &ArrayRow::GetE, "E");
00674 }
00675
00676 template<class H1SomeArrayPtr, class ArrayRow>
00677 FloatFun& JBLH1SomeArrayIterator<H1SomeArrayPtr, ArrayRow>::GetPhi() const {
00678 return *new JBLH1TObjectFloatFun<ArrayRow> (*this, &ArrayRow::GetPhi, "Phi");
00679 }
00680
00681 template<class H1SomeArrayPtr, class ArrayRow>
00682 FloatFun& JBLH1SomeArrayIterator<H1SomeArrayPtr, ArrayRow>::GetTheta() const {
00683 return *new JBLH1TObjectFloatFun<ArrayRow> (*this, &ArrayRow::GetTheta, "Theta");
00684 }
00685
00686 template<class H1SomeArrayPtr, class ArrayRow>
00687 FloatFun& JBLH1SomeArrayIterator<H1SomeArrayPtr, ArrayRow>::GetMass() const {
00688 return *new JBLH1TObjectFloatFun<ArrayRow> (*this, &ArrayRow::GetMass, "Mass");
00689 }
00690
00691 template<class H1SomeArrayPtr, class ArrayRow>
00692 FloatFun& JBLH1SomeArrayIterator<H1SomeArrayPtr, ArrayRow>::GetCharge() const {
00693 return *new JBLH1TObjectFloatFun<ArrayRow, Float_t> (*this, &ArrayRow::GetCharge, "Charge");
00694 }
00695
00696 template <class H1SomeArrayPtr, class ArrayRow>
00697 template <class H1PartSome, class TM>
00698 FloatFun& JBLH1SomeArrayIterator<H1SomeArrayPtr, ArrayRow>::Float(TM (H1PartSome::* p_mem)() const, const char *attribname) const {
00699 return *new JBLH1TObjectFloatFun<H1PartSome, TM> (*this, p_mem, attribname);
00700 }
00701 template <class H1SomeArrayPtr, class ArrayRow>
00702 template <class H1PartSome, class TM>
00703 FloatFun& JBLH1SomeArrayIterator<H1SomeArrayPtr, ArrayRow>::GetFloatFun(TM (H1PartSome::* p_mem)() const, const char *attribname) const {
00704 return *new JBLH1TObjectFloatFun<H1PartSome, TM> (*this, p_mem, attribname);
00705 }
00706
00707 template <class H1SomeArrayPtr, class ArrayRow>
00708 template <class H1PartSome, class TM>
00709 IntFun& JBLH1SomeArrayIterator<H1SomeArrayPtr, ArrayRow>::Int(TM (H1PartSome::* p_mem)() const, const char *attribname) const {
00710 return *new JBLH1TObjectIntFun<H1PartSome, TM> (*this, p_mem, attribname);
00711 }
00712 template <class H1SomeArrayPtr, class ArrayRow>
00713 template <class H1PartSome, class TM>
00714 IntFun& JBLH1SomeArrayIterator<H1SomeArrayPtr, ArrayRow>::GetIntFun(TM (H1PartSome::* p_mem)() const, const char *attribname) const {
00715 return *new JBLH1TObjectIntFun<H1PartSome, TM> (*this, p_mem, attribname);
00716 }
00717
00718 template <class H1SomeArrayPtr, class ArrayRow>
00719 template <class H1PartSome, class TM>
00720 BaseCut& JBLH1SomeArrayIterator<H1SomeArrayPtr, ArrayRow>::Bool(TM (H1PartSome::* p_mem)() const, const char *attribname) const {
00721 return *new JBLH1TObjectBaseCut<H1PartSome, TM> (*this, p_mem, attribname);
00722 }
00723 template <class H1SomeArrayPtr, class ArrayRow>
00724 template <class H1PartSome, class TM>
00725 BaseCut& JBLH1SomeArrayIterator<H1SomeArrayPtr, ArrayRow>::GetBaseCut(TM (H1PartSome::* p_mem)() const, const char *attribname) const {
00726 return *new JBLH1TObjectBaseCut<H1PartSome, TM> (*this, p_mem, attribname);
00727 }
00728
00729
00730 #endif