]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCRawStream.cxx
Bug fix (Marian)
[u/mrichter/AliRoot.git] / TPC / AliTPCRawStream.cxx
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$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 ///
20 /// This class provides access to TPC digits in raw data.
21 ///
22 /// It loops over all TPC digits in the raw data given by the AliRawReader.
23 /// The Next method goes to the next digit. If there are no digits left
24 /// it returns kFALSE.
25 /// Several getters provide information about the current digit.
26 ///
27 ///////////////////////////////////////////////////////////////////////////////
28
29 #include <TSystem.h>
30
31 #include "AliTPCRawStream.h"
32 #include "AliRawReader.h"
33 #include "AliLog.h"
34 #include "AliTPCAltroMapping.h"
35
36 ClassImp(AliTPCRawStream)
37
38 //_____________________________________________________________________________
39 AliTPCRawStream::AliTPCRawStream(AliRawReader* rawReader, AliAltroMapping **mapping) :
40   AliAltroRawStream(rawReader),
41   fSector(-1),
42   fPrevSector(-1),
43   fRow(-1),
44   fPrevRow(-1),
45   fPad(-1),
46   fPrevPad(-1),
47   fIsMapOwner(kFALSE)
48 {
49   // create an object to read TPC raw digits
50
51   SelectRawData("TPC");
52
53   if (mapping == NULL) {
54     TString path = gSystem->Getenv("ALICE_ROOT");
55     path += "/TPC/mapping/Patch";
56     TString path2;
57     for(Int_t i = 0; i < 6; i++) {
58       path2 = path;
59       path2 += i;
60       path2 += ".data";
61       fMapping[i] = new AliTPCAltroMapping(path2.Data());
62     }
63     fIsMapOwner = kTRUE;
64   }
65   else {
66     for(Int_t i = 0; i < 6; i++)
67       fMapping[i] = mapping[i];
68   }
69     
70   fNoAltroMapping = kFALSE;
71 }
72
73 //_____________________________________________________________________________
74 AliTPCRawStream::AliTPCRawStream(const AliTPCRawStream& stream) :
75   AliAltroRawStream(stream),
76   fSector(stream.fSector),
77   fPrevSector(stream.fPrevSector),
78   fRow(stream.fRow),
79   fPrevRow(stream.fPrevRow),
80   fPad(stream.fPad),
81   fPrevPad(stream.fPrevPad),
82   fIsMapOwner(kFALSE)
83 {
84   for(Int_t i = 0; i < 6; i++) fMapping[i] = stream.fMapping[i];
85 }
86
87 //_____________________________________________________________________________
88 AliTPCRawStream& AliTPCRawStream::operator = (const AliTPCRawStream& stream)
89 {
90   if(&stream == this) return *this;
91
92   ((AliAltroRawStream *)this)->operator=(stream);
93
94   fSector = stream.fSector;
95   fPrevSector = stream.fPrevSector;
96   fRow = stream.fRow;
97   fPrevRow = stream.fPrevRow;
98   fPad = stream.fPad;
99   fPrevPad = stream.fPrevPad;
100   fIsMapOwner = kFALSE;
101
102   for(Int_t i = 0; i < 6; i++) fMapping[i] = stream.fMapping[i];
103
104   return *this;
105 }
106
107 //_____________________________________________________________________________
108 AliTPCRawStream::~AliTPCRawStream()
109 {
110 // destructor
111
112   if (fIsMapOwner)
113     for(Int_t i = 0; i < 6; i++) delete fMapping[i];
114 }
115
116 //_____________________________________________________________________________
117 void AliTPCRawStream::Reset()
118 {
119   // reset tpc raw stream params
120   AliAltroRawStream::Reset();
121   fSector = fPrevSector = fRow = fPrevRow = fPad = fPrevPad = -1;
122 }
123
124 //_____________________________________________________________________________
125 Bool_t AliTPCRawStream::Next()
126 {
127   // Read next TPC signal
128   // Apply the TPC altro mapping to get
129   // the sector,pad-row and pad indeces
130   fPrevSector = fSector;
131   fPrevRow = fRow;
132   fPrevPad = fPad;
133   if (AliAltroRawStream::Next()) {
134     if (IsNewHWAddress())
135       ApplyAltroMapping();
136     return kTRUE;
137   }
138   else
139     return kFALSE;
140 }
141
142 //_____________________________________________________________________________
143 void AliTPCRawStream::ApplyAltroMapping()
144 {
145   // Take the DDL index, load
146   // the corresponding altro mapping
147   // object and fill the sector,row and pad indeces
148   Int_t ddlNumber = GetDDLNumber();
149   Int_t patchIndex;
150   if (ddlNumber < 72) {
151     fSector = ddlNumber / 2;
152     patchIndex = ddlNumber % 2;
153   }
154   else {
155     fSector = (ddlNumber - 72) / 4 + 36;
156     patchIndex = (ddlNumber - 72) % 4 + 2;
157   }
158
159   Short_t hwAddress = GetHWAddress();
160   fRow = fMapping[patchIndex]->GetPadRow(hwAddress);
161   fPad = fMapping[patchIndex]->GetPad(hwAddress);
162
163   if ((fRow < 0) || (fPad < 0))
164     AddMappingErrorLog(Form("hw=%d",hwAddress)); 
165 }