# Presentation: 198603

## AliRoot I/O and Folder

**Alice Offline****-****Week**** 10-15 V 2002**
- Piotr Krzysztof Skowroński
- June 11, 2002

## Goal

- All data types goes to the separate file.
- Each event is stored in separate root-directory within root file
- One tree per event for each data type – no event number embedded in the tree name
- Data exchange through folders.

- P. K. Skowroński   Alice Offline Week

- 11 May 2002

## RunLoader

**Tree**

- galice.root

**Tree****E**

- P. K. Skowroński   Alice Offline Week

- 11 May 2002

## Idea of Loaders

- Loader is an object responsible for openning/closing files
- Manages files and directory (OS as well as ROOT) names
- Posting data
- from file to folder – reading
- and vice versa - writing
- Plus some shortcut methods for accessing data from folders
- e.g instead of calling dynamic_cast<TTree*>(fEventFolder->FindObject(fgkHeaderContainerName));each time, one can useloader->TreeH();

- P. K. Skowroński   Alice Offline Week

- 11 May 2002

## Two types of loaders

- Run Loader (AliRunLoader)
- Manages all central data
- AliRun - gAlice
- Header – TreeE
- Kinematics - TreeK
- Track References - TreeTR
- Run Loader itself
- Detector Loader (AliLoader)
- Manages all data related to each detector
- Hits – TreeH
- Summable Digids – TreeS
- Digits – TreeD
- Reconstructed Points – TreeR
- Tracks – TreeT

- P. K. Skowroński   Alice Offline Week

- 11 May 2002

## AliLoader

- AliLoader implements all standard functionality However if any detector needs other behaviour of loader than standard – it should create detector specific loader and overload proper methods
- The same applies if extensions are needed
- See example of AliPHOSLoader

- P. K. Skowroński   Alice Offline Week

- 11 May 2002

## AliRunLoader

- Decouples all I/O management from AliRun
- It stays itself in folder as well
- Is written to galice.root as an object
- Manages event reloading (as an only one object in aliroot)
- Is an owner of AliStack and AliHeader
- Is responsible for reloading events

- P. K. Skowroński   Alice Offline Week

- 11 May 2002

## Architecture

- AliRunLoader is a central I/O manager
- It is created in Config.C and set to gAlice object
- AliRunLoader has a list of AliLoaders
- Each detector registers its loader during MC initialization
- Detector itself stores the pointer to its loader
- Faster data access
- If detector is read from file, it gets pointer to its loader automatically
- AliDetector is not „owner” of loader!

- P. K. Skowroński   Alice Offline Week

- 11 May 2002

## Usage

- Each session should be started from loading RunLoader itself**static** AliRunLoader* **AliRunLoader::****Open**(**const char*** filename = "galice.root",    **const char*** eventfoldername= AliConfig::fgkDefaultEventFolderName,   Option_t* option = "READ");For exampleAliRunLoader *rl = AliRunLoader::Open("galice.root","MyFolder","READ");**if** (rl == 0x0) {   cerr<<"Can not open session for file galice.root";   **return**;
-      }

- P. K. Skowroński   Alice Offline Week

- 11 May 2002

## AliRunLoader::Open

-  This method tries
- to open file in mode specified by option
- Find the run loader object in file
- If file option is „new”, „create” or „recreate” it creates new AliRunObject instead
- Calls AliConfig::BuildEventFolder to create folder structure for event
- Puts AliRunLoader in folder and returns pointer to it
- In case of error returns **NULL**

- P. K. Skowroński   Alice Offline Week

- 11 May 2002

## Usage cont. (AliRunLoader) 

- In order to load data
**LoadgAlice** – loads AliRun
**LoadHeader** – Loads TreeE, creates AliHeader, sets address in tree and gets header for current event
**LoadKinematics** – Opens kine file, posts TreeK for current event to folder. If header loaded calls AliStack::GetEvent which connects Tree.
**LoadTrackRefs** – Opens file with track references and puts them in folder

- P. K. Skowroński   Alice Offline Week

- 11 May 2002

## Usage cont. (AliRunLoader)

- To write data, call
- WriteKinematics
- WriteHeader
- WriteTrackRefs
- Tu unload data
- UnloadKinematics
- UnloadHeader
- UnloadTrackRefs
- UnloadgAlice

- P. K. Skowroński   Alice Offline Week

- 11 May 2002

## Usage cont. (AliLoader)

- To **load** detector specific data call following methods
**LoadHits** – loads hits for given detector
**LoadSDigits** – loads summable digits
**LoadDigits** –
**LoadRecPoints** –
**LoadTracks** –
- All methods above takes **Option_t** as a parameter, which is passed to TFile::Open

- P. K. Skowroński   Alice Offline Week

- 11 May 2002

## Usage cont. (AliLoader)

- To **write** detector specific data call following methods
**WriteHits** – writes hits for given detector
**Write****SDigits** – writes summable digits
**Write****Digits** –
**Write****RecPoints** –
**Write****Tracks** –
- They take option, which can be „OVERWRITE” to force overwriting

- P. K. Skowroński   Alice Offline Week

- 11 May 2002

## Usage cont.

- To unload call **Unload*****DataType ***e.g.
-  UnloadHits
- To make new container (tree) call **Make*****DataType*****Container**
- e.g.
**AliLoader::MakeHitsContainer**
**AliRunLoader::MakeKineContainer**
- Old style MakeTree(Option_t*) is supported as well
**AliRunLoader::MakeTree(****”K”****) – ***makes TreeK*
**AliRunLoader::MakeTree(****”H”****) – ***makes TreeH for all loaders in the list*
**AliLoader::MakeTree(****”D”****) – ***makes TreeD for only one detector*
**However it does not support option „TR” since it will be recognized as Track Tree and Recostruction Tree**

- P. K. Skowroński   Alice Offline Week

- 11 May 2002

## Usage cont.

- To get access to data (trees) one can use shortcut methods like
**AliLoader::TreeH()**
**AliLoader::TreeS()**
**AliRunLoader::TreeK()**
**AliRunLoader::TreeE()**

- P. K. Skowroński   Alice Offline Week

- 11 May 2002

## Usage cont. (AliRunLoader)

- To get loader for specific detector use
**AliLoader* GetLoader(****const char***** name)**
**AliLoader* GetLoader(AliDetector* name****)**
- Getting event: AliRunLoader::GetEvent(Int_t)
- Reloads **all loaded** data, for example**AliRunLoader *rl =****	****	****AliRunLoader::Open(****"galice.root"****,****"****MyFolder****"****,****"****READ****"****);****rl->GetEvent(0);*****//(1) – redundant: default is event 0*****rl->LoadKinematics(****"****READ****"****);*****//(2)-loads kinematics*****AliLoader* tpcloader = rl->GetLoader(****"TPCLoader"****);*****//(3)*****tpcloader->LoadDigits(****"****R****ECREATE"****);*****//(4)-loads Digits for TPC*****rl->GetEvent(1);*****//(5)***
- At the moment of loading data (2),(3),(4) they are loaded for event 0 (current event). GetEvent in line (5) causes that all loaded data are reloaded for event 1.

- P. K. Skowroński   Alice Offline Week

- 11 May 2002

## Usage cont. (AliRunLoader)

- To load detector data you can use method**AliRunLoader::Load*****DataType*****  (Option_t* detectors=****"****all****"****,****   Option_t* opt=****"****READ****"****)****eg:**
**AliRunLoader::LoadHits() – calls LoadHits(****"****READ****"****) for all loaders**
**AliRunLoader::LoadHits(****"****TPC ITS PHOS****"****) calls LoadHits(****"****READ****"****) for TPC, ITS and PHOS laoders**
**AliRunLoader::LoadHits(****"****all****"****,****"****update****"****) calls LoadHits(****"****update****"****) for all loaders**

- P. K. Skowroński   Alice Offline Week

- 11 May 2002

## Status

- New I/O version is merged with v3-08-02
- It compiles for all detectors but EMCAL
- TPC even works up to tracking
- Take it as a practical example
- display.C works as well
- I already wrote some documentation   up to now rather poor however..._[http://alisoft.cern.ch/people/skowron/codedoc/split](http://alisoft.cern.ch/people/skowron/codedoc/split)_

- P. K. Skowroński   Alice Offline Week

- 11 May 2002

## Substitutions

**AliRun::GetEvent(Int_t)**
**AliRun::Stack()**
**AliRun::GetHeader()**
**AliRun::TreeK()**
**AliRun::TreeE()**
**AliRun::TreeH()**
**AliRun::TreeS()**
**AliRun::TreeD()**
**AliRun::TreeR()**

**AliRunLoader::GetEvent(Int_t)**
**AliRunLoader::Stack()**
**AliRunLoader::GetHeader()**
**AliRunLoader::TreeK()**
**AliRunLoader::TreeE()**
**AliLoader::TreeH()**
**AliLoader::TreeS()**
**AliLoader::TreeD()**
**AliLoader::TreeR()**

- P. K. Skowroński   Alice Offline Week

- 11 May 2002

## Clue

- How to get access to Run Loader?
- Add a data member with folder name
- In AliDetector is not needed – it already have pointer to its AliLoader.
- AliRunLoader is easily accessible from folder using static method
**AliRunLoader* AliRunLoader::****      GetRunLoader(const char* eventfoldername);**
- Set the event folder name from the place you open session – macro, manager or superior class

- P. K. Skowroński   Alice Offline Week

- 11 May 2002

## Example

**AliRunLoader *rl = AliRunLoader::Open(****"galice.root"****,****"Event"****,****“read"****);**
**rl->LoadgAlice();**
**gAlice = rl->GetAliRun();//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!**
**AliTPC *TPC = (AliTPC*)gAlice->GetDetector(****"TPC"****);**
**AliLoader * tpcl = rl->GetLoader(****"TPCLoader"****);**
**tpcl->LoadHits(****"READ"****);**
**tpcl->LoadSDigits(****"RECREATE"****);**
**Int_t**** nevent = rl->GetNumberOfEvents();**
**for****(****Int_t**** eventn =****0****;eventn<nevent;eventn++)**
** ****{**
**	****rl->GetEvent(eventn);**
**	****TPC->Hits2SDigits2(eventn);**
**   ****tpcl->WriteSDigits(****“OVERWRITE”****);**
** ****}**
**delete**** rl;**

- P. K. Skowroński   Alice Offline Week

- 11 May 2002