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"
31 #include "AliRunLoader.h"
32 #include "AliHeader.h"
33 #include "AliTracker.h"
34 #include "AliCDBManager.h"
35 #include "AliCDBEntry.h"
36 #include "AliCDBPath.h"
38 #include "AliCDBMetaData.h"
39 #include "AliHLTSystem.h"
40 #include "AliRawReaderFile.h"
41 #include "AliRawReaderDate.h"
42 #include "AliRawReaderRoot.h"
43 #include "AliESDEvent.h"
44 #include "AliHLTOUTComponent.h"
46 #if ALIHLTSIMULATION_LIBRARY_VERSION != LIBHLTSIM_VERSION
47 #error library version in header file and lib*.pkg do not match
50 /** ROOT macro for the implementation of ROOT specific class methods */
51 ClassImp(AliHLTSimulation);
53 AliHLTSimulation::AliHLTSimulation()
59 // see header file for class documentation
61 // refer to README to build package
63 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
66 AliHLTSimulation::~AliHLTSimulation()
68 // see header file for function documentation
79 AliHLTSimulation* AliHLTSimulation::CreateInstance()
81 // see header file for function documentation
82 return new AliHLTSimulation;
85 int AliHLTSimulation::DeleteInstance(AliHLTSimulation* pSim)
87 // see header file for function documentation
93 int AliHLTSimulation::Init(AliRunLoader* pRunLoader, const char* options)
95 // init the simulation
99 if (!fpSystem) fpSystem=new AliHLTSystem;
101 AliError("can not create AliHLTSystem object");
104 if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
105 AliError("HLT system in error state");
109 // scan options for specific entries
110 TObjArray* pTokens=fOptions.Tokenize(" ");
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);
128 fpRawReader->RewindEvents();
130 for (; fpRawReader->NextEvent(); count++);
131 if (count!=pRunLoader->GetNumberOfEvents()) {
132 AliError(Form("mismatch in event count: runloader %d, rawreader %d; ignoring rawreader",
133 pRunLoader->GetNumberOfEvents(), count));
137 fpRawReader->RewindEvents();
138 fpRawReader->NextEvent();
144 } else if (token.Contains("writerawfiles=")) {
145 if (!token.ReplaceAll("writerawfiles=", "").Contains("HLT")) {
146 AliHLTOUTComponent::ClearGlobalOption(AliHLTOUTComponent::kWriteRawFiles);
149 if (sysOp.Length()>0) sysOp+=" ";
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())
163 const char* cdbSolenoidPath="HLT/ConfigHLT/SolenoidBz";
164 int runNo=pRunLoader->GetHeader()->GetRun();
165 TString cdbSolenoidParam;
166 cdbSolenoidParam.Form("-solenoidBz %f", solenoidBz);
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());
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);
183 if (fpSystem->ScanOptions(sysOp.Data())<0) {
184 AliError("error setting options for HLT system");
188 if (!fpSystem->CheckStatus(AliHLTSystem::kReady)) {
189 if ((fpSystem->Configure(pRunLoader))<0) {
190 AliError("error during HLT system configuration");
199 int AliHLTSimulation::Run(AliRunLoader* pRunLoader)
201 // HLT reconstruction for simulated data
203 AliError("Missing RunLoader! 0x0");
207 int nEvents = pRunLoader->GetNumberOfEvents();
210 if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
211 AliError("HLT system in error state");
215 // Note: the rawreader is already placed at the first event
216 if ((iResult=fpSystem->Reconstruct(1, pRunLoader, fpRawReader))>=0) {
217 fpSystem->FillESD(0, pRunLoader, NULL);
218 for (int i=1; i<nEvents; i++) {
219 if (fpRawReader && !fpRawReader->NextEvent()) {
220 AliError("mismatch in event count, rawreader corrupted");
223 fpSystem->Reconstruct(1, pRunLoader, fpRawReader);
224 fpSystem->FillESD(i, pRunLoader, NULL);
226 // send specific 'event' to execute the stop sequence
227 fpSystem->Reconstruct(0, NULL, NULL);
233 AliHLTSimulation* AliHLTSimulationCreateInstance()
235 // see header file for function documentation
236 return AliHLTSimulation::CreateInstance();
239 int AliHLTSimulationDeleteInstance(AliHLTSimulation* pSim)
241 // see header file for function documentation
242 return AliHLTSimulation::DeleteInstance(pSim);
245 int AliHLTSimulationInit(AliHLTSimulation* pSim, AliRunLoader* pRunLoader, const char* options)
249 return pSim->Init(pRunLoader, options);
254 int AliHLTSimulationRun(AliHLTSimulation* pSim, AliRunLoader* pRunLoader)
258 return pSim->Run(pRunLoader);
263 int AliHLTSimulationGetLibraryVersion()
265 // see header file for function documentation
266 return LIBHLTSIM_VERSION;