1 |
|
---|
2 | /** \class ExRootTreeBranch
|
---|
3 | *
|
---|
4 | * Class handling output ROOT tree branch
|
---|
5 | *
|
---|
6 | * $Date: 2009-02-02 11:32:01 $
|
---|
7 | * $Revision: 1.2 $
|
---|
8 | *
|
---|
9 | *
|
---|
10 | * \author S. Ovyn - UCL, Louvain-la-Neuve
|
---|
11 | *
|
---|
12 | */
|
---|
13 |
|
---|
14 | #include "ExRootTreeBranch.h"
|
---|
15 | #include "TTree.h"
|
---|
16 | #include "TClonesArray.h"
|
---|
17 |
|
---|
18 | //------------------------------------------------------------------------------
|
---|
19 |
|
---|
20 | ExRootTreeBranch::ExRootTreeBranch(const TString &name, TClass *cl, TTree *tree) :
|
---|
21 | fSize(0), fCapacity(1), fData(0)
|
---|
22 | {
|
---|
23 | cl->IgnoreTObjectStreamer();
|
---|
24 | fData = new TClonesArray(cl, fCapacity);
|
---|
25 |
|
---|
26 | if(fData)
|
---|
27 | {
|
---|
28 | fData->ExpandCreateFast(fCapacity);
|
---|
29 | fData->Clear();
|
---|
30 | tree->Branch(name, &fData, 64000);
|
---|
31 | tree->Branch(name + "_size", &fSize, name + "_size/I");
|
---|
32 | }
|
---|
33 | else
|
---|
34 | {
|
---|
35 | throw MemoryAllocationExeption();
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | //------------------------------------------------------------------------------
|
---|
40 |
|
---|
41 | ExRootTreeBranch::~ExRootTreeBranch()
|
---|
42 | {
|
---|
43 | if(fData) delete fData;
|
---|
44 | }
|
---|
45 |
|
---|
46 | //------------------------------------------------------------------------------
|
---|
47 |
|
---|
48 | TObject *ExRootTreeBranch::NewEntry()
|
---|
49 | {
|
---|
50 | if(!fData) return 0;
|
---|
51 |
|
---|
52 | if(fSize >= fCapacity)
|
---|
53 | {
|
---|
54 | Int_t entry;
|
---|
55 |
|
---|
56 | if(fCapacity < 10) fCapacity = 10;
|
---|
57 | else if(fCapacity < 30) fCapacity = 30;
|
---|
58 | else if(fCapacity < 100) fCapacity = 100;
|
---|
59 | else if(fCapacity < 250) fCapacity = 250;
|
---|
60 | else fCapacity *= 2;
|
---|
61 |
|
---|
62 | fData->ExpandCreateFast(fCapacity);
|
---|
63 |
|
---|
64 | fData->Clear();
|
---|
65 | for(entry = 0; entry < fSize; ++entry) fData->AddrAt(entry);
|
---|
66 | }
|
---|
67 |
|
---|
68 | return fData->AddrAt(fSize++);
|
---|
69 | }
|
---|
70 |
|
---|
71 | //------------------------------------------------------------------------------
|
---|
72 |
|
---|
73 | void ExRootTreeBranch::Clear()
|
---|
74 | {
|
---|
75 | fSize = 0;
|
---|
76 | if(fData) fData->Clear();
|
---|
77 | }
|
---|
78 |
|
---|
79 | //------------------------------------------------------------------------------
|
---|
80 |
|
---|