Fork me on GitHub

source: git/external/ExRootAnalysis/ExRootTreeBranch.cc@ a0431dc

ImprovedOutputFile Timing dual_readout llp
Last change on this file since a0431dc was d7d2da3, checked in by pavel <pavel@…>, 12 years ago

move branches/ModularDelphes to trunk

  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[d7d2da3]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#include <stdexcept>
24#include <sstream>
25
26using namespace std;
27
28//------------------------------------------------------------------------------
29
30ExRootTreeBranch::ExRootTreeBranch(const char *name, TClass *cl, TTree *tree) :
31 fSize(0), fCapacity(1), fData(0)
32{
33 stringstream message;
34// cl->IgnoreTObjectStreamer();
35// cl->BypassStreamer();
36 fData = new TClonesArray(cl, fCapacity);
37
38 if(fData)
39 {
40 fData->SetName(name);
41 fData->ExpandCreateFast(fCapacity);
42 fData->Clear();
43 if(tree)
44 {
45 tree->Branch(name, &fData, 64000);
46 tree->Branch(TString(name) + "_size", &fSize, TString(name) + "_size/I");
47 }
48 }
49 else
50 {
51 message << "can't create TClonesArray for branch '" << name << "'";
52 throw runtime_error(message.str());
53 }
54}
55
56//------------------------------------------------------------------------------
57
58ExRootTreeBranch::~ExRootTreeBranch()
59{
60 if(fData) delete fData;
61}
62
63//------------------------------------------------------------------------------
64
65TObject *ExRootTreeBranch::NewEntry()
66{
67 if(!fData) return 0;
68
69 if(fSize >= fCapacity)
70 {
71 if(fCapacity < 10) fCapacity = 10;
72 else if(fCapacity < 30) fCapacity = 30;
73 else if(fCapacity < 100) fCapacity = 100;
74 else if(fCapacity < 250) fCapacity = 250;
75 else fCapacity *= 2;
76
77 fData->ExpandCreateFast(fCapacity);
78
79 fData->Clear();
80 fData->ExpandCreateFast(fSize);
81 }
82
83 return fData->AddrAt(fSize++);
84}
85
86//------------------------------------------------------------------------------
87
88void ExRootTreeBranch::Clear()
89{
90 fSize = 0;
91 if(fData) fData->Clear();
92}
93
94//------------------------------------------------------------------------------
95
Note: See TracBrowser for help on using the repository browser.