Fork me on GitHub

source: git/external/ExRootAnalysis/ExRootTreeBranch.cc@ 127644a

Last change on this file since 127644a was 341014c, checked in by Pavel Demin <pavel-demin@…>, 6 years ago

apply .clang-format to all .h, .cc and .cpp files

  • 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 "TClonesArray.h"
14#include "TFile.h"
15#include "TString.h"
16#include "TTree.h"
17
18#include <iostream>
19#include <sstream>
20#include <stdexcept>
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)
68 fCapacity = 10;
69 else if(fCapacity < 30)
70 fCapacity = 30;
71 else if(fCapacity < 100)
72 fCapacity = 100;
73 else if(fCapacity < 250)
74 fCapacity = 250;
75 else
76 fCapacity *= 2;
77
78 fData->ExpandCreateFast(fCapacity);
79
80 fData->Clear();
81 fData->ExpandCreateFast(fSize);
82 }
83
84 return fData->AddrAt(fSize++);
85}
86
87//------------------------------------------------------------------------------
88
89void ExRootTreeBranch::Clear()
90{
91 fSize = 0;
92 if(fData) fData->Clear();
93}
94
95//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.