ATLAS Offline Software
Loading...
Searching...
No Matches
RootAuxDynIO::TBranchAuxDynWriter Class Reference

#include <TBranchAuxDynWriter.h>

Inheritance diagram for RootAuxDynIO::TBranchAuxDynWriter:
Collaboration diagram for RootAuxDynIO::TBranchAuxDynWriter:

Public Member Functions

 TBranchAuxDynWriter (TTree &tree, TClass &cls, int bufferSize, int splitLevel, int offsettab_len, bool branch_fill)
virtual ~TBranchAuxDynWriter ()
virtual void setBranchFillMode (bool mode) override final
 set Filling mode (true/false) for branch containers
void createAuxBranch (AuxInfo &info)
void setBranchOffsetTabLen (TBranch *b, int offsettab_len)
virtual int writeAuxAttributes (const std::string &base_branchname, void *store, size_t backfill_nrows) override final
 handle writing of dynamic xAOD attributes of an object called from RootTreeContainer::writeObject()
virtual bool needsCommit () override final
 is there a need to call commit()?
virtual int commit () override final
 Call Fill() on the ROOT object used by this writer.
bool msgLvl (const MSG::Level lvl) const
 Test the output level.
MsgStream & msg () const
 The standard message stream.
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream.
void setLevel (MSG::Level lvl)
 Change the current logging level.
bool hasAuxDynStore () const

Protected Member Functions

int auxStoreOffset (TClass &tc)
SG::IAuxStoreIOcastIOStore (void *object)

Protected Attributes

TFile * m_tfile = nullptr
TTree * m_ttree = nullptr
int m_bufferSize = 8192
int m_splitLevel = 1
int m_branchOffsetTabLen = 0
bool m_branchFillMode = false
bool m_needsFill = false
std::map< SG::auxid_t, AuxInfom_auxInfoMap
 cached aux branches data by auxid
TClass & m_holderType
 TClass of the type containing the AuxStore with attributes.
int m_ioStoreOffset
 AuxStoreIO interface offset in the subclass type (for casting). negative means no inheritance.

Private Member Functions

void initMessaging () const
 Initialize our message level and MessageSvc.

Private Attributes

std::string m_nm
 Message source name.
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels)
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer.
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level.
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging)

Detailed Description

Definition at line 51 of file TBranchAuxDynWriter.h.

Constructor & Destructor Documentation

◆ TBranchAuxDynWriter()

RootAuxDynIO::TBranchAuxDynWriter::TBranchAuxDynWriter ( TTree & tree,
TClass & cls,
int bufferSize,
int splitLevel,
int offsettab_len,
bool branch_fill )

Definition at line 42 of file TBranchAuxDynWriter.cxx.

43 :
44 AthMessaging ("TBranchAuxDynWriter"), AuxDynAttrAccess(cls),
45 m_ttree( &tree ),
46 m_bufferSize( bufferSize ),
47 m_splitLevel( splitLevel ),
48 m_branchOffsetTabLen( offsettab_len ),
49 m_branchFillMode( branch_fill )
50 { }
AthMessaging()
Default constructor:
TChain * tree

◆ ~TBranchAuxDynWriter()

virtual RootAuxDynIO::TBranchAuxDynWriter::~TBranchAuxDynWriter ( )
inlinevirtual

Definition at line 55 of file TBranchAuxDynWriter.h.

55{ }

Member Function Documentation

◆ auxStoreOffset()

int RootAuxDynIO::AuxDynAttrAccess::auxStoreOffset ( TClass & tc)
protectedinherited

Definition at line 29 of file RootAuxDynIO.cxx.

30 {
31 TClass *storeTClass = tc.GetBaseClass("SG::IAuxStoreIO");
32 if( storeTClass ) {
33 // This is a class implementing SG::IAuxStoreIO
34 // Find IAuxStoreIO interface offset
35 return tc.GetBaseClassOffset( storeTClass );
36 }
37 return -1;
38 }
static Double_t tc

◆ castIOStore()

SG::IAuxStoreIO * RootAuxDynIO::AuxDynAttrAccess::castIOStore ( void * object)
protectedinherited

Definition at line 45 of file RootAuxDynIO.cxx.

45 {
46 return ( hasAuxDynStore()?
47 reinterpret_cast<SG::IAuxStoreIO*>( (char*)object + m_ioStoreOffset )
48 : nullptr);
49 }
int m_ioStoreOffset
AuxStoreIO interface offset in the subclass type (for casting). negative means no inheritance.

◆ commit()

int RootAuxDynIO::TBranchAuxDynWriter::commit ( )
finaloverridevirtual

Call Fill() on the ROOT object used by this writer.

Implements RootAuxDynIO::IRootAuxDynWriter.

Definition at line 193 of file TBranchAuxDynWriter.cxx.

193 {
194 ATH_MSG_WARNING("Commit for TBranchAuxDynWriter should be handled on the DB level");
195 return 0;
196 }
#define ATH_MSG_WARNING(x)

◆ createAuxBranch()

void RootAuxDynIO::TBranchAuxDynWriter::createAuxBranch ( AuxInfo & info)

Definition at line 68 of file TBranchAuxDynWriter.cxx.

68 {
69 std::string error_type("is unknown");
70 const std::type_info& ti = *info.typeinfo;
71 try {
72 auto createBasicAuxBranch = [&](const char* typeopt) {
73 info.is_basic_type = true;
74 info.branch = m_ttree->Branch(info.branch_name.c_str(), info.buffer, (info.name+typeopt).c_str(), 2048);
75 ATH_MSG_VERBOSE("Created branch with name=" << info.branch_name << " type: " << info.name+typeopt);
76 };
77 if ( ti == typeid(UInt_t) ) createBasicAuxBranch("/i");
78 else if( ti == typeid(Int_t) ) createBasicAuxBranch("/I");
79 else if( ti == typeid(Double_t) ) createBasicAuxBranch("/D");
80 else if( ti == typeid(Float_t) ) createBasicAuxBranch("/F");
81 else if( ti == typeid(Long64_t) or ti == typeid(std::int64_t) ) createBasicAuxBranch("/L");
82 else if( ti == typeid(ULong64_t) or ti == typeid(std::uint64_t) ) createBasicAuxBranch("/l");
83 else if( ti == typeid(Short_t) ) createBasicAuxBranch("/S");
84 else if( ti == typeid(UShort_t) ) createBasicAuxBranch("/s");
85 else if( ti == typeid(Char_t) ) createBasicAuxBranch("/B");
86 else if( ti == typeid(UChar_t) ) createBasicAuxBranch("/b");
87 else if( ti == typeid(bool) ) createBasicAuxBranch("/O");
88 else if( ti == typeid(char*) || ti == typeid(unsigned char*) ) createBasicAuxBranch("/C");
89 else {
90 TClass* cl = TClass::GetClass(info.type_name.c_str());
91 if( !cl ) {
92 error_type =" has no TClass";
93 } else if( !cl->GetStreamerInfo() ) {
94 error_type =" has no streamer";
95 } else if( !cl->HasDictionary() ) {
96 error_type =" has no dictionary";
97 } else {
98 info.tclass = cl;
99 int split = cl->CanSplit() ? m_splitLevel : 0;
100 info.branch = m_ttree->Branch( info.branch_name.c_str(), // Branch name
101 cl->GetName(), // Object class
102 (void*)&info.buffer, // Object address
103 m_bufferSize, // Buffer size
104 split); // Split Mode (Levels)
105 ATH_MSG_VERBOSE("Created branch with name=" << info.branch_name << " type: " << cl->GetName());
106 }
107 }
108 } catch( const std::exception& e ) {
109 error_type += std::string(" Exception msg: ") + e.what();
110 }
111 catch (...) {
112 error_type += " Unknown exception.";
113 }
114
115 if( !info.branch ) {
116 throw std::runtime_error( std::string("Failed to create Auxiliary branch '") + info.branch_name
117 + "'. Class: " + info.type_name + error_type );
118 }
119 // Set AUTO-DELETE OFF. ROOT will not delete objects created by the framework
120 info.branch->SetAutoDelete(kFALSE);
121
123 }
#define ATH_MSG_VERBOSE(x)
void setBranchOffsetTabLen(TBranch *b, int offsettab_len)
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]

◆ hasAuxDynStore()

bool RootAuxDynIO::AuxDynAttrAccess::hasAuxDynStore ( ) const
inherited

Definition at line 40 of file RootAuxDynIO.cxx.

41 {
42 return m_ioStoreOffset >= 0;
43 }

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40{
42 // If user did not set an explicit level, set a default
43 if (m_lvl == MSG::NIL) {
44 m_lvl = m_imsg ?
45 static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
46 MSG::INFO;
47 }
48}
std::string m_nm
Message source name.
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
std::atomic< MSG::Level > m_lvl
Current logging level.
IMessageSvc * getMessageSvc(bool quiet=false)

◆ msg() [1/2]

MsgStream & AthMessaging::msg ( ) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 163 of file AthMessaging.h.

164{
165 MsgStream* ms = m_msg_tls.get();
166 if (!ms) {
167 if (!m_initialized.test_and_set()) initMessaging();
168 ms = new MsgStream(m_imsg,m_nm);
169 m_msg_tls.reset( ms );
170 }
171
172 ms->setLevel (m_lvl);
173 return *ms;
174}
boost::thread_specific_ptr< MsgStream > m_msg_tls
MsgStream instance (a std::cout like with print-out levels)
void initMessaging() const
Initialize our message level and MessageSvc.

◆ msg() [2/2]

MsgStream & AthMessaging::msg ( const MSG::Level lvl) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 178 of file AthMessaging.h.

179{ return msg() << lvl; }
MsgStream & msg() const
The standard message stream.

◆ msgLvl()

bool AthMessaging::msgLvl ( const MSG::Level lvl) const
inlineinherited

Test the output level.

Parameters
lvlThe message level to test against
Returns
boolean Indicating if messages at given level will be printed
Return values
trueMessages at level "lvl" will be printed

Definition at line 151 of file AthMessaging.h.

152{
153 if (m_lvl <= lvl) {
154 msg() << lvl;
155 return true;
156 } else {
157 return false;
158 }
159}

◆ needsCommit()

virtual bool RootAuxDynIO::TBranchAuxDynWriter::needsCommit ( )
inlinefinaloverridevirtual

is there a need to call commit()?

Implements RootAuxDynIO::IRootAuxDynWriter.

Definition at line 72 of file TBranchAuxDynWriter.h.

◆ setBranchFillMode()

virtual void RootAuxDynIO::TBranchAuxDynWriter::setBranchFillMode ( bool mode)
inlinefinaloverridevirtual

set Filling mode (true/false) for branch containers

Implements RootAuxDynIO::IRootAuxDynWriter.

Definition at line 58 of file TBranchAuxDynWriter.h.

◆ setBranchOffsetTabLen()

void RootAuxDynIO::TBranchAuxDynWriter::setBranchOffsetTabLen ( TBranch * b,
int offsettab_len )

Definition at line 54 of file TBranchAuxDynWriter.cxx.

54 {
55 if( offsettab_len > 0 ) {
56 if( b->GetEntryOffsetLen() > 0 )
57 b->SetEntryOffsetLen( offsettab_len );
58 TIter biter( b->GetListOfBranches() );
59 TBranch* subbranch(nullptr);
60 while( (subbranch = (TBranch*)biter.Next()) ) {
61 setBranchOffsetTabLen( subbranch, offsettab_len );
62 }
63 }
64 }

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29{
30 m_lvl = lvl;
31}

◆ writeAuxAttributes()

int RootAuxDynIO::TBranchAuxDynWriter::writeAuxAttributes ( const std::string & base_branchname,
void * store,
size_t backfill_nrows )
finaloverridevirtual

handle writing of dynamic xAOD attributes of an object called from RootTreeContainer::writeObject()

handle writing of dynamic xAOD attributes of an object - called from RootTreeContainer::writeObject()

Implements RootAuxDynIO::IRootAuxDynWriter.

Definition at line 128 of file TBranchAuxDynWriter.cxx.

131 {
132 SG::IAuxStoreIO *store = castIOStore(object);
133 int bytes_written = 0;
134 const SG::auxid_set_t selection = store->getSelectedAuxIDs();
135 ATH_MSG_DEBUG("Writing " << base_branchname << " with " << selection.size() << " Dynamic attributes");
136
137 // mark all attributes as not written yet
138 for( auto& aux_info_entry : m_auxInfoMap ) aux_info_entry.second.written = false;
139 m_needsFill = false;
140
141 for(SG::auxid_t id : selection) {
142 AuxInfo& attrInfo = m_auxInfoMap[id];
143 if( !attrInfo.branch ) {
144 // new attribute info, fill it
145 attrInfo.typeinfo = store->getIOType(id);
146 attrInfo.type_name = SG::normalizedTypeinfoName( *attrInfo.typeinfo );
147 attrInfo.name = SG::AuxTypeRegistry::instance().getName(id);
148 attrInfo.branch_name = RootAuxDynIO::auxBranchName(attrInfo.name, base_branchname);
149
150 ATH_MSG_DEBUG("Creating branch for new dynamic attribute, Id=" << id << ": type=" << attrInfo.type_name
151 << ", branch=" << attrInfo.branch_name );
152 createAuxBranch( attrInfo );
153 // backfill here
154 if( backfill_nrows ) {
155 // if this is not the first row, catch up with the rows written already to other branches
156 ATH_MSG_DEBUG(" Backfilling " << backfill_nrows << " entries for " << attrInfo.name);
157 // As of root 6.22, calling SetAddress with nullptr may not work as expected if the address had
158 // previously been set to something non-null.
159 // So we need to create the temp object ourselves.
160 attrInfo.setDummyAddr();
161 for( size_t r=0; r<backfill_nrows; ++r ) {
162 bytes_written += attrInfo.branch->BackFill();
163 ATH_MSG_VERBOSE("BACKFilled branch:" << m_ttree->GetName() << "::" << attrInfo.branch->GetName() <<
164 " Tree size=" << m_ttree->GetEntries()
165 << " branch size:" << attrInfo.branch->GetEntries() );
166 }
167 }
168 }
169 void *obj ATLAS_THREAD_SAFE = const_cast<void*>( store->getIOData(id) );
170 attrInfo.object = obj;
171 attrInfo.branch->SetAddress( attrInfo.objectAddr() );
172 attrInfo.written = true;
173 }
174
175 for( auto& aux_info_entry : m_auxInfoMap ) {
176 AuxInfo& attrInfo = aux_info_entry.second;
177 // if an attribute was not written create a default object for it
178 if( !attrInfo.written ) {
179 attrInfo.setDummyAddr();
180 ATH_MSG_DEBUG("Default object added to branch: " << attrInfo.branch_name);
181 }
182 // if writing to branches independently, do it now
183 if( m_branchFillMode ) {
184 bytes_written += attrInfo.branch->Fill();
185 } else {
186 m_needsFill = true;
187 }
188 }
189 return bytes_written;
190 }
#define ATH_MSG_DEBUG(x)
std::atomic_flag m_initialized ATLAS_THREAD_SAFE
Messaging initialized (initMessaging)
SG::IAuxStoreIO * castIOStore(void *object)
std::map< SG::auxid_t, AuxInfo > m_auxInfoMap
cached aux branches data by auxid
std::string getName(SG::auxid_t auxid) const
Return the name of an aux data item.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
const std::string selection
int r
Definition globals.cxx:22
std::string auxBranchName(const std::string &attr_name, const std::string &baseBranchName)
Construct branch name for a given dynamic attribute.
TestStore store
Definition TestStore.cxx:23
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...
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
mutableprivateinherited

Messaging initialized (initMessaging)

Definition at line 141 of file AthMessaging.h.

◆ m_auxInfoMap

std::map<SG::auxid_t, AuxInfo> RootAuxDynIO::TBranchAuxDynWriter::m_auxInfoMap
protected

cached aux branches data by auxid

Definition at line 86 of file TBranchAuxDynWriter.h.

◆ m_branchFillMode

bool RootAuxDynIO::TBranchAuxDynWriter::m_branchFillMode = false
protected

Definition at line 82 of file TBranchAuxDynWriter.h.

◆ m_branchOffsetTabLen

int RootAuxDynIO::TBranchAuxDynWriter::m_branchOffsetTabLen = 0
protected

Definition at line 81 of file TBranchAuxDynWriter.h.

◆ m_bufferSize

int RootAuxDynIO::TBranchAuxDynWriter::m_bufferSize = 8192
protected

Definition at line 79 of file TBranchAuxDynWriter.h.

◆ m_holderType

TClass& RootAuxDynIO::AuxDynAttrAccess::m_holderType
protectedinherited

TClass of the type containing the AuxStore with attributes.

Definition at line 30 of file RootAuxDynIO.h.

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

135{ nullptr };

◆ m_ioStoreOffset

int RootAuxDynIO::AuxDynAttrAccess::m_ioStoreOffset
protectedinherited

AuxStoreIO interface offset in the subclass type (for casting). negative means no inheritance.

Definition at line 32 of file RootAuxDynIO.h.

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivateinherited

Current logging level.

Definition at line 138 of file AthMessaging.h.

138{ MSG::NIL };

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivateinherited

MsgStream instance (a std::cout like with print-out levels)

Definition at line 132 of file AthMessaging.h.

◆ m_needsFill

bool RootAuxDynIO::TBranchAuxDynWriter::m_needsFill = false
protected

Definition at line 83 of file TBranchAuxDynWriter.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.

◆ m_splitLevel

int RootAuxDynIO::TBranchAuxDynWriter::m_splitLevel = 1
protected

Definition at line 80 of file TBranchAuxDynWriter.h.

◆ m_tfile

TFile* RootAuxDynIO::TBranchAuxDynWriter::m_tfile = nullptr
protected

Definition at line 77 of file TBranchAuxDynWriter.h.

◆ m_ttree

TTree* RootAuxDynIO::TBranchAuxDynWriter::m_ttree = nullptr
protected

Definition at line 78 of file TBranchAuxDynWriter.h.


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