99{
101
103
104
107 return 0;
108 }
109 if( argc < 3 ){
110 cerr << "ERROR! insufficient number of arguments" << endl;
112 return 1;
113 }
115
118 }else{
120 }
122 string pfn =
options.getOptByName(
'p');
123 string newpfn =
options.getOptByName(
'n');
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 );
132 mycatalog->init();
133
134 if( action == "delete" ) {
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;
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 );
157 cout <<
file.first <<
" , " <<
file.second << endl;
158 }
159 }
160 }
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) );
167 } else {
168
169 mycatalog->getFID( fids );
170 }
171 for( const auto& fid: fids ) {
172 Gaudi::IFileCatalog::Files
files;
173 mycatalog->getPFN( fid,
files );
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;
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 }
214 }
215 else {
216 cerr << "ERROR! Unsupported catalog item type for registration: "<< item << endl;
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;
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}
static bool initGaudi()
initialize the Gaudi framework for standalone executables
std::vector< std::string > files
file names and file pointers
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).