ATLAS Offline Software
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.
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 
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 }
beamspotman.r
def r
Definition: beamspotman.py:676
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
TBranchAuxDynStore::TBranchAuxDynStore
TBranchAuxDynStore(TBranchAuxDynReader &reader, long long entry, bool standalone, std::recursive_mutex *iomtx=nullptr)
Definition: TBranchAuxDynStore.cxx:17
L1CaloPhase1Monitoring.standalone
standalone
Definition: L1CaloPhase1Monitoring.py:112
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:640
ATHCONTAINERS_ERROR
#define ATHCONTAINERS_ERROR(ctx, msg)
Definition: error.h:50
SG::AuxStoreInternal::standalone
bool standalone() const
Return the standalone flag.
Definition: AuxStoreInternal.cxx:67
exceptions.h
Exceptions that can be thrown from AthContainers.
TBranchAuxDynStore::m_reader
TBranchAuxDynReader & m_reader
Definition: TBranchAuxDynStore.h:32
TBranchAuxDynStore::readData
virtual bool readData(SG::auxid_t auxid) override final
read data from ROOT and store it in m_vecs. Returns False on error
Definition: TBranchAuxDynStore.cxx:25
RootAuxDynStore
Definition: RootAuxDynStore.h:16
AuxDataOption.h
Hold information about an option setting request.
SG::AuxTypeRegistry
Handle mappings between names and auxid_t.
Definition: AuxTypeRegistry.h:61
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
RootAuxDynStore::m_entry
long long m_entry
Definition: RootAuxDynStore.h:62
lumiFormat.i
int i
Definition: lumiFormat.py:85
vector
Definition: MultiHisto.h:13
lumiFormat.e_str
e_str
Definition: lumiFormat.py:81
error.h
Helper for emitting error messages.
SG::AuxStoreInternal::setOption
virtual bool setOption(auxid_t id, const AuxDataOption &option) override
Set an option for an auxiliary data variable.
Definition: AuxStoreInternal.cxx:636
SG::AuxStoreInternal::getDataInternal
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.
Definition: AuxStoreInternal.cxx:735
TBranchAuxDynReader::addBytes
void addBytes(size_t bytes)
Definition: TBranchAuxDynReader.h:88
SG::AuxStoreInternal::getIOData
virtual const void * getIOData(SG::auxid_t auxid) const override
Return a pointer to the data to be stored for one aux data item.
Definition: AuxStoreInternal.cxx:515
TBranchAuxDynReader
Definition: TBranchAuxDynReader.h:20
SG::AuxDataOption
Hold information about an option setting request.
Definition: AuxDataOption.h:37
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
TBranchAuxDynReader::getBranchInfo
BranchInfo & getBranchInfo(const SG::auxid_t &auxid, const SG::AuxStoreInternal &store)
Definition: TBranchAuxDynReader.cxx:242
TBranchAuxDynReader.h
AuxTypeRegistry.h
Handle mappings between names and auxid_t.
TBranchAuxDynStore.h
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
collisions.reader
reader
read the goodrunslist xml file(s)
Definition: collisions.py:22
RootAuxDynStore::m_iomutex
std::recursive_mutex * m_iomutex
Optional mutex used to serialize I/O with RootStorageSvc (not owned)
Definition: RootAuxDynStore.h:70