ATLAS Offline Software
Loading...
Searching...
No Matches
AthenaPoolCnvSvc Class Reference

This class provides the interface between Athena and PoolSvc. More...

#include <AthenaPoolCnvSvc.h>

Inheritance diagram for AthenaPoolCnvSvc:
Collaboration diagram for AthenaPoolCnvSvc:

Public Member Functions

virtual StatusCode initialize () override
 Required of all Gaudi Services.
virtual StatusCode io_reinit () override
virtual StatusCode finalize () override
 Required of all Gaudi Services.
virtual StatusCode io_finalize () override
virtual StatusCode stop () override
virtual StatusCode createObj (IOpaqueAddress *pAddress, DataObject *&refpObject) override
 Implementation of IConversionSvc: Create the transient representation of an object from persistent state.
virtual StatusCode createRep (DataObject *pObject, IOpaqueAddress *&refpAddress) override
 Implementation of IConversionSvc: Convert the transient object to the requested representation.
virtual StatusCode fillRepRefs (IOpaqueAddress *pAddress, DataObject *pObject) override
 Implementation of IConversionSvc: Resolve the references of the converted object.
virtual StatusCode connectOutput (const std::string &outputConnectionSpec, const std::string &openMode) override
 Implementation of IConversionSvc: Connect to the output connection specification with open mode.
virtual StatusCode connectOutput (const std::string &outputConnectionSpec) override
 Implementation of IConversionSvc: Connect to the output connection specification with open mode.
virtual StatusCode commitOutput (const std::string &outputConnectionSpec, bool doCommit) override
 Implementation of IConversionSvc: Commit pending output.
virtual StatusCode disconnectOutput (const std::string &outputConnectionSpec) override
 Disconnect to the output connection.
virtual IPoolSvcgetPoolSvc () override
virtual TokenregisterForWrite (Placement *placement, const void *obj, const RootType &classDesc) override
virtual void setObjPtr (void *&obj, const Token *token) override
virtual bool useDetailChronoStat () const override
StatusCode createAddress (long svcType, const CLID &clid, const std::string *par, const unsigned long *ip, IOpaqueAddress *&refpAddress) override
 Create a Generic address using explicit arguments to identify a single object.
virtual StatusCode createAddress (long svcType, const CLID &clid, const std::string &refAddress, IOpaqueAddress *&refpAddress) override
 Create address from string form.
virtual StatusCode convertAddress (const IOpaqueAddress *pAddress, std::string &refAddress) override
 Convert address to string form.
virtual StatusCode registerCleanUp (IAthenaPoolCleanUp *cnv) override
 Implement registerCleanUp to register a IAthenaPoolCleanUp to be called during cleanUp.
virtual StatusCode cleanUp (const std::string &connection) override
 Implement cleanUp to call all registered IAthenaPoolCleanUp cleanUp() function.
virtual StatusCode setInputAttributes (const std::string &fileName) override
 Set the input file attributes, if any are requested from jobOpts.
virtual void handle (const Incident &incident) override
 Implementation of IIncidentListener: Handle for EndEvent incidence.
void flushDataHeaderForms (const std::string &streamName="*")
 Tell DataHeaderCnv to write out all DataHeaderForms for a given streamName (default is all).
 AthenaPoolCnvSvc (const std::string &name, ISvcLocator *pSvcLocator)
 Standard Service Constructor.
virtual ~AthenaPoolCnvSvc ()=default
 Destructor.

Protected Member Functions

unsigned outputContextId (const std::string &outputConnection)

Protected Attributes

PMonUtils::BasicStopWatchResultMap_t m_chronoMap {}
 Map that holds chrono information.
Gaudi::Property< bool > m_persSvcPerOutput {this,"PersSvcPerOutput",true}
 PersSvcPerOutput, boolean property to use multiple persistency services, one per output stream.
Gaudi::Property< std::string > m_persSvcPerInputType {this,"PersSvcPerInputType",""}
 PersSvcPerInputType, string property, tree name to use multiple persistency services, one per input type.
std::mutex m_mutex
std::set< unsigned int > m_processedContextIds
 Track context IDs for which extractPoolAttributes has been called.
Gaudi::Property< bool > m_oneDataHeaderForm { this, "OneDataHeaderForm", false }
 If true, use only one DataHeaderForm per Stream.
Gaudi::Property< int > m_DHFormCacheSize { this, "maxDHFormCacheSize", 100 }
 Property for DataHeaderCnv input DHForm cache size.
Gaudi::Property< bool > m_DHFilterAliases { this, "doFilterDHAliases", true }
 Flag to control SG alias filtering when writing out DataHeader (see DataHeaderCnv_p6).

Private Member Functions

void extractPoolAttributes (const Gaudi::Property< std::vector< std::string > > &property, std::vector< std::vector< std::string > > *contAttr, std::vector< std::vector< std::string > > *dbAttr, std::vector< std::vector< std::string > > *domAttr=0) const
 Extract POOL ItechnologySpecificAttributes for Domain, Database and Container from property.
StatusCode processPoolAttributes (std::vector< std::vector< std::string > > &attr, const std::string &fileName, unsigned long contextId, bool doGet=true, bool doSet=true, bool doClear=true) const
 Set/get technology dependent POOL attributes.

Private Attributes

std::string m_lastInputFileName
 decoded storage tech requested in "StorageTechnology" property
ServiceHandle< IPoolSvcm_poolSvc {this,"PoolSvc","PoolSvc"}
ServiceHandle< IClassIDSvc > m_clidSvc {this,"ClassIDSvc","ClassIDSvc"}
Gaudi::Property< bool > m_useDetailChronoStat {this,"UseDetailChronoStat",false}
 UseDetailChronoStat, enable detailed output for time and size statistics for AthenaPOOL: default = false.
Gaudi::Property< std::string > m_containerNamingSchemeProp {this, "PoolContainerNamingScheme", "Historical"}
 POOL container naming scheme selection.
Gaudi::Property< std::vector< std::string > > m_poolAttr {this,"PoolAttributes",{},"Pool Attributes","OrderedSet<std::string>"}
 Output PoolAttributes, vector with names and values of technology specific attributes for POOL.
std::vector< std::vector< std::string > > m_domainAttr
std::vector< std::vector< std::string > > m_databaseAttr
std::vector< std::vector< std::string > > m_containerAttr
Gaudi::Property< std::vector< std::string > > m_inputPoolAttr {this,"InputPoolAttributes",{}}
 Input PoolAttributes, vector with names and values of technology specific attributes for POOL.
std::vector< std::vector< std::string > > m_inputAttr
Gaudi::Property< std::vector< std::string > > m_inputPoolAttrPerEvent {this,"PrintInputAttrPerEvt",{}}
 Print input PoolAttributes per event, vector with names of technology specific attributes for POOL to be printed each event.
std::vector< std::vector< std::string > > m_inputAttrPerEvent

Friends

class SvcFactory< AthenaPoolCnvSvc >

Detailed Description

This class provides the interface between Athena and PoolSvc.

Definition at line 40 of file AthenaPoolCnvSvc.h.

Constructor & Destructor Documentation

◆ AthenaPoolCnvSvc()

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

Standard Service Constructor.

Definition at line 463 of file AthenaPoolCnvSvc.cxx.

463 :
464 base_class(name, pSvcLocator, pool::POOL_StorageType.type()) {
465}
static const DbType POOL_StorageType
Definition DbType.h:84

◆ ~AthenaPoolCnvSvc()

virtual AthenaPoolCnvSvc::~AthenaPoolCnvSvc ( )
virtualdefault

Destructor.

Member Function Documentation

◆ cleanUp()

StatusCode AthenaPoolCnvSvc::cleanUp ( const std::string & connection)
overridevirtual

Implement cleanUp to call all registered IAthenaPoolCleanUp cleanUp() function.

Definition at line 412 of file AthenaPoolCnvSvc.cxx.

412 {
413 bool retError = false;
414 std::size_t cpos = connection.find(':');
415 std::size_t bpos = connection.find('[');
416 if (cpos == std::string::npos) {
417 cpos = 0;
418 } else {
419 cpos++;
420 }
421 if (bpos != std::string::npos) bpos = bpos - cpos;
422 const std::string conn = connection.substr(cpos, bpos);
423 ATH_MSG_VERBOSE("Cleanup for Connection='"<< conn <<"'");
424 for (auto converter : m_cnvs) {
425 if (!converter->cleanUp(conn).isSuccess()) {
426 ATH_MSG_WARNING("AthenaPoolConverter cleanUp failed.");
427 retError = true;
428 }
429 }
430 return(retError ? StatusCode::FAILURE : StatusCode::SUCCESS);
431}
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)

◆ commitOutput()

StatusCode AthenaPoolCnvSvc::commitOutput ( const std::string & outputConnectionSpec,
bool doCommit )
overridevirtual

Implementation of IConversionSvc: Commit pending output.

Parameters
doCommit[IN] boolean to force full commit

Definition at line 263 of file AthenaPoolCnvSvc.cxx.

263 {
264 // This is called after all DataObjects are converted.
265 std::string outputConnection = outputConnectionSpec.substr(0, outputConnectionSpec.find('['));
266 // StopWatch listens from here until the end of this current scope
267 PMonUtils::BasicStopWatch stopWatch("commitOutput", m_chronoMap);
268 std::unique_lock<std::mutex> lock(m_mutex);
269 unsigned int contextId = outputContextId(outputConnection);
270 if (!processPoolAttributes(m_domainAttr, outputConnection, contextId).isSuccess()) {
271 ATH_MSG_DEBUG("commitOutput failed process POOL domain attributes.");
272 }
273 if (!processPoolAttributes(m_databaseAttr, outputConnection, contextId).isSuccess()) {
274 ATH_MSG_DEBUG("commitOutput failed process POOL database attributes.");
275 }
276 if (!processPoolAttributes(m_containerAttr, outputConnection, contextId).isSuccess()) {
277 ATH_MSG_DEBUG("commitOutput failed process POOL container attributes.");
278 }
279
280 // lock.unlock(); //MN: first need to make commitCache slot-specific
281 try {
282 if (doCommit) {
283 if (!m_poolSvc->commit(contextId).isSuccess()) {
284 ATH_MSG_ERROR("commitOutput FAILED to commit OutputStream.");
285 return(StatusCode::FAILURE);
286 }
287 } else {
288 if (!m_poolSvc->commitAndHold(contextId).isSuccess()) {
289 ATH_MSG_ERROR("commitOutput FAILED to commitAndHold OutputStream.");
290 return(StatusCode::FAILURE);
291 }
292 }
293 } catch (std::exception& e) {
294 ATH_MSG_ERROR("commitOutput - caught exception: " << e.what());
295 return(StatusCode::FAILURE);
296 }
297 if (!this->cleanUp(outputConnection).isSuccess()) {
298 ATH_MSG_ERROR("commitOutput FAILED to cleanup converters.");
299 return(StatusCode::FAILURE);
300 }
301
302 return(StatusCode::SUCCESS);
303}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
StatusCode processPoolAttributes(std::vector< std::vector< std::string > > &attr, const std::string &fileName, unsigned long contextId, bool doGet=true, bool doSet=true, bool doClear=true) const
Set/get technology dependent POOL attributes.
ServiceHandle< IPoolSvc > m_poolSvc
virtual StatusCode cleanUp(const std::string &connection) override
Implement cleanUp to call all registered IAthenaPoolCleanUp cleanUp() function.

◆ connectOutput() [1/2]

StatusCode AthenaPoolCnvSvc::connectOutput ( const std::string & outputConnectionSpec)
overridevirtual

Implementation of IConversionSvc: Connect to the output connection specification with open mode.

Parameters
outputConnectionSpec[IN] the name of the output connection specification as string.

Definition at line 235 of file AthenaPoolCnvSvc.cxx.

235 {
236// This is called before DataObjects are being converted.
237 std::string outputConnection = outputConnectionSpec.substr(0, outputConnectionSpec.find('['));
238 unsigned int contextId = outputContextId(outputConnection);
239 try {
240 if (!m_poolSvc->connect(pool::ITransaction::UPDATE, contextId).isSuccess()) {
241 ATH_MSG_ERROR("connectOutput FAILED to open an UPDATE transaction.");
242 return(StatusCode::FAILURE);
243 }
244 } catch (std::exception& e) {
245 ATH_MSG_ERROR("connectOutput - caught exception: " << e.what());
246 return(StatusCode::FAILURE);
247 }
248 std::unique_lock<std::mutex> lock(m_mutex);
249 if (m_processedContextIds.insert(contextId).second) {
250 // Extracting OUTPUT POOL ItechnologySpecificAttributes for Domain, Database and Container.
251 extractPoolAttributes(m_poolAttr, &m_containerAttr, &m_databaseAttr, &m_domainAttr);
252 }
253 if (!processPoolAttributes(m_domainAttr, outputConnection, contextId).isSuccess()) {
254 ATH_MSG_DEBUG("connectOutput failed process POOL domain attributes.");
255 }
256 if (!processPoolAttributes(m_databaseAttr, outputConnection, contextId).isSuccess()) {
257 ATH_MSG_DEBUG("connectOutput failed process POOL database attributes.");
258 }
259 return(StatusCode::SUCCESS);
260}
void extractPoolAttributes(const Gaudi::Property< std::vector< std::string > > &property, std::vector< std::vector< std::string > > *contAttr, std::vector< std::vector< std::string > > *dbAttr, std::vector< std::vector< std::string > > *domAttr=0) const
Extract POOL ItechnologySpecificAttributes for Domain, Database and Container from property.
std::set< unsigned int > m_processedContextIds
Track context IDs for which extractPoolAttributes has been called.

◆ connectOutput() [2/2]

StatusCode AthenaPoolCnvSvc::connectOutput ( const std::string & outputConnectionSpec,
const std::string & openMode )
overridevirtual

Implementation of IConversionSvc: Connect to the output connection specification with open mode.

Parameters
outputConnectionSpec[IN] the name of the output connection specification as string.
openMode[IN] the open mode of the file as string.

Definition at line 230 of file AthenaPoolCnvSvc.cxx.

231 {
232 return(connectOutput(outputConnectionSpec));
233}

◆ convertAddress()

StatusCode AthenaPoolCnvSvc::convertAddress ( const IOpaqueAddress * pAddress,
std::string & refAddress )
overridevirtual

Convert address to string form.

Parameters
pAddress[IN] address to be converted.
refAddress[OUT] converted string form.

Definition at line 395 of file AthenaPoolCnvSvc.cxx.

396 {
397 assert(pAddress);
398 const TokenAddress* tokAddr = dynamic_cast<const TokenAddress*>(pAddress);
399 if (tokAddr != nullptr && tokAddr->getToken() != nullptr) {
400 refAddress = tokAddr->getToken()->toString();
401 } else {
402 refAddress = *pAddress->par();
403 }
404 return(StatusCode::SUCCESS);
405}
This class provides a Generic Transient Address for POOL tokens.
Token * getToken()
virtual const std::string toString() const
Retrieve the string representation of the token.
Definition Token.cxx:134

◆ createAddress() [1/2]

StatusCode AthenaPoolCnvSvc::createAddress ( long svcType,
const CLID & clid,
const std::string & refAddress,
IOpaqueAddress *& refpAddress )
overridevirtual

Create address from string form.

Parameters
svcType[IN] service type of the address.
clid[IN] class id for the address.
refAddress[IN] string form to be converted.
refpAddress[OUT] converted address.

Definition at line 383 of file AthenaPoolCnvSvc.cxx.

386 {
387 if (svcType != repSvcType()) {
388 ATH_MSG_ERROR("createAddress: svcType != POOL_StorageType " << svcType << " " << repSvcType());
389 return(StatusCode::FAILURE);
390 }
391 refpAddress = new GenericAddress(repSvcType(), clid, refAddress);
392 return(StatusCode::SUCCESS);
393}

◆ createAddress() [2/2]

StatusCode AthenaPoolCnvSvc::createAddress ( long svcType,
const CLID & clid,
const std::string * par,
const unsigned long * ip,
IOpaqueAddress *& refpAddress )
override

Create a Generic address using explicit arguments to identify a single object.

Parameters
svcType[IN] service type of the address.
clid[IN] class id for the address.
par[IN] string containing the database name.
ip[IN] object identifier.
refpAddress[OUT] converted address.

Definition at line 353 of file AthenaPoolCnvSvc.cxx.

357 {
358 if( svcType != repSvcType() ) {
359 ATH_MSG_ERROR("createAddress: svcType != POOL_StorageType " << svcType << " " << repSvcType());
360 return(StatusCode::FAILURE);
361 }
362 std::unique_ptr<Token> token;
363 if (par[0].compare(0, 3, "SHM") == 0) {
364 token = std::make_unique<Token>();
365 token->setOid(Token::OID_t(ip[0], ip[1]));
366 token->setAuxString("[PNAME=" + par[2] + "]");
367 RootType classDesc = RootType::ByNameNoQuiet(par[2]);
368 token->setClassID(pool::DbReflex::guid(classDesc));
369 } else {
370 Token *t = m_poolSvc->getToken(par[0], par[1], ip[0]);
371 if( t ) {
372 token = std::make_unique<Token>(t);
373 t->release();
374 }
375 }
376 if (token == nullptr) {
377 return(StatusCode::RECOVERABLE);
378 }
379 refpAddress = new TokenAddress(repSvcType(), clid, "", par[1], IPoolSvc::kInputStream, std::move(token));
380 return(StatusCode::SUCCESS);
381}
TTypeAdapter RootType
Definition RootType.h:211
@ kInputStream
Definition IPoolSvc.h:40
static TScopeAdapter ByNameNoQuiet(const std::string &name, Bool_t load=kTRUE)
Definition RootType.cxx:586
static Guid guid(const TypeH &id)
Determine Guid (normalized string form) from reflection type.

◆ createObj()

StatusCode AthenaPoolCnvSvc::createObj ( IOpaqueAddress * pAddress,
DataObject *& refpObject )
overridevirtual

Implementation of IConversionSvc: Create the transient representation of an object from persistent state.

Parameters
pAddress[IN] pointer to IOpaqueAddress of the representation.
refpObject[OUT] pointer to DataObject to be created.

Definition at line 134 of file AthenaPoolCnvSvc.cxx.

134 {
135 assert(pAddress);
136 std::string objName = "ALL";
137 if (m_useDetailChronoStat.value()) {
138 if (m_clidSvc->getTypeNameOfID(pAddress->clID(), objName).isFailure()) {
139 objName = std::to_string(pAddress->clID());
140 }
141 objName += '#';
142 objName += *(pAddress->par() + 1);
143 }
144 // StopWatch listens from here until the end of this current scope
145 PMonUtils::BasicStopWatch stopWatch("cObj_" + objName, m_chronoMap);
146 if (!m_persSvcPerInputType.value().empty()) { // Use separate PersistencySvc for each input data type
147 TokenAddress* tokAddr = dynamic_cast<TokenAddress*>(pAddress);
148 if (tokAddr != nullptr && tokAddr->getToken() != nullptr && (tokAddr->getToken()->contID().starts_with(m_persSvcPerInputType.value() + "(") || tokAddr->getToken()->contID().starts_with(m_persSvcPerInputType.value() + "_"))) {
149 const unsigned int maxContext = m_poolSvc->getInputContextMapSize();
150 const unsigned int auxContext = m_poolSvc->getInputContext(tokAddr->getToken()->classID().toString() + tokAddr->getToken()->dbID().toString(), 1);
151 if (m_poolSvc->getInputContextMapSize() > maxContext) {
152 if (!processPoolAttributes(m_inputAttr, m_lastInputFileName, auxContext, false, true, false).isSuccess()) {
153 ATH_MSG_DEBUG("setInputAttribute failed setting POOL database/container attributes.");
154 }
155 }
156 char text[32];
157 const std::string contextStr = std::format("[CTXT={:08X}]", auxContext);
158 std::strncpy(text, contextStr.c_str(), sizeof(text) - 1);
159 text[sizeof(text) - 1] = '\0';
160 tokAddr->getToken()->setAuxString(text);
161 }
162 }
163 // Forward to base class createObj
164 StatusCode status = ::AthCnvSvc::createObj(pAddress, refpObject);
165 return(status);
166}
virtual StatusCode createObj(IOpaqueAddress *pAddress, DataObject *&refpObject) override
Implementation of IConverter: Create the transient representation of an object.
Gaudi::Property< std::string > m_persSvcPerInputType
PersSvcPerInputType, string property, tree name to use multiple persistency services,...
constexpr void toString(std::span< char, StrLen > buf, bool uppercase=true) const noexcept
Automatic conversion to string representation.
Token & setAuxString(const std::string &auxString)
Set auxiliary string.
Definition Token.h:93
const std::string & contID() const
Access container identifier.
Definition Token.h:69
const Guid & classID() const
Access database identifier.
Definition Token.h:73
const Guid & dbID() const
Access database identifier.
Definition Token.h:64
::StatusCode StatusCode
StatusCode definition for legacy code.
status
Definition merge.py:16

◆ createRep()

StatusCode AthenaPoolCnvSvc::createRep ( DataObject * pObject,
IOpaqueAddress *& refpAddress )
overridevirtual

Implementation of IConversionSvc: Convert the transient object to the requested representation.

Parameters
pObject[IN] pointer to DataObject.
refpAddress[OUT] pointer to IOpaqueAddress of the representation to be created.

Definition at line 168 of file AthenaPoolCnvSvc.cxx.

168 {
169 assert(pObject);
170 std::string objName = "ALL";
171 if (m_useDetailChronoStat.value()) {
172 if (m_clidSvc->getTypeNameOfID(pObject->clID(), objName).isFailure()) {
173 objName = std::to_string(pObject->clID());
174 }
175 objName += '#';
176 objName += pObject->registry()->name();
177 }
178 // StopWatch listens from here until the end of this current scope
179 PMonUtils::BasicStopWatch stopWatch("cRep_" + objName, m_chronoMap);
180 StatusCode status = StatusCode::FAILURE;
181 if (pObject->clID() == 1) {
182 // No transient object was found use cnv to write default persistent object
183 SG::DataProxy* proxy = dynamic_cast<SG::DataProxy*>(pObject->registry());
184 if (proxy != nullptr) {
185 IConverter* cnv = converter(proxy->clID());
186 status = cnv->createRep(pObject, refpAddress);
187 }
188 } else {
189 // Forward to base class createRep
190 try {
191 status = ::AthCnvSvc::createRep(pObject, refpAddress);
192 } catch(std::runtime_error& e) {
193 ATH_MSG_FATAL(e.what());
194 }
195 }
196 return(status);
197}
#define ATH_MSG_FATAL(x)
virtual StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress) override
Implementation of IConverter: Convert the transient object to the requested representation.

◆ disconnectOutput()

StatusCode AthenaPoolCnvSvc::disconnectOutput ( const std::string & outputConnectionSpec)
overridevirtual

Disconnect to the output connection.

Definition at line 306 of file AthenaPoolCnvSvc.cxx.

306 {
307 std::string outputConnection = outputConnectionSpec.substr(0, outputConnectionSpec.find('['));
308 unsigned int contextId = outputContextId(outputConnection);
309 StatusCode sc = m_poolSvc->disconnect(contextId);
310 return sc;
311}
static Double_t sc

◆ extractPoolAttributes()

void AthenaPoolCnvSvc::extractPoolAttributes ( const Gaudi::Property< std::vector< std::string > > & property,
std::vector< std::vector< std::string > > * contAttr,
std::vector< std::vector< std::string > > * dbAttr,
std::vector< std::vector< std::string > > * domAttr = 0 ) const
private

Extract POOL ItechnologySpecificAttributes for Domain, Database and Container from property.

Definition at line 467 of file AthenaPoolCnvSvc.cxx.

470 {
471 std::vector<std::string> opt;
472 std::string attributeName, containerName, databaseName, valueString;
473 for (const auto& propertyValue : property.value()) {
474 opt.clear();
475 attributeName.clear();
476 containerName.clear();
477 databaseName.clear();
478 valueString.clear();
479 using Gaudi::Utils::AttribStringParser;
480 for (const AttribStringParser::Attrib& attrib : AttribStringParser (propertyValue)) {
481 if (attrib.tag == "DatabaseName") {
482 databaseName = attrib.value;
483 } else if (attrib.tag == "ContainerName") {
484 if (databaseName.empty()) {
485 databaseName = "*";
486 }
487 containerName = attrib.value;
488 } else {
489 attributeName = attrib.tag;
490 valueString = attrib.value;
491 }
492 }
493 if (!attributeName.empty() && !valueString.empty()) {
494 opt.push_back(attributeName);
495 opt.push_back(valueString);
496 if (!databaseName.empty()) {
497 opt.push_back(databaseName);
498 if (!containerName.empty()) {
499 opt.push_back(containerName);
500 if (containerName.compare(0, 6, "TTree=") == 0) {
501 dbAttr->push_back(opt);
502 } else {
503 contAttr->push_back(opt);
504 }
505 } else {
506 opt.push_back("");
507 dbAttr->push_back(opt);
508 }
509 } else if (domAttr != 0) {
510 domAttr->push_back(opt);
511 } else {
512 opt.push_back("*");
513 opt.push_back("");
514 dbAttr->push_back(opt);
515 }
516 }
517 }
518}

◆ fillRepRefs()

StatusCode AthenaPoolCnvSvc::fillRepRefs ( IOpaqueAddress * pAddress,
DataObject * pObject )
overridevirtual

Implementation of IConversionSvc: Resolve the references of the converted object.

Parameters
pAddress[IN] pointer to IOpaqueAddress of the representation to be resolved.
pObject[IN] pointer to DataObject to be created.

Definition at line 199 of file AthenaPoolCnvSvc.cxx.

199 {
200 assert(pObject);
201 std::string objName = "ALL";
202 if (m_useDetailChronoStat.value()) {
203 if (m_clidSvc->getTypeNameOfID(pObject->clID(), objName).isFailure()) {
204 objName = std::to_string(pObject->clID());
205 }
206 objName += '#';
207 objName += pObject->registry()->name();
208 }
209 // StopWatch listens from here until the end of this current scope
210 PMonUtils::BasicStopWatch stopWatch("fRep_" + objName, m_chronoMap);
211 StatusCode status = StatusCode::FAILURE;
212 if (pObject->clID() == 1) {
213 // No transient object was found use cnv to write default persistent object
214 SG::DataProxy* proxy = dynamic_cast<SG::DataProxy*>(pObject->registry());
215 if (proxy != nullptr) {
216 IConverter* cnv = converter(proxy->clID());
217 status = cnv->fillRepRefs(pAddress, pObject);
218 }
219 } else {
220 // Forward to base class fillRepRefs
221 try {
222 status = ::AthCnvSvc::fillRepRefs(pAddress, pObject);
223 } catch(std::runtime_error& e) {
224 ATH_MSG_FATAL(e.what());
225 }
226 }
227 return(status);
228}
virtual StatusCode fillRepRefs(IOpaqueAddress *pAddress, DataObject *pObject) override
Implementation of IConverter: Resolve the references of the converted object.

◆ finalize()

StatusCode AthenaPoolCnvSvc::finalize ( )
overridevirtual

Required of all Gaudi Services.

Definition at line 100 of file AthenaPoolCnvSvc.cxx.

100 {
101 ATH_MSG_VERBOSE("Finalizing...");
102 // Some algorithms write in finalize(), flush DHForms if any are left
103 flushDataHeaderForms();
104 // Release ClassIDSvc
105 if (!m_clidSvc.release().isSuccess()) {
106 ATH_MSG_WARNING("Cannot release ClassIDSvc.");
107 }
108 // Release PoolSvc
109 if (!m_poolSvc.release().isSuccess()) {
110 ATH_MSG_WARNING("Cannot release PoolSvc.");
111 }
112 // Print Performance Statistics
113 // The pattern AthenaPoolCnvSvc.*PerfStats is ignored in AtlasTest/TestTools/share/post.sh
114 const std::string msgPrefix{"PerfStats "};
115 ATH_MSG_INFO(msgPrefix << std::string(40, '-'));
116 ATH_MSG_INFO(msgPrefix << "Timing Measurements for AthenaPoolCnvSvc");
117 ATH_MSG_INFO(msgPrefix << std::string(40, '-'));
118 for(const auto& [key, value] : m_chronoMap) {
119 ATH_MSG_INFO(msgPrefix << "| " << std::left << std::setw(15) << key << " | "
120 << std::right << std::setw(15) << std::fixed << std::setprecision(0) << value << " ms |");
121 }
122 ATH_MSG_INFO(msgPrefix << std::string(40, '-'));
123
124 m_cnvs.clear();
125 m_cnvs.shrink_to_fit();
126 return(StatusCode::SUCCESS);
127}
#define ATH_MSG_INFO(x)

◆ flushDataHeaderForms()

void AthenaPoolCnvSvc::flushDataHeaderForms ( const std::string & streamName = "*")

Tell DataHeaderCnv to write out all DataHeaderForms for a given streamName (default is all).

Definition at line 86 of file AthenaPoolCnvSvc.cxx.

86 {
87 // Write remaining DataHeaderForms for a given streamName, "*"" means all
88 auto DHCnvListener = dynamic_cast<IIncidentListener*>( converter( ClassID_traits<DataHeader>::ID() ) );
89 FileIncident incident(name(), "WriteDataHeaderForms", streamName);
90 if( DHCnvListener ) DHCnvListener->handle(incident);
91}

◆ getPoolSvc()

IPoolSvc * AthenaPoolCnvSvc::getPoolSvc ( )
overridevirtual
Returns
pointer to PoolSvc instance.

Definition at line 320 of file AthenaPoolCnvSvc.cxx.

320 {
321 return(&*m_poolSvc);
322}

◆ handle()

void AthenaPoolCnvSvc::handle ( const Incident & incident)
overridevirtual

Implementation of IIncidentListener: Handle for EndEvent incidence.

Definition at line 455 of file AthenaPoolCnvSvc.cxx.

455 {
456 if (incident.type() == "EndEvent") {
457 if (!processPoolAttributes(m_inputAttrPerEvent, m_lastInputFileName, IPoolSvc::kInputStream).isSuccess()) {
458 ATH_MSG_DEBUG("handle EndEvent failed process POOL database attributes.");
459 }
460 }
461}

◆ initialize()

StatusCode AthenaPoolCnvSvc::initialize ( )
overridevirtual

Required of all Gaudi Services.

Definition at line 35 of file AthenaPoolCnvSvc.cxx.

35 {
36 // Retrieve PoolSvc
37 ATH_CHECK(m_poolSvc.retrieve());
38 // Retrieve ClassIDSvc
39 ATH_CHECK(m_clidSvc.retrieve());
40 // Register this service for 'I/O' events
41 ServiceHandle<IIoComponentMgr> iomgr("IoComponentMgr", name());
42 ATH_CHECK(iomgr.retrieve());
43 if (!iomgr->io_register(this).isSuccess()) {
44 ATH_MSG_FATAL("Could not register myself with the IoComponentMgr !");
45 return(StatusCode::FAILURE);
46 }
47 // Global POOL container naming scheme
48 if (auto scheme = APRDefaults::WriteConfig::parseNamingScheme(m_containerNamingSchemeProp.value())) {
50 } else {
51 ATH_MSG_ERROR(std::format("Invalid PoolContainerNamingScheme: {}, see APRDefaults.h for the full list.", m_containerNamingSchemeProp.value()));
52 return StatusCode::FAILURE;
53 }
54 // Extracting INPUT POOL ItechnologySpecificAttributes for Domain, Database and Container.
55 extractPoolAttributes(m_inputPoolAttr, &m_inputAttr, &m_inputAttr, &m_inputAttr);
56 // Extracting the INPUT POOL ItechnologySpecificAttributes which are to be printed for each event
57 extractPoolAttributes(m_inputPoolAttrPerEvent, &m_inputAttrPerEvent, &m_inputAttrPerEvent, &m_inputAttrPerEvent);
58 // Setup incident for EndEvent to print out attributes each event
59 ServiceHandle<IIncidentSvc> incSvc("IncidentSvc", name());
60 long int pri = 1000;
61 if (!m_inputPoolAttrPerEvent.value().empty()) {
62 // Set to be listener for EndEvent
63 incSvc->addListener(this, "EndEvent", pri);
64 ATH_MSG_DEBUG("Subscribed to EndEvent for printing out input file attributes.");
65 }
66 if (!processPoolAttributes(m_inputAttr, "", IPoolSvc::kInputStream, false, true, true).isSuccess()) {
67 ATH_MSG_DEBUG("setInputAttribute failed setting POOL domain attributes.");
68 }
69
70 // Load these dictionaries now, so we don't need to try to do so
71 // while multiple threads are running.
72 TClass::GetClass ("TLeafI");
73 TClass::GetClass ("TLeafL");
74 TClass::GetClass ("TLeafD");
75 TClass::GetClass ("TLeafF");
76
77 return(StatusCode::SUCCESS);
78}
#define ATH_CHECK
Evaluate an expression and check for errors.
Gaudi::Property< std::string > m_containerNamingSchemeProp
POOL container naming scheme selection.
Gaudi::Property< std::vector< std::string > > m_inputPoolAttrPerEvent
Print input PoolAttributes per event, vector with names of technology specific attributes for POOL to...
std::optional< NamingScheme > parseNamingScheme(std::string_view name)
Definition APRDefaults.h:89
void setNamingScheme(NamingScheme scheme)
Definition APRDefaults.h:79

◆ io_finalize()

StatusCode AthenaPoolCnvSvc::io_finalize ( )
overridevirtual

Definition at line 129 of file AthenaPoolCnvSvc.cxx.

129 {
130 ATH_MSG_DEBUG("I/O finalization...");
131 return(StatusCode::SUCCESS);
132}

◆ io_reinit()

StatusCode AthenaPoolCnvSvc::io_reinit ( )
overridevirtual

Definition at line 80 of file AthenaPoolCnvSvc.cxx.

80 {
81 ATH_MSG_DEBUG("I/O reinitialization...");
82 m_processedContextIds.clear();
83 return(StatusCode::SUCCESS);
84}

◆ outputContextId()

unsigned int AthenaPoolCnvSvc::outputContextId ( const std::string & outputConnection)
protected

Definition at line 314 of file AthenaPoolCnvSvc.cxx.

314 {
315 return m_persSvcPerOutput?
316 m_poolSvc->getOutputContext(outputConnection) : (unsigned int)IPoolSvc::kOutputStream;
317}
@ kOutputStream
Definition IPoolSvc.h:40

◆ processPoolAttributes()

StatusCode AthenaPoolCnvSvc::processPoolAttributes ( std::vector< std::vector< std::string > > & attr,
const std::string & fileName,
unsigned long contextId,
bool doGet = true,
bool doSet = true,
bool doClear = true ) const
private

Set/get technology dependent POOL attributes.

Definition at line 520 of file AthenaPoolCnvSvc.cxx.

525 {
526 bool retError = false;
527 for (auto& attrEntry : attr) {
528 if (attrEntry.size() == 2) {
529 const std::string& opt = attrEntry[0];
530 std::string data = attrEntry[1];
531 if (data == "int" || data == "DbLonglong" || data == "double" || data == "string") {
532 if (doGet) {
533 if (!m_poolSvc->getAttribute(opt, data, pool::DbType(pool::ROOTTREE_StorageType).type(), contextId).isSuccess()) {
534 ATH_MSG_DEBUG("getAttribute failed for domain attr " << opt);
535 retError = true;
536 }
537 }
538 } else if (doSet) {
539 if (m_poolSvc->setAttribute(opt, data, pool::DbType(pool::ROOTTREE_StorageType).type(), contextId).isSuccess()) {
540 ATH_MSG_DEBUG("setAttribute " << opt << " to " << data);
541 if (doClear) {
542 attrEntry.clear();
543 }
544 } else {
545 ATH_MSG_DEBUG("setAttribute failed for domain attr " << opt << " to " << data);
546 retError = true;
547 }
548 }
549 }
550 if (attrEntry.size() == 4) {
551 const std::string& opt = attrEntry[0];
552 std::string data = attrEntry[1];
553 const std::string& file = attrEntry[2];
554 const std::string& cont = attrEntry[3];
555 if (!fileName.empty() && (0 == fileName.compare(0, fileName.find('?'), file)
556 || (file[0] == '*' && file.find("," + fileName + ",") == std::string::npos))) {
557 if (data == "int" || data == "DbLonglong" || data == "double" || data == "string") {
558 if (doGet) {
559 if (!m_poolSvc->getAttribute(opt, data, pool::DbType(pool::ROOTTREE_StorageType).type(), fileName, cont, contextId).isSuccess()) {
560 ATH_MSG_DEBUG("getAttribute failed for database/container attr " << opt);
561 retError = true;
562 }
563 }
564 } else if (doSet) {
565 if (m_poolSvc->setAttribute(opt, data, pool::DbType(pool::ROOTTREE_StorageType).type(), fileName, cont, contextId).isSuccess()) {
566 ATH_MSG_DEBUG("setAttribute " << opt << " to " << data << " for db: " << fileName << " and cont: " << cont);
567 if (doClear) {
568 if (file[0] == '*' && !m_persSvcPerOutput) {
569 attrEntry[2] += "," + fileName + ",";
570 } else {
571 attrEntry.clear();
572 }
573 }
574 } else {
575 ATH_MSG_DEBUG("setAttribute failed for " << opt << " to " << data << " for db: " << fileName << " and cont: " << cont);
576 retError = true;
577 }
578 }
579 }
580 }
581 }
582 std::erase_if(attr, [](const auto& entry) { return entry.empty(); });
583 return(retError ? StatusCode::FAILURE : StatusCode::SUCCESS);
584}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
int type() const
Access to full type.
Definition DbType.h:65
static const DbType ROOTTREE_StorageType
Definition DbType.h:87
std::size_t erase_if(T_container &container, T_Func pred)
TFile * file

◆ registerCleanUp()

StatusCode AthenaPoolCnvSvc::registerCleanUp ( IAthenaPoolCleanUp * cnv)
overridevirtual

Implement registerCleanUp to register a IAthenaPoolCleanUp to be called during cleanUp.

Definition at line 407 of file AthenaPoolCnvSvc.cxx.

407 {
408 m_cnvs.push_back(cnv);
409 return(StatusCode::SUCCESS);
410}

◆ registerForWrite()

Token * AthenaPoolCnvSvc::registerForWrite ( Placement * placement,
const void * obj,
const RootType & classDesc )
overridevirtual
Returns
a string token to a Data Object written to Pool
Parameters
placement[IN] pointer to the placement hint
obj[IN] pointer to the Data Object to be written to Pool
classDesc[IN] pointer to the Seal class description for the Data Object.

Definition at line 324 of file AthenaPoolCnvSvc.cxx.

324 {
325 // StopWatch listens from here until the end of this current scope
326 PMonUtils::BasicStopWatch stopWatch("cRepR_ALL", m_chronoMap);
327 Token* token = nullptr;
328 if (m_persSvcPerOutput) { // Use separate PersistencySvc for each output stream/file
329 char text[32];
330 const std::string contextStr = std::format("[CTXT={:08X}]", m_poolSvc->getOutputContext(placement->fileName()));
331 std::strncpy(text, contextStr.c_str(), sizeof(text) - 1);
332 text[sizeof(text) - 1] = '\0';
333 placement->setAuxString(text);
334 }
335 token = m_poolSvc->registerForWrite(placement, obj, classDesc);
336 return(token);
337}
Placement & setAuxString(const std::string &auxString)
Set auxiliary string.
Definition Placement.h:42
const std::string & fileName() const
Access file name.
Definition Placement.h:28
This class provides a token that identifies in a unique way objects on the persistent storage.
Definition Token.h:21

◆ setInputAttributes()

StatusCode AthenaPoolCnvSvc::setInputAttributes ( const std::string & fileName)
overridevirtual

Set the input file attributes, if any are requested from jobOpts.

Parameters
fileName[IN] name of the input file

Definition at line 433 of file AthenaPoolCnvSvc.cxx.

433 {
434 // Set attributes for input file
435 m_lastInputFileName = fileName; // Save file name for printing attributes per event
436 if (!m_persSvcPerInputType.empty()) {
437// Loop over all extra event input contexts
438 const auto& extraInputContextMap = m_poolSvc->getInputContextMap();
439 for (const auto& [label, id]: extraInputContextMap) {
440 if (!processPoolAttributes(m_inputAttr, m_lastInputFileName, id, false, true, false).isSuccess()) {
441 ATH_MSG_DEBUG("setInputAttribute failed setting POOL database/container attributes.");
442 }
443 }
444 }
445 if (!processPoolAttributes(m_inputAttr, m_lastInputFileName, IPoolSvc::kInputStream, false, true, false).isSuccess()) {
446 ATH_MSG_DEBUG("setInputAttribute failed setting POOL database/container attributes.");
447 }
448 if (!processPoolAttributes(m_inputAttr, m_lastInputFileName, IPoolSvc::kInputStream, true, false).isSuccess()) {
449 ATH_MSG_DEBUG("setInputAttribute failed getting POOL database/container attributes.");
450 }
451 return(StatusCode::SUCCESS);
452}
std::string label(const std::string &format, int i)
Definition label.h:19

◆ setObjPtr()

void AthenaPoolCnvSvc::setObjPtr ( void *& obj,
const Token * token )
overridevirtual
Parameters
obj[OUT] pointer to the Data Object.
token[IN] string token of the Data Object for which a Pool Ref is filled.

Definition at line 339 of file AthenaPoolCnvSvc.cxx.

339 {
340 ATH_MSG_VERBOSE("Requesting object for: " << token->toString());
341 // StopWatch listens from here until the end of this current scope
342 PMonUtils::BasicStopWatch stopWatch("cObjR_ALL", m_chronoMap);
343 if (token->dbID() != Guid::null()) {
344 ATH_MSG_VERBOSE("Requesting object for: " << token->toString());
345 m_poolSvc->setObjPtr(obj, token);
346 }
347}
static const Guid & null() noexcept
NULL-Guid: static class method.
Definition Guid.cxx:14

◆ stop()

StatusCode AthenaPoolCnvSvc::stop ( )
overridevirtual

Definition at line 93 of file AthenaPoolCnvSvc.cxx.

93 {
94 ATH_MSG_VERBOSE("stop()");
95 // In case of direct writing without an OutputStream, this should be a good time to flush DHForms
96 flushDataHeaderForms();
97 return StatusCode::SUCCESS;
98}

◆ useDetailChronoStat()

bool AthenaPoolCnvSvc::useDetailChronoStat ( ) const
overridevirtual
Returns
a boolean for using detailed time and size statistics.

Definition at line 349 of file AthenaPoolCnvSvc.cxx.

349 {
350 return(m_useDetailChronoStat.value());
351}

◆ SvcFactory< AthenaPoolCnvSvc >

friend class SvcFactory< AthenaPoolCnvSvc >
friend

Definition at line 1 of file AthenaPoolCnvSvc.h.

Member Data Documentation

◆ m_chronoMap

PMonUtils::BasicStopWatchResultMap_t AthenaPoolCnvSvc::m_chronoMap {}
protected

Map that holds chrono information.

Definition at line 177 of file AthenaPoolCnvSvc.h.

177{};

◆ m_clidSvc

ServiceHandle<IClassIDSvc> AthenaPoolCnvSvc::m_clidSvc {this,"ClassIDSvc","ClassIDSvc"}
private

Definition at line 173 of file AthenaPoolCnvSvc.h.

173{this,"ClassIDSvc","ClassIDSvc"};

◆ m_containerAttr

std::vector<std::vector<std::string> > AthenaPoolCnvSvc::m_containerAttr
private

Definition at line 191 of file AthenaPoolCnvSvc.h.

◆ m_containerNamingSchemeProp

Gaudi::Property<std::string> AthenaPoolCnvSvc::m_containerNamingSchemeProp {this, "PoolContainerNamingScheme", "Historical"}
private

POOL container naming scheme selection.

Definition at line 185 of file AthenaPoolCnvSvc.h.

185{this, "PoolContainerNamingScheme", "Historical"};

◆ m_databaseAttr

std::vector<std::vector<std::string> > AthenaPoolCnvSvc::m_databaseAttr
private

Definition at line 190 of file AthenaPoolCnvSvc.h.

◆ m_DHFilterAliases

Gaudi::Property<bool> AthenaPoolCnvSvc::m_DHFilterAliases { this, "doFilterDHAliases", true }
protected

Flag to control SG alias filtering when writing out DataHeader (see DataHeaderCnv_p6).

Definition at line 222 of file AthenaPoolCnvSvc.h.

222{ this, "doFilterDHAliases", true };

◆ m_DHFormCacheSize

Gaudi::Property<int> AthenaPoolCnvSvc::m_DHFormCacheSize { this, "maxDHFormCacheSize", 100 }
protected

Property for DataHeaderCnv input DHForm cache size.

Definition at line 219 of file AthenaPoolCnvSvc.h.

219{ this, "maxDHFormCacheSize", 100 };

◆ m_domainAttr

std::vector<std::vector<std::string> > AthenaPoolCnvSvc::m_domainAttr
private

Definition at line 189 of file AthenaPoolCnvSvc.h.

◆ m_inputAttr

std::vector<std::vector<std::string> > AthenaPoolCnvSvc::m_inputAttr
private

Definition at line 195 of file AthenaPoolCnvSvc.h.

◆ m_inputAttrPerEvent

std::vector<std::vector<std::string> > AthenaPoolCnvSvc::m_inputAttrPerEvent
private

Definition at line 199 of file AthenaPoolCnvSvc.h.

◆ m_inputPoolAttr

Gaudi::Property<std::vector<std::string> > AthenaPoolCnvSvc::m_inputPoolAttr {this,"InputPoolAttributes",{}}
private

Input PoolAttributes, vector with names and values of technology specific attributes for POOL.

Definition at line 194 of file AthenaPoolCnvSvc.h.

194{this,"InputPoolAttributes",{}};

◆ m_inputPoolAttrPerEvent

Gaudi::Property<std::vector<std::string> > AthenaPoolCnvSvc::m_inputPoolAttrPerEvent {this,"PrintInputAttrPerEvt",{}}
private

Print input PoolAttributes per event, vector with names of technology specific attributes for POOL to be printed each event.

Definition at line 198 of file AthenaPoolCnvSvc.h.

198{this,"PrintInputAttrPerEvt",{}};

◆ m_lastInputFileName

std::string AthenaPoolCnvSvc::m_lastInputFileName
private

decoded storage tech requested in "StorageTechnology" property

Definition at line 171 of file AthenaPoolCnvSvc.h.

◆ m_mutex

std::mutex AthenaPoolCnvSvc::m_mutex
protected

Definition at line 210 of file AthenaPoolCnvSvc.h.

◆ m_oneDataHeaderForm

Gaudi::Property<bool> AthenaPoolCnvSvc::m_oneDataHeaderForm { this, "OneDataHeaderForm", false }
protected

If true, use only one DataHeaderForm per Stream.

Definition at line 216 of file AthenaPoolCnvSvc.h.

216{ this, "OneDataHeaderForm", false };

◆ m_persSvcPerInputType

Gaudi::Property<std::string> AthenaPoolCnvSvc::m_persSvcPerInputType {this,"PersSvcPerInputType",""}
protected

PersSvcPerInputType, string property, tree name to use multiple persistency services, one per input type.

default = "", no tree name results in a single persistency service.

Definition at line 209 of file AthenaPoolCnvSvc.h.

209{this,"PersSvcPerInputType",""};

◆ m_persSvcPerOutput

Gaudi::Property<bool> AthenaPoolCnvSvc::m_persSvcPerOutput {this,"PersSvcPerOutput",true}
protected

PersSvcPerOutput, boolean property to use multiple persistency services, one per output stream.

default = true.

Definition at line 204 of file AthenaPoolCnvSvc.h.

204{this,"PersSvcPerOutput",true};

◆ m_poolAttr

Gaudi::Property<std::vector<std::string> > AthenaPoolCnvSvc::m_poolAttr {this,"PoolAttributes",{},"Pool Attributes","OrderedSet<std::string>"}
private

Output PoolAttributes, vector with names and values of technology specific attributes for POOL.

Definition at line 188 of file AthenaPoolCnvSvc.h.

188{this,"PoolAttributes",{},"Pool Attributes","OrderedSet<std::string>"};

◆ m_poolSvc

ServiceHandle<IPoolSvc> AthenaPoolCnvSvc::m_poolSvc {this,"PoolSvc","PoolSvc"}
private

Definition at line 172 of file AthenaPoolCnvSvc.h.

172{this,"PoolSvc","PoolSvc"};

◆ m_processedContextIds

std::set<unsigned int> AthenaPoolCnvSvc::m_processedContextIds
protected

Track context IDs for which extractPoolAttributes has been called.

Definition at line 213 of file AthenaPoolCnvSvc.h.

◆ m_useDetailChronoStat

Gaudi::Property<bool> AthenaPoolCnvSvc::m_useDetailChronoStat {this,"UseDetailChronoStat",false}
private

UseDetailChronoStat, enable detailed output for time and size statistics for AthenaPOOL: default = false.

Definition at line 182 of file AthenaPoolCnvSvc.h.

182{this,"UseDetailChronoStat",false};

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