Possibility to specify event selection criteria within the raw-data input URI. The...
[u/mrichter/AliRoot.git] / HLT / sim / AliHLTSimulation.cxx
CommitLineData
4cbaf07b 1// $Id$
2
c5123824 3//**************************************************************************
4//* This file is property of and copyright by the ALICE HLT Project *
5//* ALICE Experiment at CERN, All rights reserved. *
6//* *
7//* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8//* for The ALICE HLT Project. *
9//* *
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//**************************************************************************
4cbaf07b 18
19/** @file AliHLTSimulation.cxx
20 @author Matthias Richter
21 @date
22 @brief Binding class for HLT simulation in AliRoot. */
23
24#include <cassert>
25#include <cerrno>
7777fa45 26#include "TObjArray.h"
27#include "TObjString.h"
4cbaf07b 28#include "AliHLTSimulation.h"
29#include "AliLog.h"
90c37647 30#include "AliRun.h"
4cbaf07b 31#include "AliRunLoader.h"
90c37647 32#include "AliHeader.h"
33#include "AliTracker.h"
34#include "AliCDBManager.h"
35#include "AliCDBEntry.h"
36#include "AliCDBPath.h"
37#include "AliCDBId.h"
38#include "AliCDBMetaData.h"
4cbaf07b 39#include "AliHLTSystem.h"
7777fa45 40#include "AliRawReaderFile.h"
41#include "AliRawReaderDate.h"
42#include "AliRawReaderRoot.h"
a8420176 43#include "AliESDEvent.h"
2c0e5942 44#include "AliHLTOUTComponent.h"
4cbaf07b 45
46#if ALIHLTSIMULATION_LIBRARY_VERSION != LIBHLTSIM_VERSION
47#error library version in header file and lib*.pkg do not match
48#endif
49
50/** ROOT macro for the implementation of ROOT specific class methods */
51ClassImp(AliHLTSimulation);
52
53AliHLTSimulation::AliHLTSimulation()
54 :
55 fOptions(),
57034f7f 56 fpSystem(NULL),
7777fa45 57 fpRawReader(NULL)
4cbaf07b 58{
59 // see header file for class documentation
60 // or
61 // refer to README to build package
62 // or
63 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
64}
65
66AliHLTSimulation::~AliHLTSimulation()
67{
68 // see header file for function documentation
57034f7f 69 if (fpSystem) {
70 delete fpSystem;
71 }
72 fpSystem=NULL;
7777fa45 73 if (fpRawReader) {
74 delete fpRawReader;
75 }
76 fpRawReader=NULL;
4cbaf07b 77}
78
79AliHLTSimulation* AliHLTSimulation::CreateInstance()
80{
81 // see header file for function documentation
82 return new AliHLTSimulation;
83}
84
85int AliHLTSimulation::DeleteInstance(AliHLTSimulation* pSim)
86{
87 // see header file for function documentation
88 assert(pSim!=NULL);
89 delete pSim;
90 return 0;
91}
92
93int AliHLTSimulation::Init(AliRunLoader* pRunLoader, const char* options)
94{
95 // init the simulation
96 fOptions=options;
7777fa45 97 TString sysOp;
4cbaf07b 98
57034f7f 99 if (!fpSystem) fpSystem=new AliHLTSystem;
100 if (!fpSystem) {
101 AliError("can not create AliHLTSystem object");
4cbaf07b 102 return -ENOMEM;
103 }
57034f7f 104 if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
4cbaf07b 105 AliError("HLT system in error state");
106 return -EFAULT;
107 }
108
7777fa45 109 // scan options for specific entries
110 TObjArray* pTokens=fOptions.Tokenize(" ");
111 if (pTokens) {
112 int iEntries=pTokens->GetEntries();
113 for (int i=0; i<iEntries; i++) {
114 TString token=(((TObjString*)pTokens->At(i))->GetString());
115 if (token.Contains("rawfile=")) {
116 TString param=token.ReplaceAll("rawfile=", "");
117 if (param.EndsWith("/")) {
118 AliInfo(Form("creating AliRawReaderFile (%s)", param.Data()));
119 fpRawReader = new AliRawReaderFile(param);
120 } else if (param.EndsWith(".root")) {
121 AliInfo(Form("creating AliRawReaderRoot (%s)", param.Data()));
122 fpRawReader = new AliRawReaderRoot(param);
123 } else if (!param.IsNull()) {
124 AliInfo(Form("creating AliRawReaderDate (%s)", param.Data()));
125 fpRawReader = new AliRawReaderDate(param);
7777fa45 126 }
127 if (fpRawReader) {
128 fpRawReader->RewindEvents();
129 int count=0;
130 for (; fpRawReader->NextEvent(); count++);
131 if (count!=pRunLoader->GetNumberOfEvents()) {
c5123824 132 AliError(Form("mismatch in event count: runloader %d, rawreader %d; ignoring rawreader",
7777fa45 133 pRunLoader->GetNumberOfEvents(), count));
134 count=0;
135 }
136 if (count>0) {
137 fpRawReader->RewindEvents();
138 fpRawReader->NextEvent();
139 } else {
140 delete fpRawReader;
141 fpRawReader=NULL;
142 }
143 }
2c0e5942 144 } else if (token.Contains("writerawfiles=")) {
145 if (!token.ReplaceAll("writerawfiles=", "").Contains("HLT")) {
146 AliHLTOUTComponent::ClearGlobalOption(AliHLTOUTComponent::kWriteRawFiles);
147 }
7777fa45 148 } else {
149 if (sysOp.Length()>0) sysOp+=" ";
150 sysOp+=token;
151 }
152 }
153 delete pTokens;
154 }
155
90c37647 156 // init solenoid field
157 Bool_t bUniformField=kTRUE;
158 AliTracker::SetFieldMap(pRunLoader->GetAliRun()->Field(),bUniformField);
159 Double_t solenoidBz=AliTracker::GetBz();
160 AliCDBManager* man = AliCDBManager::Instance();
161 if (man && man->IsDefaultStorageSet())
162 {
163 const char* cdbSolenoidPath="HLT/ConfigHLT/SolenoidBz";
164 int runNo=pRunLoader->GetHeader()->GetRun();
165 TString cdbSolenoidParam;
166 cdbSolenoidParam.Form("-solenoidBz %f", solenoidBz);
167
168 // check if the entry is already there
169 AliCDBEntry *pEntry = man->Get(cdbSolenoidPath, runNo);
170 TObjString* pString=NULL;
171 if (pEntry) pString=dynamic_cast<TObjString*>(pEntry->GetObject());
172
173 if (!pEntry || !pString || pString->GetString().CompareTo(cdbSolenoidParam)!=0) {
174 TObjString obj(cdbSolenoidParam);
175 AliCDBPath cdbSolenoidEntry(cdbSolenoidPath);
176 AliCDBId cdbSolenoidId(cdbSolenoidEntry, runNo, runNo);
177 AliCDBMetaData cdbMetaData;
178 man->Put(&obj, cdbSolenoidId, &cdbMetaData);
179 }
180 }
181
7777fa45 182 // scan options
57034f7f 183 if (fpSystem->ScanOptions(sysOp.Data())<0) {
4cbaf07b 184 AliError("error setting options for HLT system");
185 return -EINVAL;
186 }
187
57034f7f 188 if (!fpSystem->CheckStatus(AliHLTSystem::kReady)) {
189 if ((fpSystem->Configure(pRunLoader))<0) {
4cbaf07b 190 AliError("error during HLT system configuration");
191 return -EFAULT;
192 }
193 }
194
195 return 0;
196}
197
198
199int AliHLTSimulation::Run(AliRunLoader* pRunLoader)
200{
201 // HLT reconstruction for simulated data
202 if(!pRunLoader) {
203 AliError("Missing RunLoader! 0x0");
204 return -EINVAL;
205 }
206
7777fa45 207 int nEvents = pRunLoader->GetNumberOfEvents();
4cbaf07b 208 int iResult=0;
209
57034f7f 210 if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
4cbaf07b 211 AliError("HLT system in error state");
212 return -EFAULT;
213 }
7777fa45 214
215 // Note: the rawreader is already placed at the first event
57034f7f 216 if ((iResult=fpSystem->Reconstruct(1, pRunLoader, fpRawReader))>=0) {
217 fpSystem->FillESD(0, pRunLoader, NULL);
7777fa45 218 for (int i=1; i<nEvents; i++) {
219 if (fpRawReader && !fpRawReader->NextEvent()) {
c5123824 220 AliError("mismatch in event count, rawreader corrupted");
7777fa45 221 break;
222 }
57034f7f 223 fpSystem->Reconstruct(1, pRunLoader, fpRawReader);
224 fpSystem->FillESD(i, pRunLoader, NULL);
7777fa45 225 }
dee38f1b 226 // send specific 'event' to execute the stop sequence
57034f7f 227 fpSystem->Reconstruct(0, NULL, NULL);
4cbaf07b 228 }
229 return iResult;
230}
231
232
233AliHLTSimulation* AliHLTSimulationCreateInstance()
234{
235 // see header file for function documentation
236 return AliHLTSimulation::CreateInstance();
237}
238
239int AliHLTSimulationDeleteInstance(AliHLTSimulation* pSim)
240{
241 // see header file for function documentation
242 return AliHLTSimulation::DeleteInstance(pSim);
243}
244
245int AliHLTSimulationInit(AliHLTSimulation* pSim, AliRunLoader* pRunLoader, const char* options)
246{
247 assert(pSim!=NULL);
248 if (pSim) {
249 return pSim->Init(pRunLoader, options);
250 }
251 return -ENODEV;
252}
253
254int AliHLTSimulationRun(AliHLTSimulation* pSim, AliRunLoader* pRunLoader)
255{
256 assert(pSim!=NULL);
257 if (pSim) {
258 return pSim->Run(pRunLoader);
259 }
260 return -ENODEV;
261}
262
263int AliHLTSimulationGetLibraryVersion()
264{
265 // see header file for function documentation
266 return LIBHLTSIM_VERSION;
267}