void KVDP2toCsIGridConvertor::ReadGammaFile(const Char_t* gammafile) { ifstream gamfile; gamfile.open(gammafile); if (!gamfile.good()) { Error(KV__ERROR(ReadGammaFile), "Problem reading file %s", gammafile); return; } KVString s; s.ReadLine(gamfile); while (gamfile.good()) { if (s == "") { s.ReadLine(gamfile); continue; } if (!s.BeginsWith('#')) { //'#' sign signals comments int ring, modu, frun, lrun; if (sscanf(s.Data(), "%d %d %d %d", &ring, &modu, &frun, &lrun) != 4) { Error(KV__ERROR(ReadGammaFile), "Problem reading file %s\nLast line read: %s", gammafile, s.Data()); return; }; //get grid for this ring,mod TString name; name. Form ("CsI R-L Grid First run=%d Last run=%d Ring min=%d Ring max=%d Mod min=%d Mod max=%d", frun, lrun, ring, ring, modu, modu); KVIDGrid* grid = (KVIDGrid*)fGrids->FindObject(name.Data()); if (!grid) { Error(KV__ERROR(ReadGammaFile), "Can't find grid %s", name.Data()); } int npoints; gamfile >> npoints; //found gamma line KVIDLine* line = 0; if (grid) { line = grid->NewLine("ok"); line->SetName("gamma_line"); line->Set(npoints); grid->Add("ok", line); } //read in points for (int i = 0; i < npoints; i++) { Double_t x, y; gamfile >> x >> y; if (grid) line->SetPoint(i, x, y); } } s.ReadLine(gamfile); }
void KVDP2toIDGridConvertor::ReadFile(const Char_t* filename) { // Read grids in file and add to fGrids list if (!fGridClass) { Error(KV__ERROR(ReadFile), "Set class of ID grids to generate first!"); return; } ifstream datfile; datfile.open(filename); if (!datfile.good()) { Error(KV__ERROR(ReadFile), "Problem reading file %s", filename); return; } KVString s; s.ReadLine(datfile); while (datfile.good()) { if (s == "") { s.ReadLine(datfile); continue; } if (!s.BeginsWith('#')) { //'#' sign signals comments int ring, modu, frun, lrun, totpoints; if (sscanf(s.Data(), "%d %d %d %d", &ring, &modu, &frun, &lrun) != 4) { Error(KV__ERROR(ReadFile), "Problem reading file %s\nLast line read: %s", filename, s.Data()); return; }; KVIDGrid* grid = (KVIDGrid*) fGridClass->New(); //create new grid //add to list of grids fGrids->Add(grid); grid->GetParameters()->SetValue("First run", frun); grid->GetParameters()->SetValue("Last run", lrun); grid->GetParameters()->SetValue("Ring min", ring); grid->GetParameters()->SetValue("Ring max", ring); grid->GetParameters()->SetValue("Mod min", modu); grid->GetParameters()->SetValue("Mod max", modu); int nlines; datfile >> nlines; totpoints = 0; //read Z,A and number of points in each line for (int i = 0; i < nlines; i++) { int z, a, npoints; datfile >> z >> a >> npoints; totpoints += 2 * npoints; if (z > 0) { //identification line KVIDLine* line = (KVIDLine*)grid->NewLine("id"); line->SetZ(z); line->SetA(a); line->Set(npoints); grid->Add("id", line); } else { //"ok" line KVIDLine* line = (KVIDLine*)grid->NewLine("ok"); line->Set(npoints); grid->Add("ok", line); } } ReadLineCoords(grid, datfile); //calculate line widths in grid grid->CalculateLineWidths(); } s.ReadLine(datfile); }