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()
51 // see header file for class documentation
53 // refer to README to build package
55 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
58 AliHLTSimulation::~AliHLTSimulation()
60 // see header file for function documentation
71 AliHLTSimulation* AliHLTSimulation::CreateInstance()
73 // see header file for function documentation
74 return new AliHLTSimulation;
77 int AliHLTSimulation::DeleteInstance(AliHLTSimulation* pSim)
79 // see header file for function documentation
85 int AliHLTSimulation::Init(AliRunLoader* pRunLoader, const char* options)
87 // init the simulation
91 if (!fpSystem) fpSystem=new AliHLTSystem;
93 AliError("can not create AliHLTSystem object");
96 if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
97 AliError("HLT system in error state");
101 // scan options for specific entries
102 TObjArray* pTokens=fOptions.Tokenize(" ");
104 int iEntries=pTokens->GetEntries();
105 for (int i=0; i<iEntries; i++) {
106 TString token=(((TObjString*)pTokens->At(i))->GetString());
107 if (token.Contains("rawfile=")) {
108 TString param=token.ReplaceAll("rawfile=", "");
109 if (param.EndsWith("/")) {
110 AliInfo(Form("creating AliRawReaderFile (%s)", param.Data()));
111 fpRawReader = new AliRawReaderFile(param);
112 } else if (param.EndsWith(".root")) {
113 AliInfo(Form("creating AliRawReaderRoot (%s)", param.Data()));
114 fpRawReader = new AliRawReaderRoot(param);
115 } else if (!param.IsNull()) {
116 AliInfo(Form("creating AliRawReaderDate (%s)", param.Data()));
117 fpRawReader = new AliRawReaderDate(param);
118 fpRawReader->SelectEvents(7);
121 fpRawReader->RewindEvents();
123 for (; fpRawReader->NextEvent(); count++);
124 if (count!=pRunLoader->GetNumberOfEvents()) {
125 AliError(Form("missmatch in event count: runloader %d, rawreader %d; ignoring rawreader",
126 pRunLoader->GetNumberOfEvents(), count));
130 fpRawReader->RewindEvents();
131 fpRawReader->NextEvent();
137 } else if (token.Contains("writerawfiles=")) {
138 if (!token.ReplaceAll("writerawfiles=", "").Contains("HLT")) {
139 AliHLTOUTComponent::ClearGlobalOption(AliHLTOUTComponent::kWriteRawFiles);
142 if (sysOp.Length()>0) sysOp+=" ";
150 if (fpSystem->ScanOptions(sysOp.Data())<0) {
151 AliError("error setting options for HLT system");
155 if (!fpSystem->CheckStatus(AliHLTSystem::kReady)) {
156 if ((fpSystem->Configure(pRunLoader))<0) {
157 AliError("error during HLT system configuration");
166 int AliHLTSimulation::Run(AliRunLoader* pRunLoader)
168 // HLT reconstruction for simulated data
170 AliError("Missing RunLoader! 0x0");
174 int nEvents = pRunLoader->GetNumberOfEvents();
177 if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
178 AliError("HLT system in error state");
182 // Note: the rawreader is already placed at the first event
183 if ((iResult=fpSystem->Reconstruct(1, pRunLoader, fpRawReader))>=0) {
184 fpSystem->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 fpSystem->Reconstruct(1, pRunLoader, fpRawReader);
191 fpSystem->FillESD(i, pRunLoader, NULL);
193 // send specific 'event' to execute the stop sequence
194 fpSystem->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;