ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Database
AthenaPOOL
PoolSvc
src
FileCatalogUtils.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
PoolSvc/FileCatalogUtils.h
"
6
7
#include <algorithm>
8
#include <exception>
9
10
void
FileCatalogUtils::
11
getFirstPFN
(
const
Gaudi::IFileCatalog& fc,
12
const
std::string& fid, std::string& pfn, std::string& tech )
13
{
14
Gaudi::IFileCatalog::Files pfns_techs;
15
fc.getPFN( fid, pfns_techs );
16
if
( pfns_techs.empty() ) {
17
pfn.clear();
18
tech.clear();
19
}
else
{
20
pfn = pfns_techs[0].first;
21
tech = pfns_techs[0].second;
22
}
23
}
24
25
26
void
FileCatalogUtils::
27
lookupFileByPFN
(
const
Gaudi::IFileCatalog& fc,
28
const
std::string& pfn, std::string& fid, std::string& tech )
29
{
30
fid = fc.lookupPFN( pfn );
31
tech.clear();
32
if
( !fid.empty() ) {
33
Gaudi::IFileCatalog::Files pfns_techs;
34
fc.getPFN( fid, pfns_techs );
35
for
(
const
auto
& attr_pair: pfns_techs ) {
36
if
( attr_pair.first == pfn )
37
tech = attr_pair.second;
38
}
39
}
40
}
41
42
43
void
FileCatalogUtils::
44
registerPFN
( Gaudi::IFileCatalog& fc,
45
const
std::string& pfn,
const
std::string& ftype, std::string& fid )
46
{
47
if
( fc.existsPFN(pfn) ) {
48
throw
std::runtime_error(
"PFN '"
+ pfn +
"' already registered (APR: \" registerPFN \" from \" FileCatalog \")"
);
49
}
50
if
( fid.empty() ) fid = fc.createFID();
51
fc.registerPFN(fid, pfn, ftype);
52
}
53
54
55
std::string
FileCatalogUtils::
56
addCatalog
( Gaudi::IFileCatalogMgr& mgr,
const
std::string& connect,
bool
forWriting )
57
{
58
std::string url;
59
if
( connect.empty() ) {
60
url =
"file:PoolFileCatalog.xml"
;
61
}
else
{
62
auto
pos = connect.find(
"file:"
);
63
url = (pos==std::string::npos)?
"file:"
+ connect : connect.substr(pos);
64
}
65
Gaudi::IFileCatalogMgr::Catalogs& cats = mgr.catalogs();
66
auto
i = std::find_if( cats.begin(), cats.end(),
67
[&](
const
Gaudi::IFileCatalog* f )
68
{ return url == f->connectInfo(); } );
69
std::string addedConnectStr;
70
if
( i==cats.end() ) {
71
// add a new catalog
72
addedConnectStr =
"xmlcatalog_"
+ url;
73
mgr.addCatalog( addedConnectStr );
74
}
75
if
( forWriting ) {
76
mgr.setWriteCatalog( mgr.findCatalog( url,
true
) );
77
}
78
return
addedConnectStr;
79
}
FileCatalogUtils.h
FileCatalogUtils::registerPFN
void registerPFN(Gaudi::IFileCatalog &fc, const std::string &pfn, const std::string &ftype, std::string &fid)
Register PFN, assign new FID if not given. Throws if the PFN is already registered.
Definition
FileCatalogUtils.cxx:44
FileCatalogUtils::addCatalog
std::string addCatalog(Gaudi::IFileCatalogMgr &mgr, const std::string &connect, bool forWriting=false)
Add new catalog, identified by name, to the existing ones, optionally as the write catalog.
Definition
FileCatalogUtils.cxx:56
FileCatalogUtils::lookupFileByPFN
void lookupFileByPFN(const Gaudi::IFileCatalog &fc, const std::string &pfn, std::string &fid, std::string &tech)
Get FID and filetype for a given PFN.
Definition
FileCatalogUtils.cxx:27
FileCatalogUtils::getFirstPFN
void getFirstPFN(const Gaudi::IFileCatalog &fc, const std::string &fid, std::string &pfn, std::string &tech)
Get the first PFN + filetype for the given FID.
Definition
FileCatalogUtils.cxx:11
Generated on
for ATLAS Offline Software by
1.17.0