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

#include <RNTupleAuxDynReader.h>

Inheritance diagram for RootAuxDynIO::RNTupleAuxDynReader:
Collaboration diagram for RootAuxDynIO::RNTupleAuxDynReader:

Classes

struct  FieldInfo

Public Member Functions

 RNTupleAuxDynReader (const std::string &field_name, const std::string &field_type, ROOT::RNTupleReader *reader)
 create Reader for Aux attributes of an AuxContainer object stored in a given field
void init (bool standalone)
 initialize once the mode of the Aux store is known
virtual void addReaderToObject (void *object, size_t row, std::recursive_mutex *iomtx=nullptr) override final
 attach RNTupleAuxStore to the current Aux container @object
FieldInfogetFieldInfo (const SG::auxid_t &auxid, const SG::AuxStoreInternal &store)
 get field informatino for auxid
ROOT::RNTupleReader * getNativeReader ()
virtual ~RNTupleAuxDynReader ()=default
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.
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_storeFieldName
int m_storeHolderOffset = -1
bool m_initialized = false
std::string m_key
std::map< SG::auxid_t, FieldInfom_fieldInfos
ROOT::RNTupleReader * m_ntupleReader
SG::auxid_set_t m_auxids
size_t m_bytesRead = 0

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 22 of file RNTupleAuxDynReader.h.

Constructor & Destructor Documentation

◆ RNTupleAuxDynReader()

RootAuxDynIO::RNTupleAuxDynReader::RNTupleAuxDynReader ( const std::string & field_name,
const std::string & field_type,
ROOT::RNTupleReader * reader )

create Reader for Aux attributes of an AuxContainer object stored in a given field

Definition at line 152 of file RNTupleAuxDynReader.cxx.

155 : AthMessaging( std::string("RNTupleAuxDynReader[")+field_name+"]" ),
156 m_storeFieldName( field_name ),
157 m_ntupleReader( reader )
158 {
159 const std::string field_prefix = field_type + "_";
160 if( m_storeFieldName.rfind( field_type, 0 ) != std::string::npos ) {
161 m_key = m_storeFieldName.substr( field_type.size()+1 );
162 }
163 else if( m_storeFieldName.ends_with( "Aux:" ) ) {
164 m_key = m_storeFieldName.substr( 0, m_storeFieldName.size() - 4 );
165 }
166 ATH_MSG_VERBOSE("field name=" << m_storeFieldName << " field_prefix=" << field_prefix << " key=" << m_key);
167 TClass *tc = TClass::GetClass( field_type.c_str() );
168 if( tc ) {
169 TClass *storeTC = tc->GetBaseClass("SG::IAuxStoreHolder");
170 if( storeTC ) {
171 m_storeHolderOffset = tc->GetBaseClassOffset( storeTC );
172 } else {
173 throw std::runtime_error(string("Class ") + tc->GetName() +" does not implement SG::IAuxStoreHolder");
174 }
175 } else {
176 throw std::runtime_error(string("Class ") + field_type +" could not be found");
177 }
178 }
#define ATH_MSG_VERBOSE(x)
static Double_t tc
AthMessaging()
Default constructor:

◆ ~RNTupleAuxDynReader()

virtual RootAuxDynIO::RNTupleAuxDynReader::~RNTupleAuxDynReader ( )
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 RootAuxDynIO::RNTupleAuxDynReader::addReaderToObject ( void * object,
size_t row,
std::recursive_mutex * iomtx = nullptr )
finaloverridevirtual

attach RNTupleAuxStore to the current Aux container @object

Implements RootAuxDynIO::IRootAuxDynReader.

Definition at line 285 of file RNTupleAuxDynReader.cxx.

286 {
287 auto store_holder = reinterpret_cast<SG::IAuxStoreHolder*>((char*)object + m_storeHolderOffset);
288 bool standalone { store_holder->getStoreType()==SG::IAuxStoreHolder::AST_ObjectStore };
289 if( !m_initialized )
290 init(standalone);
291 store_holder->setStore( new RNTupleAuxDynStore(*this, row, standalone, iomtx) );
292 }
void init(bool standalone)
initialize once the mode of the Aux store is known
@ AST_ObjectStore
The store describes a single object.

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

◆ getBytesRead()

size_t RootAuxDynReader::getBytesRead ( ) const
inlinevirtualinherited

Implements RootAuxDynIO::IRootAuxDynReader.

Definition at line 45 of file RootAuxDynReader.h.

45 {
46 return m_bytesRead;
47}

◆ getFieldInfo()

RNTupleAuxDynReader::FieldInfo & RootAuxDynIO::RNTupleAuxDynReader::getFieldInfo ( const SG::auxid_t & auxid,
const SG::AuxStoreInternal & store )

get field informatino for auxid

Definition at line 220 of file RNTupleAuxDynReader.cxx.

221 {
222 FieldInfo& fieldInfo = m_fieldInfos[auxid];
223 if( fieldInfo.status == FieldInfo::NotInitialized )
224 {
225 SG::AuxTypeRegistry& reg = SG::AuxTypeRegistry::instance();
226 fieldInfo.auxid = auxid;
227 fieldInfo.attribName = reg.getName(auxid);
228 // Don't match this attribute if it's been renamed.
229 // For example, suppose we've renamed attribute `foo' to `foo_old',
230 // and someone then comes and asks for `foo'.
231 // `foo' will not be found in the m_fieldMap test below
232 // (`foo_old' will be in this map). However, in the following
233 // else clause, we'll recreate the field name from `foo'.
234 // This field exists (renaming is only in the transient store),
235 // so if we didn't have the condition here, then we'd then
236 // make a `foo' attribute from that field.
237 if( reg.inputRename(m_key, fieldInfo.attribName) != fieldInfo.attribName ) {
238 fieldInfo.status = FieldInfo::NotFound;
239 return fieldInfo;
240 }
241
242 if( fieldInfo.fieldName.empty() ) {
243 // mark initialized here so it remembers this field was not found
244 fieldInfo.status = FieldInfo::NotFound;
245 return fieldInfo;
246 }
247
248 if( !store.standalone() and fieldInfo.fieldName.rfind("SG::PackedContainer<", 0) == 0 )
249 fieldInfo.isPackedContainer = true;
250
251 /*
252 string elem_tname, branch_tname;
253 const type_info* ti = getAuxElementType( fieldInfo.tclass, typ, store.standalone(),
254 elem_tname, branch_tname );
255 const type_info* reg_ti = reg.getType(auxid);
256 if( ti && ti != reg_ti && strcmp(ti->name(), reg_ti->name()) != 0 )
257 {
258 // type in registry is different than type in the file.
259 // will need to use ROOT auto schema evolution
260 fieldInfo.needsSE = true;
261 errorcheck::ReportMessage msg (MSG::INFO, ERRORCHECK_ARGS, "RNTupleAuxDynReader");
262 msg << "attribute " << fieldInfo.attribName << " (id=" << auxid <<
263 " typename=" << SG::AuxTypeRegistry::instance().getType(auxid)->name()
264 << ") has different type than the branch " << branch_tname;
265
266 const std::type_info *tinf = store.getIOType(auxid);
267 fieldInfo.SE_tclass = TClass::GetClass(*tinf);
268 fieldInfo.SE_edt = kOther_t;
269 if( !fieldInfo.SE_tclass ) {
270 fieldInfo.SE_edt = TDataType::GetType(*tinf);
271 if( fieldInfo.SE_edt <=0 ) {
272 fieldInfo.status = FieldInfo::TypeError;
273 throw string("Error getting ROOT type for AUX branch ") + fieldInfo.branch->GetName()
274 + " typeinfo=" + tinf->name();
275 }
276 }
277 }
278 */
279 fieldInfo.status = FieldInfo::Initialized;
280 }
281 return fieldInfo;
282 }
std::map< SG::auxid_t, FieldInfo > m_fieldInfos
static AuxTypeRegistry & instance()
Return the singleton registry instance.
TestStore store
Definition TestStore.cxx:23

◆ getNativeReader()

ROOT::RNTupleReader * RootAuxDynIO::RNTupleAuxDynReader::getNativeReader ( )
inline

Definition at line 75 of file RNTupleAuxDynReader.h.

75 {
76 return m_ntupleReader;
77 }

◆ init()

void RootAuxDynIO::RNTupleAuxDynReader::init ( bool standalone)

initialize once the mode of the Aux store is known

Definition at line 183 of file RNTupleAuxDynReader.cxx.

184 {
185 if( m_initialized ) return;
186
187 const SG::AuxTypeRegistry& reg = SG::AuxTypeRegistry::instance();
188 const string field_prefix = RootAuxDynIO::auxFieldName("", m_storeFieldName);
189 const auto& desc = m_ntupleReader->GetDescriptor();
190 for( const auto &f : desc.GetTopLevelFields() ) {
191 const string field_name = f.GetFieldName();
192 if( field_name.starts_with(field_prefix) ) {
193 const string attr_infile = field_name.substr(field_prefix.size());
194 const string attr_name = reg.inputRename(m_key, attr_infile);
195 const string field_type = f.GetTypeName();
196
197 SG::auxid_t auxid = getAuxIdForAttribute(reg, desc, field_prefix,
198 attr_name, field_type, standalone);
199 // add AuxID to the list
200 // May still be null if we don't have a dictionary for this field
201 if( auxid != SG::null_auxid ) {
202 addAuxID(auxid);
203 m_fieldInfos[auxid].fieldName = field_name;
204 // Can't use type_info because of default template argument in DataVectors ATEAM-1087
205 const std::string& tiname = (standalone and !reg.isLinked(auxid))? reg.getTypeName(auxid) : reg.getVecTypeName(auxid);
206 m_fieldInfos[auxid].view = m_ntupleReader->GetView(field_name, nullptr, tiname);
207 } else {
208 errorcheck::ReportMessage msg (MSG::WARNING, ERRORCHECK_ARGS, "RNTupleAuxDynReader::init");
209 msg << "Could not find auxid for " << attr_infile << " type: " << field_type
210 << " standalone=" << standalone;
211 }
212 }
213 }
214 m_initialized = true;
215 }
MsgStream & msg() const
The standard message stream.
bool addAuxID(const SG::auxid_t &id)
std::string auxFieldName(const std::string &attr_name, const std::string &baseName)
Construct field name for a given dynamic attribute.
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27

◆ 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; }

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

◆ resetBytesRead()

void RootAuxDynReader::resetBytesRead ( )
inlinevirtualinherited

Implements RootAuxDynIO::IRootAuxDynReader.

Definition at line 50 of file RootAuxDynReader.h.

50 {
51 m_bytesRead = 0;
52}

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

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_auxids

SG::auxid_set_t RootAuxDynReader::m_auxids
protectedinherited

Definition at line 31 of file RootAuxDynReader.h.

◆ m_bytesRead

size_t RootAuxDynReader::m_bytesRead = 0
protectedinherited

Definition at line 34 of file RootAuxDynReader.h.

◆ m_fieldInfos

std::map<SG::auxid_t, FieldInfo> RootAuxDynIO::RNTupleAuxDynReader::m_fieldInfos
protected

Definition at line 68 of file RNTupleAuxDynReader.h.

◆ m_imsg

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

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

135{ nullptr };

◆ m_initialized

bool RootAuxDynIO::RNTupleAuxDynReader::m_initialized = false
protected

Definition at line 64 of file RNTupleAuxDynReader.h.

◆ m_key

std::string RootAuxDynIO::RNTupleAuxDynReader::m_key
protected

Definition at line 65 of file RNTupleAuxDynReader.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_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.

◆ m_ntupleReader

ROOT::RNTupleReader* RootAuxDynIO::RNTupleAuxDynReader::m_ntupleReader
protected

Definition at line 71 of file RNTupleAuxDynReader.h.

◆ m_storeFieldName

std::string RootAuxDynIO::RNTupleAuxDynReader::m_storeFieldName
protected

Definition at line 61 of file RNTupleAuxDynReader.h.

◆ m_storeHolderOffset

int RootAuxDynIO::RNTupleAuxDynReader::m_storeHolderOffset = -1
protected

Definition at line 63 of file RNTupleAuxDynReader.h.


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