Rev | Line | |
---|
[3] | 1 | #ifndef TSimpleBranch_h
|
---|
| 2 | #define TSimpleBranch_h
|
---|
| 3 |
|
---|
| 4 | #include "TTree.h"
|
---|
| 5 | #include "TClonesArray.h"
|
---|
| 6 |
|
---|
| 7 | class TBaseBranch
|
---|
| 8 | {
|
---|
| 9 | public:
|
---|
| 10 |
|
---|
| 11 | class OverFlow{};
|
---|
| 12 |
|
---|
| 13 | TBaseBranch() : fSize(0), fMaxSize(0), fData(0) {}
|
---|
| 14 |
|
---|
| 15 | ~TBaseBranch() { if(fData) delete fData; }
|
---|
| 16 |
|
---|
| 17 | void Clear()
|
---|
| 18 | {
|
---|
| 19 | fSize = 0;
|
---|
| 20 | if(fData) fData->Clear();
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | protected:
|
---|
| 24 |
|
---|
| 25 | Int_t fSize, fMaxSize;
|
---|
| 26 | TClonesArray *fData;
|
---|
| 27 | };
|
---|
| 28 |
|
---|
| 29 | //------------------------------------------------------------------------------
|
---|
| 30 |
|
---|
| 31 | template<typename T>
|
---|
| 32 | class TSimpleBranch: public TBaseBranch
|
---|
| 33 | {
|
---|
| 34 | public:
|
---|
| 35 |
|
---|
| 36 | TSimpleBranch(const TString &name, Int_t maxsize, TTree *tree)
|
---|
| 37 | {
|
---|
| 38 | fMaxSize = maxsize;
|
---|
| 39 |
|
---|
| 40 | if(fMaxSize > 1)
|
---|
| 41 | {
|
---|
| 42 | tree->Branch(name + "_size", &fSize, name + "_size/I");
|
---|
| 43 | }
|
---|
| 44 | else
|
---|
| 45 | {
|
---|
| 46 | fMaxSize = 1;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | T::Class()->IgnoreTObjectStreamer();
|
---|
| 50 | fData = new TClonesArray(T::Class(), maxsize);
|
---|
| 51 | fData->ExpandCreateFast(maxsize);
|
---|
| 52 |
|
---|
| 53 | tree->Branch(name, &fData, 64000, 2);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | T *NewEntry()
|
---|
| 57 | {
|
---|
| 58 | if(fSize >= fMaxSize) throw OverFlow();
|
---|
| 59 | return fData ? static_cast<T*>(fData->AddrAt(fSize++)) : 0;
|
---|
| 60 | }
|
---|
| 61 | };
|
---|
| 62 |
|
---|
| 63 | #endif /* TSimpleBranch */
|
---|
| 64 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.