98int main(
int argc,
char** argv)
105 if( options.exists(
'h') ) {
110 cerr <<
"ERROR! insufficient number of arguments" << endl;
116 if( options.exists(
'u') ){
117 catName=options.getOptByName(
'u');
121 string lfn = options.getOptByName(
'l');
122 string pfn = options.getOptByName(
'p');
123 string newpfn = options.getOptByName(
'n');
124 string guid = options.getOptByName(
'g');
125 string action = options.getAction();
126 string item = options.getItem();
129 SmartIF<Gaudi::IFileCatalogMgr> catalogMgr = Gaudi::svcLocator()->service<Gaudi::IFileCatalogMgr>(
"Gaudi::MultiFileCatalog" );
130 SmartIF<Gaudi::IFileCatalog> mycatalog( catalogMgr );
134 if( action ==
"delete" ) {
136 mycatalog->deleteFID( mycatalog->lookupLFN( lfn ) );
137 }
else if( !pfn.empty() ) {
138 mycatalog->deleteFID( mycatalog->lookupPFN( pfn ) );
140 cerr <<
"ERROR! Use PFN or LFN to specify the entry for deletion: " << endl;
145 }
else if( action ==
"list" ) {
146 if( item ==
"lfn" ) {
147 Gaudi::IFileCatalog::Strings fids;
149 fids.push_back( mycatalog->lookupPFN( pfn ) );
151 mycatalog->getFID( fids );
153 for(
const auto& fid: fids ) {
154 Gaudi::IFileCatalog::Files
files;
155 mycatalog->getLFN( fid,
files );
157 cout <<
file.first <<
" , " <<
file.second << endl;
161 else if( item ==
"pfn" ) {
162 Gaudi::IFileCatalog::Strings fids;
164 fids.push_back( mycatalog->lookupLFN( lfn ) );
165 }
else if( !guid.empty() ) {
166 fids.emplace_back( std::move(guid) );
169 mycatalog->getFID( fids );
171 for(
const auto& fid: fids ) {
172 Gaudi::IFileCatalog::Files
files;
173 mycatalog->getPFN( fid,
files );
175 string pf =
file.first;
176 string filetype = (
file.second.empty()?
string(
"NULL") :
file.second);
177 cout<<pf<<
" "<<filetype<<endl;
181 else if( item ==
"guid" ) {
182 Gaudi::IFileCatalog::Strings fids;
184 fids.push_back( mycatalog->lookupPFN( pfn ) );
185 }
else if( !lfn.empty() ){
186 fids.push_back( mycatalog->lookupLFN( lfn ) );
188 mycatalog->getFID( fids );
190 for(
const auto& fid: fids ) {
195 cerr<<
"ERROR! Unsupported catalog item type for listing: "<< item << endl;
200 }
else if( action ==
"register" ) {
201 if( item ==
"lfn" ) {
202 if( pfn.empty() || lfn.empty() ){
203 cerr<<
"ERROR! You must specify PFName using -p and LFName using -l" << endl;
206 mycatalog->registerLFN( mycatalog->lookupPFN(pfn), lfn );
208 else if( item ==
"pfn" ) {
209 if( pfn.empty() or guid.empty() ) {
210 cerr<<
"ERROR! You must specify PFName using -p and GUID using -g options" << endl;
216 cerr <<
"ERROR! Unsupported catalog item type for registration: "<< item << endl;
221 }
else if( action ==
"rename" ) {
222 if( pfn.empty() || newpfn.empty() ){
223 cerr<<
"ERROR! You must specify the current PFName using -p and the new PFName using -n option" << endl;
226 mycatalog->renamePFN(pfn, newpfn);
229 cerr <<
"ERROR! Unsupported action: " << action << endl;
236 }
catch (
const std::runtime_error& er){
237 cerr<<er.what()<<endl;
239 }
catch (
const std::exception& er){
240 cerr<<er.what()<<endl;
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.