1 #ifndef DTreeInterface_h
2 #define DTreeInterface_h
15 #include <TDirectory.h>
17 #include <TClonesArray.h>
20 #include <TLorentzVector.h>
22 #include <JANA/JApplication.h>
50 static DTreeInterface* Create_DTreeInterface(
string locTreeName,
string locFileName);
56 void Set_InitialArraySize(
string locArraySizeBranchName, UInt_t locInitialSize);
60 void Set_TreeIndexBranchNames(
string locTreeIndex_MajorBranchName,
string locTreeIndex_MinorBranchName =
"0");
63 bool Get_BranchesCreatedFlag(
void)
const;
64 const TList* Get_UserInfo(
void)
const;
79 void GetOrCreate_FileAndTree(
string locTreeName);
89 void Create_Branch(
const DTreeBranchRegister& locTreeBranchRegister,
string locBranchName, map<string, size_t>& locFundamentalArraySizeMap);
90 void Create_Branch(
string locBranchName, type_index locTypeIndex,
size_t locArraySize,
string locArraySizeName);
93 template <
typename DType>
typename enable_if<std::is_base_of<TObject, DType>::value,
void>::type
94 Create_Branch(
string locBranchName,
size_t locArraySize,
string locArraySizeName);
97 template <
typename DType>
typename enable_if<!std::is_base_of<TObject, DType>::value,
void>::type
98 Create_Branch(
string locBranchName,
size_t locArraySize,
string locArraySizeName);
100 template <
typename DType>
void Create_Branch_Fundamental(
string locBranchName);
101 template <
typename DType>
void Create_Branch_TObject(
string locBranchName);
102 template <
typename DType>
void Create_Branch_FundamentalArray(
string locBranchName,
string locArraySizeString,
unsigned int locInitialSize);
103 template <
typename DType>
void Create_Branch_ClonesArray(
string locBranchName,
unsigned int locSize);
107 void Change_ArraySize(
string locBranchName, type_index locTypeIndex,
size_t locNewArraySize);
108 template <
typename DType>
void Change_ArraySize(
string locBranchName,
int locNewArraySize);
109 void Fill(
string locBranchName, type_index locTypeIndex,
void* locVoidPointer,
bool locIsArrayFlag,
size_t locArrayIndex = 0);
110 template <
typename DType>
void Fill_TObject(
string locBranchName, DType& locObject,
bool locIsArrayFlag,
size_t locArrayIndex);
114 template <
typename DType> DType* Get_Pointer_Fundamental(
string locBranchName)
const;
115 template <
typename DType> DType* Get_Pointer_TObject(
string locBranchName)
const;
116 TClonesArray* Get_Pointer_TClonesArray(
string locBranchName);
138 map<string, int>& Get_NumWritersByFileMap(
void)
const;
139 map<string, size_t>& Get_FundamentalArraySizeMap(TTree* locTree)
const;
153 size_t dMaxArraySize = 1000;
154 Long64_t dAutoFlush = -5000000;
164 TBranch* locBranch = dTree->GetBranch(locBranchName.c_str());
165 return ((locBranch != NULL) ? (DType*)locBranch->GetAddress() : NULL);
170 TBranch* locBranch = dTree->GetBranch(locBranchName.c_str());
171 return ((locBranch != NULL) ? *(DType**)locBranch->GetAddress() : NULL);
176 TBranch* locBranch = dTree->GetBranch(locBranchName.c_str());
177 return ((locBranch != NULL) ? *(TClonesArray**)locBranch->GetAddress() : NULL);
182 template <
typename DType>
inline typename enable_if<std::is_base_of<TObject, DType>::value,
void>::type
185 if(locArraySize == 0)
186 Create_Branch_TObject<DType>(locBranchName);
188 Create_Branch_ClonesArray<DType>(locBranchName, locArraySize);
191 template <
typename DType>
inline typename enable_if<!std::is_base_of<TObject, DType>::value,
void>::type
194 if(locArraySize == 0)
195 Create_Branch_Fundamental<DType>(locBranchName);
197 Create_Branch_FundamentalArray<DType>(locBranchName, locArraySizeName, locArraySize);
202 if(dTree->GetBranch(locBranchName.c_str()) != NULL)
206 string locTypeName = locBranchName +
string(
"/") + locTypeString;
207 dTree->Branch(locBranchName.c_str(),
new DType(), locTypeName.c_str());
212 if(dTree->GetBranch(locBranchName.c_str()) != NULL)
215 dMemoryMap_TObject[locBranchName] = (TObject*)(
new DType());
216 dTree->Branch(locBranchName.c_str(), (DType**)&(dMemoryMap_TObject[locBranchName]), 32000, 0);
221 if(dTree->GetBranch(locBranchName.c_str()) != NULL)
225 string locArrayName = locBranchName +
string(
"[") + locArraySizeString +
string(
"]/") + locTypeString;
226 dTree->Branch(locBranchName.c_str(),
new DType[locInitialSize], locArrayName.c_str());
231 if(dTree->GetBranch(locBranchName.c_str()) != NULL)
234 dMemoryMap_ClonesArray[locBranchName] =
new TClonesArray(DType::Class()->GetName(), locInitialSize);
235 dTree->Branch(locBranchName.c_str(), &(dMemoryMap_ClonesArray[locBranchName]), 32000, 0);
257 dTreeIndex_MajorBranchName = locTreeIndex_MajorBranchName;
258 dTreeIndex_MinorBranchName = locTreeIndex_MinorBranchName;
266 DType* locOldBranchAddress = Get_Pointer_Fundamental<DType>(locBranchName);
267 dTree->SetBranchAddress(locBranchName.c_str(),
new DType[locNewArraySize]);
268 delete[] locOldBranchAddress;
275 TClonesArray* locClonesArray = Get_Pointer_TClonesArray(locBranchName);
276 *(DType*)locClonesArray->ConstructedAt(locArrayIndex) = locObject;
279 *Get_Pointer_TObject<DType>(locBranchName) = locObject;
282 #endif //DTreeInterface_h
DType * Get_Pointer_TObject(string locBranchName) const
static const char * GetTypeString()
map< string, TClonesArray * > dMemoryMap_ClonesArray
void Change_ArraySize(string locBranchName, type_index locTypeIndex, size_t locNewArraySize)
DType * Get_Pointer_Fundamental(string locBranchName) const
static const char * GetTypeString()
void Create_Branch(const DTreeBranchRegister &locTreeBranchRegister, string locBranchName, map< string, size_t > &locFundamentalArraySizeMap)
string dTreeIndex_MinorBranchName
static const char * GetTypeString()
static const char * GetTypeString()
static const char * GetTypeString()
static const char * GetTypeString()
void Fill_TObject(string locBranchName, DType &locObject, bool locIsArrayFlag, size_t locArrayIndex)
static const char * GetTypeString()
void Create_Branch_Fundamental(string locBranchName)
static const char * GetTypeString()
static const char * GetTypeString()
void Set_TreeIndexBranchNames(string locTreeIndex_MajorBranchName, string locTreeIndex_MinorBranchName="0")
void Create_Branch_ClonesArray(string locBranchName, unsigned int locSize)
static const char * GetTypeString()
static const char * GetTypeString()
void Create_Branch_FundamentalArray(string locBranchName, string locArraySizeString, unsigned int locInitialSize)
map< string, TObject * > dMemoryMap_TObject
static const char * GetTypeString()
TClonesArray * Get_Pointer_TClonesArray(string locBranchName)
string dTreeIndex_MajorBranchName
void Create_Branch_TObject(string locBranchName)