ATLAS Offline Software
Loading...
Searching...
No Matches
FileCatalogUtils Namespace Reference

Free-standing helpers for operations on Gaudi's file catalog interfaces (Gaudi::IFileCatalog / Gaudi::IFileCatalogMgr) that have no direct equivalent there, so clients can use those interfaces directly instead of a wrapper class. More...

Functions

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.
void lookupFileByPFN (const Gaudi::IFileCatalog &fc, const std::string &pfn, std::string &fid, std::string &tech)
 Get FID and filetype for a given PFN.
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.
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.

Detailed Description

Free-standing helpers for operations on Gaudi's file catalog interfaces (Gaudi::IFileCatalog / Gaudi::IFileCatalogMgr) that have no direct equivalent there, so clients can use those interfaces directly instead of a wrapper class.

Function Documentation

◆ addCatalog()

std::string FileCatalogUtils::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.

Returns the full connect string of the newly added catalog, or an empty string if it already existed and nothing was added.

Definition at line 55 of file FileCatalogUtils.cxx.

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}

◆ getFirstPFN()

void FileCatalogUtils::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 at line 10 of file FileCatalogUtils.cxx.

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}

◆ lookupFileByPFN()

void FileCatalogUtils::lookupFileByPFN ( const Gaudi::IFileCatalog & fc,
const std::string & pfn,
std::string & fid,
std::string & tech )

Get FID and filetype for a given PFN.

Definition at line 26 of file FileCatalogUtils.cxx.

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}

◆ registerPFN()

void FileCatalogUtils::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 at line 43 of file FileCatalogUtils.cxx.

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}