Fork me on GitHub

source: svn/trunk/Utilities/ExRootAnalysis/src/ExRootTreeBranch.cc@ 206

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

first commit

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