ATLAS Offline Software
Loading...
Searching...
No Matches
TBranchAuxDynStore Class Reference

#include <TBranchAuxDynStore.h>

Inheritance diagram for TBranchAuxDynStore:
Collaboration diagram for TBranchAuxDynStore:

Public Member Functions

 TBranchAuxDynStore (TBranchAuxDynReader &reader, long long entry, bool standalone, std::recursive_mutex *iomtx=nullptr)
virtual ~TBranchAuxDynStore ()
virtual const void * getData (SG::auxid_t auxid) const override
 implementation of the IAuxStore interface
virtual void * getData (SG::auxid_t auxid, size_t size, size_t capacity) override
virtual const SG::IAuxTypeVectorgetVector (SG::auxid_t auxid) const override
virtual const void * getIOData (SG::auxid_t auxid) const override
 implementation of the IAuxStoreIO interface
virtual void * getDecoration (SG::auxid_t auxid, size_t size, size_t capacity) override
 Return the data vector for one aux data decoration item.
virtual bool isDecoration (SG::auxid_t auxid) const override
 Test if a particular variable is tagged as a decoration.
virtual size_t size () const override
 Return the number of elements in the store.

Protected Types

typedef AthContainers_detail::mutex mutex_t
 Mutex used to synchronize modifications to the cache vector.
typedef AthContainers_detail::lock_guard< mutex_tguard_t

Protected Member Functions

virtual bool readData (SG::auxid_t auxid) override final
 read data from ROOT and store it in m_vecs. Returns False on error

Protected Attributes

TBranchAuxDynReaderm_reader
long long m_entry
mutex_t m_mutex
std::recursive_mutex * m_iomutex
 Optional mutex used to serialize I/O with RootStorageSvc (not owned).

Detailed Description

Definition at line 20 of file TBranchAuxDynStore.h.

Member Typedef Documentation

◆ guard_t

Definition at line 67 of file RootAuxDynStore.h.

◆ mutex_t

Mutex used to synchronize modifications to the cache vector.

Definition at line 66 of file RootAuxDynStore.h.

Constructor & Destructor Documentation

◆ TBranchAuxDynStore()

TBranchAuxDynStore::TBranchAuxDynStore ( TBranchAuxDynReader & reader,
long long entry,
bool standalone,
std::recursive_mutex * iomtx = nullptr )

Definition at line 17 of file TBranchAuxDynStore.cxx.

19 : RootAuxDynStore( reader, entry, standalone, iomtx ),
20 m_reader(reader)
21{
22}
RootAuxDynStore(RootAuxDynReader &reader, long long entry, bool standalone, std::recursive_mutex *iomtx=nullptr)
TBranchAuxDynReader & m_reader

◆ ~TBranchAuxDynStore()

virtual TBranchAuxDynStore::~TBranchAuxDynStore ( )
inlinevirtual

Definition at line 26 of file TBranchAuxDynStore.h.

26{}

Member Function Documentation

◆ getData() [1/2]

const void * RootAuxDynStore::getData ( SG::auxid_t auxid) const
overridevirtualinherited

implementation of the IAuxStore interface

Definition at line 25 of file RootAuxDynStore.cxx.

26{
27 const SG::IAuxTypeVector* v = getVector( auxid );
28 if( v ) {
29 return v->toPtr();
30 }
31 return nullptr;
32}
virtual const SG::IAuxTypeVector * getVector(SG::auxid_t auxid) const override

◆ getData() [2/2]

void * RootAuxDynStore::getData ( SG::auxid_t auxid,
size_t size,
size_t capacity )
overridevirtualinherited

Definition at line 50 of file RootAuxDynStore.cxx.

51{
52 // MN: how do we add new attributes to this store? A:for now we don't
53 throw("Non-const access to RootAuxDynStore is not supported");
54}

◆ getDecoration()

void * RootAuxDynStore::getDecoration ( SG::auxid_t auxid,
size_t size,
size_t capacity )
overridevirtualinherited

Return the data vector for one aux data decoration item.

Parameters
auxidThe identifier of the desired aux data item.
sizeThe current size of the container (in case the data item does not already exist).
capacityThe current capacity of the container (in case the data item does not already exist).
auxidThe identifier of the desired aux data item.
sizeThe current size of the container (in case the data item does not already exist).
capacityThe current capacity of the container (in case the data item does not already exist).

Each aux data item is stored as a vector, with one entry per entry in the owning container. This returns a pointer to the start of the vector.

The base class implementation works except for the case where we have not yet created a vector for an item in the root file. We need to detect that case and raise an exception.

Definition at line 87 of file RootAuxDynStore.cxx.

88{
89 guard_t guard (m_mutex);
90 if (SG::AuxStoreInternal::getIODataInternal (auxid, true) == 0 &&
91 SG::AuxStoreInternal::getAuxIDs().count (auxid) > 0)
92 {
93 throw SG::ExcStoreLocked (auxid);
94 }
95 return SG::AuxStoreInternal::getDecoration (auxid, size, capacity);
96}
AthContainers_detail::lock_guard< mutex_t > guard_t
virtual size_t size() const override
Return the number of elements in the store.
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:148

◆ getIOData()

const void * RootAuxDynStore::getIOData ( SG::auxid_t auxid) const
overridevirtualinherited

implementation of the IAuxStoreIO interface

Definition at line 57 of file RootAuxDynStore.cxx.

58{
59 guard_t guard (m_mutex);
60 const void* ret = SG::AuxStoreInternal::getIODataInternal (auxid, true);
61 if (!ret) {
62 auto this_nc ATLAS_THREAD_SAFE = const_cast<RootAuxDynStore*>(this); // locked above
63 if( this_nc->readData(auxid) ) {
64 ret = SG::AuxStoreInternal::getIOData (auxid);
65 }
66 }
67 return ret;
68}
#define ATLAS_THREAD_SAFE

◆ getVector()

const SG::IAuxTypeVector * RootAuxDynStore::getVector ( SG::auxid_t auxid) const
overridevirtualinherited

Definition at line 35 of file RootAuxDynStore.cxx.

36{
37 guard_t guard (m_mutex);
38 // lock
39 const SG::IAuxTypeVector* ret = SG::AuxStoreInternal::getVector (auxid);
40 if (!ret) {
41 auto this_nc ATLAS_THREAD_SAFE = const_cast<RootAuxDynStore*>(this); // locked above
42 if( this_nc->readData(auxid) ) {
43 ret = SG::AuxStoreInternal::getVector (auxid);
44 }
45 }
46 return ret;
47}

◆ isDecoration()

bool RootAuxDynStore::isDecoration ( SG::auxid_t auxid) const
overridevirtualinherited

Test if a particular variable is tagged as a decoration.

Parameters
auxidThe identifier of the desired aux data item.
auxidThe identifier of the desired aux data item.

See getDecoration() above.

Definition at line 105 of file RootAuxDynStore.cxx.

106{
107 guard_t guard( m_mutex );
108 if (SG::AuxStoreInternal::getIODataInternal (auxid, true) == 0 &&
109 SG::AuxStoreInternal::getAuxIDs().count (auxid) > 0)
110 {
111 return false;
112 }
113 return SG::AuxStoreInternal::isDecoration (auxid);
114}

◆ readData()

bool TBranchAuxDynStore::readData ( SG::auxid_t auxid)
finaloverrideprotectedvirtual

read data from ROOT and store it in m_vecs. Returns False on error

Implements RootAuxDynStore.

Definition at line 25 of file TBranchAuxDynStore.cxx.

26{
27 try {
28 auto& brInfo = m_reader.getBranchInfo(auxid, *this);
29 if( !brInfo.branch ) return false;
30
31 // Make a 1-element vector.
32 SG::AuxStoreInternal::getDataInternal(auxid, 1, 1, true);
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
70 SG::AuxTypeRegistry& r = SG::AuxTypeRegistry::instance();
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}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
if(pathvar)
std::recursive_mutex * m_iomutex
Optional mutex used to serialize I/O with RootStorageSvc (not owned).
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
#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
virtual bool setOption(auxid_t id, const AuxDataOption &option) override
Set an option for an auxiliary data variable.
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27

◆ size()

size_t RootAuxDynStore::size ( ) const
overridevirtualinherited

Return the number of elements in the store.

May return 0 for a store with no aux data.

NOTE: this method will attempt to read data if size unknown (0) May return 0 for a store with no aux data.

Definition at line 121 of file RootAuxDynStore.cxx.

122{
123 const std::size_t s = SG::AuxStoreInternal::size();
124 if( s != 0 ) {
125 return s;
126 }
127
128 for( SG::auxid_t id : getAuxIDs() ) {
129 if( getData( id ) != nullptr ) {
130 return SG::AuxStoreInternal::size();
131 }
132 }
133
134 return 0;
135}
virtual const void * getData(SG::auxid_t auxid) const override
implementation of the IAuxStore interface
const SG::auxid_set_t & getAuxIDs() const
Return a set of identifiers for existing data items for this object.

Member Data Documentation

◆ m_entry

long long RootAuxDynStore::m_entry
protectedinherited

Definition at line 63 of file RootAuxDynStore.h.

◆ m_iomutex

std::recursive_mutex* RootAuxDynStore::m_iomutex
protectedinherited

Optional mutex used to serialize I/O with RootStorageSvc (not owned).

Definition at line 71 of file RootAuxDynStore.h.

◆ m_mutex

mutex_t RootAuxDynStore::m_mutex
mutableprotectedinherited

Definition at line 68 of file RootAuxDynStore.h.

◆ m_reader

TBranchAuxDynReader& TBranchAuxDynStore::m_reader
protected

Definition at line 32 of file TBranchAuxDynStore.h.


The documentation for this class was generated from the following files: