28{
   31  
   36 
   37  try {
   38 
   39    JParser<> zap(
"Auxiliary program to rename ROOT objects.");
 
   40 
   41    zap[
'f'] = 
make_field(inputFile,  
"<input file>:<object name>");
 
   43    zap[
'R'] = 
make_field(rename,     
"<target> <replacement>");
 
   45 
   46    zap(argc, argv);
   47  }
   48  catch(const exception &error) {
   49    FATAL(error.what() << endl);
 
   50  }
   51 
   52 
   54 
   55  for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
   56 
   57    DEBUG(
"Input: " << *input << endl);
 
   58 
   60 
   61    if (dir == NULL) {
   62      ERROR(
"File: " << input->getFullFilename() << 
" not opened." << endl);
 
   63      continue;
   64    }
   65 
   66    const TRegexp regexp(input->getObjectName());
   67 
   68    TIter iter(dir->GetListOfKeys());
   69 
   70    for (TKey* key; (
key = (TKey*) iter.Next()) != NULL; ) {
 
   71 
   72      const TString tag(
key->GetName());
 
   73 
   74      DEBUG(
"Key: " << tag << 
" match = " << tag.Contains(regexp) << endl);
 
   75 
   76      
   77 
   78      if (tag.Contains(regexp) && 
isTObject(key)) {
 
   79 
   81        TString   buffer = p->GetName();
   82 
   83        buffer.ReplaceAll(
rename.first.c_str(), 
rename.second.c_str());
 
   84 
   85        DEBUG(p->GetName() << 
" -> " << buffer << endl);
 
   86 
   87        dynamic_cast<TNamed*>(p)->SetName(buffer);
   88 
   89        listOfObjects.push_back(p);
   90      }
   91    }
   92  }
   93 
   94 
   96 
   97  for (
TObject* p: listOfObjects) {
 
   98    p->Write();
   99  }
  100    
  101  out.Write();
  102  out.Close();
  103}
#define DEBUG(A)
Message macros.
 
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
 
Utility class to parse command line options.
 
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
 
bool isTObject(const TKey *key)
Check if given key corresponds to a TObject.
 
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
 
int rename(const std::string &inputFile, const std::string &outputFile)
Rename file across file systems.