17#include <TChainElement.h>
20#include <TFriendElement.h>
22#include <TMethodCall.h>
35#ifndef XAOD_STANDALONE
73 :
Event(
"xAOD::TEvent", ctx),
94 "Did not call finishWritingTo() before destroying the TEvent object!");
110 if (pattern.size()) {
119 return StatusCode::SUCCESS;
133 std::string_view treeName) {
136 if (
file ==
nullptr) {
138 return StatusCode::SUCCESS;
164 ATH_MSG_ERROR(
"Couldn't find metadata tree on input. Object is unusable!");
165 return StatusCode::FAILURE;
172 return StatusCode::FAILURE;
177 ATH_MSG_WARNING(
"Was expecting a metadata tree with size 1, instead of "
179 ATH_MSG_WARNING(
"The input file was most probably produced by hadd...");
185 static const std::string eventFormatTypeName =
187 ::TClass* cl = ::TClass::GetClass(eventFormatTypeName.c_str());
194 auto readEventFormatMetadata =
195 [&](std::string_view thisTreeName) -> StatusCode {
197 TTree* metaTree =
file->Get<TTree>(thisTreeName.data());
198 if (metaTree ==
nullptr) {
199 ATH_MSG_ERROR(
"Couldn't find metadata tree \"" << thisTreeName
201 return StatusCode::FAILURE;
204 if (metaTree->LoadTree(0) < 0) {
206 << thisTreeName <<
"\"");
207 return StatusCode::FAILURE;
211 const std::string eventFormatBranchName =
213 if (!metaTree->GetBranch(eventFormatBranchName.c_str())) {
217 ATH_MSG_INFO(
"Input file provides no event or metadata");
218 return StatusCode::RECOVERABLE;
225 metaTree->SetBranchAddress(eventFormatBranchName.c_str(), &format, &br);
227 ATH_MSG_ERROR(
"Failed to connect to xAOD::EventFormat object");
228 return StatusCode::FAILURE;
233 for (
const auto &[key, element] : *format) {
244 return StatusCode::SUCCESS;
250 if (
sc.isRecoverable()) {
253 return StatusCode::SUCCESS;
260 std::set<std::string> lOtherMetaTreeNames = {};
261 TList* lKeys =
file->GetListOfKeys();
264 for (
int iKey = 0; iKey < lKeys->GetEntries(); iKey++) {
266 std::string keyName = lKeys->At(iKey)->GetName();
273 const char* className = ((::TKey* )lKeys->At(iKey))->GetClassName();
274 static constexpr Bool_t LOAD = kFALSE;
275 static constexpr Bool_t SILENT = kTRUE;
276 ::TClass* cl = ::TClass::GetClass(className, LOAD, SILENT);
277 if ((cl !=
nullptr) && cl->InheritsFrom(::TTree::Class())) {
279 lOtherMetaTreeNames.insert(std::move(keyName));
286 for (
const std::string &metaTreeName : lOtherMetaTreeNames) {
287 ATH_CHECK(readEventFormatMetadata(metaTreeName));
310 stats.setNEvents(stats.nEvents() +
m_inTree->GetEntries());
316 listener->handle(beginIncident);
325 listener->handle(endIncident);
329 return StatusCode::SUCCESS;
352 if (useTreeCache && (!
m_inChain->GetCacheSize())) {
362 ATH_MSG_ERROR(
"Couldn't get the list of files from the input TChain");
363 return StatusCode::FAILURE;
365 if (!
files->GetEntries()) {
366 ATH_MSG_ERROR(
"No files are present in the received TChain");
367 return StatusCode::FAILURE;
369 const ::TChainElement* chEl =
370 dynamic_cast<const ::TChainElement*
>(
files->At(0));
373 return StatusCode::FAILURE;
376 std::unique_ptr<TFile> dummyFile{TFile::Open(chEl->GetTitle())};
379 return StatusCode::FAILURE;
394 return StatusCode::SUCCESS;
404 ::TFile*
file =
tree->GetCurrentFile();
422 return StatusCode::SUCCESS;
434 std::string_view treeName) {
439 return StatusCode::FAILURE;
444 ATH_MSG_ERROR(
"Object already writing to a file. Close that file first!");
445 return StatusCode::FAILURE;
453 m_outTree = std::make_unique<TTree>(treeName.data(),
"xAOD event tree");
463 return StatusCode::SUCCESS;
486 ATH_MSG_ERROR(
"The object doesn't seem to be connected to an output file!");
487 return StatusCode::FAILURE;
497 listener->handle(incident);
511 return StatusCode::SUCCESS;
517 metatree->SetAutoSave(10000);
518 metatree->SetAutoFlush(-30000000);
519 metatree->SetDirectory(
file);
527 }
catch (
const CxxUtils::ClassName::ExcBadClassName &
e) {
528 ::Error(
"xAOD::TEvent::finishWritingTo",
529 XAOD_MESSAGE(
"Class name parsing fails for %s ! "),
e.what());
530 return StatusCode::FAILURE;
536 std::vector<std::pair<std::string, TObjectManager* >> outputMetaObjects;
540 if (objMgr ==
nullptr) {
542 return StatusCode::FAILURE;
544 outputMetaObjects.emplace_back(key, objMgr);
549 for (
auto &[key, mgr] : outputMetaObjects) {
553 const ::Int_t splitLevel = (key.ends_with(
"Aux.") ? 1 : 0);
555 *(mgr->branchPtr()) =
556 metatree->Branch(key.c_str(), mgr->holder()->getClass()->GetName(),
557 mgr->holder()->getPtr(), 32000, splitLevel);
558 if (!mgr->branch()) {
560 << mgr->holder()->getClass()->GetName() <<
"/" << key
562 return StatusCode::FAILURE;
566 static constexpr bool METADATA =
true;
571 if (metatree->Fill() <= 0) {
572 ATH_MSG_ERROR(
"Failed to write event format metadata into the output");
573 metatree->SetDirectory(
nullptr);
574 return StatusCode::FAILURE;
579 metatree->SetDirectory(
nullptr);
585 return StatusCode::SUCCESS;
624 static constexpr bool TOP_STORE =
true;
626 key, TOP_STORE, mode), key)
628 ATH_MSG_ERROR(
"Couldn't connect TAuxStore object to the output");
697 const ::Long64_t fileEntry =
m_inChain->LoadTree(entry);
700 <<
" from the input chain");
714 static constexpr bool USE_TREE_CACHE =
false;
739 <<
" from the input file");
755 static const std::string dynStorePostfix =
"Aux.Dynamic";
756 if (key.ends_with(dynStorePostfix)) {
764 static constexpr bool SILENT =
true;
765 static constexpr bool METADATA =
false;
772 result += mgr->getEntry(getall);
780 listener->handle(incident);
799 return m_inChain->GetListOfFiles()->GetEntries();
835 ::Long64_t entry = 0;
836 for (::Long64_t i = 0; i <
file; ++i) {
877 std::string unsetObjects;
878 std::vector<std::pair<std::string, TVirtualManager* >> outputObjectsCopy;
881 outputObjectsCopy.emplace_back(key, mgr.get());
883 for (
auto &[key, mgr] : outputObjectsCopy) {
885 if (!mgr->create()) {
888 if (unsetObjects.size()) {
889 unsetObjects +=
", ";
891 unsetObjects.append(
"\"" + key +
"\"");
897 static constexpr bool METADATA =
false;
900 "in the output for object \""
907 if (unsetObjects.size()) {
908 ATH_MSG_ERROR(
"The following objects were not set in the current event: "
916 ATH_MSG_ERROR(
"Output tree filling failed with return value: " << ret);
936 std::vector<std::string> &vkeys,
937 bool metadata)
const {
939 std::set<std::string>
keys;
943 std::vector<TObjArray* > fullListOfBranches = {};
949 fullListOfBranches.push_back(
m_inMetaTree->GetListOfBranches());
955 fullListOfBranches.push_back(
m_inTree->GetListOfBranches());
960 TList* fList =
m_inTree->GetListOfFriends();
962 for (TObject* feObj : *fList) {
965 auto* pElement =
dynamic_cast<TFriendElement*
>(feObj);
966 if (pElement ==
nullptr) {
969 TTree* friendTree = pElement->GetTree();
971 fullListOfBranches.push_back(friendTree->GetListOfBranches());
979 for (
const TObjArray* in : fullListOfBranches) {
981 for (
const TObject* obj : *in) {
983 if (obj ==
nullptr) {
986 const TBranch* element =
dynamic_cast<const TBranch*
>(obj);
989 return StatusCode::FAILURE;
991 const std::string objClassName = element->GetClassName();
992 std::string key = obj->GetName();
995 if (objClassName == targetClassName) {
996 ATH_MSG_DEBUG(
"Matched \"" << targetClassName <<
"\" to key \"" << key
998 keys.insert(std::move(key));
1005 ATH_MSG_DEBUG(
"Scanning input objects for \"" << targetClassName <<
"\"");
1006 for (
const auto &[key, vmgr] : inAux) {
1010 if (mgr ==
nullptr) {
1013 const std::string &objClassName = mgr->holder()->getClass()->GetName();
1016 if (objClassName == targetClassName) {
1017 ATH_MSG_DEBUG(
"Matched \"" << targetClassName <<
"\" to key \"" << key
1025 const TObjArray* out =
m_outTree->GetListOfBranches();
1028 for (
const TObject* obj : *out) {
1029 if (obj ==
nullptr) {
1032 const TBranch* element =
dynamic_cast<const TBranch*
>(obj);
1033 if (element ==
nullptr) {
1035 return StatusCode::FAILURE;
1037 const std::string objClassName = element->GetClassName();
1038 std::string key = obj->GetName();
1041 if (objClassName == targetClassName) {
1042 ATH_MSG_DEBUG(
"Matched \"" << targetClassName <<
"\" to key \"" << key
1044 keys.insert(std::move(key));
1052 ATH_MSG_DEBUG(
"Scanning output objects for \"" << targetClassName <<
"\"");
1053 for (
const auto &[key, vmgr] : outAux) {
1056 if (mgr ==
nullptr) {
1059 const std::string &objClassName = mgr->holder()->getClass()->GetName();
1062 if (objClassName == targetClassName) {
1063 ATH_MSG_DEBUG(
"Matched \"" << targetClassName <<
"\" to key \"" << key
1069 vkeys.insert(vkeys.end(),
keys.begin(),
keys.end());
1072 return StatusCode::SUCCESS;
1097 return StatusCode::FAILURE;
1105 return StatusCode::SUCCESS;
1109 if (silent ==
false) {
1112 return StatusCode::RECOVERABLE;
1118 if (silent ==
false) {
1126 ::TBranch* br =
m_inTree->GetBranch(key.c_str());
1127 if (br ==
nullptr) {
1132 return StatusCode::RECOVERABLE;
1136 br->SetMakeClass(0);
1140 std::string className = br->GetClassName();
1141 if (className ==
"") {
1145 className = ef->className();
1148 "Couldn't find an appropriate type with a dictionary for branch \""
1150 return StatusCode::FAILURE;
1153 ::TClass* realClass = ::TClass::GetClass(className.c_str());
1154 if (((!realClass) || (!realClass->IsLoaded())) && ef) {
1158 className = ef->className();
1159 realClass = ::TClass::GetClass(className.c_str());
1161 if ((!realClass) || (!realClass->IsLoaded())) {
1164 "Couldn't find an appropriate type with a dictionary for branch \""
1166 return StatusCode::FAILURE;
1170#ifndef XAOD_STANDALONE
1171 SG::CurrentEventStore::Push save (SG::CurrentEventStore::store());
1176 static const ::EDataType dataType = kOther_t;
1182 void* ptr =
nullptr;
1187 if (mgr ==
nullptr) {
1188 ATH_MSG_ERROR(
"Couldn't access output manager for: " << key);
1189 return StatusCode::FAILURE;
1192 ptr = mgr->holder()->get();
1198 if (ptr ==
nullptr) {
1199 ptr = realClass->New();
1204 auto mgr = std::make_unique<TObjectManager>(
1205 nullptr, std::make_unique<THolder>(ptr, realClass), renewOnRead);
1214 << key <<
"\" is " << br->GetSplitLevel()
1215 <<
". This can only be read in kAthenaAccess mode.");
1217 *(mgr->holder()->getPtr()) =
nullptr;
1219 return StatusCode::FAILURE;
1223 const ::Int_t status =
1224 m_inTree->SetBranchAddress(key.c_str(), mgr->holder()->getPtr(),
1225 mgr->branchPtr(), realClass, dataType, kTRUE);
1228 << className <<
"\" to input branch \"" << key
1229 <<
"\". Return code: " << status);
1231 *(mgr->holder()->getPtr()) = 0;
1233 return StatusCode::FAILURE;
1253 return StatusCode::SUCCESS;
1269 return StatusCode::FAILURE;
1274 return StatusCode::SUCCESS;
1279 if (br ==
nullptr) {
1280 if (silent ==
false) {
1282 <<
"\" not available on input");
1284 return StatusCode::RECOVERABLE;
1288 if (br->GetEntries() == 0) {
1289 if (silent ==
false) {
1291 <<
"\" doesn't hold any data");
1293 return StatusCode::RECOVERABLE;
1297 br->SetMakeClass(0);
1301 ::EDataType dt = kOther_t;
1302 if (br->GetExpectedType(cl, dt) || (!cl)) {
1303 ATH_MSG_ERROR(
"Couldn't get the type for metadata branch \"" << key
1305 return StatusCode::FAILURE;
1309 void* ptr = cl->New();
1311 auto mgr = std::make_unique<TObjectManager>(
1312 nullptr, std::make_unique<THolder>(ptr, cl), renewOnRead);
1316 key.c_str(), mgr->holder()->getPtr(), mgr->branchPtr(), cl, dt, kTRUE);
1319 << cl->GetName() <<
"\" to input branch \"" << key
1320 <<
"\". Return code: " << status);
1322 *(mgr->holder()->getPtr()) = 0;
1324 return StatusCode::FAILURE;
1333 ATH_MSG_ERROR(
"Couldn't read in metadata object with key \"" << key
1335 return StatusCode::FAILURE;
1348 static constexpr bool METADATA =
true;
1353 return StatusCode::SUCCESS;
1370 return StatusCode::FAILURE;
1374 if ((!
m_inTree->GetBranch(prefix.c_str())) &&
1378 return StatusCode::SUCCESS;
1383 return StatusCode::SUCCESS;
1391 static constexpr bool SILENT =
false;
1395 return StatusCode::SUCCESS;
1401 static constexpr bool TOP_STORE =
true;
1402 auto store = std::make_unique<TAuxStore>(
1416 static constexpr bool IS_OWNER =
true;
1418 std::make_unique<TAuxManager>(store.release(), IS_OWNER);
1421 return StatusCode::SUCCESS;
1426 return StatusCode::FAILURE;
1442 return StatusCode::SUCCESS;
1448 return StatusCode::FAILURE;
1456 static constexpr bool SILENT =
false;
1460 return StatusCode::SUCCESS;
1466 static constexpr bool TOP_STORE =
true;
1467 auto store = std::make_unique<TAuxStore>(
1481 static constexpr bool IS_OWNER =
true;
1483 std::make_unique<TAuxManager>(store.release(), IS_OWNER);
1486 return StatusCode::SUCCESS;
1491 return StatusCode::FAILURE;
1511 (isAuxStore ==
false)) {
1512 return StatusCode::SUCCESS;
1525 auto itr = objects.find(key +
"Aux.");
1526 if (itr == objects.end()) {
1529 return StatusCode::SUCCESS;
1531 auxMgr = itr->second.get();
1532 auxKey = key +
"Aux.";
1535 if (metadata ==
false) {
1537 const ::Int_t readBytes = auxMgr->
getEntry();
1538 if (readBytes < 0) {
1540 "Couldn't load current entry for auxiliary object with key \""
1542 return StatusCode::FAILURE;
1547 const std::string dynAuxKey = auxKey +
"Dynamic";
1548 auto dynAuxMgr = objects.find(dynAuxKey);
1550 if ((dynAuxMgr != objects.end()) &&
1556 dynAuxMgr->second->getEntry();
1567 auto dynAuxMgr = objects.find(dynAuxKey);
1568 if (dynAuxMgr == objects.end()) {
1570 return StatusCode::FAILURE;
1572 dynAuxMgr->second->getEntry();
1579 return StatusCode::SUCCESS;
1585 switch (mgr.holder()->typeKind()) {
1600 if (
vec && (!
vec->trackIndices())) {
1601 Details::forceTrackIndices(*
vec);
1605 if ((!
vec) && (!aux)) {
1607 << mgr.holder()->getClass()->GetName()
1608 <<
"\" as SG::AuxVectorBase or SG::AuxElement");
1609 return StatusCode::FAILURE;
1613 const SG::IConstAuxStore* store = 0;
1614#ifndef XAOD_STANDALONE
1622 << auxKey <<
"\" is not of the right type");
1623 return StatusCode::FAILURE;
1634#ifndef XAOD_STANDALONE
1642 << auxKey <<
"\" is not of the right type");
1643 return StatusCode::FAILURE;
1645 void* p = omgr->
holder()->
getAs(
typeid(SG::IConstAuxStore));
1646 SG::IConstAuxStore* store1 =
reinterpret_cast<SG::IConstAuxStore*
>(p);
1648#ifndef XAOD_STANDALONE
1654 return StatusCode::FAILURE;
1657#ifndef XAOD_STANDALONE
1659 if (store_nc)[[
likely]] {
1663 return StatusCode::FAILURE;
1669 vec->setStore(store);
1671 aux->setStore(store);
1674 return StatusCode::FAILURE;
1678 return StatusCode::SUCCESS;
1697 const std::string &key,
bool overwrite,
bool metadata,
1703 "No output tree defined. Did you forget to call writeTo(...)?");
1704 return StatusCode::FAILURE;
1714 ATH_MSG_ERROR(
"Meta-object \"" << typeName <<
"\"/\"" << key
1715 <<
"\" already recorded");
1716 return StatusCode::FAILURE;
1719 TClass* cl = TClass::GetClass(typeName.c_str());
1721 ATH_MSG_ERROR(
"Didn't find dictionary for type: " << typeName);
1722 return StatusCode::FAILURE;
1727 nullptr, std::make_unique<THolder>(obj, cl, isOwner), renewOnRead);
1729 return StatusCode::SUCCESS;
1736 <<
"\" already accessed from the input, can't be "
1737 "overwritten in memory");
1738 return StatusCode::FAILURE;
1742 const Int_t splitLevel = (key.ends_with(
"Aux.") ? 1 : 0);
1749 TClass* cl = TClass::GetClass(typeName.c_str());
1750 if (cl ==
nullptr) {
1751 ATH_MSG_ERROR(
"Didn't find dictionary for type: " << typeName);
1752 return StatusCode::FAILURE;
1763 auto mgr = std::make_unique<TObjectManager>(
1764 nullptr, std::make_unique<THolder>(obj, cl, isOwner), renewOnRead);
1769 static constexpr Int_t basketSize = 32000;
1771 m_outTree->Branch(key.c_str(), cl->GetName(),
1774 ATH_MSG_ERROR(
"Failed to create branch \"" << key <<
"\" out of type \""
1775 << cl->GetName() <<
"\"");
1778 return StatusCode::FAILURE;
1783 static constexpr bool METADATA =
false;
1788 return StatusCode::SUCCESS;
1794 ATH_MSG_ERROR(
"Manager object of the wrong type encountered");
1795 return StatusCode::FAILURE;
1804 TClass* cl = TClass::GetClass(typeName.c_str());
1806 ::strcmp(cl->GetName(), omgr->
holder()->
getClass()->GetName())) {
1808 << key <<
"\" the previous type was \""
1810 <<
"\", but the newly requested type is \"" << typeName
1812 return StatusCode::FAILURE;
1820 static constexpr bool METADATA =
false;
1824 return StatusCode::SUCCESS;
1832 if (iomgr !=
nullptr) {
1834 static const bool OVERWRITE =
true;
1835 static const bool IS_OWNER =
true;
1837 key, OVERWRITE, metadata, IS_OWNER));
1838 return StatusCode::SUCCESS;
1843 if (auxmgr !=
nullptr) {
1847 "TAuxStore auxiliary objects can only be recorded for event data");
1848 return StatusCode::FAILURE;
1852 return StatusCode::SUCCESS;
1856 ATH_MSG_ERROR(
"Unknown auxiliary store manager type encountered");
1857 return StatusCode::FAILURE;
1870 return StatusCode::SUCCESS;
1875 ATH_MSG_ERROR(
"Function called on an uninitialised object");
1876 return StatusCode::FAILURE;
1885 for (; itr != end; ++itr) {
1888 const std::string &branchName = itr->second.branchName();
1891 if (branchName.find(
"Aux.") != std::string::npos) {
1900 const std::string intName = branchName.substr(0, branchName.size() - 4);
1908 ::Bool_t auxFound = kFALSE;
1911 std::vector<TObjArray* > fullListOfBranches = {};
1913 fullListOfBranches.push_back(
m_inTree->GetListOfBranches());
1916 if (
m_inTree->GetListOfFriends()) {
1918 TList* fList =
m_inTree->GetListOfFriends();
1920 for (TObject* feObj : *fList) {
1923 auto* pElement =
dynamic_cast<TFriendElement*
>(feObj);
1926 TTree* friendTree = pElement->GetTree();
1928 fullListOfBranches.push_back(friendTree->GetListOfBranches());
1933 for (TObjArray* branches : fullListOfBranches) {
1934 for (Int_t i = 0; i < branches->GetEntriesFast(); ++i) {
1935 if (!branches->At(i))
1938 const TString
name(branches->At(i)->GetName());
1939 if (
name.BeginsWith(branchName) ||
name.BeginsWith(dynName)) {
1947 << intName <<
"\" belonging to branch \""
1948 << branchName <<
"\"");
1955 ::TClass* cl = ::TClass::GetClass(el->className().c_str());
1956 if ((!cl) || (!cl->IsLoaded())) {
1958 << el->className() <<
"\"");
1965 static ::TClass*
const baseCl = ::TClass::GetClass(baseName.c_str());
1967 ATH_MSG_ERROR(
"Couldn't get dictionary for type \"" << baseName
1969 return StatusCode::FAILURE;
1979 static constexpr bool TOP_STORE =
true;
1981 static constexpr bool PRINT_WARNINGS =
false;
1989 stats.branch(branchName,
id);
1993 stats.setBranchNum(stats.branchNum() + temp.
getAuxIDs().size());
1998 const ::TBranch* container =
m_inTree->GetBranch(branchName.c_str());
2007 return StatusCode::SUCCESS;
2023 const std::string &key) {
2028 "No output tree defined. Did you forget to call writeTo(...)?");
2029 return StatusCode::FAILURE;
2033 const std::set<std::string>* filter = 0;
2036 filter = &(filter_itr->second);
2045 store->selectAux(*filter);
2050 static constexpr bool OWNS_STORE =
true;
2052 std::make_unique<TAuxManager>(store.release(), OWNS_STORE);
2055 return StatusCode::SUCCESS;
2059 if (vitr->second->object() == store.get()) {
2061 return StatusCode::SUCCESS;
2070 if (mgr ==
nullptr) {
2072 << key <<
"\" already exists, and is not of type TAuxStore");
2073 return StatusCode::FAILURE;
2078 store->selectAux(*filter);
2085 mgr->setObject(store.release());
2088 return StatusCode::SUCCESS;
2102 ::TMethodCall setNameCall;
2106 setNameCall.InitWithPrototype(mgr.holder()->getClass(),
"setName",
2108 if (setNameCall.IsValid()) {
2111 const ::TString params =
2112 ::TString::Format(
"\"%s\"", mgr.branch()->GetName());
2113 const char* charParams = params.Data();
2114 setNameCall.Execute(mgr.holder()->get(), charParams);
2117 ATH_MSG_WARNING(
"Couldn't find setName(...) function for container \""
2118 << mgr.branch()->GetName() <<
"\" (type: "
2119 << mgr.holder()->getClass()->GetName() <<
")");
2124 static const TClass*
const holderClass =
2126 if (!mgr.holder()->getClass()->InheritsFrom(holderClass)) {
2128 return StatusCode::SUCCESS;
2136 return StatusCode::FAILURE;
2143 static constexpr bool TOP_STORE =
false;
2145 auto store = std::make_unique<TAuxStore>(
2146 ctx, mgr.branch()->GetName(), TOP_STORE,
2162 static constexpr bool SHARED_OWNER =
false;
2163 m_inputObjects[std::string(mgr.branch()->GetName()) +
"Dynamic"] =
2164 std::make_unique<TAuxManager>(store.get(), SHARED_OWNER);
2167 storeHolder->
setStore(store.release());
2170 return StatusCode::SUCCESS;
2193 return StatusCode::SUCCESS;
2197 if (!mgr->holder()->getClass()->InheritsFrom(
"SG::IAuxStoreIO")) {
2198 return StatusCode::SUCCESS;
2206 return StatusCode::FAILURE;
2213 auto item_itr =
m_auxItemList.find(mgr->branch()->GetName());
2215 sel.selectAux(item_itr->second);
2226 if (auxids.empty()) {
2227 return StatusCode::SUCCESS;
2231 const std::string dynNamePrefix =
2240 typedef std::pair<std::string, SG::auxid_t> AuxVarSort_t;
2241 std::vector<AuxVarSort_t> varsort;
2242 varsort.reserve(auxids.size());
2244 varsort.emplace_back(
r.getName(
id),
id);
2246 std::sort(varsort.begin(), varsort.end());
2249 for (
const auto &p : varsort) {
2255 const std::string brName = dynNamePrefix + p.first;
2258 Object_t::iterator bmgr = objects.find(brName);
2261 if (bmgr == objects.end()) {
2264 const std::type_info* brType = aux->
getIOType(
id);
2267 return StatusCode::FAILURE;
2270 std::string brProperTypeName =
"<unknown>";
2276 if (strlen(brType->name()) == 1) {
2279 brProperTypeName = brTypeName;
2283 if (rootType ==
'\0') {
2285 << brName <<
"\" of type \"" << brTypeName <<
"\"");
2286 return StatusCode::FAILURE;
2290 std::ostringstream leaflist;
2291 leaflist << brName <<
"/" << rootType;
2294 static constexpr bool IS_OWNER =
false;
2295 auto auxmgr = std::make_unique<TPrimitiveAuxBranchManager>(
2299 static constexpr Int_t BASKET_SIZE = 32000;
2300 *(auxmgr->branchPtr()) =
2301 outTree.Branch(brName.c_str(), auxmgr->holder()->get(),
2302 leaflist.str().c_str(), BASKET_SIZE);
2303 if (!auxmgr->branch()) {
2305 << brName <<
"\" out of type \"" << brProperTypeName
2308 *(auxmgr->holder()->getPtr()) = 0;
2309 return StatusCode::FAILURE;
2311 br = auxmgr->branch();
2314 objects[brName] = std::move(auxmgr);
2319 static constexpr Bool_t LOAD_IF_NOT_FOUND = kTRUE;
2320 static constexpr Bool_t SILENT = kTRUE;
2321 TClass* cl = TClass::GetClass(*brType, LOAD_IF_NOT_FOUND, SILENT);
2322 if (cl ==
nullptr) {
2325 cl = TClass::GetClass(brTypeName.c_str());
2327 if (cl ==
nullptr) {
2329 << brName <<
"\" of type \"" << brTypeName <<
"\"");
2330 return StatusCode::FAILURE;
2335 brProperTypeName = cl->GetName();
2338 static constexpr bool IS_OWNER =
false;
2339 auto auxmgr = std::make_unique<TAuxBranchManager>(
2343 static constexpr Int_t BASKET_SIZE = 32000;
2344 static constexpr Int_t SPLIT_LEVEL = 0;
2345 *(auxmgr->branchPtr()) = outTree.Branch(brName.c_str(), cl->GetName(),
2346 auxmgr->holder()->getPtr(),
2347 BASKET_SIZE, SPLIT_LEVEL);
2348 if (!auxmgr->branch()) {
2350 << brName <<
"\" out of type \"" << brProperTypeName
2353 *(auxmgr->holder()->getPtr()) = 0;
2354 return StatusCode::FAILURE;
2356 br = auxmgr->branch();
2359 objects[brName] = std::move(auxmgr);
2364 if (outTree.GetEntries()) {
2365 void* ptr = br->GetAddress();
2367 for (::Long64_t i = 0; i < outTree.GetEntries(); ++i) {
2370 br->SetAddress(ptr);
2377 mgr->branch()->GetName(),
2386 bmgr = objects.find(brName);
2387 if (bmgr == objects.end()) {
2388 ATH_MSG_FATAL(
"There is an internal logic error in the code...");
2389 return StatusCode::FAILURE;
2395 const_cast<void*
>(
static_cast<const void*
>(aux->
getIOData(
id)));
2396 bmgr->second->setObject(nc_data);
2400 return StatusCode::SUCCESS;
2408 return StatusCode::FAILURE;
2412 const std::set<std::string>* filter = 0;
2415 filter = &(filter_itr->second);
2424 store->selectAux(*filter);
2429 static constexpr bool OWNS_STORE =
false;
2430 m_outputObjects[key] = std::make_unique<TAuxManager>(store, OWNS_STORE);
2433 return StatusCode::SUCCESS;
2437 if (vitr->second->object() == store) {
2439 return StatusCode::SUCCESS;
2448 if (mgr ==
nullptr) {
2450 << key <<
"\" already exists, and is not of type TAuxStore");
2451 return StatusCode::FAILURE;
2456 store->selectAux(*filter);
2463 mgr->setObject(store);
2466 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(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
Hold a pointer to the current event store.
Recursively separate out template arguments in a C++ class name.
Interface providing I/O for a generic auxiliary store.
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
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.
virtual SG::auxid_set_t getSelectedAuxIDs() const
Get a list of dynamic variables that need to be written out.
virtual const std::type_info * getIOType(SG::auxid_t auxid) const =0
Return the type of the data to be stored for one aux data item.
virtual const void * getIOData(SG::auxid_t auxid) const =0
Return a pointer to the data to be stored for one aux data item.
Interface for non-const operations on an auxiliary store.
virtual void toTransient(const EventContext &ctx)=0
Perform post-read processing on this 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.
std::unordered_map< std::string, std::unique_ptr< TVirtualManager > > Object_t
Definition of the internal data structure type.
Object_t m_inputObjects
Collection of all the managed input objects.
Event(std::string_view name, const EventContext *ctx=nullptr)
Constructor with a name.
static const char *const METADATA_OBJECT_NAME
Name of the metadata tree or RNTuple.
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.
AthContainers_detail::upgrading_lock< upgrade_mutex_t > upgrading_lock_t
Lock type for multithread synchronization.
const EventContext & currentContext() const
Return the event context corresponding to this event.
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
StatusCode readFrom(::TTree &tree, bool printWarnings=true)
Connect the object to an input TTree.
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.
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.
::Int_t getEntry(::Long64_t entry, ::Int_t getall=0) override
Function loading a given entry of the input TTree.
TEvent(EAuxMode mode=kClassAccess, const EventContext *ctx=nullptr)
Default constructor.
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 finishWritingTo(TFile &file) override
Finish writing to an output file.
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.
::Int_t fill() override
Function filling one event into the output tree.
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.
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.
StatusCode writeTo(TFile &file) override
Connect the object to an output file.
::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).
void add(std::string_view fileName)
Add information about a new file that got accessed.
static TFileAccessTracer & instance()
Access the singleton instance of this class.
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.
virtual const SG::auxid_set_t & getAuxIDs() const override
Get the types(names) of variables handled by this 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...
AuxElement(SG::AuxVectorData *container, size_t index)
Base class for elements of a container that can have aux data.
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...