Skip to content

Commit 7b898c8

Browse files
committed
add GetObjectWithNullptrCheck to HelperFunctions
1 parent 2593027 commit 7b898c8

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

infra/HelperFunctions.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "SimpleCut.hpp"
55

6+
#include <TFile.h>
7+
68
#include <sstream>
79
#include <string>
810
#include <vector>
@@ -101,5 +103,14 @@ inline std::vector<T> MergeVectors(const std::vector<T>& vec1, const std::vector
101103
return MergeVectors(vec1, MergeVectors(vec2, args...));
102104
}
103105

106+
template<typename T>
107+
inline T* GetObjectWithNullptrCheck(TFile* fileIn, const std::string& objectName) {
108+
T* ptr = fileIn->Get<T>(objectName.c_str());
109+
if (ptr == nullptr) {
110+
throw std::runtime_error("HelperFunctions::GetObjectWithNullptrCheck() - object " + objectName + " in file " + fileIn->GetName() + " is missing");
111+
}
112+
return ptr;
113+
}
114+
104115
}// namespace HelperFunctions
105116
#endif// ANALYSISTREE_INFRA_HELPER_FUNCTIONS_HPP

0 commit comments

Comments
 (0)