27 #include "TClassMenuItem.h"
29 #include "TVirtualPad.h"
37 const Int_t nb_color_wheel = 20;
38 Color_t color_wheel[nb_color_wheel] = {
39 kBlue+0, kMagenta+0, kRed+0, kGreen+0, kCyan+0,
40 kBlue+1, kMagenta+1, kRed+1, kGreen+1, kCyan+1,
41 kBlue+2, kMagenta+2, kRed+2, kGreen+2, kCyan+2,
42 kBlue+3, kMagenta+3, kRed+3, kGreen+3, kCyan+3
51 void ZeroOnFolder(
const char *include=
"* {TH*}",
const char *exclude=
"- {TH2*}",
const char *drawopt=
"ICE",
int searchdepth = kMaxInt, TObject *topfolder = 0x0);
54 void DisplayFolder(
const char *include=
"* {TH*}",
const char *exclude=
"- {TH2*}",
const char *drawopt=
"clone !wheel",
int searchdepth = kMaxInt, TObject *topfolder = 0x0);
57 void DisplayFolderSUM(
const char *include=
"* {TH1*}",
const char *exclude=
"- {TH2*}",
const char *drawopt=
"",
int searchdepth = kMaxInt, TObject *topfolder = 0x0);
63 TClass *cl = TFolder::Class(); TList *l = cl->GetMenuList(); TClassMenuItem *n = 0x0;
66 n =
new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
67 "Zero",
"ZeroOnFolder",0,
"char*,char*,char *,int,int,int,TObject*",4);
69 n =
new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
70 "DisplaySUM",
"DisplayFolderSUM",0,
"char*,char*,char *,int,int,int,TObject*",4);
72 n =
new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
73 "Display",
"DisplayFolder",0,
"char*,char*,char *,int,int,int,TObject*",4);
125 void ZeroOnFolder(
const char *inc,
const char *exc,
const char *ropt,
int depth, TObject *folder)
128 TString include = inc, exclude = exc, include_name =
"*", include_class =
"*", exlude_name =
"", exclude_class =
"", tmp_obj =
"", tmp_token =
"";
130 TObject *obj = 0x0, *obj_to_draw = 0x0 ;
133 TVirtualPad *top_pad = TVirtualPad::Pad();
135 if ( ! folder->InheritsFrom(
"TFolder") || TVirtualPad::Pad() == 0x0 ) {
140 Ssiz_t begin_ = include.Index(
"{"), end_ = include.Index(
"}");
141 if ( begin_ != (
const Ssiz_t)(-1) ) {
142 if ( end_ == (
const Ssiz_t)(-1) ) {
143 end_ = include.Length();
145 if ( begin_ < end_ ) {
146 include_class = include(begin_+1,end_-begin_-1);
147 include.Remove(begin_,end_-begin_+1);
150 begin_ = exclude.Index(
"{"), end_ = exclude.Index(
"}");
151 if ( begin_ != (
const Ssiz_t)(-1) ) {
152 if ( end_ == (
const Ssiz_t)(-1) ) {
153 end_ = exclude.Length();
155 if ( begin_ < end_ ) {
156 exclude_class = exclude(begin_+1,end_-begin_-1);
157 exclude.Remove(begin_,end_-begin_+1);
162 Gw::PadManager::Collect<TObject>(&collected,topfolder,include,exclude,include_class,exclude_class,depth);
164 printf(
"From TFolder::Drawall, %d object to be drawn \n",collected.GetSize());
168 if ( collected.GetSize() ) {
170 TIter next(&collected);
171 while ( (obj = next()) ) {
173 if ( obj->InheritsFrom(
"TH1") ) {
174 ((TH1 *)obj)->Reset(ropt);
184 void DisplayFolder(
const char *inc,
const char *exc,
const char *draw,
int depth, TObject *folder)
187 TString include = inc, exclude = exc, include_name =
"*", include_class =
"*", exlude_name =
"", exclude_class =
"", tmp_obj =
"", tmp_token =
"",
188 draw_option = draw, h_draw_opt =
"";
190 TObject *obj = 0x0, *obj_to_draw = 0x0 ;
193 TVirtualPad *top_pad = TVirtualPad::Pad();
195 if ( ! folder->InheritsFrom(
"TFolder") || TVirtualPad::Pad() == 0x0 ) {
200 Ssiz_t begin_ = include.Index(
"{"), end_ = include.Index(
"}");
201 if ( begin_ != (
const Ssiz_t)(-1) ) {
202 if ( end_ == (
const Ssiz_t)(-1) ) {
203 end_ = include.Length();
205 if ( begin_ < end_ ) {
206 include_class = include(begin_+1,end_-begin_-1);
207 include.Remove(begin_,end_-begin_+1);
210 begin_ = exclude.Index(
"{"), end_ = exclude.Index(
"}");
211 if ( begin_ != (
const Ssiz_t)(-1) ) {
212 if ( end_ == (
const Ssiz_t)(-1) ) {
213 end_ = exclude.Length();
215 if ( begin_ < end_ ) {
216 exclude_class = exclude(begin_+1,end_-begin_-1);
217 exclude.Remove(begin_,end_-begin_+1);
222 Gw::PadManager::Collect<TObject>(&collected,topfolder,include,exclude,include_class,exclude_class,depth);
228 if ( collected.GetSize() ) {
231 Bool_t do_clone =
false, do_wheel =
false;
233 h_draw_opt = draw_option;
234 if ( h_draw_opt.Contains(
"clone") ) {
235 if ( h_draw_opt.Contains(
"!clone") ) {
236 h_draw_opt.ReplaceAll(
"!clone",
"");
238 else { h_draw_opt.ReplaceAll(
"clone",
""); do_clone =
true; }
240 if ( h_draw_opt.Contains(
"wheel") ) {
241 if ( h_draw_opt.Contains(
"!wheel") ) {
242 h_draw_opt.ReplaceAll(
"!wheel",
"");
245 h_draw_opt.ReplaceAll(
"!wheel",
"");
251 TIter next(&collected); Int_t pad_number = top_pad->GetPad(1) ? 1 : 0; Int_t color = 0;
252 while ( (obj = next()) ) {
254 if ( top_pad->GetPad(pad_number) ) {
255 top_pad->cd(pad_number++);
258 if ( !h_draw_opt.Contains(
"same") ) {
259 h_draw_opt +=
" same ";
264 if ( draw_option.Contains(
"clone") && !draw_option.Contains(
"!clone") ) {
269 if ( h_draw_opt.IsWhitespace() ) {
272 else obj_to_draw->Draw(h_draw_opt);
275 if ( obj_to_draw->InheritsFrom(
"TAttLine") && do_wheel ) {
276 TAttLine *line = dynamic_cast <TAttLine*> (obj_to_draw);
277 line->SetLineColor( color_wheel[color % nb_color_wheel] ); color++;
282 top_pad->Update(); top_pad->cd();
286 void DisplayFolderSUM(
const char *inc,
const char *exc,
const char *draw,
int depth, TObject *folder)
289 TString include = inc, exclude = exc, include_name =
"*", include_class =
"*", exlude_name =
"", exclude_class =
"", tmp_obj =
"", tmp_token =
"",
290 draw_option = draw, h_draw_opt =
"";
294 TVirtualPad *top_pad = TVirtualPad::Pad();
296 if ( ! folder->InheritsFrom(
"TFolder") || TVirtualPad::Pad() == 0x0 ) {
301 Ssiz_t begin_ = include.Index(
"{"), end_ = include.Index(
"}");
302 if ( begin_ != (
const Ssiz_t)(-1) ) {
303 if ( end_ == (
const Ssiz_t)(-1) ) {
304 end_ = include.Length();
306 if ( begin_ < end_ ) {
307 include_class = include(begin_+1,end_-begin_-1);
308 include.Remove(begin_,end_-begin_+1);
311 begin_ = exclude.Index(
"{"), end_ = exclude.Index(
"}");
312 if ( begin_ != (
const Ssiz_t)(-1) ) {
313 if ( end_ == (
const Ssiz_t)(-1) ) {
314 end_ = exclude.Length();
316 if ( begin_ < end_ ) {
317 exclude_class = exclude(begin_+1,end_-begin_-1);
318 exclude.Remove(begin_,end_-begin_+1);
323 Gw::PadManager::Collect<TH1>(&collected,topfolder,include,exclude,include_class,exclude_class,depth);
329 if ( collected.GetSize() ) {
333 hsum = (TH1 *)collected.First()->Clone(Form(
"SUM_OF_%s",topfolder->GetName()));
334 hsum->SetTitle( Form(
"SUM of histograms from %s with pattern: %s and %s",topfolder->GetName(),inc,exc) );
337 TIter next(&collected);
338 while ( (h = (TH1 *)next()) ) {
342 top_pad->Update(); top_pad->cd();
348 namespace { TList PingNames;
char buffer[4*1024*1024]; }
353 void LoadPing(
const char * filename, Option_t * opt =
"+" )
355 TString option = opt;
356 std::ifstream inputfile(filename);
358 std::string machineName;
359 std::string portName;
361 TNamed * tmp_name = NULL;
365 inputfile >> machineName >> portName;
366 if( inputfile.eof() )
break;
367 std::cerr << machineName <<
" " << portName <<
std::endl;
368 listName_tmp.Add(
new TNamed( machineName.c_str(),
369 portName.c_str() ) );
372 std::cerr << listName_tmp.GetSize() <<
std::endl;
373 if( PingNames.GetSize() == 0 && option.Contains(
"+") ){
374 for( Int_t i = 0; i < listName_tmp.GetSize(); i++)
375 PingNames.Add( listName_tmp.At(i) );
376 listName_tmp.Clear(
"nodelete");
378 else if( option.Contains(
"+") ){
379 for( Int_t i = 0; i<listName_tmp.GetSize(); i++){
381 for( Int_t j = 0; j<PingNames.GetSize(); j++){
382 if(std::string(PingNames.At(j)->GetName()) ==
383 std::string(listName_tmp.At(i)->GetName()) &&
384 std::string(PingNames.At(j)->GetTitle()) ==
385 std::string(listName_tmp.At(i)->GetTitle()) ) test_is =
true;
387 if( test_is ==
false ) PingNames.Add(listName_tmp.At(i));
389 listName_tmp.Clear(
"nodelete");
392 if( option.Contains(
"-") ){
393 for( Int_t i = 0; i<listName_tmp.GetSize(); i++ ){
395 for( Int_t j = 0; j<PingNames.GetSize(); j++){
396 if(std::string(PingNames.At(j)->GetName()) ==
397 std::string(listName_tmp.At(i)->GetName()) &&
398 std::string(PingNames.At(j)->GetTitle()) ==
399 std::string(listName_tmp.At(i)->GetTitle()) ){
401 tmp_name = (TNamed*)PingNames.At(j);
404 if( test_is ==
true ){
405 PingNames.Remove(tmp_name);
409 listName_tmp.Clear(
"delete");
413 for( Int_t ii = 0; ii < PingNames.GetSize(); ii++ ){
414 std::cerr << PingNames.At(ii)->GetName() <<
" " << PingNames.At(ii)->GetTitle() <<
std::endl;}
420 void Ping( UInt_t nbtimes = 5,
bool dodump =
false)
422 TIter next(&PingNames);
424 while ( (obj = next()) ) {
426 TString option = obj->GetTitle(), ifdump;
427 cout <<
"Ping on : " << obj->GetName() <<
" with Port # " << obj->GetTitle() <<
endl;
429 TSocket *fSocket =
new TSocket(obj->GetName(),option.Atoi());
431 if ( fSocket->IsValid() ) {
433 cout <<
"Select with 1 millisecond " <<
endl;
434 for (UInt_t i = 0u; i < nbtimes; i++) {
435 cout <<
" - try # " << i <<
endl;
436 ifdump = Form(
"%s_%s_%d",obj->GetName(),obj->GetTitle(),i);
438 switch ( fSocket->Select(TSocket::kRead,1000) )
441 cout <<
"--> timeout " <<
endl;
444 cout <<
"--> Error " <<
endl;
447 fSocket->RecvRaw(&bsize,
sizeof(Int_t));
448 cout <<
" Size expected " << bsize <<
endl;
449 ret = fSocket->RecvRaw(buffer, bsize);
450 cout <<
" Size received " << ret <<
endl;
452 ofstream file(ifdump.Data(),ios_base::app);
454 file.write(buffer,bsize);
460 else cout <<
" *** Invalid connection *** " <<
endl;
462 else cout <<
" *** Invalid connection *** " <<
endl;
467 void Ping(
const char *machine, UInt_t port, UInt_t nbtimes = 5, Option_t *opt =
"")
469 TString option = opt, sport = Form(
"%d",port);
471 TNamed * tmp_name = NULL;
473 if ( option.Contains(
"+") ) {
475 for( Int_t i = 0; i < PingNames.GetSize(); i++ )
476 if( std::string(PingNames.At(i)->GetName()) == std::string(machine) &&
477 std::string(PingNames.At(i)->GetTitle()) == std::string(sport) ) test_is =
true;
478 if( test_is ==
false )
479 PingNames.Add (
new TNamed(machine,sport.Data()) );
481 if ( option.Contains(
"-") ){
483 for( Int_t i = 0; i < PingNames.GetSize(); i++ )
484 if( std::string(PingNames.At(i)->GetName()) == std::string(machine) &&
485 std::string(PingNames.At(i)->GetTitle()) == std::string(sport) ) {
487 tmp_name = (TNamed*)PingNames.At(i);
489 if ( test_is ==
true ) {
490 PingNames.Remove(tmp_name);
501 void SSHPing( UInt_t nbtimes = 1,
bool dodump =
false)
507 TNamed *obj =
new TNamed(
"localhost",
"10001");
509 TString option = obj->GetTitle(), ifdump;
510 cout <<
"Ping on : " << obj->GetName() <<
" with Port # " << obj->GetTitle() <<
endl;
513 TSocket *fSocket =
new TSocket(obj->GetName(),option.Atoi());
515 if ( fSocket->IsValid() ) {
517 cout <<
"Select with 1 millisecond " <<
endl;
518 for (UInt_t i = 0u; i < nbtimes; i++) {
519 cout <<
" - try # " << i <<
endl;
520 ifdump = Form(
"%s_%s_%d",obj->GetName(),obj->GetTitle(),i);
522 switch ( fSocket->Select(TSocket::kRead,1000) )
525 cout <<
"--> timeout " <<
endl;
528 cout <<
"--> Error " <<
endl;
531 fSocket->RecvRaw(&bsize,
sizeof(Int_t));
532 cout <<
" Size expected " << bsize <<
endl;
533 ret = fSocket->RecvRaw(buffer, bsize);
534 cout <<
" Size received " << ret <<
endl;
536 ofstream file(ifdump.Data(),ios_base::app);
538 file.write(buffer,bsize);
544 else cout <<
" *** Invalid connection *** " <<
endl;
546 else cout <<
" *** Invalid connection *** " <<
endl;
printf("******************************************************************** \n")
header file for PadManager.cpp
void DisplayFolderSUM(const char *include="* {TH1*}", const char *exclude="- {TH2*}", const char *drawopt="", int searchdepth=kMaxInt, TObject *topfolder=0x0)
added to the folder menu, it helps to add many spectra and display it in a pad.
void WatchersUtilities(const Char_t *="first")
Default function.
void DisplayFolder(const char *include="* {TH*}", const char *exclude="- {TH2*}", const char *drawopt="clone !wheel", int searchdepth=kMaxInt, TObject *topfolder=0x0)
added to the folder menu, it helps to draw many spectra in a pad.
void SSHPing(UInt_t nbtimes=1, bool dodump=false)
function to check if a watcher connexion is possible with an actor
void Ping(UInt_t nbtimes=5, bool dodump=false)
function to check if a watcher connexion is possible with an actor
void LoadPing(const char *filename, Option_t *opt="+")
Load list of server to ping from a file.
ADF::LogMessage & endl(ADF::LogMessage &log)
void ZeroOnFolder(const char *include="* {TH*}", const char *exclude="- {TH2*}", const char *drawopt="ICE", int searchdepth=kMaxInt, TObject *topfolder=0x0)
Call Reset of Histograms.