17#include <TChainElement.h>
20#include <TFriendElement.h>
22#include <TMethodCall.h>
33#ifndef XAOD_STANDALONE
92 "Did not call finishWritingTo() before destroying the TEvent object!");
108 if (pattern.size()) {
117 return StatusCode::SUCCESS;
131 std::string_view treeName) {
134 if (
file ==
nullptr) {
136 return StatusCode::SUCCESS;
163 ATH_MSG_ERROR(
"Couldn't find metadata tree on input. Object is unusable!");
164 return StatusCode::FAILURE;
171 return StatusCode::FAILURE;
176 ATH_MSG_WARNING(
"Was expecting a metadata tree with size 1, instead of "
178 ATH_MSG_WARNING(
"The input file was most probably produced by hadd...");
184 static const std::string eventFormatTypeName =
186 ::TClass* cl = ::TClass::GetClass(eventFormatTypeName.c_str());
193 auto readEventFormatMetadata =
194 [&](std::string_view thisTreeName) -> StatusCode {
196 TTree* metaTree =
file->Get<TTree>(thisTreeName.data());
197 if (metaTree ==
nullptr) {
198 ATH_MSG_ERROR(
"Couldn't find metadata tree \"" << thisTreeName
200 return StatusCode::FAILURE;
203 if (metaTree->LoadTree(0) < 0) {
205 << thisTreeName <<
"\"");
206 return StatusCode::FAILURE;
210 const std::string eventFormatBranchName =
212 if (!metaTree->GetBranch(eventFormatBranchName.c_str())) {
216 ATH_MSG_INFO(
"Input file provides no event or metadata");
217 return StatusCode::RECOVERABLE;
224 metaTree->SetBranchAddress(eventFormatBranchName.c_str(), &format, &br);
226 ATH_MSG_ERROR(
"Failed to connect to xAOD::EventFormat object");
227 return StatusCode::FAILURE;
232 for (
const auto &[key, element] : *format) {
243 return StatusCode::SUCCESS;
249 if (
sc.isRecoverable()) {
252 return StatusCode::SUCCESS;
259 std::set<std::string> lOtherMetaTreeNames = {};
260 TList* lKeys =
file->GetListOfKeys();
263 for (
int iKey = 0; iKey < lKeys->GetEntries(); iKey++) {
265 std::string keyName = lKeys->At(iKey)->GetName();
272 const char* className = ((::TKey* )lKeys->At(iKey))->GetClassName();
273 static constexpr Bool_t LOAD = kFALSE;
274 static constexpr Bool_t SILENT = kTRUE;
275 ::TClass* cl = ::TClass::GetClass(className, LOAD, SILENT);
276 if ((cl !=
nullptr) && cl->InheritsFrom(::TTree::Class())) {
278 lOtherMetaTreeNames.insert(std::move(keyName));
285 for (
const std::string &metaTreeName : lOtherMetaTreeNames) {
286 ATH_CHECK(readEventFormatMetadata(metaTreeName));
309 stats.setNEvents(stats.nEvents() +
m_inTree->GetEntries());
315 listener->handle(beginIncident);
324 listener->handle(endIncident);
328 return StatusCode::SUCCESS;
351 if (useTreeCache && (!
m_inChain->GetCacheSize())) {
361 ATH_MSG_ERROR(
"Couldn't get the list of files from the input TChain");
362 return StatusCode::FAILURE;
364 if (!
files->GetEntries()) {
365 ATH_MSG_ERROR(
"No files are present in the received TChain");
366 return StatusCode::FAILURE;
368 const ::TChainElement* chEl =
369 dynamic_cast<const ::TChainElement*
>(
files->At(0));
372 return StatusCode::FAILURE;
375 std::unique_ptr<TFile> dummyFile{TFile::Open(chEl->GetTitle())};
378 return StatusCode::FAILURE;
393 return StatusCode::SUCCESS;
403 ::TFile*
file =
tree->GetCurrentFile();
417 std::string_view treeName) {
422 return StatusCode::FAILURE;
427 ATH_MSG_ERROR(
"Object already writing to a file. Close that file first!");
428 return StatusCode::FAILURE;
436 m_outTree = std::make_unique<TTree>(treeName.data(),
"xAOD event tree");
446 return StatusCode::SUCCESS;
459 ATH_MSG_ERROR(
"The object doesn't seem to be connected to an output file!");
460 return StatusCode::FAILURE;
470 listener->handle(incident);
484 return StatusCode::SUCCESS;
490 metatree->SetAutoSave(10000);
491 metatree->SetAutoFlush(-30000000);
492 metatree->SetDirectory(
file);
501 ::Error(
"xAOD::TEvent::finishWritingTo",
502 XAOD_MESSAGE(
"Class name parsing fails for %s ! "),
e.what());
503 return StatusCode::FAILURE;
509 std::vector<std::pair<std::string, TObjectManager* >> outputMetaObjects;
513 if (objMgr ==
nullptr) {
515 return StatusCode::FAILURE;
517 outputMetaObjects.emplace_back(key, objMgr);
522 for (
auto &[key, mgr] : outputMetaObjects) {
526 const ::Int_t splitLevel = (key.ends_with(
"Aux.") ? 1 : 0);
528 *(mgr->branchPtr()) =
529 metatree->Branch(key.c_str(), mgr->holder()->getClass()->GetName(),
530 mgr->holder()->getPtr(), 32000, splitLevel);
531 if (!mgr->branch()) {
533 << mgr->holder()->getClass()->GetName() <<
"/" << key
535 return StatusCode::FAILURE;
539 static constexpr bool METADATA =
true;
544 if (metatree->Fill() <= 0) {
545 ATH_MSG_ERROR(
"Failed to write event format metadata into the output");
546 metatree->SetDirectory(
nullptr);
547 return StatusCode::FAILURE;
552 metatree->SetDirectory(
nullptr);
558 return StatusCode::SUCCESS;
597 static constexpr bool TOP_STORE =
true;
598 if (
record(std::make_unique<TAuxStore>(key, TOP_STORE, mode), key)
600 ATH_MSG_ERROR(
"Couldn't connect TAuxStore object to the output");
669 const ::Long64_t fileEntry =
m_inChain->LoadTree(entry);
672 <<
" from the input chain");
686 static constexpr bool USE_TREE_CACHE =
false;
711 <<
" from the input file");
727 static const std::string dynStorePostfix =
"Aux.Dynamic";
728 if (key.ends_with(dynStorePostfix)) {
736 static constexpr bool SILENT =
true;
737 static constexpr bool METADATA =
false;
744 result += mgr->getEntry(getall);
752 listener->handle(incident);
771 return m_inChain->GetListOfFiles()->GetEntries();
807 ::Long64_t entry = 0;
808 for (::Long64_t i = 0; i <
file; ++i) {
849 std::string unsetObjects;
850 std::vector<std::pair<std::string, TVirtualManager* >> outputObjectsCopy;
853 outputObjectsCopy.emplace_back(key, mgr.get());
855 for (
auto &[key, mgr] : outputObjectsCopy) {
857 if (!mgr->create()) {
860 if (unsetObjects.size()) {
861 unsetObjects +=
", ";
863 unsetObjects.append(
"\"" + key +
"\"");
869 static constexpr bool METADATA =
false;
872 "in the output for object \""
879 if (unsetObjects.size()) {
880 ATH_MSG_ERROR(
"The following objects were not set in the current event: "
888 ATH_MSG_ERROR(
"Output tree filling failed with return value: " << ret);
908 std::vector<std::string> &vkeys,
909 bool metadata)
const {
911 std::set<std::string>
keys;
915 std::vector<TObjArray* > fullListOfBranches = {};
921 fullListOfBranches.push_back(
m_inMetaTree->GetListOfBranches());
927 fullListOfBranches.push_back(
m_inTree->GetListOfBranches());
932 TList* fList =
m_inTree->GetListOfFriends();
934 for (TObject* feObj : *fList) {
937 auto* pElement =
dynamic_cast<TFriendElement*
>(feObj);
938 if (pElement ==
nullptr) {
941 TTree* friendTree = pElement->GetTree();
943 fullListOfBranches.push_back(friendTree->GetListOfBranches());
951 for (
const TObjArray* in : fullListOfBranches) {
953 for (
const TObject* obj : *in) {
955 if (obj ==
nullptr) {
958 const TBranch* element =
dynamic_cast<const TBranch*
>(obj);
961 return StatusCode::FAILURE;
963 const std::string objClassName = element->GetClassName();
964 std::string key = obj->GetName();
967 if (objClassName == targetClassName) {
968 ATH_MSG_DEBUG(
"Matched \"" << targetClassName <<
"\" to key \"" << key
970 keys.insert(std::move(key));
977 ATH_MSG_DEBUG(
"Scanning input objects for \"" << targetClassName <<
"\"");
978 for (
const auto &[key, vmgr] : inAux) {
982 if (mgr ==
nullptr) {
985 const std::string &objClassName = mgr->holder()->getClass()->GetName();
988 if (objClassName == targetClassName) {
989 ATH_MSG_DEBUG(
"Matched \"" << targetClassName <<
"\" to key \"" << key
997 const TObjArray* out =
m_outTree->GetListOfBranches();
1000 for (
const TObject* obj : *out) {
1001 if (obj ==
nullptr) {
1004 const TBranch* element =
dynamic_cast<const TBranch*
>(obj);
1005 if (element ==
nullptr) {
1007 return StatusCode::FAILURE;
1009 const std::string objClassName = element->GetClassName();
1010 std::string key = obj->GetName();
1013 if (objClassName == targetClassName) {
1014 ATH_MSG_DEBUG(
"Matched \"" << targetClassName <<
"\" to key \"" << key
1016 keys.insert(std::move(key));
1024 ATH_MSG_DEBUG(
"Scanning output objects for \"" << targetClassName <<
"\"");
1025 for (
const auto &[key, vmgr] : outAux) {
1028 if (mgr ==
nullptr) {
1031 const std::string &objClassName = mgr->holder()->getClass()->GetName();
1034 if (objClassName == targetClassName) {
1035 ATH_MSG_DEBUG(
"Matched \"" << targetClassName <<
"\" to key \"" << key
1041 vkeys.insert(vkeys.end(),
keys.begin(),
keys.end());
1044 return StatusCode::SUCCESS;
1069 return StatusCode::FAILURE;
1077 return StatusCode::SUCCESS;
1081 if (silent ==
false) {
1084 return StatusCode::RECOVERABLE;
1090 if (silent ==
false) {
1098 ::TBranch* br =
m_inTree->GetBranch(key.c_str());
1099 if (br ==
nullptr) {
1104 return StatusCode::RECOVERABLE;
1108 br->SetMakeClass(0);
1112 std::string className = br->GetClassName();
1113 if (className ==
"") {
1117 className = ef->className();
1120 "Couldn't find an appropriate type with a dictionary for branch \""
1122 return StatusCode::FAILURE;
1125 ::TClass* realClass = ::TClass::GetClass(className.c_str());
1126 if (((!realClass) || (!realClass->IsLoaded())) && ef) {
1130 className = ef->className();
1131 realClass = ::TClass::GetClass(className.c_str());
1133 if ((!realClass) || (!realClass->IsLoaded())) {
1136 "Couldn't find an appropriate type with a dictionary for branch \""
1138 return StatusCode::FAILURE;
1145 static const ::EDataType dataType = kOther_t;
1151 void* ptr =
nullptr;
1156 if (mgr ==
nullptr) {
1157 ATH_MSG_ERROR(
"Couldn't access output manager for: " << key);
1158 return StatusCode::FAILURE;
1161 ptr = mgr->holder()->get();
1167 if (ptr ==
nullptr) {
1168 ptr = realClass->New();
1173 auto mgr = std::make_unique<TObjectManager>(
1174 nullptr, std::make_unique<THolder>(ptr, realClass), renewOnRead);
1183 << key <<
"\" is " << br->GetSplitLevel()
1184 <<
". This can only be read in kAthenaAccess mode.");
1186 *(mgr->holder()->getPtr()) =
nullptr;
1188 return StatusCode::FAILURE;
1192 const ::Int_t status =
1193 m_inTree->SetBranchAddress(key.c_str(), mgr->holder()->getPtr(),
1194 mgr->branchPtr(), realClass, dataType, kTRUE);
1197 << className <<
"\" to input branch \"" << key
1198 <<
"\". Return code: " << status);
1200 *(mgr->holder()->getPtr()) = 0;
1202 return StatusCode::FAILURE;
1222 return StatusCode::SUCCESS;
1238 return StatusCode::FAILURE;
1243 return StatusCode::SUCCESS;
1248 if (br ==
nullptr) {
1249 if (silent ==
false) {
1251 <<
"\" not available on input");
1253 return StatusCode::RECOVERABLE;
1257 if (br->GetEntries() == 0) {
1258 if (silent ==
false) {
1260 <<
"\" doesn't hold any data");
1262 return StatusCode::RECOVERABLE;
1266 br->SetMakeClass(0);
1270 ::EDataType dt = kOther_t;
1271 if (br->GetExpectedType(cl, dt) || (!cl)) {
1272 ATH_MSG_ERROR(
"Couldn't get the type for metadata branch \"" << key
1274 return StatusCode::FAILURE;
1278 void* ptr = cl->New();
1280 auto mgr = std::make_unique<TObjectManager>(
1281 nullptr, std::make_unique<THolder>(ptr, cl), renewOnRead);
1285 key.c_str(), mgr->holder()->getPtr(), mgr->branchPtr(), cl, dt, kTRUE);
1288 << cl->GetName() <<
"\" to input branch \"" << key
1289 <<
"\". Return code: " << status);
1291 *(mgr->holder()->getPtr()) = 0;
1293 return StatusCode::FAILURE;
1302 ATH_MSG_ERROR(
"Couldn't read in metadata object with key \"" << key
1304 return StatusCode::FAILURE;
1317 static constexpr bool METADATA =
true;
1322 return StatusCode::SUCCESS;
1339 return StatusCode::FAILURE;
1343 if ((!
m_inTree->GetBranch(prefix.c_str())) &&
1347 return StatusCode::SUCCESS;
1352 return StatusCode::SUCCESS;
1360 static constexpr bool SILENT =
false;
1364 return StatusCode::SUCCESS;
1370 static constexpr bool TOP_STORE =
true;
1371 auto store = std::make_unique<TAuxStore>(
1384 static constexpr bool IS_OWNER =
true;
1386 std::make_unique<TAuxManager>(store.release(), IS_OWNER);
1389 return StatusCode::SUCCESS;
1394 return StatusCode::FAILURE;
1410 return StatusCode::SUCCESS;
1416 return StatusCode::FAILURE;
1424 static constexpr bool SILENT =
false;
1428 return StatusCode::SUCCESS;
1434 static constexpr bool TOP_STORE =
true;
1435 auto store = std::make_unique<TAuxStore>(
1448 static constexpr bool IS_OWNER =
true;
1450 std::make_unique<TAuxManager>(store.release(), IS_OWNER);
1453 return StatusCode::SUCCESS;
1458 return StatusCode::FAILURE;
1478 (isAuxStore ==
false)) {
1479 return StatusCode::SUCCESS;
1492 auto itr = objects.find(key +
"Aux.");
1493 if (itr == objects.end()) {
1496 return StatusCode::SUCCESS;
1498 auxMgr = itr->second.get();
1499 auxKey = key +
"Aux.";
1502 if (metadata ==
false) {
1504 const ::Int_t readBytes = auxMgr->
getEntry();
1505 if (readBytes < 0) {
1507 "Couldn't load current entry for auxiliary object with key \""
1509 return StatusCode::FAILURE;
1514 const std::string dynAuxKey = auxKey +
"Dynamic";
1515 auto dynAuxMgr = objects.find(dynAuxKey);
1517 if ((dynAuxMgr != objects.end()) &&
1523 dynAuxMgr->second->getEntry();
1534 auto dynAuxMgr = objects.find(dynAuxKey);
1535 if (dynAuxMgr == objects.end()) {
1537 return StatusCode::FAILURE;
1539 dynAuxMgr->second->getEntry();
1546 return StatusCode::SUCCESS;
1552 switch (mgr.holder()->typeKind()) {
1567 if (
vec && (!
vec->trackIndices())) {
1568 Details::forceTrackIndices(*
vec);
1574 << mgr.holder()->getClass()->GetName()
1575 <<
"\" as SG::AuxVectorBase or SG::AuxElement");
1576 return StatusCode::FAILURE;
1586 << auxKey <<
"\" is not of the right type");
1587 return StatusCode::FAILURE;
1603 << auxKey <<
"\" is not of the right type");
1604 return StatusCode::FAILURE;
1611 return StatusCode::FAILURE;
1616 vec->setStore(store);
1618 aux->setStore(store);
1621 return StatusCode::FAILURE;
1625 return StatusCode::SUCCESS;
1644 const std::string &key,
bool overwrite,
bool metadata,
1650 "No output tree defined. Did you forget to call writeTo(...)?");
1651 return StatusCode::FAILURE;
1661 ATH_MSG_ERROR(
"Meta-object \"" << typeName <<
"\"/\"" << key
1662 <<
"\" already recorded");
1663 return StatusCode::FAILURE;
1666 TClass* cl = TClass::GetClass(typeName.c_str());
1668 ATH_MSG_ERROR(
"Didn't find dictionary for type: " << typeName);
1669 return StatusCode::FAILURE;
1674 nullptr, std::make_unique<THolder>(obj, cl, isOwner), renewOnRead);
1676 return StatusCode::SUCCESS;
1683 <<
"\" already accessed from the input, can't be "
1684 "overwritten in memory");
1685 return StatusCode::FAILURE;
1689 const Int_t splitLevel = (key.ends_with(
"Aux.") ? 1 : 0);
1696 TClass* cl = TClass::GetClass(typeName.c_str());
1697 if (cl ==
nullptr) {
1698 ATH_MSG_ERROR(
"Didn't find dictionary for type: " << typeName);
1699 return StatusCode::FAILURE;
1710 auto mgr = std::make_unique<TObjectManager>(
1711 nullptr, std::make_unique<THolder>(obj, cl, isOwner), renewOnRead);
1716 static constexpr Int_t basketSize = 32000;
1718 m_outTree->Branch(key.c_str(), cl->GetName(),
1721 ATH_MSG_ERROR(
"Failed to create branch \"" << key <<
"\" out of type \""
1722 << cl->GetName() <<
"\"");
1725 return StatusCode::FAILURE;
1730 static constexpr bool METADATA =
false;
1735 return StatusCode::SUCCESS;
1741 ATH_MSG_ERROR(
"Manager object of the wrong type encountered");
1742 return StatusCode::FAILURE;
1751 TClass* cl = TClass::GetClass(typeName.c_str());
1753 ::strcmp(cl->GetName(), omgr->
holder()->
getClass()->GetName())) {
1755 << key <<
"\" the previous type was \""
1757 <<
"\", but the newly requested type is \"" << typeName
1759 return StatusCode::FAILURE;
1767 static constexpr bool METADATA =
false;
1771 return StatusCode::SUCCESS;
1779 if (iomgr !=
nullptr) {
1781 static const bool OVERWRITE =
true;
1782 static const bool IS_OWNER =
true;
1784 key, OVERWRITE, metadata, IS_OWNER));
1785 return StatusCode::SUCCESS;
1790 if (auxmgr !=
nullptr) {
1794 "TAuxStore auxiliary objects can only be recorded for event data");
1795 return StatusCode::FAILURE;
1799 return StatusCode::SUCCESS;
1803 ATH_MSG_ERROR(
"Unknown auxiliary store manager type encountered");
1804 return StatusCode::FAILURE;
1817 return StatusCode::SUCCESS;
1822 ATH_MSG_ERROR(
"Function called on an uninitialised object");
1823 return StatusCode::FAILURE;
1832 for (; itr != end; ++itr) {
1835 const std::string &branchName = itr->second.branchName();
1838 if (branchName.find(
"Aux.") != std::string::npos) {
1847 const std::string intName = branchName.substr(0, branchName.size() - 4);
1855 ::Bool_t auxFound = kFALSE;
1858 std::vector<TObjArray* > fullListOfBranches = {};
1860 fullListOfBranches.push_back(
m_inTree->GetListOfBranches());
1863 if (
m_inTree->GetListOfFriends()) {
1865 TList* fList =
m_inTree->GetListOfFriends();
1867 for (TObject* feObj : *fList) {
1870 auto* pElement =
dynamic_cast<TFriendElement*
>(feObj);
1873 TTree* friendTree = pElement->GetTree();
1875 fullListOfBranches.push_back(friendTree->GetListOfBranches());
1880 for (TObjArray* branches : fullListOfBranches) {
1881 for (Int_t i = 0; i < branches->GetEntriesFast(); ++i) {
1882 if (!branches->At(i))
1885 const TString
name(branches->At(i)->GetName());
1886 if (
name.BeginsWith(branchName) ||
name.BeginsWith(dynName)) {
1894 << intName <<
"\" belonging to branch \""
1895 << branchName <<
"\"");
1902 ::TClass* cl = ::TClass::GetClass(el->className().c_str());
1903 if ((!cl) || (!cl->IsLoaded())) {
1905 << el->className() <<
"\"");
1912 static ::TClass*
const baseCl = ::TClass::GetClass(baseName.c_str());
1914 ATH_MSG_ERROR(
"Couldn't get dictionary for type \"" << baseName
1916 return StatusCode::FAILURE;
1926 static constexpr bool TOP_STORE =
true;
1927 TAuxStore temp(branchName, TOP_STORE, mode);
1928 static constexpr bool PRINT_WARNINGS =
false;
1936 stats.branch(branchName,
id);
1940 stats.setBranchNum(stats.branchNum() + temp.getAuxIDs().size());
1954 return StatusCode::SUCCESS;
1970 const std::string &key) {
1975 "No output tree defined. Did you forget to call writeTo(...)?");
1976 return StatusCode::FAILURE;
1980 const std::set<std::string>* filter = 0;
1983 filter = &(filter_itr->second);
1992 store->selectAux(*filter);
1997 static constexpr bool OWNS_STORE =
true;
1999 std::make_unique<TAuxManager>(store.release(), OWNS_STORE);
2002 return StatusCode::SUCCESS;
2006 if (vitr->second->object() == store.get()) {
2008 return StatusCode::SUCCESS;
2017 if (mgr ==
nullptr) {
2019 << key <<
"\" already exists, and is not of type TAuxStore");
2020 return StatusCode::FAILURE;
2025 store->selectAux(*filter);
2032 mgr->setObject(store.release());
2035 return StatusCode::SUCCESS;
2049 ::TMethodCall setNameCall;
2053 setNameCall.InitWithPrototype(mgr.holder()->getClass(),
"setName",
2055 if (setNameCall.IsValid()) {
2058 const ::TString params =
2059 ::TString::Format(
"\"%s\"", mgr.branch()->GetName());
2060 const char* charParams = params.Data();
2061 setNameCall.Execute(mgr.holder()->get(), charParams);
2064 ATH_MSG_WARNING(
"Couldn't find setName(...) function for container \""
2065 << mgr.branch()->GetName() <<
"\" (type: "
2066 << mgr.holder()->getClass()->GetName() <<
")");
2071 static const TClass*
const holderClass =
2073 if (!mgr.holder()->getClass()->InheritsFrom(holderClass)) {
2075 return StatusCode::SUCCESS;
2083 return StatusCode::FAILURE;
2090 static constexpr bool TOP_STORE =
false;
2091 auto store = std::make_unique<TAuxStore>(
2092 mgr.branch()->GetName(), TOP_STORE,
2111 static constexpr bool SHARED_OWNER =
false;
2112 m_inputObjects[std::string(mgr.branch()->GetName()) +
"Dynamic"] =
2113 std::make_unique<TAuxManager>(store.get(), SHARED_OWNER);
2116 storeHolder->
setStore(store.release());
2119 return StatusCode::SUCCESS;
2142 return StatusCode::SUCCESS;
2146 if (!mgr->holder()->getClass()->InheritsFrom(
"SG::IAuxStoreIO")) {
2147 return StatusCode::SUCCESS;
2155 return StatusCode::FAILURE;
2162 auto item_itr =
m_auxItemList.find(mgr->branch()->GetName());
2164 sel.selectAux(item_itr->second);
2171 sel.getSelectedAuxIDs(
aux->getSelectedAuxIDs());
2175 if (auxids.
empty()) {
2176 return StatusCode::SUCCESS;
2180 const std::string dynNamePrefix =
2189 typedef std::pair<std::string, SG::auxid_t> AuxVarSort_t;
2190 std::vector<AuxVarSort_t> varsort;
2191 varsort.reserve(auxids.
size());
2193 varsort.emplace_back(
r.getName(
id),
id);
2195 std::sort(varsort.begin(), varsort.end());
2198 for (
const auto &p : varsort) {
2204 const std::string brName = dynNamePrefix + p.first;
2207 Object_t::iterator bmgr = objects.find(brName);
2210 if (bmgr == objects.end()) {
2213 const std::type_info* brType =
aux->getIOType(
id);
2216 return StatusCode::FAILURE;
2219 std::string brProperTypeName =
"<unknown>";
2225 if (strlen(brType->name()) == 1) {
2228 brProperTypeName = brTypeName;
2232 if (rootType ==
'\0') {
2234 << brName <<
"\" of type \"" << brTypeName <<
"\"");
2235 return StatusCode::FAILURE;
2239 std::ostringstream leaflist;
2240 leaflist << brName <<
"/" << rootType;
2243 static constexpr bool IS_OWNER =
false;
2244 auto auxmgr = std::make_unique<TPrimitiveAuxBranchManager>(
2245 id,
nullptr,
new THolder(
aux->getIOData(
id),
nullptr, IS_OWNER));
2248 static constexpr Int_t BASKET_SIZE = 32000;
2249 *(auxmgr->branchPtr()) =
2250 outTree.Branch(brName.c_str(), auxmgr->holder()->get(),
2251 leaflist.str().c_str(), BASKET_SIZE);
2252 if (!auxmgr->branch()) {
2254 << brName <<
"\" out of type \"" << brProperTypeName
2257 *(auxmgr->holder()->getPtr()) = 0;
2258 return StatusCode::FAILURE;
2260 br = auxmgr->branch();
2263 objects[brName] = std::move(auxmgr);
2268 static constexpr Bool_t LOAD_IF_NOT_FOUND = kTRUE;
2269 static constexpr Bool_t SILENT = kTRUE;
2270 TClass* cl = TClass::GetClass(*brType, LOAD_IF_NOT_FOUND, SILENT);
2271 if (cl ==
nullptr) {
2274 cl = TClass::GetClass(brTypeName.c_str());
2276 if (cl ==
nullptr) {
2278 << brName <<
"\" of type \"" << brTypeName <<
"\"");
2279 return StatusCode::FAILURE;
2284 brProperTypeName = cl->GetName();
2287 static constexpr bool IS_OWNER =
false;
2288 auto auxmgr = std::make_unique<TAuxBranchManager>(
2289 id,
nullptr,
new THolder(
aux->getIOData(
id), cl, IS_OWNER));
2292 static constexpr Int_t BASKET_SIZE = 32000;
2293 static constexpr Int_t SPLIT_LEVEL = 0;
2294 *(auxmgr->branchPtr()) = outTree.Branch(brName.c_str(), cl->GetName(),
2295 auxmgr->holder()->getPtr(),
2296 BASKET_SIZE, SPLIT_LEVEL);
2297 if (!auxmgr->branch()) {
2299 << brName <<
"\" out of type \"" << brProperTypeName
2302 *(auxmgr->holder()->getPtr()) = 0;
2303 return StatusCode::FAILURE;
2305 br = auxmgr->branch();
2308 objects[brName] = std::move(auxmgr);
2313 if (outTree.GetEntries()) {
2314 void* ptr = br->GetAddress();
2316 for (::Long64_t i = 0; i < outTree.GetEntries(); ++i) {
2319 br->SetAddress(ptr);
2326 mgr->branch()->GetName(),
2335 bmgr = objects.find(brName);
2336 if (bmgr == objects.end()) {
2337 ATH_MSG_FATAL(
"There is an internal logic error in the code...");
2338 return StatusCode::FAILURE;
2344 const_cast<void*
>(
static_cast<const void*
>(
aux->getIOData(
id)));
2345 bmgr->second->setObject(nc_data);
2349 return StatusCode::SUCCESS;
2357 return StatusCode::FAILURE;
2361 const std::set<std::string>* filter = 0;
2364 filter = &(filter_itr->second);
2373 store->selectAux(*filter);
2378 static constexpr bool OWNS_STORE =
false;
2379 m_outputObjects[key] = std::make_unique<TAuxManager>(store, OWNS_STORE);
2382 return StatusCode::SUCCESS;
2386 if (vitr->second->object() == store) {
2388 return StatusCode::SUCCESS;
2397 if (mgr ==
nullptr) {
2399 << key <<
"\" already exists, and is not of type TAuxStore");
2400 return StatusCode::FAILURE;
2405 store->selectAux(*filter);
2412 mgr->setObject(store);
2415 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
Base class for elements of a container that can have aux data.
Handle mappings between names and auxid_t.
Manage index tracking and synchronization of auxiliary data.
std::vector< size_t > vec
Recursively separate out template arguments in a C++ class name.
Interface providing I/O for a generic auxiliary store.
void upgrade()
Convert the lock from upgrade to exclusive.
Exception to signal a malformed class name.
bit_t size() const
Count the number of 1 bits in the set.
bool empty() const
Return true if there are no 1 bits in the set.
Base class for elements of a container that can have aux data.
Handle mappings between names and auxid_t.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Manage index tracking and synchronization of auxiliary data.
Interface for objects taking part in direct ROOT I/O.
AuxStoreType
Type of the auxiliary store.
@ AST_ContainerStore
The store describes a container.
@ AST_ObjectStore
The store describes a single object.
virtual AuxStoreType getStoreType() const =0
Return the type of the store object.
virtual void setStore(IAuxStore *store)=0
Give an auxiliary store object to the holder object.
Interface providing I/O for a generic auxiliary store.
Interface for non-const operations on an auxiliary store.
Interface for const operations on an auxiliary store.
A set of aux data identifiers.
Class helping in dealing with dynamic branch selection.
Manager for EDM objects created by ROOT.
const THolder * holder() const
Accessor to the Holder object.
EventFormat m_inputEventFormat
Format of the current input file.
const std::string & name() const override
Get the name of the instance.
std::set< std::string > m_inputMissingObjects
Objects that have been asked for, but were found to be missing in the current input.
const void * getInputObject(SG::sgkey_t key, const std::type_info &ti, bool silent) override
Function for retrieving an input object in a non-template way.
upgrade_mutex_t m_branchesMutex
Mutex for multithread synchronization.
AthContainers_detail::upgrading_lock< upgrade_mutex_t > upgrading_lock_t
Lock type for multithread synchronization.
Object_t m_inputObjects
Collection of all the managed input objects.
static const char *const METADATA_OBJECT_NAME
Name of the metadata tree or RNTuple.
Event(std::string_view name)
Constructor with a name.
std::unordered_map< std::string, std::unique_ptr< TVirtualManager > > Object_t
Definition of the internal data structure type.
StatusCode keys(std::vector< std::string > &vkeys, bool metadata) const
Provide a list of all data object keys associated with a specific type.
void setActive() const
Set this event object as the currently active one.
SG::sgkey_t getHash(const std::string &key) const override
Function returning the hash describing an object name.
Object_t m_inputMetaObjects
Collection of all the managed input meta-objects.
std::unordered_map< std::string, std::set< std::string > > m_auxItemList
Rules for selecting which auxiliary branches to write.
EventFormat * m_outputEventFormat
Format of the current output file.
Object_t m_outputObjects
Collection of all the managed output object.
SG::SGKeyMap< BranchInfo > m_branches ATLAS_THREAD_SAFE
Map from hashed sgkey to BranchInfo.
std::vector< TVirtualIncidentListener * > m_listeners
Listeners who should be notified when certain incidents happen.
Object_t m_outputMetaObjects
Collection of all the managed output meta-objects.
ReadStats & stats()
Access the object belonging to the current thread.
static IOStats & instance()
Singleton object accessor.
Class describing the access statistics of a collection of branches.
void nextEvent()
Function incrementing the processed event counter.
BranchStats * container(const std::string &name)
Access the description of a container. Creating it if necessary.
void setBranchNum(::Int_t num)
Set the total number of branches on the input.
void readContainer(const std::string &name)
Function incrementing the read counter on a specific container.
Manager for TAuxStore objects.
TAuxStore * getStore()
Get a type-specific pointer to the managed object.
const SG::IConstAuxStore * getConstStore() const
Get a convenience pointer to the managed object.
"ROOT @c TTree implementation" of IAuxStore
Helper class for making sure the current directory is preserved.
EAuxMode
Auxiliary store "mode".
@ kAthenaAccess
Access containers/objects like Athena does.
@ kClassAccess
Access auxiliary data using the aux containers.
@ kBranchAccess
Access auxiliary data branch-by-branch.
::TTree * m_inMetaTree
Pointer to the metadata tree in the input file.
StatusCode connectObject(const std::string &key, bool silent) override
Function setting up access to a particular object.
StatusCode connectMetaAux(const std::string &prefix, bool standalone) override
Function setting up access to a set of auxiliary branches for a metadata object.
StatusCode connectAux(const std::string &prefix, bool standalone) override
Function setting up access to a set of auxiliary branches.
StatusCode writeTo(::TFile *file, int autoFlush=200, std::string_view treeName=EVENT_TREE_NAME)
Connect the object to an output file.
bool hasOutput() const override
Check if an output file is connected to the object.
std::unique_ptr< TChainStateTracker > m_inChainTracker
Optional object for tracking the state changes of an input TChain.
StatusCode finishWritingTo(::TFile *file)
Finish writing to an output file.
::Int_t fill()
Function filling one event into the output tree.
::Int_t getEntry(::Long64_t entry, ::Int_t getall=0) override
Function loading a given entry of the input TTree.
StatusCode setAuxStore(const std::string &key, Details::IObjectManager &mgr, bool metadata) override
Function connecting a DV object to its auxiliary store.
EAuxMode auxMode() const
Get what auxiliary access mode the object was constructed with.
bool hasInput() const override
Check if an input file is connected to the object.
StatusCode initStats()
Function to initialise the statistics for all Tree content.
::Long64_t m_entry
The entry to look at from the input tree.
::Long64_t getFiles() const
Get how many files are available on the currently defined input.
void setOtherMetaDataTreeNamePattern(const std::string &pattern)
Change the pattern used for collecting information from other MetaData trees NB: Additional MetaData ...
StatusCode getNames(const std::string &targetClassName, std::vector< std::string > &vkeys, bool metadata) const override
Function determining the list keys associated with a type name.
StatusCode setUpDynamicStore(TObjectManager &mgr, ::TTree *tree)
Function adding dynamic variable reading capabilities to an auxiliary store object.
std::regex m_otherMetaDataTreeNamePattern
::TChain * m_inChain
The (optional) chain provided as input.
StatusCode putAux(::TTree &outTree, TVirtualManager &mgr, bool metadata)
Function saving the dynamically created auxiliary properties.
EAuxMode m_auxMode
The auxiliary access mode.
StatusCode readFrom(::TFile &inFile) override
Set up the reading of an input file from TFile This method implements the interface from Event.
virtual ~TEvent()
Destructor.
TEvent(EAuxMode mode=kClassAccess)
Default constructor.
SG::IAuxStore * recordAux(const std::string &key, SG::IAuxStoreHolder::AuxStoreType type=SG::IAuxStoreHolder::AST_ContainerStore)
Add an auxiliary store object to the output.
StatusCode record(void *obj, const std::string &typeName, const std::string &key, bool overwrite, bool metadata, bool isOwner) override
Record an object into a connected output file.
std::unique_ptr<::TTree > m_outTree
The tree that we are writing to.
bool m_inTreeMissing
Internal status flag showing that an input file is open, but it doesn't contain an event tree.
::Int_t m_inTreeNumber
The number of the currently open tree in the input chain.
::Int_t getFile(::Long64_t file, ::Int_t getall=0)
Load the first event for a given file from the input TChain.
::TTree * m_inTree
The main tree that we are reading from.
StatusCode connectMetaObject(const std::string &key, bool silent) override
Function setting up access to a particular metadata object.
::Long64_t getEntries() const override
Get how many entries are available from the current input file(s)
Helper class keeping track of the files that got accessed.
This class takes care of holding EDM objects in memory.
void setOwner(::Bool_t state=kTRUE)
Set whether the holder should own its object.
void ** getPtr()
Return a typeless pointer to the held object's pointer.
const ::TClass * getClass() const
virtual void * getAs(const std::type_info &tid, ::Bool_t silent=kFALSE) const
Return the object as a specific pointer.
@ DATAVECTOR
A DataVector container.
@ AUXELEMENT
A type inheriting from SG::AuxElement.
Class describing a certain "incident" that is communicated to user code.
Manager for EDM objects created by ROOT.
::TBranch ** branchPtr()
Pointer to the branch's pointer.
virtual void setObject(void *obj) override
Function replacing the object being handled.
virtual::Int_t getEntry(::Int_t getall=0) override
Function for updating the object in memory if needed.
::TBranch * branch()
Accessor to the branch.
Class providing an interface for classes listening to xAOD incidents.
Interface class for the "manager classes".
virtual const void * object() const =0
Function getting a const pointer to the object being handled.
virtual::Int_t getEntry(::Int_t getall=0)=0
Function for updating the object in memory if needed.
void setStructMode(EStructMode mode)
Set the structure mode of the object to a new value.
EStructMode
"Structural" modes of the object
@ kUndefinedStore
The structure mode is not defined.
@ kObjectStore
The object describes a single object.
@ kContainerStore
The object describes an entire container.
EStructMode structMode() const
Get what structure mode the object was constructed with.
std::vector< std::string > files
file names and file pointers
std::string normalizedTypeinfoName(const std::type_info &info)
Convert a type_info to a normalized string representation (matching the names used in the root dictio...
size_t auxid_t
Identifier for a particular aux data item.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
bool hasAuxStore(const TClass &cl)
Helper function deciding if a given type "has an auxiliary store".
bool isAuxStore(const TClass &cl)
Helper function deciding if a given type "is an auxiliary store".
bool isStandalone(const TClass &cl)
Helper function deciding if a given type "is a standalone object".
static const ::Int_t BeginEvent
A new event was just loaded.
static const ::Int_t EndInputFile
The processing of an input file has finished.
static const ::Int_t MetaDataStop
The metadata for the output file should be written out.
static const ::Int_t BeginInputFile
A new input file was just opened.
std::string dynBranchPrefix(const std::string &key)
This function is used to figure out what to name dynamic auxiliary branches coming from a container c...
char rootType(char typeidType)
This function is used internally in the code when creating primitive dynamic auxiliary branches.
std::string getFirstBranchMatch(TTree *tree, const std::string &pre)
This function is used to search for a branch in a TTree that contains a given substring.
std::string getTypeName(const std::type_info &ti)
This function is necessary in order to create type names that ROOT can understand.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
EventFormat_v1 EventFormat
Definition of the current event format version.
static const ::Int_t CACHE_SIZE
Size of a possible TTreeCache.
Helper to disable undefined behavior sanitizer for a function.
Convert a type_info to a normalized string representation (matching the names used in the root dictio...