Fork me on GitHub

source: git/external/ExRootAnalysis/ExRootTreeBranch.cc@ 95fbe30

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 95fbe30 was cab38f6, checked in by Pavel Demin <pavel.demin@…>, 10 years ago

remove svn tags and fix formatting

  • Property mode set to 100644
File size: 2.0 KB
Line 
1
2/** \class ExRootTreeBranch
3 *
4 * Class handling object creation
5 * It is also used for output ROOT tree branches
6 *
7 * \author P. Demin - UCL, Louvain-la-Neuve
8 *
9 */
10
11#include "ExRootAnalysis/ExRootTreeBranch.h"
12
13#include "TFile.h"
14#include "TTree.h"
15#include "TString.h"
16#include "TClonesArray.h"
17
18#include <iostream>
19#include <stdexcept>
20#include <sstream>
21
22using namespace std;
23
24//------------------------------------------------------------------------------
25
26ExRootTreeBranch::ExRootTreeBranch(const char *name, TClass *cl, TTree *tree) :
27 fSize(0), fCapacity(1), fData(0)
28{
29 stringstream message;
30// cl->IgnoreTObjectStreamer();
31// cl->BypassStreamer();
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 message << "can't create TClonesArray for branch '" << name << "'";
48 throw runtime_error(message.str());
49 }
50}
51
52//------------------------------------------------------------------------------
53
54ExRootTreeBranch::~ExRootTreeBranch()
55{
56 if(fData) delete fData;
57}
58
59//------------------------------------------------------------------------------
60
61TObject *ExRootTreeBranch::NewEntry()
62{
63 if(!fData) return 0;
64
65 if(fSize >= fCapacity)
66 {
67 if(fCapacity < 10) fCapacity = 10;
68 else if(fCapacity < 30) fCapacity = 30;
69 else if(fCapacity < 100) fCapacity = 100;
70 else if(fCapacity < 250) fCapacity = 250;
71 else fCapacity *= 2;
72
73 fData->ExpandCreateFast(fCapacity);
74
75 fData->Clear();
76 fData->ExpandCreateFast(fSize);
77 }
78
79 return fData->AddrAt(fSize++);
80}
81
82//------------------------------------------------------------------------------
83
84void ExRootTreeBranch::Clear()
85{
86 fSize = 0;
87 if(fData) fData->Clear();
88}
89
90//------------------------------------------------------------------------------
91
Note: See TracBrowser for help on using the repository browser.