ATLAS Offline Software
Loading...
Searching...
No Matches
FCcmd.cxx File Reference
#include "PoolSvc/IFileCatalog.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 96 of file FCcmd.cxx.

97{
99
100 Options options(argc, argv);
101 // possible options:
102 // const char* opts[] = {"n","l","p","g","u","h",0};
103 if( options.exists('h') ) {
104 printUsage();
105 return 0;
106 }
107 if( argc < 3 ){
108 cerr << "ERROR! insufficient number of arguments" << endl;
109 printUsage();
110 return 1;
111 }
112 string catName;
113 // In case none of the options below work, the default FC name is specified in IFileCatalog::addCatalog()
114 if( options.exists('u') ){
115 catName=options.getOptByName('u');
116 }else{
117 catName=getEnvStr("POOL_CATALOG");
118 }
119 string lfn = options.getOptByName('l');
120 string pfn = options.getOptByName('p');
121 string newpfn = options.getOptByName('n');
122 string guid = options.getOptByName('g');
123 string action = options.getAction();
124 string item = options.getItem();
125
126 try{
127 std::unique_ptr<IFileCatalog> mycatalog(new IFileCatalog);
128 mycatalog->setWriteCatalog(catName);
129 mycatalog->start();
130
131 if( action == "delete" ) {
132 if( !lfn.empty() ){
133 mycatalog->deleteFID( mycatalog->lookupLFN( lfn ) );
134 }else if( !pfn.empty() ) {
135 mycatalog->deleteFID( mycatalog->lookupPFN( pfn ) );
136 }else {
137 cerr << "ERROR! Use PFN or LFN to specify the entry for deletion: " << endl;
138 printUsage();
139 return 2;
140 }
141
142 } else if( action == "list" ) {
143 if( item == "lfn" ) {
145 if( !pfn.empty() ) {
146 fids.push_back( mycatalog->lookupPFN( pfn ) );
147 }else{
148 mycatalog->getFIDs( fids );
149 }
150 for( const auto& fid: fids ) {
152 mycatalog->getLFNs( fid, files );
153 for( const auto& file: files ) {
154 cout << file.first << " , " << file.second << endl;
155 }
156 }
157 }
158 else if( item == "pfn" ) {
160 if( !lfn.empty() ) {
161 fids.push_back( mycatalog->lookupLFN( lfn ) );
162 } else if( !guid.empty() ) {
163 fids.emplace_back( std::move(guid) );
164 } else {
165 // go through all FIDs in the catalog
166 mycatalog->getFIDs( fids );
167 }
168 for( const auto& fid: fids ) {
170 mycatalog->getPFNs( fid, files );
171 for( const auto& file: files ) {
172 string pf = file.first;
173 string filetype = (file.second.empty()? string("NULL") : file.second);
174 cout<<pf<<" "<<filetype<<endl;
175 }
176 }
177 }
178 else if( item == "guid" ) {
180 if( !pfn.empty() ){
181 fids.push_back( mycatalog->lookupPFN( pfn ) );
182 } else if( !lfn.empty() ){
183 fids.push_back( mycatalog->lookupLFN( lfn ) );
184 } else {
185 mycatalog->getFIDs( fids );
186 }
187 for( const auto& fid: fids ) {
188 cout << fid << endl;
189 }
190 }
191 else {
192 cerr<< "ERROR! Unsupported catalog item type for listing: "<< item << endl;
193 printUsage();
194 return 2;
195 }
196
197 } else if( action == "register" ) {
198 if( item == "lfn" ) {
199 if( pfn.empty() || lfn.empty() ){
200 cerr<<"ERROR! You must specify PFName using -p and LFName using -l" << endl;
201 return 3;
202 }
203 mycatalog->registerLFN( mycatalog->lookupPFN(pfn), lfn );
204 }
205 else if( item == "pfn" ) {
206 if( pfn.empty() or guid.empty() ) {
207 cerr<<"ERROR! You must specify PFName using -p and GUID using -g options" << endl;
208 return 3;
209 }
210 mycatalog->registerPFN(pfn, "ROOT_All", guid);
211 }
212 else {
213 cerr << "ERROR! Unsupported catalog item type for registration: "<< item << endl;
214 printUsage();
215 return 3;
216 }
217
218 } else if( action == "rename" ) {
219 if( pfn.empty() || newpfn.empty() ){
220 cerr<<"ERROR! You must specify the current PFName using -p and the new PFName using -n option" << endl;
221 return 4;
222 }
223 mycatalog->renamePFN(pfn, newpfn);
224 }
225 else {
226 cerr << "ERROR! Unsupported action: " << action << endl;
227 printUsage();
228 return 10;
229 }
230
231 mycatalog->commit();
232
233 }catch (const std::runtime_error& er){
234 cerr<<er.what()<<endl;
235 return 1;
236 }catch (const std::exception& er){
237 cerr<<er.what()<<endl;
238 return 1;
239 }
240}
void printUsage()
Definition FCcmd.cxx:19
Gaudi::IFileCatalog::Strings Strings
Gaudi::IFileCatalog::Files Files
static bool initGaudi()
initialize the Gaudi framework for standalone executables
std::vector< std::string > files
file names and file pointers
Definition hcg.cxx:52
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 19 of file FCcmd.cxx.

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