ATLAS Offline Software
Classes | Public Member Functions | Protected Attributes | Private Member Functions | List of all members
TBranchAuxDynReader Class Reference

#include <TBranchAuxDynReader.h>

Inheritance diagram for TBranchAuxDynReader:
Collaboration diagram for TBranchAuxDynReader:

Classes

struct  BranchInfo
 

Public Member Functions

 TBranchAuxDynReader (TTree *tree, TBranch *base_branch)
 
void init (bool standalone)
 
virtual void addReaderToObject (void *object, size_t ttree_row, std::recursive_mutex *iomtx=nullptr) override final
 Attach specialized AuxStore for reading dynamic attributes. More...
 
void addBytes (size_t bytes)
 
virtual size_t getBytesRead () const override final
 
virtual void resetBytesRead () override final
 
virtual const SG::auxid_set_tauxIDs () const override final
 
BranchInfogetBranchInfo (const SG::auxid_t &auxid, const SG::AuxStoreInternal &store)
 
virtual ~TBranchAuxDynReader ()
 

Protected Attributes

SG::auxid_set_t m_auxids
 
std::string m_baseBranchName
 
size_t m_bytesRead = 0
 
int m_storeHolderOffset = -1
 
bool m_initialized = false
 
std::string m_key
 
TTree * m_tree = nullptr
 
std::map< std::string, TBranch * > m_branchMap
 
std::map< SG::auxid_t, BranchInfom_branchInfos
 

Private Member Functions

SG::auxid_t initBranch (bool standalone, const std::string &attr, TBranch *branch)
 

Detailed Description

Definition at line 19 of file TBranchAuxDynReader.h.

Constructor & Destructor Documentation

◆ TBranchAuxDynReader()

TBranchAuxDynReader::TBranchAuxDynReader ( TTree *  tree,
TBranch *  base_branch 
)

Definition at line 153 of file TBranchAuxDynReader.cxx.

154  : m_baseBranchName( base_branch->GetName() ),
155  m_key( RootAuxDynIO::getKeyFromBranch(base_branch) ),
156  m_tree( tree )
157 {
158  // The Branch here is the object (AuxContainer) branch, not the attribute branch
159  TClass *tc = nullptr, *storeTC = nullptr;
160  EDataType type;
161  base_branch->GetExpectedType(tc, type); //MN: Errors would be coaught in isAuxDynBranch() earlier
162  if( tc ) storeTC = tc->GetBaseClass("SG::IAuxStoreHolder");
163  if( storeTC ) m_storeHolderOffset = tc->GetBaseClassOffset( storeTC );
164  if( m_storeHolderOffset < 0 ) {
165  const std::string name = (tc? tc->GetName() : m_baseBranchName);
166  errorcheck::ReportMessage msg (MSG::INFO, ERRORCHECK_ARGS, "TBranchAuxDynReader");
167  msg << "IAuxStoreHolder interface not found in " << name << " - will not read dynamic attributes";
168  }
169 
171  string branch_prefix = RootAuxDynIO::auxBranchName("", m_baseBranchName);
172  TObjArray *all_branches = m_tree->GetListOfBranches();
173  for( int i=0; i<all_branches->GetEntriesFast(); i++ ) {
174  const char *bname = (*all_branches)[i]->GetName();
175  if( strncmp(bname, branch_prefix.c_str(), branch_prefix.size()) == 0 ) {
176  const string attr_inFile = bname+branch_prefix.size();
177  const string attr = r.inputRename (m_key, attr_inFile);
178  m_branchMap[attr] = (TBranch*)(*all_branches)[i];
179  }
180  }
181 }

◆ ~TBranchAuxDynReader()

virtual TBranchAuxDynReader::~TBranchAuxDynReader ( )
inlinevirtual

Definition at line 61 of file TBranchAuxDynReader.h.

61 {}

Member Function Documentation

◆ addBytes()

void TBranchAuxDynReader::addBytes ( size_t  bytes)
inline

Definition at line 88 of file TBranchAuxDynReader.h.

88  {
89  m_bytesRead += bytes;
90 }

◆ addReaderToObject()

void TBranchAuxDynReader::addReaderToObject ( void *  object,
size_t  row,
std::recursive_mutex *  iomtx = nullptr 
)
finaloverridevirtual

Attach specialized AuxStore for reading dynamic attributes.

Parameters
objectobject instance to which the store will be attached to - has to be an instance of the type the reader was created for
ttree_rowUse this method to instrument an AuxStore object AFTER it was read (every time it is read) This will attach its dynamic attributes with read-on-demand capability

Implements RootAuxDynIO::IRootAuxDynReader.

Definition at line 331 of file TBranchAuxDynReader.cxx.

332 {
333  if( m_storeHolderOffset >= 0 ) {
334  auto store_holder = reinterpret_cast<SG::IAuxStoreHolder*>((char*)object + m_storeHolderOffset);
335  bool standalone { store_holder->getStoreType()==SG::IAuxStoreHolder::AST_ObjectStore };
336  if( !m_initialized )
337  init(standalone);
338  store_holder->setStore( new TBranchAuxDynStore(*this, ttree_row, standalone, iomtx) );
339  }
340 }

◆ auxIDs()

const SG::auxid_set_t & TBranchAuxDynReader::auxIDs ( ) const
inlinefinaloverridevirtual

Implements RootAuxDynIO::IRootAuxDynReader.

Definition at line 100 of file TBranchAuxDynReader.h.

100  {
101  return m_auxids;
102 }

◆ getBranchInfo()

TBranchAuxDynReader::BranchInfo & TBranchAuxDynReader::getBranchInfo ( const SG::auxid_t auxid,
const SG::AuxStoreInternal store 
)

Definition at line 242 of file TBranchAuxDynReader.cxx.

243 {
244  BranchInfo& brInfo = m_branchInfos[auxid];
245  if( brInfo.status == BranchInfo::NotInitialized )
246  {
248  brInfo.auxid = auxid;
249  brInfo.attribName = r.getName(auxid);
250  // Don't match this attribute if it's been renamed.
251  // For example, suppose we've renamed attribute `foo' to `foo_old',
252  // and someone then comes and asks for `foo'.
253  // `foo' will not be found in the m_branchMap test below
254  // (`foo_old' will be in this map). However, in the following
255  // else clause, we'll recreate the branch name from `foo'.
256  // This branch exists (renaming is only in the transient store),
257  // so if we didn't have the condition here, then we'd then
258  // make a `foo' attribute from that branch.
259  if (r.inputRename (m_key, brInfo.attribName) != brInfo.attribName) {
260  brInfo.status = BranchInfo::NotFound;
261  return brInfo;
262  }
263 
264  auto it = m_branchMap.find (brInfo.attribName);
265  if (it != m_branchMap.end()) {
266  brInfo.branch = it->second;
267  }
268  else {
269  const string aux_branch_name = RootAuxDynIO::auxBranchName(brInfo.attribName, m_baseBranchName);
270  brInfo.branch = m_tree->GetBranch( aux_branch_name.c_str() );
271  }
272 
273  // mark initialized here so it remembers this branch was not found
274  if( !brInfo.branch ) {
275  brInfo.status = BranchInfo::NotFound;
276  return brInfo;
277  }
278  if( brInfo.branch->GetExpectedType( brInfo.tclass, brInfo.edtyp) ) {
279  brInfo.status = BranchInfo::TypeError;
280  throw string("Error getting branch type for ") + brInfo.branch->GetName();
281  }
282 
283  if( !store.standalone() )
284  if( brInfo.tclass && strncmp( brInfo.tclass->GetName(), "SG::PackedContainer<", 20) == 0)
285  brInfo.isPackedContainer = true;
286 
287  string elem_tname, branch_tname;
288  // AuxElement TypeID
289  const std::type_info* ti = getAuxElementType( brInfo.tclass, brInfo.edtyp, store.standalone(),
290  elem_tname, branch_tname );
291  const std::type_info* reg_ti = r.getType(auxid);
292  // I/O / Storage TypeID
293  const std::type_info *io_tinf = store.getIOType(auxid);
294  const std::type_info *tcls_tinf = brInfo.tclass ? brInfo.tclass->GetTypeInfo() : ti;
295 
296  if (not io_tinf){
297  brInfo.status = BranchInfo::TypeError;
298  throw string("Error getting IO type for AUX branch ") + brInfo.branch->GetName();
299  }
300  // if there is a TClass compare the whole storage types (usually vectors), because the Element type
301  // returned by CollProxy loses the pointer component and element type comparison for vector<T*> fails
302  brInfo.needsSE = brInfo.tclass ?
303  io_tinf != tcls_tinf && (!tcls_tinf || strcmp(io_tinf->name(), tcls_tinf->name()) != 0)
304  : ti && ti != reg_ti && strcmp(ti->name(), reg_ti->name()) != 0;
305  if( brInfo.needsSE ) {
306  // type in registry is different than type in the file.
307  // will need to use ROOT auto schema evolution
308  errorcheck::ReportMessage msg (MSG::INFO, ERRORCHECK_ARGS, "TBranchAuxDynReader");
309  msg << "attribute '" << brInfo.attribName << "' (id=" << auxid
310  << " typename=" << SG::normalizedTypeinfoName(*reg_ti)
311  << ") has different type than the branch: " << branch_tname;
312  msg << " Marking for schema evolution.";
313 
314  brInfo.SE_tclass = TClass::GetClass(*io_tinf);
315  brInfo.SE_edt = kOther_t;
316  if( !brInfo.SE_tclass ) {
317  brInfo.SE_edt = TDataType::GetType(*io_tinf);
318  if( brInfo.SE_edt <=0 ) {
319  brInfo.status = BranchInfo::TypeError;
320  throw string("Error getting ROOT type for AUX branch ") + brInfo.branch->GetName()
321  + " typeinfo=" + io_tinf->name();
322  }
323  }
324  }
325  brInfo.status = BranchInfo::Initialized;
326  }
327  return brInfo;
328 }

◆ getBytesRead()

size_t TBranchAuxDynReader::getBytesRead ( ) const
inlinefinaloverridevirtual

Implements RootAuxDynIO::IRootAuxDynReader.

Definition at line 92 of file TBranchAuxDynReader.h.

92  {
93  return m_bytesRead;
94 }

◆ init()

void TBranchAuxDynReader::init ( bool  standalone)

Definition at line 229 of file TBranchAuxDynReader.cxx.

230 {
231  if( m_initialized ) return;
232 
233  for( const auto& attr2branch: m_branchMap ) {
234  initBranch (standalone, attr2branch.first, attr2branch.second);
235  }
236  m_initialized = true;
237 }

◆ initBranch()

SG::auxid_t TBranchAuxDynReader::initBranch ( bool  standalone,
const std::string &  attr,
TBranch *  branch 
)
private

Definition at line 184 of file TBranchAuxDynReader.cxx.

187 {
188  TClass* expectedClass = 0;
189  EDataType expectedType = kOther_t;
190  if( branch->GetExpectedType(expectedClass, expectedType) != 0) {
191  // raise hell
192  }
193 
194  SG::auxid_t linked_auxid = SG::null_auxid;
195  if (expectedClass) {
196  std::string className = expectedClass->GetName();
198  std::string linkedAttr = SG::AuxTypeRegistry::linkedName (attr);
199  auto it = m_branchMap.find (linkedAttr);
200  if (it != m_branchMap.end()) {
201  linked_auxid = initBranch (standalone, linkedAttr, it->second);
202  }
203  if (linked_auxid == SG::null_auxid) {
204  errorcheck::ReportMessage msg (MSG::WARNING, ERRORCHECK_ARGS, "TBranchAuxDynReader::initBranch");
205  msg << "Could not find linked variable for " << branch->GetName()
206  << " type: " << expectedClass->GetName();
207  }
208  }
209  }
210 
211  SG::auxid_t auxid = getAuxIdForAttribute(attr, expectedClass, expectedType, standalone,
212  linked_auxid);
213 
214  // add AuxID to the list
215  // May still be null if we don't have a dictionary for the branch.
216  if (auxid != SG::null_auxid) {
217  m_auxids.insert(auxid);
218  } else {
219  errorcheck::ReportMessage msg (MSG::WARNING, ERRORCHECK_ARGS, "TBranchAuxDynReader::initBranch");
220  msg << "Could not find auxid for " << branch->GetName()
221  << " type: " << expectedClass->GetName();
222 
223  }
224  return auxid;
225 }

◆ resetBytesRead()

void TBranchAuxDynReader::resetBytesRead ( )
inlinefinaloverridevirtual

Implements RootAuxDynIO::IRootAuxDynReader.

Definition at line 96 of file TBranchAuxDynReader.h.

96  {
97  m_bytesRead = 0;
98 }

Member Data Documentation

◆ m_auxids

SG::auxid_set_t TBranchAuxDynReader::m_auxids
protected

Definition at line 65 of file TBranchAuxDynReader.h.

◆ m_baseBranchName

std::string TBranchAuxDynReader::m_baseBranchName
protected

Definition at line 67 of file TBranchAuxDynReader.h.

◆ m_branchInfos

std::map<SG::auxid_t, BranchInfo> TBranchAuxDynReader::m_branchInfos
protected

Definition at line 79 of file TBranchAuxDynReader.h.

◆ m_branchMap

std::map<std::string, TBranch*> TBranchAuxDynReader::m_branchMap
protected

Definition at line 77 of file TBranchAuxDynReader.h.

◆ m_bytesRead

size_t TBranchAuxDynReader::m_bytesRead = 0
protected

Definition at line 69 of file TBranchAuxDynReader.h.

◆ m_initialized

bool TBranchAuxDynReader::m_initialized = false
protected

Definition at line 72 of file TBranchAuxDynReader.h.

◆ m_key

std::string TBranchAuxDynReader::m_key
protected

Definition at line 73 of file TBranchAuxDynReader.h.

◆ m_storeHolderOffset

int TBranchAuxDynReader::m_storeHolderOffset = -1
protected

Definition at line 71 of file TBranchAuxDynReader.h.

◆ m_tree

TTree* TBranchAuxDynReader::m_tree = nullptr
protected

Definition at line 75 of file TBranchAuxDynReader.h.


The documentation for this class was generated from the following files:
TBranchAuxDynReader::initBranch
SG::auxid_t initBranch(bool standalone, const std::string &attr, TBranch *branch)
Definition: TBranchAuxDynReader.cxx:184
beamspotman.r
def r
Definition: beamspotman.py:676
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:71
TBranchAuxDynReader::BranchInfo::Initialized
@ Initialized
Definition: TBranchAuxDynReader.h:25
TBranchAuxDynReader::m_branchInfos
std::map< SG::auxid_t, BranchInfo > m_branchInfos
Definition: TBranchAuxDynReader.h:79
L1CaloPhase1Monitoring.standalone
standalone
Definition: L1CaloPhase1Monitoring.py:112
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:640
SG::normalizedTypeinfoName
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...
Definition: normalizedTypeinfoName.cxx:120
tree
TChain * tree
Definition: tile_monitor.h:30
TBranchAuxDynReader::init
void init(bool standalone)
Definition: TBranchAuxDynReader.cxx:229
skel.it
it
Definition: skel.GENtoEVGEN.py:396
TBranchAuxDynReader::m_bytesRead
size_t m_bytesRead
Definition: TBranchAuxDynReader.h:69
SG::AuxTypeRegistry::linkedName
static std::string linkedName(const std::string &name)
Given a variable name, return the name of the corresponding linked variable.
Definition: AuxTypeRegistry.cxx:1303
TBranchAuxDynReader::BranchInfo::NotFound
@ NotFound
Definition: TBranchAuxDynReader.h:25
RootAuxDynIO::auxBranchName
std::string auxBranchName(const std::string &attr_name, const std::string &baseBranchName)
Construct branch name for a given dynamic attribute.
Definition: RootAuxDynDefs.h:60
errorcheck::ReportMessage
Helper class to use to report a message.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:173
TBranchAuxDynReader::BranchInfo::NotInitialized
@ NotInitialized
Definition: TBranchAuxDynReader.h:25
SG::AuxTypeRegistry::classNameHasLink
static bool classNameHasLink(const std::string &className)
Test to see if a class name corresponds to a class with a linked variable.
Definition: AuxTypeRegistry.cxx:1313
TBranchAuxDynReader::m_storeHolderOffset
int m_storeHolderOffset
Definition: TBranchAuxDynReader.h:71
TBranchAuxDynReader::m_baseBranchName
std::string m_baseBranchName
Definition: TBranchAuxDynReader.h:67
TBranchAuxDynReader::BranchInfo::TypeError
@ TypeError
Definition: TBranchAuxDynReader.h:25
SG::AuxTypeRegistry
Handle mappings between names and auxid_t.
Definition: AuxTypeRegistry.h:61
JetTagCalibConfig.className
string className
Definition: JetTagCalibConfig.py:36
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
lumiFormat.i
int i
Definition: lumiFormat.py:85
CxxUtils::ConcurrentBitset::insert
ConcurrentBitset & insert(bit_t bit, bit_t new_nbits=0)
Set a bit to 1.
RootAuxDynIO::getKeyFromBranch
std::string getKeyFromBranch(TBranch *branch)
Exctract the Aux object SG Key from the branch name.
Definition: RootAuxDynIO.cxx:40
TBranchAuxDynReader::m_branchMap
std::map< std::string, TBranch * > m_branchMap
Definition: TBranchAuxDynReader.h:77
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
TBranchAuxDynReader::m_initialized
bool m_initialized
Definition: TBranchAuxDynReader.h:72
RTTAlgmain.branch
branch
Definition: RTTAlgmain.py:61
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TBranchAuxDynReader::m_key
std::string m_key
Definition: TBranchAuxDynReader.h:73
TBranchAuxDynStore
Definition: TBranchAuxDynStore.h:21
TBranchAuxDynReader::m_tree
TTree * m_tree
Definition: TBranchAuxDynReader.h:75
SG::IAuxStoreHolder::AST_ObjectStore
@ AST_ObjectStore
The store describes a single object.
Definition: IAuxStoreHolder.h:67
SG::IAuxStoreHolder
Interface for objects taking part in direct ROOT I/O.
Definition: IAuxStoreHolder.h:36
ERRORCHECK_ARGS
#define ERRORCHECK_ARGS
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:323
TBranchAuxDynReader::m_auxids
SG::auxid_set_t m_auxids
Definition: TBranchAuxDynReader.h:65
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7