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 "AliHLTPluginBase.h"
41 #include "AliRawReaderFile.h"
42 #include "AliRawReaderDate.h"
43 #include "AliRawReaderRoot.h"
44 #include "AliESDEvent.h"
45 #include "AliHLTOUTComponent.h"
47 #if ALIHLTSIMULATION_LIBRARY_VERSION != LIBHLTSIM_VERSION
48 #error library version in header file and lib*.pkg do not match
51 /** ROOT macro for the implementation of ROOT specific class methods */
52 ClassImp(AliHLTSimulation);
54 AliHLTSimulation::AliHLTSimulation()
57 fpPluginBase(new AliHLTPluginBase),
60 // see header file for class documentation
62 // refer to README to build package
64 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
67 AliHLTSimulation::~AliHLTSimulation()
69 // see header file for function documentation
70 if (fpPluginBase) delete fpPluginBase;
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
100 AliError("internal initialization failed");
104 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
106 AliError("can not get AliHLTSystem instance");
109 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
110 AliError("HLT system in error state");
114 // scan options for specific entries
115 TObjArray* pTokens=fOptions.Tokenize(" ");
117 int iEntries=pTokens->GetEntries();
118 for (int i=0; i<iEntries; i++) {
119 TString token=(((TObjString*)pTokens->At(i))->GetString());
120 if (token.Contains("rawfile=")) {
121 TString param=token.ReplaceAll("rawfile=", "");
122 if (param.EndsWith("/")) {
123 AliInfo(Form("creating AliRawReaderFile (%s)", param.Data()));
124 fpRawReader = new AliRawReaderFile(param);
125 } else if (param.EndsWith(".root")) {
126 AliInfo(Form("creating AliRawReaderRoot (%s)", param.Data()));
127 fpRawReader = new AliRawReaderRoot(param);
128 } else if (!param.IsNull()) {
129 AliInfo(Form("creating AliRawReaderDate (%s)", param.Data()));
130 fpRawReader = new AliRawReaderDate(param);
133 fpRawReader->RewindEvents();
135 for ( ; fpRawReader->NextEvent(); count++) {/* empty body */};
136 if (count!=pRunLoader->GetNumberOfEvents()) {
137 AliError(Form("mismatch in event count: runloader %d, rawreader %d; ignoring rawreader",
138 pRunLoader->GetNumberOfEvents(), count));
142 fpRawReader->RewindEvents();
143 fpRawReader->NextEvent();
149 } else if (token.Contains("writerawfiles=")) {
150 if (!token.ReplaceAll("writerawfiles=", "").Contains("HLT")) {
151 AliHLTOUTComponent::ClearGlobalOption(AliHLTOUTComponent::kWriteRawFiles);
154 if (sysOp.Length()>0) sysOp+=" ";
161 // init solenoid field
162 Double_t solenoidBz=AliTracker::GetBz();
163 AliCDBManager* man = AliCDBManager::Instance();
164 if (man && man->IsDefaultStorageSet())
166 const char* cdbSolenoidPath="HLT/ConfigHLT/SolenoidBz";
167 int runNo=pRunLoader->GetHeader()->GetRun();
168 TString cdbSolenoidParam;
169 cdbSolenoidParam.Form("-solenoidBz %f", solenoidBz);
171 // check if the entry is already there
172 AliCDBEntry *pEntry = man->Get(cdbSolenoidPath, runNo);
173 TObjString* pString=NULL;
174 if (pEntry) pString=dynamic_cast<TObjString*>(pEntry->GetObject());
176 if (!pEntry || !pString || pString->GetString().CompareTo(cdbSolenoidParam)!=0) {
177 TObjString obj(cdbSolenoidParam);
178 AliCDBPath cdbSolenoidEntry(cdbSolenoidPath);
179 AliCDBId cdbSolenoidId(cdbSolenoidEntry, runNo, runNo);
180 AliCDBMetaData cdbMetaData;
181 man->Put(&obj, cdbSolenoidId, &cdbMetaData);
186 if (pSystem->ScanOptions(sysOp.Data())<0) {
187 AliError("error setting options for HLT system");
191 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
192 if ((pSystem->Configure(fpRawReader, pRunLoader))<0) {
193 AliError("error during HLT system configuration");
202 int AliHLTSimulation::Run(AliRunLoader* pRunLoader)
204 // HLT reconstruction for simulated data
206 AliError("internal initialization failed");
211 AliError("Missing RunLoader! 0x0");
215 int nEvents = pRunLoader->GetNumberOfEvents();
218 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
220 AliError("can not get AliHLTSystem instance");
224 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
225 AliError("HLT system in error state");
229 // Note: the rawreader is already placed at the first event
230 if ((iResult=pSystem->Reconstruct(1, pRunLoader, fpRawReader))>=0) {
231 pSystem->FillESD(0, pRunLoader, NULL);
232 for (int i=1; i<nEvents; i++) {
233 if (fpRawReader && !fpRawReader->NextEvent()) {
234 AliError("mismatch in event count, rawreader corrupted");
237 pSystem->Reconstruct(1, pRunLoader, fpRawReader);
238 pSystem->FillESD(i, pRunLoader, NULL);
240 // send specific 'event' to execute the stop sequence
241 pSystem->Reconstruct(0, NULL, NULL);
247 AliHLTSimulation* AliHLTSimulationCreateInstance()
249 // see header file for function documentation
250 return AliHLTSimulation::CreateInstance();
253 int AliHLTSimulationDeleteInstance(AliHLTSimulation* pSim)
255 // see header file for function documentation
256 return AliHLTSimulation::DeleteInstance(pSim);
259 int AliHLTSimulationInit(AliHLTSimulation* pSim, AliRunLoader* pRunLoader, const char* options)
263 return pSim->Init(pRunLoader, options);
268 int AliHLTSimulationRun(AliHLTSimulation* pSim, AliRunLoader* pRunLoader)
272 return pSim->Run(pRunLoader);
277 int AliHLTSimulationGetLibraryVersion()
279 // see header file for function documentation
280 return LIBHLTSIM_VERSION;
283 extern "C" void AliHLTSimulationCompileInfo(const char*& date, const char*& time)
285 // the fall back compile info of the HLTsim library
286 // this is not up-to-date if other files have been changed and recompiled
287 date=__DATE__; time=__TIME__;