97{
99
101
102
105 return 0;
106 }
107 if( argc < 3 ){
108 cerr << "ERROR! insufficient number of arguments" << endl;
110 return 1;
111 }
113
116 }else{
118 }
120 string pfn =
options.getOptByName(
'p');
121 string newpfn =
options.getOptByName(
'n');
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" ) {
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;
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 );
154 cout <<
file.first <<
" , " <<
file.second << endl;
155 }
156 }
157 }
158 else if( item == "pfn" ) {
161 fids.push_back( mycatalog->lookupLFN( lfn ) );
162 }
else if( !
guid.empty() ) {
163 fids.emplace_back( std::move(guid) );
164 } else {
165
166 mycatalog->getFIDs( fids );
167 }
168 for( const auto& fid: fids ) {
170 mycatalog->getPFNs( fid,
files );
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;
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;
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;
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}
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
std::string getEnvStr(const std::string &key)
Read an environment variable into string (returns empty string if not set).