]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/sim/AliHLTSimulation.cxx
scanning of handlers for HLTOUT blocks added
[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 "AliRunLoader.h"
31 #include "AliHLTSystem.h"
32 #include "AliRawReaderFile.h"
33 #include "AliRawReaderDate.h"
34 #include "AliRawReaderRoot.h"
35
36 #if ALIHLTSIMULATION_LIBRARY_VERSION != LIBHLTSIM_VERSION
37 #error library version in header file and lib*.pkg do not match
38 #endif
39
40 /** ROOT macro for the implementation of ROOT specific class methods */
41 ClassImp(AliHLTSimulation);
42
43 AliHLTSimulation::AliHLTSimulation()
44   :
45   fOptions(),
46   fpSystem(NULL),
47   fpRawReader(NULL)
48 {
49   // see header file for class documentation
50   // or
51   // refer to README to build package
52   // or
53   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
54 }
55
56 AliHLTSimulation::~AliHLTSimulation()
57 {
58   // see header file for function documentation
59   if (fpSystem) {
60     delete fpSystem;
61   }
62   fpSystem=NULL;
63   if (fpRawReader) {
64     delete fpRawReader;
65   }
66   fpRawReader=NULL;
67 }
68
69 AliHLTSimulation* AliHLTSimulation::CreateInstance()
70 {
71   // see header file for function documentation
72   return new AliHLTSimulation;
73 }
74
75 int AliHLTSimulation::DeleteInstance(AliHLTSimulation* pSim)
76 {
77   // see header file for function documentation
78   assert(pSim!=NULL);
79   delete pSim;
80   return 0;
81 }
82
83 int AliHLTSimulation::Init(AliRunLoader* pRunLoader, const char* options)
84 {
85   // init the simulation
86   fOptions=options;
87   TString sysOp;
88
89   if (!fpSystem) fpSystem=new AliHLTSystem;
90   if (!fpSystem) {
91     AliError("can not create AliHLTSystem object");
92     return -ENOMEM;
93   }
94   if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
95     AliError("HLT system in error state");
96     return -EFAULT;
97   }
98
99   // scan options for specific entries
100   TObjArray* pTokens=fOptions.Tokenize(" ");
101   if (pTokens) {
102     int iEntries=pTokens->GetEntries();
103     for (int i=0; i<iEntries; i++) {
104       TString token=(((TObjString*)pTokens->At(i))->GetString());
105       if (token.Contains("rawfile=")) {
106         TString param=token.ReplaceAll("rawfile=", "");
107         if (param.EndsWith("/")) {
108           AliInfo(Form("creating AliRawReaderFile (%s)", param.Data()));
109           fpRawReader = new AliRawReaderFile(param);
110         } else if (param.EndsWith(".root")) {
111           AliInfo(Form("creating AliRawReaderRoot (%s)", param.Data()));
112           fpRawReader = new AliRawReaderRoot(param);
113         } else if (!param.IsNull()) {
114           AliInfo(Form("creating AliRawReaderDate (%s)", param.Data()));
115           fpRawReader = new AliRawReaderDate(param);
116           fpRawReader->SelectEvents(7);
117         }
118         if (fpRawReader) {
119             fpRawReader->RewindEvents();
120             int count=0;
121             for (; fpRawReader->NextEvent(); count++);
122             if (count!=pRunLoader->GetNumberOfEvents()) {
123               AliError(Form("missmatch in event count: runloader %d, rawreader %d; ignoring rawreader", 
124                             pRunLoader->GetNumberOfEvents(), count));
125               count=0;
126             }
127             if (count>0) {
128               fpRawReader->RewindEvents();
129               fpRawReader->NextEvent();
130             } else {
131               delete fpRawReader;
132               fpRawReader=NULL;
133             }
134         }
135       } else {
136         if (sysOp.Length()>0) sysOp+=" ";
137         sysOp+=token;
138       }
139     }
140     delete pTokens;
141   }
142
143   // scan options
144   if (fpSystem->ScanOptions(sysOp.Data())<0) {
145     AliError("error setting options for HLT system");
146     return -EINVAL;     
147   }
148
149   if (!fpSystem->CheckStatus(AliHLTSystem::kReady)) {
150     if ((fpSystem->Configure(pRunLoader))<0) {
151       AliError("error during HLT system configuration");
152       return -EFAULT;
153     }
154   }
155
156   return 0;
157 }
158
159
160 int AliHLTSimulation::Run(AliRunLoader* pRunLoader)
161 {
162   // HLT reconstruction for simulated data  
163   if(!pRunLoader) {
164     AliError("Missing RunLoader! 0x0");
165     return -EINVAL;
166   }
167
168   int nEvents = pRunLoader->GetNumberOfEvents();
169   int iResult=0;
170
171   if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
172     AliError("HLT system in error state");
173     return -EFAULT;
174   }
175
176   // Note: the rawreader is already placed at the first event
177   if ((iResult=fpSystem->Reconstruct(1, pRunLoader, fpRawReader))>=0) {
178     for (int i=1; i<nEvents; i++) {
179       if (fpRawReader && !fpRawReader->NextEvent()) {
180         AliError("missmatch in event count, rawreader corrupted");
181         break;
182       }
183       fpSystem->Reconstruct(1, pRunLoader, fpRawReader);
184     }
185     // send specific 'event' to execute the stop sequence
186     fpSystem->Reconstruct(0, NULL, NULL);
187   }
188   return iResult;
189 }
190
191
192 AliHLTSimulation* AliHLTSimulationCreateInstance()
193 {
194   // see header file for function documentation
195   return AliHLTSimulation::CreateInstance();
196 }
197
198 int AliHLTSimulationDeleteInstance(AliHLTSimulation* pSim)
199 {
200   // see header file for function documentation
201   return AliHLTSimulation::DeleteInstance(pSim);
202 }
203
204 int AliHLTSimulationInit(AliHLTSimulation* pSim, AliRunLoader* pRunLoader, const char* options)
205 {
206   assert(pSim!=NULL);
207   if (pSim) {
208     return pSim->Init(pRunLoader, options);
209   }
210   return -ENODEV;
211 }
212
213 int AliHLTSimulationRun(AliHLTSimulation* pSim, AliRunLoader* pRunLoader)
214 {
215   assert(pSim!=NULL);
216   if (pSim) {
217     return pSim->Run(pRunLoader);
218   }
219   return -ENODEV;
220 }
221
222 int AliHLTSimulationGetLibraryVersion()
223 {
224   // see header file for function documentation
225   return LIBHLTSIM_VERSION;
226 }