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++) {/* empty body */};
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 Double_t solenoidBz=AliTracker::GetBz();
158 AliCDBManager* man = AliCDBManager::Instance();
159 if (man && man->IsDefaultStorageSet())
161 const char* cdbSolenoidPath="HLT/ConfigHLT/SolenoidBz";
162 int runNo=pRunLoader->GetHeader()->GetRun();
163 TString cdbSolenoidParam;
164 cdbSolenoidParam.Form("-solenoidBz %f", solenoidBz);
166 // check if the entry is already there
167 AliCDBEntry *pEntry = man->Get(cdbSolenoidPath, runNo);
168 TObjString* pString=NULL;
169 if (pEntry) pString=dynamic_cast<TObjString*>(pEntry->GetObject());
171 if (!pEntry || !pString || pString->GetString().CompareTo(cdbSolenoidParam)!=0) {
172 TObjString obj(cdbSolenoidParam);
173 AliCDBPath cdbSolenoidEntry(cdbSolenoidPath);
174 AliCDBId cdbSolenoidId(cdbSolenoidEntry, runNo, runNo);
175 AliCDBMetaData cdbMetaData;
176 man->Put(&obj, cdbSolenoidId, &cdbMetaData);
181 if (fpSystem->ScanOptions(sysOp.Data())<0) {
182 AliError("error setting options for HLT system");
186 if (!fpSystem->CheckStatus(AliHLTSystem::kReady)) {
187 if ((fpSystem->Configure(fpRawReader, pRunLoader))<0) {
188 AliError("error during HLT system configuration");
197 int AliHLTSimulation::Run(AliRunLoader* pRunLoader)
199 // HLT reconstruction for simulated data
201 AliError("Missing RunLoader! 0x0");
205 int nEvents = pRunLoader->GetNumberOfEvents();
208 if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
209 AliError("HLT system in error state");
213 // Note: the rawreader is already placed at the first event
214 if ((iResult=fpSystem->Reconstruct(1, pRunLoader, fpRawReader))>=0) {
215 fpSystem->FillESD(0, pRunLoader, NULL);
216 for (int i=1; i<nEvents; i++) {
217 if (fpRawReader && !fpRawReader->NextEvent()) {
218 AliError("mismatch in event count, rawreader corrupted");
221 fpSystem->Reconstruct(1, pRunLoader, fpRawReader);
222 fpSystem->FillESD(i, pRunLoader, NULL);
224 // send specific 'event' to execute the stop sequence
225 fpSystem->Reconstruct(0, NULL, NULL);
231 AliHLTSimulation* AliHLTSimulationCreateInstance()
233 // see header file for function documentation
234 return AliHLTSimulation::CreateInstance();
237 int AliHLTSimulationDeleteInstance(AliHLTSimulation* pSim)
239 // see header file for function documentation
240 return AliHLTSimulation::DeleteInstance(pSim);
243 int AliHLTSimulationInit(AliHLTSimulation* pSim, AliRunLoader* pRunLoader, const char* options)
247 return pSim->Init(pRunLoader, options);
252 int AliHLTSimulationRun(AliHLTSimulation* pSim, AliRunLoader* pRunLoader)
256 return pSim->Run(pRunLoader);
261 int AliHLTSimulationGetLibraryVersion()
263 // see header file for function documentation
264 return LIBHLTSIM_VERSION;
267 extern "C" void AliHLTSimulationCompileInfo(const char*& date, const char*& time)
269 // the fall back compile info of the HLTsim library
270 // this is not up-to-date if other files have been changed and recompiled
271 date=__DATE__; time=__TIME__;