forked from SridharaDasu/SimpleRootTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadASCIINTuple.C
44 lines (30 loc) · 1012 Bytes
/
readASCIINTuple.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <fstream>
#include <string.h>
#include "TNtuple.h"
void readASCIINTuple(char *inputFileName) {
ifstream in(inputFileName);
char headerLine[1024];
in.getline(headerLine, 1024);
char variableNames[1024];
char *token = strtok(headerLine, " \t");
if(token == NULL) exit(1);
strcpy(variableNames, token);
int nVariables = 1;
while(true) {
token = strtok(NULL, " \t");
if(token == NULL) break;
strcat(variableNames, ":");
strcat(variableNames, token);
}
std::cout << "variableNames = " << variableNames << std::endl;
token = strtok(inputFileName, ".");
char outputFileName[1024];
strcpy(outputFileName, inputFileName);
strcat(outputFileName, ".root");
std::cout << "outputFileName = " << outputFileName << std::endl;
TFile *f = new TFile(outputFileName, "RECREATE");
TNtuple *nTuple = new TNtuple(inputFileName, inputFileName, variableNames);
cout << "Number of rows read = " << nTuple->ReadStream(in) << endl;
in.close();
f->Write();
}