Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisManager.h
index 990f65b..538e8fa 100644 (file)
@@ -27,8 +27,10 @@ class TClass;
 class TTree;
 class TFile;
 class TStopwatch;
+class TMap;
 class AliAnalysisSelector;
 class AliAnalysisDataContainer;
+class AliAnalysisFileDescriptor;
 class AliAnalysisTask;
 class AliVEventHandler;
 class AliVEventPool;
@@ -61,8 +63,11 @@ enum EAliAnalysisFlags {
    kSaveCanvases     = BIT(17),
    kExternalLoop     = BIT(18),
    kSkipTerminate    = BIT(19),
-   kUseProgressBar   = BIT(20)
-};   
+   kUseProgressBar   = BIT(20),
+   kTrueNotify       = BIT(21),
+   kTasksInitialized = BIT(22),
+   kCollectThroughput= BIT(23)
+};
 
    AliAnalysisManager(const char *name = "mgr", const char *title="");
    virtual            ~AliAnalysisManager();
@@ -71,8 +76,9 @@ enum EAliAnalysisFlags {
    AliAnalysisManager& operator=(const AliAnalysisManager& other);
    
    // Event loop control
+   Bool_t              EventLoop(Long64_t nevents);
    virtual Int_t       GetEntry(Long64_t entry, Int_t getall = 0);
-   virtual Bool_t      Init(TTree *tree);   
+   virtual Bool_t      Init(TTree *tree);
    virtual Bool_t      Notify();
    virtual Bool_t      ProcessCut(Long64_t entry) {return Process(entry);}
    virtual Bool_t      Process(Long64_t entry);
@@ -89,10 +95,12 @@ enum EAliAnalysisFlags {
 
    // Getters/Setters
    static AliAnalysisManager *GetAnalysisManager() {return fgAnalysisManager;}
+   static Int_t        LoadMacro(const char *filename, Int_t *error = 0, Bool_t check = kFALSE);
    EAliAnalysisExecMode 
                        GetAnalysisType() const    {return fMode;}
    void                GetAnalysisTypeString(TString &type) const;                    
    Bool_t              GetAutoBranchLoading() const {return fAutoBranchHandling;} 
+   Long64_t            GetCacheSize() const       {return fCacheSize;}
    static const char  *GetCommonFileName()        {return fgCommonFileName.Data();}
    AliAnalysisDataContainer *
                        GetCommonInputContainer() const  {return fCommonInput;}
@@ -101,14 +109,17 @@ enum EAliAnalysisFlags {
    TObjArray          *GetContainers() const      {return fContainers;}
    Long64_t            GetCurrentEntry() const    {return fCurrentEntry;}
    UInt_t              GetDebugLevel() const      {return fDebug;}
+   Bool_t              GetAsyncReading() const {return fAsyncReading;}
    TString             GetExtraFiles() const      {return fExtraFiles;}
    AliVEventPool*      GetEventPool()  const      {return fEventPool;}
    Bool_t              GetFileFromWrapper(const char *filename, const TList *source);
+   const char         *GetFileInfoLog() const     {return fFileInfoLog.Data();}
    static Int_t        GetRunFromAlienPath(const char *path);
    AliAnalysisGrid*    GetGridHandler()           {return fGridHandler;}
    TObjArray          *GetInputs() const          {return fInputs;}
    AliVEventHandler*   GetInputEventHandler() const   {return fInputEventHandler;}
    AliVEventHandler*   GetMCtruthEventHandler() const {return fMCtruthEventHandler;}
+   Int_t               GetNsysInfo() const        {return fNSysInfo;}
    AliVEventHandler*   GetOutputEventHandler() const  {return fOutputEventHandler;}
    TObjArray          *GetOutputs() const         {return fOutputs;}
    TObjArray          *GetParamOutputs() const    {return fParamCont;}
@@ -118,23 +129,36 @@ enum EAliAnalysisFlags {
    TObjArray          *GetTopTasks() const        {return fTopTasks;}
    TTree              *GetTree() const            {return fTree;}
    TObjArray          *GetZombieTasks() const     {return fZombies;}
+   static const char  *GetGlobalStr(const char *key, Bool_t &valid);
+   static Int_t        GetGlobalInt(const char *key, Bool_t &valid);
+   static Double_t     GetGlobalDbl(const char *key, Bool_t &valid);
+   TMap               *GetGlobals()               {return fGlobals;}
+   static Bool_t       IsMacroLoaded(const char filename);
+   Bool_t              IsMCLoop() const           {return fMCLoop;}
    static Bool_t       IsPipe(std::ostream &out);
    Bool_t              IsProofMode() const        {return (fMode==kProofAnalysis)?kTRUE:kFALSE;}
    Bool_t              IsRemote() const           {return fIsRemote;}
+   Bool_t              IsCollectThroughput()      {return TObject::TestBit(kCollectThroughput);}
    Bool_t              IsUsingDataSet() const     {return TObject::TestBit(kUseDataSet);}
    void                LoadBranch(const char *n)  { if(fAutoBranchHandling) return; DoLoadBranch(n); }
+   void                RunLocalInit();
    void                SetAnalysisType(EAliAnalysisExecMode mode) {fMode = mode;}
    void                SetAutoBranchLoading(Bool_t b) { fAutoBranchHandling = b; }
    void                SetCurrentEntry(Long64_t entry)            {fCurrentEntry = entry;}
+   void                SetCacheSize(Long64_t size)                {fCacheSize = size;}
    void                SetCollectSysInfoEach(Int_t nevents=0)     {fNSysInfo = nevents;}
+   void                SetCollectThroughput(Bool_t flag)          {Changed(); TObject::SetBit(kCollectThroughput,flag);}
    static void         SetCommonFileName(const char *name)        {fgCommonFileName = name;}
    void                SetDebugLevel(UInt_t level);
-   void                SetDisableBranches(Bool_t disable=kTRUE)   {TObject::SetBit(kDisableBranches,disable);}
-   void                SetExternalLoop(Bool_t flag)               {TObject::SetBit(kExternalLoop,flag);}
-   void                SetEventPool(AliVEventPool* const epool)   {fEventPool = epool;}
-   void                SetGridHandler(AliAnalysisGrid * const handler) {fGridHandler = handler;}
+   void                SetDisableBranches(Bool_t disable=kTRUE)   {Changed(); TObject::SetBit(kDisableBranches,disable);}
+   void                SetAsyncReading(Bool_t flag=kTRUE)    {fAsyncReading = flag;}
+   void                SetExternalLoop(Bool_t flag)               {Changed(); TObject::SetBit(kExternalLoop,flag);}
+   void                SetMCLoop(Bool_t flag=kTRUE)               {fMCLoop = flag;}
+   void                SetEventPool(AliVEventPool* const epool)   {Changed(); fEventPool = epool;}
+   void                SetFileInfoLog(const char *name) {TObject::SetBit(kCollectThroughput,kTRUE); fFileInfoLog = name;}
+   void                SetGridHandler(AliAnalysisGrid * const handler) {Changed(); fGridHandler = handler;}
    void                SetInputEventHandler(AliVEventHandler* const handler);
-   void                SetMCtruthEventHandler(AliVEventHandler* const handler) {fMCtruthEventHandler = handler;}
+   void                SetMCtruthEventHandler(AliVEventHandler* const handler) {Changed(); fMCtruthEventHandler = handler;}
    void                SetNSysInfo(Long64_t nevents)              {fNSysInfo = nevents;}
    void                SetOutputEventHandler(AliVEventHandler* const handler);
    void                SetRunFromPath(Int_t run)                  {fRunFromPath = run;}
@@ -143,6 +167,10 @@ enum EAliAnalysisFlags {
    void                SetSkipTerminate(Bool_t flag)              {TObject::SetBit(kSkipTerminate,flag);}
    void                SetUseProgressBar(Bool_t flag, Int_t freq=1);
    void                SetSpecialOutputLocation(const char *loc)  {fSpecialOutputLocation = loc;}
+   static void         SetGlobalStr(const char *key, const char *value);
+   static void         SetGlobalInt(const char *key, Int_t value);
+   static void         SetGlobalDbl(const char *key, Double_t value);
+   
 
    // Container handling
    AliAnalysisDataContainer *CreateContainer(const char *name, TClass *datatype, 
@@ -152,6 +180,7 @@ enum EAliAnalysisFlags {
    // Including tasks and getting them
    void                 AddTask(AliAnalysisTask *task);
    AliAnalysisTask     *GetTask(const char *name) const;
+   Int_t                GetTaskIndex(const AliAnalysisTask *task) const;
    
    // Connecting data containers to task inputs/outputs
    Bool_t               ConnectInput(AliAnalysisTask *task, Int_t islot,
@@ -165,12 +194,16 @@ enum EAliAnalysisFlags {
    void                 AddBranches(const char *branches);
    void                 AddStatisticsTask(UInt_t offlineMask=0);
    void                 CheckBranches(Bool_t load=kFALSE);
+   Bool_t               CheckTasks() const;
    void                 CountEvent(Int_t ninput, Int_t nprocessed, Int_t nfailed, Int_t naccepted);
    Bool_t               InitAnalysis();
    Bool_t               IsInitialized() const {return fInitOK;}
+   Bool_t               IsTrainInitialized() const {return TObject::TestBit(kTasksInitialized);}
    Bool_t               IsExternalLoop() const {return TObject::TestBit(kExternalLoop);}
    Bool_t               IsEventLoop() const {return TObject::TestBit(kEventLoop);}
    Bool_t               IsSkipTerminate() const {return TObject::TestBit(kSkipTerminate);}
+   Bool_t               MustClean() const {return fMustClean;}
+   void                 SetMustClean(Bool_t flag=kTRUE) {fMustClean = flag;}
    void                 ResetAnalysis();
    void                 ExecAnalysis(Option_t *option="");
    void                 PrintStatus(Option_t *option="all") const;
@@ -184,9 +217,21 @@ enum EAliAnalysisFlags {
    void                 WriteStatisticsMsg(Int_t nevents);
    Int_t                GetNcalls() const {return fNcalls;}
    Bool_t               ValidateOutputFiles() const;
+   
+   static const char*   GetOADBPath();
 
+   void                 ApplyDebugOptions();
+   void                 AddClassDebug(const char *className, Int_t debugLevel);
+   
+   // Security
+   Bool_t               IsLocked() const {return fLocked;}
+   void                 Lock();
+   void                 UnLock();
+   void                 Changed();
 protected:
+   void                 CreateReadCache();
    void                 ImportWrappers(TList *source);
+   void                 InputFileFromTree(TTree * const tree, TString &fname);
    void                 SetEventLoop(Bool_t flag=kTRUE) {TObject::SetBit(kEventLoop,flag);}
    void                 DoLoadBranch(const char *name);
 
@@ -200,7 +245,10 @@ private:
    Long64_t                fNSysInfo;            // Event frequency for collecting system information
    EAliAnalysisExecMode    fMode;                // Execution mode
    Bool_t                  fInitOK;              // Initialisation done
+   Bool_t                  fMustClean;           // Flag to let ROOT do cleanup
    Bool_t                  fIsRemote;            //! Flag is set for remote analysis
+   Bool_t                  fLocked;              //! Lock for the manager and handlers
+   Bool_t                  fMCLoop;              // External MC generator loop
    UInt_t                  fDebug;               // Debug level
    TString                 fSpecialOutputLocation; // URL/path where the special outputs will be copied
    TObjArray              *fTasks;               // List of analysis tasks
@@ -210,22 +258,36 @@ private:
    TObjArray              *fInputs;              // List of containers with input data
    TObjArray              *fOutputs;             // List of containers with results
    TObjArray              *fParamCont;           // List of containers with results
+   TObjArray              *fDebugOptions;        // List of debug options
+   TObjArray              *fFileDescriptors;     //! List of file descriptors
+   AliAnalysisFileDescriptor *fCurrentDescriptor; //! Current file descriptor
    AliAnalysisDataContainer *fCommonInput;       // Common input container
    AliAnalysisDataContainer *fCommonOutput;      // Common output container
    AliAnalysisSelector    *fSelector;            //! Current selector
    AliAnalysisGrid        *fGridHandler;         //! Grid handler plugin
    TString                 fExtraFiles;          // List of extra files to be merged
+   TString                 fFileInfoLog;         // File name for fileinfo logs
    Bool_t                  fAutoBranchHandling;  // def=kTRUE, turn off if you use LoadBranch
+   Bool_t                  fAsyncReading;        // Enable async reading
    THashTable              fTable;               // keep branch ptrs in case of manual branch loading
    Int_t                   fRunFromPath;         // Run number retrieved from path to input data
    Int_t                   fNcalls;              // Total number of calls (events) of ExecAnalysis
    Long64_t                fMaxEntries;          // Maximum number of entries
+   Long64_t                fCacheSize;           // Cache size in bytes
    static Int_t            fPBUpdateFreq;        // Progress bar update freq.
    TString                 fStatisticsMsg;       // Statistics user message
    TString                 fRequestedBranches;   // Requested branch names
    AliAnalysisStatistics  *fStatistics;          // Statistics info about input events
+   TMap                   *fGlobals;             // Map with global variables
+   TStopwatch             *fIOTimer;             //! Timer for I/O + deserialization
+   TStopwatch             *fCPUTimer;            //! Timer for useful processing
+   TStopwatch             *fInitTimer;           //! Timer for initialization
+   Double_t                fIOTime;              //! Cumulated time in IO
+   Double_t                fCPUTime;             //! Cumulated time in Exec
+   Double_t                fInitTime;            //! Cumulated time in initialization
    static TString          fgCommonFileName;     //! Common output file name (not streamed)
+   static TString          fgMacroNames;         //! Loaded macro names
    static AliAnalysisManager *fgAnalysisManager; //! static pointer to object instance
-   ClassDef(AliAnalysisManager,13)  // Analysis manager class
+   ClassDef(AliAnalysisManager,19)  // Analysis manager class
 };   
 #endif