# TTask+ ## class 继承TNamed Base class for recursive execution of tasks. TTask is a base class that can be used to build a complex tree of Tasks. Each TTask derived class may contain other TTasks that can be executed recursively, such that a complex program can be dynamically built and executed by invoking the services of the top level Task or one of its subtasks. Use the TTask::Add function to add a subtask to an existing TTask. To execute a TTask, one calls the ExecuteTask function. ExecuteTask will call recursively: - the TTask::Exec function of the derived class - TTask::ExecuteTasks to execute for each task the list of its subtasks. If the top level task (see example below) is added to the list of Root browsable objects, the tree of tasks can be visualized by the Root browser. The browser can be used to start a task, set break points at the beginning of a task or when the task has completed. At a breakpoint, data structures generated by the execution up this point may be inspected asynchronously and then the execution can be resumed by selecting the "Continue" function of a task. A Task may be active or inactive (controlled by TTask::SetActive). When a task is not active, its sub tasks are not executed. A TTask tree may be made persistent, saving the status of all the tasks. ```cpp TTask(); TTask(const char* name, const char *title); virtual ~TTask(); TTask(const TTask &task); TTask& operator=(const TTask& tt); virtual void Abort(); // *MENU* virtual void Add(TTask *task) {fTasks->Add(task);} virtual void Browse(TBrowser *b); virtual void CleanTasks(); virtual void Clear(Option_t *option=""); virtual void Continue(); // *MENU* virtual void Exec(Option_t *option); virtual void ExecuteTask(Option_t *option="0"); // *MENU* virtual void ExecuteTasks(Option_t *option); Int_t GetBreakin() const { return fBreakin; } Int_t GetBreakout() const { return fBreakout; } Bool_t IsActive() const { return fActive; } Bool_t IsFolder() const { return kTRUE; } virtual void ls(Option_t *option="*") const; // *MENU* void SetActive(Bool_t active=kTRUE) { fActive = active; } // *TOGGLE* void SetBreakin(Int_t breakin=1) { fBreakin = breakin; } // *TOGGLE* void SetBreakout(Int_t breakout=1) { fBreakout = breakout; } // *TOGGLE* TList *GetListOfTasks() const { return fTasks; } ``` ## code ```cpp //The Root browser's picture below has been generated by executing the following script: { TTask *aliroot = new TTask("aliroot","ALICE reconstruction main task"); TTask *geominit = new TTask("geomInit","Initialize ALICE geometry"); TTask *matinit = new TTask("matInit","Initialize ALICE materials"); TTask *physinit = new TTask("physInit","Initialize Physics processes"); TTask *tracker = new TTask("tracker","Track reconstruction manager"); TTask *tpcrec = new TTask("tpcrec","TPC reconstruction"); TTask *itsrec = new TTask("itsrec","ITS reconstruction"); TTask *muonrec = new TTask("muonRec","Muon Reconstruction"); TTask *phosrec = new TTask("phosRec","Phos Reconstruction"); TTask *richrec = new TTask("richRec","Rich Reconstruction"); TTask *trdrec = new TTask("trdRec","TRD Reconstruction"); TTask *globrec = new TTask("globRec","Global Track Reconstruction"); TTask *pstats = new TTask("printStats","Print Run Statistics"); TTask *run = new TTask("run","Process one run"); TTask *event = new TTask("event","Process one event"); aliroot->Add(geominit); aliroot->Add(matinit); aliroot->Add(physinit); aliroot->Add(run); run->Add(event); event->Add(tracker); event->Add(muonrec); event->Add(phosrec); event->Add(richrec); event->Add(trdrec); event->Add(globrec); tracker->Add(tpcrec); tracker->Add(itsrec); run->Add(pstats); gROOT->GetListOfBrowsables()->Add(aliroot,"aliroot"); new TBrowser; } ``` ## example