The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
GaudiMP::TESSerializer Class Reference

#include </builds/gaudi/Gaudi/GaudiMP/include/GaudiMP/TESSerializer.h>

Inheritance diagram for GaudiMP::TESSerializer:
Collaboration diagram for GaudiMP::TESSerializer:

Public Member Functions

 TESSerializer (IDataProviderSvc *svc, IAddressCreator *ac)
 Constructor.
 
void dumpBuffer (TBufferFile &)
 Dump TES contents listed in m_itemList/m_optItemList to a TBufferFile.
 
void loadBuffer (TBufferFile &)
 Rebuild TES from items in a TBufferFile.
 
void addItem (const std::string &path)
 add an item to the TESSerializer's list (#notation)
 
void addOptItem (const std::string &path)
 add an item to the TESSerializer's optional list (#notation)
 
bool analyse (IRegistry *dir, int level) override
 Analysis callback.
 
void checkItems ()
 print out the contents of m_itemList and m_optItemList (std::cout)
 
virtual ~TESSerializer ()
 
- Public Member Functions inherited from IDataStoreAgent
virtual ~IDataStoreAgent ()=default
 destructor
 

Protected Member Functions

void addItem (Items &itms, const std::string &descriptor)
 Add item to the list of items to be serialized (#notation)
 
DataStoreItemfindItem (const std::string &path)
 Find single item identified by its path (exact match)
 

Private Types

typedef std::vector< DataStoreItem * > Items
 
typedef std::vector< std::string > ItemNames
 
typedef std::vector< DataObject * > Objects
 

Private Member Functions

TClass * getClass (DataObject *obj)
 caching wrapper to TClass::GetClass
 

Private Attributes

IDataProviderSvcm_TES
 TES pointer.
 
IDataManagerSvcm_TESMgr
 TES pointer.
 
ItemNames m_itemNames
 Vector of item names.
 
Items m_itemList
 Vector of items to be saved to this stream (DataStoreItem ptrs)
 
ItemNames m_optItemNames
 Vector of item names (std::strings)
 
Items m_optItemList
 Vector of optional items to be saved to this stream (DataStoreItem ptrs)
 
DataStoreItemm_currentItem
 Current item while traversing the TES tree.
 
Objects m_objects
 Selected list of Objects to be serialized (DataObject ptrs)
 
std::map< std::type_index, TClass * > m_classMap
 Map of gROOT class information.
 
bool m_verifyItems
 Boolean Flag as used by GaudiSvc/PersistencySvc/OutputStreamer.
 
bool m_strict
 Boolean Flag used to determine error tolerance.
 
IAddressCreatorm_addressCreator
 IAddress Creator for Opaque Addresses.
 

Detailed Description

Definition at line 41 of file TESSerializer.h.

Member Typedef Documentation

◆ ItemNames

typedef std::vector<std::string> GaudiMP::TESSerializer::ItemNames
private

Definition at line 43 of file TESSerializer.h.

◆ Items

typedef std::vector<DataStoreItem*> GaudiMP::TESSerializer::Items
private

Definition at line 42 of file TESSerializer.h.

◆ Objects

typedef std::vector<DataObject*> GaudiMP::TESSerializer::Objects
private

Definition at line 44 of file TESSerializer.h.

Constructor & Destructor Documentation

◆ TESSerializer()

GaudiMP::TESSerializer::TESSerializer ( IDataProviderSvc * svc,
IAddressCreator * ac )

Constructor.

Definition at line 61 of file TESSerializer.cpp.

62 : m_TES( svc )
63 , m_TESMgr( dynamic_cast<IDataManagerSvc*>( svc ) )
64 , m_currentItem( 0 )
65 , m_verifyItems( false )
66 , m_strict( false )
67 , m_addressCreator( ac ) {}
IDataManagerSvc * m_TESMgr
TES pointer.
DataStoreItem * m_currentItem
Current item while traversing the TES tree.
bool m_verifyItems
Boolean Flag as used by GaudiSvc/PersistencySvc/OutputStreamer.
bool m_strict
Boolean Flag used to determine error tolerance.
IAddressCreator * m_addressCreator
IAddress Creator for Opaque Addresses.
IDataProviderSvc * m_TES
TES pointer.

◆ ~TESSerializer()

virtual GaudiMP::TESSerializer::~TESSerializer ( )
inlinevirtual

Definition at line 68 of file TESSerializer.h.

68{}

Member Function Documentation

◆ addItem() [1/2]

void GaudiMP::TESSerializer::addItem ( const std::string & path)

add an item to the TESSerializer's list (#notation)

Add item to serialization list; ie append to std::vector of DataStoreItems.

Definition at line 348 of file TESSerializer.cpp.

348 {
349 // #notation supported
350 addItem( m_itemList, path );
351}
void addItem(const std::string &path)
add an item to the TESSerializer's list (#notation)
Items m_itemList
Vector of items to be saved to this stream (DataStoreItem ptrs)

◆ addItem() [2/2]

void GaudiMP::TESSerializer::addItem ( Items & itms,
const std::string & descriptor )
protected

Add item to the list of items to be serialized (#notation)

Add item to output streamer list (protected)

Definition at line 302 of file TESSerializer.cpp.

302 {
303 // supports # notation
304 int level = 0;
305
306 std::string slevel;
307 std::string obj_path;
308
309 // Process the incoming string
310 size_t sep = descriptor.rfind( "#" );
311 if ( sep > descriptor.length() ) {
312 // invalid sep case (# not found in string)
313 obj_path = descriptor;
314 slevel = "1";
315 } else {
316 // valid sep case
317 obj_path = descriptor.substr( 0, sep );
318 slevel = descriptor.substr( sep + 1 );
319 }
320
321 // Convert the level string to an integer
322 if ( slevel == "*" ) {
323 level = 9999999;
324 } else {
325 level = std::stoi( slevel );
326 }
327
328 // Are we verifying?
329 if ( m_verifyItems ) {
330 size_t idx = obj_path.find( "/", 1 );
331 while ( idx != std::string::npos ) {
332 std::string sub_item = obj_path.substr( 0, idx );
333 if ( 0 == findItem( sub_item ) ) {
334 cout << "... calling addItem with arg : " << sub_item << endl;
335 addItem( itms, sub_item );
336 }
337 idx = obj_path.find( "/", idx + 1 );
338 }
339 }
340 DataStoreItem* item = new DataStoreItem( obj_path, level );
341 // cout << "Adding TESSerializer item " << item->path()
342 // << " with " << item->depth()
343 // << " level(s)." << endl;
344 itms.push_back( item );
345}
DataStoreItem * findItem(const std::string &path)
Find single item identified by its path (exact match)

◆ addOptItem()

void GaudiMP::TESSerializer::addOptItem ( const std::string & path)

add an item to the TESSerializer's optional list (#notation)

Add optional item to output streamer list.

Definition at line 354 of file TESSerializer.cpp.

354 {
355 // #notation supported
356 addItem( m_optItemList, path );
357}
Items m_optItemList
Vector of optional items to be saved to this stream (DataStoreItem ptrs)

◆ analyse()

bool GaudiMP::TESSerializer::analyse ( IRegistry * dir,
int level )
overridevirtual

Analysis callback.

Implements IDataStoreAgent.

Definition at line 50 of file TESSerializer.cpp.

50 {
51 if ( level < m_currentItem->depth() ) {
52 if ( dir->object() != 0 ) {
53 m_objects.push_back( dir->object() );
54 return true;
55 }
56 }
57 return false;
58}
Objects m_objects
Selected list of Objects to be serialized (DataObject ptrs)
virtual DataObject * object() const =0
Retrieve object behind the link.

◆ checkItems()

void GaudiMP::TESSerializer::checkItems ( )

print out the contents of m_itemList and m_optItemList (std::cout)

Uses cout to print the contents of the mandatory and optional item lists.

Definition at line 360 of file TESSerializer.cpp.

360 {
361 cout << "TESSerializer m_itemList : " << m_itemList.size() << " Items" << endl;
362 for ( Items::const_iterator i = m_itemList.begin(); i != m_itemList.end(); ++i ) {
363 cout << "\tItem : " << ( *i )->path() << endl;
364 }
365 cout << "TESSerializer m_optItemList : " << m_optItemList.size() << " Items" << endl;
366 for ( Items::const_iterator i = m_optItemList.begin(); i != m_optItemList.end(); ++i ) {
367 cout << "\tItem : " << ( *i )->path() << endl;
368 }
369}

◆ dumpBuffer()

void GaudiMP::TESSerializer::dumpBuffer ( TBufferFile & buffer)

Dump TES contents listed in m_itemList/m_optItemList to a TBufferFile.

Serialize contents of TES to a TBufferFile.

Definition at line 70 of file TESSerializer.cpp.

70 {
71 //
72 // Write all valid objects to the TBufferFile provided in the argument
73 // As objects are collected, the member variable m_classMap is filled
74 // with ROOT Class data, and is kept by the Serializer for future
75 // reference
76 //
77 // @paramTBufferFile& buffer : TBufferFile passed by reference
78 // Cannot be declared inside the method, as repeated calls
79 // can cause confusion and buffer wiping.
80 //
81 StatusCode status;
82 DataObject* obj;
83
84 // Clear current selection
85 m_objects.clear();
86
87 // Traverse the tree and collect the requested objects
88 for ( DataStoreItem* item : m_itemList ) {
89 m_currentItem = item;
90 // cout << "Retrieving Mandatory Object : " << m_currentItem->path() << endl;
91 status = m_TES->retrieveObject( m_currentItem->path(), obj );
92 if ( status.isSuccess() ) {
93 m_TESMgr->traverseSubTree( obj, this ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
94 } else {
95 string text( "WARNING: Cannot retrieve TES object(s) for serialisation: " );
96 text += m_currentItem->path();
97 if ( m_strict ) {
98 throw GaudiException( text + m_currentItem->path(), "", status );
99 } else {
100 cout << text << endl;
101 // return StatusCode::FAILURE;
102 }
103 }
104 }
105 // Traverse the tree and collect the requested objects (tolerate missing items here)
106 for ( DataStoreItem* item : m_optItemList ) {
107 m_currentItem = item;
108 // cout << "Retrieving Optional Object : " << m_currentItem->path() << endl;
109 status = m_TES->retrieveObject( m_currentItem->path(), obj );
110 if ( status.isSuccess() ) {
111 m_TESMgr->traverseSubTree( obj, this ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
112 }
113 }
114
115 // Prepare for serialization:
116 // - find all TClass pointers needed and ignore objects without dictionaries
117 std::vector<std::tuple<DataObject*, TClass*>> objects;
118 objects.reserve( m_objects.size() );
119 for_each( begin( m_objects ), end( m_objects ), [this, &objects]( auto obj ) {
120 if ( auto cl = getClass( obj ) ) objects.emplace_back( obj, cl );
121 } );
122
123 // cout << "TESSerializer : Beginning loop to write to TBufferFile for nObjects : " << m_objects.size() << endl;
124 buffer.WriteInt( objects.size() );
125
126 for ( auto& [pObj, cl] : objects ) {
127 DataObjectPush p( pObj ); /* add the data object to the list... */
128
129 // write object to buffer in order location-name-object
130 std::string loc = pObj->registry()->identifier();
131 buffer.WriteString( loc.c_str() );
132 buffer.WriteString( cl->GetName() );
133 cl->Streamer( pObj, buffer );
134
135 /* take care of links */
136 LinkManager* linkMgr = pObj->linkMgr();
137 long int numLinks = linkMgr->size();
138 buffer.WriteInt( numLinks );
139 // now write each link
140 for ( int it = 0; it != numLinks; it++ ) {
141 const string& link = linkMgr->link( it )->path();
142 buffer.WriteString( link.c_str() );
143 }
144
145 // now do the thing with the opaqueAddress
146 // to go from string->object when recovering, will need svc_type, and clid, aswell as the string version
147 IOpaqueAddress* iop = pObj->registry()->address();
148 if ( iop ) {
149 buffer.WriteInt( 1 );
150 const string* par = iop->par();
151 long svcType = iop->svcType();
152 long clid = iop->clID();
153 buffer.WriteLong( svcType );
154 buffer.WriteLong( clid );
155 buffer.WriteString( par->c_str() );
156 } else {
157 buffer.WriteInt( 0 );
158 }
159 // object complete, continue in for-loop
160 }
161
162 // Final Actions
163 // Write the End Flag, to avoid potential SegFaults on loadBuffer
164 buffer.WriteString( SERIALIZER_END );
165 // return StatusCode::SUCCESS;
166}
#define SERIALIZER_END
TClass * getClass(DataObject *obj)
caching wrapper to TClass::GetClass
virtual long svcType() const =0
Retrieve service type.
virtual const CLID & clID() const =0
Retrieve class information from link.
virtual const std::string * par() const =0
Retrieve String parameters.
bool isSuccess() const
Definition StatusCode.h:314
AttribStringParser::Iterator begin(const AttribStringParser &parser)
void for_each(ContainerOfSynced &c, Fun &&f)

◆ findItem()

DataStoreItem * GaudiMP::TESSerializer::findItem ( const std::string & path)
protected

Find single item identified by its path (exact match)

Definition at line 372 of file TESSerializer.cpp.

372 {
373 for ( Items::const_iterator i = m_itemList.begin(); i != m_itemList.end(); ++i ) {
374 if ( ( *i )->path() == path ) return ( *i );
375 }
376 for ( Items::const_iterator j = m_optItemList.begin(); j != m_optItemList.end(); ++j ) {
377 if ( ( *j )->path() == path ) return ( *j );
378 }
379 return 0;
380}

◆ getClass()

TClass * GaudiMP::TESSerializer::getClass ( DataObject * obj)
inlineprivate

caching wrapper to TClass::GetClass

Definition at line 79 of file TESSerializer.h.

79 {
80 auto& id = typeid( *obj );
81 auto pos = m_classMap.find( id );
82 if ( pos == end( m_classMap ) ) { return m_classMap[id] = TClass::GetClass( id ); }
83 return pos->second;
84 }
std::map< std::type_index, TClass * > m_classMap
Map of gROOT class information.

◆ loadBuffer()

void GaudiMP::TESSerializer::loadBuffer ( TBufferFile & buffer)

Rebuild TES from items in a TBufferFile.

Reconstruct the TES from a given TBufferFile.

The next is equivalent to ReadObjectAny(cl) except of the 'magic!!'

Definition at line 169 of file TESSerializer.cpp.

169 {
170
171 // reverse mechanism of dumps
172 // buffer is: length of DataObjects vector
173 // location string
174 // type name string
175 // the object itself
176 // count of links
177 // list of links (conditional on count)
178 // flag indicating Opaque Address presence
179 // Opaque Address svcType (conditional on flag)
180 // Opaque Address clID (conditional on flag)
181 // Opaque Address par (conditional on flag)
182
183 int nObjects;
184 // 3 StatusCodes... for :
185 // general use : registering objects : creating OpaqueAddresses
186 StatusCode sc, registerStat, createAddressStat;
187
188 // Prepare for Reading
189 buffer.SetReadMode();
190 buffer.SetBufferOffset();
191
192 buffer.ReadInt( nObjects );
193 for ( int i = 0; i < nObjects; ++i ) {
194 char text[4096];
195 buffer.ReadString( text, sizeof( text ) );
196 string location( text );
197 if ( !location.compare( "EOF" ) ) {
198 /* There was an error in serialization, but the EOF
199 flag marks the endpoint in any case */
200 break;
201 }
202 buffer.ReadString( text, sizeof( text ) );
203 TClass* cl = gROOT->GetClass( text );
204 if ( cl == 0 ) {
205 if ( m_strict ) {
206 throw GaudiException( "gROOT->GetClass cannot find clName", text, StatusCode::FAILURE );
207 } else {
208 cout << "TESSerializer WARNING : gROOT->GetClass fails for clname : " << location.c_str() << endl;
209 continue;
210 }
211 }
212
214 DataObject* obj = (DataObject*)cl->New();
215 DataObjectPush push( obj ); // This is magic!
216 cl->Streamer( obj, buffer );
217
218 // now restore links
219 if ( obj ) {
220 int nlink = 0;
221 LinkManager* lnkMgr = obj->linkMgr();
222 buffer.ReadInt( nlink );
223
224 for ( int j = 0; j < nlink; ++j ) {
225 buffer.ReadString( text, sizeof( text ) );
226 lnkMgr->addLink( text, 0 );
227 }
228 }
229
230 // Re-register...
231 registerStat = m_TES->registerObject( location, obj );
232 if ( registerStat.isFailure() ) {
233 DataObject* dummy = NULL;
234 if ( location == "/Event" ) {
235 sc = m_TESMgr->setRoot( location, obj );
236 if ( sc.isFailure() ) throw GaudiException( "Cannot set root at location " + location, "", sc );
237 } else {
238 m_TES->findObject( location, dummy ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
239 if ( !dummy )
240 m_TES->registerObject( location, obj ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
241 else {
242 // skipping to the next object
243 // (flush the remaining metadata in the buffer)
244 int flag( 0 );
245 buffer.ReadInt( flag );
246 if ( flag ) {
247 long svcType;
248 buffer.ReadLong( svcType );
249 long clid;
250 buffer.ReadLong( clid );
251 buffer.ReadString( text, sizeof( text ) );
252 }
253 continue;
254 }
255 }
256 }
257 // next is the opaque address information
258 // create Generic Address using the info from the TBufferFile,
259 // then create an IOpaqueAddress object using the Persistency Svc
260 // IOpaque Address pointer (blank... pass the ref to the createAddress Fn)
261
262 int flag( 0 );
263 buffer.ReadInt( flag );
264 // flag will be 0 or 1 to indicate OpaqueAddress Info
265 if ( flag == 1 ) {
266 // will need an IOpaqueAddress and its ref
267 IOpaqueAddress* iop;
268 IOpaqueAddress*& iopref = iop;
269 // Read svcType, clID and par from buffer
270 long svcType;
271 buffer.ReadLong( svcType );
272
273 long clid;
274 buffer.ReadLong( clid );
275 const CLID classid( clid );
276
277 char* cp;
278 cp = buffer.ReadString( text, sizeof( text ) );
279 const string opaque( cp );
280 // create Generic address
281 // already have svcType, clID, par1.. just make dummy variables for par2, and ipar1 and 2
282 const string& p2 = "";
283 unsigned long ip1( 0 );
284 unsigned long ip2( 0 );
285 GenericAddress gadd( svcType, classid, opaque, p2, ip1, ip2 );
286
287 // now create the address
288 createAddressStat =
289 m_addressCreator->createAddress( gadd.svcType(), gadd.clID(), gadd.par(), gadd.ipar(), iopref );
290 if ( createAddressStat.isFailure() ) {
291 throw GaudiException( "Failure in creating OpaqueAddress for reconstructed registry", "", createAddressStat );
292 }
293 // And finally, set this address
294 obj->registry()->setAddress( iop );
295 }
296 // all done
297 }
298}
unsigned int CLID
Class ID definition.
Definition ClassID.h:16
IRegistry * registry() const
Get pointer to Registry.
Definition DataObject.h:79
LinkManager * linkMgr()
Retrieve Link manager.
Definition DataObject.h:81
virtual void setAddress(IOpaqueAddress *pAddress)=0
Set/Update Opaque storage address.
bool isFailure() const
Definition StatusCode.h:129
constexpr static const auto FAILURE
Definition StatusCode.h:100

Member Data Documentation

◆ m_addressCreator

IAddressCreator* GaudiMP::TESSerializer::m_addressCreator
private

IAddress Creator for Opaque Addresses.

Definition at line 110 of file TESSerializer.h.

◆ m_classMap

std::map<std::type_index, TClass*> GaudiMP::TESSerializer::m_classMap
private

Map of gROOT class information.

Definition at line 104 of file TESSerializer.h.

◆ m_currentItem

DataStoreItem* GaudiMP::TESSerializer::m_currentItem
private

Current item while traversing the TES tree.

Definition at line 99 of file TESSerializer.h.

◆ m_itemList

Items GaudiMP::TESSerializer::m_itemList
private

Vector of items to be saved to this stream (DataStoreItem ptrs)

Definition at line 93 of file TESSerializer.h.

◆ m_itemNames

ItemNames GaudiMP::TESSerializer::m_itemNames
private

Vector of item names.

Definition at line 91 of file TESSerializer.h.

◆ m_objects

Objects GaudiMP::TESSerializer::m_objects
private

Selected list of Objects to be serialized (DataObject ptrs)

Definition at line 101 of file TESSerializer.h.

◆ m_optItemList

Items GaudiMP::TESSerializer::m_optItemList
private

Vector of optional items to be saved to this stream (DataStoreItem ptrs)

Definition at line 97 of file TESSerializer.h.

◆ m_optItemNames

ItemNames GaudiMP::TESSerializer::m_optItemNames
private

Vector of item names (std::strings)

Definition at line 95 of file TESSerializer.h.

◆ m_strict

bool GaudiMP::TESSerializer::m_strict
private

Boolean Flag used to determine error tolerance.

Definition at line 108 of file TESSerializer.h.

◆ m_TES

IDataProviderSvc* GaudiMP::TESSerializer::m_TES
private

TES pointer.

Definition at line 87 of file TESSerializer.h.

◆ m_TESMgr

IDataManagerSvc* GaudiMP::TESSerializer::m_TESMgr
private

TES pointer.

Definition at line 89 of file TESSerializer.h.

◆ m_verifyItems

bool GaudiMP::TESSerializer::m_verifyItems
private

Boolean Flag as used by GaudiSvc/PersistencySvc/OutputStreamer.

Definition at line 106 of file TESSerializer.h.


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