]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/MUON/src/AliRoot/MicrodHLT.cxx
Changes to compile on solarisCC5
[u/mrichter/AliRoot.git] / HLT / MUON / src / AliRoot / MicrodHLT.cxx
CommitLineData
8356cc1d 1////////////////////////////////////////////////////////////////////////////////
2//
3// Author: Artur Szostak
4// Email: artur@alice.phy.uct.ac.za | artursz@iafrica.com
5//
6////////////////////////////////////////////////////////////////////////////////
7
8#include "AliRoot/MicrodHLT.hpp"
9
10#include "TMethodCall.h"
11
12#include "Version/Version.hpp"
13#include "Clustering/ClusterFinder.hpp"
14#include "Clustering/CenterOfGravityFinder.hpp"
15#include "Tracking/Tracker.hpp"
16#include "Tracking/MansoTracker.hpp"
17#include "Decision/DecisionMaker.hpp"
18#include "AliRoot/convert.hpp"
19#include "AliRoot/ClusterFinderProxy.hpp"
20#include "AliRoot/TrackerProxy.hpp"
21
22#include "Utils.hpp"
23#include "new.hpp"
24
25
26namespace dHLT
27{
28
29using namespace dHLT::AliRoot;
30
31
32class MicroFramework : public Tracking::TrackerCallback
33{
34public:
35
36 virtual void RequestClusters(
37 Tracking::Tracker* tracker,
cbee67e7 38 const Float /*left*/, const Float /*right*/, const Float /*bottom*/, const Float /*top*/,
8356cc1d 39 const ChamberID chamber, const void* tag
40 )
41 {
42 Assert( 0 <= chamber and chamber <= 10 );
43 DebugMsg(2, "RequestClusters: tag = " << tag);
44 register void* ctag = const_cast<void*>(tag); // We never modify tag so this is OK.
45 if (clusters[chamber] != NULL)
46 tracker->ReturnClusters(ctag, clusters[chamber], clustercount[chamber]);
47 tracker->EndOfClusters(ctag);
48 };
49
50
cbee67e7 51 virtual void EndOfClusterRequests(Tracking::Tracker* /*tracker*/)
8356cc1d 52 {
53 DebugMsg(2, "EndOfClusterRequests");
54 // We can ignore this. Nothing special to do here.
55 };
56
57
58 virtual void FoundTrack(Tracking::Tracker* tracker)
59 {
60 DebugMsg(2, "FoundTrack");
61
62 // Fetch the track data from the tracker.
63 dHLT::Track newtrack;
64 tracker->FillTrackData(newtrack);
65
66 // Don't forget to fill the trigger ID number, this is not done by the tracker.
67 newtrack.triggerid = currenttriggernumber;
68
69 *trackoutput->AddTrack() = Convert(newtrack);
70 };
71
72
73 virtual void NoTrackFound(Tracking::Tracker* tracker)
74 {
75 DebugMsg(2, "NoTrackFound");
76 // Again nothing special to do here. The allocated memory is released
77 // in the Run method.
78 };
79
80
81 void Run(
82 const AliMUONHLT::TriggerSource* triggersource,
83 const AliMUONHLT::ClusterSource* clustersource,
84 AliMUONHLT::TrackSink* tracksink,
85 Tracking::Tracker* tracker
86 )
87 {
88 if (not triggersource->GetFirstEvent()) return;
89 while (triggersource->MoreEvents())
90 {
91 Run(triggersource, clustersource, tracksink, tracker, triggersource->CurrentEvent());
92 triggersource->GetNextEvent();
93 };
94 };
95
96
97 void Run(
98 const AliMUONHLT::TriggerSource* triggersource,
99 const AliMUONHLT::ClusterSource* clustersource,
100 AliMUONHLT::TrackSink* tracksink,
101 Tracking::Tracker* tracker, const Int eventnumber
102 )
103 {
104 // Tell the tracker to make callbacks to this framework object.
105 tracker->SetCallback(this);
106 trackoutput = tracksink;
107 trackoutput->SetNames(triggersource); // Want the file and folder names to correspond.
108
109 CreateClusterBlocks(clustersource, eventnumber);
110 try
111 {
112 trackoutput->AddEvent(eventnumber);
113 trackoutput->AddBlock();
114 ProcessTriggers(triggersource, tracker);
115 }
116 finally
117 (
118 FreeClusterBlocks();
119 );
120 };
121
122
123private:
124
125 void CountClusterPoints(const AliMUONHLT::ClusterSource* cs)
126 {
127 for (Int i = 0; i < 10; i++)
128 clustercount[i] = 0;
129
130 cs->GetFirstBlock();
131 while (cs->MoreBlocks())
132 {
133 Int chamber = cs->Chamber();
134 if (0 <= chamber and chamber < 10)
135 {
136 clustercount[chamber] += cs->NumberOfClusters();
137 };
138 cs->GetNextBlock();
139 };
140 };
141
142
143 void CreateClusterBlocks(const AliMUONHLT::ClusterSource* cs, const Int eventnumber)
144 {
145 // Must select the proper event before counting or filling the arrays.
146 if ( not cs->GetEvent(eventnumber) ) return;
147
148 CountClusterPoints(cs);
149
150 UInt currentcount[10];
151 for (Int i = 0; i < 10; i++)
152 {
153 // Initialise currentcount.
154 currentcount[i] = 0;
155
156 // Allocate arrays.
157 if (clustercount[i] > 0)
158 clusters[i] = new ClusterPoint[ clustercount[i] ];
159 else
160 clusters[i] = NULL;
161 };
162
163 // Copy all the cluster data into arrays.
164 cs->GetFirstBlock();
165 while (cs->MoreBlocks())
166 {
167 Int chamber = cs->Chamber();
168 if (0 <= chamber and chamber < 10)
169 {
170 cs->GetFirstCluster();
171 while (cs->MoreClusters())
172 {
173 ClusterPoint newpoint;
174 cs->FetchCluster(newpoint.x, newpoint.y);
175 clusters[chamber][currentcount[chamber]++] = newpoint;
176 cs->GetNextCluster();
177 };
178 };
179 cs->GetNextBlock();
180 };
181 };
182
183
184 void FreeClusterBlocks()
185 {
186 for (Int i = 0; i < 10; i++)
187 {
188 if (clusters[i] != NULL)
189 delete [] clusters[i];
190 };
191 };
192
193
194 void ProcessTriggers(const AliMUONHLT::TriggerSource* ts, Tracking::Tracker* tracker)
195 {
196 // The proper event must be selected before calling this method.
197
198 ts->GetFirstBlock();
199 while (ts->MoreBlocks())
200 {
201 ts->GetFirstTrigger();
202 while (ts->MoreTriggers())
203 {
204 const AliMUONHLT::TriggerRecord* trigdata = ts->GetTrigger();
205 Assert( trigdata != NULL );
206 currenttriggernumber = (UInt)trigdata->TriggerNumber();
207
208 TriggerRecord trigger = Convert(*trigdata);
209
210 DebugMsg(2, "Finding track:");
211 tracker->FindTrack(trigger);
212
213 DebugMsg(2, "Reset tracker.");
214 tracker->Reset();
215
216 ts->GetNextTrigger();
217 };
218 ts->GetNextBlock();
219 };
220 };
221
222
223 UInt clustercount[10];
224 ClusterPoint* clusters[10];
225
226 AliMUONHLT::TrackSink* trackoutput; // The current track output object.
227 UInt currenttriggernumber; // The current trigger, trigger number to use.
228};
229
230
cbee67e7 231} // dHLT
8356cc1d 232
233
234////////////////////////////////////////////////////////////////////////////////
235
236
cbee67e7 237ClassImp(AliMUONHLT::MicrodHLT)
8356cc1d 238
239namespace AliMUONHLT
240{
241
242
243TString Version()
244{
245 TString str = dHLT::VersionString();
246 return str;
247};
248
249UInt_t MajorVersion()
250{
251 return dHLT::MajorVersion();
252};
253
254UInt_t MinorVersion()
255{
256 return dHLT::MinorVersion();
257};
258
259UInt_t BuildNumber()
260{
261 return dHLT::BuildNumber();
262};
263
264
265MicrodHLT::MicrodHLT() : TObject()
266{
267 fTriggerSource = NULL;
268 fClusterSource = NULL;
269 fTrackSink = NULL;
270 fClusterFinder = NULL;
271 fTracker = NULL;
272};
273
274
275MicrodHLT::~MicrodHLT()
276{
277 // Nothing to do here.
278};
279
280
281void MicrodHLT::SetTriggerSource(const TriggerSource* source)
282{
283 fTriggerSource = const_cast<TriggerSource*>( source );
284};
285
286void MicrodHLT::SetClusterSource(const ClusterSource* source)
287{
288 fClusterSource = const_cast<ClusterSource*>( source );
289};
290
291
292void MicrodHLT::Run()
293{
294 DebugMsg(1, "Run");
295
296 //dHLT::Clustering::ClusterFinder* clusterfinder;
297 //dHLT::Decision::DecisionMaker* decisionmaker;
298 //dHLT::Tracking::Tracker* tracker;
299
300 if (fTriggerSource == NULL)
301 {
302 Error("Run", "The trigger source was not set.");
303 return;
304 };
305 if (fClusterSource == NULL)
306 {
307 Error("Run", "The cluster source was not set.");
308 return;
309 };
310 if (fTrackSink == NULL)
311 {
312 Error("Run", "The track output sink was not set.");
313 return;
314 };
315
316 if (fTriggerSource->FileName() != fClusterSource->FileName() or
317 fTriggerSource->FolderName() != fClusterSource->FolderName())
318 {
319 Warning("Run", "The file and folder names of the trigger source and cluster source do not correspond.");
320 };
321
322 dHLT::Clustering::ClusterFinder* clusterfinder = NULL;
323 dHLT::Tracking::Tracker* tracker = NULL;
324 try
325 {
326 // Assign the dHLT cluster finder object. If the fClusterFinder field is
327 // not set then use the default CenterOfGravityFinder.
328 if (fClusterFinder == NULL)
329 {
330 clusterfinder = new dHLT::Clustering::CenterOfGravityFinder();
331 }
332 else
333 {
334 dHLT::AliRoot::ClusterFinderProxy* clusterfinderproxy
335 = new dHLT::AliRoot::ClusterFinderProxy(fClusterFinder);
336 fClusterFinder->SetCallback(clusterfinderproxy);
337 clusterfinder = clusterfinderproxy;
338 };
339
340 // Assign the dHLT tracker object. If the fTracker field was not set just
341 // use the default MansoTracker implementation.
342 if (fTracker == NULL)
343 {
344 tracker = new dHLT::Tracking::MansoTracker();
345 }
346 else
347 {
348 dHLT::AliRoot::TrackerProxy* trackerproxy = new dHLT::AliRoot::TrackerProxy(fTracker);
349 fTracker->SetCallback(trackerproxy);
350 tracker = trackerproxy;
351 };
352
353 dHLT::MicroFramework framework;
354 framework.Run(fTriggerSource, fClusterSource, fTrackSink, tracker);
355 }
356 finally
357 (
358 if (tracker != NULL) delete tracker;
359 if (clusterfinder != NULL) delete clusterfinder;
360 );
361};
362
363
364void MicrodHLT::DebugLevel(Int_t value)
365{
366 DebugCode( dHLT::DebugLevel = value );
367};
368
369
370Int_t MicrodHLT::DebugLevel()
371{
372#ifdef DEBUG
373 return dHLT::DebugLevel;
374#else // DEBUG
375 return -1;
376#endif // DEBUG
377};
378
379
cbee67e7 380} // AliMUONHLT