ATLAS Offline Software
Loading...
Searching...
No Matches
IFileCatalog.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 "GaudiUtils/IFileCatalog.h"
6#include "GaudiUtils/IFileCatalogMgr.h"
7#include "GaudiKernel/SmartIF.h"
8#include "GaudiKernel/Bootstrap.h"
9#include "GaudiKernel/ISvcLocator.h"
10#include "GaudiKernel/IMessageSvc.h"
11
13#include "StorageSvc/DbPrint.h"
14
15#include <exception>
16#include <algorithm>
17
18using namespace pool;
19
21 : AthMessaging( Gaudi::svcLocator()->service<IMessageSvc>("MessageSvc").get(), "APRFileCatalog" ),
22 m_mgr (Gaudi::svcLocator()->service<Gaudi::IFileCatalogMgr>( "Gaudi::MultiFileCatalog" )),
23 m_fc (m_mgr)
24{
25 // set the output level of this service
27 // set the output level of the XMLCatalog component - works only if the Gaudi AppMgr was initialized
28 Gaudi::svcLocator()->service<IMessageSvc>("MessageSvc")
29 ->setOutputLevel("XMLCatalog", DbPrint::getOutputLvl() );
30}
31
32
34getFirstPFN( const std::string& fid, std::string& pfn, std::string& tech ) const
35{
36 Files pfns_techs;
37 getPFNs( fid, pfns_techs );
38 if( pfns_techs.empty() ) {
39 pfn.clear();
40 tech.clear();
41 } else {
42 pfn = pfns_techs[0].first;
43 tech = pfns_techs[0].second;
44 }
45}
46
47
50lookupFileByPFN( const std::string& pfn, std::string& fid, std::string& tech ) const
51{
52 fid = lookupPFN( pfn );
53 if( !fid.empty() ) {
54 Files pfns_techs;
55 getPFNs( fid, pfns_techs );
56 tech.clear();
57 for( const auto& attr_pair: pfns_techs ) {
58 if( attr_pair.first == pfn )
59 tech = attr_pair.second;
60 }
61 }
62}
63
64
67registerPFN( const std::string& pfn, const std::string& ftype, std::string& fid )
68{
69 if( existsPFN(pfn) ) {
70 throw std::runtime_error("PFN '" + pfn + "' already registered (APR: \" registerPFN \" from \" FileCatalog \")");
71 }
72 if( fid.empty() ) fid = m_fc->createFID();
73 ATH_MSG_DEBUG("Registering PFN=" << pfn << " of type=" << ftype << " GUID=" << fid);
74 m_fc->registerPFN(fid, pfn, ftype);
75}
76
77
78// ------------------------- Catalog Manager interface
79
81void pool::IFileCatalog::addCatalog( const std::string& connect, bool forWriting )
82{
83 std::string url;
84 if( connect.empty() ) {
85 url = "file:PoolFileCatalog.xml";
86 } else {
87 auto pos = connect.find("file:");
88 url = (pos==std::string::npos)? "file:" + connect : connect.substr(pos);
89 }
90 Catalogs& cats = m_mgr->catalogs();
91 auto i = std::find_if( cats.begin(), cats.end(),
92 [&]( const Gaudi::IFileCatalog* f )
93 { return url == f->connectInfo(); } );
94 if( i==cats.end() ) {
95 // add a new catalog
96 const std::string fullconnectstr = "xmlcatalog_" + url;
97 ATH_MSG_DEBUG("addCatalog(\"" << fullconnectstr << "\")" );
98 m_mgr->addCatalog( fullconnectstr );
99 }
100 if( forWriting ) {
101 m_mgr->setWriteCatalog( m_mgr->findCatalog( url, true ) );
102 }
103}
104
105
#define ATH_MSG_DEBUG(x,...)
void setLevel(MSG::Level lvl)
Change the current logging level.
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
static MSG::Level getOutputLvl()
void addCatalog(const std::string &connect, bool forWriting=false)
Add new catalog identified by name to the existing ones.
void getPFNs(const std::string &fid, Files &files) const
Dump all PFNames of the catalog and their attributes associate to the FileID.
void lookupFileByPFN(const std::string &pfn, std::string &fid, std::string &tech) const
Get FID and filetype for a given PFN.
SmartIF< Gaudi::IFileCatalog > m_fc
bool existsPFN(const std::string &pfn) const
Return the status of a PFName.
void getFirstPFN(const std::string &fid, std::string &pfn, std::string &tech) const
Get the first PFN + filetype for the given FID.
SmartIF< Gaudi::IFileCatalogMgr > m_mgr
Gaudi::IFileCatalog::Files Files
Gaudi::IFileCatalogMgr::Catalogs Catalogs
void registerPFN(const std::string &pfn, const std::string &ftype, std::string &fid)
Register PFN, assign new FID if not given.
std::string lookupPFN(const std::string &pfn) const
Lookup file identifier by physical file name.
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:132
=============================================================================
Framework include files.
Definition libname.h:15