]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/sim/AliHLTSimulation.cxx
add fallback compile info of library
[u/mrichter/AliRoot.git] / HLT / sim / AliHLTSimulation.cxx
1 // $Id$
2
3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project        * 
5 //* ALICE Experiment at CERN, All rights reserved.                         *
6 //*                                                                        *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
8 //*                  for The ALICE HLT Project.                            *
9 //*                                                                        *
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 //**************************************************************************
18
19 /** @file   AliHLTSimulation.cxx
20     @author Matthias Richter
21     @date   
22     @brief  Binding class for HLT simulation in AliRoot. */
23
24 #include <cassert>
25 #include <cerrno>
26 #include "TObjArray.h"
27 #include "TObjString.h"
28 #include "AliHLTSimulation.h"
29 #include "AliLog.h"
30 #include "AliRun.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"
37 #include "AliCDBId.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"
45
46 #if ALIHLTSIMULATION_LIBRARY_VERSION != LIBHLTSIM_VERSION
47 #error library version in header file and lib*.pkg do not match
48 #endif
49
50 /** ROOT macro for the implementation of ROOT specific class methods */
51 ClassImp(AliHLTSimulation);
52
53 AliHLTSimulation::AliHLTSimulation()
54   :
55   fOptions(),
56   fpSystem(NULL),
57   fpRawReader(NULL)
58 {
59   // see header file for class documentation
60   // or
61   // refer to README to build package
62   // or
63   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
64 }
65
66 AliHLTSimulation::~AliHLTSimulation()
67 {
68   // see header file for function documentation
69   if (fpSystem) {
70     delete fpSystem;
71   }
72   fpSystem=NULL;
73   if (fpRawReader) {
74     delete fpRawReader;
75   }
76   fpRawReader=NULL;
77 }
78
79 AliHLTSimulation* AliHLTSimulation::CreateInstance()
80 {
81   // see header file for function documentation
82   return new AliHLTSimulation;
83 }
84
85 int AliHLTSimulation::DeleteInstance(AliHLTSimulation* pSim)
86 {
87   // see header file for function documentation
88   assert(pSim!=NULL);
89   delete pSim;
90   return 0;
91 }
92
93 int AliHLTSimulation::Init(AliRunLoader* pRunLoader, const char* options)
94 {
95   // init the simulation
96   fOptions=options;
97   TString sysOp;
98
99   if (!fpSystem) fpSystem=new AliHLTSystem;
100   if (!fpSystem) {
101     AliError("can not create AliHLTSystem object");
102     return -ENOMEM;
103   }
104   if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
105     AliError("HLT system in error state");
106     return -EFAULT;
107   }
108
109   // scan options for specific entries
110   TObjArray* pTokens=fOptions.Tokenize(" ");
111   if (pTokens) {
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);
126         }
127         if (fpRawReader) {
128             fpRawReader->RewindEvents();
129             int count=0;
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));
134               count=0;
135             }
136             if (count>0) {
137               fpRawReader->RewindEvents();
138               fpRawReader->NextEvent();
139             } else {
140               delete fpRawReader;
141               fpRawReader=NULL;
142             }
143         }
144       } else if (token.Contains("writerawfiles=")) {
145         if (!token.ReplaceAll("writerawfiles=", "").Contains("HLT")) {
146           AliHLTOUTComponent::ClearGlobalOption(AliHLTOUTComponent::kWriteRawFiles);
147         }
148       } else {
149         if (sysOp.Length()>0) sysOp+=" ";
150         sysOp+=token;
151       }
152     }
153     delete pTokens;
154   }
155
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())
162   {
163     const char* cdbSolenoidPath="HLT/ConfigHLT/SolenoidBz";
164     int runNo=pRunLoader->GetHeader()->GetRun();
165     TString cdbSolenoidParam;
166     cdbSolenoidParam.Form("-solenoidBz %f", solenoidBz);
167
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());
172
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);
179     }
180   }
181
182   // scan options
183   if (fpSystem->ScanOptions(sysOp.Data())<0) {
184     AliError("error setting options for HLT system");
185     return -EINVAL;     
186   }
187
188   if (!fpSystem->CheckStatus(AliHLTSystem::kReady)) {
189     if ((fpSystem->Configure(fpRawReader, pRunLoader))<0) {
190       AliError("error during HLT system configuration");
191       return -EFAULT;
192     }
193   }
194
195   return 0;
196 }
197
198
199 int AliHLTSimulation::Run(AliRunLoader* pRunLoader)
200 {
201   // HLT reconstruction for simulated data  
202   if(!pRunLoader) {
203     AliError("Missing RunLoader! 0x0");
204     return -EINVAL;
205   }
206
207   int nEvents = pRunLoader->GetNumberOfEvents();
208   int iResult=0;
209
210   if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
211     AliError("HLT system in error state");
212     return -EFAULT;
213   }
214
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");
221         break;
222       }
223       fpSystem->Reconstruct(1, pRunLoader, fpRawReader);
224       fpSystem->FillESD(i, pRunLoader, NULL);
225     }
226     // send specific 'event' to execute the stop sequence
227     fpSystem->Reconstruct(0, NULL, NULL);
228   }
229   return iResult;
230 }
231
232
233 AliHLTSimulation* AliHLTSimulationCreateInstance()
234 {
235   // see header file for function documentation
236   return AliHLTSimulation::CreateInstance();
237 }
238
239 int AliHLTSimulationDeleteInstance(AliHLTSimulation* pSim)
240 {
241   // see header file for function documentation
242   return AliHLTSimulation::DeleteInstance(pSim);
243 }
244
245 int AliHLTSimulationInit(AliHLTSimulation* pSim, AliRunLoader* pRunLoader, const char* options)
246 {
247   assert(pSim!=NULL);
248   if (pSim) {
249     return pSim->Init(pRunLoader, options);
250   }
251   return -ENODEV;
252 }
253
254 int AliHLTSimulationRun(AliHLTSimulation* pSim, AliRunLoader* pRunLoader)
255 {
256   assert(pSim!=NULL);
257   if (pSim) {
258     return pSim->Run(pRunLoader);
259   }
260   return -ENODEV;
261 }
262
263 int AliHLTSimulationGetLibraryVersion()
264 {
265   // see header file for function documentation
266   return LIBHLTSIM_VERSION;
267 }
268
269 extern "C" void AliHLTSimulationCompileInfo(const char*& date, const char*& time)
270 {
271   // the fall back compile info of the HLTsim library
272   // this is not up-to-date if other files have been changed and recompiled
273   date=__DATE__; time=__TIME__;
274   return;
275 }