KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVDP2toIDGridConvertor.cpp
Go to the documentation of this file.
1 /*
2 $Id: KVDP2toIDGridConvertor.cpp,v 1.2 2009/03/06 08:59:18 franklan Exp $
3 $Revision: 1.2 $
4 $Date: 2009/03/06 08:59:18 $
5 */
6 
7 //Created by KVClassFactory on Thu Oct 9 17:21:55 2008
8 //Author: franklan
9 
10 #include "KVDP2toIDGridConvertor.h"
11 #include "TList.h"
12 #include "KVIDGrid.h"
13 #include "KVError.h"
14 #include "KVIDGridManager.h"
15 
16 using namespace std;
17 
19 
20 
21 
25 {
26  // Default constructor
27  fGridClass = 0;
28  fGrids = 0;
29 }
30 
31 
33 
34 
37 
39 {
40  // Destructor
41  if (fGrids) {
42  fGrids->Clear();
43  delete fGrids;
44  }
45 }
46 
47 
49 
50 
52 
54 {
55  fGridClass = TClass::GetClass(cl);
56  if (!fGridClass) Error(KV__ERROR(SetGridClass), "Unknown grid class %s", cl);
57 }
58 
59 
61 
62 
64 
66 {
67  if (fGrids) fGrids->Clear();
68  else fGrids = new TList;
69  ReadFile(filename);
71  else Error(KV__ERROR(Convert), "gIDGridManager=0x0: create an ID grid manager first!");
72 }
73 
74 
76 
77 
80 
82 {
83  // Read grids in file and add to fGrids list
84 
85  if (!fGridClass) {
86  Error(KV__ERROR(ReadFile),
87  "Set class of ID grids to generate first!");
88  return;
89  }
90 
91  ifstream datfile;
92  datfile.open(filename);
93 
94  if (!datfile.good()) {
95  Error(KV__ERROR(ReadFile),
96  "Problem reading file %s", filename);
97  return;
98  }
99  KVString s;
100 
101  s.ReadLine(datfile);
102 
103  while (datfile.good()) {
104 
105  if (s == "") {
106  s.ReadLine(datfile);
107  continue;
108  }
109 
110  if (!s.BeginsWith('#')) { //'#' sign signals comments
111  int ring, modu, frun, lrun, totpoints;
112  if (sscanf(s.Data(), "%d %d %d %d", &ring, &modu, &frun, &lrun) !=
113  4) {
114  Error(KV__ERROR(ReadFile), "Problem reading file %s\nLast line read: %s",
115  filename, s.Data());
116  return;
117  };
118  KVIDGrid* grid = (KVIDGrid*) fGridClass->New(); //create new grid
119 
120  //add to list of grids
121  fGrids->Add(grid);
122 
123  grid->GetParameters()->SetValue("First run", frun);
124  grid->GetParameters()->SetValue("Last run", lrun);
125  grid->GetParameters()->SetValue("Ring min", ring);
126  grid->GetParameters()->SetValue("Ring max", ring);
127  grid->GetParameters()->SetValue("Mod min", modu);
128  grid->GetParameters()->SetValue("Mod max", modu);
129  int nlines;
130  datfile >> nlines;
131  totpoints = 0;
132  //read Z,A and number of points in each line
133  for (int i = 0; i < nlines; i++) {
134  int z, a, npoints;
135  datfile >> z >> a >> npoints;
136  totpoints += 2 * npoints;
137  if (z > 0) {
138  //identification line
139  KVIDLine* line = (KVIDLine*)grid->NewLine("id");
140  line->SetZ(z);
141  line->SetA(a);
142  line->Set(npoints);
143  grid->Add("id", line);
144  }
145  else {
146  //"ok" line
147  KVIDLine* line = (KVIDLine*)grid->NewLine("ok");
148  line->Set(npoints);
149  grid->Add("ok", line);
150  }
151  }
152  ReadLineCoords(grid, datfile);
153  //calculate line widths in grid
154  grid->CalculateLineWidths();
155  }
156  s.ReadLine(datfile);
157  }
158  datfile.close();
159 }
160 
161 
162 
166 
167 void KVDP2toIDGridConvertor::ReadLineCoords(KVIDGrid* grid, ifstream& datfile)
168 {
169  // Read coordinates of lines in the order they were created.
170  // We assume that the 'ID' lines are first, then the 'OK' lines
171 
172  TIter nextID(grid->GetIdentifiers());
174  while ((line = (KVIDentifier*) nextID())) {
175  //read in points
176  for (int i = 0; i < line->GetN(); i++) {
177  Double_t x, y;
178  datfile >> x >> y;
179  line->SetPoint(i, x, y);
180  }
181  }
182  TIter nextOK(grid->GetCuts());
183  while ((line = (KVIDentifier*) nextOK())) {
184  //read in points
185  for (int i = 0; i < line->GetN(); i++) {
186  Double_t x, y;
187  datfile >> x >> y;
188  line->SetPoint(i, x, y);
189  }
190  }
191 }
192 
193 
Defines macros for standard error messages.
#define KV__ERROR(method)
Definition: KVError.h:30
KVIDGridManager * gIDGridManager
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
char Char_t
double Double_t
Converts dp2-format grids to KVIDGrids.
virtual void SetGridClass(const Char_t *cl)
virtual ~KVDP2toIDGridConvertor()
Destructor.
virtual void ReadFile(const Char_t *filename)
Read grids in file and add to fGrids list.
void Convert(const Char_t *filename)
virtual void ReadLineCoords(KVIDGrid *, std::ifstream &)
void Add(TString, KVIDentifier *)
Definition: KVIDGraph.cpp:838
const KVList * GetCuts() const
Definition: KVIDGraph.h:307
const KVNameValueList * GetParameters() const
Definition: KVIDGraph.h:287
virtual KVIDentifier * New(const Char_t *)
Create new object of class "id_class" which derives from KVIDentifier.
Definition: KVIDGraph.cpp:807
const KVList * GetIdentifiers() const
Definition: KVIDGraph.h:297
KVList * GetGrids()
Abstract base class for 2D identification grids in e.g. (dE,E) maps.
Definition: KVIDGrid.h:73
virtual void CalculateLineWidths()
Definition: KVIDGrid.h:263
KVIDLine * NewLine(const Char_t *idline_class="")
Definition: KVIDGrid.cpp:90
Base class for lines/cuts used for particle identification in 2D data maps.
Definition: KVIDLine.h:142
Base class for graphical cuts used in particle identification.
Definition: KVIDentifier.h:27
void SetValue(const Char_t *name, value_type value)
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:72
static TClass * GetClass(Bool_t load=kTRUE, Bool_t silent=kFALSE)
virtual void AddAll(const TCollection *col)
TLine * line
Double_t y[n]
Double_t x[n]
const long double s
Definition: KVUnits.h:94
const long double cl
Definition: KVUnits.h:85
void Error(const char *location, const char *va_(fmt),...)
auto * a