ATLAS Offline Software
TreeManager.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3  */
4 
6 
7 #include "TFile.h"
8 
9 #include <iostream>
10 
12 using namespace TopEventSelectionTools;
13 
14 namespace top {
15  TreeManager::TreeManager() :
16  m_name("NULL"),
17  m_tree(nullptr) {
18  }
19 
20  TreeManager::TreeManager(const std::string& name, TFile* outputFile, const int nEventAutoFlush,
21  const int basketSizePrimitive, const int basketSizeVector) :
22  m_name(name),
23  m_tree(nullptr) {
24  outputFile->cd();
25  m_tree = new TTree(name.c_str(), "tree");
26  m_tree->SetAutoFlush(nEventAutoFlush);
27  m_tree->SetAutoSave(0);
28  m_basketSizePrimitive = basketSizePrimitive;
29  m_basketSizeVector = basketSizeVector;
30  }
31 
33  m_name(std::move(rhs.m_name)),
34  m_tree(std::move(rhs.m_tree)),
35  m_outputVarPointers(std::move(rhs.m_outputVarPointers)) {
36  }
37 
38  void TreeManager::initialize(const std::string& name, TFile* outputFile, const int nEventAutoFlush,
39  const int basketSizePrimitive, const int basketSizeVector) {
40  if (m_tree) {
41  ATH_MSG_WARNING("Tried to call initialize, but tree is already created. Doing nothing.");
42  return;
43  }
44 
45  outputFile->cd();
46  m_tree = new TTree(name.c_str(), "tree");
47  m_tree->SetAutoFlush(nEventAutoFlush);
48  m_tree->SetAutoSave(0);
49  m_basketSizePrimitive = basketSizePrimitive;
50  m_basketSizeVector = basketSizeVector;
51  }
52 
54  m_tree->Fill();
55  }
56 
57  const std::string& TreeManager::name() const {
58  return m_name;
59  }
60 
61  const char* TreeManager::RootType(const char* typeid_type) {
62  // Check that we received a reasonable input:
63  if (strlen(typeid_type) != 1) {
64  // SLogger m_logger( "SCycleBaseNTuple" );
65  // REPORT_ERROR( "Received a complex object description: " << typeid_type );
66  // throw SError( "SCycleBaseNTuple::RootType received complex object "
67  // "description", SError::StopExecution );
68  }
69 
70  // Do the hard-coded translation:
71  switch (typeid_type[ 0 ]) {
72  case 'c':
73  return "B";
74 
75  break;
76 
77  case 'h':
78  return "b";
79 
80  break;
81 
82  case 's':
83  return "S";
84 
85  break;
86 
87  case 't':
88  return "s";
89 
90  break;
91 
92  case 'i':
93  return "I";
94 
95  break;
96 
97  case 'j':
98  return "i";
99 
100  break;
101 
102  case 'f':
103  return "F";
104 
105  break;
106 
107  case 'd':
108  return "D";
109 
110  break;
111 
112  case 'x':
113  return "L";
114 
115  break;
116 
117  case 'y':
118  return "l";
119 
120  break;
121 
122  case 'b':
123  return "O";
124 
125  break;
126  }
127 
128  return "";
129  }
130 
131  const char* TreeManager::TypeidType(const char* root_type) {
132  // Do the hard-coded translation:
133  if (!strcmp(root_type, "Char_t")) {
134  return "c";
135  } else if (!strcmp(root_type, "UChar_t")) {
136  return "h";
137  } else if (!strcmp(root_type, "Short_t")) {
138  return "s";
139  } else if (!strcmp(root_type, "UShort_t")) {
140  return "t";
141  } else if (!strcmp(root_type, "Int_t")) {
142  return "i";
143  } else if (!strcmp(root_type, "UInt_t")) {
144  return "j";
145  } else if (!strcmp(root_type, "Float_t")) {
146  return "f";
147  } else if (!strcmp(root_type, "Double_t")) {
148  return "d";
149  } else if (!strcmp(root_type, "Long64_t")) {
150  return "x";
151  } else if (!strcmp(root_type, "ULong64_t")) {
152  return "y";
153  } else if (!strcmp(root_type, "Bool_t")) {
154  return "b";
155  }
156 
157  return "";
158  }
159 }
top::TreeManager::TypeidType
const char * TypeidType(const char *root_type)
Stolen from SFrame code.
Definition: TreeManager.cxx:131
top::TreeManager::m_tree
TTree * m_tree
Pointer to the TTree, created by this class in the constructor.
Definition: TreeManager.h:146
top
TopConfig A simple configuration that is NOT a singleton.
Definition: AnalysisTrackingHelper.cxx:58
top::TreeManager::m_basketSizePrimitive
int m_basketSizePrimitive
Definition: TreeManager.h:172
top::TreeManager::RootType
const char * RootType(const char *typeid_type)
Stolen from SFrame code.
Definition: TreeManager.cxx:61
top::TreeManager::TreeManager
TreeManager()
Default constructor - note need to initialize the class if you use this.
Definition: TreeManager.cxx:15
top::TreeManager::fill
void fill()
Calls TTree::Fill.
Definition: TreeManager.cxx:53
MsgCategory.h
compareGeometries.outputFile
string outputFile
Definition: compareGeometries.py:25
top::TreeManager::m_name
std::string m_name
name of the tree
Definition: TreeManager.h:110
top::TreeManager::initialize
void initialize(const std::string &name, TFile *outputFile, const int, const int, const int)
Initialize the class with a new output file.
Definition: TreeManager.cxx:38
TreeManager.h
top::TreeManager::m_basketSizeVector
int m_basketSizeVector
Definition: TreeManager.h:173
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
top::TreeManager::name
const std::string & name() const
name of the TTree
Definition: TreeManager.cxx:57
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
top::TreeManager
A class that hopefully makes making a flat ntuple tree a bit easier since you don't need to worry abo...
Definition: TreeManager.h:26