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 "AliHLTConfigurationHandler.h"
44 #include "AliHLTPluginBase.h"
45 #include "AliRawReaderFile.h"
46 #include "AliRawReaderDate.h"
47 #include "AliRawReaderRoot.h"
48 #include "AliESDEvent.h"
49 #include "AliHLTOUTComponent.h"
50 #include "AliTracker.h"
51 #include "TGeoGlobalMagField.h"
54 #include "TGeoGlobalMagField.h"
56 #if ALIHLTSIMULATION_LIBRARY_VERSION != LIBHLTSIM_VERSION
57 #error library version in header file and lib*.pkg do not match
60 /** ROOT macro for the implementation of ROOT specific class methods */
61 ClassImp(AliHLTSimulation);
63 AliHLTSimulation::AliHLTSimulation()
65 , fpPluginBase(new AliHLTPluginBase)
69 // see header file for class documentation
71 // refer to README to build package
73 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
76 AliHLTSimulation::~AliHLTSimulation()
78 // see header file for function documentation
79 if (fpPluginBase) delete fpPluginBase;
88 AliHLTSimulation* AliHLTSimulation::CreateInstance()
90 // see header file for function documentation
91 return new AliHLTSimulation;
94 int AliHLTSimulation::DeleteInstance(AliHLTSimulation* pSim)
96 // see header file for function documentation
102 int AliHLTSimulation::Init(AliRunLoader* pRunLoader, const char* options)
104 // init the simulation
109 AliError("internal initialization failed");
113 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
115 AliError("can not get AliHLTSystem instance");
118 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
119 AliError("HLT system in error state");
123 // scan options for specific entries
124 TObjArray* pTokens=fOptions.Tokenize(" ");
126 int iEntries=pTokens->GetEntries();
127 for (int i=0; i<iEntries; i++) {
128 TString token=(((TObjString*)pTokens->At(i))->GetString());
129 if (token.Contains("rawfile=")) {
130 TString param=token.ReplaceAll("rawfile=", "");
131 if (param.EndsWith("/")) {
132 AliInfo(Form("creating AliRawReaderFile (%s)", param.Data()));
133 fpRawReader = new AliRawReaderFile(param);
134 } else if (param.EndsWith(".root")) {
135 AliInfo(Form("creating AliRawReaderRoot (%s)", param.Data()));
136 fpRawReader = new AliRawReaderRoot(param);
137 } else if (!param.IsNull()) {
138 AliInfo(Form("creating AliRawReaderDate (%s)", param.Data()));
139 fpRawReader = new AliRawReaderDate(param);
142 fpRawReader->RewindEvents();
144 for ( ; fpRawReader->NextEvent(); count++) {/* empty body */};
145 if (count!=pRunLoader->GetNumberOfEvents()) {
146 AliError(Form("mismatch in event count: runloader %d, rawreader %d; ignoring rawreader",
147 pRunLoader->GetNumberOfEvents(), count));
151 fpRawReader->RewindEvents();
152 fpRawReader->NextEvent();
158 } else if (token.Contains("writerawfiles=")) {
159 if (!token.ReplaceAll("writerawfiles=", "").Contains("HLT")) {
160 if (TestBit(kOneChain) && AliHLTOUTComponent::TestGlobalOption(AliHLTOUTComponent::kWriteRawFiles)) {
161 AliWarning("empty argument 'writerawfiles=' disables HLTOUTComponent mode 'raw' which was set by argument 'hltout-mode'");
163 AliHLTOUTComponent::ClearGlobalOption(AliHLTOUTComponent::kWriteRawFiles);
165 } else if (token.BeginsWith("hltout-mode=")) {
166 // this is a legacy mode to emulate the behavior before Dec 2010 where only
167 // one chain was executed on either digits or simulated raw data and the output
168 // was controlled via global flags
169 // add to the arguments for AliHLTSystem as also there the information is needed
170 if (sysOp.Length()>0) sysOp+=" ";
172 TString param=token.ReplaceAll("hltout-mode=", "");
174 if (param.CompareTo("raw")==0) {
175 // please note that this option
176 AliHLTOUTComponent::SetGlobalOption(AliHLTOUTComponent::kWriteRawFiles);
177 AliHLTOUTComponent::ClearGlobalOption(AliHLTOUTComponent::kWriteDigits);
178 } else if (param.CompareTo("digits")==0) {
179 // please note that this option
180 AliHLTOUTComponent::ClearGlobalOption(AliHLTOUTComponent::kWriteRawFiles);
181 AliHLTOUTComponent::SetGlobalOption(AliHLTOUTComponent::kWriteDigits);
182 } else if (param.CompareTo("legacy")==0) {
183 AliHLTOUTComponent::SetGlobalOption(AliHLTOUTComponent::kWriteRawFiles);
184 AliHLTOUTComponent::SetGlobalOption(AliHLTOUTComponent::kWriteDigits);
186 AliError(Form("invalid parameter for argument 'hltout-mode=' %s, allowed: raw, digits, legacy ... ignoring argument and using the standard simulation", param.Data()));
189 } else if (token.Contains("events=")) {
190 fNEvents=token.ReplaceAll("events=", "").Atoi();
192 if (sysOp.Length()>0) sysOp+=" ";
198 // only store the options for AliHLTSystem
201 // if no specific hltout-mode has been chosen set the split mode for
202 // running separate chains for digits and raw data
203 if (!fOptions.Contains("hltout-mode=")) fOptions+=" hltout-mode=split";
205 AliCDBManager* man = AliCDBManager::Instance();
206 if (man && man->IsDefaultStorageSet())
208 // init solenoid field
209 // 2009-11-07 magnetic field handling fo HLT components has been switched to the
210 // global AliMagF instance, the HLT/ConfigHLT/SolenoidBz entry is obsolete
211 // The global instance is either established by the AliRoot environment or the
212 // component external interface.
213 if (TGeoGlobalMagField::Instance()->GetField()) {
214 AliDebug(0, Form("magnetic field: %f", AliTracker::GetBz()));
216 // workaround for bug #51285
217 AliGRPManager grpman;
218 if (grpman.ReadGRPEntry() &&
219 grpman.SetMagField()) {
220 // nothing to do any more
222 AliError(Form("can not get the AliMagF instance, falling back to GRP entry (%f)", AliTracker::GetBz()));
225 AliError("OCDB default storage not yet set, can not prepare OCDB entries");
227 AliError("unable to get instance of AliCDBMetaData, can not prepare OCDB entries");
230 // configure the main HLTSystem instance for digit simulation (pRawReader NULL)
231 return ConfigureHLTSystem(pSystem, fOptions.Data(), pRunLoader, TestBit(kOneChain)?fpRawReader:NULL);
234 int AliHLTSimulation::ConfigureHLTSystem(AliHLTSystem* pSystem, const char* options, AliRunLoader* pRunLoader, AliRawReader* pRawReader) const
236 // scan options and configure AliHLTSystem
237 if (pSystem->ScanOptions(options)<0) {
238 AliError("error setting options for HLT system");
242 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
243 if ((pSystem->Configure(pRawReader, pRunLoader))<0) {
244 AliError("error during HLT system configuration");
252 int AliHLTSimulation::Run(AliRunLoader* pRunLoader)
254 // HLT reconstruction for simulated data
256 AliError("internal initialization failed");
261 AliError("Missing RunLoader! 0x0");
267 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
269 AliError("can not get AliHLTSystem instance");
273 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
274 AliError("HLT system in error state");
278 // run the main HLTSystem instance for digit simulation (pRawReader NULL)
279 // in legacy mode only one chain is run and the output is controlled via
281 if (!TestBit(kOneChain)) AliInfo("running HLT simulation for digits");
282 iResult=RunHLTSystem(pSystem, pRunLoader, TestBit(kOneChain)?fpRawReader:NULL);
284 // now run once again with the raw data as input, a completely new HLT system
285 // with new configurations is used
286 if (fpRawReader && !TestBit(kOneChain)) {
287 AliInfo("running HLT simulation for raw data");
289 AliHLTConfigurationHandler* confHandler=new AliHLTConfigurationHandler;
290 // note that the configuration handler is owned by the
291 // AliHLTSystem instance from now on
292 AliHLTSystem rawSimulation(kHLTLogDefault, "", NULL, confHandler);
293 if ((iLocalResult=ConfigureHLTSystem(&rawSimulation, fOptions.Data(), pRunLoader, fpRawReader))>=0) {
294 iLocalResult=RunHLTSystem(&rawSimulation, pRunLoader, fpRawReader);
296 if (iResult>=0) iResult=iLocalResult;
302 int AliHLTSimulation::RunHLTSystem(AliHLTSystem* pSystem, AliRunLoader* pRunLoader, AliRawReader* pRawReader) const
304 // run reconstruction cycle for AliHLTSystem
305 int nEvents = (fNEvents<0 || fNEvents>pRunLoader->GetNumberOfEvents())?pRunLoader->GetNumberOfEvents():fNEvents;
308 // Note: the rawreader is already placed at the first event
309 if ((iResult=pSystem->Reconstruct(1, pRunLoader, pRawReader))>=0) {
310 pSystem->FillESD(0, pRunLoader, NULL);
311 for (int i=1; i<nEvents; i++) {
312 if (pRawReader && !pRawReader->NextEvent()) {
313 AliError("mismatch in event count, rawreader corrupted");
316 pSystem->Reconstruct(1, pRunLoader, pRawReader);
317 pSystem->FillESD(i, pRunLoader, NULL);
319 // send specific 'event' to execute the stop sequence
320 pSystem->Reconstruct(0, NULL, NULL);
325 AliHLTSimulation* AliHLTSimulationCreateInstance()
327 // see header file for function documentation
328 return AliHLTSimulation::CreateInstance();
331 int AliHLTSimulationDeleteInstance(AliHLTSimulation* pSim)
333 // see header file for function documentation
334 return AliHLTSimulation::DeleteInstance(pSim);
337 int AliHLTSimulationInit(AliHLTSimulation* pSim, AliRunLoader* pRunLoader, const char* options)
341 return pSim->Init(pRunLoader, options);
346 int AliHLTSimulationRun(AliHLTSimulation* pSim, AliRunLoader* pRunLoader)
350 return pSim->Run(pRunLoader);
355 int AliHLTSimulationGetLibraryVersion()
357 // see header file for function documentation
358 return LIBHLTSIM_VERSION;
361 int AliHLTSimulationSetup(AliHLTSimulation* /*pHLTSim*/, AliSimulation* pSim, const char* specificObjects)
363 // see header file for function documentation
365 // this is an attempt to solve issue #48360
366 // since there are many jobs running in parallel during the production,
367 // all the jobs want to put entries into the OCDB. The solution is to
368 // make them temporary, since they are only used to propagate information
369 // from the simulation to the reconstruction.
371 if (!pSim) return -EINVAL;
372 const char* entries[]={
376 TString specificStorage;
377 specificStorage.Form("local://%s",gSystem->pwd());
378 for (const char** pEntry=entries; *pEntry!=NULL; pEntry++) {
379 const char* pObject=specificObjects?strstr(specificObjects, *pEntry):NULL;
381 // skip this entry if it is found in the list and either
382 // last one or separated by a blank
383 pObject+=strlen(*pEntry);
384 if (*pObject==0 || *pObject==' ') continue;
386 pSim->SetSpecificStorage(*pEntry, specificStorage.Data());
392 #ifndef HAVE_COMPILEINFO
393 extern "C" void CompileInfo(const char*& date, const char*& time)
395 // the fall back compile info of the HLTsim library
396 // this is not up-to-date if other files have been changed and recompiled
397 date=__DATE__; time=__TIME__;