GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WatchersTools.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <fstream>
4 #include <sstream>
5 #include <vector>
6 #include <string>
7 #include <map>
8 
9 #include "TString.h"
10 #include "TObjArray.h"
11 #include "BashColor.h"
12 #include "TROOT.h"
13 #include "TPaveStats.h"
14 #include "TTimer.h"
15 #include "TSystem.h"
16 #include "TRootBrowser.h"
17 #include "TGTab.h"
18 #include "TBrowser.h"
19 
20 #include "PadManager.h"
21 
22 #include "WatchersTools.h"
23 
24 using namespace std;
25 
29 
30 WatchersTools::WatchersTools(const char* name, const char *title) :
31  TTask(name,title),
32  CanvasVisu(name,title),
33  fBashColor(new BashColor())
34 {
35 
36 }
37 
39 
41 {
42 
43 }
44 
45 
49 
50 Collector::Collector(const char* name, const char *title) :
51  WatchersTools(name,title),
52  fNpadX(5),
53  fNpadY(5)
54 {
55 
56 }
57 
59 
61 {
62 
63 }
64 
65 
67 
68 void Collector::CloseTab(const char *TabName)
69 {
70  if(gROOT->GetListOfCanvases()->FindObject(TabName))
71  {
72  TBrowser *Browser = (TBrowser*)((TList*)gROOT->GetListOfBrowsers())->At(0);
73 
74  TRootBrowser *RootBrowser = (TRootBrowser *) Browser->GetBrowserImp();
75  if(((TGTab*)RootBrowser->GetTabRight())->SetTab(TabName))
76  {
77  RootBrowser->GetTabRight()->CloseTab(RootBrowser->GetTabRight()->GetCurrent());
78  }
79  }
80 }
81 
83 
84 bool Collector::Collectistos(const char* Folder, const char *inc, const char *exc, const char *class_inc, const char* class_exc, const char *CanvasName)
85 {
86  TFolder *top_folder = (TFolder *)gROOT->GetRootFolder()->FindObject(Folder);
87  if(top_folder == 0x0)
88  {
90  cout<<Folder<<" not found"<<endl;
92  return false;
93  }
94 
95  if(((TString)CanvasName) == "Canvas")
96  {
97  CanvasName = ((TString)(TString)inc + "_" + (TString)class_inc).Data();
98  }
99 
100  TList collected;
101 
102  Gw::PadManager::Collect<TObject>(&collected,top_folder,inc,exc,class_inc,class_exc);
103 
104  int PadNbr = 0;
105 
106  TString Name;
107  TCanvas *c = 0x0;
108 
109  double topmarg = 0.0679612;
110  double rightmarg = 0.0121951;
111  double leftmarg = 0.0983588;
112  double bottommarg = 0.11165;
113 
114  gPad->SetRightMargin(rightmarg);
115  gPad->SetTopMargin(topmarg);
116  gPad->SetLeftMargin(leftmarg);
117  gPad->SetBottomMargin(bottommarg);
118 
119  TPaveStats *st;
120 
121  if(collected.GetSize()>100)
122  {
124  cout<<"The number of histos to plot is "<<collected.GetSize()<<" ! Plot it anyway ? (y,n)"<<endl;
126  TString test;
127  cin>>test;
128  if(!test.EqualTo("y",TString::kIgnoreCase)) return false;
129  }
130 
131  Int_t NpadPerCanvas = fNpadX*fNpadY;
132 
133  for(int i=0 ; i<collected.GetSize() ; i++)
134  {
135  if(PadNbr%NpadPerCanvas==0)
136  {
137  if(collected.GetSize()>NpadPerCanvas) Name = Form("%s_%d_%d",CanvasName,PadNbr+1,PadNbr+NpadPerCanvas);
138  else Name = CanvasName;
139  c = CanvasVisu::NewCanvas(Name,Name);
140 
141  new LoupeOnPad(c);
142  SetLoupe(false);
143  c->Divide(fNpadX,fNpadY,0.001,0.001);
144  }
145 
146  c->cd(PadNbr%NpadPerCanvas+1);
147 
148  TH1 *h = (TH1*)collected.At(i);
149 
150  if(h)
151  {
152  gPad->SetRightMargin(rightmarg);
153  gPad->SetTopMargin(topmarg);
154  gPad->SetLeftMargin(leftmarg);
155  gPad->SetBottomMargin(bottommarg);
156 
157  h->SetBit(TH1::kNoTitle);
158 
159  h->GetXaxis()->SetLabelSize(0.05);
160  h->GetXaxis()->SetTitleSize(0.06);
161  h->GetXaxis()->SetTitleOffset(0.85);
162 
163  h->GetYaxis()->SetLabelSize(0.05);
164  h->GetYaxis()->SetTitleSize(0.06);
165  h->GetYaxis()->SetTitleOffset(0.90);
166 
167  h->SetLineColor(GetColor(0));
168 
169  if(h->InheritsFrom("TH2"))
170  {
171  h->Draw("col");
172  gPad->SetLogz();
173  if( strncmp(h->GetName(),"ADC",3) == 0 ) h->GetYaxis()->SetRangeUser(0,2000);
174  }
175  else
176  {
177  h->Draw();
178  }
179 
180  gPad->Modified();
181  gPad->Update();
182 
183  st = (TPaveStats*)h->FindObject("stats");
184  if(st)
185  {
186  st->SetX2NDC(1-rightmarg);
187  st->SetY2NDC(1-topmarg);
188  st->SetX1NDC(0.681013);
189  st->SetY1NDC(0.663962);
190  }
191 
192  }
193  PadNbr++;
194  }
195  return true;
196 }
197 
201 
202 WatchersRefresh::WatchersRefresh(const char* name, const char *title) :
203  WatchersTools(name,title),
204  fTimer(new TTimer())
205 {
206 
207 }
208 
210 
212 {
213 
214 }
215 
217 
218 void WatchersRefresh::PadRefresh(bool IsOn, Long_t RefreshTimeIn_ms)
219 {
220  if(IsOn)
221  {
222  fTimer->Connect("Timeout()","WatchersRefresh",this,"DoPadRefresh()");
223  fTimer->Start(RefreshTimeIn_ms);
224  }
225  else
226  {
227  fTimer->Stop();
228  }
229 }
230 
232 
233 void WatchersRefresh::CanvasRefresh(bool IsOn, Long_t RefreshTimeIn_ms)
234 {
235  if(IsOn)
236  {
237  fTimer->Connect("Timeout()","WatchersRefresh",this,"DoCanvasRefresh()");
238  fTimer->Start(RefreshTimeIn_ms);
239  }
240  else
241  {
242  fTimer->Stop();
243  }
244 }
245 
247 
249 {
250  TVirtualPad *Pad = gROOT->GetSelectedPad();
251 
252  if(Pad && Pad->GetListOfPrimitives())
253  {
254  Pad->Modified();
255  Pad->Update();
256  }
257 }
258 
260 
262 {
263  if(gROOT->GetSelectedPad())
264  {
265  TCanvas *c = gROOT->GetSelectedPad()->GetCanvas();
266 
267  if(c)
268  {
269  c->Paint();
270  c->Update();
271  }
272  }
273 }
274 
278 
279 ManipConfig::ManipConfig(const char* name, const char *title) :
280  WatchersTools(name,title),
281  fNpadX(5),
282  fNpadY(5)
283 {
284 
285 }
286 
288 
290 {
291 
292 }
293 
295 
297 {
298  Collector *TheCollector = (Collector*)gROOT->FindObjectAny("SpectraCollector");
299  if(TheCollector == 0x0)
300  {
302  cout<<"No SpectraCollector found !"<<endl;
304  return;
305  }
306 
307  TheCollector->SetNPads(fNpadX,fNpadY);
308  TString CanvasName;
309 
310  CanvasName = "TimeStamp_1h";
311  if(!gROOT->GetListOfCanvases()->FindObject(CanvasName))TheCollector->Collectistos("//root/GwWatchers","CCrystal*_1hour","","TH1","",CanvasName.Data());
312 
313  CanvasName = "CoreEnergy";
314  if(!gROOT->GetListOfCanvases()->FindObject(CanvasName))TheCollector->Collectistos("//root/GwWatchers","*HG*CalSpectra","","TH1","",CanvasName.Data());
315 
316  CanvasName = "EvsSegID";
317  if(!gROOT->GetListOfCanvases()->FindObject(CanvasName))TheCollector->Collectistos("//root/GwWatchers","*EvsSegID","","TH2","",CanvasName.Data());
318 }
319 
321 
322 
void SetNPads(int nx=5, int ny=5)
Definition: WatchersTools.h:97
void CloseTab(const char *TabName)
******************************************************************************************/// ...
void CanvasRefresh(bool IsOn=false, Long_t RefreshTimeIn_ms=500)
******************************************************************************************/// ...
void StartManipViewLLP()
******************************************************************************************/// ...
ManipConfig(const char *name, const char *title)
*/
header file for PadManager.cpp
virtual ~Collector()
******************************************************************************************/// ...
void PadRefresh(bool IsOn=false, Long_t RefreshTimeIn_ms=500)
******************************************************************************************/// ...
virtual ~WatchersTools()
******************************************************************************************/// ...
void DoPadRefresh()
******************************************************************************************/// ...
TCanvas * NewCanvas(TString cname, TString ctitle)
Definition: CanvasVisu.C:102
void DoCanvasRefresh()
******************************************************************************************/// ...
WatchersTools(const char *name, const char *title)
*/
virtual void SetLoupe(bool loupeon=true)
Definition: WatchersTools.h:38
LoupOnPad, a class to Loupe on a Pad in a Canvas with many pads in it.
Definition: LoupeOnPad.h:76
WatchersRefresh(const char *name, const char *title)
*/
virtual ~WatchersRefresh()
******************************************************************************************/// ...
virtual ~ManipConfig()
******************************************************************************************/// ...
Color_t GetColor(int i)
Definition: CanvasVisu.h:49
ClassImp(BaseNucleus)
ADF::LogMessage & endl(ADF::LogMessage &log)
bool Collectistos(const char *Folder="//root/GwWatchers", const char *inc="", const char *exc="", const char *class_inc="TH1", const char *class_exc="", const char *CanvasName="Canvas")
******************************************************************************************/// ...
BashColor * fBashColor
Definition: WatchersTools.h:14
Collector(const char *name, const char *title)
*/