35int main(
int argc,
char **argv)
38 char str1[127], str2[127], *stra, *strb;
41 short mat[4096] = {0};
47 std::cout <<
"No input file specified" << std::endl;
55 printf(
"writing to %s\n", argv[2]);
57 RootName =
"bin2root.root";
58 printf(
"writing to bin2root.root\n");
60 TFile *fRoot =
new TFile(RootName,
"RECREATE");
69 current_dir = opendir(
".");
72 while ((dir = readdir(current_dir)) != NULL) {
75 strcpy(str1, dir->d_name);
76 stra = strtok(str1,
".");
77 strb = strtok(NULL,
".");
80 for (
int i = 0; i < (int)strlen(str1); i++) {
81 if (str1[i] ==
'-' || str1[i] ==
' ') {
87 str2[(int)strlen(str1)] =
'\0';
91 if (stra != NULL && strb != NULL) {
95 if (strcmp(strb,
"mat") == 0) {
96 if ((
fp = fopen(dir->d_name,
"r")) == NULL) {
97 fprintf(stderr,
"Error, cannot open input file %s\n", dir->d_name);
102 fseek(
fp, 0L, SEEK_END);
103 ydim = (ftell(
fp) /
sizeof(
short int)) / 4096;
108 mat1d =
new TH1S(Form(
"ID%s",str2), Form(
"ID%s",str2), 4096, 0, 4096);
109 }
else if (ydim > 1) {
110 mat2d =
new TH2S(Form(
"ID%s",str2), Form(
"ID%s",str2), 4096, 0, 4096, ydim, 0, ydim);
112 printf(
"no data in %s\n", dir->d_name);
117 for (
int i = 0; i < ydim; i++) {
118 if (fread(mat, 4096 *
sizeof(
short int), 1,
fp) == 1) {
119 for (
int j = 0; j < 4096; j++) {
121 std::cout <<
"filling " << j <<
" " << i <<
" " << mat[j] << std::endl;
123 for (
int k = 0; k < mat[j]; k++) {
128 mat2d->Fill(j+0.5, i+0.5);
132 printf(
"Error in reading file\n");
141 printf(
"read in %s, 4096 row width, short int : y = %d rows\n", dir->d_name, ydim);
146 if (strcmp(strb,
"spn") == 0) {
147 if ((
fp = fopen(dir->d_name,
"r")) == NULL) {
148 fprintf(stderr,
"Error, cannot open input file %s\n", dir->d_name);
153 fseek(
fp, 0L, SEEK_END);
154 ydim = (ftell(
fp) /
sizeof(int)) / 4096;
159 spn1d =
new TH1I(Form(
"ID%s",str2), Form(
"ID%s",str2), 4096, 0, 4096);
160 }
else if (ydim > 1) {
161 spn2d =
new TH2I(Form(
"ID%s",str2), Form(
"ID%s",str2), 4096, 0, 4096, ydim, 0, ydim);
163 printf(
"no data in %s\n", dir->d_name);
168 for (
int i = 0; i < ydim; i++) {
169 if (fread(spn, 4096 *
sizeof(
int), 1,
fp) == 1) {
170 for (
int j = 0; j < 4096; j++) {
171 for (
int k = 0; k < spn[j]; k++) {
180 printf(
"Error in reading file\n");
189 printf(
"read in %s, 4096 row width, int : y = %d rows\n", dir->d_name, ydim);
194 if (strcmp(strb,
"sec") == 0) {
195 if ((
fp = fopen(dir->d_name,
"r")) == NULL) {
196 fprintf(stderr,
"Error, cannot open input file %s\n", dir->d_name);
201 fseek(
fp, 0L, SEEK_END);
202 ydim = (ftell(
fp) /
sizeof(int)) / 8192;
207 sec1d =
new TH1I(Form(
"ID%s",str2), Form(
"ID%s",str2), 8192, 0, 8192);
208 }
else if (ydim > 1) {
209 sec2d =
new TH2I(Form(
"ID%s",str2), Form(
"ID%s",str2), 8192, 0, 8192, ydim, 0, ydim);
211 printf(
"no data in %s\n", dir->d_name);
216 for (
int i = 0; i < ydim; i++) {
217 if (fread(sec, 8192 *
sizeof(
int), 1,
fp) == 1) {
218 for (
int j = 0; j < 8192; j++) {
219 for (
int k = 0; k < sec[j]; k++) {
228 printf(
"Error in reading file\n");
237 printf(
"read in %s, 8192 row width, int : y = %d rows\n", dir->d_name, ydim);
241 closedir(current_dir);