ROOT logo
#ifndef ALIRUNLoader_H
#define ALIRUNLoader_H

//___________________________________________________________________
/////////////////////////////////////////////////////////////////////
//                                                                 //
//  class AliRunLoader                                             //
//                                                                 //
//  This class aims to be the only one interface for manging data  //
//  It stores Loaders for all modules which knows the filenames    //
//  of the data files to be stored.                                //
//  It aims to substitude AliRun in automatic managing of data     //
//  positioning thus there won't be necessity of loading gAlice    //
//  from file in order to get fast access to the data              //
//                                                                 //
//  Logical place to put the specific Loader to the given          //
//  detector is detector  itself (i.e ITSLoader in ITS).           //
//  But, to load detector object one need to load gAlice, and      //
//  by the way all other detectors with their geometrieces and     //
//  so on. So, if one need to open TPC clusters there is no        //
//  principal nedd to read everything.                             //
//                                                                 //
/////////////////////////////////////////////////////////////////////

class TFile;
class TString;
class TFolder;
class TObjArray;
class TTree;
class TParticle;

class AliRun;
class AliLoader;
class AliDetector;
class AliHeader;
class AliStack;
class AliCDBEntry;
class AliCentralTrigger;

#include <TNamed.h>

#include "AliConfig.h"
#include "AliDataLoader.h"

class AliRunLoader: public TNamed
{
  public:
    
    AliRunLoader();
    AliRunLoader(const char* topfoldername);
    AliRunLoader(TFolder* topfolder);
    
    virtual ~AliRunLoader();
    
    static AliRunLoader* Open(const char* filename = "galice.root",
                              const char* eventfoldername = AliConfig::GetDefaultEventFolderName(),
	          Option_t* option = "READ");

    Int_t       GetEventNumber() const {return fCurrentEvent;}

    Int_t       GetEvent(Int_t evno);//sets the event number and reloads data in folders properly
    Int_t       GetNextEvent(){return GetEvent(fCurrentEvent+1);}//gets next event 
    Int_t       SetEventNumber(Int_t evno); //cleans folders and sets the root dirs in files (do not reload data)
    Int_t       SetNextEvent(){return SetEventNumber(fCurrentEvent+1);}
    
    Int_t       GetNumberOfEvents();
    
    AliCDBEntry* GetCDBEntry(const char* name) const;

    void        MakeTree(Option_t *option);
    void        MakeHeader();
    void        MakeTrigger();
    void        MakeStack();
    
    Int_t       LoadgAlice();
    Int_t       LoadHeader();
    Int_t       LoadKinematics(Option_t* option = "READ");
    Int_t       LoadTrigger(Option_t* option = "READ");
    Int_t       LoadTrackRefs(Option_t* option = "READ");
    
    void        UnloadHeader();
    void        UnloadTrigger();
    void        UnloadKinematics();
    void        UnloadgAlice();
    void        UnloadTrackRefs();
    
    void        SetKineFileName(const TString& fname){fKineDataLoader->SetFileName(fname);}
    void        SetTrackRefsFileName(const TString& fname){fTrackRefsDataLoader->SetFileName(fname);}
    
    TTree*      TreeE() const; //returns the tree from folder; shortcut method
    TTree*      TreeCT() const; //returns the tree from folder; shortcut method
    AliHeader*  GetHeader() const;
    AliCentralTrigger*  GetTrigger() const;
    
    AliStack*   Stack() const {return fStack;}
    
    TTree*      TreeK() const; //returns the tree from folder; shortcut method
    TTree*      TreeTR() const; //returns the tree from folder; shortcut method    
    
    AliRun*     GetAliRun()const;
    Int_t       GetRunNumber() const {return fRun;}
    void        SetRunNumber(Int_t run) {fRun=run;}
        
    Int_t       WriteHeader(Option_t* opt="");
    Int_t       WriteTrigger(Option_t* opt="");
    Int_t       WriteAliRun(Option_t* opt="");
    Int_t       WriteKinematics(Option_t* opt="");
    Int_t       WriteTrackRefs(Option_t* opt="");
    Int_t       WriteRunLoader(Option_t* opt="");
    
    Int_t       WriteHits(Option_t* opt=""); 
    Int_t       WriteSDigits(Option_t* opt="");
    Int_t       WriteDigits(Option_t* opt="");
    Int_t       WriteRecPoints(Option_t* opt="");
    Int_t       WriteTracks(Option_t* opt="");
    
    Int_t       LoadHits(Option_t* detectors = "all",Option_t* opt = "READ");
    Int_t       LoadSDigits(Option_t* detectors = "all",Option_t* opt = "READ");
    Int_t       LoadDigits(Option_t* detectors = "all",Option_t* opt = "READ");
    Int_t       LoadRecPoints(Option_t* detectors = "all",Option_t* opt = "READ");
    Int_t       LoadTracks(Option_t* detectors = "all",Option_t* opt = "READ");
    Int_t       LoadRecParticles(Option_t* detectors = "all",Option_t* opt = "READ");
    
    void        UnloadHits(Option_t* detectors = "all");
    void        UnloadSDigits(Option_t* detectors = "all");
    void        UnloadDigits(Option_t* detectors = "all");
    void        UnloadRecPoints(Option_t* detectors = "all");
    void        UnloadTracks(Option_t* detectors = "all");
    void        UnloadRecParticles(Option_t* detectors = "all");
    void        UnloadAll(Option_t* detectors = "all");    
    
    void        AddLoader(AliLoader* loader);
    void        AddLoader(AliDetector* det);
    AliLoader*  GetLoader(const char* detname) const;
    AliLoader*  GetLoader(AliDetector* det) const;
    Int_t       SetEventFolderName(const TString& name = AliConfig::GetDefaultEventFolderName());//sets top folder name for this run; of alread
    void        CleanFolders();//removes all abjects from folder structure
    void        CleanDetectors();
    void        CleanKinematics(){Clean(fgkKineContainerName);}
    void        CleanTrackRefs(){Clean(fgkTrackRefsContainerName);}
    
    void        RemoveEventFolder(); //remove folder structure from top folder 
    void        SetCompressionLevel(Int_t cl);
    void        SetKineComprLevel(Int_t cl);
    void        SetTrackRefsComprLevel(Int_t cl);

    TFolder*    GetEventFolder() const {return fEventFolder;}
    void        CdGAFile();

    void        MakeTrackRefsContainer();
    void        SetDirName(TString& dirname);
    Int_t       GetFileOffset() const;
    void        SetNumberOfEventsPerFile(Int_t nevpf){fNEventsPerFile = nevpf;}
    void        SetNumberOfEventsPerRun(Int_t nevpr) {fNEventsPerRun = nevpr;}
    Int_t       GetNumberOfEventsPerRun()            {return fNEventsPerRun;}
    void        SetDigitsFileNameSuffix(const TString& suffix);//adds the suffix before ".root", 
                                                               //e.g. TPC.Digits.root -> TPC.DigitsMerged.root
                                                               //made on Jiri Chudoba demand
    TString     GetFileName() const;//returns name of galice file
    const TObjArray* GetArrayOfLoaders() const {return fLoaders;}
    void Cd(){fgRunLoader = this;}
    void Synchronize();
    
    AliLoader*    GetDetectorLoader(const char* detname);
    TTree*        GetTreeH(const char* detname, Bool_t maketree);
    TTree*        GetTreeS(const char* detname, Bool_t maketree);
    TTree*        GetTreeD(const char* detname, Bool_t maketree);
    TTree*        GetTreeR(const char* detname, Bool_t maketree);
    TTree*        GetTreeT(const char* detname, Bool_t maketree);
    TTree*        GetTreeP(const char* detname, Bool_t maketree);

  /******************************************/
  /*****   Public S T A T I C Stuff   *******/
  /******************************************/
    static AliRunLoader* GetRunLoader(const char* eventfoldername);
    static AliRunLoader* Instance(){return fgRunLoader;}
    static AliLoader*    GetDetectorLoader(const char* detname, const char* eventfoldername);
    static TTree*        GetTreeH(const char* detname, Bool_t maketree, const char* eventfoldername);
    static TTree*        GetTreeS(const char* detname, Bool_t maketree, const char* eventfoldername);
    static TTree*        GetTreeD(const char* detname, Bool_t maketree, const char* eventfoldername);
    static TTree*        GetTreeR(const char* detname, Bool_t maketree, const char* eventfoldername);
    static TTree*        GetTreeT(const char* detname, Bool_t maketree, const char* eventfoldername);
    static TTree*        GetTreeP(const char* detname, Bool_t maketree, const char* eventfoldername);

    static TString GetRunLoaderName () {return fgkRunLoaderName;}
    static TString GetHeaderContainerName () {return fgkHeaderContainerName;}
    static TString GetTriggerContainerName () {return fgkTriggerContainerName;}
    static TString GetKineContainerName () {return fgkKineContainerName;}
    static TString GetTrackRefsContainerName () {return fgkTrackRefsContainerName;}
    static TString GetHeaderBranchName () {return fgkHeaderBranchName;}
    static TString GetTriggerBranchName () {return fgkTriggerBranchName;}
    static TString GetKineBranchName () {return fgkKineBranchName;}
    static TString GetTriggerFileName() { return fgkDefaultTriggerFileName; }
    static TString GetGAliceName () {return fgkGAliceName;}
     
protected:
    void               SetGAliceFile(TFile* gafile);//sets the pointer to gAlice file
    Int_t              OpenKineFile(Option_t* opt);
    Int_t              OpenTrackRefsFile(Option_t* opt);

    Int_t              OpenDataFile(const TString& filename,TFile*& file,TDirectory*& dir,Option_t* opt,Int_t cl);
    void               SetUnixDir(const TString& udirname);
    const TString      SetFileOffset(const TString& fname);//adds the proper number before .root
    void               SetDetectorAddresses();

    TObjArray         *fLoaders;          //  List of Detectors
    TFolder           *fEventFolder;      //!top folder for this run
    
    Int_t              fRun;               //! Current run number
    Int_t              fCurrentEvent;//!Number of current event
    
    TFile             *fGAFile;//!  pointer to main file with AliRun and Run Loader -> galice.root 
    AliHeader         *fHeader;//!  pointer to header
    AliStack          *fStack; //!  pointer to stack
    AliCentralTrigger *fCTrigger; //! pointer to CEntral Trigger Processor
    
    AliDataLoader     *fKineDataLoader;// kinematics data loader
    AliDataLoader     *fTrackRefsDataLoader;//track reference data loader
    
    Int_t              fNEventsPerFile;  //defines number of events stored per one file
    Int_t              fNEventsPerRun;   //defines number of event per run
    TString            fUnixDirName;     //! name of unix path to directory that contains event
    static const TString   fgkDefaultKineFileName;//default file name with kinamatics
    static const TString   fgkDefaultTrackRefsFileName;//default file name with kinamatics
    static const TString   fgkDefaultTriggerFileName;//default file name with trigger

        
  private:
    AliRunLoader(const AliRunLoader &r);      //Not implemented
    AliRunLoader & operator = (const AliRunLoader &); //Not implemented 
    void  GetListOfDetectors(const char * namelist,TObjArray& pointerarray) const;
    void  CleanHeader(){Clean(fgkHeaderContainerName);}
    void  CleanTrigger(){Clean(fgkTriggerContainerName);}
    void  Clean(const TString& name);
    Int_t SetEvent();
   
    static AliRunLoader*   fgRunLoader; //pointer to the AliRunLoader instance

    static const TString   fgkRunLoaderName;          //default name of the run loader
    static const TString   fgkHeaderContainerName;    //default name of the kinematics container (TREE) name - TreeE
    static const TString   fgkTriggerContainerName;   //default name of the trigger container (TREE) name - TreeCT
    static const TString   fgkKineContainerName;      //default name of the kinematics container (TREE) name - TreeK
    static const TString   fgkTrackRefsContainerName; //default name of the track references container (TREE) name - TreeTR
    static const TString   fgkHeaderBranchName;       //default name of the branch containing the header
    static const TString   fgkTriggerBranchName;      //default name of the branch containing the trigger
    static const TString   fgkKineBranchName;         //default name of the branch with kinematics
    static const TString   fgkGAliceName;             //default name for gAlice file    
    
    ClassDef(AliRunLoader,3)
};

#endif
 AliRunLoader.h:1
 AliRunLoader.h:2
 AliRunLoader.h:3
 AliRunLoader.h:4
 AliRunLoader.h:5
 AliRunLoader.h:6
 AliRunLoader.h:7
 AliRunLoader.h:8
 AliRunLoader.h:9
 AliRunLoader.h:10
 AliRunLoader.h:11
 AliRunLoader.h:12
 AliRunLoader.h:13
 AliRunLoader.h:14
 AliRunLoader.h:15
 AliRunLoader.h:16
 AliRunLoader.h:17
 AliRunLoader.h:18
 AliRunLoader.h:19
 AliRunLoader.h:20
 AliRunLoader.h:21
 AliRunLoader.h:22
 AliRunLoader.h:23
 AliRunLoader.h:24
 AliRunLoader.h:25
 AliRunLoader.h:26
 AliRunLoader.h:27
 AliRunLoader.h:28
 AliRunLoader.h:29
 AliRunLoader.h:30
 AliRunLoader.h:31
 AliRunLoader.h:32
 AliRunLoader.h:33
 AliRunLoader.h:34
 AliRunLoader.h:35
 AliRunLoader.h:36
 AliRunLoader.h:37
 AliRunLoader.h:38
 AliRunLoader.h:39
 AliRunLoader.h:40
 AliRunLoader.h:41
 AliRunLoader.h:42
 AliRunLoader.h:43
 AliRunLoader.h:44
 AliRunLoader.h:45
 AliRunLoader.h:46
 AliRunLoader.h:47
 AliRunLoader.h:48
 AliRunLoader.h:49
 AliRunLoader.h:50
 AliRunLoader.h:51
 AliRunLoader.h:52
 AliRunLoader.h:53
 AliRunLoader.h:54
 AliRunLoader.h:55
 AliRunLoader.h:56
 AliRunLoader.h:57
 AliRunLoader.h:58
 AliRunLoader.h:59
 AliRunLoader.h:60
 AliRunLoader.h:61
 AliRunLoader.h:62
 AliRunLoader.h:63
 AliRunLoader.h:64
 AliRunLoader.h:65
 AliRunLoader.h:66
 AliRunLoader.h:67
 AliRunLoader.h:68
 AliRunLoader.h:69
 AliRunLoader.h:70
 AliRunLoader.h:71
 AliRunLoader.h:72
 AliRunLoader.h:73
 AliRunLoader.h:74
 AliRunLoader.h:75
 AliRunLoader.h:76
 AliRunLoader.h:77
 AliRunLoader.h:78
 AliRunLoader.h:79
 AliRunLoader.h:80
 AliRunLoader.h:81
 AliRunLoader.h:82
 AliRunLoader.h:83
 AliRunLoader.h:84
 AliRunLoader.h:85
 AliRunLoader.h:86
 AliRunLoader.h:87
 AliRunLoader.h:88
 AliRunLoader.h:89
 AliRunLoader.h:90
 AliRunLoader.h:91
 AliRunLoader.h:92
 AliRunLoader.h:93
 AliRunLoader.h:94
 AliRunLoader.h:95
 AliRunLoader.h:96
 AliRunLoader.h:97
 AliRunLoader.h:98
 AliRunLoader.h:99
 AliRunLoader.h:100
 AliRunLoader.h:101
 AliRunLoader.h:102
 AliRunLoader.h:103
 AliRunLoader.h:104
 AliRunLoader.h:105
 AliRunLoader.h:106
 AliRunLoader.h:107
 AliRunLoader.h:108
 AliRunLoader.h:109
 AliRunLoader.h:110
 AliRunLoader.h:111
 AliRunLoader.h:112
 AliRunLoader.h:113
 AliRunLoader.h:114
 AliRunLoader.h:115
 AliRunLoader.h:116
 AliRunLoader.h:117
 AliRunLoader.h:118
 AliRunLoader.h:119
 AliRunLoader.h:120
 AliRunLoader.h:121
 AliRunLoader.h:122
 AliRunLoader.h:123
 AliRunLoader.h:124
 AliRunLoader.h:125
 AliRunLoader.h:126
 AliRunLoader.h:127
 AliRunLoader.h:128
 AliRunLoader.h:129
 AliRunLoader.h:130
 AliRunLoader.h:131
 AliRunLoader.h:132
 AliRunLoader.h:133
 AliRunLoader.h:134
 AliRunLoader.h:135
 AliRunLoader.h:136
 AliRunLoader.h:137
 AliRunLoader.h:138
 AliRunLoader.h:139
 AliRunLoader.h:140
 AliRunLoader.h:141
 AliRunLoader.h:142
 AliRunLoader.h:143
 AliRunLoader.h:144
 AliRunLoader.h:145
 AliRunLoader.h:146
 AliRunLoader.h:147
 AliRunLoader.h:148
 AliRunLoader.h:149
 AliRunLoader.h:150
 AliRunLoader.h:151
 AliRunLoader.h:152
 AliRunLoader.h:153
 AliRunLoader.h:154
 AliRunLoader.h:155
 AliRunLoader.h:156
 AliRunLoader.h:157
 AliRunLoader.h:158
 AliRunLoader.h:159
 AliRunLoader.h:160
 AliRunLoader.h:161
 AliRunLoader.h:162
 AliRunLoader.h:163
 AliRunLoader.h:164
 AliRunLoader.h:165
 AliRunLoader.h:166
 AliRunLoader.h:167
 AliRunLoader.h:168
 AliRunLoader.h:169
 AliRunLoader.h:170
 AliRunLoader.h:171
 AliRunLoader.h:172
 AliRunLoader.h:173
 AliRunLoader.h:174
 AliRunLoader.h:175
 AliRunLoader.h:176
 AliRunLoader.h:177
 AliRunLoader.h:178
 AliRunLoader.h:179
 AliRunLoader.h:180
 AliRunLoader.h:181
 AliRunLoader.h:182
 AliRunLoader.h:183
 AliRunLoader.h:184
 AliRunLoader.h:185
 AliRunLoader.h:186
 AliRunLoader.h:187
 AliRunLoader.h:188
 AliRunLoader.h:189
 AliRunLoader.h:190
 AliRunLoader.h:191
 AliRunLoader.h:192
 AliRunLoader.h:193
 AliRunLoader.h:194
 AliRunLoader.h:195
 AliRunLoader.h:196
 AliRunLoader.h:197
 AliRunLoader.h:198
 AliRunLoader.h:199
 AliRunLoader.h:200
 AliRunLoader.h:201
 AliRunLoader.h:202
 AliRunLoader.h:203
 AliRunLoader.h:204
 AliRunLoader.h:205
 AliRunLoader.h:206
 AliRunLoader.h:207
 AliRunLoader.h:208
 AliRunLoader.h:209
 AliRunLoader.h:210
 AliRunLoader.h:211
 AliRunLoader.h:212
 AliRunLoader.h:213
 AliRunLoader.h:214
 AliRunLoader.h:215
 AliRunLoader.h:216
 AliRunLoader.h:217
 AliRunLoader.h:218
 AliRunLoader.h:219
 AliRunLoader.h:220
 AliRunLoader.h:221
 AliRunLoader.h:222
 AliRunLoader.h:223
 AliRunLoader.h:224
 AliRunLoader.h:225
 AliRunLoader.h:226
 AliRunLoader.h:227
 AliRunLoader.h:228
 AliRunLoader.h:229
 AliRunLoader.h:230
 AliRunLoader.h:231
 AliRunLoader.h:232
 AliRunLoader.h:233
 AliRunLoader.h:234
 AliRunLoader.h:235
 AliRunLoader.h:236
 AliRunLoader.h:237
 AliRunLoader.h:238
 AliRunLoader.h:239
 AliRunLoader.h:240
 AliRunLoader.h:241
 AliRunLoader.h:242
 AliRunLoader.h:243
 AliRunLoader.h:244
 AliRunLoader.h:245
 AliRunLoader.h:246
 AliRunLoader.h:247
 AliRunLoader.h:248
 AliRunLoader.h:249
 AliRunLoader.h:250
 AliRunLoader.h:251
 AliRunLoader.h:252