ATLAS Offline Software
Loading...
Searching...
No Matches
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.
BranchInfogetBranchInfo (const SG::auxid_t &auxid, const SG::AuxStoreInternal &store)
virtual ~TBranchAuxDynReader ()=default
const SG::auxid_set_tauxIDs () const
 Aux IDs of all the Aux attributes belonging to the Aux container being read.
bool addAuxID (const SG::auxid_t &id)
void addBytes (size_t bytes)
size_t getBytesRead () const
void resetBytesRead ()

Protected Attributes

std::string m_baseBranchName
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
SG::auxid_set_t m_auxids
size_t m_bytesRead = 0

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 171 of file TBranchAuxDynReader.cxx.

172 : m_baseBranchName( base_branch->GetName() ),
173 m_key( getKeyFromBranch(base_branch) ),
174 m_tree( tree )
175{
176 // The Branch here is the object (AuxContainer) branch, not the attribute branch
177 TClass *tc = nullptr, *storeTC = nullptr;
178 EDataType type;
179 (void)base_branch->GetExpectedType(tc, type); //MN: Errors would be caught in isAuxDynBranch() earlier
180 if( tc ) storeTC = tc->GetBaseClass("SG::IAuxStoreHolder");
181 if( storeTC ) m_storeHolderOffset = tc->GetBaseClassOffset( storeTC );
182 if( m_storeHolderOffset < 0 ) {
183 const std::string name = (tc? tc->GetName() : m_baseBranchName);
184 errorcheck::ReportMessage msg (MSG::INFO, ERRORCHECK_ARGS, "TBranchAuxDynReader");
185 msg << "IAuxStoreHolder interface not found in " << name << " - will not read dynamic attributes";
186 }
187
188 const SG::AuxTypeRegistry& r = SG::AuxTypeRegistry::instance();
189 string branch_prefix = RootAuxDynIO::auxBranchName("", m_baseBranchName);
190 TObjArray *all_branches = m_tree->GetListOfBranches();
191 for( int i=0; i<all_branches->GetEntriesFast(); i++ ) {
192 const char *bname = (*all_branches)[i]->GetName();
193 if( strncmp(bname, branch_prefix.c_str(), branch_prefix.size()) == 0 ) {
194 const string attr_inFile = bname+branch_prefix.size();
195 const string attr = r.inputRename (m_key, attr_inFile);
196 m_branchMap[attr] = (TBranch*)(*all_branches)[i];
197 }
198 }
199}
static Double_t tc
static AuxTypeRegistry & instance()
Return the singleton registry instance.
std::map< std::string, TBranch * > m_branchMap
int r
Definition globals.cxx:22
std::string getKeyFromBranch(TBranch *branch)
Exctract the Aux object SG Key from the branch name.
std::string auxBranchName(const std::string &attr_name, const std::string &baseBranchName)
Construct branch name for a given dynamic attribute.
MsgStream & msg
Definition testRead.cxx:32
TChain * tree

◆ ~TBranchAuxDynReader()

virtual TBranchAuxDynReader::~TBranchAuxDynReader ( )
virtualdefault

Member Function Documentation

◆ addAuxID()

bool RootAuxDynReader::addAuxID ( const SG::auxid_t & id)
inlineinherited

Definition at line 60 of file RootAuxDynReader.h.

60 {
61 if( id != SG::null_auxid ) {
62 m_auxids.insert(id);
63 return true;
64 }
65 return false;
66}
SG::auxid_set_t m_auxids
static const auxid_t null_auxid
To signal no aux data item.
Definition AuxTypes.h:30

◆ addBytes()

void RootAuxDynReader::addBytes ( size_t bytes)
inlineinherited

Definition at line 40 of file RootAuxDynReader.h.

40 {
41 m_bytesRead += bytes;
42}

◆ 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_row

Use 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 349 of file TBranchAuxDynReader.cxx.

350{
351 if( m_storeHolderOffset >= 0 ) {
352 auto store_holder = reinterpret_cast<SG::IAuxStoreHolder*>((char*)object + m_storeHolderOffset);
353 bool standalone { store_holder->getStoreType()==SG::IAuxStoreHolder::AST_ObjectStore };
354 if( !m_initialized )
355 init(standalone);
356 store_holder->setStore( new TBranchAuxDynStore(*this, ttree_row, standalone, iomtx) );
357 }
358}
@ AST_ObjectStore
The store describes a single object.
void init(bool standalone)

◆ auxIDs()

const SG::auxid_set_t & RootAuxDynReader::auxIDs ( ) const
inlineinherited

Aux IDs of all the Aux attributes belonging to the Aux container being read.

Definition at line 55 of file RootAuxDynReader.h.

55 {
56 return m_auxids;
57}

◆ getBranchInfo()

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

Definition at line 260 of file TBranchAuxDynReader.cxx.

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

◆ getBytesRead()

size_t RootAuxDynReader::getBytesRead ( ) const
inlinevirtualinherited

Implements RootAuxDynIO::IRootAuxDynReader.

Definition at line 45 of file RootAuxDynReader.h.

45 {
46 return m_bytesRead;
47}

◆ init()

void TBranchAuxDynReader::init ( bool standalone)

Definition at line 247 of file TBranchAuxDynReader.cxx.

248{
249 if( m_initialized ) return;
250
251 for( const auto& attr2branch: m_branchMap ) {
252 initBranch (standalone, attr2branch.first, attr2branch.second);
253 }
254 m_initialized = true;
255}
SG::auxid_t initBranch(bool standalone, const std::string &attr, TBranch *branch)

◆ initBranch()

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

Definition at line 202 of file TBranchAuxDynReader.cxx.

205{
206 TClass* expectedClass = 0;
207 EDataType expectedType = kOther_t;
208 if( branch->GetExpectedType(expectedClass, expectedType) != 0) {
209 // raise hell
210 }
211
212 SG::auxid_t linked_auxid = SG::null_auxid;
213 if (expectedClass) {
214 std::string className = expectedClass->GetName();
216 std::string linkedAttr = SG::AuxTypeRegistry::linkedName (attr);
217 auto it = m_branchMap.find (linkedAttr);
218 if (it != m_branchMap.end()) {
219 linked_auxid = initBranch (standalone, linkedAttr, it->second);
220 }
221 if (linked_auxid == SG::null_auxid) {
222 errorcheck::ReportMessage msg (MSG::WARNING, ERRORCHECK_ARGS, "TBranchAuxDynReader::initBranch");
223 msg << "Could not find linked variable for " << branch->GetName()
224 << " type: " << expectedClass->GetName();
225 }
226 }
227 }
228
229 SG::auxid_t auxid = getAuxIdForAttribute(attr, expectedClass, expectedType, standalone,
230 linked_auxid);
231
232 // add AuxID to the list
233 // May still be null if we don't have a dictionary for the branch.
234 if (auxid != SG::null_auxid) {
235 addAuxID(auxid);
236 } else {
237 errorcheck::ReportMessage msg (MSG::WARNING, ERRORCHECK_ARGS, "TBranchAuxDynReader::initBranch");
238 msg << "Could not find auxid for " << branch->GetName()
239 << " type: " << expectedClass->GetName();
240
241 }
242 return auxid;
243}
bool addAuxID(const SG::auxid_t &id)
static std::string linkedName(const std::string &name)
Given a variable name, return the name of the corresponding linked variable.
static bool classNameHasLink(const std::string &className)
Test to see if a class name corresponds to a class with a linked variable.
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27

◆ resetBytesRead()

void RootAuxDynReader::resetBytesRead ( )
inlinevirtualinherited

Implements RootAuxDynIO::IRootAuxDynReader.

Definition at line 50 of file RootAuxDynReader.h.

50 {
51 m_bytesRead = 0;
52}

Member Data Documentation

◆ m_auxids

SG::auxid_set_t RootAuxDynReader::m_auxids
protectedinherited

Definition at line 31 of file RootAuxDynReader.h.

◆ m_baseBranchName

std::string TBranchAuxDynReader::m_baseBranchName
protected

Definition at line 56 of file TBranchAuxDynReader.h.

◆ m_branchInfos

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

Definition at line 66 of file TBranchAuxDynReader.h.

◆ m_branchMap

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

Definition at line 64 of file TBranchAuxDynReader.h.

◆ m_bytesRead

size_t RootAuxDynReader::m_bytesRead = 0
protectedinherited

Definition at line 34 of file RootAuxDynReader.h.

◆ m_initialized

bool TBranchAuxDynReader::m_initialized = false
protected

Definition at line 59 of file TBranchAuxDynReader.h.

◆ m_key

std::string TBranchAuxDynReader::m_key
protected

Definition at line 60 of file TBranchAuxDynReader.h.

◆ m_storeHolderOffset

int TBranchAuxDynReader::m_storeHolderOffset = -1
protected

Definition at line 58 of file TBranchAuxDynReader.h.

◆ m_tree

TTree* TBranchAuxDynReader::m_tree = nullptr
protected

Definition at line 62 of file TBranchAuxDynReader.h.


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