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"
29 #include "AliSimulation.h"
32 #include "AliRunLoader.h"
33 #include "AliHeader.h"
34 #include "AliCDBManager.h"
35 #include "AliCDBEntry.h"
36 #include "AliCDBPath.h"
38 #include "AliCDBMetaData.h"
39 #include "AliCDBStorage.h"
40 #include "AliGRPObject.h"
41 #include "AliGRPManager.h"
42 #include "AliHLTSystem.h"
43 #include "AliHLTPluginBase.h"
44 #include "AliRawReaderFile.h"
45 #include "AliRawReaderDate.h"
46 #include "AliRawReaderRoot.h"
47 #include "AliESDEvent.h"
48 #include "AliHLTOUTComponent.h"
49 #include "AliTracker.h"
50 #include "TGeoGlobalMagField.h"
53 #include "TGeoGlobalMagField.h"
55 #if ALIHLTSIMULATION_LIBRARY_VERSION != LIBHLTSIM_VERSION
56 #error library version in header file and lib*.pkg do not match
59 /** ROOT macro for the implementation of ROOT specific class methods */
60 ClassImp(AliHLTSimulation);
62 AliHLTSimulation::AliHLTSimulation()
65 fpPluginBase(new AliHLTPluginBase),
68 // see header file for class documentation
70 // refer to README to build package
72 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
75 AliHLTSimulation::~AliHLTSimulation()
77 // see header file for function documentation
78 if (fpPluginBase) delete fpPluginBase;
87 AliHLTSimulation* AliHLTSimulation::CreateInstance()
89 // see header file for function documentation
90 return new AliHLTSimulation;
93 int AliHLTSimulation::DeleteInstance(AliHLTSimulation* pSim)
95 // see header file for function documentation
101 int AliHLTSimulation::Init(AliRunLoader* pRunLoader, const char* options)
103 // init the simulation
108 AliError("internal initialization failed");
112 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
114 AliError("can not get AliHLTSystem instance");
117 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
118 AliError("HLT system in error state");
122 // scan options for specific entries
123 TObjArray* pTokens=fOptions.Tokenize(" ");
125 int iEntries=pTokens->GetEntries();
126 for (int i=0; i<iEntries; i++) {
127 TString token=(((TObjString*)pTokens->At(i))->GetString());
128 if (token.Contains("rawfile=")) {
129 TString param=token.ReplaceAll("rawfile=", "");
130 if (param.EndsWith("/")) {
131 AliInfo(Form("creating AliRawReaderFile (%s)", param.Data()));
132 fpRawReader = new AliRawReaderFile(param);
133 } else if (param.EndsWith(".root")) {
134 AliInfo(Form("creating AliRawReaderRoot (%s)", param.Data()));
135 fpRawReader = new AliRawReaderRoot(param);
136 } else if (!param.IsNull()) {
137 AliInfo(Form("creating AliRawReaderDate (%s)", param.Data()));
138 fpRawReader = new AliRawReaderDate(param);
141 fpRawReader->RewindEvents();
143 for ( ; fpRawReader->NextEvent(); count++) {/* empty body */};
144 if (count!=pRunLoader->GetNumberOfEvents()) {
145 AliError(Form("mismatch in event count: runloader %d, rawreader %d; ignoring rawreader",
146 pRunLoader->GetNumberOfEvents(), count));
150 fpRawReader->RewindEvents();
151 fpRawReader->NextEvent();
157 } else if (token.Contains("writerawfiles=")) {
158 if (!token.ReplaceAll("writerawfiles=", "").Contains("HLT")) {
159 AliHLTOUTComponent::ClearGlobalOption(AliHLTOUTComponent::kWriteRawFiles);
162 if (sysOp.Length()>0) sysOp+=" ";
169 AliCDBManager* man = AliCDBManager::Instance();
170 if (man && man->IsDefaultStorageSet())
172 int runNo=pRunLoader->GetHeader()->GetRun();
174 // init solenoid field
175 // 2009-11-07 magnetic field handling fo HLT components has been switched to the
176 // global AliMagF instance, the HLT/ConfigHLT/SolenoidBz entry is obsolete
177 // The global instance is either established by the AliRoot environment or the
178 // component external interface.
179 if (TGeoGlobalMagField::Instance()->GetField()) {
180 AliDebug(0, Form("magnetic field: %f", AliTracker::GetBz()));
182 // workaround for bug #51285
183 AliGRPManager grpman;
184 if (grpman.ReadGRPEntry() &&
185 grpman.SetMagField()) {
186 // nothing to do any more
188 AliError(Form("can not get the AliMagF instance, falling back to GRP entry (%f)", AliTracker::GetBz()));
191 AliError("OCDB default storage not yet set, can not prepare OCDB entries");
193 AliError("unable to get instance of AliCDBMetaData, can not prepare OCDB entries");
197 if (pSystem->ScanOptions(sysOp.Data())<0) {
198 AliError("error setting options for HLT system");
202 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
203 if ((pSystem->Configure(fpRawReader, pRunLoader))<0) {
204 AliError("error during HLT system configuration");
213 int AliHLTSimulation::Run(AliRunLoader* pRunLoader)
215 // HLT reconstruction for simulated data
217 AliError("internal initialization failed");
222 AliError("Missing RunLoader! 0x0");
226 int nEvents = pRunLoader->GetNumberOfEvents();
229 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
231 AliError("can not get AliHLTSystem instance");
235 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
236 AliError("HLT system in error state");
240 // Note: the rawreader is already placed at the first event
241 if ((iResult=pSystem->Reconstruct(1, pRunLoader, fpRawReader))>=0) {
242 pSystem->FillESD(0, pRunLoader, NULL);
243 for (int i=1; i<nEvents; i++) {
244 if (fpRawReader && !fpRawReader->NextEvent()) {
245 AliError("mismatch in event count, rawreader corrupted");
248 pSystem->Reconstruct(1, pRunLoader, fpRawReader);
249 pSystem->FillESD(i, pRunLoader, NULL);
251 // send specific 'event' to execute the stop sequence
252 pSystem->Reconstruct(0, NULL, NULL);
258 AliHLTSimulation* AliHLTSimulationCreateInstance()
260 // see header file for function documentation
261 return AliHLTSimulation::CreateInstance();
264 int AliHLTSimulationDeleteInstance(AliHLTSimulation* pSim)
266 // see header file for function documentation
267 return AliHLTSimulation::DeleteInstance(pSim);
270 int AliHLTSimulationInit(AliHLTSimulation* pSim, AliRunLoader* pRunLoader, const char* options)
274 return pSim->Init(pRunLoader, options);
279 int AliHLTSimulationRun(AliHLTSimulation* pSim, AliRunLoader* pRunLoader)
283 return pSim->Run(pRunLoader);
288 int AliHLTSimulationGetLibraryVersion()
290 // see header file for function documentation
291 return LIBHLTSIM_VERSION;
294 int AliHLTSimulationSetup(AliHLTSimulation* /*pHLTSim*/, AliSimulation* pSim, const char* specificObjects)
296 // see header file for function documentation
298 // this is an attempt to solve issue #48360
299 // since there are many jobs running in parallel during the production,
300 // all the jobs want to put entries into the OCDB. The solution is to
301 // make them temporary, since they are only used to propagate information
302 // from the simulation to the reconstruction.
304 if (!pSim) return -EINVAL;
305 const char* entries[]={
309 TString specificStorage;
310 specificStorage.Form("local://%s",gSystem->pwd());
311 for (const char** pEntry=entries; *pEntry!=NULL; pEntry++) {
312 const char* pObject=specificObjects?strstr(specificObjects, *pEntry):NULL;
314 // skip this entry if it is found in the list and either
315 // last one or separated by a blank
316 pObject+=strlen(*pEntry);
317 if (*pObject==0 || *pObject==' ') continue;
319 pSim->SetSpecificStorage(*pEntry, specificStorage.Data());
325 #ifndef HAVE_COMPILEINFO
326 extern "C" void CompileInfo(const char*& date, const char*& time)
328 // the fall back compile info of the HLTsim library
329 // this is not up-to-date if other files have been changed and recompiled
330 date=__DATE__; time=__TIME__;