]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONDataInterface.cxx
Update of the class ESDMuonFilter. New marcros for creating AOD with muon information...
[u/mrichter/AliRoot.git] / MUON / AliMUONDataInterface.cxx
CommitLineData
13985652 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$ */
48b32e42 17
48b32e42 18#include "AliMUONDataInterface.h"
e9bef706 19#include "AliMUONGeometryTransformer.h"
e8636ba0 20#include "AliMUONVDigit.h"
2060b217 21#include "AliMUONVCluster.h"
e8636ba0 22#include "AliMUONLocalTrigger.h"
23#include "AliMUONRegionalTrigger.h"
24#include "AliMUONGlobalTrigger.h"
e9bef706 25#include "AliMUONTriggerCircuit.h"
a202c2d2 26#include "AliMUONVClusterStore.h"
e9bef706 27#include "AliMUONVDigitStore.h"
e9bef706 28#include "AliMUONVTriggerStore.h"
c074480f 29#include "AliMpCDB.h"
e9bef706 30
e8636ba0 31#include "AliMpIntPair.h"
32#include "AliMpDEManager.h"
33#include "AliMpConstants.h"
a55f49a0 34#include "AliMpCDB.h"
e8636ba0 35
e9bef706 36#include "AliLoader.h"
37#include "AliLog.h"
e9bef706 38#include "AliRunLoader.h"
aa73f8fb 39#include "AliHeader.h"
40#include "AliCDBManager.h"
e9bef706 41
42#include <TError.h>
43#include <TParticle.h>
44#include <Riostream.h>
45#include <TFile.h>
a202c2d2 46#include <TList.h>
e9bef706 47#include <TNtuple.h>
48#include <TSystem.h>
e8636ba0 49#include <TIterator.h>
50#include <cstdlib>
51#include <cassert>
6d149c9e 52
3d1463c8 53//-----------------------------------------------------------------------------
85fec35d 54/// \class AliMUONDataInterface
55///
a202c2d2 56/// An easy to use interface to the MUON data data stored in
61fed964 57/// TreeS, TreeD and TreeR.
a202c2d2 58///
59/// For MC related information (i.e. TreeH, TreeK, TreeTR), see
60/// AliMUONMCDataInterface.
61///
85fec35d 62///
63/// This interface in not necessarily the fastest way to fetch the data but
64/// it is the easiest.
85fec35d 65///
e8636ba0 66/// \author Laurent Aphecetche, Subatech & Artur Szostak <artursz@iafrica.com> (University of Cape Town)
3d1463c8 67//-----------------------------------------------------------------------------
13985652 68
69/// \cond CLASSIMP
70ClassImp(AliMUONDataInterface)
71/// \endcond
48b32e42 72
e9bef706 73
74Int_t AliMUONDataInterface::fgInstanceCounter(0);
75
a202c2d2 76//______________________________________________________________________________
77AliMUONDataInterface::AliMUONDataInterface(const char* filename)
e9bef706 78: TObject(),
79fLoader(0x0),
80fDigitStore(0x0),
81fTriggerStore(0x0),
82fClusterStore(0x0),
e9bef706 83fCurrentEvent(-1),
e8636ba0 84fIsValid(kFALSE),
85fCurrentIteratorType(kNoIterator),
86fCurrentIndex(-1),
87fDataX(-1),
88fDataY(-1),
89fIterator(0x0)
48b32e42 90{
a202c2d2 91 /// ctor
92 /// @param filename should be the full path to a valid galice.root file
93
e9bef706 94 ++fgInstanceCounter;
95
88c5d53f 96 if ( AliCDBManager::Instance() != NULL &&
97 AliCDBManager::Instance()->GetDefaultStorage() == NULL ) {
98 AliFatal("CDB default storage not defined.");
ae9e8f66 99 }
100
e9bef706 101 Open(filename);
a55f49a0 102
103 // Load mapping
104 if ( ! AliMpCDB::LoadDDLStore() ) {
105 AliFatal("Could not access mapping from OCDB !");
106 }
925e6570 107}
48b32e42 108
a202c2d2 109//______________________________________________________________________________
48b32e42 110AliMUONDataInterface::~AliMUONDataInterface()
111{
a202c2d2 112 /// dtor
e8636ba0 113 ResetStores();
114 if ( fLoader != 0x0 )
e9bef706 115 {
116 delete fLoader->GetRunLoader();
117 }
118 --fgInstanceCounter;
a202c2d2 119}
48b32e42 120
e8636ba0 121//______________________________________________________________________________
122AliMUONVDigitStore*
123AliMUONDataInterface::DigitStore(Int_t event)
124{
125 /// Return digitStore for a given event.
126 /// Return 0x0 if event not found.
127 /// Returned pointer should not be deleted
128
129 if (not IsValid()) return 0x0;
130 if (event == fCurrentEvent and fDigitStore != 0x0) return fDigitStore;
131
132 ResetStores();
133 if (not LoadEvent(event)) return 0x0;
134
135 fLoader->LoadDigits();
136
137 TTree* treeD = fLoader->TreeD();
138 if (treeD == 0x0)
139 {
140 AliError("Could not get treeD");
141 return 0x0;
142 }
143
144 fDigitStore = AliMUONVDigitStore::Create(*treeD);
145 if ( fDigitStore != 0x0 )
146 {
147 fDigitStore->Clear();
148 fDigitStore->Connect(*treeD);
149 treeD->GetEvent(0);
150 }
151
152 fLoader->UnloadDigits();
153
154 return fDigitStore;
155}
156
a202c2d2 157//______________________________________________________________________________
158AliMUONVClusterStore*
e9bef706 159AliMUONDataInterface::ClusterStore(Int_t event)
a202c2d2 160{
e9bef706 161 /// Return clusterStore for a given event.
162 /// Return 0x0 if event not found.
163 /// Returned pointer should not be deleted
164
e8636ba0 165 if (not IsValid()) return 0x0;
166 if (event == fCurrentEvent and fClusterStore != 0x0) return fClusterStore;
167
168 ResetStores();
169 if (not LoadEvent(event)) return 0x0;
e9bef706 170
171 fLoader->LoadRecPoints();
172
173 TTree* treeR = fLoader->TreeR();
e8636ba0 174 if (treeR == 0x0)
e9bef706 175 {
176 AliError("Could not get treeR");
177 return 0x0;
178 }
179
e8636ba0 180 fClusterStore = AliMUONVClusterStore::Create(*treeR);
181 if ( fClusterStore != 0x0 )
e9bef706 182 {
183 fClusterStore->Clear();
184 fClusterStore->Connect(*treeR);
185 treeR->GetEvent(0);
186 }
187
188 fLoader->UnloadRecPoints();
189
190 return fClusterStore;
191}
3455463a 192
e8636ba0 193//_____________________________________________________________________________
194AliMUONVTriggerStore*
195AliMUONDataInterface::TriggerStore(Int_t event, const char* treeLetter)
196{
197 /// Return the triggerStore for a given event.
198 /// Return 0x0 if event not found.
199 /// Returned pointer should not be deleted
200 /// treeLetter can be R or D to tell from which tree to read the information
201
202 if (not IsValid()) return 0x0;
203 if (event == fCurrentEvent and fTriggerStore != 0x0) return fTriggerStore;
204
205 ResetStores();
206 if (not LoadEvent(event)) return 0x0;
207
208 TTree* tree(0x0);
209
210 TString stree(treeLetter);
211 stree.ToUpper();
212
213 if ( stree == "D" )
214 {
215 fLoader->LoadDigits();
216 tree = fLoader->TreeD();
217 }
218 else if ( stree == "R" )
219 {
220 fLoader->LoadRecPoints();
221 tree = fLoader->TreeR();
222 }
223
224 if ( tree == 0x0 )
225 {
226 AliError(Form("Could not get tree%s",treeLetter));
227 return 0x0;
228 }
229
230 fTriggerStore = AliMUONVTriggerStore::Create(*tree);
231 if ( fTriggerStore != 0x0 )
232 {
233 fTriggerStore->Clear();
234 fTriggerStore->Connect(*tree);
235 tree->GetEvent(0);
236 }
237
238 if ( stree == "D" )
239 {
240 fLoader->UnloadDigits();
241 }
242 else if ( stree == "R" )
243 {
244 fLoader->UnloadRecPoints();
245 }
246
247 return fTriggerStore;
925e6570 248}
48b32e42 249
a202c2d2 250//______________________________________________________________________________
251void
e9bef706 252AliMUONDataInterface::DumpDigits(Int_t event, Bool_t sorted)
48b32e42 253{
e9bef706 254 /// Dump the digits for a given event, sorted if so required
255 DigitStore(event);
e8636ba0 256 if ( fDigitStore != 0x0 )
e9bef706 257 {
258 if ( sorted )
259 {
260 DumpSorted(*fDigitStore);
261 }
262 else
263 {
264 fDigitStore->Print();
265 }
266 }
925e6570 267}
48b32e42 268
a202c2d2 269//______________________________________________________________________________
e9bef706 270void
271AliMUONDataInterface::DumpRecPoints(Int_t event, Bool_t sorted)
6d149c9e 272{
e9bef706 273 /// Dump the recpoints for a given event, sorted if so required
274 ClusterStore(event);
e8636ba0 275 if ( fClusterStore != 0x0 )
e9bef706 276 {
277 if ( sorted )
278 {
279 DumpSorted(*fClusterStore);
280 }
281 else
282 {
283 fClusterStore->Print();
284 }
285 }
6d149c9e 286}
287
e9bef706 288//_____________________________________________________________________________
289void
290AliMUONDataInterface::DumpSorted(const AliMUONVStore& store) const
6d149c9e 291{
e9bef706 292 /// Dump the given store, in sorted order
a202c2d2 293
e9bef706 294 TIter next(store.CreateIterator());
a202c2d2 295 TObject* object;
e9bef706 296 TList list;
297 list.SetOwner(kFALSE);
a202c2d2 298
e9bef706 299 while ( ( object = next() ) )
a202c2d2 300 {
e9bef706 301 list.Add(object);
a202c2d2 302 }
303
e9bef706 304 list.Sort();
305
306 list.Print();
a202c2d2 307}
308
e9bef706 309//_____________________________________________________________________________
310void
311AliMUONDataInterface::DumpTrigger(Int_t event, const char* treeLetter)
312{
313 /// Dump trigger for a given event from a given tree (if event>=0)
314 /// or loop over all events and build a trigger ntuple if event<0
315 /// treeLetter can be R or D to tell from which tree to read the information
a202c2d2 316
e9bef706 317 if ( event < 0 )
318 {
319 NtupleTrigger(treeLetter);
a202c2d2 320 }
321 else
322 {
e9bef706 323 TriggerStore(event,treeLetter);
a202c2d2 324
e8636ba0 325 if ( fTriggerStore != 0x0 )
e9bef706 326 {
327 fTriggerStore->Print();
328 }
329 }
a202c2d2 330}
6d149c9e 331
e9bef706 332//_____________________________________________________________________________
a202c2d2 333void
e9bef706 334AliMUONDataInterface::NtupleTrigger(const char* treeLetter)
48b32e42 335{
e9bef706 336 //// Loop over events to build trigger ntuples
337 ///
338
339 TString sTreeLetter(treeLetter);
340 sTreeLetter.ToUpper();
341
342 if ( sTreeLetter != "R" && sTreeLetter != "D" )
343 {
344 AliError(Form("Cannot handle tree%s. Use D or R",treeLetter));
345 return;
346 }
347
348 // book ntuples
349 TNtuple tupleGlo("TgtupleGlo","Global Trigger Ntuple",
350 "ev:slpt:shpt:uplpt:uphpt:lplpt:lplpt");
351 TNtuple tupleLoc("TgtupleLoc","Local Trigger Ntuple",
352 "ev:LoCircuit:LoStripX:LoDev:StripY:LoLpt:LoHpt:y11:y21:x11");
353
354 // initialize counters
355 Int_t sLowpt=0;
356 Int_t sHighpt=0;
357 Int_t uSLowpt=0;
358 Int_t uSHighpt=0;
359 Int_t lSLowpt=0;
360 Int_t lSHighpt=0;
361
d3acfadf 362 AliMUONGeometryTransformer transformer;
ef4cb4f1 363 transformer.LoadGeometryData(Form("%s/geometry.root",
e9bef706 364 gSystem->DirName(fLoader->GetRunLoader()->GetFileName())));
a55f49a0 365 AliMUONTriggerCircuit triggerCircuit(&transformer);
e9bef706 366
367 // select output file name from selected Tree
368 Char_t fileNameOut[30];
369 if (sTreeLetter == "D")
370 {
371 AliInfo(Form("reading from Digits\n"));
372 sprintf(fileNameOut,"TriggerCheckFromDigits.root");
373 }
374 else if (sTreeLetter == "R")
375 {
376 AliInfo(Form("reading from RecPoints\n"));
377 sprintf(fileNameOut,"TriggerCheckFromRP.root");
378 }
379
380 // loop on events
381 Int_t nevents = NumberOfEvents();
382
383 for (Int_t ievent=0; ievent<nevents; ++ievent)
384 {
385 if (ievent%100==0) AliInfo(Form("Processing event %d\n",ievent));
386
8af099d3 387 AliMUONVTriggerStore* triggerStore = TriggerStore(ievent,treeLetter);
e9bef706 388
389 if (!triggerStore)
390 {
391 AliError(Form("Could not read %s from tree%s","Trigger",treeLetter));
392 return;
393 }
394
395 // get global trigger info
396 AliMUONGlobalTrigger* gloTrg = triggerStore->Global();
397 sLowpt+=gloTrg->SingleLpt();
398 sHighpt+=gloTrg->SingleHpt();
399 uSLowpt+=gloTrg->PairUnlikeLpt();
400 uSHighpt+=gloTrg->PairUnlikeHpt();
401 lSLowpt+=gloTrg->PairLikeLpt();
402 lSHighpt+=gloTrg->PairLikeHpt();
403
404 // loop on local triggers
405 TIter next(triggerStore->CreateIterator());
406 AliMUONLocalTrigger* locTrg(0x0);
407 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
408 {
d72d7b9e 409 Bool_t xTrig=locTrg->IsTrigX();
410 Bool_t yTrig=locTrg->IsTrigY();
e9bef706 411
412 if (xTrig && yTrig)
413 { // fill ntuple if trigger in X and Y
414 tupleLoc.Fill(ievent,locTrg->LoCircuit(),
415 locTrg->LoStripX(),
416 locTrg->LoDev(),
417 locTrg->LoStripY(),
418 locTrg->LoLpt(),
419 locTrg->LoHpt(),
420 triggerCircuit.GetY11Pos(locTrg->LoCircuit(),locTrg->LoStripX()),
421 triggerCircuit.GetY21Pos(locTrg->LoCircuit(),locTrg->LoStripX()+locTrg->LoDev()+1),
422 triggerCircuit.GetX11Pos(locTrg->LoCircuit(),locTrg->LoStripY()));
423 }
424 tupleGlo.Fill(ievent,gloTrg->SingleLpt(),gloTrg->SingleHpt(),
425 gloTrg->PairUnlikeLpt(),gloTrg->PairUnlikeHpt(),
426 gloTrg->PairLikeLpt(),gloTrg->PairLikeHpt());
427 } // end of loop on local triggers
428 } // end of loop on events
429
430 // print info and store ntuples
431 printf("\n");
432 printf("=============================================\n");
433 printf("================ SUMMARY ==================\n");
434 printf("\n");
435 printf("Total number of events processed %d \n",nevents);
436 printf("\n");
437 printf(" Global Trigger output Low pt High pt\n");
438 printf(" number of Single :\t");
439 printf("%i\t%i\t",sLowpt,sHighpt);
440 printf("\n");
441 printf(" number of UnlikeSign pair :\t");
442 printf("%i\t%i\t",uSLowpt,uSHighpt);
443 printf("\n");
444 printf(" number of LikeSign pair :\t");
445 printf("%i\t%i\t",lSLowpt,lSHighpt);
446 printf("\n");
447 printf("=============================================\n");
448 fflush(stdout);
449
450 TFile myFile(fileNameOut, "RECREATE");
451 tupleGlo.Write();
452 tupleLoc.Write();
453 myFile.Close();
925e6570 454}
48b32e42 455
e9bef706 456//_____________________________________________________________________________
e8636ba0 457Bool_t
e9bef706 458AliMUONDataInterface::LoadEvent(Int_t event)
48b32e42 459{
e9bef706 460 /// Load event if different from the current one.
e8636ba0 461 /// Returns kFALSE on error and kTRUE if the event was loaded.
462
463 assert( IsValid() );
464
465 AliDebug(1,Form("Loading event %d using runLoader %p",event,fLoader->GetRunLoader()));
466 if (fLoader->GetRunLoader()->GetEvent(event) == 0)
e9bef706 467 {
468 fCurrentEvent = event;
e8636ba0 469 return kTRUE;
e9bef706 470 }
e8636ba0 471 else
472 return kFALSE;
925e6570 473}
48b32e42 474
a202c2d2 475//______________________________________________________________________________
e9bef706 476Int_t
477AliMUONDataInterface::NumberOfEvents() const
a202c2d2 478{
e9bef706 479 /// Number of events in the current galice.root file we're attached to
e8636ba0 480 if (not IsValid()) return -1;
e9bef706 481 return fLoader->GetRunLoader()->GetNumberOfEvents();
a202c2d2 482}
48b32e42 483
e9bef706 484//_____________________________________________________________________________
a202c2d2 485void
e9bef706 486AliMUONDataInterface::Open(const char* filename)
48b32e42 487{
e9bef706 488 /// Connect to a given galice.root file
489
e8636ba0 490 ResetStores();
e9bef706 491
492 fCurrentEvent=-1;
493
e8636ba0 494 if ( fLoader != 0x0 )
e9bef706 495 {
496 delete fLoader->GetRunLoader();
497 }
498
499 fLoader = 0x0;
500
501 fIsValid = kTRUE;
502
503 TString foldername(Form("%s-%d",ClassName(),fgInstanceCounter));
504
e8636ba0 505 while (AliRunLoader::GetRunLoader(foldername) != 0x0)
e9bef706 506 {
507 delete AliRunLoader::GetRunLoader(foldername);
508 }
509
510 AliRunLoader* runLoader = AliRunLoader::Open(filename,foldername);
e8636ba0 511 if (runLoader == 0x0)
e9bef706 512 {
513 AliError(Form("Cannot open file %s",filename));
514 fIsValid = kFALSE;
515 }
aa73f8fb 516
517 runLoader->LoadHeader();
518 if ( ! runLoader->GetHeader() ) {
519 AliError("Cannot load header.");
520 fIsValid = kFALSE;
521 }
522 else {
523 Int_t runNumber = runLoader->GetHeader()->GetRun();
524 AliCDBManager::Instance()->SetRun(runNumber);
525 }
526 runLoader->UnloadHeader();
527
e9bef706 528 fLoader = runLoader->GetDetectorLoader("MUON");
e8636ba0 529 if (fLoader == 0x0)
e9bef706 530 {
531 AliError("Cannot get AliMUONLoader");
532 fIsValid = kFALSE;
533 }
534
e8636ba0 535 if (not IsValid())
e9bef706 536 {
537 AliError(Form("Could not access %s filename. Object is unuseable",filename));
538 }
925e6570 539}
48b32e42 540
e9bef706 541//_____________________________________________________________________________
e8636ba0 542Bool_t AliMUONDataInterface::GetEvent(Int_t event)
48b32e42 543{
e8636ba0 544/// Loads all reconstructed data for the given event.
545
546 if (DigitStore(event) == 0x0) return kFALSE;
547 if (ClusterStore(event) == 0x0) return kFALSE;
e8636ba0 548 if (TriggerStore(event) == 0x0) return kFALSE;
e8636ba0 549 return kTRUE;
925e6570 550}
48b32e42 551
e8636ba0 552//_____________________________________________________________________________
553Int_t AliMUONDataInterface::NumberOfDigits(Int_t detElemId)
48b32e42 554{
e8636ba0 555/// Returns the number of digits to be found on a given detector element.
556/// @param detElemId The detector element ID number to search on.
a202c2d2 557
e8636ba0 558 TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
559 return CountObjects(iter);
925e6570 560}
48b32e42 561
e8636ba0 562//_____________________________________________________________________________
563AliMUONVDigit* AliMUONDataInterface::Digit(Int_t detElemId, Int_t index)
48b32e42 564{
e8636ba0 565/// Returns the a pointer to the index'th digit on the specified detector element.
566/// @param detElemId The detector element ID number to search on.
567/// @param index The index number of the digit to fetch in the range [0 .. N-1],
568/// where N = NumberOfDigits(detElemId)
a202c2d2 569
e8636ba0 570 TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
571 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
925e6570 572}
48b32e42 573
e8636ba0 574//_____________________________________________________________________________
575Int_t AliMUONDataInterface::NumberOfDigits(Int_t chamber, Int_t cathode)
48b32e42 576{
e8636ba0 577/// Returns the number of digits to be found on a specific chamber and cathode.
578/// @param chamber The chamber number in the range [0 .. 13].
579/// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
580/// 1 is the non-bending plane.
48b32e42 581
e8636ba0 582 TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
583 return CountObjects(iter);
925e6570 584}
48b32e42 585
e8636ba0 586//_____________________________________________________________________________
587AliMUONVDigit* AliMUONDataInterface::Digit(Int_t chamber, Int_t cathode, Int_t index)
48b32e42 588{
e8636ba0 589/// Returns the a pointer to the index'th digit on the specified chamber and cathode.
590/// @param chamber The chamber number in the range [0 .. 13].
591/// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
592/// 1 is the non-bending plane.
593/// @param index The index number of the digit to fetch in the range [0 .. N-1],
594/// where N = NumberOfDigits(chamber, cathode)
595
596 TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
597 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
925e6570 598}
48b32e42 599
e8636ba0 600//_____________________________________________________________________________
601Int_t AliMUONDataInterface::NumberOfRawClusters(Int_t chamber)
48b32e42 602{
e8636ba0 603/// Returns the number of reconstructed raw clusters on the specified chamber.
604/// @param chamber The chamber number in the range [0 .. 13].
a202c2d2 605
e8636ba0 606 TIterator* iter = GetIterator(kRawClusterIterator, chamber);
607 return CountObjects(iter);
925e6570 608}
48b32e42 609
e8636ba0 610//_____________________________________________________________________________
2060b217 611AliMUONVCluster* AliMUONDataInterface::RawCluster(Int_t chamber, Int_t index)
48b32e42 612{
e8636ba0 613/// Returns a pointer to the index'th raw cluster on the specified chamber.
614/// @param chamber The chamber number in the range [0 .. 13].
615/// @param index The index number of the raw cluster to fetch in the range [0 .. N-1],
616/// where N = NumberOfRawClusters(chamber)
a202c2d2 617
e8636ba0 618 TIterator* iter = GetIterator(kRawClusterIterator, chamber);
2060b217 619 return static_cast<AliMUONVCluster*>( FetchObject(iter, index) );
925e6570 620}
48b32e42 621
e8636ba0 622//_____________________________________________________________________________
623Int_t AliMUONDataInterface::NumberOfLocalTriggers()
48b32e42 624{
e8636ba0 625/// Returns the number of reconstructed local trigger objects.
a202c2d2 626
e8636ba0 627 TIterator* iter = GetIterator(kLocalTriggerIterator);
628 return CountObjects(iter);
925e6570 629}
48b32e42 630
e8636ba0 631//_____________________________________________________________________________
632AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(Int_t index)
48b32e42 633{
e8636ba0 634/// Returns a pointer to the index'th local trigger object.
635/// @param index The index number of the local trigger object to fetch in the range [0 .. N-1],
636/// where N = NumberOfLocalTriggers()
a202c2d2 637
e8636ba0 638 TIterator* iter = GetIterator(kLocalTriggerIterator);
639 return static_cast<AliMUONLocalTrigger*>( FetchObject(iter, index) );
925e6570 640}
48b32e42 641
e8636ba0 642//_____________________________________________________________________________
643Int_t AliMUONDataInterface::NumberOfRegionalTriggers()
48b32e42 644{
e8636ba0 645/// Returns the number of regional trigger objects reconstructed.
a202c2d2 646
e8636ba0 647 TIterator* iter = GetIterator(kRegionalTriggerIterator);
648 return CountObjects(iter);
925e6570 649}
48b32e42 650
e8636ba0 651//_____________________________________________________________________________
652AliMUONRegionalTrigger* AliMUONDataInterface::RegionalTrigger(Int_t index)
48b32e42 653{
e8636ba0 654/// Returns a pointer to the index'th regional trigger object.
655/// @param index The index number of the regional trigger object to fetch in the range [0 .. N-1],
656/// where N = NumberOfRegionalTriggers()
a202c2d2 657
e8636ba0 658 TIterator* iter = GetIterator(kRegionalTriggerIterator);
659 return static_cast<AliMUONRegionalTrigger*>( FetchObject(iter, index) );
925e6570 660}
48b32e42 661
e8636ba0 662//_____________________________________________________________________________
663AliMUONGlobalTrigger* AliMUONDataInterface::GlobalTrigger()
48b32e42 664{
e8636ba0 665/// Returns a pointer to the reconstructed global trigger object for the event.
a202c2d2 666
e8636ba0 667 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
668 if (store == 0x0) return 0x0;
669 return store->Global();
925e6570 670}
48b32e42 671
e8636ba0 672//_____________________________________________________________________________
673void AliMUONDataInterface::ResetStores()
48b32e42 674{
e8636ba0 675/// Deletes all the store objects that have been created and resets the pointers to 0x0.
676/// The temporary iterator object is automatically reset. See ResetIterator for more details.
a202c2d2 677
e8636ba0 678 ResetIterator();
679 if (fDigitStore != 0x0)
680 {
681 delete fDigitStore;
682 fDigitStore = 0x0;
683 }
684 if (fTriggerStore != 0x0)
685 {
686 delete fTriggerStore;
687 fTriggerStore = 0x0;
688 }
689 if (fClusterStore != 0x0)
690 {
691 delete fClusterStore;
692 fClusterStore = 0x0;
693 }
925e6570 694}
554b38a6 695
e8636ba0 696//_____________________________________________________________________________
697TIterator* AliMUONDataInterface::GetIterator(IteratorType type, Int_t x, Int_t y)
554b38a6 698{
e8636ba0 699/// Creates an appropriate iterator object and returns it.
700/// If the iterator has already been created then that one is returned otherwise
701/// a new object is created.
702/// Depending on the value of 'type' the semantics of parameters x and y can change.
703/// @param type The type of iterator to create.
704/// @param x This is the detector element ID if type == kDigitIteratorByDetectorElement
705/// If type equals kDigitIteratorByChamberAndCathode or kRawClusterIterator
706/// then this is the chamber number. In all other cases this parameter is
707/// ignored.
708/// @param y If type == kDigitIteratorByChamberAndCathode then this parameter is the
709/// cathode number. In all other cases this parameter is
710/// ignored.
711
712 if (type == fCurrentIteratorType and fDataX == x and fDataY == y)
713 return fIterator;
714
715 if (fCurrentEvent == -1)
716 {
717 AliError("No event was selected. Try first using GetEvent().");
718 return 0x0;
719 }
720
721 ResetIterator();
722
723 switch (type)
724 {
725 case kDigitIteratorByDetectorElement:
726 {
727 Int_t detElem = x;
728 AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
729 if (store == 0x0) return 0x0;
e8636ba0 730 fIterator = store->CreateIterator(detElem, detElem, 2);
731 if (fIterator == 0x0) return 0x0;
732 fCurrentIteratorType = kDigitIteratorByDetectorElement;
733 fDataX = detElem;
734 return fIterator;
735 }
736
737 case kDigitIteratorByChamberAndCathode:
738 {
739 Int_t chamber = x;
740 Int_t cathode = y;
741 if (chamber < 0 or AliMpConstants::NofChambers() <= chamber)
742 {
743 AliError(Form(
744 "Must have give a chamber value in the range [0..%d], but got a value of: %d",
745 AliMpConstants::NofChambers() - 1,
746 chamber
747 ));
748 return 0x0;
749 }
750 if (cathode < 0 or 1 < cathode)
751 {
752 AliError(Form("Must have give a cathode value in the range [0..1], but got a value of: %d", cathode));
753 return 0x0;
754 }
755
756 AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
757 if (store == 0x0) return 0x0;
e8636ba0 758 AliMpIntPair pair = AliMpDEManager::GetDetElemIdRange(chamber);
759 fIterator = store->CreateIterator(pair.GetFirst(), pair.GetSecond(), cathode);
760 if (fIterator == 0x0) return 0x0;
761 fCurrentIteratorType = kDigitIteratorByChamberAndCathode;
762 fDataX = chamber;
763 fDataY = cathode;
764 return fIterator;
765 }
766
767 case kRawClusterIterator:
768 {
769 Int_t chamber = x;
770 AliMUONVClusterStore* store = ClusterStore(fCurrentEvent);
771 if (store == 0x0) return 0x0;
772 fIterator = store->CreateChamberIterator(chamber, chamber);
773 if (fIterator == 0x0) return 0x0;
774 fCurrentIteratorType = kRawClusterIterator;
775 fDataX = chamber;
776 return fIterator;
777 }
778
e8636ba0 779 case kLocalTriggerIterator:
780 {
781 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
782 if (store == 0x0) return 0x0;
783 fIterator = store->CreateLocalIterator();
784 if (fIterator == 0x0) return 0x0;
785 fCurrentIteratorType = kLocalTriggerIterator;
786 return fIterator;
787 }
788
789 case kRegionalTriggerIterator:
790 {
791 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
792 if (store == 0x0) return 0x0;
793 fIterator = store->CreateRegionalIterator();
794 if (fIterator == 0x0) return 0x0;
795 fCurrentIteratorType = kRegionalTriggerIterator;
796 return fIterator;
797 }
798
e8636ba0 799 default:
800 return 0x0;
801 }
554b38a6 802}
803
e8636ba0 804//_____________________________________________________________________________
805void AliMUONDataInterface::ResetIterator()
554b38a6 806{
e8636ba0 807/// The temporary iterator object is deleted if it exists and the pointer reset to 0x0.
808/// The iterator type and temporary data indicating the state of the iterator are
809/// also reset.
810
811 if (fIterator != 0x0) delete fIterator;
812 fCurrentIteratorType = kNoIterator;
813 fCurrentIndex = fDataX = fDataY = -1;
814 fIterator = 0x0;
554b38a6 815}
816
e8636ba0 817//_____________________________________________________________________________
818Int_t AliMUONDataInterface::CountObjects(TIterator* iter)
554b38a6 819{
e8636ba0 820/// Counts the number of objects in the iterator and resets it.
821/// @return The number of objects in 'iter'.
822
823 if (iter == 0x0) return -1;
824 Int_t count = 0;
825 iter->Reset();
826 while ( iter->Next() != 0x0 ) count++;
827 iter->Reset();
828 fCurrentIndex = -1;
829 return count;
554b38a6 830}
831
e8636ba0 832//_____________________________________________________________________________
833TObject* AliMUONDataInterface::FetchObject(TIterator* iter, Int_t index)
554b38a6 834{
e8636ba0 835/// Fetches the index'th object from the iterator counting the first object
836/// returned by iterator after it is reset as index == 0. The next object
837/// has index == 1 and so on where the last object returned by the iterator
838/// has index == N-1 where N = CountObjects(iter)
839/// This method will only reset the iterator if index is smaller than
840/// fCurrentIndex, which is used to track the iteration progress and is
841/// updated when a new object if returned by this method.
842/// @param iter The iterator to fetch an object from.
843/// @param index The index number of the object to fetch in the range [0 .. N-1]
844/// where N = CountObjects(iter)
845
846 if (index < 0)
847 {
848 AliError(Form("Index is out of bounds. Got a value of %d.", index));
849 return 0x0;
850 }
a202c2d2 851
e8636ba0 852 if (iter == 0x0) return 0x0;
853 if (index <= fCurrentIndex)
854 {
855 iter->Reset();
856 fCurrentIndex = -1;
857 }
858
859 TObject* object = 0x0;
860 while (fCurrentIndex < index)
861 {
862 object = iter->Next();
863 if (object == 0x0)
864 {
865 AliError(Form("Index is out of bounds. Got a value of %d.", index));
866 iter->Reset();
867 fCurrentIndex = -1;
868 return 0x0;
869 }
870 fCurrentIndex++;
871 }
872 return object;
554b38a6 873}