]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/sim/AliHLTSimulation.cxx
added cutoff parameter in z direction to ignore clusters of large z (Gaute)
[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           fpRawReader->SelectEvents(7);
127         }
128         if (fpRawReader) {
129             fpRawReader->RewindEvents();
130             int count=0;
131             for (; fpRawReader->NextEvent(); count++);
132             if (count!=pRunLoader->GetNumberOfEvents()) {
133               AliError(Form("mismatch in event count: runloader %d, rawreader %d; ignoring rawreader", 
134                             pRunLoader->GetNumberOfEvents(), count));
135               count=0;
136             }
137             if (count>0) {
138               fpRawReader->RewindEvents();
139               fpRawReader->NextEvent();
140             } else {
141               delete fpRawReader;
142               fpRawReader=NULL;
143             }
144         }
145       } else if (token.Contains("writerawfiles=")) {
146         if (!token.ReplaceAll("writerawfiles=", "").Contains("HLT")) {
147           AliHLTOUTComponent::ClearGlobalOption(AliHLTOUTComponent::kWriteRawFiles);
148         }
149       } else {
150         if (sysOp.Length()>0) sysOp+=" ";
151         sysOp+=token;
152       }
153     }
154     delete pTokens;
155   }
156
157   // init solenoid field
158   Bool_t bUniformField=kTRUE;
159   AliTracker::SetFieldMap(pRunLoader->GetAliRun()->Field(),bUniformField);
160   Double_t solenoidBz=AliTracker::GetBz();
161   AliCDBManager* man = AliCDBManager::Instance();
162   if (man && man->IsDefaultStorageSet())
163   {
164     const char* cdbSolenoidPath="HLT/ConfigHLT/SolenoidBz";
165     int runNo=pRunLoader->GetHeader()->GetRun();
166     TString cdbSolenoidParam;
167     cdbSolenoidParam.Form("-solenoidBz %f", solenoidBz);
168
169     // check if the entry is already there
170     AliCDBEntry *pEntry = man->Get(cdbSolenoidPath, runNo);
171     TObjString* pString=NULL;
172     if (pEntry) pString=dynamic_cast<TObjString*>(pEntry->GetObject());
173
174     if (!pEntry || !pString || pString->GetString().CompareTo(cdbSolenoidParam)!=0) {
175       TObjString obj(cdbSolenoidParam);
176       AliCDBPath cdbSolenoidEntry(cdbSolenoidPath);
177       AliCDBId cdbSolenoidId(cdbSolenoidEntry, runNo, runNo);
178       AliCDBMetaData cdbMetaData;
179       man->Put(&obj, cdbSolenoidId, &cdbMetaData);
180     }
181   }
182
183   // scan options
184   if (fpSystem->ScanOptions(sysOp.Data())<0) {
185     AliError("error setting options for HLT system");
186     return -EINVAL;     
187   }
188
189   if (!fpSystem->CheckStatus(AliHLTSystem::kReady)) {
190     if ((fpSystem->Configure(pRunLoader))<0) {
191       AliError("error during HLT system configuration");
192       return -EFAULT;
193     }
194   }
195
196   return 0;
197 }
198
199
200 int AliHLTSimulation::Run(AliRunLoader* pRunLoader)
201 {
202   // HLT reconstruction for simulated data  
203   if(!pRunLoader) {
204     AliError("Missing RunLoader! 0x0");
205     return -EINVAL;
206   }
207
208   int nEvents = pRunLoader->GetNumberOfEvents();
209   int iResult=0;
210
211   if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
212     AliError("HLT system in error state");
213     return -EFAULT;
214   }
215
216   // Note: the rawreader is already placed at the first event
217   if ((iResult=fpSystem->Reconstruct(1, pRunLoader, fpRawReader))>=0) {
218     fpSystem->FillESD(0, pRunLoader, NULL);
219     for (int i=1; i<nEvents; i++) {
220       if (fpRawReader && !fpRawReader->NextEvent()) {
221         AliError("mismatch in event count, rawreader corrupted");
222         break;
223       }
224       fpSystem->Reconstruct(1, pRunLoader, fpRawReader);
225       fpSystem->FillESD(i, pRunLoader, NULL);
226     }
227     // send specific 'event' to execute the stop sequence
228     fpSystem->Reconstruct(0, NULL, NULL);
229   }
230   return iResult;
231 }
232
233
234 AliHLTSimulation* AliHLTSimulationCreateInstance()
235 {
236   // see header file for function documentation
237   return AliHLTSimulation::CreateInstance();
238 }
239
240 int AliHLTSimulationDeleteInstance(AliHLTSimulation* pSim)
241 {
242   // see header file for function documentation
243   return AliHLTSimulation::DeleteInstance(pSim);
244 }
245
246 int AliHLTSimulationInit(AliHLTSimulation* pSim, AliRunLoader* pRunLoader, const char* options)
247 {
248   assert(pSim!=NULL);
249   if (pSim) {
250     return pSim->Init(pRunLoader, options);
251   }
252   return -ENODEV;
253 }
254
255 int AliHLTSimulationRun(AliHLTSimulation* pSim, AliRunLoader* pRunLoader)
256 {
257   assert(pSim!=NULL);
258   if (pSim) {
259     return pSim->Run(pRunLoader);
260   }
261   return -ENODEV;
262 }
263
264 int AliHLTSimulationGetLibraryVersion()
265 {
266   // see header file for function documentation
267   return LIBHLTSIM_VERSION;
268 }