source: trunk/src/ExRootTreeBranch.cc@ 3

Last change on this file since 3 was 2, checked in by Pavel Demin, 16 years ago

first commit

File size: 1.8 KB
RevLine 
[2]1
2/** \class ExRootTreeBranch
3*
4* Class handling object creation
5* It is also used for output ROOT tree branches
6*
7* $Date: 2008-06-04 13:57:56 $
8* $Revision: 1.1 $
9*
10*
11* \author P. Demin - UCL, Louvain-la-Neuve
12*
13*/
14
15#include "ExRootAnalysis/ExRootTreeBranch.h"
16
17#include "TFile.h"
18#include "TTree.h"
19#include "TString.h"
20#include "TClonesArray.h"
21
22#include <iostream>
23
24using namespace std;
25
26//------------------------------------------------------------------------------
27
28ExRootTreeBranch::ExRootTreeBranch(const char *name, TClass *cl, TTree *tree) :
29 fSize(0), fCapacity(1), fData(0)
30{
31// cl->IgnoreTObjectStreamer();
32 fData = new TClonesArray(cl, fCapacity);
33
34 if(fData)
35 {
36 fData->SetName(name);
37 fData->ExpandCreateFast(fCapacity);
38 fData->Clear();
39 if(tree)
40 {
41 tree->Branch(name, &fData, 64000);
42 tree->Branch(TString(name) + "_size", &fSize, TString(name) + "_size/I");
43 }
44 }
45 else
46 {
47 throw MemoryAllocationExeption();
48 }
49}
50
51//------------------------------------------------------------------------------
52
53ExRootTreeBranch::~ExRootTreeBranch()
54{
55 if(fData) delete fData;
56}
57
58//------------------------------------------------------------------------------
59
60TObject *ExRootTreeBranch::NewEntry()
61{
62 if(!fData) return 0;
63
64 if(fSize >= fCapacity)
65 {
66 if(fCapacity < 10) fCapacity = 10;
67 else if(fCapacity < 30) fCapacity = 30;
68 else if(fCapacity < 100) fCapacity = 100;
69 else if(fCapacity < 250) fCapacity = 250;
70 else fCapacity *= 2;
71
72 fData->ExpandCreateFast(fCapacity);
73
74 fData->Clear();
75 fData->ExpandCreateFast(fSize);
76 }
77
78 return fData->AddrAt(fSize++);
79}
80
81//------------------------------------------------------------------------------
82
83void ExRootTreeBranch::Clear()
84{
85 fSize = 0;
86 if(fData) fData->Clear();
87}
88
89//------------------------------------------------------------------------------
90
Note: See TracBrowser for help on using the repository browser.