ATLAS Offline Software
Public Member Functions | Private Types | Private Attributes | List of all members
AthenaRootStreamerSvc Class Reference

This class provides the manager for ROOT custom streamers. More...

#include <AthenaRootStreamerSvc.h>

Inheritance diagram for AthenaRootStreamerSvc:
Collaboration diagram for AthenaRootStreamerSvc:

Public Member Functions

 AthenaRootStreamerSvc (const std::string &name, ISvcLocator *pSvcLocator)
 Standard Service Constructor. More...
 
virtual ~AthenaRootStreamerSvc ()
 Destructor. More...
 
virtual StatusCode initialize ()
 Required of all Gaudi services: More...
 
virtual StatusCode finalize ()
 Required of all Gaudi services: More...
 
virtual const InterfaceID & type () const
 Service type. More...
 
virtual StatusCode AddStreamer (const std::string &converter_classname, bool adopt=true)
 
virtual StatusCode AddStreamer (T_AthenaRootConverterBase *converter, bool adopt=true)
 
virtual StatusCode AdoptStreamerForClass (const std::string &class_name)
 
virtual StatusCode AdoptAllStreamers ()
 

Private Types

typedef std::map< std::string, AthenaRootStreamer * > StreamerMap
 map of streamers for given class names More...
 
typedef std::pair< RootType, void * > ConverterPair_t
 vector of converters created by the service, (as Reflex Objects) kept so they can be deleted at the end More...
 
typedef std::vector< ConverterPair_tConverterVector_t
 

Private Attributes

StringArrayProperty m_streamerClassNames
 
StreamerMap m_streamerMap
 
ConverterVector_t m_createdConverters
 

Detailed Description

This class provides the manager for ROOT custom streamers.

Author
Marcin Nowak

Definition at line 29 of file AthenaRootStreamerSvc.h.

Member Typedef Documentation

◆ ConverterPair_t

typedef std::pair<RootType, void*> AthenaRootStreamerSvc::ConverterPair_t
private

vector of converters created by the service, (as Reflex Objects) kept so they can be deleted at the end

Definition at line 65 of file AthenaRootStreamerSvc.h.

◆ ConverterVector_t

Definition at line 66 of file AthenaRootStreamerSvc.h.

◆ StreamerMap

typedef std::map<std::string, AthenaRootStreamer*> AthenaRootStreamerSvc::StreamerMap
private

map of streamers for given class names

Definition at line 60 of file AthenaRootStreamerSvc.h.

Constructor & Destructor Documentation

◆ AthenaRootStreamerSvc()

AthenaRootStreamerSvc::AthenaRootStreamerSvc ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

Standard Service Constructor.

Definition at line 28 of file AthenaRootStreamerSvc.cxx.

29  : base_class(name, pSvcLocator),
31 {
32  declareProperty( "Streamers", m_streamerClassNames );
33 }

◆ ~AthenaRootStreamerSvc()

AthenaRootStreamerSvc::~AthenaRootStreamerSvc ( )
virtual

Destructor.

Definition at line 36 of file AthenaRootStreamerSvc.cxx.

37 {
38 }

Member Function Documentation

◆ AddStreamer() [1/2]

StatusCode AthenaRootStreamerSvc::AddStreamer ( const std::string &  converter_classname,
bool  adopt = true 
)
virtual

Definition at line 97 of file AthenaRootStreamerSvc.cxx.

98 {
99  RootType streamer_class( converter_classname );
100  if( !streamer_class ) {
101 
102  // Enable library auto-loading. Only once per job.
103  static std::once_flag libLoadFlag;
104  std::call_once( libLoadFlag, []( TInterpreter& interpreter ) {
105 
106  // Enable library auto-loading.
107  TClass::ReadRules();
108  interpreter.LoadLibraryMap();
109  interpreter.SetClassAutoloading( true );
110 
111  }, *gInterpreter );
112 
113  // int ntypesBefore = Reflex::Type::TypeSize();
114  gInterpreter->AutoLoad( converter_classname.c_str() );
115 
116  MsgStream log(msgSvc(), name());
117  streamer_class = RootType( converter_classname );
118  if( ! streamer_class ) {
119  ATH_MSG_ERROR ( "Could not find <" << converter_classname
120  << "> in the dictionary, and autoloading failed" );
121  return(StatusCode::FAILURE);
122  }
123  log << MSG::DEBUG << "Loaded dictionary for class " << converter_classname
124  // << " ntypes before load " << ntypesBefore
125  // << " ntypes loaded " << Reflex::Type::TypeSize() - ntypesBefore
126  << endmsg;
127  }
128  void* obj = streamer_class.Construct();
129  m_createdConverters.emplace_back( streamer_class, obj );
130  return AddStreamer( (T_AthenaRootConverterBase*)obj, adopt);
131 }

◆ AddStreamer() [2/2]

StatusCode AthenaRootStreamerSvc::AddStreamer ( T_AthenaRootConverterBase converter,
bool  adopt = true 
)
virtual

Definition at line 134 of file AthenaRootStreamerSvc.cxx.

135 {
136  const std::string &classname = converter->ClassName();
137  AthenaRootStreamer* & streamer = m_streamerMap[classname];
138  if (!streamer) {
139  // no streamer for this class yet
140  streamer = new AthenaRootStreamer(classname, this);
141  }
142  auto convH = std::make_unique<AthenaRootConverterHandle>(converter);
143  if( streamer->AddConverter(std::move(convH)).isFailure() ) {
144  ATH_MSG_ERROR ( "ROOT Streamer for " << classname
145  << " already has a converter for checksum = "
146  << converter->StreamerChecksum() );
147  return(StatusCode::FAILURE);
148  }
149  ATH_MSG_INFO ( "ROOT Streamer for " << classname
150  << " added converter for checksum = "
151  << converter->StreamerChecksum() );
152 
153  if( adopt ) {
154  return AdoptStreamerForClass( classname );
155  }
156  return(StatusCode::SUCCESS);
157 }

◆ AdoptAllStreamers()

StatusCode AthenaRootStreamerSvc::AdoptAllStreamers ( )
virtual

Definition at line 178 of file AthenaRootStreamerSvc.cxx.

179 {
180  StatusCode sc = StatusCode::SUCCESS;
181  for (auto& p : m_streamerMap) {
182  if( p.second->Adopt().isFailure() ) {
183  ATH_MSG_INFO ( "Failed to adopt streamer for class " << p.first );
184  sc = StatusCode::FAILURE;
185  }
186  }
187  return sc;
188 }

◆ AdoptStreamerForClass()

StatusCode AthenaRootStreamerSvc::AdoptStreamerForClass ( const std::string &  class_name)
virtual

Definition at line 161 of file AthenaRootStreamerSvc.cxx.

161  {
162  if (m_streamerMap.find(class_name) == m_streamerMap.end()) {
163  ATH_MSG_ERROR ( "Attemt to adopt streamer for "
164  << class_name
165  << " with has no converters defined" );
166  return(StatusCode::FAILURE);
167  }
168  if (m_streamerMap[class_name]->Adopt().isSuccess()) {
169  ATH_MSG_INFO ( "Adopted streamer for class " << class_name );
170  return(StatusCode::SUCCESS);
171  }
172  ATH_MSG_ERROR ( "Failed to adopt streamer for " << class_name );
173  return(StatusCode::FAILURE);
174 }

◆ finalize()

StatusCode AthenaRootStreamerSvc::finalize ( )
virtual

Required of all Gaudi services:

Definition at line 75 of file AthenaRootStreamerSvc.cxx.

76 {
77  // Destroy converter Objects created by the service
78  for (auto& p : m_createdConverters)
79  {
80  p.first.Destruct (p.second);
81  }
82  m_createdConverters.clear();
83 
84  // do NOT delete the streamers created by the service - they are owned by TClass
85  m_streamerMap.clear();
86 
87  return AthService::finalize();
88 }

◆ initialize()

StatusCode AthenaRootStreamerSvc::initialize ( )
virtual

Required of all Gaudi services:

Definition at line 41 of file AthenaRootStreamerSvc.cxx.

42 {
44 
45  pool::DbSession session;
46  // initialize the session
47  // using NULL context, hopefully not a problem
48  pool::DbStatus rc = session.open();
49  // create ROOT-type database object -
50  // this loads the ROOT storage service plugin and
51  // initializes POOL/ROOT class loader needed by GetClass()
52  if( rc != pool::DbStatus::Success || ! session.db(pool::ROOT_StorageType) ) {
53  ATH_MSG_ERROR ( "Failed to open POOL/ROOT session" );
54  return StatusCode::FAILURE;
55  }
56  ATH_MSG_INFO ( "POOL/ROOT class loader initialized" );
57  session.close();
58 
59  StatusCode status = StatusCode::SUCCESS;
60  if( m_streamerClassNames.value().size() ) {
61  ATH_MSG_INFO ( m_streamerClassNames.value().size() << " ROOT streamers declared" );
62 
63  std::vector< std::string >::const_iterator i = m_streamerClassNames.value().begin();
64  while( i != m_streamerClassNames.value().end() ) {
65  ATH_MSG_INFO ( " - Streamer name:" << *i );
66  if( AddStreamer( *i++ ).isFailure() )
67  status = StatusCode::FAILURE;
68  }
69  }
70 
71  return status;
72 }

◆ type()

const InterfaceID & AthenaRootStreamerSvc::type ( ) const
virtual

Service type.

Definition at line 91 of file AthenaRootStreamerSvc.cxx.

92 {
93  return IAthenaRootStreamerSvc::interfaceID();
94 }

Member Data Documentation

◆ m_createdConverters

ConverterVector_t AthenaRootStreamerSvc::m_createdConverters
private

Definition at line 67 of file AthenaRootStreamerSvc.h.

◆ m_streamerClassNames

StringArrayProperty AthenaRootStreamerSvc::m_streamerClassNames
private

Definition at line 57 of file AthenaRootStreamerSvc.h.

◆ m_streamerMap

StreamerMap AthenaRootStreamerSvc::m_streamerMap
private

Definition at line 61 of file AthenaRootStreamerSvc.h.


The documentation for this class was generated from the following files:
pool::DbSession::close
DbStatus close()
Close the session.
T_AthenaRootConverterBase
Definition: T_AthenaRootConverter.h:17
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:50
pool::DbStatus
Definition: DbStatus.h:67
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
initialize
void initialize()
Definition: run_EoverP.cxx:894
AthenaRootStreamerSvc::m_streamerMap
StreamerMap m_streamerMap
Definition: AthenaRootStreamerSvc.h:61
pool::DbSession
Db objects: class DbSession.
Definition: DbSession.h:43
T_AthenaRootConverterBase::ClassName
const std::string & ClassName()
Definition: T_AthenaRootConverter.h:27
AthenaRootStreamer::AddConverter
StatusCode AddConverter(std::unique_ptr< AthenaRootConverterHandle > converter)
Add a converter to this streamer.
Definition: AthenaRootStreamer.cxx:36
AthenaRootStreamerSvc::AdoptStreamerForClass
virtual StatusCode AdoptStreamerForClass(const std::string &class_name)
Definition: AthenaRootStreamerSvc.cxx:161
T_AthenaRootConverterBase::StreamerChecksum
unsigned StreamerChecksum()
Definition: T_AthenaRootConverter.h:28
RootType
TTypeAdapter RootType
Definition: RootType.h:211
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthenaRootStreamerSvc::m_createdConverters
ConverterVector_t m_createdConverters
Definition: AthenaRootStreamerSvc.h:67
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
pool::DbSession::open
DbStatus open()
Open the session in a given mode.
AthenaRootStreamer
This class enhances ROOT custom streamer base TClassStreamer and can choose a converter function base...
Definition: AthenaRootStreamer.h:33
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
AthenaRootStreamerSvc::AddStreamer
virtual StatusCode AddStreamer(const std::string &converter_classname, bool adopt=true)
Definition: AthenaRootStreamerSvc.cxx:97
DEBUG
#define DEBUG
Definition: page_access.h:11
pool::DbSession::db
IOODatabase * db(const DbType &typ)
Allow access to the Database implementation.
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
merge.status
status
Definition: merge.py:17
python.DetectStreamerInfoChanges.class_name
class_name
Definition: DetectStreamerInfoChanges.py:57
python.PyAthena.obj
obj
Definition: PyAthena.py:132
pool::DbStatus::Success
@ Success
Definition: DbStatus.h:73
AthenaRootStreamerSvc::m_streamerClassNames
StringArrayProperty m_streamerClassNames
Definition: AthenaRootStreamerSvc.h:57
python.trfValidateRootFile.rc
rc
Definition: trfValidateRootFile.py:349
TScopeAdapter
Definition: RootType.h:119