00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4AnalysisImp.h"
00015
00016 #include <stdexcept>
00017 #include <stdio.h>
00018 #include <stdlib.h>
00019
00020 #include "Riostream.h"
00021 #include "TSystem.h"
00022 #include "TInterpreter.h"
00023 #include "TNamed.h"
00024 #include "TApplication.h"
00025 #include "TH1.h"
00026 #include "TH2.h"
00027 #include "TTree.h"
00028 #include "TCanvas.h"
00029 #include "TFolder.h"
00030 #include "TFile.h"
00031 #include "TKey.h"
00032 #include "TMutex.h"
00033 #include "TROOT.h"
00034 #include "TCutG.h"
00035 #include "TStopwatch.h"
00036 #include "TTimeStamp.h"
00037 #include "snprintf.h"
00038
00039 #include "TGo4Log.h"
00040 #include "TGo4LockGuard.h"
00041 #include "TGo4Thread.h"
00042 #include "TGo4CommandInvoker.h"
00043 #include "TGo4Ratemeter.h"
00044 #include "TGo4AnalysisCommandList.h"
00045 #include "TGo4UserException.h"
00046 #include "TGo4TaskHandler.h"
00047 #include "TGo4WinCond.h"
00048 #include "TGo4PolyCond.h"
00049
00050 #include "TGo4Version.h"
00051 #include "TGo4AnalysisStepManager.h"
00052 #include "TGo4AnalysisObjectManager.h"
00053 #include "TGo4AnalysisObjectNames.h"
00054 #include "TGo4AnalysisStatus.h"
00055 #include "TGo4AnalysisStep.h"
00056 #include "TGo4AnalysisClientImp.h"
00057 #include "TGo4AnalysisSniffer.h"
00058 #include "TGo4HistogramStatus.h"
00059 #include "TGo4DynamicListException.h"
00060 #include "TGo4Condition.h"
00061 #include "TGo4Parameter.h"
00062 #include "TGo4Picture.h"
00063 #include "TGo4Fitter.h"
00064 #include "TGo4ObjectStatus.h"
00065 #include "TGo4ObjEnvelope.h"
00066 #include "TGo4EventStoreParameter.h"
00067 #include "TGo4EventSourceParameter.h"
00068 #include "TGo4EventProcessorParameter.h"
00069 #include "TGo4EventElement.h"
00070 #include "TGo4EventStore.h"
00071 #include "TGo4EventSource.h"
00072 #include "TGo4EventProcessor.h"
00073 #include "TGo4EventErrorException.h"
00074 #include "TGo4EventTimeoutException.h"
00075 #include "TGo4EventEndException.h"
00076 #include "TGo4CompositeEvent.h"
00077 #include "TGo4AnalysisStepException.h"
00078 #include "TGo4TreeStructure.h"
00079
00080
00081
00082 #if ROOT_VERSION_CODE > ROOT_VERSION(5,2,0)
00083 #if ROOT_VERSION_CODE < ROOT_VERSION(5,99,0)
00084 #include "TCint.h"
00085 #endif
00086 #endif
00087
00088
00089 class TGo4InterruptHandler : public TSignalHandler {
00090 public:
00091 TGo4InterruptHandler() :
00092 TSignalHandler(kSigInterrupt, kFALSE)
00093 {
00094 }
00095
00096 virtual Bool_t Notify()
00097 {
00098 if (TGo4Analysis::Exists())
00099 TGo4Analysis::Instance()->ProcessCrtlCSignal();
00100
00101 return kTRUE;
00102 }
00103 };
00104
00105
00106 #ifdef WIN32
00107
00108 namespace {
00109 void InstallGo4CtrlCHandler(bool on);
00110 }
00111
00112 #endif
00113
00114
00115
00116
00117
00118 TGo4Analysis* TGo4Analysis::fxInstance = 0;
00119 Bool_t TGo4Analysis::fbExists = kFALSE;
00120 Int_t TGo4Analysis::fiRunningMode = 0;
00121 const Int_t TGo4Analysis::fgiAUTOSAVECOUNTS= 500;
00122 const Int_t TGo4Analysis::fgiDYNLISTINTERVAL= 1000;
00123 const Int_t TGo4Analysis::fgiMACROSTARTPOLL= 1000;
00124 const char* TGo4Analysis::fgcDEFAULTFILENAME="Go4AutoSave.root";
00125 const char* TGo4Analysis::fgcDEFAULTSTATUSFILENAME="Go4AnalysisPrefs.root";
00126 const char* TGo4Analysis::fgcDEFAULTFILESUF=".root";
00127 const char* TGo4Analysis::fgcTOPDYNAMICLIST="Go4DynamicList";
00128
00129
00130 TGo4Analysis* TGo4Analysis::Instance()
00131 {
00132 GO4TRACE((14,"TGo4Analysis::Instance()",__LINE__, __FILE__));
00133 if(fxInstance==0) {
00134 fxInstance=new TGo4Analysis;
00135 fbExists=kTRUE;
00136 }
00137 return fxInstance;
00138 }
00139
00140 Bool_t TGo4Analysis::Exists()
00141 {
00142 return fbExists;
00143 }
00144
00145 Bool_t TGo4Analysis::IsBatchMode()
00146 {
00147 return fiRunningMode == 0;
00148 }
00149
00150 Bool_t TGo4Analysis::IsClientMode()
00151 {
00152 return fiRunningMode == 1;
00153 }
00154
00155 Bool_t TGo4Analysis::IsServerMode()
00156 {
00157 return fiRunningMode == 2;
00158 }
00159
00160 void TGo4Analysis::SetRunningMode(int mode)
00161 {
00162 fiRunningMode = mode;
00163 }
00164
00165
00166
00167 TGo4Analysis::TGo4Analysis(const char* name) :
00168 TGo4CommandReceiver(),
00169 TObject(),
00170 fbInitIsDone(kFALSE),
00171 fbAutoSaveOn(kTRUE),
00172 fxAnalysisSlave(0),
00173 fxStepManager(0),
00174 fxObjectManager(0),
00175 fiAutoSaveCount(0),
00176 fiAutoSaveInterval(TGo4Analysis::fgiAUTOSAVECOUNTS),
00177 fiAutoSaveCompression(5),
00178 fxAutoFile(0),
00179 fbAutoSaveOverwrite(kFALSE),
00180 fbNewInputFile(kFALSE),
00181 fxCurrentInputFileName(),
00182 fbAutoSaveFileChange(kFALSE),
00183 fxSampleEvent(0),
00184 fxObjectNames(0),
00185 fxDoWorkingFlag(flagRunning),
00186 fxInterruptHandler(0),
00187 fAnalysisName(),
00188 fBatchLoopCount(-1),
00189 fServerAdminPass(),
00190 fServerCtrlPass(),
00191 fServerObserverPass(),
00192 fbMakeWithAutosave(kTRUE),
00193 fbObjMade(kFALSE),
00194 fNumCtrlC(0),
00195 fSniffer(0)
00196 {
00197 GO4TRACE((15,"TGo4Analysis::TGo4Analysis(const char*)",__LINE__, __FILE__));
00198
00199 if (name!=0) SetAnalysisName(name);
00200
00201 Constructor();
00202 }
00203
00204
00205 TGo4Analysis::TGo4Analysis(int argc, char** argv) :
00206 TGo4CommandReceiver(),
00207 TObject(),
00208 fbInitIsDone(kFALSE),
00209 fbAutoSaveOn(kTRUE),
00210 fxAnalysisSlave(0),
00211 fxStepManager(0),
00212 fxObjectManager(0),
00213 fiAutoSaveCount(0),
00214 fiAutoSaveInterval(TGo4Analysis::fgiAUTOSAVECOUNTS),
00215 fiAutoSaveCompression(5),
00216 fxAutoFile(0),
00217 fbAutoSaveOverwrite(kFALSE),
00218 fbNewInputFile(kFALSE),
00219 fxCurrentInputFileName(),
00220 fbAutoSaveFileChange(kFALSE),
00221 fxSampleEvent(0),
00222 fxObjectNames(0),
00223 fxDoWorkingFlag(flagRunning),
00224 fxInterruptHandler(0),
00225 fAnalysisName(),
00226 fBatchLoopCount(-1),
00227 fServerAdminPass(),
00228 fServerCtrlPass(),
00229 fServerObserverPass(),
00230 fbMakeWithAutosave(kTRUE),
00231 fbObjMade(kFALSE),
00232 fNumCtrlC(0),
00233 fSniffer(0)
00234 {
00235 GO4TRACE((15,"TGo4Analysis::TGo4Analysis(const char*)",__LINE__, __FILE__));
00236
00237 if ((argc>0) && (argv[0]!=0)) SetAnalysisName(argv[0]);
00238
00239 Constructor();
00240 }
00241
00242 void TGo4Analysis::Constructor()
00243 {
00244 if (!TGo4Version::CheckVersion(__GO4BUILDVERSION__)) {
00245
00246 Message(-1,"!!!! Analysis Base class:\n\t User Analysis was built with wrong \t\tGo4 Buildversion %d !!!!!",
00247 TGo4Version::Instance()->GetBuildVersion());
00248 Message(-1,"\t Please rebuild your analysis with current \tGo4 Buildversion %d ", __GO4BUILDVERSION__);
00249 Message(-1,"\t >>make clean all<<");
00250 Message(-1,"Aborting in 20 s...");
00251 gSystem->Sleep(20000);
00252 exit(-1);
00253 } else {
00254
00255 Message(-1,"Welcome to Go4 Analysis Framework Release %s (build %d) !",
00256 __GO4RELEASE__ , __GO4BUILDVERSION__);
00257 }
00258
00259 if(fxInstance==0) {
00260 gROOT->SetBatch(kTRUE);
00261 fxStepManager = new TGo4AnalysisStepManager("Go4 Analysis Step Manager");
00262 fxObjectManager = new TGo4AnalysisObjectManager("Go4 Central Object Manager");
00263 SetDynListInterval(TGo4Analysis::fgiDYNLISTINTERVAL);
00264 fxAutoSaveMutex = new TMutex(kTRUE);
00265 fxAutoSaveClock = new TStopwatch;
00266 fxAutoSaveClock->Stop();
00267 fxAutoFileName = fgcDEFAULTFILENAME;
00268 if (fAnalysisName.Length()>0) fxAutoFileName = TString::Format("%sASF.root", fAnalysisName.Data());
00269 fxConfigFilename = fgcDEFAULTSTATUSFILENAME;
00270 TGo4CommandInvoker::Instance();
00271 TGo4CommandInvoker::SetCommandList(new TGo4AnalysisCommandList);
00272 TGo4CommandInvoker::Register("Analysis",this);
00273 fxInstance = this;
00274 fbExists = kTRUE;
00275
00276 fxInterruptHandler = new TGo4InterruptHandler();
00277 fxInterruptHandler->Add();
00278
00279 #ifdef WIN32
00280 InstallGo4CtrlCHandler(true);
00281 #endif
00282
00283 } else {
00284
00285 Message(2,"Analysis BaseClass ctor -- analysis singleton already exists !!!");
00286 }
00287
00288 gROOT->ProcessLineSync("TGo4Analysis *go4 = TGo4Analysis::Instance();");
00289 gROOT->ProcessLineSync(Form(".x %s", TGo4Log::subGO4SYS("macros/anamacroinit.C").Data()));
00290 }
00291
00292
00293 TGo4Analysis::~TGo4Analysis()
00294 {
00295
00296 #ifdef WIN32
00297 InstallGo4CtrlCHandler(false);
00298 #endif
00299
00300 if (fxInterruptHandler!=0) {
00301 delete fxInterruptHandler;
00302 fxInterruptHandler = 0;
00303 }
00304
00305 GO4TRACE((15,"TGo4Analysis::~TGo4Analysis()",__LINE__, __FILE__));
00306 CloseAnalysis();
00307 CloseAutoSaveFile();
00308 delete fxStepManager;
00309 delete fxObjectManager;
00310 delete fxObjectNames;
00311 delete fxAutoSaveClock;
00312 delete fxSampleEvent;
00313 TGo4CommandInvoker::UnRegister(this);
00314 fxInstance = 0;
00315 gROOT->ProcessLineSync(Form(".x %s", TGo4Log::subGO4SYS("macros/anamacroclose.C").Data()));
00316
00317 }
00318
00319
00320 void TGo4Analysis::ProcessCrtlCSignal()
00321 {
00322 switch(fNumCtrlC++) {
00323 case 0:
00324 StopWorking();
00325 ShutdownServer();
00326 break;
00327 case 1:
00328
00329 CloseAnalysis();
00330 CloseAutoSaveFile();
00331 TGo4Log::CloseLogfile();
00332 if (gApplication) gApplication->Terminate();
00333 break;
00334 case 2:
00335 default:
00336 exit(1);
00337 break;
00338 }
00339 }
00340
00341
00343
00344
00345 Bool_t TGo4Analysis::InitEventClasses()
00346 {
00347 GO4TRACE((14,"TGo4Analysis::InitEventClasses()",__LINE__, __FILE__));
00348
00349 Bool_t rev = kTRUE;
00350 if(!fbInitIsDone) {
00351 try {
00352 TGo4Log::Debug("Analysis -- Initializing EventClasses...");
00353 LoadObjects();
00354 rev = fxStepManager->InitEventClasses();
00355 UpdateNamesList();
00356 TGo4Log::Info("Analysis -- Initializing EventClasses done.");
00357 fbInitIsDone = kTRUE;
00358 } catch(TGo4EventErrorException& ex) {
00359 Message(ex.GetPriority(), ex.GetErrMess());
00360 rev = kFALSE;
00361 }
00362 } else
00363 TGo4Log::Info("Analysis BaseClass -- EventClasses were already initialized.");
00364 return rev;
00365 }
00366
00368
00369
00370 Int_t TGo4Analysis::MainCycle()
00371 {
00372 GO4TRACE((11,"TGo4Analysis::MainCycle()",__LINE__, __FILE__));
00373 if(!fbInitIsDone)
00374 throw TGo4UserException(3,"Analysis not yet initialized");
00375
00376 {
00377 TGo4LockGuard mainlock;
00378
00379 ProcessAnalysisSteps();
00380
00381 UserEventFunc();
00382
00383 fxObjectManager->ProcessDynamicList();
00384
00385 if (fbAutoSaveOn && (fiAutoSaveInterval!=0)) {
00386 fiAutoSaveCount++;
00387 Double_t rt = fxAutoSaveClock->RealTime();
00388 if (rt > (Double_t) fiAutoSaveInterval) {
00389 Message(0,"Analysis: Main Cycle Autosaving after %.2f s (%d events).",rt,fiAutoSaveCount);
00390 AutoSave();
00391 fiAutoSaveCount = 0;
00392 fxAutoSaveClock->Start(kTRUE);
00393 } else
00394 fxAutoSaveClock->Continue();
00395 }
00396
00397 SetNewInputFile(kFALSE);
00398
00399 }
00400
00401 if(fxAnalysisSlave) {
00402 fxAnalysisSlave->UpdateRate();
00403
00404
00405 if (fxAnalysisSlave->TestBufferUpdateConditions())
00406 fxAnalysisSlave->UpdateStatusBuffer();
00407 }
00408
00409 return 0;
00410 }
00411
00412 Int_t TGo4Analysis::UserEventFunc()
00413 {
00414 GO4TRACE((11,"TGo4Analysis::UserEventFunc()",__LINE__, __FILE__));
00415 return 0;
00416 }
00417
00418 Int_t TGo4Analysis::Process()
00419 {
00420 GO4TRACE((11,"TGo4Analysis::Process()",__LINE__, __FILE__));
00421 Int_t rev=0;
00422 #if ROOT_VERSION_CODE > ROOT_VERSION(5,2,0)
00423 #if ROOT_VERSION_CODE < ROOT_VERSION(5,99,0)
00424 Bool_t unlockedcint=kFALSE;
00425 if(gCINTMutex) {
00426 gCINTMutex->UnLock();
00427 unlockedcint=kTRUE;
00428
00429 }
00430 #endif
00431 #endif
00432
00433 try
00434 {
00435 if(fxAnalysisSlave)
00436 {
00437 gSystem->ProcessEvents();
00438
00439
00440 }
00441 {
00442
00443 if(!IsRunning())
00444 {
00445 rev=-1;
00446 }
00447
00448 else
00449 {
00450 TDirectory* savdir = gDirectory;
00451 gROOT->cd();
00452 MainCycle();
00453 savdir->cd();
00454 }
00455 }
00456
00457 }
00459
00460 catch(TGo4EventTimeoutException& ex)
00461 {
00462 {
00463 TGo4LockGuard global;
00464 ex.Handle();
00465 }
00466 if(TGo4Log::GetIgnoreLevel()<1)
00467 {
00468
00469 Message(2,"Analysis %s TIMEOUT for eventsource %s:%s.",
00470 GetName(), ex.GetSourceClass(), ex.GetSourceName());
00471 } else{}
00472
00473 }
00474 catch(TGo4EventEndException& ex)
00475 {
00476 Message(2,"End of event source %s: name:%s - msg:%s",
00477 ex.GetSourceClass(), ex.GetSourceName(), ex.GetErrMess());
00478 if(IsErrorStopEnabled()) {
00479 if(fxAnalysisSlave) fxAnalysisSlave->Stop();
00480
00481 rev=-1;
00482 }
00483
00484 }
00485 catch(TGo4EventErrorException& ex)
00486 {
00487
00488 Int_t prio=ex.GetPriority();
00489 if(prio==0)
00490 {
00491
00492
00493
00494 }
00495 else
00496 {
00497 Message(3,"Analysis %s ERROR: %s from event source %s:\n %s",
00498 GetName(),ex.GetErrMess(),
00499 ex.GetSourceClass(), ex.GetSourceName());
00500 if(IsErrorStopEnabled())
00501 {
00502 if(fxAnalysisSlave) fxAnalysisSlave->Stop();
00503
00504 rev=-1;
00505 }
00506 }
00507
00508 }
00509
00510 catch(TGo4DynamicListException& ex)
00511 {
00512 {
00513 TGo4LockGuard global;
00514 ex.Handle();
00515 }
00516 Message(3,"Analysis %s ERROR: %s from dynamic list entry %s:%s",
00517 GetName(),ex.GetStatusMessage(),
00518 ex.GetEntryName(), ex.GetEntryClass());
00519 if(IsErrorStopEnabled())
00520 {
00521 if(fxAnalysisSlave) fxAnalysisSlave->Stop();
00522
00523 rev=-1;
00524 }
00525
00526 }
00527
00528 catch(TGo4AnalysisStepException& ex)
00529 {
00530 TGo4LockGuard global;
00531 ex.Handle();
00532 Message(3,"Analysis %s ERROR: %s in Analysis Step %s",
00533 GetName(), ex.GetStatusMessage(), ex.GetStepName());
00534 if(IsErrorStopEnabled())
00535 {
00536 if(fxAnalysisSlave) fxAnalysisSlave->Stop();
00537
00538 rev=-1;
00539 }
00540
00541 }
00542
00543 catch(TGo4UserException& ex)
00544 {
00545
00546
00547 if(strlen(ex.GetMessage())!=0)
00548 Message(ex.GetPriority(), ex.GetMessage());
00549 if(IsErrorStopEnabled() && (ex.GetPriority() > 2)) {
00550 if(fxAnalysisSlave) fxAnalysisSlave->Stop();
00551
00552 rev=-1;
00553
00554 }
00555
00556 }
00557
00558 catch(std::exception& ex)
00559 {
00560 Message(3,"Analysis %s got standard exception %s",
00561 GetName(), ex.what());
00562 if(IsErrorStopEnabled())
00563 {
00564 if(fxAnalysisSlave) fxAnalysisSlave->Stop();
00565
00566 rev=-1;
00567 }
00568
00569 }
00570
00572 #if ROOT_VERSION_CODE > ROOT_VERSION(5,2,0)
00573 #if ROOT_VERSION_CODE < ROOT_VERSION(5,99,0)
00574
00575 if(gCINTMutex && unlockedcint) {
00576 gCINTMutex->Lock();
00577
00578 }
00579 #endif
00580 #endif
00581 return rev;
00582 }
00583
00584
00585
00586 Int_t TGo4Analysis::RunImplicitLoop(Int_t times, Bool_t showrate, Double_t process_event_interval)
00587 {
00588 GO4TRACE((11,"TGo4Analysis::RunImplicitLoop(Int_t)",__LINE__, __FILE__));
00589 Int_t cnt = 0;
00590 if (process_event_interval>1.) process_event_interval = 1.;
00591
00592 if (times < 0) times = fBatchLoopCount;
00593
00594 TGo4Ratemeter rate;
00595 TString ratefmt = TString::Format("\rCnt = %s Rate = %s Ev/s", TGo4Log::GetPrintfArg(kULong64_t),"%5.*f");
00596 Bool_t userate = showrate || (process_event_interval>0.);
00597 if (userate)
00598 rate.SetUpdateInterval(process_event_interval>0. ? process_event_interval : 1.);
00599 if (showrate) rate.Reset();
00600
00601 TTimeStamp last_update;
00602
00603 try
00604 {
00605 PreLoop();
00606 if (times>0)
00607 Message(1, "Analysis loop for %d cycles is starting...", times);
00608 else
00609 Message(1, "Analysis loop is starting...");
00610
00611 while (fxDoWorkingFlag != flagStop) {
00612
00613 if ((times>0) && (cnt>=times)) break;
00614
00615 if (userate && rate.Update((fxDoWorkingFlag == flagRunning) ? 1 : 0)) {
00616 if (process_event_interval>0.) gSystem->ProcessEvents();
00617
00618 bool need_update = false;
00619 TTimeStamp now;
00620 if ((now.AsDouble() - last_update.AsDouble()) >= 1.) {
00621 last_update = now; need_update = true;
00622 }
00623
00624 if (need_update && showrate) {
00625 int width = (rate.GetRate()>1e4) ? 0 : (rate.GetRate()<1. ? 3 : 1);
00626 printf(ratefmt.Data(), rate.GetCurrentCount(), width, rate.GetRate());
00627 fflush(stdout);
00628 }
00629 if (need_update && fSniffer) {
00630 fSniffer->RatemeterUpdate(&rate);
00631 }
00632 }
00633
00634 try
00635 {
00636 if (fxDoWorkingFlag == flagRunning) MainCycle();
00637
00638 cnt++;
00639 }
00640 catch(TGo4UserException& ex)
00641 {
00642 if(ex.GetPriority()>2)
00643 {
00644 PostLoop();
00645 throw;
00646 }
00647 else
00648 {
00649 ex.Handle();
00650 }
00651 }
00652 catch(TGo4EventEndException& ex)
00653 {
00654 Message(1,"End of event source %s: name:%s msg:%s",ex.GetSourceClass(), ex.GetSourceName(),ex.GetErrMess());
00655 PostLoop();
00656 throw;
00657 }
00658
00659 catch(TGo4EventErrorException& ex)
00660 {
00661 if(ex.GetPriority()>0)
00662 {
00663 Message(ex.GetPriority(),"%s",ex.GetErrMess());
00664 PostLoop();
00665 throw;
00666 }
00667 else
00668 {
00669
00670
00671
00672 ex.Handle();
00673 }
00674 }
00675
00676 catch(TGo4EventTimeoutException& ex)
00677 {
00678 ex.Handle();
00679 }
00680
00681 catch(...)
00682 {
00683 PostLoop();
00684 throw;
00685 }
00687 }
00688
00689 Message(1, "Analysis implicit Loop has finished after %d cycles.", cnt);
00690 PostLoop();
00691 }
00692
00693 catch(TGo4Exception& ex) {
00694 Message(1, "%s appeared in %d cycle.", ex.What(), cnt);
00695 ex.Handle();
00696 }
00697 catch(std::exception& ex) {
00698 Message(1, "standard exception %s appeared in %d cycle.", ex.what(), cnt);
00699 }
00700 catch(...) {
00701 Message(1, "!!! Unexpected exception in %d cycle !!!", cnt);
00702 }
00703
00704 if (showrate) {
00705 printf("\n"); fflush(stdout);
00706 }
00707
00709 return cnt;
00710 }
00711
00713
00714
00715
00716 Bool_t TGo4Analysis::RemoveDynamicEntry(const char * entryname, const char* listname)
00717 {
00718 GO4TRACE((11,"TGo4Analysis::RemoveDynamicEntry(const char *, const char* )",__LINE__, __FILE__));
00719 Bool_t rev=fxObjectManager->RemoveDynamicEntry(entryname);
00720 if(rev) UpdateNamesList();
00721 return rev;
00722 }
00723
00724
00726
00727
00728 void TGo4Analysis::UpdateStatus(TGo4AnalysisStatus* state)
00729 {
00730 GO4TRACE((11,"TGo4Analysis::UpdateStatus(TGo4AnalysisStatus*)",__LINE__, __FILE__));
00731 fxStepManager->UpdateStatus(state);
00732 if(state!=0) {
00733 state->SetAutoSaveInterval(fiAutoSaveInterval);
00734 state->SetAutoFileName(fxAutoFileName);
00735 state->SetAutoSaveCompression(fiAutoSaveCompression);
00736 state->SetAutoSaveOverwrite(fbAutoSaveOverwrite);
00737 state->SetAutoSaveOn(fbAutoSaveOn);
00738 state->SetConfigFileName(fxConfigFilename.Data());
00739 }
00740 }
00741
00742 void TGo4Analysis::SetStatus(TGo4AnalysisStatus * state)
00743 {
00744 GO4TRACE((11,"TGo4Analysis::SetStatus(TGo4AnalysisStatus*)",__LINE__, __FILE__));
00745 if(state!=0) {
00746
00747 CloseAnalysis();
00748 SetAutoSaveInterval(state->GetAutoSaveInterval());
00749 SetAutoSave(state->IsAutoSaveOn());
00750 SetAutoSaveFile(state->GetAutoFileName(),
00751 state->IsAutoSaveOverwrite(),
00752 state->GetAutoSaveCompression());
00753 fxStepManager->SetStatus(state);
00754 }
00755 }
00756
00757
00758 Bool_t TGo4Analysis::LoadStatus(const char* filename)
00759 {
00760 GO4TRACE((11,"TGo4Analysis::LoadStatus(const char*)",__LINE__, __FILE__));
00761
00762 Bool_t rev=kFALSE;
00763 TString fname = filename ? filename : fgcDEFAULTSTATUSFILENAME;
00764
00765
00766 if(!fname.Contains(fgcDEFAULTFILESUF)) fname.Append(fgcDEFAULTFILESUF);
00767
00768 TFile* statusfile = TFile::Open(fname.Data(), "READ");
00769 if(statusfile && statusfile->IsOpen()) {
00770 TGo4AnalysisStatus* state=
00771 dynamic_cast<TGo4AnalysisStatus*>( statusfile->Get( GetName() ) );
00772 if (state==0) {
00773 TIter iter(statusfile->GetListOfKeys());
00774 TKey* key = 0;
00775 while ((key = (TKey*)iter()) != 0) {
00776 if (strcmp(key->GetClassName(),"TGo4AnalysisStatus")==0) break;
00777 }
00778
00779 if (key!=0) state = dynamic_cast<TGo4AnalysisStatus*>( statusfile->Get( key->GetName() ) );
00780 }
00781
00782
00783 if(state) {
00784 Message(1,"Analysis %s: Found status object %s in file %s",
00785 GetName(), state->GetName(), fname.Data());
00786 SetStatus(state);
00787 fxConfigFilename = fname;
00788 Message(0,"Analysis: New analysis state is set.");
00789 rev=kTRUE;
00790 } else {
00791 Message(3,"Analysis LoadStatus: Could not find status %s in file %s",
00792 GetName(), fname.Data());
00793 rev=kFALSE;
00794 }
00795 } else {
00796 Message(3,"Analysis LoadStatus: Failed to open file %s", fname.Data());
00797 rev = kFALSE;
00798 }
00799
00800 delete statusfile;
00801
00802 return rev;
00803 }
00804
00805 Bool_t TGo4Analysis::SaveStatus(const char* filename)
00806 {
00807 GO4TRACE((11,"TGo4Analysis::SaveStatus(const char*)",__LINE__, __FILE__));
00808 Bool_t rev=kFALSE;
00809 char buffer[1024];
00810 if(filename)
00811 strncpy(buffer, filename, sizeof(buffer)-100);
00812 else
00813 strncpy(buffer,fgcDEFAULTSTATUSFILENAME, sizeof(buffer)-100);
00814 if(!strstr(buffer,fgcDEFAULTFILESUF))
00815 strcat(buffer,fgcDEFAULTFILESUF);
00816 TFile* statusfile = TFile::Open(buffer,"RECREATE");
00817 if(statusfile && statusfile->IsOpen()) {
00818 fxConfigFilename=buffer;
00819 statusfile->cd();
00820 TGo4AnalysisStatus* state= CreateStatus();
00821 if(state) {
00822 state->Write();
00823 delete state;
00824 delete statusfile;
00825 rev=kTRUE;
00826 Message(-1,"Analysis SaveStatus: Saved Analysis settings to file %s",
00827 buffer);
00828 } else {
00829 Message(3,"Analysis SaveStatus: FAILED to create status object !!!");
00830 rev=kFALSE;
00831 }
00832 } else {
00833 Message(3,"Analysis SaveStatus: Failed to open file %s ",
00834 buffer);
00835 rev=kFALSE;
00836 }
00837 return rev;
00838 }
00839
00840 TGo4AnalysisStatus* TGo4Analysis::CreateStatus()
00841 {
00842 GO4TRACE((11,"TGo4Analysis::CreateStatus()",__LINE__, __FILE__));
00843 TDirectory* filsav=gDirectory;
00844 gROOT->cd();
00845 TGo4AnalysisStatus* state= new TGo4AnalysisStatus(GetName());
00846 UpdateStatus(state);
00847 filsav->cd();
00848 return state;
00849 }
00850
00851 void TGo4Analysis::Print(Option_t*) const
00852 {
00853 TGo4Analysis* localthis=const_cast<TGo4Analysis*>(this);
00854 TGo4AnalysisStatus* state=localthis->CreateStatus();
00855 state->PrintStatus();
00856 delete state;
00857 }
00858
00859 TTree* TGo4Analysis::CreateSingleEventTree(TGo4EventElement* event)
00860 {
00861 GO4TRACE((11,"TGo4Analysis::CreateSingleEventTree(TGo4EventElement*)",__LINE__, __FILE__));
00862
00863 if(event==0) return 0;
00864 TDirectory* filsav=gDirectory;
00865 gROOT->cd();
00866 delete fxSampleEvent;
00867 fxSampleEvent=(TGo4EventElement*) event->Clone();
00868 TTree* thetree= new TTree(fxSampleEvent->GetName(), "Single Event Tree");
00869 thetree->SetDirectory(0);
00870 TBranch *topbranch=
00871 thetree->Branch("Go4EventSample", fxSampleEvent->ClassName(), &fxSampleEvent, 64000, 99);
00872 if (fxSampleEvent->InheritsFrom("TGo4CompositeEvent"))
00873 dynamic_cast<TGo4CompositeEvent*> (fxSampleEvent)->makeBranch(topbranch);
00874 thetree->Fill();
00875 filsav->cd();
00876 return thetree;
00877
00878 }
00879
00880 TTree* TGo4Analysis::CreateSingleEventTree(const char* name, Bool_t isoutput)
00881 {
00882 GO4TRACE((11,"TGo4Analysis::CreateSingleEventTree(const char*, Bool_t)",__LINE__, __FILE__));
00883
00884 TGo4EventElement* event=0;
00885 if(isoutput) event = GetOutputEvent(name);
00886 else event = GetInputEvent(name);
00887 if(event==0)
00888
00889 event=GetEventStructure(name);
00890 return CreateSingleEventTree(event);
00891 }
00892
00893 void TGo4Analysis::CloseAnalysis()
00894 {
00895 GO4TRACE((14,"TGo4Analysis::CloseAnalysis()",__LINE__, __FILE__));
00896
00897 if(fbInitIsDone) {
00898 AutoSave();
00899 fxStepManager->CloseAnalysis();
00900 fxObjectManager->CloseAnalysis();
00901 fbInitIsDone=kFALSE;
00902 }
00903 }
00904
00905 Int_t TGo4Analysis::PreLoop()
00906 {
00907 GO4TRACE((11,"TGo4Analysis:PreLoop()",__LINE__, __FILE__));
00908 TGo4LockGuard autoguard(fxAutoSaveMutex);
00909
00910 fiAutoSaveCount = 0;
00911 Int_t rev = UserPreLoop();
00912 for (Int_t num = 0; num < fxStepManager->GetNumberOfAnalysisSteps(); num++) {
00913 TGo4AnalysisStep* step = fxStepManager->GetAnalysisStepNum(num);
00914 TGo4EventProcessor* proc = step ? step->GetEventProcessor() : 0;
00915 if (proc) proc->UserPreLoop();
00916 }
00917
00918 fxAutoSaveClock->Start(kTRUE);
00919 return rev;
00920 }
00921
00922 Int_t TGo4Analysis::PostLoop()
00923 {
00924 GO4TRACE((11,"TGo4Analysis::PostLoop()",__LINE__, __FILE__));
00925 TGo4LockGuard autoguard(fxAutoSaveMutex);
00926 Int_t rev=0;
00928
00929
00930
00931
00932
00933
00935 if(fbInitIsDone) {
00936 for (Int_t num = 0; num < fxStepManager->GetNumberOfAnalysisSteps(); num++) {
00937 TGo4AnalysisStep* step = fxStepManager->GetAnalysisStepNum(num);
00938 TGo4EventProcessor* proc = step ? step->GetEventProcessor() : 0;
00939 if (proc) proc->UserPostLoop();
00940 }
00941
00942 rev = UserPostLoop();
00943 }
00944 return rev;
00945 }
00946
00947 Int_t TGo4Analysis::UserPreLoop()
00948 {
00949 GO4TRACE((11,"TGo4Analysis::UserPreLoop()",__LINE__, __FILE__));
00950
00951 Message(0,"Analysis BaseClass -- executing default User Preloop");
00952 return 0;
00953 }
00954
00955 Int_t TGo4Analysis::UserPostLoop()
00956 {
00957 GO4TRACE((11,"TGo4Analysis::UserPostLoop()",__LINE__, __FILE__));
00958
00959 Message(0,"Analysis BaseClass -- executing default User Postloop");
00960 return 0;
00961 }
00962
00963 void TGo4Analysis::SetAutoSaveFile(const char * filename, Bool_t overwrite, Int_t compression)
00964 {
00965
00966
00967 TString buffer;
00968 if(filename) buffer = filename;
00969 else buffer = fgcDEFAULTFILENAME;
00970 if(!buffer.Contains(fgcDEFAULTFILESUF))
00971 buffer.Append(fgcDEFAULTFILESUF);
00972
00973 fxAutoFileName = buffer;
00974 fbAutoSaveOverwrite = overwrite;
00975 fiAutoSaveCompression = compression;
00976 }
00977
00978 Bool_t TGo4Analysis::IsAutoSaveFileName() const
00979 {
00980 return fxAutoFileName.Length() > 0;
00981 }
00982
00983
00984 Int_t TGo4Analysis::LockAutoSave()
00985 {
00986 GO4TRACE((12,"TGo4Analysis::LockAutoSave()",__LINE__, __FILE__));
00987 Int_t rev;
00988 if(TThread::Exists()>0 && fxAutoSaveMutex)
00989 rev=fxAutoSaveMutex->Lock();
00990 else
00991 rev=-1;
00992 return rev;
00993 }
00994
00995 Int_t TGo4Analysis::UnLockAutoSave()
00996 {
00997 GO4TRACE((12,"TGo4Analysis::UnLockAutoSave()",__LINE__, __FILE__));
00998 Int_t rev(-1);
00999 if(TThread::Exists()>0 && fxAutoSaveMutex)
01000 rev = fxAutoSaveMutex->UnLock();
01001
01002 return rev;
01003 }
01004
01005 void TGo4Analysis::AutoSave()
01006 {
01007 GO4TRACE((12,"TGo4Analysis::AutoSave()",__LINE__, __FILE__));
01008
01009 if(!fbAutoSaveOn) return;
01010 TGo4LockGuard autoguard(fxAutoSaveMutex);
01011 Message(0,"Analysis -- AutoSaving....");
01012
01013 fxStepManager->AutoSave();
01014 OpenAutoSaveFile(true);
01015 fxObjectManager->SaveObjects(fxAutoFile);
01016 CloseAutoSaveFile();
01017 Message(0,"Analysis -- AutoSave done.");
01018 }
01019
01020 void TGo4Analysis::OpenAutoSaveFile(bool for_writing)
01021 {
01022 if(!fbAutoSaveOn) return;
01023 TGo4LockGuard autoguard(fxAutoSaveMutex);
01024 gROOT->cd();
01025 if (for_writing) {
01026 delete fxAutoFile;
01027 fxAutoFile = TFile::Open(fxAutoFileName.Data() ,"RECREATE");
01028 if (fxAutoFile==0)
01029 Message(3,"Fail to open AutoSave file %s", fxAutoFileName.Data());
01030 else
01031 Message(-1,"Opening AutoSave file %s with RECREATE mode",fxAutoFileName.Data());
01032 if (fxAutoFile) fxAutoFile->SetCompressionLevel(fiAutoSaveCompression);
01033 } else {
01034 if(fxAutoFile==0) {
01035 if (!gSystem->AccessPathName(fxAutoFileName.Data()))
01036 fxAutoFile = TFile::Open(fxAutoFileName.Data(), "READ");
01037 if (fxAutoFile==0)
01038 Message(3,"Fail to open AutoSave file %s", fxAutoFileName.Data());
01039 else
01040 Message(-1,"Opening AutoSave file %s with READ mode",fxAutoFileName.Data());
01041
01042 } else {
01043 Message(-1,"Reusing AutoSave file %s with READ mode",fxAutoFileName.Data());
01044 }
01045 }
01046
01047 gROOT->cd();
01048 }
01049
01050
01051 void TGo4Analysis::CloseAutoSaveFile()
01052 {
01053 if(fxAutoFile) {
01054 TGo4LockGuard autoguard(fxAutoSaveMutex);
01055 delete fxAutoFile;
01056 fxAutoFile=0;
01057 Message(-1,"AutoSave file %s was closed.",fxAutoFileName.Data());
01058 }
01059 }
01060
01061
01062 void TGo4Analysis::UpdateNamesList()
01063 {
01064 GO4TRACE((11,"TGo4Analysis::UpdateNamesList()",__LINE__, __FILE__));
01065
01066
01067
01068 delete fxObjectNames;
01069 fxObjectNames = CreateNamesList();
01070 Message(0,"Analysis BaseClass -- Nameslist updated.");
01071
01072
01073 }
01074
01075
01076 Bool_t TGo4Analysis::LoadObjects(const char* filename)
01077 {
01078 TGo4LockGuard autoguard(fxAutoSaveMutex);
01079 if(filename) fxAutoFileName = filename;
01080
01081 if(!fbAutoSaveOn) {
01082 TGo4Log::Info("Analysis LoadObjects: AUTOSAVE file is DISABLED, did NOT read objects back from file %s", fxAutoFileName.Data());
01083 return kFALSE;
01084 }
01085
01086 if (fbAutoSaveOverwrite) {
01087 TGo4Log::Info("Analysis LoadObjects: AUTOSAVE is in overwrite mode - no objects will be loaded from %s", fxAutoFileName.Data());
01088 return kTRUE;
01089 }
01090
01091 Bool_t rev(kTRUE);
01092 OpenAutoSaveFile(false);
01093 if(fxAutoFile && fxAutoFile->IsOpen()) {
01094 TGo4Log::Info("Analysis LoadObjects: Loading from autosave file %s ", fxAutoFile->GetName());
01095 rev = fxObjectManager->LoadObjects(fxAutoFile);
01096 } else {
01097 TGo4Log::Info("Analysis LoadObjects: Failed to load from file %s", fxAutoFileName.Data());
01098 rev = kFALSE;
01099 }
01100 CloseAutoSaveFile();
01101 gROOT->cd();
01102 return rev;
01103 }
01104
01105 void TGo4Analysis::Message(Int_t prio, const char* text,...)
01106 {
01107 char txtbuf[TGo4Log::fguMESLEN];
01108 va_list args;
01109 va_start(args, text);
01110 vsnprintf(txtbuf, TGo4Log::fguMESLEN, text, args);
01111 va_end(args);
01112 SendMessageToGUI(prio, kTRUE, txtbuf);
01113 }
01114
01115 void TGo4Analysis::SendMessageToGUI(Int_t level, Bool_t printout, const char* text)
01116 {
01117 if(fxAnalysisSlave) {
01118
01119 fxAnalysisSlave->SendStatusMessage(level, printout, text);
01120 } else {
01121
01122 Bool_t previousmode = TGo4Log::IsOutputEnabled();
01123 TGo4Log::OutputEnable(printout);
01124 TGo4Log::Message(level, text);
01125 TGo4Log::OutputEnable(previousmode);
01126
01127 if (fSniffer) fSniffer->StatusMessage(level, text);
01128 }
01129 }
01130
01131 void TGo4Analysis::SendObjectToGUI(TObject* ob)
01132 {
01133 if (ob==0) return;
01134
01135 if(fxAnalysisSlave==0) {
01136 Message(2,"Could not send object %s to GUI in batch mode.", ob->GetName());
01137 return;
01138 }
01139
01140 TString pathname;
01141
01142 if (ObjectManager()->FindObjectPathName(ob, pathname)) {
01143 TGo4ObjEnvelope* envelope = new TGo4ObjEnvelope(ob, ob->GetName(), pathname.Data());
01144 fxAnalysisSlave->SendObject(envelope);
01145 delete envelope;
01146 return;
01147 }
01148
01149 fxAnalysisSlave->SendObject(dynamic_cast<TNamed*>(ob));
01150 }
01151
01152 Bool_t TGo4Analysis::IsRunning()
01153 {
01154 if(fxAnalysisSlave)
01155 return fxAnalysisSlave->MainIsRunning();
01156
01157 return TGo4Analysis::fbExists;
01158 }
01159
01160 void TGo4Analysis::SetRunning(Bool_t on)
01161 {
01162 if(fxAnalysisSlave==0) return;
01163 if(on)
01164 fxAnalysisSlave->Start();
01165 else
01166 fxAnalysisSlave->Stop();
01167 }
01168
01169 Int_t TGo4Analysis::WaitForStart()
01170 {
01171 #if ROOT_VERSION_CODE > ROOT_VERSION(5,2,0)
01172 #if ROOT_VERSION_CODE < ROOT_VERSION(5,99,0)
01173
01174 Bool_t unlockedcint=kFALSE;
01175 if(gCINTMutex) {
01176 gCINTMutex->UnLock();
01177 unlockedcint=kTRUE;
01178 }
01179 #endif
01180 #endif
01181
01182 Int_t cycles=0;
01183 while(!IsRunning())
01184 {
01185
01186 gSystem->Sleep(fgiMACROSTARTPOLL);
01187 cycles++;
01188 Bool_t sysret = gSystem->ProcessEvents();
01189 if (sysret || (fxDoWorkingFlag == flagStop)) {
01190 cycles=-1;
01191 break;
01192
01193
01194
01195 }
01196 }
01197 #if ROOT_VERSION_CODE > ROOT_VERSION(5,2,0)
01198 #if ROOT_VERSION_CODE < ROOT_VERSION(5,99,0)
01199
01200 if(gCINTMutex && unlockedcint)
01201 gCINTMutex->Lock();
01202 #endif
01203 #endif
01204 return cycles;
01205 }
01206
01207 void TGo4Analysis::StartObjectServer(const char* basename, const char* passwd)
01208 {
01209 if(fxAnalysisSlave) {
01210 Message(1,"Start object server not yet enabled.");
01211
01212 } else {
01213 Message(2,"Could not start object server in batch mode.");
01214 }
01215 }
01216
01217 void TGo4Analysis::StopObjectServer()
01218 {
01219 if(fxAnalysisSlave) {
01220
01221 Message(1,"Stop object server not yet enabled.");
01222 } else {
01223 Message(2,"Could not stop object server in batch mode.");
01224 }
01225 }
01226
01227 void TGo4Analysis::ShutdownServer()
01228 {
01229
01230
01231 if(fxAnalysisSlave)
01232 {
01233 TGo4Log::Message(1,"Analysis server is initiating shutdown after ctrl-c, please wait!!\n");
01234 fxAnalysisSlave->SubmitShutdown();
01235 }
01236
01237 }
01238
01239
01240
01241 void TGo4Analysis::ShowEvent(const char* stepname, Bool_t isoutput)
01242 {
01243 TTree* sevtree=CreateSingleEventTree(stepname,isoutput);
01244 if(sevtree) {
01245 if(isoutput)
01246 Message(1,"Showing Output Event %s of step %s",sevtree->GetName(),stepname);
01247 else
01248 Message(1,"Showing Input Event %s of step %s",sevtree->GetName(),stepname);
01249 sevtree->Show(0);
01250 std::cout << std::endl;
01251 delete sevtree;
01252 }
01253 }
01254
01256
01257
01258 Bool_t TGo4Analysis::AddDynamicHistogram(const char* name,
01259 const char* histo,
01260 const char* hevx, const char* hmemx,
01261 const char* hevy, const char* hmemy,
01262 const char* hevz, const char* hmemz,
01263 const char* condition,
01264 const char* cevx, const char* cmemx,
01265 const char* cevy, const char* cmemy)
01266 {
01267 return fxObjectManager->AddDynamicHistogram(name,
01268 histo, hevx, hmemx, hevy, hmemy, hevz, hmemz,
01269 condition, cevx, cmemx, cevy, cmemy);
01270 }
01271
01272 Bool_t TGo4Analysis::AddTreeHistogram(const char* hisname, const char* treename, const char* varexp, const char* cutexp)
01273 {
01274 Bool_t rev=fxObjectManager->AddTreeHistogram(hisname,treename,varexp,cutexp);
01275 if(rev) UpdateNamesList();
01276 return rev;
01277 }
01278
01279 Bool_t TGo4Analysis::AddEventProcessor(TGo4EventProcessor * pro)
01280 {
01281 return fxObjectManager->AddEventProcessor(pro);
01282 }
01283
01284 Bool_t TGo4Analysis::AddEventSource(TGo4EventSource * source)
01285 {
01286 return fxObjectManager->AddEventSource(source);
01287 }
01288
01289 Bool_t TGo4Analysis::AddEventStore(TGo4EventStore * store)
01290 {
01291 return fxObjectManager->AddEventStore(store);
01292 }
01293
01294 Bool_t TGo4Analysis::AddEventStructure(TGo4EventElement * ev)
01295 {
01296 return fxObjectManager->AddEventStructure(ev);
01297 }
01298
01299 Bool_t TGo4Analysis::AddHistogram(TH1 * his , const char* subfolder, Bool_t replace)
01300 {
01301 return fxObjectManager->AddHistogram(his,subfolder, replace);
01302 }
01303
01304 Bool_t TGo4Analysis::AddObject(TNamed * anything, const char* subfolder, Bool_t replace)
01305 {
01306 return fxObjectManager->AddObject(anything,subfolder,replace);
01307 }
01308
01309 Bool_t TGo4Analysis::AddParameter(TGo4Parameter * par, const char* subfolder)
01310 {
01311 return fxObjectManager->AddParameter(par,subfolder);
01312 }
01313
01314 Bool_t TGo4Analysis::AddPicture(TGo4Picture * pic, const char* subfolder)
01315 {
01316 return fxObjectManager->AddPicture(pic,subfolder);
01317 }
01318
01319 Bool_t TGo4Analysis::AddCanvas(TCanvas * can, const char* subfolder)
01320 {
01321 return fxObjectManager->AddCanvas(can,subfolder);
01322 }
01323
01324 Bool_t TGo4Analysis::AddTree(TTree* tree, const char* subfolder)
01325 {
01326 if(tree) tree->ResetBit(TGo4Status::kGo4BackStoreReset);
01327 return fxObjectManager->AddTree(tree, subfolder);
01328 }
01329
01330 Bool_t TGo4Analysis::AddAnalysisCondition(TGo4Condition * con, const char* subfolder)
01331 {
01332 return fxObjectManager->AddAnalysisCondition(con,subfolder);
01333 }
01334
01335 TGo4Condition * TGo4Analysis::GetAnalysisCondition(const char * name, const char* cond_cl)
01336 {
01337 return fxObjectManager->GetAnalysisCondition(name, cond_cl);
01338 }
01339
01340 TGo4AnalysisStep* TGo4Analysis::GetAnalysisStep(const char* name)
01341 {
01342 return fxStepManager->GetAnalysisStep(name);
01343 }
01344
01345 TGo4AnalysisStep* TGo4Analysis::GetAnalysisStepNum(Int_t number)
01346 {
01347 return fxStepManager->GetAnalysisStepNum(number);
01348 }
01349
01350 Int_t TGo4Analysis::GetDynListInterval()
01351 {
01352 return fxObjectManager->GetDynListInterval();
01353 }
01354
01355 TGo4EventElement * TGo4Analysis::GetEventStructure(const char * name)
01356 {
01357 return fxObjectManager->GetEventStructure(name);
01358 }
01359
01360 TH1* TGo4Analysis::GetHistogram(const char * name)
01361 {
01362 return fxObjectManager->GetHistogram(name);
01363 }
01364
01365 TNamed * TGo4Analysis::GetObject(const char * name, const char* folder)
01366 {
01367 return fxObjectManager->GetObject(name,folder);
01368 }
01369
01370 TGo4Parameter * TGo4Analysis::GetParameter(const char * name, const char* par_class)
01371 {
01372 return fxObjectManager->GetParameter(name, par_class);
01373 }
01374
01375 TGo4Picture * TGo4Analysis::GetPicture(const char * name)
01376 {
01377 return fxObjectManager->GetPicture(name);
01378 }
01379
01380 TCanvas * TGo4Analysis::GetCanvas(const char * name)
01381 {
01382 return fxObjectManager->GetCanvas(name);
01383 }
01384
01385 TTree * TGo4Analysis::GetTree(const char * name)
01386 {
01387 return fxObjectManager->GetTree(name);
01388 }
01389
01390 TGo4AnalysisObjectNames * TGo4Analysis::CreateNamesList()
01391 {
01392 return fxObjectManager->CreateNamesList();
01393 }
01394
01395 TFolder * TGo4Analysis::GetObjectFolder()
01396 {
01397 return fxObjectManager->GetObjectFolder();
01398 }
01399
01400 TGo4ObjectStatus * TGo4Analysis::CreateObjectStatus(const char * name, const char* folder)
01401 {
01402 return fxObjectManager->CreateObjectStatus(name,folder);
01403 }
01404
01405 TGo4TreeStructure * TGo4Analysis::CreateTreeStructure(const char* treename)
01406 {
01407 return fxObjectManager->CreateTreeStructure(treename);
01408 }
01409
01410 Bool_t TGo4Analysis::RemoveEventSource(TGo4EventSource* source)
01411 {
01412 return fxObjectManager->RemoveEventSource(source);
01413 }
01414
01415 Bool_t TGo4Analysis::RemoveEventStore(TGo4EventStore * store)
01416 {
01417 return fxObjectManager->RemoveEventStore(store);
01418 }
01419
01420 Bool_t TGo4Analysis::RemoveEventStructure(TGo4EventElement * ev)
01421 {
01422 return fxObjectManager->RemoveEventStructure(ev);
01423 }
01424
01425 Bool_t TGo4Analysis::RemoveHistogram(const char * name, Bool_t del)
01426 {
01427 return fxObjectManager->RemoveHistogram(name,del);
01428 }
01429
01430 Bool_t TGo4Analysis::RemoveObject(const char * name, Bool_t del)
01431 {
01432 return fxObjectManager->RemoveObject(name,del);
01433 }
01434
01435 Bool_t TGo4Analysis::RemoveParameter(const char * name)
01436 {
01437 return fxObjectManager->RemoveParameter(name);
01438 }
01439
01440 Bool_t TGo4Analysis::RemovePicture(const char * name)
01441 {
01442 return fxObjectManager->RemovePicture(name);
01443 }
01444
01445 Bool_t TGo4Analysis::RemoveCanvas(const char * name)
01446 {
01447 return fxObjectManager->RemoveCanvas(name);
01448 }
01449
01450 Bool_t TGo4Analysis::RemoveTree(TTree * tree, const char* stepname)
01451 {
01452 return fxObjectManager->RemoveTree(tree, stepname);
01453 }
01454
01455 Bool_t TGo4Analysis::RemoveAnalysisCondition(const char* name)
01456 {
01457 return fxObjectManager->RemoveAnalysisCondition(name);
01458 }
01459
01460 Bool_t TGo4Analysis::RemoveEventProcessor(TGo4EventProcessor * pro)
01461 {
01462 return fxObjectManager->RemoveEventProcessor(pro);
01463 }
01464
01465 Bool_t TGo4Analysis::DeleteObjects(const char * name)
01466 {
01467 return fxObjectManager->DeleteObjects(name);
01468 }
01469
01470 Bool_t TGo4Analysis::ClearObjects(const char * name)
01471 {
01472 return fxObjectManager->ClearObjects(name);
01473 }
01474
01475 Bool_t TGo4Analysis::ProtectObjects(const char * name, const Option_t* flags)
01476 {
01477 return fxObjectManager->ProtectObjects(name, flags);
01478 }
01479
01480 Bool_t TGo4Analysis::ResetBackStores(Bool_t clearflag)
01481 {
01482 return fxObjectManager->ResetBackStores(clearflag);
01483 }
01484
01485 Bool_t TGo4Analysis::SetAnalysisCondition(const char * name, TGo4Condition* con, Bool_t counter)
01486 {
01487 return fxObjectManager->SetAnalysisCondition(name, con, counter);
01488 }
01489
01490 Bool_t TGo4Analysis::SetParameter(const char* name, TGo4Parameter* par)
01491 {
01492 return fxObjectManager->SetParameter(name, par);
01493 }
01494
01495 Bool_t TGo4Analysis::SetParameterStatus(const char* name, TGo4ParameterStatus* par)
01496 {
01497 return fxObjectManager->SetParameterStatus(name, par);
01498 }
01499
01500 Bool_t TGo4Analysis::SetPicture(const char * name, TGo4Picture * pic)
01501 {
01502 return fxObjectManager->SetPicture(name, pic);
01503 }
01504
01505 void TGo4Analysis::SetDynListInterval(Int_t val)
01506 {
01507 fxObjectManager->SetDynListInterval(val);
01508 }
01509
01510 void TGo4Analysis::PrintConditions(const char* expression)
01511 {
01512 fxObjectManager->PrintConditions(expression);
01513 }
01514
01515 void TGo4Analysis::PrintHistograms(const char* expression)
01516 {
01517 fxObjectManager->PrintHistograms(expression);
01518 }
01519
01520 void TGo4Analysis::PrintParameters(const char* expression)
01521 {
01522 fxObjectManager->PrintParameters(expression);
01523 }
01524
01525 void TGo4Analysis::PrintDynamicList()
01526 {
01527 fxObjectManager->PrintDynamicList();
01528 }
01529
01530 TObject* TGo4Analysis::NextMatchingObject(const char* expr, const char* folder, Bool_t reset)
01531 {
01532 return fxObjectManager->NextMatchingObject(expr,folder,reset);
01533 }
01534
01535
01537
01538
01539 TGo4EventElement* TGo4Analysis::GetInputEvent(Int_t stepindex)
01540 {
01541 return fxStepManager->GetInputEvent(stepindex);
01542 }
01543
01544 TGo4EventElement* TGo4Analysis::GetInputEvent(const char* stepname)
01545 {
01546 return fxStepManager->GetInputEvent(stepname);
01547 }
01548
01549 TGo4EventElement* TGo4Analysis::GetOutputEvent()
01550 {
01551 return fxStepManager->GetOutputEvent();
01552 }
01553
01554 TGo4EventElement* TGo4Analysis::GetOutputEvent(Int_t stepindex)
01555 {
01556 return fxStepManager->GetOutputEvent(stepindex);
01557 }
01558
01559 TGo4EventElement* TGo4Analysis::GetOutputEvent(const char* stepname)
01560 {
01561 return fxStepManager->GetOutputEvent(stepname);
01562 }
01563
01564 Bool_t TGo4Analysis::NewStepProcessor(const char* name, TGo4EventProcessorParameter * par)
01565 {
01566 return fxStepManager->NewStepProcessor(name,par);
01567 }
01568
01569 Bool_t TGo4Analysis::NewStepSource(const char* name, TGo4EventSourceParameter * par)
01570 {
01571 return fxStepManager->NewStepSource(name,par);
01572 }
01573
01574 Bool_t TGo4Analysis::NewStepStore(const char* name, TGo4EventStoreParameter* par)
01575 {
01576 return fxStepManager->NewStepStore(name,par);
01577 }
01578
01579 Bool_t TGo4Analysis::AddDynamicEntry(TGo4DynamicEntry* entry)
01580 {
01581 return fxObjectManager->AddDynamicEntry(entry);
01582 }
01583
01584 void TGo4Analysis::SetStepChecking(Bool_t on)
01585 {
01586 fxStepManager->SetStepChecking(on);
01587 }
01588
01589 Bool_t TGo4Analysis::SetFirstStep(const char* name)
01590 {
01591 return fxStepManager->SetFirstStep(name);
01592 }
01593
01594 Bool_t TGo4Analysis::SetLastStep(const char * name)
01595 {
01596 return fxStepManager->SetLastStep(name);
01597 }
01598
01599 Bool_t TGo4Analysis::SetStepStorage(const char * name, Bool_t on)
01600 {
01601 return fxStepManager->SetStepStorage(name,on);
01602 }
01603
01604 Int_t TGo4Analysis::IsErrorStopEnabled()
01605 {
01606 return fxStepManager->IsErrorStopEnabled();
01607 }
01608
01609 Bool_t TGo4Analysis::AddAnalysisStep(TGo4AnalysisStep* next)
01610 {
01611 return fxStepManager->AddAnalysisStep(next);
01612 }
01613
01614 Int_t TGo4Analysis::ProcessAnalysisSteps()
01615 {
01616 return fxStepManager->ProcessAnalysisSteps();
01617 }
01618
01619 void TGo4Analysis::SetOutputEvent(TGo4EventElement * event)
01620 {
01621 fxStepManager->SetOutputEvent(event);
01622 }
01623
01624 Int_t TGo4Analysis::StoreParameter(const char * name, TGo4Parameter* par)
01625 {
01626 return fxStepManager->Store(name, par);
01627 }
01628
01629 Int_t TGo4Analysis::StoreCondition(const char * name, TGo4Condition* con)
01630 {
01631 return fxStepManager->Store(name, con);
01632 }
01633
01634 Int_t TGo4Analysis::StoreFitter(const char * name, TGo4Fitter* fit)
01635 {
01636 return fxStepManager->Store(name, fit);
01637 }
01638
01639 Int_t TGo4Analysis::StoreFolder(const char * name, TFolder* folder)
01640 {
01641 return fxStepManager->Store(name, folder);
01642 }
01643
01644 Int_t TGo4Analysis::StoreFolder(const char * stepname, const char * foldername)
01645 {
01646 TFolder* myfolder = fxObjectManager->FindSubFolder(GetObjectFolder(), foldername, kFALSE);
01647 return myfolder ? fxStepManager->Store(stepname, myfolder) : 2;
01648 }
01649
01650 void TGo4Analysis::DefineServerPasswords(const char* admin, const char* controller, const char* observer)
01651 {
01652 fServerAdminPass = admin ? admin : "";
01653 fServerCtrlPass = controller ? controller : "";
01654 fServerObserverPass = observer ? observer : "";
01655 }
01656
01657 void TGo4Analysis::SetObserverPassword(const char* passwd)
01658 {
01659 fServerObserverPass = passwd ? passwd : "";
01660 }
01661
01662 void TGo4Analysis::SetControllerPassword(const char* passwd)
01663 {
01664 fServerCtrlPass = passwd ? passwd : "";
01665 }
01666
01667 void TGo4Analysis::SetAdministratorPassword(const char* passwd)
01668 {
01669 fServerAdminPass = passwd ? passwd : "";
01670 }
01671
01672 TH1* TGo4Analysis::MakeTH1(char type, const char* fullname, const char* title,
01673 Int_t nbinsx, Double_t xlow, Double_t xup,
01674 const char* xtitle, const char* ytitle)
01675 {
01676 fbObjMade = kFALSE;
01677 TString foldername, histoname;
01678
01679 if ((fullname==0) || (strlen(fullname)==0)) {
01680 TGo4Log::Error("Histogram name not specified, can be a hard error");
01681 return 0;
01682 }
01683 const char* separ = strrchr(fullname, '/');
01684 if (separ!=0) {
01685 histoname = separ + 1;
01686 foldername.Append(fullname, separ - fullname);
01687 } else
01688 histoname = fullname;
01689
01690 int itype = 0;
01691 const char* sclass = "TH1I";
01692 switch (type) {
01693 case 'I': case 'i': itype = 0; sclass = "TH1I"; break;
01694 case 'F': case 'f': itype = 1; sclass = "TH1F"; break;
01695 case 'D': case 'd': itype = 2; sclass = "TH1D"; break;
01696 case 'S': case 's': itype = 3; sclass = "TH1S"; break;
01697 case 'C': case 'c': itype = 4; sclass = "TH1C"; break;
01698 default: TGo4Log::Error("There is no histogram type: %c, use I instead", type); break;
01699 }
01700
01701 TH1* oldh = GetHistogram(fullname);
01702
01703 if (oldh!=0) {
01704 if (oldh->InheritsFrom(sclass) && fbMakeWithAutosave) {
01705 if (title) oldh->SetTitle(title);
01706 if (xtitle) oldh->GetXaxis()->SetTitle(xtitle);
01707 if (ytitle) oldh->GetYaxis()->SetTitle(ytitle);
01708 return oldh;
01709 }
01710
01711 if (oldh->InheritsFrom(sclass))
01712 TGo4Log::Info("Rebuild existing histogram %s, reuse content", fullname);
01713 else
01714 TGo4Log::Info("There is histogram %s with type %s other than specified %s, rebuild and reuse content",
01715 fullname, oldh->ClassName(), sclass);
01716
01717
01718 RemoveHistogram(fullname, kFALSE);
01719
01720
01721 oldh->SetName("___");
01722 }
01723
01724 TH1* newh = 0;
01725
01726 switch (itype) {
01727 case 0: newh = new TH1I(histoname, title, nbinsx, xlow, xup); break;
01728 case 1: newh = new TH1F(histoname, title, nbinsx, xlow, xup); break;
01729 case 2: newh = new TH1D(histoname, title, nbinsx, xlow, xup); break;
01730 case 3: newh = new TH1S(histoname, title, nbinsx, xlow, xup); break;
01731 case 4: newh = new TH1C(histoname, title, nbinsx, xlow, xup); break;
01732 }
01733
01734 newh->SetTitle(title);
01735
01736 if (xtitle) newh->GetXaxis()->SetTitle(xtitle);
01737 if (ytitle) newh->GetYaxis()->SetTitle(ytitle);
01738
01739 if (oldh) {
01740 if ((oldh->GetDimension()==1) && fbMakeWithAutosave) newh->Add(oldh);
01741 delete oldh; oldh = 0;
01742 }
01743
01744 if (foldername.Length() > 0)
01745 AddHistogram(newh, foldername.Data());
01746 else
01747 AddHistogram(newh);
01748
01749 fbObjMade = kTRUE;
01750
01751 return newh;
01752 }
01753
01754 TH2* TGo4Analysis::MakeTH2(char type, const char* fullname, const char* title,
01755 Int_t nbinsx, Double_t xlow, Double_t xup,
01756 Int_t nbinsy, Double_t ylow, Double_t yup,
01757 const char* xtitle, const char* ytitle, const char* ztitle)
01758 {
01759 fbObjMade = kFALSE;
01760 TString foldername, histoname;
01761
01762 if ((fullname==0) || (strlen(fullname)==0)) {
01763 TGo4Log::Error("Histogram name not specified, can be a hard error");
01764 return 0;
01765 }
01766 const char* separ = strrchr(fullname, '/');
01767 if (separ!=0) {
01768 histoname = separ + 1;
01769 foldername.Append(fullname, separ - fullname);
01770 } else
01771 histoname = fullname;
01772
01773 int itype = 0;
01774 const char* sclass = "TH2I";
01775 switch (type) {
01776 case 'I': case 'i': itype = 0; sclass = "TH2I"; break;
01777 case 'F': case 'f': itype = 1; sclass = "TH2F"; break;
01778 case 'D': case 'd': itype = 2; sclass = "TH2D"; break;
01779 case 'S': case 's': itype = 3; sclass = "TH2S"; break;
01780 case 'C': case 'c': itype = 4; sclass = "TH2C"; break;
01781 default: TGo4Log::Error("There is no histogram type: %c, use I instead", type); break;
01782 }
01783
01784 TH1* oldh = GetHistogram(fullname);
01785
01786 if (oldh!=0) {
01787 if (oldh->InheritsFrom(sclass) && fbMakeWithAutosave) {
01788 if (title) oldh->SetTitle(title);
01789 if (xtitle) oldh->GetXaxis()->SetTitle(xtitle);
01790 if (ytitle) oldh->GetYaxis()->SetTitle(ytitle);
01791 return (TH2*) oldh;
01792 }
01793 if (oldh->InheritsFrom(sclass))
01794 TGo4Log::Info("Rebuild existing histogram %s, reuse content", fullname);
01795 else
01796 TGo4Log::Info("There is histogram %s with type %s other than specified %s, rebuild and reuse content",
01797 fullname, oldh->ClassName(), sclass);
01798
01799
01800 RemoveHistogram(fullname, kFALSE);
01801
01802
01803 oldh->SetName("___");
01804 }
01805
01806 TH2* newh = 0;
01807
01808 switch (itype) {
01809 case 0: newh = new TH2I(histoname, title, nbinsx, xlow, xup, nbinsy, ylow, yup); break;
01810 case 1: newh = new TH2F(histoname, title, nbinsx, xlow, xup, nbinsy, ylow, yup); break;
01811 case 2: newh = new TH2D(histoname, title, nbinsx, xlow, xup, nbinsy, ylow, yup); break;
01812 case 3: newh = new TH2S(histoname, title, nbinsx, xlow, xup, nbinsy, ylow, yup); break;
01813 case 4: newh = new TH2C(histoname, title, nbinsx, xlow, xup, nbinsy, ylow, yup); break;
01814 }
01815
01816 newh->SetTitle(title);
01817
01818 if (xtitle) newh->GetXaxis()->SetTitle(xtitle);
01819 if (ytitle) newh->GetYaxis()->SetTitle(ytitle);
01820 if (ztitle) newh->GetZaxis()->SetTitle(ztitle);
01821
01822 if (oldh) {
01823 if ((oldh->GetDimension()==2) && fbMakeWithAutosave) newh->Add(oldh);
01824 delete oldh;
01825 oldh = 0;
01826 }
01827
01828 if (foldername.Length() > 0)
01829 AddHistogram(newh, foldername.Data());
01830 else
01831 AddHistogram(newh);
01832
01833 fbObjMade = kTRUE;
01834
01835 return newh;
01836 }
01837
01838 TGo4WinCond* TGo4Analysis::MakeWinCond(const char* fullname,
01839 Double_t xmin, Double_t xmax,
01840 const char* HistoName)
01841 {
01842 fbObjMade = kFALSE;
01843 TString foldername, condname;
01844
01845 if ((fullname==0) || (strlen(fullname)==0)) {
01846 TGo4Log::Error("Condition name not specified, can be a hard error");
01847 return 0;
01848 }
01849 const char* separ = strrchr(fullname, '/');
01850 if (separ!=0) {
01851 condname = separ + 1;
01852 foldername.Append(fullname, separ - fullname);
01853 } else
01854 condname = fullname;
01855
01856 TGo4Condition* cond = GetAnalysisCondition(fullname);
01857
01858 if (cond!=0) {
01859 if (cond->InheritsFrom(TGo4WinCond::Class()) && fbMakeWithAutosave) {
01860 cond->ResetCounts();
01861 return (TGo4WinCond*) cond;
01862 }
01863 RemoveAnalysisCondition(fullname);
01864 }
01865
01866 TGo4WinCond* wcond = new TGo4WinCond(condname);
01867 wcond->SetValues(xmin, xmax);
01868 wcond->SetHistogram(HistoName);
01869 wcond->Enable();
01870
01871 if (foldername.Length() > 0)
01872 AddAnalysisCondition(wcond, foldername.Data());
01873 else
01874 AddAnalysisCondition(wcond);
01875
01876 fbObjMade = kTRUE;
01877
01878 return wcond;
01879 }
01880
01881 TGo4WinCond* TGo4Analysis::MakeWinCond(const char* fullname,
01882 Double_t xmin, Double_t xmax,
01883 Double_t ymin, Double_t ymax,
01884 const char* HistoName)
01885 {
01886 fbObjMade = kFALSE;
01887 TString foldername, condname;
01888
01889 if ((fullname==0) || (strlen(fullname)==0)) {
01890 TGo4Log::Error("Condition name not specified, can be a hard error");
01891 return 0;
01892 }
01893 const char* separ = strrchr(fullname, '/');
01894 if (separ!=0) {
01895 condname = separ + 1;
01896 foldername.Append(fullname, separ - fullname);
01897 } else
01898 condname = fullname;
01899
01900 TGo4Condition* cond = GetAnalysisCondition(fullname);
01901
01902 if (cond!=0) {
01903 if (cond->InheritsFrom(TGo4WinCond::Class()) && fbMakeWithAutosave) {
01904 cond->ResetCounts();
01905 return (TGo4WinCond*) cond;
01906 }
01907 RemoveAnalysisCondition(fullname);
01908 }
01909
01910 TGo4WinCond* wcond = new TGo4WinCond(condname);
01911 wcond->SetValues(xmin, xmax, ymin, ymax);
01912 wcond->SetHistogram(HistoName);
01913 wcond->Enable();
01914
01915 if (foldername.Length() > 0)
01916 AddAnalysisCondition(wcond, foldername.Data());
01917 else
01918 AddAnalysisCondition(wcond);
01919
01920 fbObjMade = kTRUE;
01921
01922 return wcond;
01923 }
01924
01925 TGo4PolyCond* TGo4Analysis::MakePolyCond(const char* fullname,
01926 Int_t npoints,
01927 Double_t (*points) [2],
01928 const char* HistoName)
01929 {
01930 fbObjMade = kFALSE;
01931 TString foldername, condname;
01932
01933 if ((fullname==0) || (strlen(fullname)==0)) {
01934 TGo4Log::Error("Condition name not specified, can be a hard error");
01935 return 0;
01936 }
01937 const char* separ = strrchr(fullname, '/');
01938 if (separ!=0) {
01939 condname = separ + 1;
01940 foldername.Append(fullname, separ - fullname);
01941 } else
01942 condname = fullname;
01943
01944 TGo4Condition* cond = GetAnalysisCondition(fullname);
01945
01946 if (cond!=0) {
01947 if (cond->InheritsFrom(TGo4PolyCond::Class()) && fbMakeWithAutosave) {
01948 cond->ResetCounts();
01949 return (TGo4PolyCond*) cond;
01950 }
01951 RemoveAnalysisCondition(fullname);
01952 }
01953
01954 TArrayD fullx(npoints+1), fully(npoints+1);
01955
01956 for (int i=0;i<npoints;i++) {
01957 fullx[i] = points[i][0];
01958 fully[i] = points[i][1];
01959 }
01960
01961
01962 if ((fullx[0]!=fullx[npoints-1]) || (fully[0]!=fully[npoints-1])) {
01963 fullx[npoints] = fullx[0];
01964 fully[npoints] = fully[0];
01965 npoints++;
01966 }
01967
01968 TCutG mycat("initialcut", npoints, fullx.GetArray(), fully.GetArray());
01969
01970 TGo4PolyCond* pcond = new TGo4PolyCond(condname);
01971 pcond->SetValues(&mycat);
01972 pcond->Enable();
01973
01974 pcond->SetHistogram(HistoName);
01975
01976 if (foldername.Length() > 0)
01977 AddAnalysisCondition(pcond, foldername.Data());
01978 else
01979 AddAnalysisCondition(pcond);
01980
01981 fbObjMade = kTRUE;
01982
01983 return pcond;
01984 }
01985
01986 TGo4Parameter* TGo4Analysis::MakeParameter(const char* fullname,
01987 const char* classname,
01988 const char* newcmd)
01989 {
01990 fbObjMade = kFALSE;
01991 TString foldername, paramname;
01992
01993 if ((fullname==0) || (strlen(fullname)==0)) {
01994 TGo4Log::Error("Parameter name not specified, can be a hard error");
01995 return 0;
01996 }
01997 const char* separ = strrchr(fullname, '/');
01998 if (separ!=0) {
01999 paramname = separ + 1;
02000 foldername.Append(fullname, separ - fullname);
02001 } else
02002 paramname = fullname;
02003
02004 TGo4Parameter* param = GetParameter(fullname);
02005
02006 if (param!=0) {
02007 if (!param->InheritsFrom(classname)) {
02008 TGo4Log::Info("There is parameter %s with type %s other than specified %s, rebuild",
02009 fullname, param->ClassName(), classname);
02010 RemoveParameter(fullname);
02011 param = 0;
02012 }
02013 }
02014
02015 if (param==0) {
02016 paramname = TString("\"") + paramname + TString("\"");
02017
02018 TString cmd;
02019 if ((newcmd!=0) && (strstr(newcmd,"new ")==newcmd))
02020 cmd = TString::Format(newcmd, paramname.Data());
02021 else
02022 cmd = TString::Format("new %s(%s)", classname, paramname.Data());
02023
02024 Long_t res = gROOT->ProcessLineFast(cmd.Data());
02025
02026 if (res==0) {
02027 TGo4Log::Error("Cannot create parameter of class %s", classname);
02028 return 0;
02029 }
02030
02031 param = (TGo4Parameter*) res;
02032
02033 if (foldername.Length() > 0)
02034 AddParameter(param, foldername.Data());
02035 else
02036 AddParameter(param);
02037
02038 fbObjMade = kTRUE;
02039 }
02040
02041 if ((newcmd!=0) && (strstr(newcmd,"set_")==newcmd)) {
02042
02043
02044 ExecuteScript(newcmd);
02045 }
02046
02047 return param;
02048 }
02049
02050 Long_t TGo4Analysis::ExecuteScript(const char* macro_name)
02051 {
02052 if ((macro_name==0) || (strlen(macro_name)==0)) return -1;
02053
02054
02055 TString file_name(macro_name);
02056 Ssiz_t pos = file_name.First('(');
02057 if (pos>0) file_name.Resize(pos);
02058 pos = file_name.First('+');
02059 if (pos>0) file_name.Resize(pos);
02060 while ((file_name.Length()>0) && (file_name[file_name.Length()-1] == ' '))
02061 file_name.Resize(file_name.Length()-1);
02062 while ((file_name.Length()>0) && (file_name[0]==' '))
02063 file_name.Remove(0, 1);
02064
02065 if (gSystem->AccessPathName(file_name.Data())) {
02066 TGo4Log::Error("ROOT script %s nof found", file_name.Data());
02067 return -1;
02068 }
02069
02070 TGo4Log::Info("Executing ROOT script %s", macro_name);
02071 return gROOT->ProcessLineSync(Form(".x %s", macro_name));
02072 }
02073
02074
02075 void TGo4Analysis::StopAnalysis()
02076 {
02077 if (fxAnalysisSlave)
02078
02079 fxAnalysisSlave->Stop();
02080 else
02081 fxDoWorkingFlag = flagPause;
02082 }
02083
02084
02085 void TGo4Analysis::StartAnalysis()
02086 {
02087 if (fxAnalysisSlave)
02088 fxAnalysisSlave->Start();
02089
02090 else
02091 fxDoWorkingFlag = flagRunning;
02092 }
02093
02094
02095
02096
02097 #ifdef WIN32
02098
02099 #include "windows.h"
02100
02101
02102 namespace {
02103
02104 static BOOL Go4ConsoleSigHandler(DWORD sig)
02105 {
02106
02107
02108 switch (sig) {
02109 case CTRL_C_EVENT:
02110 if (TGo4Analysis::Exists())
02111 TGo4Analysis::Instance()->ProcessCrtlCSignal();
02112 return TRUE;
02113 case CTRL_BREAK_EVENT:
02114 case CTRL_LOGOFF_EVENT:
02115 case CTRL_SHUTDOWN_EVENT:
02116 case CTRL_CLOSE_EVENT:
02117 default:
02118 printf(" non CTRL-C signal - ignore\n");
02119 return TRUE;
02120 }
02121 }
02122
02123 void InstallGo4CtrlCHandler(bool on)
02124 {
02125 ::SetConsoleCtrlHandler((PHANDLER_ROUTINE)Go4ConsoleSigHandler, on);
02126 }
02127
02128 }
02129
02130
02131
02132 #endif