ATLAS Offline Software
Loading...
Searching...
No Matches
FCcmd.cxx File Reference
#include "PoolSvc/FileCatalogUtils.h"
#include "GaudiKernel/Bootstrap.h"
#include "GaudiKernel/ISvcLocator.h"
#include "StorageSvc/SimpleUtilityBase.h"
#include <exception>
#include <memory>
Include dependency graph for FCcmd.cxx:

Go to the source code of this file.

Classes

class  Options

Functions

void printUsage ()
int main (int argc, char **argv)

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 98 of file FCcmd.cxx.

99{
101
102 Options options(argc, argv);
103 // possible options:
104 // const char* opts[] = {"n","l","p","g","u","h",0};
105 if( options.exists('h') ) {
106 printUsage();
107 return 0;
108 }
109 if( argc < 3 ){
110 cerr << "ERROR! insufficient number of arguments" << endl;
111 printUsage();
112 return 1;
113 }
114 string catName;
115 // In case none of the options below work, the default FC name is specified in FileCatalogUtils::addCatalog()
116 if( options.exists('u') ){
117 catName=options.getOptByName('u');
118 }else{
119 catName=getEnvStr("POOL_CATALOG");
120 }
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();
127
128 try{
129 SmartIF<Gaudi::IFileCatalogMgr> catalogMgr = Gaudi::svcLocator()->service<Gaudi::IFileCatalogMgr>( "Gaudi::MultiFileCatalog" );
130 SmartIF<Gaudi::IFileCatalog> mycatalog( catalogMgr );
131 FileCatalogUtils::addCatalog( *catalogMgr, catName, true );
132 mycatalog->init();
133
134 if( action == "delete" ) {
135 if( !lfn.empty() ){
136 mycatalog->deleteFID( mycatalog->lookupLFN( lfn ) );
137 }else if( !pfn.empty() ) {
138 mycatalog->deleteFID( mycatalog->lookupPFN( pfn ) );
139 }else {
140 cerr << "ERROR! Use PFN or LFN to specify the entry for deletion: " << endl;
141 printUsage();
142 return 2;
143 }
144
145 } else if( action == "list" ) {
146 if( item == "lfn" ) {
147 Gaudi::IFileCatalog::Strings fids;
148 if( !pfn.empty() ) {
149 fids.push_back( mycatalog->lookupPFN( pfn ) );
150 }else{
151 mycatalog->getFID( fids );
152 }
153 for( const auto& fid: fids ) {
154 Gaudi::IFileCatalog::Files files;
155 mycatalog->getLFN( fid, files );
156 for( const auto& file: files ) {
157 cout << file.first << " , " << file.second << endl;
158 }
159 }
160 }
161 else if( item == "pfn" ) {
162 Gaudi::IFileCatalog::Strings fids;
163 if( !lfn.empty() ) {
164 fids.push_back( mycatalog->lookupLFN( lfn ) );
165 } else if( !guid.empty() ) {
166 fids.emplace_back( std::move(guid) );
167 } else {
168 // go through all FIDs in the catalog
169 mycatalog->getFID( fids );
170 }
171 for( const auto& fid: fids ) {
172 Gaudi::IFileCatalog::Files files;
173 mycatalog->getPFN( fid, files );
174 for( const auto& file: files ) {
175 string pf = file.first;
176 string filetype = (file.second.empty()? string("NULL") : file.second);
177 cout<<pf<<" "<<filetype<<endl;
178 }
179 }
180 }
181 else if( item == "guid" ) {
182 Gaudi::IFileCatalog::Strings fids;
183 if( !pfn.empty() ){
184 fids.push_back( mycatalog->lookupPFN( pfn ) );
185 } else if( !lfn.empty() ){
186 fids.push_back( mycatalog->lookupLFN( lfn ) );
187 } else {
188 mycatalog->getFID( fids );
189 }
190 for( const auto& fid: fids ) {
191 cout << fid << endl;
192 }
193 }
194 else {
195 cerr<< "ERROR! Unsupported catalog item type for listing: "<< item << endl;
196 printUsage();
197 return 2;
198 }
199
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;
204 return 3;
205 }
206 mycatalog->registerLFN( mycatalog->lookupPFN(pfn), lfn );
207 }
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;
211 return 3;
212 }
213 FileCatalogUtils::registerPFN(*mycatalog, pfn, "ROOT_All", guid);
214 }
215 else {
216 cerr << "ERROR! Unsupported catalog item type for registration: "<< item << endl;
217 printUsage();
218 return 3;
219 }
220
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;
224 return 4;
225 }
226 mycatalog->renamePFN(pfn, newpfn);
227 }
228 else {
229 cerr << "ERROR! Unsupported action: " << action << endl;
230 printUsage();
231 return 10;
232 }
233
234 mycatalog->commit();
235
236 }catch (const std::runtime_error& er){
237 cerr<<er.what()<<endl;
238 return 1;
239 }catch (const std::exception& er){
240 cerr<<er.what()<<endl;
241 return 1;
242 }
243}
void printUsage()
Definition FCcmd.cxx:21
static bool initGaudi()
initialize the Gaudi framework for standalone executables
std::vector< std::string > files
file names and file pointers
Definition hcg.cxx:52
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.
std::string getEnvStr(const std::string &key)
Read an environment variable into string (returns empty string if not set).
TFile * file

◆ printUsage()

void printUsage ( )

Definition at line 21 of file FCcmd.cxx.

21 {
22 cout <<
23 "Usage: " << endl <<
24 "FCcmd <action> <item> [-p PFName -l LFName -n newPFName -g GUID -u catalogName -h]" << endl <<
25 " supported actions are:" <<endl <<
26 " register : <item> = lfn|pfn (registering a PFN requires a GUID)" <<endl <<
27 " list : <item> = guid|lfn|pfn" <<endl <<
28 " delete : deletes an entry using LFN or PFN" <<endl <<
29 " rename : rename PFName to a new PFName" <<endl <<
30 " example: FCcmd list pfn -l myLogicalFileName" << endl;
31}