ATLAS Offline Software
Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
RootAuxDynIO::TBranchAuxDynWriter Class Reference

#include <TBranchAuxDynWriter.h>

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

Public Member Functions

 TBranchAuxDynWriter (TTree *tree, 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 More...
 
void createAuxBranch (AuxInfo &info)
 
void setBranchOffsetTabLen (TBranch *b, int offsettab_len)
 
virtual int writeAuxAttributes (const std::string &base_branchname, SG::IAuxStoreIO *store, size_t backfill_nrows) override final
 handle writing of dynamic xAOD attributes of an object called from RootTreeContainer::writeObject() More...
 
virtual bool needsCommit () override final
 is there a need to call commit()? More...
 
virtual int commit () override final
 Call Fill() on the ROOT object used by this writer. More...
 
bool msgLvl (const MSG::Level lvl) const
 Test the output level. More...
 
MsgStream & msg () const
 The standard message stream. More...
 
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream. More...
 
void setLevel (MSG::Level lvl)
 Change the current logging level. More...
 

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 More...
 

Private Member Functions

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

Private Attributes

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

Detailed Description

Definition at line 50 of file TBranchAuxDynWriter.h.

Constructor & Destructor Documentation

◆ TBranchAuxDynWriter()

RootAuxDynIO::TBranchAuxDynWriter::TBranchAuxDynWriter ( TTree *  tree,
int  bufferSize,
int  splitLevel,
int  offsettab_len,
bool  branch_fill 
)

Definition at line 42 of file TBranchAuxDynWriter.cxx.

42  :
43  AthMessaging ("TBranchAuxDynWriter"),
44  m_ttree( tree ),
45  m_bufferSize( bufferSize ),
46  m_splitLevel( splitLevel ),
47  m_branchOffsetTabLen( offsettab_len ),
48  m_branchFillMode( branch_fill )
49  { }

◆ ~TBranchAuxDynWriter()

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

Definition at line 54 of file TBranchAuxDynWriter.h.

54 { }

Member Function Documentation

◆ commit()

int RootAuxDynIO::TBranchAuxDynWriter::commit ( )
finaloverridevirtual

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

Implements RootAuxDynIO::IRootAuxDynWriter.

Definition at line 203 of file TBranchAuxDynWriter.cxx.

203  {
204  ATH_MSG_WARNING("Commit for TBranchAuxDynWriter should be handled on the DB level");
205  return 0;
206  }

◆ createAuxBranch()

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

Definition at line 67 of file TBranchAuxDynWriter.cxx.

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

◆ 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  m_lvl = m_imsg ?
43  static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
44  MSG::INFO;
45 }

◆ 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 164 of file AthMessaging.h.

165 {
166  MsgStream* ms = m_msg_tls.get();
167  if (!ms) {
168  if (!m_initialized.test_and_set()) initMessaging();
169  ms = new MsgStream(m_imsg,m_nm);
170  m_msg_tls.reset( ms );
171  }
172 
173  ms->setLevel (m_lvl);
174  return *ms;
175 }

◆ 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 179 of file AthMessaging.h.

180 { return msg() << lvl; }

◆ 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_initialized.test_and_set()) initMessaging();
154  if (m_lvl <= lvl) {
155  msg() << lvl;
156  return true;
157  } else {
158  return false;
159  }
160 }

◆ needsCommit()

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

is there a need to call commit()?

Implements RootAuxDynIO::IRootAuxDynWriter.

Definition at line 71 of file TBranchAuxDynWriter.h.

71 { return m_needsFill; }

◆ setBranchFillMode()

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

set Filling mode (true/false) for branch containers

Implements RootAuxDynIO::IRootAuxDynWriter.

Definition at line 57 of file TBranchAuxDynWriter.h.

◆ setBranchOffsetTabLen()

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

Definition at line 53 of file TBranchAuxDynWriter.cxx.

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

◆ 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,
SG::IAuxStoreIO 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 127 of file TBranchAuxDynWriter.cxx.

130  {
131  int bytes_written = 0;
132  const SG::auxid_set_t selection = store->getSelectedAuxIDs();
133  ATH_MSG_DEBUG("Writing " << base_branchname << " with " << selection.size() << " Dynamic attributes");
134 
135  // mark all attributes as not written yet
136  for( auto& aux_info_entry : m_auxInfoMap ) aux_info_entry.second.written = false;
137  m_needsFill = false;
138 
139  for(SG::auxid_t id : selection) {
140  AuxInfo& attrInfo = m_auxInfoMap[id];
141  if( !attrInfo.branch ) {
142  // new attribute info, fill it
143  attrInfo.typeinfo = store->getIOType(id);
144  attrInfo.type_name = SG::normalizedTypeinfoName( *attrInfo.typeinfo );
145  attrInfo.name = SG::AuxTypeRegistry::instance().getName(id);
146  attrInfo.branch_name = RootAuxDynIO::auxBranchName(attrInfo.name, base_branchname);
147  /*
148  // MN: this part can be used to reject late attribs and not do backfilling, to be compatible with current RNTuple behavior
149  static std::set<std::string> bad_branches;
150  std::string bnam = attrInfo.branch_name + ":" + attrInfo.name;
151  if( bad_branches.count(bnam) > 0 ) continue;
152  if( backfill_nrows ) {
153  bad_branches.insert(bnam);
154  if(mn) cout << "MN: ignoring late attribute: " << bnam << " type: " << attrInfo.type_name<< endl;
155  continue;
156  }
157  */
158  ATH_MSG_DEBUG("Creating branch for new dynamic attribute, Id=" << id << ": type=" << attrInfo.type_name << ", branch=" << attrInfo.branch_name );
159  createAuxBranch( attrInfo );
160  // backfill here
161  if( backfill_nrows ) {
162  // if this is not the first row, catch up with the rows written already to other branches
163  ATH_MSG_DEBUG(" Backfilling " << backfill_nrows << " entries for " << attrInfo.name);
164  // As of root 6.22, calling SetAddress with nullptr may not work as expected if the address had
165  // previously been set to something non-null.
166  // So we need to create the temp object ourselves.
167  attrInfo.setDummyAddr();
168  for( size_t r=0; r<backfill_nrows; ++r ) {
169  bytes_written += attrInfo.branch->BackFill();
170  ATH_MSG_VERBOSE("BACKFilled branch:" << m_ttree->GetName() << "::" << attrInfo.branch->GetName() <<
171  " Tree size=" << m_ttree->GetEntries()
172  << " branch size:" << attrInfo.branch->GetEntries() );
173  }
174  }
175  }
176  void *obj ATLAS_THREAD_SAFE = const_cast<void*>( store->getIOData(id) );
177  attrInfo.object = obj;
178  attrInfo.branch->SetAddress( attrInfo.objectAddr() );
179  attrInfo.written = true;
180  }
181 
182  for( auto& aux_info_entry : m_auxInfoMap ) {
183  AuxInfo& attrInfo = aux_info_entry.second;
184  // cout << "MN: AuxInfo loop: branch name=" << attrInfo.branch_name << " branch addr=" << attrInfo.branch<< endl;
185  // if an attribute was not written create a default object for it
186  if( !attrInfo.written ) {
187  attrInfo.setDummyAddr();
188  ATH_MSG_DEBUG("Default object added to branch: " << attrInfo.branch_name);
189  // cout << "Default object added to branch: " << attrInfo.branch_name << " Tree size=" << m_ttree->GetEntries() << " branch size:" << attrInfo.branch->GetEntries() << endl;
190  }
191  // if writing to branches independently, do it now
192  if( m_branchFillMode ) {
193  // cout << "MN: BranchFill for " << attrInfo.branch_name << endl;
194  bytes_written += attrInfo.branch->Fill();
195  } else {
196  m_needsFill = true;
197  }
198  }
199  return bytes_written;
200  }

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 85 of file TBranchAuxDynWriter.h.

◆ m_branchFillMode

bool RootAuxDynIO::TBranchAuxDynWriter::m_branchFillMode = false
protected

Definition at line 81 of file TBranchAuxDynWriter.h.

◆ m_branchOffsetTabLen

int RootAuxDynIO::TBranchAuxDynWriter::m_branchOffsetTabLen = 0
protected

Definition at line 80 of file TBranchAuxDynWriter.h.

◆ m_bufferSize

int RootAuxDynIO::TBranchAuxDynWriter::m_bufferSize = 8192
protected

Definition at line 78 of file TBranchAuxDynWriter.h.

◆ m_imsg

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

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

◆ m_lvl

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

Current logging level.

Definition at line 138 of file AthMessaging.h.

◆ 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 82 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 79 of file TBranchAuxDynWriter.h.

◆ m_tfile

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

Definition at line 76 of file TBranchAuxDynWriter.h.

◆ m_ttree

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

Definition at line 77 of file TBranchAuxDynWriter.h.


The documentation for this class was generated from the following files:
grepfile.info
info
Definition: grepfile.py:38
AthMessaging::m_lvl
std::atomic< MSG::Level > m_lvl
Current logging level.
Definition: AthMessaging.h:138
beamspotman.r
def r
Definition: beamspotman.py:676
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
RootAuxDynIO::TBranchAuxDynWriter::createAuxBranch
void createAuxBranch(AuxInfo &info)
Definition: TBranchAuxDynWriter.cxx:67
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:49
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
RootAuxDynIO::TBranchAuxDynWriter::m_ttree
TTree * m_ttree
Definition: TBranchAuxDynWriter.h:77
SG::AuxTypeRegistry::getName
std::string getName(SG::auxid_t auxid) const
Return the name of an aux data item.
Definition: AuxTypeRegistry.cxx:277
tree
TChain * tree
Definition: tile_monitor.h:30
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
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:46
AthMessaging::m_imsg
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
Definition: AthMessaging.h:135
python.SystemOfUnits.ms
int ms
Definition: SystemOfUnits.py:132
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
RootAuxDynIO::TBranchAuxDynWriter::setBranchOffsetTabLen
void setBranchOffsetTabLen(TBranch *b, int offsettab_len)
Definition: TBranchAuxDynWriter.cxx:53
AthMessaging::ATLAS_THREAD_SAFE
std::atomic_flag m_initialized ATLAS_THREAD_SAFE
Messaging initialized (initMessaging)
Definition: AthMessaging.h:141
AthMessaging::AthMessaging
AthMessaging()
Default constructor:
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
RootAuxDynIO::TBranchAuxDynWriter::m_branchFillMode
bool m_branchFillMode
Definition: TBranchAuxDynWriter.h:81
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
calibdata.exception
exception
Definition: calibdata.py:496
RootAuxDynIO::TBranchAuxDynWriter::m_needsFill
bool m_needsFill
Definition: TBranchAuxDynWriter.h:82
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
Preparation.mode
mode
Definition: Preparation.py:95
selection
std::string selection
Definition: fbtTestBasics.cxx:73
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:194
RootAuxDynIO::TBranchAuxDynWriter::m_splitLevel
int m_splitLevel
Definition: TBranchAuxDynWriter.h:79
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
AthMessaging::m_nm
std::string m_nm
Message source name.
Definition: AthMessaging.h:129
SG::auxid_set_t
A set of aux data identifiers.
Definition: AuxTypes.h:47
AthMessaging::initMessaging
void initMessaging() const
Initialize our message level and MessageSvc.
Definition: AthMessaging.cxx:39
AthMessaging::m_msg_tls
boost::thread_specific_ptr< MsgStream > m_msg_tls
MsgStream instance (a std::cout like with print-out levels)
Definition: AthMessaging.h:132
python.PyAthena.obj
obj
Definition: PyAthena.py:135
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
RootAuxDynIO::TBranchAuxDynWriter::m_auxInfoMap
std::map< SG::auxid_t, AuxInfo > m_auxInfoMap
cached aux branches data by auxid
Definition: TBranchAuxDynWriter.h:85
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
RootAuxDynIO::TBranchAuxDynWriter::m_bufferSize
int m_bufferSize
Definition: TBranchAuxDynWriter.h:78
RootAuxDynIO::TBranchAuxDynWriter::m_branchOffsetTabLen
int m_branchOffsetTabLen
Definition: TBranchAuxDynWriter.h:80