3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
19 /** @file AliHLTSimulation.cxx
20 @author Matthias Richter
22 @brief Binding class for HLT simulation in AliRoot. */
26 #include "TObjArray.h"
27 #include "TObjString.h"
28 #include "AliHLTSimulation.h"
30 #include "AliRunLoader.h"
31 #include "AliHLTSystem.h"
32 #include "AliRawReaderFile.h"
33 #include "AliRawReaderDate.h"
34 #include "AliRawReaderRoot.h"
35 #include "AliESDEvent.h"
36 #include "AliHLTOUTComponent.h"
38 #if ALIHLTSIMULATION_LIBRARY_VERSION != LIBHLTSIM_VERSION
39 #error library version in header file and lib*.pkg do not match
42 /** ROOT macro for the implementation of ROOT specific class methods */
43 ClassImp(AliHLTSimulation);
45 AliHLTSimulation::AliHLTSimulation()
50 // see header file for class documentation
52 // refer to README to build package
54 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
57 AliHLTSimulation::~AliHLTSimulation()
59 // see header file for function documentation
66 AliHLTSimulation* AliHLTSimulation::CreateInstance()
68 // see header file for function documentation
69 return new AliHLTSimulation;
72 int AliHLTSimulation::DeleteInstance(AliHLTSimulation* pSim)
74 // see header file for function documentation
80 int AliHLTSimulation::Init(AliRunLoader* pRunLoader, const char* options)
82 // init the simulation
86 AliHLTSystem* pSystem=GetInstance();
88 AliError("can not get AliHLTSystem instance");
91 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
92 AliError("HLT system in error state");
96 // scan options for specific entries
97 TObjArray* pTokens=fOptions.Tokenize(" ");
99 int iEntries=pTokens->GetEntries();
100 for (int i=0; i<iEntries; i++) {
101 TString token=(((TObjString*)pTokens->At(i))->GetString());
102 if (token.Contains("rawfile=")) {
103 TString param=token.ReplaceAll("rawfile=", "");
104 if (param.EndsWith("/")) {
105 AliInfo(Form("creating AliRawReaderFile (%s)", param.Data()));
106 fpRawReader = new AliRawReaderFile(param);
107 } else if (param.EndsWith(".root")) {
108 AliInfo(Form("creating AliRawReaderRoot (%s)", param.Data()));
109 fpRawReader = new AliRawReaderRoot(param);
110 } else if (!param.IsNull()) {
111 AliInfo(Form("creating AliRawReaderDate (%s)", param.Data()));
112 fpRawReader = new AliRawReaderDate(param);
113 fpRawReader->SelectEvents(7);
116 fpRawReader->RewindEvents();
118 for (; fpRawReader->NextEvent(); count++);
119 if (count!=pRunLoader->GetNumberOfEvents()) {
120 AliError(Form("missmatch in event count: runloader %d, rawreader %d; ignoring rawreader",
121 pRunLoader->GetNumberOfEvents(), count));
125 fpRawReader->RewindEvents();
126 fpRawReader->NextEvent();
132 } else if (token.Contains("writerawfiles=")) {
133 if (!token.ReplaceAll("writerawfiles=", "").Contains("HLT")) {
134 AliHLTOUTComponent::ClearGlobalOption(AliHLTOUTComponent::kWriteRawFiles);
137 if (sysOp.Length()>0) sysOp+=" ";
145 if (pSystem->ScanOptions(sysOp.Data())<0) {
146 AliError("error setting options for HLT system");
150 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
151 if ((pSystem->Configure(pRunLoader))<0) {
152 AliError("error during HLT system configuration");
161 int AliHLTSimulation::Run(AliRunLoader* pRunLoader)
163 // HLT reconstruction for simulated data
165 AliError("Missing RunLoader! 0x0");
169 int nEvents = pRunLoader->GetNumberOfEvents();
172 AliHLTSystem* pSystem=GetInstance();
174 AliError("can not get AliHLTSystem instance");
177 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
178 AliError("HLT system in error state");
182 // Note: the rawreader is already placed at the first event
183 if ((iResult=pSystem->Reconstruct(1, pRunLoader, fpRawReader))>=0) {
184 pSystem->FillESD(0, pRunLoader, NULL);
185 for (int i=1; i<nEvents; i++) {
186 if (fpRawReader && !fpRawReader->NextEvent()) {
187 AliError("missmatch in event count, rawreader corrupted");
190 pSystem->Reconstruct(1, pRunLoader, fpRawReader);
191 pSystem->FillESD(i, pRunLoader, NULL);
193 // send specific 'event' to execute the stop sequence
194 pSystem->Reconstruct(0, NULL, NULL);
200 AliHLTSimulation* AliHLTSimulationCreateInstance()
202 // see header file for function documentation
203 return AliHLTSimulation::CreateInstance();
206 int AliHLTSimulationDeleteInstance(AliHLTSimulation* pSim)
208 // see header file for function documentation
209 return AliHLTSimulation::DeleteInstance(pSim);
212 int AliHLTSimulationInit(AliHLTSimulation* pSim, AliRunLoader* pRunLoader, const char* options)
216 return pSim->Init(pRunLoader, options);
221 int AliHLTSimulationRun(AliHLTSimulation* pSim, AliRunLoader* pRunLoader)
225 return pSim->Run(pRunLoader);
230 int AliHLTSimulationGetLibraryVersion()
232 // see header file for function documentation
233 return LIBHLTSIM_VERSION;