KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
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 "Riostream.h"
22#include "KVString.h"
23#include "TClass.h"
24#include "TROOT.h"
25
26using namespace std;
27
29KVIDGridManager* gIDGridManager = nullptr;
30
31
36
38{
39 //Default constructor
40 //Initialise global pointer gIDGridManager
41 //Create list for ID grids
42 gIDGridManager = this;
44 fGrids.Connect("Modified()", "KVIDGridManager", this, "Modified()");
46}
47
48
49
53
55{
56 //Destructor
57 //Reset global pointer gIDGridManager
58
59 if (gIDGridManager == this)
60 gIDGridManager = 0;
61 fGrids.Disconnect("Modified()", this, "Modified()");
63}
64
65
66
69
71{
72 // Add a grid to the collection. It will be deleted by the manager.
73
74 fGrids.Add(grid);
75}
76
77
78
83
85{
86 //Remove grid from manager's list and delete it
87 //update flag allows to disable the emission of the 'Modified' signal in case the GUI
88 //is deleting a list of grids - in this case we don't want to update until the end
89
90 if (!update) fGrids.Disconnect("Modified()", this, "Modified()");
91 fGrids.Remove(grid);
92 delete grid;
93 if (!update) fGrids.Connect("Modified()", "KVIDGridManager", this, "Modified()");
94}
95
96
97
100
102{
103 //Delete all grids and empty list, ready to start anew
104
105 fGrids.Disconnect("Modified()", this, "Modified()");
107 fGrids.Clear();
108 Modified(); // emit signal to say something changed
109 fGrids.Connect("Modified()", "KVIDGridManager", this, "Modified()");
110}
111
112
113
125
127{
128 //read file, create grids corresponding to information in file.
129 //note: any existing grids are not destroyed, use Clear() beforehand if you want to
130 //start afresh and anew (ais athat aOK?)
131 //
132 // N.B. the links between each grid and the IDtelescope(s) for which it is to be used
133 // are not set up by this method.
134 //
135 //the list of grids created by reading the file can be accessed with method
136 //GetLastReadGrids() after calling this method
137
138 // clear list of read grids
140
141 Bool_t is_it_ok = kFALSE;
142 ifstream gridfile(filename);
143 if (!gridfile.good()) {
144 Error("ReadAsciiFile", "File %s cannot be opened", filename);
145 return is_it_ok;
146 }
147
148 KVString s;
149
150 fGrids.Disconnect("Modified()", this, "Modified()");
151 while (gridfile.good()) {
152 //read a line
153 s.ReadLine(gridfile);
154 if (s.BeginsWith("++")) {
155 //New grid
156 //Get name of class by stripping off the '+' at the start of the line
157 s.Remove(0, 2);
158 /************ BACKWARDS COMPATIBILITY FIX *************
159 Old grid files may contain obsolete KVIDZGrid class
160 We replace by KVIDZAGrid with SetOnlyZId(kTRUE)
161 */
162 //Make new grid using this class
163 KVIDGraph* grid = 0;
164 Bool_t onlyz = kFALSE;
165 if (s == "KVIDZGrid") {
166 s = "KVIDZAGrid";
167 onlyz = kTRUE;
168 }
169 TClass* clas = TClass::GetClass(s.Data());
170 if (!clas) {
171 Fatal("ReadAsciiFile",
172 "Cannot load TClass information for %s", s.Data());
173 }
174 grid = (KVIDGraph*) clas->New();
175 fLastReadGrids.Add(grid);
176 //read grid
177 grid->ReadFromAsciiFile(gridfile);
178 if (onlyz) grid->SetOnlyZId(kTRUE);
179 }
180 }
181
182 gridfile.close();
183 is_it_ok = kTRUE;
184 Modified(); // emit signal to say something changed
185 fGrids.Connect("Modified()", "KVIDGridManager", this, "Modified()");
186 return is_it_ok;
187}
188
189
190
196
197Int_t KVIDGridManager::WriteAsciiFile(const Char_t* filename, const TCollection* selection)
198{
199 // Write grids in file 'filename'.
200 // If selection=0 (default), write all grids.
201 // If selection!=0, write only grids in list.
202 // Returns number of grids written in file.
203
204 ofstream gridfile(filename);
205
206 const TCollection* list_of_grids = (selection ? selection : &fGrids);
207 TIter next(list_of_grids);
208 KVIDGraph* grid = 0;
209 Int_t n_saved = 0;
210 while ((grid = (KVIDGraph*) next())) {
211
212 grid->WriteToAsciiFile(gridfile);
213 Info("WriteAsciiFile", "%s saved", grid->GetName());
214 n_saved++;
215
216 }
217
218 gridfile.close();
219 return n_saved;
220}
221
222
223
226
228{
229 //Return pointer to grid with name "name"
231}
232
233
234
237
239{
240 //Opens GUI for managing grids
241 if (gROOT->IsBatch()) {
242 Warning("StartViewer", "To launch graphical interface, you should not use ROOT in batch mode");
243 return;
244 }
245 TClass* cl = TClass::GetClass("KVIDGridManagerGUI");
246 cl->New();
247}
248
249
250
254
256{
257 // Replace contents of KVString with a comma-separated list of all
258 // different labels of ID telescopes associated with current list of ID grids.
259
260 list = "";
261 TIter next(&fGrids);
262 KVIDGraph* grid = 0;
263 KVString lab;
264 while ((grid = (KVIDGraph*) next())) {
265 //cout << "grid=" << grid->GetName() << " label=" << grid->GetIDTelescopeLabel() << endl;
266 lab.Form("/%s/", grid->GetIDTelescopeLabel());
267 if (!list.Contains(lab)) list.Append(lab);
268 }
269 //cout << "list=" << list << endl;
270 list.ReplaceAll("//", ",");
271 list.ReplaceAll("/", "");
272 if (list.EqualTo(",")) list = "";
273}
274
275
276
280
282{
283 // Initialize all grids in ID grid manager's list, i.e. we call the Initialize() method
284 // of every grid/graph.
285 TIter next(&fGrids);
286 KVIDGraph* gr = 0;
287 while ((gr = (KVIDGraph*) next())) gr->Initialize();
288}
289
290
291
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
virtual void WriteToAsciiFile(std::ofstream &gridfile)
virtual void ReadFromAsciiFile(std::ifstream &gridfile)
const Char_t * GetName() const
const Char_t * GetIDTelescopeLabel() const
Definition KVIDGraph.h:430
virtual void SetOnlyZId(Bool_t yes=kTRUE)
Handles a stock of identification grids to be used by one or more identification telescopes.
void GetListOfIDTelescopeLabels(KVString &)
KVList * GetGrids()
void DeleteGrid(KVIDGraph *, Bool_t update=kTRUE)
void Clear(Option_t *opt="")
Delete all grids and empty list, ready to start anew.
Int_t WriteAsciiFile(const Char_t *filename, const TCollection *selection=0)
virtual ~KVIDGridManager()
Bool_t ReadAsciiFile(const Char_t *filename)
void StartViewer() const
Opens GUI for managing grids.
TList fLastReadGrids
list of grids created by last call to ReadAsciiFile
KVList fGrids
collection of all ID graphs handled by manager
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. It will be deleted by the manager.
virtual void SendModifiedSignals(Bool_t yes=kTRUE)
virtual void SetOwner(Bool_t enable=kTRUE)
virtual void Clear(Option_t *option="")
virtual TObject * FindObjectByName(const Char_t *name) const
virtual void Add(TObject *obj)
virtual TObject * Remove(TObject *obj)
Remove object from list.
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
void Clear(Option_t *option="") override
void Add(TObject *obj) override
virtual void Warning(const char *method, const char *msgfmt,...) const
virtual void Error(const char *method, const char *msgfmt,...) const
virtual void Fatal(const char *method, const char *msgfmt,...) const
virtual void Info(const char *method, const char *msgfmt,...) const
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 update(const LAYERDATA &prevLayerData, LAYERDATA &currLayerData, double factorWeightDecay, EnumRegularization regularization)
ClassImp(TPyArg)