ATLAS Offline Software
Loading...
Searching...
No Matches
TBranchAuxDynStore.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5
10
11#include "TBranchAuxDynStore.h"
12#include "TBranchAuxDynReader.h"
13
14#include "TTree.h"
15
16
17TBranchAuxDynStore::TBranchAuxDynStore(TBranchAuxDynReader& reader, long long entry, bool standalone,
18 std::recursive_mutex* iomtx)
19 : RootAuxDynStore( reader, entry, standalone, iomtx ),
20 m_reader(reader)
21{
22}
23
24
26{
27 try {
28 // if have mutex, lock to prevent potential concurrent I/O from elsewhere;
29 // also protects the branch infos of the reader, which is shared between events
30 auto io_lock = m_iomutex? std::unique_lock<std::recursive_mutex>(*m_iomutex)
31 : std::unique_lock<std::recursive_mutex>();
32 auto& brInfo = m_reader.getBranchInfo(auxid, *this);
33 if( !brInfo.branch ) return false;
34
35 // Make a 1-element vector.
36 SG::AuxStoreInternal::getDataInternal(auxid, 1, 1, true);
37 if( brInfo.isPackedContainer ) {
38 setOption (auxid, SG::AuxDataOption ("nbits", 32));
39 }
40
41 // get memory location where to write data from the branch entry
42 // const_cast because TTree::SetBranchAddress requires void*
43 void * vector ATLAS_THREAD_SAFE = const_cast<void*>(SG::AuxStoreInternal::getIOData (auxid));
44 void * data = &vector;
45 if( standalone() && !brInfo.tclass ) {
46 // reading fundamental type - ROOT expects a direct pointer
47 data = vector;
48 }
49
50 // read branch
51 brInfo.setAddress(data);
52 int nbytes = brInfo.branch->GetEntry(m_entry);
53 if( nbytes <= 0 )
54 throw std::string("Error reading branch ") + brInfo.branch->GetName();
55 // read OK
56 m_reader.addBytes(nbytes);
57 TTree::TClusterIterator clusterIterator = brInfo.branch->GetTree()->GetClusterIterator(m_entry);
58 clusterIterator.Next();
59 if (m_entry == clusterIterator.GetStartEntry() && brInfo.branch->GetTree()->GetMaxVirtualSize() != 0) {
60 for (int i = brInfo.branch->GetReadBasket(); i < brInfo.branch->GetMaxBaskets()
61 && brInfo.branch->GetBasketEntry()[i] < clusterIterator.GetNextEntry(); i++) {
62 brInfo.branch->GetBasket(i);
63 }
64 }
65 }
66 catch(const std::string& e_str) {
67 ATHCONTAINERS_ERROR("TBranchAuxDynStore::getData", e_str);
68 return false;
69 }
70
71 SG::AuxStoreInternal::toTransient (m_ctx, auxid);
73 SG::auxid_t linked_auxid = r.linkedVariable (auxid);
74 if (linked_auxid != SG::null_auxid) {
75 return readData (linked_auxid);
76 }
77 return true;
78}
Hold information about an option setting request.
Handle mappings between names and auxid_t.
Exceptions that can be thrown from AthContainers.
#define ATLAS_THREAD_SAFE
RootAuxDynStore(RootAuxDynReader &reader, long long entry, bool standalone, std::recursive_mutex *iomtx=nullptr)
std::recursive_mutex * m_iomutex
Optional mutex used to serialize I/O with RootStorageSvc (not owned).
EventContext m_ctx
Event context associated with the event store.
Hold information about an option setting request.
Handle mappings between names and auxid_t.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
virtual bool readData(SG::auxid_t auxid) override final
read data from ROOT and store it in m_vecs. Returns False on error
TBranchAuxDynStore(TBranchAuxDynReader &reader, long long entry, bool standalone, std::recursive_mutex *iomtx=nullptr)
TBranchAuxDynReader & m_reader
Helper for emitting error messages.
#define ATHCONTAINERS_ERROR(ctx, msg,...)
Definition error.h:62
int r
Definition globals.cxx:22
static const auxid_t null_auxid
To signal no aux data item.
Definition AuxTypes.h:30
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27