Fork me on GitHub

source: svn/trunk/Utilities/ExRootAnalysis/interface/TSimpleBranch.h@ 13

Last change on this file since 13 was 3, checked in by Xavier Rouby, 16 years ago

first commit

File size: 1.1 KB
Line 
1#ifndef TSimpleBranch_h
2#define TSimpleBranch_h
3
4#include "TTree.h"
5#include "TClonesArray.h"
6
7class TBaseBranch
8{
9public:
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
23protected:
24
25 Int_t fSize, fMaxSize;
26 TClonesArray *fData;
27};
28
29//------------------------------------------------------------------------------
30
31template<typename T>
32class TSimpleBranch: public TBaseBranch
33{
34public:
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.