ATLAS Offline Software
Loading...
Searching...
No Matches
TBranchAuxDynStore.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 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
18 std::recursive_mutex* iomtx)
19 : RootAuxDynStore( reader, entry, standalone, iomtx ),
20 m_reader(reader)
21{
22}
23
24
26{
27 try {
28 auto& brInfo = m_reader.getBranchInfo(auxid, *this);
29 if( !brInfo.branch ) return false;
30
31 // Make a 1-element vector.
33 if( brInfo.isPackedContainer ) {
34 setOption (auxid, SG::AuxDataOption ("nbits", 32));
35 }
36
37 // get memory location where to write data from the branch entry
38 // const_cast because TTree::SetBranchAddress requires void*
39 void * vector ATLAS_THREAD_SAFE = const_cast<void*>(SG::AuxStoreInternal::getIOData (auxid));
40 void * data = &vector;
41 if( standalone() && !brInfo.tclass ) {
42 // reading fundamental type - ROOT expects a direct pointer
43 data = vector;
44 }
45
46 // if have mutex, lock to prevent potential concurrent I/O from elsewhere
47 auto io_lock = m_iomutex? std::unique_lock<std::recursive_mutex>(*m_iomutex)
48 : std::unique_lock<std::recursive_mutex>();
49 // read branch
50 brInfo.setAddress(data);
51 int nbytes = brInfo.branch->GetEntry(m_entry);
52 if( nbytes <= 0 )
53 throw std::string("Error reading branch ") + brInfo.branch->GetName();
54 // read OK
55 m_reader.addBytes(nbytes);
56 TTree::TClusterIterator clusterIterator = brInfo.branch->GetTree()->GetClusterIterator(m_entry);
57 clusterIterator.Next();
58 if (m_entry == clusterIterator.GetStartEntry() && brInfo.branch->GetTree()->GetMaxVirtualSize() != 0) {
59 for (int i = brInfo.branch->GetReadBasket(); i < brInfo.branch->GetMaxBaskets()
60 && brInfo.branch->GetBasketEntry()[i] < clusterIterator.GetNextEntry(); i++) {
61 brInfo.branch->GetBasket(i);
62 }
63 }
64 }
65 catch(const std::string& e_str) {
66 ATHCONTAINERS_ERROR("TBranchAuxDynStore::getData", e_str);
67 return false;
68 }
69
71 SG::auxid_t linked_auxid = r.linkedVariable (auxid);
72 if (linked_auxid != SG::null_auxid) {
73 return readData (linked_auxid);
74 }
75 return true;
76}
Hold information about an option setting request.
Handle mappings between names and auxid_t.
Exceptions that can be thrown from AthContainers.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
#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)
Hold information about an option setting request.
virtual void * getDataInternal(SG::auxid_t auxid, size_t size, size_t capacity, bool no_lock_check)
Return the data vector for one aux data item.
virtual bool setOption(auxid_t id, const AuxDataOption &option) override
Set an option for an auxiliary data variable.
bool standalone() const
Return the standalone flag.
virtual const void * getIOData(SG::auxid_t auxid) const override
Return a pointer to the data to be stored for one aux data item.
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:54
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