38 return object.ReadLine(in);
50 return out <<
object.Data();
63inline TString
replace(
const TString& target,
const TRegexp& regexp,
const T& replacement)
68 TString buffer = target;
70 if ((pos = buffer.Index(regexp, &len)) != -1) {
72 TSubString substr = buffer(pos, len);
74 TString format(substr.Data(), substr.Length());
76 format.ReplaceAll(
"T",
"s");
78 buffer.Replace(pos, len, TString::Format(format.Data(), replacement));
95int main(
int argc,
char **argv)
107 JParser<> zap(
"Auxiliary program to print result from ROOT objects."\
108 "\nNote that the formula may contain method names of the specified object.");
110 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
112 zap[
'O'] =
make_field(option,
"format, e.g. \"%s %T %f\","\
113 "\nwhere '%s', '%T' and '%f' will be replaced by name, title and value(s) from formula(s), respectively") =
"";
118 catch(
const exception &error) {
119 FATAL(error.what() << endl);
123 const TRegexp STRING(
"%[+-]?[0-9]*s");
124 const TRegexp TITLE (
"%[+-]?[0-9]*T");
125 const TRegexp DOUBLE(
"%[+-]?[0-9]*\\.?[0-9]*f");
128 for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
130 DEBUG(
"Input: " << *input << endl);
132 TDirectory* dir = getDirectory(*input);
135 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
139 const TRegexp regexp(input->getObjectName());
141 TIter iter(dir->GetListOfKeys());
143 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
145 const TString tag(key->GetName());
147 DEBUG(
"Key: " << tag <<
" match = " << tag.Contains(regexp) << endl);
151 if (tag.Contains(regexp) && isTObject(key)) {
153 TObject*
object = key->ReadObj();
159 TString buffer = option;
161 buffer =
replace(buffer, STRING, object->GetName());
162 buffer =
replace(buffer, TITLE, object->GetTitle());
164 for (vector<JFormula>::const_iterator i = formula.begin(); i != formula.end(); ++i) {
166 const double value = getResult(*i,
object);
168 if (buffer.Contains(DOUBLE)){
170 buffer =
replace(buffer, DOUBLE, value);
174 if (i != formula.begin()) {
178 buffer.Append(TString::Format(
"%20.10e", value));
181 cout << buffer << endl;
185 for (vector<JFormula>::const_iterator i = formula.begin(); i != formula.end(); ++i) {
186 cout <<
' ' <<
SCIENTIFIC(20,10) << getResult(*i,
object);
General purpose messaging.
#define DEBUG(A)
Message macros.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
int main(int argc, char **argv)
TString replace(const TString &target, const TRegexp ®exp, const T &replacement)
Replace regular expression in input by given replacement.
std::ostream & operator<<(std::ostream &out, const JFormula &object)
Write formula to output stream.
std::istream & operator>>(std::istream &in, JFormula &object)
Read formula from input stream.
I/O formatting auxiliaries.
Utility class to parse command line options.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Auxiliary data structure for floating point format specification.