ATLAS Offline Software
Loading...
Searching...
No Matches
PoolSvc.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
9
10#include "PoolSvc.h"
11
12#include "GaudiKernel/IIoComponentMgr.h"
13#include "GaudiKernel/ConcurrencyFlags.h"
14
16
17#include "CoralKernel/Context.h"
18
21
23
25#include "POOLCore/DbPrint.h"
33#include "StorageSvc/DbType.h"
34
35#include "RelationalAccess/ConnectionService.h"
36#include "RelationalAccess/IConnectionServiceConfiguration.h"
37#include "RelationalAccess/IWebCacheControl.h"
38#include "RelationalAccess/IWebCacheInfo.h"
39#include "RelationalAccess/ILookupService.h"
40#include "RelationalAccess/IDatabaseServiceSet.h"
41#include "RelationalAccess/IDatabaseServiceDescription.h"
42
44
45#include <cstdlib>
46#include <cstring>
47#include <algorithm>
48#include <cstdio>
49#include <cctype>
50#include <exception> // for runtime_error
51
52bool isNumber(const std::string& s) {
53 return !s.empty() && (std::isdigit(s[0]) || s[0] == '+' || s[0] == '-');
54}
55
56//__________________________________________________________________________
57StatusCode PoolSvc::initialize() {
58 ATH_CHECK(::AthService::initialize());
59
60 // Register this service for 'I/O' events
61 ServiceHandle<IIoComponentMgr> iomgr("IoComponentMgr", name());
62 ATH_CHECK(iomgr.retrieve());
63 ATH_CHECK(iomgr->io_register(this));
64 // Register input file's names with the I/O manager, unless in SharedWrite mode, set by AthenaPoolCnvSvc
65 bool allGood = true;
66 for (const auto& catalog : m_readCatalog.value()) {
67 if (catalog.starts_with("xmlcatalog_file:")) {
68 const std::string fileName = catalog.substr(16);
69 if (!iomgr->io_register(this, IIoComponentMgr::IoMode::READ, fileName, fileName).isSuccess()) {
70 ATH_MSG_FATAL("could not register [" << catalog << "] for input !");
71 allGood = false;
72 } else {
73 ATH_MSG_INFO("io_register[" << this->name() << "](" << catalog << ") [ok]");
74 }
75 }
76 }
77 if (m_writeCatalog.value().starts_with("xmlcatalog_file:")) {
78 const std::string fileName = m_writeCatalog.value().substr(16);
79 if (!iomgr->io_register(this, IIoComponentMgr::IoMode::WRITE, fileName, fileName).isSuccess()) {
80 ATH_MSG_FATAL("could not register [" << m_writeCatalog.value() << "] for input !");
81 allGood = false;
82 } else {
83 ATH_MSG_INFO("io_register[" << this->name() << "](" << m_writeCatalog.value() << ") [ok]");
84 }
85 }
86 if (!allGood) {
87 return(StatusCode::FAILURE);
88 }
89 m_context = &coral::Context::instance();
90 if (m_context == nullptr) {
91 ATH_MSG_FATAL("Failed to access CORAL Context");
92 return(StatusCode::FAILURE);
93 }
94 coral::ConnectionService conSvcH;
95 coral::IConnectionServiceConfiguration& csConfig = conSvcH.configuration();
96 csConfig.setConnectionRetrialPeriod(m_retrialPeriod);
97 csConfig.setConnectionRetrialTimeOut(m_retrialTimeOut);
98 if (m_connClean) {
99 csConfig.enablePoolAutomaticCleanUp();
100 csConfig.setConnectionTimeOut(m_timeOut);
101 } else {
102 csConfig.disablePoolAutomaticCleanUp();
103 csConfig.setConnectionTimeOut(0);
104 }
105 ATH_MSG_INFO("Set connectionsvc retry/timeout/IDLE timeout to "
107 << "/"
109 << "/"
110 << m_timeOut
111 << " seconds with connection cleanup "
112 << (csConfig.isPoolAutomaticCleanUpEnabled() ? "enabled" : "disabled"));
113 // set Frontier web cache compression level
114 coral::IWebCacheControl& webCache = conSvcH.webCacheControl();
115 webCache.setCompressionLevel(m_frontierComp);
116 ATH_MSG_INFO("Frontier compression level set to " << webCache.compressionLevel());
117 if (m_sortReplicas) {
118 // set replica sorter - get service
119 ServiceHandle<IDBReplicaSvc> replicasvc("DBReplicaSvc", name());
120 if (replicasvc.retrieve().isSuccess()) {
121 csConfig.setReplicaSortingAlgorithm(*replicasvc);
122 ATH_MSG_INFO("Successfully setup replica sorting algorithm");
123 } else {
124 ATH_MSG_WARNING("Cannot setup replica sorting algorithm");
125 }
126 }
127 MSG::Level athLvl = msg().level();
128 ATH_MSG_DEBUG("OutputLevel is " << (int)athLvl);
130 return(setupPersistencySvc());
131}
132
133//__________________________________________________________________________
134StatusCode PoolSvc::io_reinit() {
135 ATH_MSG_INFO("I/O reinitialization...");
136 ServiceHandle<IIoComponentMgr> iomgr("IoComponentMgr", name());
137 if (!iomgr.retrieve().isSuccess()) {
138 ATH_MSG_FATAL("Could not retrieve IoComponentMgr !");
139 return(StatusCode::FAILURE);
140 }
141 if (!iomgr->io_hasitem(this)) {
142 ATH_MSG_FATAL("IoComponentMgr does not know about myself !");
143 return(StatusCode::FAILURE);
144 }
145 std::vector<std::string> readcat = m_readCatalog.value();
146 for (std::size_t icat = 0, imax = readcat.size(); icat < imax; icat++) {
147 if (readcat[icat].compare(0, 16, "xmlcatalog_file:") == 0) {
148 std::string fileName = readcat[icat].substr(16);
149 if (iomgr->io_contains(this, fileName)) {
150 if (!iomgr->io_retrieve(this, fileName).isSuccess()) {
151 ATH_MSG_FATAL("Could not retrieve new value for [" << fileName << "] !");
152 return(StatusCode::FAILURE);
153 }
154 readcat[icat] = "xmlcatalog_file:" + fileName;
155 }
156 }
157 }
158 // all good... copy over.
159 m_readCatalog = readcat;
160 if (m_writeCatalog.value().compare(0, 16, "xmlcatalog_file:") == 0) {
161 std::string fileName = m_writeCatalog.value().substr(16);
162 if (iomgr->io_contains(this, fileName)) {
163 if (!iomgr->io_retrieve(this, fileName).isSuccess()) {
164 ATH_MSG_FATAL("Could not retrieve new value for [" << fileName << "] !");
165 return(StatusCode::FAILURE);
166 }
167 if (!m_shareCat) {
168 m_writeCatalog.setValue("xmlcatalog_file:" + fileName);
169 }
170 }
171 }
172 return(setupPersistencySvc());
173}
174//__________________________________________________________________________
176 clearState();
177 ATH_MSG_INFO("Setting up APR FileCatalog and Streams");
179 if (m_catalog != nullptr) {
180 m_catalog->start();
181 } else {
182 ATH_MSG_FATAL("Failed to setup POOL File Catalog.");
183 return(StatusCode::FAILURE);
184 }
185 // Setup a persistency services
186 m_persistencySvcVec.push_back(pool::IPersistencySvc::create(*m_catalog).release()); // Read Service
187 m_pers_mut.push_back(new CallMutex);
188 if (!m_persistencySvcVec[IPoolSvc::kInputStream]->session().technologySpecificAttributes(pool::ROOT_StorageType.type()).setAttribute<bool>("ENABLE_THREADSAFETY", true)) {
189 ATH_MSG_FATAL("Failed to enable thread safety in ROOT via PersistencySvc.");
190 return(StatusCode::FAILURE);
191 }
192 m_contextMaxFile.insert(std::pair<unsigned int, int>(IPoolSvc::kInputStream, m_dbAgeLimit));
194 ATH_MSG_FATAL("Failed to connect Input PersistencySvc.");
195 return(StatusCode::FAILURE);
196 }
197 m_persistencySvcVec.push_back(pool::IPersistencySvc::create(*m_catalog).release()); // Write Service
198 m_pers_mut.push_back(new CallMutex);
202 if (m_fileOpen.value() == "update") {
204 }
205 m_persistencySvcVec[IPoolSvc::kOutputStream]->session().setDefaultConnectionPolicy(policy);
206 if (!m_persistencySvcVec[IPoolSvc::kOutputStream]->session().technologySpecificAttributes(pool::ROOT_StorageType.type()).setAttribute<int>("DEFAULT_CONTAINER_TYPE", pool::DbType::getType(m_defaultROOTContainerType).type())) {
207 ATH_MSG_FATAL("Failed to set ROOT default container type via PersistencySvc.");
208 return(StatusCode::FAILURE);
209 }
210
211 return(StatusCode::SUCCESS);
212}
213//__________________________________________________________________________
214StatusCode PoolSvc::start() {
215 // Switiching on ROOT implicit multi threading for AthenaMT
216 if (m_useROOTIMT && Gaudi::Concurrency::ConcurrencyFlags::numThreads() > 1) {
217 if (!m_persistencySvcVec[IPoolSvc::kInputStream]->session().technologySpecificAttributes(pool::ROOT_StorageType.type()).setAttribute<int>("ENABLE_IMPLICITMT", Gaudi::Concurrency::ConcurrencyFlags::numThreads() - 1)) {
218 ATH_MSG_FATAL("Failed to enable implicit multithreading in ROOT via PersistencySvc.");
219 return(StatusCode::FAILURE);
220 }
221 ATH_MSG_INFO("Enabled implicit multithreading in ROOT via PersistencySvc to: " << Gaudi::Concurrency::ConcurrencyFlags::numThreads() - 1);
222 }
223 return(StatusCode::SUCCESS);
224}
225//__________________________________________________________________________
226StatusCode PoolSvc::stop() {
227 ATH_MSG_VERBOSE("stop()");
228 bool retError = false;
229 for (unsigned int contextId = 0, imax = m_persistencySvcVec.size(); contextId < imax; contextId++) {
230 if (!disconnect(contextId).isSuccess()) {
231 ATH_MSG_FATAL("Cannot disconnect Stream: " << contextId);
232 retError = true;
233 }
234 }
235 return(retError ? StatusCode::FAILURE : StatusCode::SUCCESS);
236}
237
238//__________________________________________________________________________
240 std::lock_guard<CallMutex> lock(m_pool_mut);
241 // Cleanup persistency service
242 for (const auto& persistencySvc : m_persistencySvcVec) {
243 delete persistencySvc;
244 }
245 m_persistencySvcVec.clear();
246 for (const auto& persistencyMutex : m_pers_mut) {
247 delete persistencyMutex;
248 }
249 m_mainOutputLabel.clear();
250 m_inputContextLabel.clear();
251 m_outputContextLabel.clear();
252 m_pers_mut.clear();
253 if (m_catalog != nullptr) {
254 m_catalog->commit();
255 delete m_catalog; m_catalog = nullptr;
256 }
257}
258//__________________________________________________________________________
259StatusCode PoolSvc::finalize() {
260 clearState();
261 return(::AthService::finalize());
262}
263//__________________________________________________________________________
265 ATH_MSG_INFO("I/O finalization...");
266 for (size_t i = 0; i < m_persistencySvcVec.size(); i++) {
267 if (m_persistencySvcVec[i]->session().defaultConnectionPolicy().writeModeForNonExisting() != pool::DatabaseConnectionPolicy::RAISE_ERROR &&
268 !disconnect(i).isSuccess()) {
269 ATH_MSG_WARNING("Cannot disconnect output Stream " << i);
270 }
271 }
272 clearState();
273 return(StatusCode::SUCCESS);
274}
275//__________________________________________________________________________
277 const void* obj,
278 const RootType& classDesc) {
279 unsigned int contextId = IPoolSvc::kOutputStream;
280 const std::string& auxString = placement->auxString();
281 if (!auxString.empty()) {
282 if (auxString.compare(0, 6, "[CTXT=") == 0) {
283 ::sscanf(auxString.c_str(), "[CTXT=%08X]", &contextId);
284 } else if (auxString.compare(0, 8, "[CLABEL=") == 0) {
285 contextId = this->getOutputContext(auxString);
286 }
287 if (contextId >= m_persistencySvcVec.size()) {
288 ATH_MSG_WARNING("registerForWrite: Using default output Stream instead of id = " << contextId);
289 contextId = IPoolSvc::kOutputStream;
290 }
291 }
292 std::lock_guard<CallMutex> lock(*m_pers_mut[contextId]);
293 Token* token = m_persistencySvcVec[contextId]->registerForWrite(*placement, obj, classDesc);
294 if (token == nullptr) {
295 ATH_MSG_WARNING("Cannot write object: " << placement->containerName());
296 }
297 return(token);
298}
299//__________________________________________________________________________
300void PoolSvc::setObjPtr(void*& obj, const Token* token) {
301 unsigned int contextId = IPoolSvc::kInputStream;
302 const std::string& auxString = token->auxString();
303 if (!auxString.empty()) {
304 if (auxString.compare(0, 6, "[CTXT=") == 0) {
305 ::sscanf(auxString.c_str(), "[CTXT=%08X]", &contextId);
306 } else if (auxString.compare(0, 8, "[CLABEL=") == 0) {
307 contextId = this->getInputContext(auxString);
308 }
309 if (contextId >= m_persistencySvcVec.size()) {
310 ATH_MSG_WARNING("setObjPtr: Using default input Stream instead of id = " << contextId);
311 contextId = IPoolSvc::kInputStream;
312 }
313 }
314 ATH_MSG_VERBOSE("setObjPtr: token=" << token->toString() << ", auxString=" << auxString << ", contextID=" << contextId);
315 // Get Context ID/label from Token
316 std::lock_guard<CallMutex> lock(*m_pers_mut[contextId]);
317 obj = m_persistencySvcVec[contextId]->readObject(*token, obj);
318 std::map<unsigned int, unsigned int>::const_iterator maxFileIter = m_contextMaxFile.find(contextId);
319 if (maxFileIter != m_contextMaxFile.end() && maxFileIter->second > 0) {
320 m_guidLists[contextId].remove(token->dbID());
321 m_guidLists[contextId].push_back(token->dbID());
322 while (m_guidLists[contextId].size() > maxFileIter->second) {
323 this->disconnectDb("FID:" + m_guidLists[contextId].begin()->toString(), contextId).ignore();
324 }
325 }
326}
327//__________________________________________________________________________
328unsigned int PoolSvc::getOutputContext(const std::string& label) {
329 std::lock_guard<CallMutex> lock(m_pool_mut);
330 if (m_mainOutputLabel.empty()) {
332 m_outputContextLabel.insert(std::pair<std::string, unsigned int>(label, IPoolSvc::kOutputStream));
333 }
334 if (label == m_mainOutputLabel || label.empty()) {
336 }
337 std::map<std::string, unsigned int>::const_iterator contextIter = m_outputContextLabel.find(label);
338 if (contextIter != m_outputContextLabel.end()) {
339 return(contextIter->second);
340 }
341 const unsigned int id = m_persistencySvcVec.size();
342 m_persistencySvcVec.push_back(pool::IPersistencySvc::create(*m_catalog).release());
343 m_pers_mut.push_back(new CallMutex);
347 if (m_fileOpen.value() == "update") {
349 }
350 m_persistencySvcVec[id]->session().setDefaultConnectionPolicy(policy);
351 if (!m_persistencySvcVec[id]->session().technologySpecificAttributes(pool::ROOT_StorageType.type()).setAttribute<int>("DEFAULT_CONTAINER_TYPE", pool::DbType::getType(m_defaultROOTContainerType).type())) {
352 ATH_MSG_WARNING("Failed to set ROOT default container type via PersistencySvc for id " << id);
354 }
355 m_outputContextLabel.insert(std::pair<std::string, unsigned int>(label, id));
356 return(id);
357}
358//__________________________________________________________________________
359unsigned int PoolSvc::getInputContext(const std::string& label, unsigned int maxFile) {
360 std::lock_guard<CallMutex> lock(m_pool_mut);
361 if (!label.empty()) {
362 std::map<std::string, unsigned int>::const_iterator contextIter = m_inputContextLabel.find(label);
363 if (contextIter != m_inputContextLabel.end()) {
364 if (maxFile > 0) {
365 m_contextMaxFile[contextIter->second] = maxFile;
366 }
367 return(contextIter->second);
368 }
369 }
370 const unsigned int id = m_persistencySvcVec.size();
371 m_persistencySvcVec.push_back( pool::IPersistencySvc::create(*m_catalog).release() );
372 m_pers_mut.push_back(new CallMutex);
373 if (!connect(pool::ITransaction::READ, id).isSuccess()) {
374 ATH_MSG_WARNING("Failed to connect Input PersistencySvc: " << id);
376 }
377 if (!label.empty()) {
378 m_inputContextLabel.insert(std::pair<std::string, unsigned int>(label, id));
379 }
380 m_contextMaxFile.insert(std::pair<unsigned int, int>(id, maxFile));
381 return(id);
382}
383//__________________________________________________________________________
384const std::map<std::string, unsigned int>& PoolSvc::getInputContextMap() const {
385 return(m_inputContextLabel);
386}
387//__________________________________________________________________________
388const coral::Context* PoolSvc::context() const {
389 return(m_context);
390}
391//__________________________________________________________________________
392void PoolSvc::loadComponent(const std::string& compName) {
393 m_context->loadComponent(compName);
394}
395//__________________________________________________________________________
396void PoolSvc::setShareMode(bool shareCat) {
397 m_shareCat = shareCat;
398}
399//__________________________________________________________________________
401 return(m_catalog);
402}
403//__________________________________________________________________________
404void PoolSvc::lookupBestPfn(const std::string& token, std::string& pfn, std::string& type) const {
405 std::string dbID;
406 if (token.compare(0, 4, "PFN:") == 0) {
407 m_catalog->lookupFileByPFN(token.substr(4), dbID, type); // PFN -> FID
408 } else if (token.compare(0, 4, "LFN:") == 0) {
409 m_catalog->lookupFileByLFN(token.substr(4), dbID); // LFN -> FID
410 } else if (token.compare(0, 4, "FID:") == 0) {
411 dbID = token.substr(4);
412 } else if (token.size() > Guid::stringSize()) { // full token
413 Token tok;
414 tok.fromString(token);
415 dbID = tok.dbID().toString();
416 } else { // guid only
417 dbID = token;
418 }
419 m_catalog->getFirstPFN(dbID, pfn, type); // FID -> best PFN
420}
421//__________________________________________________________________________
422void PoolSvc::renamePfn(const std::string& pf, const std::string& newpf) {
423 std::string dbID, type;
424 m_catalog->lookupFileByPFN(pf, dbID, type);
425 if (dbID.empty()) {
426 ATH_MSG_WARNING("Failed to lookup: " << pf << " in FileCatalog");
427 return;
428 }
429 m_catalog->lookupFileByPFN(newpf, dbID, type);
430 if (!dbID.empty()) {
431 ATH_MSG_INFO("Found: " << newpf << " in FileCatalog");
432 return;
433 }
434 m_catalog->renamePFN(pf, newpf);
435}
436//__________________________________________________________________________
437pool::ICollection* PoolSvc::createCollection(const std::string& collectionType,
438 const std::string& connection,
439 const std::string& collectionName,
440 unsigned int contextId) const {
441 ATH_MSG_DEBUG("createCollection() type="<< collectionType << ", connection=" << connection
442 << ", name=" << collectionName << ", contextID=" << contextId);
443 std::string collection(collectionName);
444 if (collectionType == "RootCollection") {
445 if (collectionName.find("PFN:") == std::string::npos
446 && collectionName.find("LFN:") == std::string::npos
447 && collectionName.find("FID:") == std::string::npos) {
448 collection = "PFN:" + collectionName;
449 }
450 }
451 if (contextId >= m_persistencySvcVec.size()) {
452 ATH_MSG_WARNING("createCollection: Using default input Stream instead of id = " << contextId);
453 contextId = IPoolSvc::kInputStream;
454 }
455 ContextLock lock(contextId, m_pool_mut, m_pers_mut);
456 // Check POOL FileCatalog entry.
457 bool insertFile = false;
458 if (connection.compare(0, 4, "PFN:") == 0) {
459 std::string fid, fileType;
460 m_catalog->lookupFileByPFN(connection.substr(4), fid, fileType);
461 if (fid.empty()) { // No entry in file catalog
462 insertFile = true;
463 ATH_MSG_INFO("File is not in Catalog! Attempt to open it anyway.");
464 }
465 }
466 // Check whether Collection Container exists.
467 if (collectionType == "ImplicitCollection") {
468 std::unique_ptr<pool::IDatabase> dbH = getDbHandle(contextId, connection);
469 if (dbH == nullptr) {
470 ATH_MSG_INFO("Failed to get Session/DatabaseHandle to create POOL collection.");
471 return(nullptr);
472 }
473 try {
474 if (dbH->openMode() == pool::IDatabase::CLOSED) {
475 dbH->connectForRead();
476 }
477 std::map<unsigned int, unsigned int>::const_iterator maxFileIter = m_contextMaxFile.find(contextId);
478 if (maxFileIter != m_contextMaxFile.end() && maxFileIter->second > 0 && !dbH->fid().empty()) {
479 const Guid guid(dbH->fid());
480 m_guidLists[contextId].remove(guid);
481 m_guidLists[contextId].push_back(guid);
482 while (m_guidLists[contextId].size() > maxFileIter->second + 1) {
483 this->disconnectDb("FID:" + m_guidLists[contextId].begin()->toString(), contextId).ignore();
484 }
485 }
486 std::unique_ptr<pool::IContainer> contH = getContainerHandle(dbH.get(), collection);
487 if (contH == nullptr) {
488 ATH_MSG_INFO("Failed to find container " << collection << " to create POOL collection.");
489 if (insertFile && m_attemptCatalogPatch.value()) {
490 patchCatalog(connection.substr(4), *dbH);
491 }
492 return(nullptr); // no events
493 }
494 } catch(std::exception& e) {
495 ATH_MSG_INFO("Failed to open container to check POOL collection - trying.");
496 }
497 }
498
499 // access to these variables is locked below:
501 pool::ICollection* collPtr ATLAS_THREAD_SAFE = nullptr;
502
503 if (collectionType == "RootCollection" &&
504 m_persistencySvcVec[contextId]->session().defaultConnectionPolicy().writeModeForNonExisting() != pool::DatabaseConnectionPolicy::RAISE_ERROR) {
505 ATH_MSG_INFO("Writing RootCollection - do not pass session pointer");
506 std::scoped_lock lock(m_pool_mut);
507 collPtr = collSvc.handle(collection, collectionType, "", true);
508 } else {
509 // Try to open APR EventTags Collection in the input file - first as RootCollection, then as RNTCollection
510 std::scoped_lock lock(m_pool_mut);
511 std::string tree_error, rntuple_error;
512 try {
513 collPtr = collSvc.handle(collection, collectionType, collectionType == "ImplicitCollection" ? connection : "", true, &m_persistencySvcVec[contextId]->session());
514 } catch (std::exception &e) {
515 tree_error = e.what();
516 }
517 if( !collPtr ) try {
518 collPtr = collSvc.handle(collection, "RNTCollection", collectionType == "ImplicitCollection" ? connection : "", true, &m_persistencySvcVec[contextId]->session());
519 } catch (std::exception &e) {
520 if (insertFile) {
521 std::unique_ptr<pool::IDatabase> dbH = getDbHandle(contextId, connection);
522 if (dbH != nullptr) {
523 if (!dbH->fid().empty()) {
524 return(nullptr); // no events
525 }
526 }
527 }
528 rntuple_error = e.what();
529 }
530 if( !collPtr ) throw std::runtime_error( "Failed to open APR Collection as RootCollection or RNTCollection: "
531 + tree_error + " | " + rntuple_error + "PoolSvc::createCollection" );
532 }
533 if (insertFile && m_attemptCatalogPatch.value()) {
534 std::unique_ptr<pool::IDatabase> dbH = getDbHandle(contextId, connection);
535 if (dbH == nullptr) {
536 ATH_MSG_INFO("Failed to create FileCatalog entry.");
537 } else if (dbH->fid().empty()) {
538 ATH_MSG_INFO("Cannot retrieve the FID of an existing POOL database: '"
539 << connection << "' - FileCatalog will NOT be updated.");
540 } else {
541 patchCatalog(connection.substr(4), *dbH);
542 }
543 }
544 // For multithreaded processing (with multiple events in flight),
545 // increase virtual tree size to accomodate back reads
546 if (m_useROOTMaxTree && Gaudi::Concurrency::ConcurrencyFlags::numConcurrentEvents() > 1) {
547 if (!this->setAttribute("TREE_MAX_VIRTUAL_SIZE", "-1", pool::ROOT_StorageType.type(), connection.substr(4), "CollectionTree", IPoolSvc::kInputStream).isSuccess()) {
548 ATH_MSG_WARNING("Failed to increase maximum virtual TTree size.");
549 }
550 }
551
552 return(collPtr);
553}
554//__________________________________________________________________________
555void PoolSvc::patchCatalog(const std::string& pfn, pool::IDatabase& dbH) const {
556 std::scoped_lock lock(m_pool_mut);
558 std::string fid = dbH.fid();
560 catalog_locked->registerPFN(pfn, "ROOT_All", fid);
561}
562//__________________________________________________________________________
563Token* PoolSvc::getToken(const std::string& connection,
564 const std::string& collection,
565 const unsigned long ientry) const {
566 std::lock_guard<CallMutex> lock(*m_pers_mut[IPoolSvc::kInputStream]);
567 std::unique_ptr<pool::IDatabase> dbH = getDbHandle(IPoolSvc::kInputStream, connection);
568 if (dbH == nullptr) {
569 return(nullptr);
570 }
571 if (dbH->openMode() == pool::IDatabase::CLOSED) {
572 dbH->connectForRead();
573 }
574 std::unique_ptr<pool::IContainer> contH = getContainerHandle(dbH.get(), collection);
575 if (contH == nullptr) {
576 return(nullptr);
577 }
578 pool::ITokenIterator* tokenIter = contH->tokens();
579 Token* thisToken = tokenIter->next();
580 for (unsigned long ipos = 0; ipos < ientry; ipos++) {
581 delete thisToken; thisToken = tokenIter->next();
582 }
583 delete tokenIter; tokenIter = nullptr;
584 return(thisToken);
585}
586//__________________________________________________________________________
587StatusCode PoolSvc::connect(pool::ITransaction::Type type, unsigned int contextId) {
589 if (contextId >= m_persistencySvcVec.size()) {
590 ATH_MSG_WARNING("connect: Using default output Stream instead of id = " << contextId);
591 contextId = IPoolSvc::kOutputStream;
592 }
593 } else {
594 if (contextId > m_persistencySvcVec.size()) {
595 ATH_MSG_WARNING("connect: Using default input Stream instead of id = " << contextId);
596 contextId = IPoolSvc::kInputStream;
597 } else if (contextId == m_persistencySvcVec.size()) {
598 ATH_MSG_INFO("Connecting to InputStream for: " << contextId);
599 contextId = this->getInputContext("");
600 }
601 }
602 if (contextId >= m_persistencySvcVec.size()) {
603 return(StatusCode::FAILURE);
604 }
605 ContextLock lock(contextId, m_pool_mut, m_pers_mut);
606 pool::IPersistencySvc* persSvc = m_persistencySvcVec[contextId];
607 // Connect to a logical database using the pre-defined technology and dbID
608 if (persSvc->session().transaction().isActive()) {
609 return(StatusCode::SUCCESS);
610 }
611 if (!persSvc->session().transaction().start(type)) {
612 ATH_MSG_ERROR("connect failed persSvc = " << persSvc << " type = " << type);
613 return(StatusCode::FAILURE);
614 }
615
616 return(StatusCode::SUCCESS);
617}
618//__________________________________________________________________________
619StatusCode PoolSvc::commit(unsigned int contextId) const {
620 if (contextId >= m_persistencySvcVec.size()) {
621 return(StatusCode::FAILURE);
622 }
623 ContextLock lock(contextId, m_pool_mut, m_pers_mut);
624 pool::IPersistencySvc* persSvc = m_persistencySvcVec[contextId];
625 if (persSvc != nullptr && persSvc->session().transaction().isActive()) {
626 if (!persSvc->session().transaction().commit()) {
627 ATH_MSG_ERROR("POOL commit failed " << persSvc);
628 return(StatusCode::FAILURE);
629 }
630 if (persSvc->session().transaction().type() == pool::ITransaction::READ) {
631 persSvc->session().disconnectAll();
632 }
633 }
634 return(StatusCode::SUCCESS);
635}
636//__________________________________________________________________________
637StatusCode PoolSvc::commitAndHold(unsigned int contextId) const {
638 if (contextId >= m_persistencySvcVec.size()) {
639 return(StatusCode::FAILURE);
640 }
641 ContextLock lock(contextId, m_pool_mut, m_pers_mut);
642 pool::IPersistencySvc* persSvc = m_persistencySvcVec[contextId];
643 if (persSvc != nullptr && persSvc->session().transaction().isActive()) {
644 if (!persSvc->session().transaction().commitAndHold()) {
645 ATH_MSG_ERROR("POOL commitAndHold failed " << persSvc);
646 return(StatusCode::FAILURE);
647 }
648 }
649 return(StatusCode::SUCCESS);
650}
651//__________________________________________________________________________
652StatusCode PoolSvc::disconnect(unsigned int contextId) const {
653 ATH_MSG_DEBUG("Disconnect request for contextId=" << contextId);
654 if (contextId >= m_persistencySvcVec.size()) {
655 return(StatusCode::SUCCESS);
656 }
657 ContextLock lock(contextId, m_pool_mut, m_pers_mut);
658 pool::IPersistencySvc* persSvc = m_persistencySvcVec[contextId];
659 if (persSvc != nullptr && persSvc->session().transaction().isActive()) {
660 if (!commit(contextId).isSuccess()) {
661 ATH_MSG_ERROR("disconnect failed to commit " << persSvc);
662 return(StatusCode::FAILURE);
663 }
664 if (persSvc->session().disconnectAll()) {
665 ATH_MSG_DEBUG("Disconnected PersistencySvc session");
666 } else {
667 ATH_MSG_ERROR("disconnect failed to diconnect PersistencySvc");
668 return(StatusCode::FAILURE);
669 }
670 }
671 return(StatusCode::SUCCESS);
672}
673//__________________________________________________________________________
674StatusCode PoolSvc::disconnectDb(const std::string& connection, unsigned int contextId) const {
675 if (contextId >= m_persistencySvcVec.size()) {
676 return(StatusCode::SUCCESS);
677 }
678 ContextLock lock(contextId, m_pool_mut, m_pers_mut);
679 std::unique_ptr<pool::IDatabase> dbH = getDbHandle(contextId, connection);
680 if (dbH == nullptr) {
681 ATH_MSG_ERROR("Failed to get Session/DatabaseHandle.");
682 return(StatusCode::FAILURE);
683 }
684 std::map<unsigned int, unsigned int>::const_iterator maxFileIter = m_contextMaxFile.find(contextId);
685 if (maxFileIter != m_contextMaxFile.end() && maxFileIter->second > 0) {
686 m_guidLists[contextId].remove(Guid(dbH->fid()));
687 }
688 dbH->disconnect();
689 return(StatusCode::SUCCESS);
690}
691//_______________________________________________________________________
692long long int PoolSvc::getFileSize(const std::string& dbName, long tech, unsigned int contextId) const {
693 ContextLock lock(contextId, m_pool_mut, m_pers_mut);
694 std::unique_ptr<pool::IDatabase> dbH = getDbHandle(contextId, dbName);
695 if (dbH == nullptr) {
696 ATH_MSG_DEBUG("getFileSize: Failed to get Session/DatabaseHandle to get POOL FileSize property.");
697 return 0; // failure
698 }
699 if (dbH->openMode() == pool::IDatabase::CLOSED) {
700 if (m_persistencySvcVec[contextId]->session().defaultConnectionPolicy().writeModeForNonExisting() != pool::DatabaseConnectionPolicy::RAISE_ERROR) {
701 dbH->setTechnology(tech);
702 dbH->connectForWrite();
703 } else {
704 dbH->connectForRead();
705 }
706 }
707 return(dbH->technologySpecificAttributes().attribute<long long int>("FILE_SIZE"));
708}
709//_______________________________________________________________________
710StatusCode PoolSvc::getAttribute(const std::string& optName,
711 std::string& data,
712 long tech,
713 unsigned int contextId) const {
714 if (contextId >= m_persistencySvcVec.size()) {
715 ATH_MSG_WARNING("getAttribute: Using default input Stream instead of id = " << contextId);
716 contextId = IPoolSvc::kInputStream;
717 }
718 ContextLock lock(contextId, m_pool_mut, m_pers_mut);
719 pool::ISession& sesH = m_persistencySvcVec[contextId]->session();
720 std::ostringstream oss;
721 if (data == "DbLonglong") {
722 oss << std::dec << sesH.technologySpecificAttributes(tech).attribute<long long int>(optName);
723 } else if (data == "double") {
724 oss << std::dec << sesH.technologySpecificAttributes(tech).attribute<double>(optName);
725 } else {
726 oss << std::dec << sesH.technologySpecificAttributes(tech).attribute<int>(optName);
727 }
728 data = oss.str();
729 ATH_MSG_INFO("Domain attribute [" << optName << "]" << ": " << data);
730 return(StatusCode::SUCCESS);
731}
732//_______________________________________________________________________
733StatusCode PoolSvc::getAttribute(const std::string& optName,
734 std::string& data,
735 long tech,
736 const std::string& dbName,
737 const std::string& contName,
738 unsigned int contextId) const {
739 ContextLock lock(contextId, m_pool_mut, m_pers_mut);
740 std::unique_ptr<pool::IDatabase> dbH = getDbHandle(contextId, dbName);
741 if (dbH == nullptr) {
742 ATH_MSG_DEBUG("getAttribute: Failed to get Session/DatabaseHandle to get POOL property.");
743 return(StatusCode::FAILURE);
744 }
745 if (dbH->openMode() == pool::IDatabase::CLOSED) {
746 if (m_persistencySvcVec[contextId]->session().defaultConnectionPolicy().writeModeForNonExisting() != pool::DatabaseConnectionPolicy::RAISE_ERROR) {
747 dbH->setTechnology(tech);
748 dbH->connectForWrite();
749 } else {
750 dbH->connectForRead();
751 }
752 }
753 std::ostringstream oss;
754 if (contName.empty()) {
755 if (data == "DbLonglong") {
756 oss << std::dec << dbH->technologySpecificAttributes().attribute<long long int>(optName);
757 } else if (data == "double") {
758 oss << std::dec << dbH->technologySpecificAttributes().attribute<double>(optName);
759 } else if (data == "string") {
760 oss << dbH->technologySpecificAttributes().attribute<char*>(optName);
761 } else {
762 oss << std::dec << dbH->technologySpecificAttributes().attribute<int>(optName);
763 }
764 ATH_MSG_INFO("Database (" << dbH->pfn() << ") attribute [" << optName << "]" << ": " << oss.str());
765 } else {
766 std::unique_ptr<pool::IContainer> contH = getContainerHandle(dbH.get(), contName);
767 if (contH == nullptr) {
768 ATH_MSG_DEBUG("Failed to get ContainerHandle to get POOL property.");
769 return(StatusCode::FAILURE);
770 }
771 if (data == "DbLonglong") {
772 oss << std::dec << contH->technologySpecificAttributes().attribute<long long int>(optName);
773 } else if (data == "double") {
774 oss << std::dec << contH->technologySpecificAttributes().attribute<double>(optName);
775 } else {
776 oss << std::dec << contH->technologySpecificAttributes().attribute<int>(optName);
777 }
778 ATH_MSG_INFO("Container attribute [" << contName << "." << optName << "]: " << oss.str());
779 }
780 data = oss.str();
781 return(StatusCode::SUCCESS);
782}
783//_______________________________________________________________________
784StatusCode PoolSvc::setAttribute(const std::string& optName,
785 const std::string& data,
786 long tech,
787 unsigned int contextId) const {
788 if (contextId >= m_persistencySvcVec.size()) {
789 ATH_MSG_WARNING("setAttribute: Using default output Stream instead of id = " << contextId);
790 contextId = IPoolSvc::kOutputStream;
791 }
792 ContextLock lock(contextId, m_pool_mut, m_pers_mut);
793 pool::ISession& sesH = m_persistencySvcVec[contextId]->session();
794 if (data[data.size() - 1] == 'L') {
795 if (!sesH.technologySpecificAttributes(tech).setAttribute<long long int>(optName, atoll(data.c_str()))) {
796 ATH_MSG_DEBUG("Failed to set POOL property, " << optName << " to " << data);
797 return(StatusCode::FAILURE);
798 }
799 } else {
800 if (!sesH.technologySpecificAttributes(tech).setAttribute<int>(optName, atoi(data.c_str()))) {
801 ATH_MSG_DEBUG("Failed to set POOL property, " << optName << " to " << data);
802 return(StatusCode::FAILURE);
803 }
804 }
805 return(StatusCode::SUCCESS);
806}
807//_______________________________________________________________________
808StatusCode PoolSvc::setAttribute(const std::string& optName,
809 const std::string& data,
810 long tech,
811 const std::string& dbName,
812 const std::string& contName,
813 unsigned int contextId) const {
814 if (contextId >= m_persistencySvcVec.size()) {
815 ATH_MSG_WARNING("setAttribute: Using default output Stream instead of id = " << contextId);
816 contextId = IPoolSvc::kOutputStream;
817 }
818 ContextLock lock(contextId, m_pool_mut, m_pers_mut);
819 std::unique_ptr<pool::IDatabase> dbH = getDbHandle(contextId, dbName);
820 if (dbH == nullptr) {
821 ATH_MSG_DEBUG("Failed to get Session/DatabaseHandle to set POOL property.");
822 return(StatusCode::FAILURE);
823 }
824 if (dbH->openMode() == pool::IDatabase::CLOSED) {
825 if (m_persistencySvcVec[contextId]->session().defaultConnectionPolicy().writeModeForNonExisting() != pool::DatabaseConnectionPolicy::RAISE_ERROR) {
826 dbH->setTechnology(tech);
827 dbH->connectForWrite();
828 } else {
829 dbH->connectForRead();
830 }
831 }
832 bool retError = false;
833 std::string objName;
834 bool hasTTreeName = (contName.length() > 6 && contName.compare(0, 6, "TTree=") == 0);
835 if (contName.empty() || hasTTreeName || m_persistencySvcVec[contextId]->session().defaultConnectionPolicy().writeModeForNonExisting() == pool::DatabaseConnectionPolicy::RAISE_ERROR) {
836 objName = hasTTreeName ? contName.substr(6) : contName;
837 if( !isNumber(data) ) {
838 retError = dbH->technologySpecificAttributes().setAttribute(optName, data.c_str(), objName);
839 } else if( data[data.size() - 1] == 'L' ) {
840 retError = dbH->technologySpecificAttributes().setAttribute<long long int>(optName, atoll(data.c_str()), objName);
841 } else {
842 retError = dbH->technologySpecificAttributes().setAttribute<int>(optName, atoi(data.c_str()), objName);
843 }
844 if (!retError) {
845 ATH_MSG_DEBUG("Failed to set POOL property, " << optName << " to " << data);
846 return(StatusCode::FAILURE);
847 }
848 } else {
849 std::unique_ptr<pool::IContainer> contH = getContainerHandle(dbH.get(), contName);
850 if (contH == nullptr) {
851 ATH_MSG_DEBUG("Failed to get ContainerHandle to set POOL property.");
852 return(StatusCode::FAILURE);
853 }
854 if (auto p = contName.find('('); p != std::string::npos) {
855 objName = contName.substr(p + 1); // Get BranchName between parenthesis
856 objName.erase(objName.find(')'));
857 } else if (auto p = contName.find("::"); p != std::string::npos) {
858 objName = contName.substr(p + 2); // Split off Tree name
859 } else if (auto p = contName.find('_'); p != std::string::npos) {
860 objName = contName.substr(p + 1); // Split off "POOLContainer"
861 objName.erase(objName.find('/')); // Split off key
862 }
863 std::string::size_type off = 0;
864 while ((off = objName.find_first_of("<>/")) != std::string::npos) {
865 objName[off] = '_'; // Replace special chars (e.g. templates)
866 }
867 if (data[data.size() - 1] == 'L') {
868 retError = contH->technologySpecificAttributes().setAttribute<long long int>(optName, atoll(data.c_str()), objName);
869 } else {
870 retError = contH->technologySpecificAttributes().setAttribute<int>(optName, atoi(data.c_str()), objName);
871 }
872 if (!retError) {
873 ATH_MSG_DEBUG("Failed to set POOL container property, " << optName << " for " << contName << " : " << objName << " to " << data);
874 return(StatusCode::FAILURE);
875 }
876 }
877 return(StatusCode::SUCCESS);
878}
879//__________________________________________________________________________
880StatusCode PoolSvc::setFrontierCache(const std::string& conn) {
881 std::lock_guard<CallMutex> lock(m_pool_mut);
882 ATH_MSG_VERBOSE("setFrontierCache called for connection:" << conn);
883 // setup the Frontier cache information for the given logical or physical connection string
884 // first determine if the connection is logical (no ':')
885 std::vector<std::string> physcons;
886 if (conn.find(':') == std::string::npos) {
887 // if logical, have to lookup list of physical replicas, and consider each
888 // need the CORAL ILookupSvc interface which must be loaded if needed
889 const std::string lookSvcStr("CORAL/Services/XMLLookupService");
890 coral::IHandle<coral::ILookupService> lookSvcH = m_context->query<coral::ILookupService>();
891 if (!lookSvcH.isValid()) {
892 m_context->loadComponent(lookSvcStr);
893 lookSvcH = m_context->query<coral::ILookupService>();
894 }
895 if (!lookSvcH.isValid()) {
896 ATH_MSG_ERROR("Cannot locate " << lookSvcStr);
897 return(StatusCode::FAILURE);
898 }
899 coral::IDatabaseServiceSet* dbset = lookSvcH->lookup(conn, coral::ReadOnly);
900 if (dbset != nullptr) {
901 for (int irep = 0, nrep = dbset->numberOfReplicas(); irep < nrep; ++irep) {
902 const std::string pcon = dbset->replica(irep).connectionString();
903 if (pcon.compare(0, 9, "frontier:") == 0) {
904 physcons.push_back(std::move(pcon));
905 }
906 }
907 delete dbset; dbset = nullptr;
908 } else {
909 ATH_MSG_DEBUG("setFrontierCache: Could not find any replicas for " << conn);
910 }
911 } else if (conn.compare(0, 9, "frontier:") == 0) {
912 physcons.push_back(conn);
913 }
914 // check if any replicas will try and use frontier
915 if (physcons.size() == 0) {
916 return(StatusCode::SUCCESS);
917 }
918 coral::ConnectionService conSvcH;
919 // for each frontier replica, define the web cache info
920 // get the WebCacheControl interface via ConnectionSvc
921 // note ConnectionSvc should already be loaded by initialize
922 coral::IWebCacheControl& webCache = conSvcH.webCacheControl();
923 for (const auto& physcon : physcons) {
924 const auto& refreshList = m_frontierRefresh.value();
925 if (std::find(refreshList.begin(), refreshList.end(), physcon) == refreshList.end()
926 && std::find(refreshList.begin(), refreshList.end(), conn) == refreshList.end()) {
927 // set that a table DUMMYTABLE should be refreshed - indicates that everything
928 // else in the schema should not be
929 webCache.refreshTable(physcon, "DUMMYTABLE");
930 } else {
931 // set the schema to be refreshed
932 webCache.refreshSchemaInfo(physcon);
933 }
934 ATH_MSG_DEBUG("Cache flag for connection " << physcon << " set to " << webCache.webCacheInfo(physcon).isSchemaInfoCached());
935 }
936 return(StatusCode::SUCCESS);
937}
938//__________________________________________________________________________
941 ctlg->removeCatalog("*");
942 for (auto& catalog : m_readCatalog.value()) {
943 ATH_MSG_DEBUG("POOL ReadCatalog is " << catalog);
944 if (catalog.compare(0, 8,"apcfile:") == 0 || catalog.compare(0, 7, "prfile:") == 0) {
945 std::string::size_type cpos = catalog.find(':');
946 // check for file accessed via ATLAS_POOLCOND_PATH
947 std::string file = poolCondPath(catalog.substr(cpos + 1));
948 if (!file.empty()) {
949 ATH_MSG_INFO("Resolved path (via ATLAS_POOLCOND_PATH) is " << file);
950 ctlg->addReadCatalog("file:" + file);
951 } else {
952 // As backup, check for file accessed via PathResolver
953 file = PathResolver::find_file(catalog.substr(cpos + 1), "DATAPATH");
954 if (!file.empty()) {
955 ATH_MSG_INFO("Resolved path (via DATAPATH) is " << file);
956 ctlg->addReadCatalog("file:" + file);
957 } else {
958 ATH_MSG_INFO("Unable find catalog "
959 << catalog
960 << " in $ATLAS_POOLCOND_PATH and $DATAPATH");
961 }
962 }
963 } else {
964 ctlg->addReadCatalog(catalog);
965 }
966 }
967 try {
968 ATH_MSG_INFO("POOL WriteCatalog is " << m_writeCatalog.value());
969 ctlg->setWriteCatalog(m_writeCatalog.value());
970 ctlg->connect();
971 } catch(std::exception& e) {
972 ATH_MSG_ERROR("setWriteCatalog - caught exception: " << e.what());
973 return(nullptr); // This catalog is not setup properly!
974 }
975 return(ctlg);
976}
977
978//__________________________________________________________________________
981//__________________________________________________________________________
982std::unique_ptr<pool::IDatabase> PoolSvc::getDbHandle(unsigned int contextId, const std::string& dbName) const {
983 if (contextId >= m_persistencySvcVec.size()) {
984 ATH_MSG_WARNING("getDbHandle: Using default input Stream instead of id = " << contextId);
985 contextId = IPoolSvc::kInputStream;
986 }
987 pool::ISession& sesH = m_persistencySvcVec[contextId]->session();
988 if (!sesH.transaction().isActive()) {
990 if (m_persistencySvcVec[contextId]->session().defaultConnectionPolicy().writeModeForNonExisting() != pool::DatabaseConnectionPolicy::RAISE_ERROR) {
991 transMode = pool::ITransaction::UPDATE;
992 }
993 ATH_MSG_DEBUG("Start transaction, type = " << transMode);
994 if (!sesH.transaction().start(transMode)) {
995 ATH_MSG_WARNING("Failed to start transaction, type = " << transMode);
996 return(nullptr);
997 }
998 }
999 if (dbName.compare(0, 4,"PFN:") == 0) {
1000 return sesH.databaseHandle(dbName.substr(4), pool::DatabaseSpecification::PFN);
1001 } else if (dbName.compare(0, 4, "LFN:") == 0) {
1002 return sesH.databaseHandle(dbName.substr(4), pool::DatabaseSpecification::LFN);
1003 } else if (dbName.compare(0, 4,"FID:") == 0) {
1004 return sesH.databaseHandle(dbName.substr(4), pool::DatabaseSpecification::FID);
1005 }
1007}
1008//__________________________________________________________________________
1009std::unique_ptr<pool::IContainer> PoolSvc::getContainerHandle(pool::IDatabase* dbH, const std::string& contName) const {
1010 pool::IContainer* contH = nullptr;
1011 if (dbH == nullptr) {
1012 ATH_MSG_DEBUG("No DatabaseHandle to get Container.");
1013 return(nullptr);
1014 }
1015 if (dbH->openMode() == pool::IDatabase::CLOSED) {
1016 dbH->connectForRead();
1017 }
1018 if (contName.find("DataHeader") != std::string::npos) {
1019 contH = dbH->containerHandle(contName.substr(0, contName.find("_p")));
1020 } else {
1021 contH = dbH->containerHandle(contName);
1022 }
1023 return(std::unique_ptr<pool::IContainer>(contH));
1024}
1025//__________________________________________________________________________
1026std::string PoolSvc::poolCondPath(const std::string& leaf) {
1027 // look for files at $ATLAS_POOLCOND_PATH/<leaf>
1028 // return full filename if exists, or empty string if not
1029 const char* cpath = std::getenv("ATLAS_POOLCOND_PATH");
1030 if (cpath && strcmp(cpath, "") != 0) {
1031 const std::string testpath = std::string(cpath) + "/" + leaf;
1032
1033 // Try to open file for reading. Note that a simple stat call may return
1034 // a wrong result if the file is residing on an auto-mounted FS (ATR-28801).
1035 if (FILE* fp = std::fopen(testpath.c_str(), "r")) {
1036 std::fclose(fp);
1037 return testpath;
1038 }
1039 }
1040 return {};
1041}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
This file contains the class definition for the Placement class (migrated from POOL).
bool isNumber(const std::string &s)
Definition PoolSvc.cxx:52
This file contains the class definition for the PoolSvc class.
TTypeAdapter RootType
Definition RootType.h:211
int imax(int i, int j)
This file contains the class definition for the Token class (migrated from POOL).
This class provides a encapsulation of a GUID/UUID/CLSID/IID data structure (128 bit number).
Definition Guid.h:25
constexpr void toString(std::span< char, StrLen > buf, bool uppercase=true) const noexcept
Automatic conversion to string representation.
static constexpr int stringSize()
Definition Guid.h:61
@ kOutputStream
Definition IPoolSvc.h:39
@ kInputStream
Definition IPoolSvc.h:39
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
This class holds all the necessary information to guide the writing of an object in a physical place.
Definition Placement.h:19
const std::string & auxString() const
Access auxiliary string.
Definition Placement.h:40
const std::string & containerName() const
Access container name.
Definition Placement.h:32
virtual long long int getFileSize(const std::string &dbName, long tech, unsigned int contextId) const override
Get POOL FileSize attribute for database without logging a message.
Definition PoolSvc.cxx:692
virtual StatusCode io_reinit() override
Definition PoolSvc.cxx:134
pool::IFileCatalog * createCatalog()
Definition PoolSvc.cxx:939
virtual Token * registerForWrite(const Placement *placement, const void *obj, const RootType &classDesc) override
Definition PoolSvc.cxx:276
virtual ~PoolSvc()
Destructor.
Definition PoolSvc.cxx:979
virtual StatusCode connect(pool::ITransaction::Type type, unsigned int contextId=IPoolSvc::kInputStream) override
Connect to a logical database unit; PersistencySvc is chosen according to transaction type (accessmod...
Definition PoolSvc.cxx:587
Gaudi::Property< int > m_retrialTimeOut
ConnectionRetrialTimeOut, the retrial time out for CORAL Connection Service: default = 300 seconds.
Definition PoolSvc.h:253
Gaudi::Property< int > m_timeOut
ConnectionTimeOut, the time out for CORAL Connection Service: default = 5 seconds.
Definition PoolSvc.h:255
virtual void renamePfn(const std::string &pf, const std::string &newpf) override
Definition PoolSvc.cxx:422
Gaudi::Property< int > m_retrialPeriod
ConnectionRetrialPeriod, retry period for CORAL Connection Service: default = 30 seconds.
Definition PoolSvc.h:251
virtual const coral::Context * context() const override
Definition PoolSvc.cxx:388
pool::IFileCatalog * m_catalog
Definition PoolSvc.h:222
Gaudi::Property< std::vector< std::string > > m_frontierRefresh
Definition PoolSvc.h:260
std::string poolCondPath(const std::string &leaf)
Resolve a file using ATLAS_POOLCOND_PATH.
Definition PoolSvc.cxx:1026
void patchCatalog(const std::string &pfn, pool::IDatabase &dbH) const
Definition PoolSvc.cxx:555
CallMutex m_pool_mut
Definition PoolSvc.h:219
virtual unsigned int getInputContext(const std::string &label, unsigned int maxFile=0) override
Definition PoolSvc.cxx:359
Gaudi::Property< bool > m_sortReplicas
Use DBReplicaSvc to sort database connections, default = true.
Definition PoolSvc.h:262
std::recursive_mutex CallMutex
Definition PoolSvc.h:205
Gaudi::Property< std::string > m_defaultROOTContainerType
Default ROOT container type.
Definition PoolSvc.h:264
virtual void lookupBestPfn(const std::string &token, std::string &pfn, std::string &type) const override
Definition PoolSvc.cxx:404
virtual StatusCode setAttribute(const std::string &optName, const std::string &data, long tech, unsigned int contextId=IPoolSvc::kOutputStream) const override
Set POOL attributes - domain.
Definition PoolSvc.cxx:784
Gaudi::Property< bool > m_connClean
ConnectionCleanUp - whether to use CORAL connection management thread: default = false.
Definition PoolSvc.h:257
Gaudi::Property< bool > m_useROOTIMT
Use ROOT Implicit MultiThreading, default = true.
Definition PoolSvc.h:244
virtual StatusCode commit(unsigned int contextId=IPoolSvc::kInputStream) const override
Commit data for a given contextId and flush buffer.
Definition PoolSvc.cxx:619
std::unique_ptr< pool::IContainer > getContainerHandle(pool::IDatabase *dbH, const std::string &contName) const
Get Container handle.
Definition PoolSvc.cxx:1009
virtual Token * getToken(const std::string &connection, const std::string &collection, const unsigned long ientry) const override
Definition PoolSvc.cxx:563
virtual StatusCode start() override
Required of all Gaudi services:
Definition PoolSvc.cxx:214
Gaudi::Property< int > m_frontierComp
Frontier proprties, compression level and list of schemas to be refreshed: default = 5.
Definition PoolSvc.h:259
StatusCode setupPersistencySvc()
Definition PoolSvc.cxx:175
virtual const std::map< std::string, unsigned int > & getInputContextMap() const override
Definition PoolSvc.cxx:384
virtual StatusCode io_finalize() override
Definition PoolSvc.cxx:264
Gaudi::Property< int > m_dbAgeLimit
MaxFilesOpen, option to have PoolSvc limit the number of open Input Files: default = 0 (No files are ...
Definition PoolSvc.h:237
Gaudi::Property< bool > m_useROOTMaxTree
Increase virtual TTree size to avoid backreads in multithreading, default = false.
Definition PoolSvc.h:246
std::map< std::string, unsigned int > m_outputContextLabel
Definition PoolSvc.h:226
std::vector< pool::IPersistencySvc * > m_persistencySvcVec
Definition PoolSvc.h:223
virtual StatusCode disconnectDb(const std::string &connection, unsigned int contextId=IPoolSvc::kInputStream) const override
Disconnect single Database.
Definition PoolSvc.cxx:674
std::vector< CallMutex * > m_pers_mut
Definition PoolSvc.h:224
std::map< std::string, unsigned int > m_inputContextLabel
Definition PoolSvc.h:225
virtual void setObjPtr(void *&obj, const Token *token) override
Definition PoolSvc.cxx:300
virtual void loadComponent(const std::string &compName) override
Definition PoolSvc.cxx:392
Gaudi::Property< std::vector< std::string > > m_readCatalog
ReadCatalog, the list of additional POOL input file catalogs to consult: default = empty vector.
Definition PoolSvc.h:242
std::string m_mainOutputLabel
Definition PoolSvc.h:227
virtual const pool::IFileCatalog * catalog() const override
Definition PoolSvc.cxx:400
void clearState()
Definition PoolSvc.cxx:239
std::map< unsigned int, unsigned int > m_contextMaxFile
Definition PoolSvc.h:228
virtual pool::ICollection * createCollection(const std::string &collectionType, const std::string &connection, const std::string &collectionName, unsigned int contextId=IPoolSvc::kInputStream) const override
Definition PoolSvc.cxx:437
virtual void setShareMode(bool shareCat) override
Definition PoolSvc.cxx:396
std::unique_ptr< pool::IDatabase > getDbHandle(unsigned int contextId, const std::string &dbName) const
Get Database handle.
Definition PoolSvc.cxx:982
coral::Context * m_context
Definition PoolSvc.h:220
virtual StatusCode commitAndHold(unsigned int contextId=IPoolSvc::kInputStream) const override
Commit data for a given contextId and hold buffer.
Definition PoolSvc.cxx:637
virtual StatusCode disconnect(unsigned int contextId=IPoolSvc::kInputStream) const override
Disconnect PersistencySvc associated with a contextId.
Definition PoolSvc.cxx:652
virtual StatusCode finalize() override
Required of all Gaudi services:
Definition PoolSvc.cxx:259
virtual StatusCode initialize() override
Required of all Gaudi services:
Definition PoolSvc.cxx:57
virtual StatusCode setFrontierCache(const std::string &conn) override
Setup Frontier cache for given logical or physical connection name.
Definition PoolSvc.cxx:880
virtual unsigned int getOutputContext(const std::string &label) override
Definition PoolSvc.cxx:328
Gaudi::Property< std::string > m_writeCatalog
WriteCatalog, the file catalog to be used to register output files (also default input catalog): defa...
Definition PoolSvc.h:240
virtual StatusCode stop() override
Definition PoolSvc.cxx:226
Gaudi::Property< bool > m_attemptCatalogPatch
AttemptCatalogPatch, option to create catalog: default = false.
Definition PoolSvc.h:249
std::map< unsigned int, std::list< Guid > > m_guidLists ATLAS_THREAD_SAFE
Definition PoolSvc.h:230
virtual StatusCode getAttribute(const std::string &optName, std::string &data, long tech, unsigned int contextId=IPoolSvc::kInputStream) const override
Get POOL attributes - domain.
Definition PoolSvc.cxx:710
bool m_shareCat
Definition PoolSvc.h:221
Gaudi::Property< std::string > m_fileOpen
FileOpen, the open mode for the file ("append" or "overwrite").
Definition PoolSvc.h:234
This class provides a token that identifies in a unique way objects on the persistent storage.
Definition Token.h:21
const std::string & auxString() const
Access auxiliary string.
Definition Token.h:91
virtual const std::string toString() const
Retrieve the string representation of the token.
Definition Token.cxx:134
Token & fromString(const std::string_view from)
Build from the string representation of a token.
Definition Token.cxx:147
const Guid & dbID() const
Access database identifier.
Definition Token.h:64
A service for creating, accessing and managing an ensemble of collections of event references.
DatabaseConnectionPolicy is a class holding information on the policy to be followed whenever a datab...
bool setWriteModeForExisting(Mode mode)
Sets the opening mode when an existing database is opened for writing.
bool setWriteModeForNonExisting(Mode mode)
Sets the opening mode when a non existing database is opened for writing Acceptable values are RAISE_...
static DbType getType(const std::string &name)
Access known storage type object by name.
An interface to a storage technology specific collection of event references and attributes.
Definition ICollection.h:23
IContainer is the base class for container objects.
Definition IContainer.h:23
IDatabase is the base class for database objects.
Definition IDatabase.h:25
virtual OpenMode openMode() const =0
Returns the opening mode. It can be used to check whether the database is connected.
virtual bool setTechnology(long technology)=0
Sets the technology identifier for this database.
virtual const std::string & fid()=0
Returns the file identifier of this database.
virtual void connectForRead()=0
Connects explicitly to the database for read operations.
virtual IContainer * containerHandle(const std::string &name)=0
Returns a pointer to a container object. The user acquires ownership of that object.
void addReadCatalog(const std::string &connect)
Add new catalog identified by name to the existing ones.
void removeCatalog(const std::string &connect)
Add new catalog identified by reference to the existing ones.
void setWriteCatalog(const std::string &connect)
Access to the (first) writable file catalog.
IPersistencySvc is the abstract interface for all services which execute the conversion between trans...
virtual ISession & session()=0
Returns the underlying global session.
static std::unique_ptr< IPersistencySvc > create(IFileCatalog &catalog)
Factory for PersistencySvc.
ISession is the interface class for user (macroscopic) sessions Every transaction and connection to a...
Definition ISession.h:32
virtual std::unique_ptr< IDatabase > databaseHandle(const std::string &dbName, DatabaseSpecification::NameType dbNameType)=0
Returns a pointer to a database object. The user acquires ownership of that object.
virtual ITransaction & transaction()=0
Returns the transaction object.
virtual const ITechnologySpecificAttributes & technologySpecificAttributes(long technology) const =0
Returns the object holding the technology specific attributes for a given technology domain.
virtual bool disconnectAll()=0
Explicitly disconnects all the databases.
T attribute(const std::string &attributeName, const std::string &option="")
Templated method to retrieve an attribute.
bool setAttribute(const std::string &attributeName, const T &atttibuteValue, const std::string &option="")
Templated method to set an attribute.
ITokenIterator is the interface class for iterators of tokens.
virtual Token * next()=0
Returns the pointer to next token.
virtual bool commitAndHold()=0
Commits the holds transaction.
Type
Transaction type enumeration.
virtual bool commit()=0
Commits the transaction.
virtual Type type() const =0
Returns the transaction type.
virtual bool start(Type type=READ)=0
Starts a new transaction. Returns the success of the operation.
virtual bool isActive() const =0
Checks if the transaction is active.
std::string label(const std::string &format, int i)
Definition label.h:19
static const DbType ROOT_StorageType
Definition DbType.h:99
static void setLevel(MSG::Level l)
Definition DbPrint.h:21
MsgStream & msg
Definition testRead.cxx:32
TFile * file