Jpp in_tag_pdf_generation
the software that should make you happy
Loading...
Searching...
No Matches
JRename.cc
Go to the documentation of this file.
1
2#include <string>
3#include <iostream>
4#include <iomanip>
5#include <vector>
6
7#include "TROOT.h"
8#include "TFile.h"
9#include "TKey.h"
10#include "TNamed.h"
11#include "TString.h"
12#include "TRegexp.h"
13
16
17#include "Jeep/JParser.hh"
18#include "Jeep/JMessage.hh"
19
20
21/**
22 * \file
23 * Auxiliary program to rename ROOT objects.
24 *
25 * \author mdejong
26 */
27int main(int argc, char **argv)
28{
29 using namespace std;
30 using namespace JPP;
31
32 vector<JRootObjectID> inputFile;
33 string outputFile;
35 int debug;
36
37 try {
38
39 JParser<> zap("Auxiliary program to rename ROOT objects.");
40
41 zap['f'] = make_field(inputFile, "<input file>:<object name>");
42 zap['o'] = make_field(outputFile, "ROOT file with object(s)") = "rename.root";
43 zap['R'] = make_field(rename, "<target> <replacement>");
44 zap['d'] = make_field(debug) = 1;
45
46 zap(argc, argv);
47 }
48 catch(const exception &error) {
49 FATAL(error.what() << endl);
50 }
51
52
53 vector<TObject*> listOfObjects;
54
55 for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
56
57 DEBUG("Input: " << *input << endl);
58
59 TDirectory* dir = getDirectory(*input);
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 // option match
77
78 if (tag.Contains(regexp) && isTObject(key)) {
79
80 TObject* p = key->ReadObj();
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
95 TFile out(outputFile.c_str(), "recreate");
96
97 for (TObject* p: listOfObjects) {
98 p->Write();
99 }
100
101 out.Write();
102 out.Close();
103}
string outputFile
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define ERROR(A)
Definition JMessage.hh:66
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
int main(int argc, char **argv)
Definition JRename.cc:27
Utility class to parse command line options.
Definition JParser.hh:1698
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).