FairRoot/PandaRoot
SimpleNtp.C
Go to the documentation of this file.
1 #include "TTree.h"
2 #include "TString.h"
3 #include <map>
4 #include <iostream>
5 
6 using std::cout;
7 using std::endl;
8 
9 class SimpleNtp {
10 public:
11 
12  SimpleNtp(TString name, TString title, int maxsize = 100) {
13  fTree = new TTree(name, title);
14  fValues = new Float_t[maxsize];
15  fBranchMap.clear();
16  fSize=0;
17  fMax=maxsize;
18  };
19 
20  ~SimpleNtp(){delete fTree; delete[] fValues;}
21 
22  void Column(TString name, Float_t value);
23  void DumpData() { fTree->Fill(); }
24 
25 private:
26  TTree *fTree;
27  std::map<TString, Int_t> fBranchMap;
28  Float_t *fValues;
29  int fSize;
30  int fMax;
31 };
32 
33 void SimpleNtp::Column(TString name, Float_t value)
34 {
35  if (fBranchMap.find(name)==fBranchMap.end())
36  {
37  if (fSize<fMax)
38  {
39  fTree->Branch(name.Data(),&(fValues[fSize]));
41  }
42  else
43  {
44  cout <<" - WARNING - max size reached, branch '"<<name.Data()<<"' is not created!"<<endl;
45  return;
46  }
47  }
48  fValues[fBranchMap[name]]=value;
49 }
TTree * fTree
Definition: SimpleNtp.C:26
SimpleNtp(TString name, TString title, int maxsize=100)
Definition: SimpleNtp.C:12
int fMax
Definition: SimpleNtp.C:30
std::map< TString, Int_t > fBranchMap
Definition: SimpleNtp.C:27
int fSize
Definition: SimpleNtp.C:29
Float_t * fValues
Definition: SimpleNtp.C:28
TString name
void Column(TString name, Float_t value)
Definition: SimpleNtp.C:33
void DumpData()
Definition: SimpleNtp.C:23
~SimpleNtp()
Definition: SimpleNtp.C:20