KaliVeda
Toolkit for HIC analysis
KVIDGridManager.cpp
1 /***************************************************************************
2  KVIDGridManager.cpp - description
3  -------------------
4  begin : Jan 27 2005
5  copyright : (C) 2005 by J.D. Frankland
6  email : frankland@ganil.fr
7 
8 $Id: KVIDGridManager.cpp,v 1.13 2009/03/03 14:27:15 franklan Exp $
9 ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  ***************************************************************************/
19 
20 #include "KVIDGridManager.h"
21 #include "KVString.h"
22 #include "TClass.h"
23 #include "TROOT.h"
24 
25 using namespace std;
26 
28 KVIDGridManager* gIDGridManager = nullptr;
29 
30 
38 
40 {
41  //Default constructor
42  //Initialise global pointer gIDGridManager
43  //
44  //Create list for ID grids
45  //
46  //Will delete grids if owns_grids=true
47  gIDGridManager = this;
48  fGrids.SendModifiedSignals(kTRUE);
49  fGrids.Connect("Modified()", "KVIDGridManager", this, "Modified()");
50  fGrids.SetOwner(owns_grids);
51 }
52 
53 
54 
58 
59 KVIDGridManager::~KVIDGridManager()
60 {
61  //Destructor
62  //Reset global pointer gIDGridManager
63 
64  if (gIDGridManager == this)
65  gIDGridManager = 0;
66  fGrids.Disconnect("Modified()", this, "Modified()");
67  fLastReadGrids.Clear();
68 }
69 
70 
71 
74 
76 {
77  // Add a grid to the collection
78 
79  fGrids.Add(grid);
80 }
81 
82 
83 
88 
90 {
91  //Remove grid from manager's list and delete it
92  //update flag allows to disable the emission of the 'Modified' signal in case the GUI
93  //is deleting a list of grids - in this case we don't want to update until the end
94 
95  if (!update) fGrids.Disconnect("Modified()", this, "Modified()");
96  fGrids.Remove(grid);
97  delete grid;
98  if (!update) fGrids.Connect("Modified()", "KVIDGridManager", this, "Modified()");
99 }
100 
101 
102 
105 
107 {
108  //Delete all grids and empty list, ready to start anew
109 
110  fGrids.Disconnect("Modified()", this, "Modified()");
111  fLastReadGrids.Clear();
112  fGrids.Clear();
113  Modified(); // emit signal to say something changed
114  fGrids.Connect("Modified()", "KVIDGridManager", this, "Modified()");
115 }
116 
117 
118 
130 
132 {
133  //read file, create grids corresponding to information in file.
134  //note: any existing grids are not destroyed, use Clear() beforehand if you want to
135  //start afresh and anew (ais athat aOK?)
136  //
137  // N.B. the links between each grid and the IDtelescope(s) for which it is to be used
138  // are not set up by this method.
139  //
140  //the list of grids created by reading the file can be accessed with method
141  //GetLastReadGrids() after calling this method
142 
143  // clear list of read grids
144  fLastReadGrids.Clear();
145 
146  Bool_t is_it_ok = kFALSE;
147  ifstream gridfile(filename);
148  if (!gridfile.good()) {
149  Error("ReadAsciiFile", "File %s cannot be opened", filename);
150  return is_it_ok;
151  }
152 
153  KVString s;
154 
155  fGrids.Disconnect("Modified()", this, "Modified()");
156  while (gridfile.good()) {
157  //read a line
158  s.ReadLine(gridfile);
159  if (s.BeginsWith("++")) {
160  //New grid
161  //Get name of class by stripping off the '+' at the start of the line
162  s.Remove(0, 2);
163  /************ BACKWARDS COMPATIBILITY FIX *************
164  Old grid files may contain obsolete KVIDZGrid class
165  We replace by KVIDZAGrid with SetOnlyZId(kTRUE)
166  */
167  //Make new grid using this class
168  KVIDGraph* grid = 0;
169  Bool_t onlyz = kFALSE;
170  if (s == "KVIDZGrid") {
171  s = "KVIDZAGrid";
172  onlyz = kTRUE;
173  }
174  TClass* clas = TClass::GetClass(s.Data());
175  if (!clas) {
176  Fatal("ReadAsciiFile",
177  "Cannot load TClass information for %s", s.Data());
178  }
179  grid = (KVIDGraph*) clas->New();
180  fLastReadGrids.Add(grid);
181  //read grid
182  grid->ReadFromAsciiFile(gridfile);
183  if (onlyz) grid->SetOnlyZId(kTRUE);
184  }
185  }
186 
187  gridfile.close();
188  is_it_ok = kTRUE;
189  Modified(); // emit signal to say something changed
190  fGrids.Connect("Modified()", "KVIDGridManager", this, "Modified()");
191  return is_it_ok;
192 }
193 
194 
195 
198 
200 {
201  // Add all grids read the last time ReadAsciiFile() was called to the grid manager
202 
203  TIter it(&fLastReadGrids);KVIDGraph* igr;
204  while( (igr = (KVIDGraph*)it()) )
205  fGrids.Add(igr);
206 }
207 
208 
209 
215 
216 Int_t KVIDGridManager::WriteAsciiFile(const Char_t* filename, const TCollection* selection)
217 {
218  // Write grids in file 'filename'.
219  // If selection=0 (default), write all grids.
220  // If selection!=0, write only grids in list.
221  // Returns number of grids written in file.
222 
223  ofstream gridfile(filename);
224 
225  const TCollection* list_of_grids = (selection ? selection : &fGrids);
226  TIter next(list_of_grids);
227  KVIDGraph* grid = 0;
228  Int_t n_saved = 0;
229  while ((grid = (KVIDGraph*) next())) {
230 
231  grid->WriteToAsciiFile(gridfile);
232  Info("WriteAsciiFile", "%s saved", grid->GetName());
233  n_saved++;
234 
235  }
236 
237  gridfile.close();
238  return n_saved;
239 }
240 
241 
242 
245 
247 {
248  //Return pointer to grid with name "name"
249  return (KVIDGraph*) GetGrids()->FindObjectByName(name);
250 }
251 
252 
253 
256 
258 {
259  //Opens GUI for managing grids
260  if (gROOT->IsBatch()) {
261  Warning("StartViewer", "To launch graphical interface, you should not use ROOT in batch mode");
262  return;
263  }
264  TClass* cl = TClass::GetClass("KVIDGridManagerGUI");
265  cl->New();
266 }
267 
268 
269 
273 
275 {
276  // Replace contents of KVString with a comma-separated list of all
277  // different labels of ID telescopes associated with current list of ID grids.
278 
279  list = "";
280  TIter next(&fGrids);
281  KVIDGraph* grid = 0;
282  KVString lab;
283  while ((grid = (KVIDGraph*) next())) {
284  //cout << "grid=" << grid->GetName() << " label=" << grid->GetIDTelescopeLabel() << endl;
285  lab.Form("/%s/", grid->GetIDTelescopeLabel());
286  if (!list.Contains(lab)) list.Append(lab);
287  }
288  //cout << "list=" << list << endl;
289  list.ReplaceAll("//", ",");
290  list.ReplaceAll("/", "");
291  if (list.EqualTo(",")) list = "";
292 }
293 
294 
295 
299 
301 {
302  // Initialize all grids in ID grid manager's list, i.e. we call the Initialize() method
303  // of every grid/graph.
304  TIter next(&fGrids);
305  KVIDGraph* gr = 0;
306  while ((gr = (KVIDGraph*) next())) gr->Initialize();
307 }
308 
309 
310 
int Int_t
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
const char Option_t
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
char name[80]
#define gROOT
Base class for particle identification in a 2D map.
Definition: KVIDGraph.h:32
void Add(TString, KVIDentifier *)
Definition: KVIDGraph.cpp:844
virtual void WriteToAsciiFile(std::ofstream &gridfile)
Definition: KVIDGraph.cpp:442
virtual void ReadFromAsciiFile(std::ifstream &gridfile)
Definition: KVIDGraph.cpp:601
const Char_t * GetName() const override
Definition: KVIDGraph.cpp:1344
const Char_t * GetIDTelescopeLabel() const
Definition: KVIDGraph.h:458
virtual void SetOnlyZId(Bool_t yes=kTRUE)
Definition: KVIDGraph.cpp:1508
Handles a stock of identification grids to be used by one or more identification telescopes.
void Clear(Option_t *opt="") override
Delete all grids and empty list, ready to start anew.
void GetListOfIDTelescopeLabels(KVString &)
void DeleteGrid(KVIDGraph *, Bool_t update=kTRUE)
KVIDGridManager(Bool_t owns_grids=kFALSE)
Int_t WriteAsciiFile(const Char_t *filename, const TCollection *selection=0)
void AddLastReadGrids()
Add all grids read the last time ReadAsciiFile() was called to the grid manager.
Bool_t ReadAsciiFile(const Char_t *filename)
void StartViewer() const
Opens GUI for managing grids.
KVIDGraph * GetGrid(const Char_t *name)
Return pointer to grid with name "name".
void Initialize(Option_t *="")
void AddGrid(KVIDGraph *)
Add a grid to the collection.
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
static TClass * GetClass(Bool_t load=kTRUE, Bool_t silent=kFALSE)
Bool_t EqualTo(const char *cs, ECaseCompare cmp=kExact) const
TString & Append(char c, Ssiz_t rep=1)
void Form(const char *fmt,...)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TString & ReplaceAll(const char *s1, const char *s2)
TGraphErrors * gr
void Error(const char *location, const char *fmt,...)
void Info(const char *location, const char *fmt,...)
void Fatal(const char *location, const char *fmt,...)
void Warning(const char *location, const char *fmt,...)
void update(const LAYERDATA &prevLayerData, LAYERDATA &currLayerData, double factorWeightDecay, EnumRegularization regularization)
ClassImp(TPyArg)