GSI Object Oriented Online Offline (Go4)  GO4-5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4AnalysisImp.cxx
Go to the documentation of this file.
1 // $Id: TGo4AnalysisImp.cxx 1998 2017-04-28 10:27:53Z adamczew $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum f�r Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4AnalysisImp.h"
15 
16 #include <stdexcept>
17 #include <stdio.h>
18 #include <stdlib.h>
19 
20 #include "Riostream.h"
21 #include "TSystem.h"
22 #include "TInterpreter.h"
23 #include "TNamed.h"
24 #include "TApplication.h"
25 #include "TH1.h"
26 #include "TH2.h"
27 #include "TTree.h"
28 #include "TCanvas.h"
29 #include "TFolder.h"
30 #include "TFile.h"
31 #include "TKey.h"
32 #include "TThread.h"
33 #include "TMutex.h"
34 #include "TROOT.h"
35 #include "TCutG.h"
36 #include "TStopwatch.h"
37 #include "TTimeStamp.h"
38 #include "snprintf.h"
39 
40 #include "TGo4Log.h"
41 #include "TGo4LockGuard.h"
42 #include "TGo4Thread.h"
43 #include "TGo4CommandInvoker.h"
44 #include "TGo4Ratemeter.h"
46 #include "TGo4UserException.h"
47 #include "TGo4TaskHandler.h"
48 #include "TGo4WinCond.h"
49 #include "TGo4PolyCond.h"
50 #include "TGo4ShapedCond.h"
51 
52 #include "TGo4Version.h"
56 #include "TGo4AnalysisStatus.h"
57 #include "TGo4AnalysisWebStatus.h"
58 #include "TGo4AnalysisStep.h"
59 #include "TGo4AnalysisClientImp.h"
60 #include "TGo4AnalysisSniffer.h"
62 #include "TGo4Condition.h"
63 #include "TGo4Parameter.h"
64 #include "TGo4Picture.h"
65 #include "TGo4Fitter.h"
66 #include "TGo4ObjectStatus.h"
67 #include "TGo4ObjEnvelope.h"
71 #include "TGo4EventElement.h"
72 #include "TGo4EventStore.h"
73 #include "TGo4EventSource.h"
74 #include "TGo4EventProcessor.h"
77 #include "TGo4EventEndException.h"
78 #include "TGo4CompositeEvent.h"
80 #include "TGo4TreeStructure.h"
81 
82 
83 
84 #if ROOT_VERSION_CODE > ROOT_VERSION(5,2,0)
85 #if ROOT_VERSION_CODE < ROOT_VERSION(5,99,0)
86 #include "TCint.h"
87 #endif
88 #endif
89 
90 
91 class TGo4InterruptHandler : public TSignalHandler {
92  public:
94  TSignalHandler(kSigInterrupt, kFALSE)
95  {
96  }
97 
98  virtual Bool_t Notify()
99  {
100  if (TGo4Analysis::Exists())
102 
103  return kTRUE;
104  }
105 };
106 
107 
108 #ifdef WIN32
109 
110 namespace {
111  void InstallGo4CtrlCHandler(bool on);
112 }
113 
114 #endif
115 
116 
117 // _________________________________________________________________________________
118 
119 
121 Bool_t TGo4Analysis::fbExists = kFALSE;
123 const Int_t TGo4Analysis::fgiAUTOSAVECOUNTS= 500;
124 const Int_t TGo4Analysis::fgiDYNLISTINTERVAL= 1000;
125 const Int_t TGo4Analysis::fgiMACROSTARTPOLL= 1000; //polling time for macro in WaitForStart
126 const char* TGo4Analysis::fgcDEFAULTFILENAME="Go4AutoSave.root";
127 const char* TGo4Analysis::fgcDEFAULTSTATUSFILENAME="Go4AnalysisPrefs.root";
128 const char* TGo4Analysis::fgcDEFAULTFILESUF=".root";
129 const char* TGo4Analysis::fgcTOPDYNAMICLIST="Go4DynamicList";
130 
131 const char TGo4Analysis::fgcPYPROMPT = '$';
132 const char* TGo4Analysis::fgcPYINIT = "python/go4init.py";
133 
135 {
136  GO4TRACE((14,"TGo4Analysis::Instance()",__LINE__, __FILE__));
137  if(fxInstance==0) {
139  fbExists=kTRUE;
140  }
141  return fxInstance;
142 }
143 
145 {
146  return fbExists;
147 }
148 
150 {
151  return fiRunningMode == 0;
152 }
153 
155 {
156  return fiRunningMode == 1;
157 }
158 
160 {
161  return fiRunningMode == 2;
162 }
163 
165 {
166  fiRunningMode = mode;
167 }
168 
169 
170 
171 TGo4Analysis::TGo4Analysis(const char* name) :
172  TObject(),TGo4CommandReceiver(),
173  fbInitIsDone(kFALSE),
174  fbAutoSaveOn(kTRUE),
175  fxAnalysisSlave(0),
176  fxStepManager(0),
177  fxObjectManager(0),
178  fiAutoSaveCount(0),
179  fiAutoSaveInterval(TGo4Analysis::fgiAUTOSAVECOUNTS),
180  fiAutoSaveCompression(5),
181  fxAutoFile(0),
182  fbAutoSaveOverwrite(kFALSE),
183  fbNewInputFile(kFALSE),
184  fxCurrentInputFileName(),
185  fbAutoSaveFileChange(kFALSE),
186  fxSampleEvent(0),
187  fxObjectNames(0),
188  fxDoWorkingFlag(flagInit),
189  fxInterruptHandler(0),
190  fAnalysisName(),
191  fBatchLoopCount(-1),
192  fServerAdminPass(),
193  fServerCtrlPass(),
194  fServerObserverPass(),
195  fbMakeWithAutosave(kTRUE),
196  fbObjMade(kFALSE),
197  fbPythonBound(kFALSE),
198  fNumCtrlC(0),
199  fSniffer(0),
200  fxRate(0)
201 {
202  GO4TRACE((15,"TGo4Analysis::TGo4Analysis(const char*)",__LINE__, __FILE__));
203 
204  if (name!=0) SetAnalysisName(name);
205 
206  Constructor();
207 }
208 
209 
210 TGo4Analysis::TGo4Analysis(int argc, char** argv) :
211  TObject(),TGo4CommandReceiver(),
212  fbInitIsDone(kFALSE),
213  fbAutoSaveOn(kTRUE),
214  fxAnalysisSlave(0),
215  fxStepManager(0),
216  fxObjectManager(0),
217  fiAutoSaveCount(0),
218  fiAutoSaveInterval(TGo4Analysis::fgiAUTOSAVECOUNTS),
219  fiAutoSaveCompression(5),
220  fxAutoFile(0),
221  fbAutoSaveOverwrite(kFALSE),
222  fbNewInputFile(kFALSE),
223  fxCurrentInputFileName(),
224  fbAutoSaveFileChange(kFALSE),
225  fxSampleEvent(0),
226  fxObjectNames(0),
227  fxDoWorkingFlag(flagInit),
228  fxInterruptHandler(0),
229  fAnalysisName(),
230  fBatchLoopCount(-1),
231  fServerAdminPass(),
232  fServerCtrlPass(),
233  fServerObserverPass(),
234  fbMakeWithAutosave(kTRUE),
235  fbObjMade(kFALSE),
236  fbPythonBound(kFALSE),
237  fNumCtrlC(0),
238  fSniffer(0),
239  fxRate(0)
240 {
241  GO4TRACE((15,"TGo4Analysis::TGo4Analysis(const char*)",__LINE__, __FILE__));
242 
243  if ((argc>0) && (argv[0]!=0)) SetAnalysisName(argv[0]);
244 
245  Constructor();
246 }
247 
249 {
251  // wrong version number between framework and user executable
252  Message(-1,"!!!! Analysis Base class:\n\t User Analysis was built with wrong \t\tGo4 Buildversion %d !!!!!",
253  TGo4Version::Instance()->GetBuildVersion());
254  Message(-1,"\t Please rebuild your analysis with current \tGo4 Buildversion %d ", __GO4BUILDVERSION__);
255  Message(-1,"\t >>make clean all<<");
256  Message(-1,"Aborting in 20 s...");
257  gSystem->Sleep(20000);
258  exit(-1);
259  } else {
260  // may not disable output of version number:
261  Message(-1,"Welcome to Go4 Analysis Framework Release %s (build %d) !",
263  }
264 
265  if(fxInstance==0) {
266  gROOT->SetBatch(kTRUE);
267  fxStepManager = new TGo4AnalysisStepManager("Go4 Analysis Step Manager");
268  fxObjectManager = new TGo4AnalysisObjectManager("Go4 Central Object Manager");
270  fxAutoSaveMutex = new TMutex(kTRUE);
271  fxAutoSaveClock = new TStopwatch;
272  fxAutoSaveClock->Stop();
274  if (fAnalysisName.Length()>0) fxAutoFileName = TString::Format("%sASF.root", fAnalysisName.Data());
276  fxDefaultTestFileName=TString::Format("%s/data/test.lmd",getenv("GO4SYS"));
277 
278  TGo4CommandInvoker::Instance(); // make sure we have an invoker instance!
280  TGo4CommandInvoker::Register("Analysis",this); // register as command receiver at the global invoker
281  fxInstance = this; // for ctor usage from derived user subclass
282  fbExists = kTRUE;
283 
285  fxInterruptHandler->Add();
286 
287 #ifdef WIN32
288  InstallGo4CtrlCHandler(true);
289 #endif
290 
291  } else {
292  // instance already there
293  Message(2,"Analysis BaseClass ctor -- analysis singleton already exists !!!");
294  }
295  // settings for macro execution
296  gROOT->ProcessLineSync("TGo4Analysis *go4 = TGo4Analysis::Instance();");
297  gROOT->ProcessLineSync(Form(".x %s", TGo4Log::subGO4SYS("macros/anamacroinit.C").Data()));
298 }
299 
300 
302 {
303 
304 #ifdef WIN32
305  InstallGo4CtrlCHandler(false);
306 #endif
307 
308  if (fxInterruptHandler!=0) {
309  delete fxInterruptHandler;
310  fxInterruptHandler = 0;
311  }
312 
313  GO4TRACE((15,"TGo4Analysis::~TGo4Analysis()",__LINE__, __FILE__));
314  CloseAnalysis();
316  delete fxStepManager;
317  delete fxObjectManager;
318  delete fxObjectNames;
319  delete fxAutoSaveClock;
320  delete fxSampleEvent;
322  fxInstance = 0; // reset static singleton instance pointer
323  gROOT->ProcessLineSync(Form(".x %s", TGo4Log::subGO4SYS("macros/anamacroclose.C").Data()));
324  //std::cout <<"end of dtor" << std::endl;
325 }
326 
327 
329 {
330  switch(fNumCtrlC++) {
331  case 0:
332  StopWorking(); // for batch mode and server mode
333  ShutdownServer(); // only for server mode
334  break;
335  case 1:
336  // if shutdown should hang, we do second try closing the files directly
337  CloseAnalysis();
340  if (gApplication) gApplication->Terminate();
341  break;
342  case 2:
343  default:
344  exit(1); // the hard way if nothing helps
345  break;
346  }
347 }
348 
349 
351 // Initialization and analysis defining methods:
352 
354 {
355  GO4TRACE((14,"TGo4Analysis::InitEventClasses()",__LINE__, __FILE__));
356  //
357  Bool_t rev = kTRUE;
358  if(!fbInitIsDone) {
359  try {
360  TGo4Log::Debug("Analysis -- Initializing EventClasses...");
361  LoadObjects(); // always use autosave file to get last objects list
363  UpdateNamesList();
364  TGo4Log::Info("Analysis -- Initializing EventClasses done.");
365  fbInitIsDone = kTRUE;
366  if (!fxAnalysisSlave) {
369  }
370 
371  } catch(TGo4EventErrorException& ex) {
372  Message(ex.GetPriority(), ex.GetErrMess());
373  rev = kFALSE;
374  }
375  } else
376  TGo4Log::Info("Analysis BaseClass -- EventClasses were already initialized.");
377  return rev;
378 }
379 
381 // main event cycle methods:
382 
384 {
385  GO4TRACE((11,"TGo4Analysis::MainCycle()",__LINE__, __FILE__));
386  if(!fbInitIsDone)
387  throw TGo4UserException(3,"Analysis not yet initialized");
388 
389  {
390  TGo4LockGuard mainlock; // protect analysis, but not status buffer
391 
393 
394  UserEventFunc();
395 
397 
398  if (fbAutoSaveOn && (fiAutoSaveInterval!=0)) {
399  fiAutoSaveCount++;
400  Double_t rt = fxAutoSaveClock->RealTime();
401  if (rt > (Double_t) fiAutoSaveInterval) {
402  Message(0,"Analysis: Main Cycle Autosaving after %.2f s (%d events).",rt,fiAutoSaveCount);
403  AutoSave();
404  fiAutoSaveCount = 0;
405  fxAutoSaveClock->Start(kTRUE);
406  } else
407  fxAutoSaveClock->Continue();
408  }
409 
410  SetNewInputFile(kFALSE); // reset flag of new input file
411 
412  } //TGo4LockGuard main;
413 
414  if(fxAnalysisSlave) {
416  // note: creation of status buffer uses mainlock internally now
417  // status mutex required to be outside main mutex always JA
420  }
421 
422  return 0;
423 }
424 
426 {
427  GO4TRACE((11,"TGo4Analysis::UserEventFunc()",__LINE__, __FILE__));
428  return 0;
429 }
430 
432 {
434 }
435 
437 {
438  GO4TRACE((11,"TGo4Analysis::Process()",__LINE__, __FILE__));
439  Int_t rev=0;
440 #if ROOT_VERSION_CODE > ROOT_VERSION(5,2,0)
441 #if ROOT_VERSION_CODE < ROOT_VERSION(5,99,0)
442  Bool_t unlockedcint=kFALSE;
443  if(gCINTMutex) {
444  gCINTMutex->UnLock();
445  unlockedcint=kTRUE;
446  //std::cout <<"Process() Unlocked cint mutex..." << std::endl;
447  }
448 #endif
449 #endif
450 
451  try
452  {
453  ProcessEvents();
454 
455  if(fxAnalysisSlave)
456  {
457  gSystem->ProcessEvents(); // ensure cintlocktimer to give mainlock back
458  //if(!IsRunning()) TGo4Thread::Sleep(200);
459  //TGo4Thread::Sleep(50); // give other threads time to operate
460  }
461  {
462  //TGo4LockGuard mainlock; // moved to MainCycle
463  if(!IsRunning())
464  {
465  rev=-1;
466  }
467  //return -1;
468  else
469  {
470  TDirectory* savdir = gDirectory;
471  gROOT->cd(); // necessary for dynamic list scope
472  MainCycle();
473  savdir->cd();
474  }
475  }
476 
477  }
479  // begin catch block
480  catch(TGo4EventTimeoutException& ex)
481  {
482  {
483  TGo4LockGuard global;
484  ex.Handle(); // display exception on terminal in case of debug
485  }
487  {
488  // only display message if debug output enabled
489  Message(2,"Analysis %s TIMEOUT for eventsource %s:%s.",
490  GetName(), ex.GetSourceClass(), ex.GetSourceName());
491  } else{}
492  //return 0;
493  }
494  catch(TGo4EventEndException& ex)
495  {
496  Message(2,"End of event source %s: name:%s - msg:%s",
497  ex.GetSourceClass(), ex.GetSourceName(), ex.GetErrMess());
498  if(IsErrorStopEnabled()) {
500  //return -1;
501  rev=-1;
502  }
503  //return 0;
504  }
505  catch(TGo4EventErrorException& ex)
506  {
507  //ex.Handle();
508  Int_t prio=ex.GetPriority();
509  if(prio==0)
510  {
511  // SL:12.2011 even erre display can be skipped, continue without stop
512  // Message(1,"Event source %s: %s - %s",
513  // ex.GetSourceClass(), ex.GetSourceName(),ex.GetErrMess());
514  }
515  else
516  {
517  Message(3,"Analysis %s ERROR: %s from event source %s:\n %s",
518  GetName(),ex.GetErrMess(),
519  ex.GetSourceClass(), ex.GetSourceName());
520  if(IsErrorStopEnabled())
521  {
523  //return -1;
524  rev=-1;
525  }
526  }
527  //return 0;
528  }
529 
530  catch(TGo4DynamicListException& ex)
531  {
532  {
533  TGo4LockGuard global;
534  ex.Handle();
535  }
536  Message(3,"Analysis %s ERROR: %s from dynamic list entry %s:%s",
537  GetName(),ex.GetStatusMessage(),
538  ex.GetEntryName(), ex.GetEntryClass());
539  if(IsErrorStopEnabled())
540  {
542  //return -1;
543  rev=-1;
544  }
545  //return 0;
546  }
547 
548  catch(TGo4AnalysisStepException& ex)
549  {
550  TGo4LockGuard global;
551  ex.Handle();
552  Message(3,"Analysis %s ERROR: %s in Analysis Step %s",
553  GetName(), ex.GetStatusMessage(), ex.GetStepName());
554  if(IsErrorStopEnabled())
555  {
557  //return -1;
558  rev=-1;
559  }
560  //return 0;
561  }
562 
563  catch(TGo4UserException& ex)
564  {
565  // { TGo4LockGuard global; ex.Handle(); }
566 
567  if(strlen(ex.GetMessage())!=0)
568  Message(ex.GetPriority(), ex.GetMessage());
569  if(IsErrorStopEnabled() && (ex.GetPriority() > 2)) {
570  if(fxAnalysisSlave) fxAnalysisSlave->Stop(); // only stop for errors, warnings and infos continue loop!
571  //return -1;
572  rev=-1;
573 
574  }
575  //return 0;
576  }
577 
578  catch(std::exception& ex) // treat standard library exceptions
579  {
580  Message(3,"Analysis %s got standard exception %s",
581  GetName(), ex.what());
582  if(IsErrorStopEnabled())
583  {
585  //return -1;
586  rev=-1;
587  }
588  //return 0;
589  }
590  // end catch block
592 #if ROOT_VERSION_CODE > ROOT_VERSION(5,2,0)
593 #if ROOT_VERSION_CODE < ROOT_VERSION(5,99,0)
594  if(gCINTMutex && unlockedcint) {
596  gCINTMutex->Lock();
597  //std::cout <<"PPPProcess() locked cint mutex..." << std::endl;
598  }
599 #endif
600 #endif
601  return rev;
602 }
603 
604 
605 
606 Int_t TGo4Analysis::RunImplicitLoop(Int_t times, Bool_t showrate, Double_t process_event_interval, Bool_t iswebserver)
607 {
608  GO4TRACE((11,"TGo4Analysis::RunImplicitLoop(Int_t)",__LINE__, __FILE__));
609  Int_t cnt = 0; // number of actually processed events
610  Int_t nextcnt = 0; // number of actually processed events
611  if (process_event_interval>1.) process_event_interval = 1.;
612 
613  if (times < 0) times = fBatchLoopCount;
614 
615  fxRate = new TGo4Ratemeter();
616  TString ratefmt = TString::Format("\rCnt = %s Rate = %s Ev/s", TGo4Log::GetPrintfArg(kULong64_t),"%5.*f");
617  TString ratestr; // string used for rate output
618  Bool_t userate = showrate || (process_event_interval>0.);
619  Bool_t process_events = kFALSE;
620  if (userate)
621  fxRate->SetUpdateInterval(process_event_interval>0. ? process_event_interval : 1.);
622  if (showrate) fxRate->Reset();
623 
624  TTimeStamp last_update;
625 
626  try
627  {
628  if (times>0)
629  Message(1, "Analysis loop for %d cycles is starting...", times);
630  else
631  Message(1, "Analysis loop is starting...");
632 
633  while (fxDoWorkingFlag != flagStop) {
634 
635  if ((times>0) && (cnt>=times)) break;
636 
637  if (userate && fxRate->Update(nextcnt)) {
638 
639  process_events = kTRUE;
640 
641  bool need_update = false;
642  TTimeStamp now;
643  if ((now.AsDouble() - last_update.AsDouble()) >= 1.) {
644  last_update = now; need_update = true;
645  }
646 
647  if (need_update) {
649 
650  TDatime dt;
651  fxRate->SetDateTime(dt.AsSQLString());
652 
653  TGo4AnalysisStep* firststep = GetAnalysisStep(0);
654  if(firststep) {
656  } else {
657  fxRate->SetCurrentSource("- No event source -");
658  }
659 
660  if (showrate) {
661  int width = (fxRate->GetRate()>1e4) ? 0 : (fxRate->GetRate()<1. ? 3 : 1);
662  ratestr.Form(ratefmt.Data(), fxRate->GetCurrentCount(), width, fxRate->GetRate());
663  TGo4Log::Printf(kTRUE, ratestr.Data());
664  }
666  }
667  }
668 
669  nextcnt = 0;
670 
671  try
672  {
673  if (process_events) {
674  // put events processing in exception-handling area
675  process_events = kFALSE;
676  gSystem->ProcessEvents();
677  ProcessEvents();
678  }
679 
680  if (fxDoWorkingFlag == flagRunning) {
681  MainCycle();
682  cnt++; // account completely executed cycles
683  nextcnt = 1; // we process one event
684  } else {
685  gSystem->Sleep(100);
686  }
687 
688  }
689  catch(TGo4UserException& ex)
690  {
691  if(ex.GetPriority()>2)
692  {
693  PostLoop();
694  if(iswebserver)
695  {
696  fxDoWorkingFlag = flagPause; // errors: stop event loop
697  ex.Handle();
698  }
699  else
700  {
701  throw; // return to shell if not remotely controlled
702  }
703  }
704  else
705  {
706  ex.Handle(); // warnings and infos: continue loop after display message
707  }
708  }
709  catch(TGo4EventEndException& ex)
710  {
711  Message(1,"End of event source %s: name:%s msg:%s",ex.GetSourceClass(), ex.GetSourceName(),ex.GetErrMess());
712  PostLoop();
713  if(iswebserver)
714  {
715  fxDoWorkingFlag = flagPause; // errors: stop event loop
716  ex.Handle();
717  }
718  else
719  {
720  throw; // return to shell if not remotely controlled
721  }
722  }
723 
724  catch(TGo4EventErrorException& ex)
725  {
726  if(ex.GetPriority()>0)
727  {
728  Message(ex.GetPriority(),"%s",ex.GetErrMess());
729  PostLoop();
730  if(iswebserver)
731  {
732  fxDoWorkingFlag = flagPause;// errors: stop event loop
733  ex.Handle();
734  }
735  else
736  {
737  throw; // return to shell if not remotely controlled
738  }
739  }
740  else
741  {
742  // SL:12.2011 even error display can be skipped, continue without stop
743  // Message(1,"Eventsource %s:%s %s",ex.GetSourceClass(),
744  // ex.GetSourceName(),ex.GetErrMess());
745  ex.Handle(); // infos: continue loop after display message
746  }
747  }
748 
749  catch(TGo4EventTimeoutException& ex)
750  {
751  ex.Handle(); // just show timeout message, continue event loop
752  }
753 
754  catch(...)
755  {
756  PostLoop(); // make sure that postloop is executed for all exceptions
757  if(iswebserver)
758  {
760  Message(1, "!!! Unexpected exception in %d cycle !!!", cnt);
761  }
762  else
763  {
764  throw;
765  }
766  }
768  }// while loop
769 
770  Message(1, "Analysis implicit Loop has finished after %d cycles.", cnt);
771 
772  // postloop only if analysis not yet closed
774  PostLoop();
775  } // try
776 
777  catch(TGo4Exception& ex) {
778  Message(1, "%s appeared in %d cycle.", ex.What(), cnt);
779  ex.Handle();
780  }
781  catch(std::exception& ex) { // treat standard library exceptions
782  Message(1, "standard exception %s appeared in %d cycle.", ex.what(), cnt);
783  }
784  catch(...) {
785  Message(1, "!!! Unexpected exception in %d cycle !!!", cnt);
786  }
787 
788  if (showrate) {
789  printf("\n"); fflush(stdout);
790  }
791  delete fxRate;
792  fxRate=0;
794  return cnt;
795 }
796 
798 // dynamic list stuff:
799 
800 
801 Bool_t TGo4Analysis::RemoveDynamicEntry(const char * entryname, const char* listname)
802 {
803  GO4TRACE((11,"TGo4Analysis::RemoveDynamicEntry(const char *, const char* )",__LINE__, __FILE__));
804  Bool_t rev=fxObjectManager->RemoveDynamicEntry(entryname);
805  if(rev) UpdateNamesList();
806  return rev;
807 }
808 
809 
811 // status related methods:
812 
814 {
815  GO4TRACE((11,"TGo4Analysis::UpdateStatus(TGo4AnalysisStatus*)",__LINE__, __FILE__));
816  fxStepManager->UpdateStatus(state);
817  if(state!=0) {
822  state->SetAutoSaveOn(fbAutoSaveOn);
823  state->SetConfigFileName(fxConfigFilename.Data());
824  } // if(state!=0)
825 }
826 
828 {
829  GO4TRACE((11,"TGo4Analysis::SetStatus(TGo4AnalysisStatus*)",__LINE__, __FILE__));
830  if(state!=0) {
831  // first we close down existing analysis:
832  CloseAnalysis();
834  SetAutoSave(state->IsAutoSaveOn());
836  state->IsAutoSaveOverwrite(),
837  state->GetAutoSaveCompression());
838  fxStepManager->SetStatus(state);
839  }
840 }
841 
842 
843 Bool_t TGo4Analysis::LoadStatus(const char* filename)
844 {
845  GO4TRACE((11,"TGo4Analysis::LoadStatus(const char*)",__LINE__, __FILE__));
846  //
847  Bool_t rev=kFALSE;
848  TString fname = filename ? filename : fgcDEFAULTSTATUSFILENAME;
849 
850  // file suffix if not given by user
851  if(!fname.Contains(fgcDEFAULTFILESUF)) fname.Append(fgcDEFAULTFILESUF);
852 
853  TFile* statusfile = TFile::Open(fname.Data(), "READ");
854  if(statusfile && statusfile->IsOpen()) {
855  TGo4AnalysisStatus* state=
856  dynamic_cast<TGo4AnalysisStatus*>( statusfile->Get( GetName() ) );
857  if (state==0) {
858  TIter iter(statusfile->GetListOfKeys());
859  TKey* key = 0;
860  while ((key = (TKey*)iter()) != 0) {
861  if (strcmp(key->GetClassName(),"TGo4AnalysisStatus")==0) break;
862  }
863 
864  if (key!=0) state = dynamic_cast<TGo4AnalysisStatus*>( statusfile->Get( key->GetName() ) );
865  }
866 
867  // name of status object is name of analysis itself
868  if(state) {
869  Message(1,"Analysis %s: Found status object %s in file %s",
870  GetName(), state->GetName(), fname.Data());
871  SetStatus(state);
872  fxConfigFilename = fname; // remember last configuration file name
873  Message(0,"Analysis: New analysis state is set.");
874  rev = kTRUE;
875  } else {
876  Message(3,"Analysis LoadStatus: Could not find status %s in file %s", GetName(), fname.Data());
877  rev = kFALSE;
878  } // if(state)
879  } else {
880  Message(3,"Analysis LoadStatus: Failed to open file %s", fname.Data());
881  rev = kFALSE;
882  } // if(statusfile && statusfile->IsOpen())
883 
884  delete statusfile;
885 
886  return rev;
887 }
888 
889 Bool_t TGo4Analysis::SaveStatus(const char* filename)
890 {
891  GO4TRACE((11,"TGo4Analysis::SaveStatus(const char*)",__LINE__, __FILE__));
892  Bool_t rev=kFALSE;
893  char buffer[1024];
894  if(filename)
895  strncpy(buffer, filename, sizeof(buffer)-100);
896  else
897  strncpy(buffer,fgcDEFAULTSTATUSFILENAME, sizeof(buffer)-100);
898  if(!strstr(buffer,fgcDEFAULTFILESUF))
899  strcat(buffer,fgcDEFAULTFILESUF); // file suffix if not given by user
900  TFile* statusfile = TFile::Open(buffer,"RECREATE");
901  if(statusfile && statusfile->IsOpen()) {
902  fxConfigFilename=buffer; // remember name of status
903  statusfile->cd();
905  if(state) {
906  state->Write();
907  delete state;
908  delete statusfile;
909  rev=kTRUE;
910  Message(-1,"Analysis SaveStatus: Saved Analysis settings to file %s", buffer);
911  } else {
912  Message(3,"Analysis SaveStatus: FAILED to create status object !!!");
913  rev=kFALSE;
914  }
915  } else {
916  Message(3,"Analysis SaveStatus: Failed to open file %s ",
917  buffer);
918  rev=kFALSE;
919  } // if(statusfile && statusfile->IsOpen())
920  return rev;
921 }
922 
924 {
925  GO4TRACE((11,"TGo4Analysis::CreateStatus()",__LINE__, __FILE__));
926  TDirectory* filsav=gDirectory;
927  gROOT->cd();
929  UpdateStatus(state);
930  filsav->cd();
931  return state;
932 }
933 
935 {
936  GO4TRACE((11,"TGo4Analysis::CreateWebStatus()",__LINE__, __FILE__));
937  TDirectory* filsav=gDirectory;
938  gROOT->cd();
940  UpdateStatus(state);
941  filsav->cd();
942  return state;
943 }
944 
945 
946 
947 
948 void TGo4Analysis::Print(Option_t*) const
949 {
950  TGo4Analysis* localthis=const_cast<TGo4Analysis*>(this);
951  TGo4AnalysisStatus* state=localthis->CreateStatus();
952  state->PrintStatus();
953  delete state;
954 }
955 
957 {
958  GO4TRACE((11,"TGo4Analysis::CreateSingleEventTree(TGo4EventElement*)",__LINE__, __FILE__));
959 
960  return event ? event->CreateSampleTree(&fxSampleEvent) : 0;
961 }
962 
963 TTree* TGo4Analysis::CreateSingleEventTree(const char* name, Bool_t isoutput)
964 {
965  GO4TRACE((11,"TGo4Analysis::CreateSingleEventTree(const char*, Bool_t)",__LINE__, __FILE__));
966  //
967  TGo4EventElement* event=0;
968  if(isoutput) event = GetOutputEvent(name);
969  else event = GetInputEvent(name);
970  if(event==0) event=GetEventStructure(name);
971 
972  return CreateSingleEventTree(event);
973 }
974 
976 {
977  GO4TRACE((14,"TGo4Analysis::CloseAnalysis()",__LINE__, __FILE__));
978  //
979  if(fbInitIsDone) {
980  AutoSave();
983  fbInitIsDone = kFALSE;
985  }
986 }
987 
989 {
990  GO4TRACE((11,"TGo4Analysis:PreLoop()",__LINE__, __FILE__));
991  TGo4LockGuard autoguard(fxAutoSaveMutex);
992  // avoid conflict with possible user object modifications during startup autosave!
993  fiAutoSaveCount = 0;
994  Int_t rev = UserPreLoop();
995  for (Int_t num = 0; num < fxStepManager->GetNumberOfAnalysisSteps(); num++) {
997  TGo4EventProcessor* proc = step ? step->GetEventProcessor() : 0;
998  if (proc) proc->UserPreLoop();
999  }
1000 
1001  fxAutoSaveClock->Start(kTRUE);
1002  return rev;
1003 }
1004 
1006 {
1007  GO4TRACE((11,"TGo4Analysis::PostLoop()",__LINE__, __FILE__));
1008  TGo4LockGuard autoguard(fxAutoSaveMutex);
1009  Int_t rev=0;
1011  // TTree* mytree = CreateSingleEventTree("Unpack");
1012  // TFile* myfile = TFile::Open("eventsample.root","RECREATE");
1013  // mytree->SetDirectory(myfile);
1014  // mytree->Write();
1015  // delete myfile;
1016  // std::cout <<"___________Wrote eventsample to file eventsample.root" << std::endl;
1018  if(fbInitIsDone) {
1019  for (Int_t num = 0; num < fxStepManager->GetNumberOfAnalysisSteps(); num++) {
1021  TGo4EventProcessor* proc = step ? step->GetEventProcessor() : 0;
1022  if (proc) proc->UserPostLoop();
1023  }
1024 
1025  rev = UserPostLoop(); // do not call userpostloop after error in initialization
1026  }
1027  return rev;
1028 }
1029 
1031 {
1032  GO4TRACE((11,"TGo4Analysis::UserPreLoop()",__LINE__, __FILE__));
1033  //
1034  Message(0,"Analysis BaseClass -- executing default User Preloop");
1035  return 0;
1036 }
1037 
1039 {
1040  GO4TRACE((11,"TGo4Analysis::UserPostLoop()",__LINE__, __FILE__));
1041  //
1042  Message(0,"Analysis BaseClass -- executing default User Postloop");
1043  return 0;
1044 }
1045 
1046 void TGo4Analysis::SetAutoSaveFile(const char * filename, Bool_t overwrite, Int_t compression)
1047 {
1048 // if(!fbAutoSaveOn) return; // do not set autosave file if disabled!
1049  //TGo4LockGuard autoguard(fxAutoSaveMutex);
1050  TString buffer;
1051  if(filename) buffer = filename;
1052  else buffer = fgcDEFAULTFILENAME;
1053  if(!buffer.Contains(fgcDEFAULTFILESUF))
1054  buffer.Append(fgcDEFAULTFILESUF); // file suffix if not given by user
1055  // new: just set parameters, do not open file here:
1056  fxAutoFileName = buffer;
1057  fbAutoSaveOverwrite = overwrite;
1058  fiAutoSaveCompression = compression;
1059 }
1060 
1062 {
1063  return fxAutoFileName.Length() > 0;
1064 }
1065 
1067 {
1068  GO4TRACE((12,"TGo4Analysis::LockAutoSave()",__LINE__, __FILE__));
1069  Int_t rev(-1);
1070  if (TThread::Exists()>0 && fxAutoSaveMutex)
1071  rev = fxAutoSaveMutex->Lock();
1072  return rev;
1073 }
1074 
1076 {
1077  GO4TRACE((12,"TGo4Analysis::UnLockAutoSave()",__LINE__, __FILE__));
1078  Int_t rev(-1);
1079  if (TThread::Exists()>0 && fxAutoSaveMutex)
1080  rev = fxAutoSaveMutex->UnLock();
1081 
1082  return rev;
1083 }
1084 
1086 {
1087  GO4TRACE((12,"TGo4Analysis::AutoSave()",__LINE__, __FILE__));
1088 
1089  if(!fbAutoSaveOn) return;
1090  TGo4LockGuard autoguard(fxAutoSaveMutex);
1091  Message(0,"Analysis -- AutoSaving....");
1092  //UpdateNamesList();
1094  OpenAutoSaveFile(true);
1097  Message(0,"Analysis -- AutoSave done.");
1098 }
1099 
1100 void TGo4Analysis::OpenAutoSaveFile(bool for_writing)
1101 {
1102  if(!fbAutoSaveOn) return;
1103  TGo4LockGuard autoguard(fxAutoSaveMutex);
1104  gROOT->cd();
1105  if (for_writing) {
1106  delete fxAutoFile;
1107  fxAutoFile = TFile::Open(fxAutoFileName.Data() ,"RECREATE");
1108  if (fxAutoFile==0)
1109  Message(3,"Fail to open AutoSave file %s", fxAutoFileName.Data());
1110  else
1111  Message(-1,"Opening AutoSave file %s with RECREATE mode",fxAutoFileName.Data());
1112  if (fxAutoFile) fxAutoFile->SetCompressionLevel(fiAutoSaveCompression);
1113  } else {
1114  if(fxAutoFile==0) {
1115  if (!gSystem->AccessPathName(fxAutoFileName.Data()))
1116  fxAutoFile = TFile::Open(fxAutoFileName.Data(), "READ");
1117  if (fxAutoFile==0)
1118  Message(3,"Fail to open AutoSave file %s", fxAutoFileName.Data());
1119  else
1120  Message(-1,"Opening AutoSave file %s with READ mode",fxAutoFileName.Data());
1121 
1122  } else {
1123  Message(-1,"Reusing AutoSave file %s with READ mode",fxAutoFileName.Data());
1124  }
1125  } // if(fbAutoSaveOverwrite)
1126 
1127  gROOT->cd();
1128 }
1129 
1130 
1132 {
1133  if(fxAutoFile) {
1134  TGo4LockGuard autoguard(fxAutoSaveMutex);
1135  delete fxAutoFile;
1136  fxAutoFile=0;
1137  Message(-1,"AutoSave file %s was closed.",fxAutoFileName.Data());
1138  }
1139 }
1140 
1141 
1143 {
1144  GO4TRACE((11,"TGo4Analysis::UpdateNamesList()",__LINE__, __FILE__));
1145  //
1146  //std::cout <<"UpdateNamesList: current dir:"<< gDirectory->GetName() << std::endl;
1147  // first try: update all
1148  delete fxObjectNames;
1150  Message(0,"Analysis BaseClass -- Nameslist updated.");
1151 }
1152 
1153 
1154 Bool_t TGo4Analysis::LoadObjects(const char* filename)
1155 {
1156  TGo4LockGuard autoguard(fxAutoSaveMutex);
1157  if(filename) fxAutoFileName = filename;
1158 
1159  if(!fbAutoSaveOn) {
1160  TGo4Log::Info("Analysis LoadObjects: AUTOSAVE file is DISABLED, did NOT read objects back from file %s", fxAutoFileName.Data());
1161  return kFALSE;
1162  }
1163 
1164  if (fbAutoSaveOverwrite) {
1165  TGo4Log::Info("Analysis LoadObjects: AUTOSAVE is in overwrite mode - no objects will be loaded from %s", fxAutoFileName.Data());
1166  return kTRUE;
1167  }
1168 
1169  Bool_t rev(kTRUE);
1170  OpenAutoSaveFile(false);
1171  if(fxAutoFile && fxAutoFile->IsOpen()) {
1172  TGo4Log::Info("Analysis LoadObjects: Loading from autosave file %s ", fxAutoFile->GetName());
1174  } else {
1175  TGo4Log::Info("Analysis LoadObjects: Failed to load from file %s", fxAutoFileName.Data());
1176  rev = kFALSE;
1177  }
1179  gROOT->cd();
1180  return rev;
1181 }
1182 
1183 void TGo4Analysis::Message(Int_t prio, const char* text,...)
1184 {
1185  char txtbuf[TGo4Log::fguMESLEN];
1186  va_list args;
1187  va_start(args, text);
1188  vsnprintf(txtbuf, TGo4Log::fguMESLEN, text, args);
1189  va_end(args);
1190  SendMessageToGUI(prio, kTRUE, txtbuf);
1191 }
1192 
1193 void TGo4Analysis::SendMessageToGUI(Int_t level, Bool_t printout, const char* text)
1194 {
1195  if(fxAnalysisSlave) {
1196  // gui mode: send Text via status channel - also sniffer will be informed
1197  fxAnalysisSlave->SendStatusMessage(level, printout, text);
1198  } else {
1199  // batch mode: no gui connection, handle local printout
1200  Bool_t previousmode = TGo4Log::IsOutputEnabled();
1201  TGo4Log::OutputEnable(printout); // override the messaging state
1202  TGo4Log::Message(level, text);
1203  TGo4Log::OutputEnable(previousmode);
1204 
1205  if (fSniffer) fSniffer->StatusMessage(level, printout, text);
1206  } // if (fxAnalysisSlave)
1207 
1208 }
1209 
1211 {
1212  if (ob==0) return;
1213 
1214  if(fxAnalysisSlave==0) {
1215  Message(2,"Could not send object %s to GUI in batch mode.", ob->GetName());
1216  return;
1217  }
1218 
1219  TString pathname;
1220 
1221  if (ObjectManager()->FindObjectPathName(ob, pathname)) {
1222  TGo4ObjEnvelope* envelope = new TGo4ObjEnvelope(ob, ob->GetName(), pathname.Data());
1223  fxAnalysisSlave->SendObject(envelope);
1224  delete envelope;
1225  return;
1226  }
1227 
1228  fxAnalysisSlave->SendObject(dynamic_cast<TNamed*>(ob));
1229 }
1230 
1232 {
1233  if(fxAnalysisSlave)
1234  return fxAnalysisSlave->MainIsRunning();
1235 
1236  return TGo4Analysis::fbExists; // should be kTRUE
1237 }
1238 
1240 {
1241  if(fxAnalysisSlave==0) return;
1242  if(on)
1244  else
1245  fxAnalysisSlave->Stop();
1246 }
1247 
1249 {
1250  #if ROOT_VERSION_CODE > ROOT_VERSION(5,2,0)
1251  #if ROOT_VERSION_CODE < ROOT_VERSION(5,99,0)
1252  Bool_t unlockedcint=kFALSE;
1254  if(gCINTMutex) {
1255  gCINTMutex->UnLock();
1256  unlockedcint=kTRUE;
1257  }
1258  #endif
1259  #endif
1260  Int_t cycles=0;
1262  while(!IsRunning())
1263  {
1264  //std::cout <<"WWWWWWWait for Start before Sleep..." << std::endl;
1265  gSystem->Sleep(fgiMACROSTARTPOLL);
1266  cycles++;
1267  Bool_t sysret = gSystem->ProcessEvents();
1268  if (sysret || (fxDoWorkingFlag == flagStop)) {
1269  cycles=-1;
1270  break;
1271  // allows cint canvas menu "Interrupt" to get us out of here!
1272  // additionally, without ProcessEvents no connect/disconnect of Go4
1273  // would be possible from this wait loop
1274  }
1275  }
1276  #if ROOT_VERSION_CODE > ROOT_VERSION(5,2,0)
1277  #if ROOT_VERSION_CODE < ROOT_VERSION(5,99,0)
1278  if(gCINTMutex && unlockedcint)
1280  gCINTMutex->Lock();
1281  #endif
1282  #endif
1283  return cycles;
1284 }
1285 
1286 void TGo4Analysis::StartObjectServer(const char* basename, const char* passwd)
1287 {
1288  if(fxAnalysisSlave) {
1289  Message(1,"Start object server not yet enabled.");
1290  //fxAnalysisSlave->StartObjectServer(basename,passwd);
1291  } else {
1292  Message(2,"Could not start object server in batch mode.");
1293  }
1294 }
1295 
1297 {
1298  if(fxAnalysisSlave) {
1299  //fxAnalysisSlave->StopObjectServer();
1300  Message(1,"Stop object server not yet enabled.");
1301  } else {
1302  Message(2,"Could not stop object server in batch mode.");
1303  }
1304 }
1305 
1307 {
1308  // this method to be called from ctrl-c signal handler of analysis server
1309  //std::cout <<"######### TGo4Analysis::ShutdownServer()" << std::endl;
1310  if(fxAnalysisSlave)
1311  {
1312  TGo4Log::Message(1,"Analysis server is initiating shutdown after ctrl-c, please wait!!\n");
1313  fxAnalysisSlave->SubmitShutdown(); // shutdown will be performed in local command thread
1314  }
1315 
1316 }
1317 
1318 
1319 
1320 void TGo4Analysis::ShowEvent(const char* stepname, Bool_t isoutput)
1321 {
1322  TTree* sevtree=CreateSingleEventTree(stepname,isoutput);
1323  if(sevtree) {
1324  if(isoutput)
1325  Message(1,"Showing Output Event %s of step %s",sevtree->GetName(),stepname);
1326  else
1327  Message(1,"Showing Input Event %s of step %s",sevtree->GetName(),stepname);
1328  sevtree->Show(0);
1329  std::cout << std::endl;
1330  delete sevtree;
1331  }
1332 }
1333 
1335 // Methods that forward to object manager:
1336 
1337 Bool_t TGo4Analysis::AddDynamicHistogram(const char* name,
1338  const char* histo,
1339  const char* hevx, const char* hmemx,
1340  const char* hevy, const char* hmemy,
1341  const char* hevz, const char* hmemz,
1342  const char* condition,
1343  const char* cevx, const char* cmemx,
1344  const char* cevy, const char* cmemy)
1345 {
1346  return fxObjectManager->AddDynamicHistogram(name,
1347  histo, hevx, hmemx, hevy, hmemy, hevz, hmemz,
1348  condition, cevx, cmemx, cevy, cmemy);
1349 }
1350 
1351 Bool_t TGo4Analysis::AddTreeHistogram(const char* hisname, const char* treename, const char* varexp, const char* cutexp)
1352 {
1353  Bool_t rev=fxObjectManager->AddTreeHistogram(hisname,treename,varexp,cutexp);
1354  if(rev) UpdateNamesList();
1355  return rev;
1356 }
1357 
1359 {
1360  return fxObjectManager->AddEventProcessor(pro);
1361 }
1362 
1364 {
1365  return fxObjectManager->AddEventSource(source);
1366 }
1367 
1369 {
1370  return fxObjectManager->AddEventStore(store);
1371 }
1372 
1374 {
1375  return fxObjectManager->AddEventStructure(ev);
1376 }
1377 
1378 Bool_t TGo4Analysis::AddHistogram(TH1 * his , const char* subfolder, Bool_t replace)
1379 {
1380  return fxObjectManager->AddHistogram(his,subfolder, replace);
1381 }
1382 
1383 Bool_t TGo4Analysis::AddObject(TNamed * anything, const char* subfolder, Bool_t replace)
1384 {
1385  return fxObjectManager->AddObject(anything,subfolder,replace);
1386 }
1387 
1388 Bool_t TGo4Analysis::AddParameter(TGo4Parameter * par, const char* subfolder)
1389 {
1390  return fxObjectManager->AddParameter(par,subfolder);
1391 }
1392 
1393 Bool_t TGo4Analysis::AddPicture(TGo4Picture * pic, const char* subfolder)
1394 {
1395  return fxObjectManager->AddPicture(pic,subfolder);
1396 }
1397 
1398 Bool_t TGo4Analysis::AddCanvas(TCanvas * can, const char* subfolder)
1399 {
1400  return fxObjectManager->AddCanvas(can,subfolder);
1401 }
1402 
1403 Bool_t TGo4Analysis::AddTree(TTree* tree, const char* subfolder)
1404 {
1405  if(tree) tree->ResetBit(TGo4Status::kGo4BackStoreReset);
1406  return fxObjectManager->AddTree(tree, subfolder);
1407 }
1408 
1409 Bool_t TGo4Analysis::AddAnalysisCondition(TGo4Condition * con, const char* subfolder)
1410 {
1411  return fxObjectManager->AddAnalysisCondition(con,subfolder);
1412 }
1413 
1414 TGo4Condition * TGo4Analysis::GetAnalysisCondition(const char * name, const char* cond_cl)
1415 {
1416  return fxObjectManager->GetAnalysisCondition(name, cond_cl);
1417 }
1418 
1420 {
1421  return fxStepManager->GetAnalysisStep(name);
1422 }
1423 
1425 {
1426  return fxStepManager->GetAnalysisStepNum(number);
1427 }
1428 
1430 {
1432 }
1433 
1435 {
1436  return fxObjectManager->GetEventStructure(name);
1437 }
1438 
1439 TH1* TGo4Analysis::GetHistogram(const char * name)
1440 {
1441  return fxObjectManager->GetHistogram(name);
1442 }
1443 
1444 TNamed * TGo4Analysis::GetObject(const char * name, const char* folder)
1445 {
1446  return fxObjectManager->GetObject(name,folder);
1447 }
1448 
1449 TGo4Parameter * TGo4Analysis::GetParameter(const char * name, const char* par_class)
1450 {
1451  return fxObjectManager->GetParameter(name, par_class);
1452 }
1453 
1455 {
1456  return fxObjectManager->GetPicture(name);
1457 }
1458 
1459 TCanvas * TGo4Analysis::GetCanvas(const char * name)
1460 {
1461  return fxObjectManager->GetCanvas(name);
1462 }
1463 
1464 TTree * TGo4Analysis::GetTree(const char * name)
1465 {
1466  return fxObjectManager->GetTree(name);
1467 }
1468 
1470 {
1471  return fxObjectManager->CreateNamesList();
1472 }
1473 
1475 {
1476  return fxObjectManager->GetObjectFolder();
1477 }
1478 
1479 TGo4ObjectStatus * TGo4Analysis::CreateObjectStatus(const char * name, const char* folder)
1480 {
1481  return fxObjectManager->CreateObjectStatus(name,folder);
1482 }
1483 
1485 {
1486  return fxObjectManager->CreateTreeStructure(treename);
1487 }
1488 
1490 {
1491  return fxObjectManager->RemoveEventSource(source);
1492 }
1493 
1495 {
1496  return fxObjectManager->RemoveEventStore(store);
1497 }
1498 
1500 {
1502 }
1503 
1504 Bool_t TGo4Analysis::RemoveHistogram(const char * name, Bool_t del)
1505 {
1506  return fxObjectManager->RemoveHistogram(name,del);
1507 }
1508 
1509 Bool_t TGo4Analysis::RemoveObject(const char * name, Bool_t del)
1510 {
1511  return fxObjectManager->RemoveObject(name,del);
1512 }
1513 
1514 Bool_t TGo4Analysis::RemoveParameter(const char * name)
1515 {
1516  return fxObjectManager->RemoveParameter(name);
1517 }
1518 
1519 Bool_t TGo4Analysis::RemovePicture(const char * name)
1520 {
1521  return fxObjectManager->RemovePicture(name);
1522 }
1523 
1524 Bool_t TGo4Analysis::RemoveCanvas(const char * name)
1525 {
1526  return fxObjectManager->RemoveCanvas(name);
1527 }
1528 
1529 Bool_t TGo4Analysis::RemoveTree(TTree * tree, const char* stepname)
1530 {
1531  return fxObjectManager->RemoveTree(tree, stepname);
1532 }
1533 
1535 {
1537 }
1538 
1540 {
1542 }
1543 
1544 Bool_t TGo4Analysis::DeleteObjects(const char * name)
1545 {
1546  return fxObjectManager->DeleteObjects(name);
1547 }
1548 
1549 Bool_t TGo4Analysis::ClearObjects(const char * name)
1550 {
1551  return fxObjectManager->ClearObjects(name);
1552 }
1553 
1554 Bool_t TGo4Analysis::ProtectObjects(const char * name, const Option_t* flags)
1555 {
1556  return fxObjectManager->ProtectObjects(name, flags);
1557 }
1558 
1559 Bool_t TGo4Analysis::ResetBackStores(Bool_t clearflag)
1560 {
1561  return fxObjectManager->ResetBackStores(clearflag);
1562 }
1563 
1564 Bool_t TGo4Analysis::SetAnalysisCondition(const char * name, TGo4Condition* con, Bool_t counter)
1565 {
1566  return fxObjectManager->SetAnalysisCondition(name, con, counter);
1567 }
1568 
1569 Bool_t TGo4Analysis::SetParameter(const char* name, TGo4Parameter* par)
1570 {
1571  return fxObjectManager->SetParameter(name, par);
1572 }
1573 
1575 {
1576  return fxObjectManager->SetParameterStatus(name, par);
1577 }
1578 
1579 Bool_t TGo4Analysis::SetPicture(const char * name, TGo4Picture * pic)
1580 {
1581  return fxObjectManager->SetPicture(name, pic);
1582 }
1583 
1585 {
1587 }
1588 
1589 void TGo4Analysis::PrintConditions(const char* expression)
1590 {
1591  fxObjectManager->PrintConditions(expression);
1592 }
1593 
1594 void TGo4Analysis::PrintHistograms(const char* expression)
1595 {
1596  fxObjectManager->PrintHistograms(expression);
1597 }
1598 
1599 void TGo4Analysis::PrintParameters(const char* expression)
1600 {
1601  fxObjectManager->PrintParameters(expression);
1602 }
1603 
1605 {
1607 }
1608 
1609 TObject* TGo4Analysis::NextMatchingObject(const char* expr, const char* folder, Bool_t reset)
1610 {
1611  return fxObjectManager->NextMatchingObject(expr,folder,reset);
1612 }
1613 
1614 
1616 // Methods that forward to stepmanager:
1617 
1619 {
1620  return fxStepManager->GetInputEvent(stepindex);
1621 }
1622 
1624 {
1625  return fxStepManager->GetInputEvent(stepname);
1626 }
1627 
1629 {
1630  return fxStepManager->GetOutputEvent();
1631 }
1632 
1634 {
1635  return fxStepManager->GetOutputEvent(stepindex);
1636 }
1637 
1639 {
1640  return fxStepManager->GetOutputEvent(stepname);
1641 }
1642 
1644 {
1645  return fxStepManager->NewStepProcessor(name,par);
1646 }
1647 
1649 {
1650  return fxStepManager->NewStepSource(name,par);
1651 }
1652 
1654 {
1655  return fxStepManager->NewStepStore(name,par);
1656 }
1657 
1659 {
1660  return fxObjectManager->AddDynamicEntry(entry);
1661 }
1662 
1664 {
1666 }
1667 
1668 Bool_t TGo4Analysis::SetFirstStep(const char* name)
1669 {
1670  return fxStepManager->SetFirstStep(name);
1671 }
1672 
1673 Bool_t TGo4Analysis::SetLastStep(const char * name)
1674 {
1675  return fxStepManager->SetLastStep(name);
1676 }
1677 
1678 Bool_t TGo4Analysis::SetStepStorage(const char * name, Bool_t on)
1679 {
1680  return fxStepManager->SetStepStorage(name,on);
1681 }
1682 
1684 {
1686 }
1687 
1689 {
1690  return fxStepManager->AddAnalysisStep(next);
1691 }
1692 
1694 {
1696 }
1697 
1699 {
1700  fxStepManager->SetOutputEvent(event);
1701 }
1702 
1703 Int_t TGo4Analysis::StoreParameter(const char * name, TGo4Parameter* par)
1704 {
1705  return fxStepManager->Store(name, par);
1706 }
1707 
1708 Int_t TGo4Analysis::StoreCondition(const char * name, TGo4Condition* con)
1709 {
1710  return fxStepManager->Store(name, con);
1711 }
1712 
1713 Int_t TGo4Analysis::StoreFitter(const char * name, TGo4Fitter* fit)
1714 {
1715  return fxStepManager->Store(name, fit);
1716 }
1717 
1718 Int_t TGo4Analysis::StoreFolder(const char * name, TFolder* folder)
1719 {
1720  return fxStepManager->Store(name, folder);
1721 }
1722 
1723 Int_t TGo4Analysis::StoreFolder(const char * stepname, const char * foldername)
1724 {
1725  TFolder* myfolder = fxObjectManager->FindSubFolder(GetObjectFolder(), foldername, kFALSE);
1726  return myfolder ? fxStepManager->Store(stepname, myfolder) : 2;
1727 }
1728 
1729 void TGo4Analysis::DefineServerPasswords(const char* admin, const char* controller, const char* observer)
1730 {
1731  fServerAdminPass = admin ? admin : "";
1732  fServerCtrlPass = controller ? controller : "";
1733  fServerObserverPass = observer ? observer : "";
1734 }
1735 
1736 void TGo4Analysis::SetObserverPassword(const char* passwd)
1737 {
1738  fServerObserverPass = passwd ? passwd : "";
1739 }
1740 
1741 void TGo4Analysis::SetControllerPassword(const char* passwd)
1742 {
1743  fServerCtrlPass = passwd ? passwd : "";
1744 }
1745 
1747 {
1748  fServerAdminPass = passwd ? passwd : "";
1749 }
1750 
1751 TH1* TGo4Analysis::MakeTH1(char type, const char* fullname, const char* title,
1752  Int_t nbinsx, Double_t xlow, Double_t xup,
1753  const char* xtitle, const char* ytitle)
1754 {
1755  fbObjMade = kFALSE;
1756  TString foldername, histoname;
1757 
1758  if ((fullname==0) || (strlen(fullname)==0)) {
1759  TGo4Log::Error("Histogram name not specified, can be a hard error");
1760  return 0;
1761  }
1762  const char* separ = strrchr(fullname, '/');
1763  if (separ!=0) {
1764  histoname = separ + 1;
1765  foldername.Append(fullname, separ - fullname);
1766  } else
1767  histoname = fullname;
1768 
1769  int itype = 0;
1770  const char* sclass = "TH1I";
1771  switch (type) {
1772  case 'I': case 'i': itype = 0; sclass = "TH1I"; break;
1773  case 'F': case 'f': itype = 1; sclass = "TH1F"; break;
1774  case 'D': case 'd': itype = 2; sclass = "TH1D"; break;
1775  case 'S': case 's': itype = 3; sclass = "TH1S"; break;
1776  case 'C': case 'c': itype = 4; sclass = "TH1C"; break;
1777  default: TGo4Log::Error("There is no histogram type: %c, use I instead", type); break;
1778  }
1779 
1780  TH1* oldh = GetHistogram(fullname);
1781 
1782  if (oldh!=0) {
1783  if (oldh->InheritsFrom(sclass) && fbMakeWithAutosave) {
1784  if (title) oldh->SetTitle(title);
1785  if (xtitle) oldh->GetXaxis()->SetTitle(xtitle);
1786  if (ytitle) oldh->GetYaxis()->SetTitle(ytitle);
1787  return oldh;
1788  }
1789 
1790  if (fbMakeWithAutosave)
1791  TGo4Log::Info("There is histogram %s with type %s other than specified %s, create new and reuse content",
1792  fullname, oldh->ClassName(), sclass);
1793 
1794  // do not delete histogram immediately
1795  RemoveHistogram(fullname, kFALSE);
1796 
1797  // prevent ROOT to complain about same name
1798  oldh->SetName("___");
1799  }
1800 
1801  TH1* newh = 0;
1802 
1803  switch (itype) {
1804  case 0: newh = new TH1I(histoname, title, nbinsx, xlow, xup); break;
1805  case 1: newh = new TH1F(histoname, title, nbinsx, xlow, xup); break;
1806  case 2: newh = new TH1D(histoname, title, nbinsx, xlow, xup); break;
1807  case 3: newh = new TH1S(histoname, title, nbinsx, xlow, xup); break;
1808  case 4: newh = new TH1C(histoname, title, nbinsx, xlow, xup); break;
1809  }
1810 
1811  newh->SetTitle(title);
1812 
1813  if (xtitle) newh->GetXaxis()->SetTitle(xtitle);
1814  if (ytitle) newh->GetYaxis()->SetTitle(ytitle);
1815 
1816  if (oldh) {
1817  if ((oldh->GetDimension()==1) && fbMakeWithAutosave) newh->Add(oldh);
1818  delete oldh; oldh = 0;
1819  }
1820 
1821  if (foldername.Length() > 0)
1822  AddHistogram(newh, foldername.Data());
1823  else
1824  AddHistogram(newh);
1825 
1826  fbObjMade = kTRUE;
1827 
1828  return newh;
1829 }
1830 
1831 TH2* TGo4Analysis::MakeTH2(char type, const char* fullname, const char* title,
1832  Int_t nbinsx, Double_t xlow, Double_t xup,
1833  Int_t nbinsy, Double_t ylow, Double_t yup,
1834  const char* xtitle, const char* ytitle, const char* ztitle)
1835 {
1836  fbObjMade = kFALSE;
1837  TString foldername, histoname;
1838 
1839  if ((fullname==0) || (strlen(fullname)==0)) {
1840  TGo4Log::Error("Histogram name not specified, can be a hard error");
1841  return 0;
1842  }
1843  const char* separ = strrchr(fullname, '/');
1844  if (separ!=0) {
1845  histoname = separ + 1;
1846  foldername.Append(fullname, separ - fullname);
1847  } else
1848  histoname = fullname;
1849 
1850  int itype = 0;
1851  const char* sclass = "TH2I";
1852  switch (type) {
1853  case 'I': case 'i': itype = 0; sclass = "TH2I"; break;
1854  case 'F': case 'f': itype = 1; sclass = "TH2F"; break;
1855  case 'D': case 'd': itype = 2; sclass = "TH2D"; break;
1856  case 'S': case 's': itype = 3; sclass = "TH2S"; break;
1857  case 'C': case 'c': itype = 4; sclass = "TH2C"; break;
1858  default: TGo4Log::Error("There is no histogram type: %c, use I instead", type); break;
1859  }
1860 
1861  TH1* oldh = GetHistogram(fullname);
1862 
1863  if (oldh!=0) {
1864  if (oldh->InheritsFrom(sclass) && fbMakeWithAutosave) {
1865  if (title) oldh->SetTitle(title);
1866  if (xtitle) oldh->GetXaxis()->SetTitle(xtitle);
1867  if (ytitle) oldh->GetYaxis()->SetTitle(ytitle);
1868  return (TH2*) oldh;
1869  }
1870 
1871  if (fbMakeWithAutosave)
1872  TGo4Log::Info("There is histogram %s with type %s other than specified %s, create new and reuse content",
1873  fullname, oldh->ClassName(), sclass);
1874 
1875  // do not delete histogram immediately
1876  RemoveHistogram(fullname, kFALSE);
1877 
1878  // prevent ROOT to complain about same name
1879  oldh->SetName("___");
1880  }
1881 
1882  TH2* newh = 0;
1883 
1884  switch (itype) {
1885  case 0: newh = new TH2I(histoname, title, nbinsx, xlow, xup, nbinsy, ylow, yup); break;
1886  case 1: newh = new TH2F(histoname, title, nbinsx, xlow, xup, nbinsy, ylow, yup); break;
1887  case 2: newh = new TH2D(histoname, title, nbinsx, xlow, xup, nbinsy, ylow, yup); break;
1888  case 3: newh = new TH2S(histoname, title, nbinsx, xlow, xup, nbinsy, ylow, yup); break;
1889  case 4: newh = new TH2C(histoname, title, nbinsx, xlow, xup, nbinsy, ylow, yup); break;
1890  }
1891 
1892  newh->SetTitle(title);
1893 
1894  if (xtitle) newh->GetXaxis()->SetTitle(xtitle);
1895  if (ytitle) newh->GetYaxis()->SetTitle(ytitle);
1896  if (ztitle) newh->GetZaxis()->SetTitle(ztitle);
1897 
1898  if (oldh) {
1899  if ((oldh->GetDimension()==2) && fbMakeWithAutosave) newh->Add(oldh);
1900  delete oldh;
1901  oldh = 0;
1902  }
1903 
1904  if (foldername.Length() > 0)
1905  AddHistogram(newh, foldername.Data());
1906  else
1907  AddHistogram(newh);
1908 
1909  fbObjMade = kTRUE;
1910 
1911  return newh;
1912 }
1913 
1915  Double_t xmin, Double_t xmax,
1916  const char* HistoName)
1917 {
1918  fbObjMade = kFALSE;
1919  TString foldername, condname;
1920 
1921  if ((fullname==0) || (strlen(fullname)==0)) {
1922  TGo4Log::Error("Condition name not specified, can be a hard error");
1923  return 0;
1924  }
1925  const char* separ = strrchr(fullname, '/');
1926  if (separ!=0) {
1927  condname = separ + 1;
1928  foldername.Append(fullname, separ - fullname);
1929  } else
1930  condname = fullname;
1931 
1932  TGo4Condition* cond = GetAnalysisCondition(fullname);
1933 
1934  if (cond!=0) {
1935  if (cond->InheritsFrom(TGo4WinCond::Class()) && fbMakeWithAutosave) {
1936  cond->ResetCounts();
1937  return (TGo4WinCond*) cond;
1938  }
1939  RemoveAnalysisCondition(fullname);
1940  }
1941 
1942  TGo4WinCond* wcond = new TGo4WinCond(condname);
1943  wcond->SetValues(xmin, xmax);
1944  wcond->SetHistogram(HistoName);
1945  wcond->Enable();
1946 
1947  if (foldername.Length() > 0)
1948  AddAnalysisCondition(wcond, foldername.Data());
1949  else
1950  AddAnalysisCondition(wcond);
1951 
1952  fbObjMade = kTRUE;
1953 
1954  return wcond;
1955 }
1956 
1958  Double_t xmin, Double_t xmax,
1959  Double_t ymin, Double_t ymax,
1960  const char* HistoName)
1961 {
1962  fbObjMade = kFALSE;
1963  TString foldername, condname;
1964 
1965  if ((fullname==0) || (strlen(fullname)==0)) {
1966  TGo4Log::Error("Condition name not specified, can be a hard error");
1967  return 0;
1968  }
1969  const char* separ = strrchr(fullname, '/');
1970  if (separ!=0) {
1971  condname = separ + 1;
1972  foldername.Append(fullname, separ - fullname);
1973  } else
1974  condname = fullname;
1975 
1976  TGo4Condition* cond = GetAnalysisCondition(fullname);
1977 
1978  if (cond!=0) {
1979  if (cond->InheritsFrom(TGo4WinCond::Class()) && fbMakeWithAutosave) {
1980  cond->ResetCounts();
1981  return (TGo4WinCond*) cond;
1982  }
1983  RemoveAnalysisCondition(fullname);
1984  }
1985 
1986  TGo4WinCond* wcond = new TGo4WinCond(condname);
1987  wcond->SetValues(xmin, xmax, ymin, ymax);
1988  wcond->SetHistogram(HistoName);
1989  wcond->Enable();
1990 
1991  if (foldername.Length() > 0)
1992  AddAnalysisCondition(wcond, foldername.Data());
1993  else
1994  AddAnalysisCondition(wcond);
1995 
1996  fbObjMade = kTRUE;
1997 
1998  return wcond;
1999 }
2000 
2002  Int_t npoints,
2003  Double_t (*points) [2],
2004  const char* HistoName,
2005  Bool_t shapedcond)
2006 {
2007  fbObjMade = kFALSE;
2008  TString foldername, condname;
2009 
2010  if ((fullname==0) || (strlen(fullname)==0)) {
2011  TGo4Log::Error("Condition name not specified, can be a hard error");
2012  return 0;
2013  }
2014  const char* separ = strrchr(fullname, '/');
2015  if (separ!=0) {
2016  condname = separ + 1;
2017  foldername.Append(fullname, separ - fullname);
2018  } else
2019  condname = fullname;
2020 
2021  TGo4Condition* cond = GetAnalysisCondition(fullname);
2022 
2023  if (cond!=0) {
2024  if (cond->InheritsFrom(TGo4PolyCond::Class()) && fbMakeWithAutosave) {
2025  cond->ResetCounts();
2026  return (TGo4PolyCond*) cond;
2027  }
2028  RemoveAnalysisCondition(fullname);
2029  }
2030 
2031  TArrayD fullx(npoints+1), fully(npoints+1);
2032 
2033  for (int i=0;i<npoints;i++) {
2034  fullx[i] = points[i][0];
2035  fully[i] = points[i][1];
2036  }
2037 
2038  // connect first and last points
2039  if ((fullx[0]!=fullx[npoints-1]) || (fully[0]!=fully[npoints-1])) {
2040  fullx[npoints] = fullx[0];
2041  fully[npoints] = fully[0];
2042  npoints++;
2043  }
2044 
2045  TCutG mycat("initialcut", npoints, fullx.GetArray(), fully.GetArray());
2046  TGo4PolyCond* pcond;
2047  if(shapedcond)
2048  pcond = new TGo4ShapedCond(condname);
2049  else
2050  pcond = new TGo4PolyCond(condname);
2051  pcond->SetValues(&mycat);
2052  pcond->Enable();
2053 
2054  pcond->SetHistogram(HistoName);
2055 
2056  if (foldername.Length() > 0)
2057  AddAnalysisCondition(pcond, foldername.Data());
2058  else
2059  AddAnalysisCondition(pcond);
2060 
2061  fbObjMade = kTRUE;
2062 
2063  return pcond;
2064 }
2065 
2066 
2068  Int_t npoints,
2069  Double_t cx, Double_t cy, Double_t a1, Double_t a2, Double_t theta,
2070  const char* HistoName)
2071 {
2072  fbObjMade = kFALSE;
2073  TString foldername, condname;
2074 
2075  if ((fullname==0) || (strlen(fullname)==0)) {
2076  TGo4Log::Error("Condition name not specified, can be a hard error");
2077  return 0;
2078  }
2079  const char* separ = strrchr(fullname, '/');
2080  if (separ!=0) {
2081  condname = separ + 1;
2082  foldername.Append(fullname, separ - fullname);
2083  } else
2084  condname = fullname;
2085 
2086  TGo4Condition* cond = GetAnalysisCondition(fullname);
2087 
2088  if (cond!=0) {
2089  if (cond->InheritsFrom(TGo4ShapedCond::Class()) && fbMakeWithAutosave) {
2090  cond->ResetCounts();
2091  return (TGo4ShapedCond*) cond;
2092  }
2093  RemoveAnalysisCondition(fullname);
2094  }
2095 
2096  TGo4ShapedCond* econd = new TGo4ShapedCond(condname);
2097  econd->SetEllipse(cx,cy,a1,a2,theta,npoints);
2098  econd->Enable();
2099  econd->SetHistogram(HistoName);
2100  if (foldername.Length() > 0)
2101  AddAnalysisCondition(econd, foldername.Data());
2102  else
2103  AddAnalysisCondition(econd);
2104 
2105  fbObjMade = kTRUE;
2106 
2107  return econd;
2108 }
2109 
2110 
2112  Int_t npoints, Double_t cx, Double_t cy, Double_t r,
2113  const char* HistoName)
2114 {
2115  TGo4ShapedCond* elli=MakeEllipseCond(fullname,npoints,cx,cy, r, r, 0, HistoName);
2116  elli->SetCircle(); // mark "circle shape" property
2117  return elli;
2118 }
2119 
2120 TGo4ShapedCond* TGo4Analysis::MakeBoxCond(const char* fullname, Double_t cx, Double_t cy, Double_t a1, Double_t a2, Double_t theta,
2121  const char* HistoName)
2122 {
2123  TGo4ShapedCond* elli=MakeEllipseCond(fullname,4,cx,cy, a1, a2, theta, HistoName);
2124  elli->SetBox(); // convert to "box shape" property
2125  return elli;
2126 }
2127 
2128 
2129 
2131  Int_t npoints,
2132  Double_t (*points) [2],
2133  const char* HistoName)
2134 {
2135  TGo4ShapedCond* elli=dynamic_cast<TGo4ShapedCond*>(MakePolyCond(fullname, npoints, points, HistoName,true));
2136  elli->SetFreeShape();
2137  return elli;
2138 }
2139 
2140 
2141 
2142 
2144  const char* classname,
2145  const char* newcmd)
2146 {
2147  fbObjMade = kFALSE;
2148  TString foldername, paramname;
2149 
2150  if ((fullname==0) || (strlen(fullname)==0)) {
2151  TGo4Log::Error("Parameter name not specified, can be a hard error");
2152  return 0;
2153  }
2154  const char* separ = strrchr(fullname, '/');
2155  if (separ!=0) {
2156  paramname = separ + 1;
2157  foldername.Append(fullname, separ - fullname);
2158  } else
2159  paramname = fullname;
2160 
2161  TGo4Parameter* param = GetParameter(fullname);
2162 
2163  if (param!=0) {
2164  if (!param->InheritsFrom(classname)) {
2165  TGo4Log::Info("There is parameter %s with type %s other than specified %s, rebuild",
2166  fullname, param->ClassName(), classname);
2167  RemoveParameter(fullname);
2168  param = 0;
2169  }
2170  }
2171 
2172  if (param==0) {
2173  paramname = TString("\"") + paramname + TString("\"");
2174 
2175  TString cmd;
2176  if ((newcmd!=0) && (strstr(newcmd,"new ")==newcmd))
2177  cmd = TString::Format(newcmd, paramname.Data());
2178  else
2179  cmd = TString::Format("new %s(%s)", classname, paramname.Data());
2180 
2181  Long_t res = gROOT->ProcessLineFast(cmd.Data());
2182 
2183  if (res==0) {
2184  TGo4Log::Error("Cannot create parameter of class %s", classname);
2185  return 0;
2186  }
2187 
2188  param = (TGo4Parameter*) res;
2189 
2190  if (foldername.Length() > 0)
2191  AddParameter(param, foldername.Data());
2192  else
2193  AddParameter(param);
2194 
2195  fbObjMade = kTRUE;
2196  }
2197 
2198  if ((newcmd!=0) && (strstr(newcmd,"set_")==newcmd)) {
2199  // executing optional set macro
2200 
2201  ExecuteScript(newcmd);
2202  }
2203 
2204  return param;
2205 }
2206 
2207 Long_t TGo4Analysis::ExecuteScript(const char* macro_name)
2208 {
2209  if ((macro_name==0) || (strlen(macro_name)==0)) return -1;
2210 
2211  // exclude arguments which could be specified with macro name
2212  TString file_name(macro_name);
2213  Ssiz_t pos = file_name.First('(');
2214  if (pos>0) file_name.Resize(pos);
2215  pos = file_name.First('+');
2216  if (pos>0) file_name.Resize(pos);
2217  while ((file_name.Length()>0) && (file_name[file_name.Length()-1] == ' '))
2218  file_name.Resize(file_name.Length()-1);
2219  while ((file_name.Length()>0) && (file_name[0]==' '))
2220  file_name.Remove(0, 1);
2221 
2222  if (gSystem->AccessPathName(file_name.Data())) {
2223  TGo4Log::Error("ROOT script %s nof found", file_name.Data());
2224  return -1;
2225  }
2226 
2227  TGo4Log::Info("Executing ROOT script %s", macro_name);
2228  return gROOT->ProcessLineSync(Form(".x %s", macro_name)); // here faster than ExecuteLine...
2229 }
2230 
2231 Long_t TGo4Analysis::ExecutePython(const char* macro_name, Int_t* errcode)
2232 {
2233  if ((macro_name==0) || (strlen(macro_name)==0)) return -1;
2234  TString comstring=macro_name;
2235  comstring.Prepend(TGo4Analysis::fgcPYPROMPT); // emulate interactive command line mode here
2236  return ExecuteLine(comstring.Data(), errcode);
2237 }
2238 
2239 
2240 Long_t TGo4Analysis::ExecuteLine(const char* command, Int_t* errcode)
2241 {
2242  TString comstring;
2243 if (strchr(command,TGo4Analysis::fgcPYPROMPT) && (strchr(command,TGo4Analysis::fgcPYPROMPT) == strrchr(command,TGo4Analysis::fgcPYPROMPT))) {
2244  // this one is by Sven Augustin, MPI Heidelberg
2245  comstring = command;
2246  comstring = comstring.Strip(TString::kBoth);
2247  comstring = comstring.Strip(TString::kLeading,TGo4Analysis::fgcPYPROMPT);
2248  comstring = comstring.Strip(TString::kLeading);
2249  TGo4Log::Debug("Executing Python script: %s", comstring.Data());
2250  comstring = "TPython::LoadMacro(\"" + comstring + "\")";
2251  if(!fbPythonBound)
2252  {
2253  TString go4sys=TGo4Log::GO4SYS();
2254  TString pyinit=TGo4Analysis::fgcPYINIT; // JAM todo: put python path and filename into settings
2255  comstring.Prepend("TPython::LoadMacro(\"" + go4sys + pyinit +"\");");
2256  comstring.Prepend("TPython::Bind(go4, \"go4\");" );
2257  fbPythonBound=kTRUE;
2258  }
2259  } else {
2260  comstring="";
2261  const char* cursor = command;
2262  const char* at=0;
2263  do
2264  {
2265  Ssiz_t len=strlen(cursor);
2266  at = strstr(cursor,"@");
2267  if(at)
2268  {
2269  //std::cout <<"Found at: "<<at << std::endl;
2270  len=(Ssiz_t) (at-cursor);
2271  comstring.Append(cursor,len);
2272  comstring.Append("TGo4Analysis::Instance()->");
2273  cursor=at+1;
2274  }
2275  else
2276  {
2277  //std::cout <<"Appended "<<cursor << std::endl;
2278  comstring.Append(cursor);
2279  }
2280  }
2281  while(at);
2282  }
2283  TGo4Log::Debug("ExecuteLine: %s", comstring.Data());
2284  return gROOT->ProcessLineSync(comstring, errcode);
2285  }
2286 
2288 {
2289  if (fxAnalysisSlave) {
2290  // fxAnalysisSlave->GetTask()->SubmitCommand("THStop");
2291  fxAnalysisSlave->Stop();
2292  } else {
2295  }
2296 }
2297 
2299 {
2300  if (fxAnalysisSlave)
2301  {
2303  // fxAnalysisSlave->GetTask()->SubmitCommand("THStart");
2304  }
2305  else
2306  {
2307  // JAM reproduce behavior of analysis client, check init state before executing preloop
2308  if (fbInitIsDone)
2309  {
2311  {
2312  PreLoop();
2313  if(fxRate) fxRate->Reset(); // reset counters and time whenever started again
2314  }
2316  }
2317  else
2318  {
2319  Message(2, TString::Format("Analysis %s was not initialized! Please SUBMIT settings first.", GetName()));
2320  }
2321 
2322  }
2323 }
2324 
2325 
2326 #ifdef WIN32
2327 
2328 #include "windows.h"
2329 
2330 
2331 namespace {
2332 
2333  static BOOL Go4ConsoleSigHandler(DWORD sig)
2334  {
2335  // WinNT signal handler.
2336 
2337  switch (sig) {
2338  case CTRL_C_EVENT:
2339  if (TGo4Analysis::Exists())
2341  return TRUE;
2342  case CTRL_BREAK_EVENT:
2343  case CTRL_LOGOFF_EVENT:
2344  case CTRL_SHUTDOWN_EVENT:
2345  case CTRL_CLOSE_EVENT:
2346  default:
2347  printf(" non CTRL-C signal - ignore\n");
2348  return TRUE;
2349  }
2350  }
2351 
2352  void InstallGo4CtrlCHandler(bool on)
2353  {
2354  ::SetConsoleCtrlHandler((PHANDLER_ROUTINE)Go4ConsoleSigHandler, on);
2355  }
2356 
2357 }
2358 
2359 
2360 
2361 #endif
Bool_t AddTreeHistogram(const char *hisname, const char *treename, const char *varexp, const char *cutexp)
Bool_t SetParameter(const char *name, TGo4Parameter *par, TFolder *parent=0)
Int_t Store(const char *name, TGo4Parameter *obj)
void SetAutoFileName(const char *name)
void SetOutputEvent(TGo4EventElement *event)
void SetRunning(Bool_t on=kTRUE)
const char * GetErrMess() const
TH1 * MakeTH1(char type, const char *fullname, const char *title, Int_t nbinsx, Double_t xlow, Double_t xup, const char *xtitle=0, const char *ytitle=0)
Bool_t SetAnalysisCondition(const char *name, TGo4Condition *con, Bool_t counter=kTRUE, TFolder *parent=0)
void PrintParameters(const char *expression=0)
static const Int_t fgiMACROSTARTPOLL
TGo4Analysis(const char *name=0)
static Bool_t IsServerMode()
static const char * fgcPYINIT
Bool_t NewStepProcessor(const char *name, TGo4EventProcessorParameter *par)
void SetEllipse(Double_t cx, Double_t cy, Double_t a1, Double_t a2, Double_t theta=0, Int_t npoints=0)
Bool_t NewStepSource(const char *name, TGo4EventSourceParameter *par)
Bool_t RemoveEventProcessor(TGo4EventProcessor *pro)
Bool_t NewStepProcessor(const char *name, TGo4EventProcessorParameter *par)
virtual void StatusMessage(int level, Bool_t printout, const TString &)
void UpdateStatus(TGo4AnalysisStatus *state)
Bool_t RemoveEventStructure(TGo4EventElement *ev)
TGo4ShapedCond * MakeFreeShapeCond(const char *fullname, Int_t npoints, Double_t(*points)[2], const char *HistoName=0)
Bool_t SetStepStorage(const char *name, Bool_t on)
Bool_t LoadStatus(const char *filename=0)
Bool_t AddCanvas(TCanvas *can, const char *subfolder=0)
void SetDateTime(const char *str)
Definition: TGo4Ratemeter.h:70
Int_t GetAutoSaveCompression() const
virtual void SendStatusMessage(Int_t level, Bool_t printout, const TString &text)
TGo4ShapedCond * MakeCircleCond(const char *fullname, Int_t npoints, Double_t cx, Double_t cy, Double_t r, const char *HistoName=0)
virtual Int_t UserPreLoop()
TGo4AnalysisClient * fxAnalysisSlave
void SetStatus(TGo4AnalysisStatus *state)
void SetStepChecking(Bool_t on=kTRUE)
void SetAnalysisName(const char *name)
Bool_t AddObject(TNamed *anything, const char *subfolder=0, Bool_t replace=kTRUE)
void SetOutputEvent(TGo4EventElement *event)
void DefineServerPasswords(const char *admin, const char *controller, const char *observer)
Bool_t RemoveParameter(const char *name)
Bool_t AddParameter(TGo4Parameter *par, const char *subfolder=0)
void UpdateStatus(TGo4AnalysisStatus *state)
const char * GetStatusMessage() const
Bool_t AddDynamicEntry(TGo4DynamicEntry *entry)
static void SetCommandList(TGo4CommandProtoList *list)
virtual void UserPreLoop()
Bool_t SetParameter(const char *name, TGo4Parameter *par)
static void UnRegister(TGo4CommandReceiver *p)
TGo4ShapedCond * MakeEllipseCond(const char *fullname, Int_t npoints, Double_t cx, Double_t cy, Double_t a1, Double_t a2, Double_t theta=0, const char *HistoName=0)
static Bool_t CheckVersion(Int_t version)
Definition: TGo4Version.cxx:42
virtual void CloseAnalysis()
Int_t StoreFolder(const char *stepname, TFolder *folder)
void SetCurrentSource(const char *str)
Definition: TGo4Ratemeter.h:71
Bool_t LoadObjects(const char *filename=0)
TGo4TreeStructure * CreateTreeStructure(const char *treename)
void SetObserverPassword(const char *passwd)
Int_t StoreParameter(const char *name, TGo4Parameter *par)
TGo4InterruptHandler * fxInterruptHandler
Bool_t RemovePicture(const char *name)
virtual const char * What()
void SetAutoSaveOn(Bool_t on=kTRUE)
Bool_t AddDynamicHistogram(const char *name, const char *histo, const char *hevx, const char *hmemx, const char *hevy=0, const char *hmemy=0, const char *hevz=0, const char *hmemz=0, const char *condition=0, const char *cevx=0, const char *cmemx=0, const char *cevy=0, const char *cmemy=0)
Bool_t MainIsRunning()
Definition: TGo4Slave.h:92
virtual Int_t PrintStatus(Text_t *buffer=0, Int_t buflen=0)
static void CloseLogfile()
Definition: TGo4Log.cxx:449
void SetControllerPassword(const char *passwd)
static Bool_t IsOutputEnabled()
Definition: TGo4Log.cxx:364
Bool_t ClearObjects(const char *name)
TString fServerCtrlPass
Bool_t DeleteObjects(const char *name)
Bool_t RemoveObject(const char *name, Bool_t del=kTRUE)
static const char * fgcDEFAULTSTATUSFILENAME
TGo4Picture * GetPicture(const char *name)
Int_t IsErrorStopEnabled()
void SendMessageToGUI(Int_t level, Bool_t printout, const char *text)
void SetStepChecking(Bool_t on=kTRUE)
static Bool_t IsClientMode()
Bool_t AddCanvas(TCanvas *can, const char *subfolder=0)
TGo4AnalysisObjectNames * fxObjectNames
Int_t StoreFitter(const char *name, TGo4Fitter *fit)
static const char * GetPrintfArg(Int_t type_id)
Definition: TGo4Log.cxx:343
Bool_t AddPicture(TGo4Picture *pic, const char *subfolder=0)
Bool_t RemoveEventSource(TGo4EventSource *source)
Bool_t RemoveDynamicEntry(const char *entryname)
TH1 * GetHistogram(const char *name)
void ShowEvent(const char *stepname, Bool_t isoutput=kTRUE)
friend class TGo4AnalysisWebStatus
void SetUpdateInterval(double v)
Definition: TGo4Ratemeter.h:82
TString fServerAdminPass
TString fxDefaultTestFileName
Bool_t SetParameterStatus(const char *name, TGo4ParameterStatus *par)
TString fxConfigFilename
static void Register(const char *name, TGo4CommandReceiver *p)
virtual void RatemeterUpdate(TGo4Ratemeter *)
Bool_t RemoveAnalysisCondition(const char *name)
TGo4AnalysisObjectManager * fxObjectManager
virtual Int_t UserEventFunc()
Bool_t SetFirstStep(const char *name)
static void OutputEnable(Bool_t on=kTRUE)
Definition: TGo4Log.cxx:358
Int_t GetPriority() const
TH2 * MakeTH2(char type, const char *fullname, const char *title, Int_t nbinsx, Double_t xlow, Double_t xup, Int_t nbinsy, Double_t ylow, Double_t yup, const char *xtitle=0, const char *ytitle=0, const char *ztitle=0)
Bool_t FindObjectPathName(TObject *obj, TString &pathname, TFolder *fold=0)
Int_t fiAutoSaveInterval
TGo4AnalysisStepManager * fxStepManager
void PrintHistograms(const char *expression=0)
void SetDynListInterval(Int_t val)
void SetRunning(Bool_t on=kTRUE)
Definition: TGo4Ratemeter.h:69
TGo4AnalysisObjectNames * CreateNamesList()
TMutex * fxAutoSaveMutex
void PrintConditions(const char *expression=0)
virtual void ResetCounts()
TGo4EventElement * GetOutputEvent()
TTree * CreateSingleEventTree(const char *name, Bool_t isoutput=kTRUE)
Bool_t fbMakeWithAutosave
TGo4EventElement * GetEventStructure(const char *name)
const char * GetEntryClass() const
Bool_t RemoveEventStructure(TGo4EventElement *ev)
TGo4Condition * GetAnalysisCondition(const char *name, const char *cond_cl=0)
Bool_t AddHistogram(TH1 *his, const char *subfolder=0, Bool_t replace=kTRUE)
Bool_t RemoveEventStore(TGo4EventStore *store)
TGo4AnalysisStep * GetAnalysisStep(const char *name)
static const char * fgcTOPDYNAMICLIST
virtual void UserPostLoop()
void SetAdministratorPassword(const char *passwd)
Bool_t AddHistogram(TH1 *his, const char *subfolder=0, Bool_t replace=kTRUE)
Bool_t AddEventProcessor(TGo4EventProcessor *pro)
Long_t ExecutePython(const char *script_name, Int_t *errcode=0)
Bool_t AddEventSource(TGo4EventSource *source)
static const char fgcPYPROMPT
void SetNewInputFile(Bool_t on=kTRUE)
void ProcessCrtlCSignal()
virtual void Enable()
Bool_t AddAnalysisCondition(TGo4Condition *con, const char *subfolder=0)
Bool_t SetAnalysisCondition(const char *name, TGo4Condition *con, Bool_t counter=kTRUE)
TString fxAutoFileName
Bool_t ResetBackStores(Bool_t clearflag=kFALSE)
Bool_t SetStepStorage(const char *name, Bool_t on)
static const char * fgcDEFAULTFILENAME
const char * GetAutoFileName() const
TGo4Parameter * MakeParameter(const char *fullname, const char *classname, const char *cmd=0)
void PrintHistograms(const char *expression=0)
TGo4EventElement * GetEventStructure(const char *name)
static const char * fgcDEFAULTFILESUF
#define __GO4RELEASE__
Definition: TGo4Version.h:25
Bool_t RemoveEventSource(TGo4EventSource *source)
TH1 * GetHistogram(const char *name)
Int_t RunImplicitLoop(Int_t times, Bool_t showrate=kFALSE, Double_t process_event_interval=-1., Bool_t iswebserver=kFALSE)
TGo4EventElement * GetInputEvent(const char *stepname)
Int_t IsAutoSaveOverwrite() const
TCanvas * GetCanvas(const char *name)
TStopwatch * fxAutoSaveClock
void SetAutoSave(Bool_t on=kTRUE)
Bool_t AddObject(TNamed *anything, const char *subfolder=0, Bool_t replace=kTRUE)
Bool_t RemoveEventStore(TGo4EventStore *store)
#define TRUE
Definition: f_stccomm.h:356
void SendObjectToGUI(TObject *ob)
TString fServerObserverPass
static TGo4CommandInvoker * Instance()
Bool_t RemoveCanvas(const char *name)
Bool_t AddEventStructure(TGo4EventElement *ev)
Bool_t AddEventStore(TGo4EventStore *store)
void Message(Int_t prio, const char *text,...)
Bool_t AddEventSource(TGo4EventSource *source)
const char * GetSourceName() const
Bool_t AddPicture(TGo4Picture *pic, const char *subfolder=0)
void OpenAutoSaveFile(bool for_writing=false)
Bool_t AddParameter(TGo4Parameter *par, const char *subfolder=0)
Double_t GetRate() const
Definition: TGo4Ratemeter.h:50
TFolder * FindSubFolder(TFolder *parent, const char *subfolder, Bool_t create=kTRUE)
Bool_t AddAnalysisCondition(TGo4Condition *con, const char *subfolder=0)
Int_t StoreCondition(const char *name, TGo4Condition *con)
Bool_t AddEventProcessor(TGo4EventProcessor *pro)
Bool_t RemoveTree(TTree *tree, const char *stepname=0)
TGo4Parameter * GetParameter(const char *name, const char *parameter_class=0)
void SetCircle(Double_t cx, Double_t cy, Double_t r, Int_t npoints=0)
Bool_t ResetBackStores(Bool_t clearflag=kFALSE)
Int_t IsAutoSaveOn() const
Long_t ExecuteScript(const char *script_name)
void SetHistogram(const char *name)
void SendObject(TObject *obj, const char *receiver=0)
Definition: TGo4Slave.cxx:120
TTree * GetTree(const char *name)
Bool_t NewStepStore(const char *name, TGo4EventStoreParameter *par)
static Bool_t IsBatchMode()
Bool_t DeleteObjects(const char *name)
static Bool_t fbExists
Bool_t RemoveCanvas(const char *name)
Bool_t AddTree(TTree *tree, const char *subfolder=0)
Bool_t RemoveEventProcessor(TGo4EventProcessor *pro)
Bool_t AddAnalysisStep(TGo4AnalysisStep *next)
static const char * Message(Int_t prio, const char *text,...)
Definition: TGo4Log.cxx:209
TGo4EventElement * GetInputEvent(const char *stepname)
TString fAnalysisName
TGo4Parameter * GetParameter(const char *name, const char *parameter_class=0)
const char * GetEntryName() const
virtual Int_t UserPostLoop()
void StartObjectServer(const char *basename, const char *passwd)
TGo4AnalysisObjectNames * CreateNamesList()
TGo4EventElement * GetOutputEvent(const char *stepname)
TObject * NextMatchingObject(const char *expr, const char *folder, Bool_t reset)
Bool_t ClearObjects(const char *name)
TGo4Picture * GetPicture(const char *name)
TGo4Ratemeter * fxRate
#define __GO4BUILDVERSION__
Definition: TGo4Version.h:24
Int_t fiAutoSaveCompression
virtual void SetValues(Double_t low1, Double_t up1)
virtual const char * GetName() const
TGo4Condition * GetAnalysisCondition(const char *name, const char *cond_cl=0)
const char * GetStatusMessage() const
static TGo4Version * Instance()
Definition: TGo4Version.cxx:22
static TGo4Analysis * fxInstance
Bool_t AddTree(TTree *tree, const char *subfolder=0)
TGo4AnalysisObjectManager * ObjectManager() const
Bool_t RemoveTree(TTree *tree, const char *stepname=0)
virtual void ProcessSnifferEvents()
TGo4ShapedCond * MakeBoxCond(const char *fullname, Double_t cx, Double_t cy, Double_t a1, Double_t a2, Double_t theta, const char *HistoName=0)
virtual ~TGo4Analysis()
Bool_t RemoveAnalysisCondition(const char *name)
TGo4AnalysisSniffer * fSniffer
TGo4ObjectStatus * CreateObjectStatus(const char *name, const char *folder=0)
static void Printf(Bool_t _stdout, const char *text)
Definition: TGo4Log.cxx:255
Bool_t Update(Int_t increment=1)
virtual Bool_t InitEventClasses()
virtual void Print(Option_t *opt="") const
Bool_t NewStepStore(const char *name, TGo4EventStoreParameter *par)
virtual Bool_t Notify()
virtual Int_t Handle()
TObject * NextMatchingObject(const char *expr=0, const char *folder=0, Bool_t reset=kFALSE)
#define GO4TRACE(X)
Definition: TGo4Log.h:26
static Int_t fiRunningMode
TGo4AnalysisStep * GetAnalysisStep(const char *name)
Bool_t RemoveObject(const char *name, Bool_t del=kTRUE)
static Int_t GetIgnoreLevel()
Definition: TGo4Log.cxx:328
Bool_t RemoveHistogram(const char *name, Bool_t del=kTRUE)
void PrintParameters(const char *expression=0)
void SetAutoSaveOverwrite(Bool_t over=kTRUE)
Bool_t IsAutoSaveFileName() const
TGo4ObjectStatus * CreateObjectStatus(const char *name, const char *folder=0)
Long_t ExecuteLine(const char *command, Int_t *errcode=0)
void SetAutoSaveFile(const char *filename=0, Bool_t overwrite=kFALSE, Int_t compression=5)
TGo4AnalysisStep * GetAnalysisStepNum(Int_t number)
Bool_t AddAnalysisStep(TGo4AnalysisStep *next)
Bool_t ProtectObjects(const char *name, const Option_t *flags)
static TString subGO4SYS(const char *subdir)
Definition: TGo4Log.cxx:192
Bool_t ProtectObjects(const char *name, const Option_t *flags)
Bool_t SetPicture(const char *name, TGo4Picture *pic)
Bool_t SaveStatus(const char *filename=0)
Bool_t AddTreeHistogram(const char *hisname, const char *treename, const char *varexp, const char *cutexp)
void SetConfigFileName(const char *name)
Bool_t SetPicture(const char *name, TGo4Picture *pic, TFolder *parent=0)
TGo4AnalysisStep * GetAnalysisStepNum(Int_t number)
TNamed * GetObject(const char *name, const char *folder=0)
Bool_t RemoveDynamicEntry(const char *entryname, const char *listname=0)
ULong64_t GetCurrentCount() const
Definition: TGo4Ratemeter.h:54
Bool_t RemoveParameter(const char *name)
void UpdateStatusBuffer()
Definition: TGo4Slave.cxx:157
Bool_t SetParameterStatus(const char *name, TGo4ParameterStatus *par, TFolder *parent=0)
Bool_t fbAutoSaveOverwrite
void SetAutoSaveInterval(Int_t i)
Bool_t AddDynamicHistogram(const char *name, const char *histo, const char *hevx, const char *hmemx, const char *hevy=0, const char *hmemy=0, const char *hevz=0, const char *hmemz=0, const char *condition=0, const char *cevx=0, const char *cmemx=0, const char *cevy=0, const char *cmemy=0)
TNamed * GetObject(const char *name, const char *folder=0)
Bool_t AddDynamicEntry(TGo4DynamicEntry *entry)
TGo4AnalysisStatus * CreateStatus()
void SetBox(Double_t cx, Double_t cy, Double_t a1, Double_t a2, Double_t theta=0)
Bool_t AddEventStructure(TGo4EventElement *ev)
static Bool_t Exists()
void UpdateRate(Int_t counts=1)
static const char * GO4SYS()
Definition: TGo4Log.cxx:158
Bool_t RemoveHistogram(const char *name, Bool_t del=kTRUE)
Bool_t LoadObjects(TFile *statusfile)
Int_t ProcessAnalysisSteps()
enum TGo4Analysis::@0 fxDoWorkingFlag
Bool_t AddEventStore(TGo4EventStore *store)
const char * GetSourceClass() const
static const Int_t fgiDYNLISTINTERVAL
static void SetRunningMode(int mode)
static TGo4Analysis * Instance()
TGo4EventElement * fxSampleEvent
static const Int_t fgiAUTOSAVECOUNTS
TTree * GetTree(const char *name)
Bool_t SetFirstStep(const char *name)
const char * GetMessage() const
const char * GetEventSourceName()
Int_t GetDynListInterval()
TGo4EventProcessor * GetEventProcessor() const
TGo4AnalysisWebStatus * CreateWebStatus()
TGo4PolyCond * MakePolyCond(const char *fullname, Int_t npoints, Double_t(*points)[2], const char *HistoName=0, Bool_t shapedcond=kFALSE)
static void Error(const char *text,...)
Definition: TGo4Log.cxx:309
Bool_t NewStepSource(const char *name, TGo4EventSourceParameter *par)
void PrintConditions(const char *expression=0)
void SetAutoSaveCompression(Int_t i=5)
TGo4TreeStructure * CreateTreeStructure(TTree *thetree)
static void Info(const char *text,...)
Definition: TGo4Log.cxx:283
TFolder * GetObjectFolder()
Bool_t SetLastStep(const char *name)
Int_t GetAutoSaveInterval() const
Bool_t RemovePicture(const char *name)
TCanvas * GetCanvas(const char *name)
Bool_t SetLastStep(const char *name)
void SetAutoSaveInterval(Int_t interval=0)
TGo4WinCond * MakeWinCond(const char *fullname, Double_t xmin, Double_t xmax, const char *HistoName=0)
static void Debug(const char *text,...)
Definition: TGo4Log.cxx:270
void SetStatus(TGo4AnalysisStatus *state)