#include #include #include #include #include #include #include "data.h" #include "util.h" using namespace std; Tube *read_tubes(const char *path, int *n) { FILE *f = fopen(path, "r"); if(!f) { fprintf(stderr, "cannot read tubes file %s\n", path); exit(-1); return 0; } *n = 0; vector tubes; int id, row, sector; float px, py, pz, dx, dy, dz, half_length; int nread_pos; const int GOOD_NREAD_POS = 10; while((nread_pos = fscanf (f, "%d %f %f %f %f %f %f %f %d %d %*[\n]", &id, &px, &py, &pz, &dx, &dy, &dz, &half_length, &row, §or)) > 0) { if(nread_pos < GOOD_NREAD_POS) { fprintf(stderr, "cannot read tube line from file %s\n", path); exit(-1); return 0; } //if(dz != 1.0f && id != 0) // continue; tubes.push_back(Tube(id, fvec3::from(px, py, pz), fvec3::from(dx, dy, dz), half_length, row, sector)); //Tube tube = tubes.back(); //printf("read tube id=%d x=%lf y=%lf\n", tube.id, (double)tube.pos.x, // (double)tube.pos.y); } // while() fclose(f); *n = tubes.size(); Tube *res; cucheck(cudaMallocHost((void **)&res, *n * sizeof(Tube))); copy(tubes.begin(), tubes.end(), res); return res; } // read_tubes Hit *read_hits(const char *path, int *n) { FILE *f = fopen(path, "r"); if(!f) { fprintf(stderr, "cannot read hits file %s\n", path); exit(-1); return 0; } int max_nhits = *n; if(max_nhits < 0) max_nhits = INT_MAX; *n = 0; vector hits; int tube_id; float t; int nread_pos; const int GOOD_NREAD_POS = 2; int line = 1; while(hits.size() < max_nhits && (nread_pos = fscanf(f, "%f %d %*[\n]", &t, &tube_id)) > 0) { if(nread_pos < GOOD_NREAD_POS) { fprintf(stderr, "cannot read hit line %d from file %s\n", line, path); exit(-1); return 0; } hits.push_back(Hit(t, tube_id)); line++; } // while() fclose(f); *n = hits.size(); Hit *res; cucheck(cudaMallocHost((void **)&res, *n * sizeof(Hit))); copy(hits.begin(), hits.end(), res); return res; } // read_hits