39{
41
44 bool multicolumn;
45 bool header;
46 string title;
48
49 try {
50
51 JParser<> zap(
"Auxiliary program to create TGraph from input file with ASCII data.");
52
59
60 zap(argc, argv);
61 }
62 catch(const exception &error) {
63 FATAL(error.what() << endl);
64 }
65
67
69
70
71 for (vector<string>::const_iterator file_name = inputFile.begin(); file_name != inputFile.end(); ++file_name) {
72
73 const string gname = (title != "" ? title : getFilename(*file_name));
74
75 ifstream in(file_name->c_str());
76
77 while (in.peek() == '#') {
78 in.ignore(numeric_limits<streamsize>::max(), '\n');
79 }
80
82
83 if (header) {
84
85 if (multicolumn) {
86
87 string buffer;
88
90
91 istringstream is(buffer);
92
93 for (
string key; is >>
key; ) {
94 column.push_back(key);
95 }
96 }
97
98 } else {
99
100 in.ignore(numeric_limits<streamsize>::max(), '\n');
101 }
102 }
103
104
105 Double_t
x,
y, ex, ey;
106
107 if (!multicolumn) {
108
113
114 for (
string buffer;
getline(in,buffer); ) {
115
116 istringstream is(buffer);
117
118 if (is >> x) X .push_back(x);
119 if (is >> y) Y .push_back(y);
120 if (is >> ex) EX.push_back(ex);
121 if (is >> ey) EY.push_back(ey);
122 }
123
124 if (X.size() != Y.size()) {
125 FATAL(
"Number of points " << X.size() <<
' ' << Y.size() << endl);
126 }
127
128
129 TGraph* graph = NULL;
130
131 if (EX.empty()) {
132
133 graph = new TGraph(X.size(), X.data(), Y.data());
134
135 } else {
136
137 if (X.size() != EX.size()) {
138 FATAL(
"Number of x points " << X.size() <<
' ' << EX.size() << endl);
139 }
140
141 if (EY.empty()) {
142 EY.swap(EX);
143 EX.resize(X.size(), 0.0);
144 }
145
146 if (Y.size() != EY.size()) {
147 FATAL(
"Number of y points " << Y.size() <<
' ' << EY.size() << endl);
148 }
149
150 graph = new TGraphErrors(X.size(), X.data(), Y.data(), EX.data(), EY.data());
151 }
152
153 if (graph != NULL) {
154
155 graph->SetName(gname.c_str());
156
158
159 DEBUG(
"TGraph " << graph->GetName() << endl);
160
161 graph->Write();
162 }
163
164 } else {
165
168
169 for (
string buffer;
getline(in,buffer); ) {
170
171 istringstream is(buffer);
172
173 if (is >> x) {
174
175 X.push_back(x);
176
177 size_t i = 0;
178
179 for ( ; is >>
y; ++i) {
180
181 if (i == Y.size()) {
182 Y.resize(i+1);
183 }
184
185 Y[i].push_back(y);
186 }
187
188 if (i+1 != column.size()) {
189 FATAL(
"Number of colums " << i+1 <<
' ' << column.size() << endl);
190 }
191 }
192 }
193
194 for (size_t i = 0; i != Y.size(); ++i) {
195
196 TGraph* graph = new TGraph(X.size(), X.data(), Y[i].data());
197
198 ostringstream os;
199
200 os << gname << "[" << column[i+1] << "]";
201
202 graph->SetName(os.str().c_str());
203
205
206 DEBUG(
"TGraph " << graph->GetName() << endl);
207
208 graph->Write();
209 }
210 }
211
212 in.close();
213 }
214
215 out.Write();
216 out.Close();
217}
#define DEBUG(A)
Message macros.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Utility class to parse command line options.
void setLimits(TGraph &g1)
Set limits of TGraph.
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).