96int main(
int argc,
char** argv)
103 if( options.exists(
'h') ) {
108 cerr <<
"ERROR! insufficient number of arguments" << endl;
114 if( options.exists(
'u') ){
115 catName=options.getOptByName(
'u');
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();
127 std::unique_ptr<IFileCatalog> mycatalog(
new IFileCatalog);
128 mycatalog->setWriteCatalog(catName);
131 if( action ==
"delete" ) {
133 mycatalog->deleteFID( mycatalog->lookupLFN( lfn ) );
134 }
else if( !pfn.empty() ) {
135 mycatalog->deleteFID( mycatalog->lookupPFN( pfn ) );
137 cerr <<
"ERROR! Use PFN or LFN to specify the entry for deletion: " << endl;
142 }
else if( action ==
"list" ) {
143 if( item ==
"lfn" ) {
146 fids.push_back( mycatalog->lookupPFN( pfn ) );
148 mycatalog->getFIDs( fids );
150 for(
const auto& fid: fids ) {
152 mycatalog->getLFNs( fid,
files );
154 cout <<
file.first <<
" , " <<
file.second << endl;
158 else if( item ==
"pfn" ) {
161 fids.push_back( mycatalog->lookupLFN( lfn ) );
162 }
else if( !guid.empty() ) {
163 fids.emplace_back( std::move(guid) );
166 mycatalog->getFIDs( fids );
168 for(
const auto& fid: fids ) {
170 mycatalog->getPFNs( fid,
files );
172 string pf =
file.first;
173 string filetype = (
file.second.empty()?
string(
"NULL") :
file.second);
174 cout<<pf<<
" "<<filetype<<endl;
178 else if( item ==
"guid" ) {
181 fids.push_back( mycatalog->lookupPFN( pfn ) );
182 }
else if( !lfn.empty() ){
183 fids.push_back( mycatalog->lookupLFN( lfn ) );
185 mycatalog->getFIDs( fids );
187 for(
const auto& fid: fids ) {
192 cerr<<
"ERROR! Unsupported catalog item type for listing: "<< item << endl;
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;
203 mycatalog->registerLFN( mycatalog->lookupPFN(pfn), lfn );
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;
210 mycatalog->registerPFN(pfn,
"ROOT_All", guid);
213 cerr <<
"ERROR! Unsupported catalog item type for registration: "<< item << endl;
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;
223 mycatalog->renamePFN(pfn, newpfn);
226 cerr <<
"ERROR! Unsupported action: " << action << endl;
233 }
catch (
const std::runtime_error& er){
234 cerr<<er.what()<<endl;
236 }
catch (
const std::exception& er){
237 cerr<<er.what()<<endl;