]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PMD/AliPMDRawStream.cxx
Remove some bugs that sneaked in during the code revision
[u/mrichter/AliRoot.git] / PMD / AliPMDRawStream.cxx
CommitLineData
a09a2da4 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 PMD digits in raw data.
21///
22/// It loops over all PMD 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
34ab69dd 29#include <Riostream.h>
30#include <TObjArray.h>
31#include <TString.h>
32#include <TSystem.h>
33
ecee2a1a 34#include "AliLog.h"
34ab69dd 35#include "AliPMDBlockHeader.h"
36#include "AliPMDDspHeader.h"
37#include "AliPMDPatchBusHeader.h"
38#include "AliPMDddldata.h"
a09a2da4 39#include "AliPMDRawStream.h"
40#include "AliRawReader.h"
41
42ClassImp(AliPMDRawStream)
43
44
45//_____________________________________________________________________________
46AliPMDRawStream::AliPMDRawStream(AliRawReader* rawReader) :
34ab69dd 47 fRawReader(rawReader)
a09a2da4 48{
49// create an object to read PMD raw digits
50
362c9d61 51 fRawReader->Select("PMD");
a09a2da4 52}
53
54//_____________________________________________________________________________
55AliPMDRawStream::AliPMDRawStream(const AliPMDRawStream& stream) :
56 TObject(stream),
34ab69dd 57 fRawReader(NULL)
a09a2da4 58{
59// copy constructor
60
ecee2a1a 61 AliFatal("Copy constructor not implemented");
a09a2da4 62}
63
64//_____________________________________________________________________________
65AliPMDRawStream& AliPMDRawStream::operator = (const AliPMDRawStream&
66 /* stream */)
67{
68// assignment operator
69
ecee2a1a 70 AliFatal("operator = assignment operator not implemented");
a09a2da4 71 return *this;
72}
73
74//_____________________________________________________________________________
75AliPMDRawStream::~AliPMDRawStream()
76{
77// destructor
78
79}
80
81
82//_____________________________________________________________________________
34ab69dd 83
84void AliPMDRawStream::DdlData(TObjArray *pmdddlcont)
a09a2da4 85{
86// read the next raw digit
87// returns kFALSE if there is no digit left
88
34ab69dd 89 AliPMDddldata *pmdddldata;
90
91 // Int_t indexDDL = 0;
92 // fRawReader->Select(12, indexDDL, indexDDL);
93 fRawReader->ReadHeader();
94 Int_t iddl = fRawReader->GetDDLID();
95 Int_t dataSize = fRawReader->GetDataSize();
96 Int_t totaldataword = dataSize/4;
a09a2da4 97
34ab69dd 98 UInt_t *buffer;
99 buffer = new UInt_t[totaldataword];
a09a2da4 100 UInt_t data;
34ab69dd 101 for (Int_t i = 0; i < totaldataword; i++)
102 {
103 fRawReader->ReadNextInt(data);
104 buffer[i] = data;
105 }
a09a2da4 106
34ab69dd 107 // --- Open the mapping file
a09a2da4 108
a09a2da4 109
34ab69dd 110 TString fileName(gSystem->Getenv("ALICE_ROOT"));
111 if(iddl == 0)
112 {
113 fileName += "/PMD/PMD_Mapping_ddl0.dat";
114 }
115 else if(iddl == 1)
116 {
117 fileName += "/PMD/PMD_Mapping_ddl1.dat";
118 }
119 else if(iddl == 2)
120 {
121 fileName += "/PMD/PMD_Mapping_ddl2.dat";
122 }
123 else if(iddl == 3)
124 {
125 fileName += "/PMD/PMD_Mapping_ddl3.dat";
126 }
127 else if(iddl == 4)
128 {
129 fileName += "/PMD/PMD_Mapping_ddl4.dat";
130 }
131 else if(iddl == 5)
132 {
133 fileName += "/PMD/PMD_Mapping_ddl5.dat";
134 }
135
136 ifstream infile;
137 infile.open(fileName.Data(), ios::in); // ascii file
138 if(!infile)
139 AliError(Form("Could not read the mapping file for DDL No = %d",iddl));
140
141 Int_t modulePerDDL = 0;
142 if (iddl < 4)
143 {
144 modulePerDDL = 6;
145 }
146 else if (iddl == 4 || iddl == 5)
147 {
148 modulePerDDL = 12;
149 }
150
151 const Int_t kNPatchBus = 50;
152
153 Int_t modno, totPatchBus, bPatchBus, ePatchBus;
154 Int_t ibus, totmcm, rows, rowe, cols, cole;
155 Int_t moduleNo[kNPatchBus], mcmperBus[kNPatchBus];
156 Int_t startRowBus[kNPatchBus], endRowBus[kNPatchBus];
157 Int_t startColBus[kNPatchBus], endColBus[kNPatchBus];
158
159
160 for (Int_t ibus = 0; ibus < kNPatchBus; ibus++)
161 {
162 mcmperBus[ibus] = -1;
163 startRowBus[ibus] = -1;
164 endRowBus[ibus] = -1;
165 startColBus[ibus] = -1;
166 endColBus[ibus] = -1;
167 }
168
169
170 for (Int_t im = 0; im < modulePerDDL; im++)
171 {
172 infile >> modno;
173 infile >> totPatchBus >> bPatchBus >> ePatchBus;
174
175 for(Int_t i=0; i<totPatchBus; i++)
176 {
177 infile >> ibus >> totmcm >> rows >> rowe >> cols >> cole;
178
179 moduleNo[ibus] = modno;
180 mcmperBus[ibus] = totmcm;
181 startRowBus[ibus] = rows;
182 endRowBus[ibus] = rowe;
183 startColBus[ibus] = cols;
184 endColBus[ibus] = cole;
185 }
186 }
187
188 infile.close();
189
190
191 AliPMDBlockHeader blockHeader;
192 AliPMDDspHeader dspHeader;
193 AliPMDPatchBusHeader pbusHeader;
194
195 Int_t idet, ismn;
196 Int_t irow = -1;
197 Int_t icol = -1;
198
199 Int_t block[8];
200 Int_t pbus[4];
201
202 Int_t ilowLimit = 0;
203 Int_t iuppLimit = 0;
204 for (Int_t iblock = 0; iblock < 2; iblock++)
205 {
206 ilowLimit = iuppLimit;
207 iuppLimit = ilowLimit + 8;
208
209 for (Int_t i = ilowLimit; i < iuppLimit; i++)
210 {
211 block[i-ilowLimit] = (Int_t) buffer[i];
212 }
213 blockHeader.SetHeader(block);
214 for (Int_t idsp = 0; idsp < 5; idsp++)
215 {
216 ilowLimit = iuppLimit;
217 iuppLimit = ilowLimit + 8;
218
219 for (Int_t i = ilowLimit; i < iuppLimit; i++)
220 {
221 block[i-ilowLimit] = (Int_t) buffer[i];
222 }
223 dspHeader.SetHeader(block);
224
225 for (Int_t ibus = 0; ibus < 5; ibus++)
226 {
227
228 ilowLimit = iuppLimit;
229 iuppLimit = ilowLimit + 4;
230
231 for (Int_t i = ilowLimit; i < iuppLimit; i++)
232 {
233 pbus[i-ilowLimit] = (Int_t) buffer[i];
234 }
235 pbusHeader.SetHeader(pbus);
236 Int_t rawdatalength = pbusHeader.GetRawDataLength();
237 Int_t pbusid = pbusHeader.GetPatchBusId();
238
239 ilowLimit = iuppLimit;
240 iuppLimit = ilowLimit + rawdatalength;
241
242 Int_t imodule = moduleNo[pbusid];
243
244
245 for (Int_t iword = ilowLimit; iword < iuppLimit; iword++)
246 {
247 data = buffer[iword];
248
249 Int_t isig = data & 0x0FFF;
250 Int_t ich = (data >> 12) & 0x003F;
251 Int_t imcm = (data >> 18) & 0x07FF;
252 Int_t ibit = (data >> 31) & 0x0001;
253
254 GetRowCol(iddl, pbusid, imcm, ich,
255 startRowBus, endRowBus,
256 startColBus, endColBus,
257 irow, icol);
258
259 ConvertDDL2SMN(iddl, imodule, ismn, idet);
260 TransformH2S(ismn, irow, icol);
261
262 pmdddldata = new AliPMDddldata();
263
264 pmdddldata->SetDetector(idet);
265 pmdddldata->SetSMN(ismn);
266 pmdddldata->SetModule(imodule);
267 pmdddldata->SetPatchBusId(pbusid);
268 pmdddldata->SetMCM(imcm);
269 pmdddldata->SetChannel(ich);
270 pmdddldata->SetRow(irow);
271 pmdddldata->SetColumn(icol);
272 pmdddldata->SetSignal(isig);
273 pmdddldata->SetParityBit(ibit);
274
275 pmdddlcont->Add(pmdddldata);
276
277 }
278
279 }
280 } // end of DSP
281
282
283 } // end of BLOCK
284
285
286 delete [] buffer;
a09a2da4 287
a09a2da4 288}
a09a2da4 289//_____________________________________________________________________________
34ab69dd 290void AliPMDRawStream::GetRowCol(Int_t ddlno, Int_t pbusid,
291 UInt_t mcmno, UInt_t chno,
292 Int_t startRowBus[], Int_t endRowBus[],
293 Int_t startColBus[], Int_t endColBus[],
294 Int_t &row, Int_t &col) const
a09a2da4 295{
34ab69dd 296// decode: ddlno, patchbusid, mcmno, chno -> um, row, col
a09a2da4 297
a09a2da4 298
299 static const UInt_t kCh[64] = { 21, 25, 29, 28, 17, 24, 20, 16,
300 12, 13, 8, 4, 0, 1, 9, 5,
301 10, 6, 2, 3, 14, 7, 11, 15,
302 19, 18, 23, 27, 31, 30, 22, 26,
303 53, 57, 61, 60, 49, 56, 52, 48,
304 44, 45, 40, 36, 32, 33, 41, 37,
305 42, 38, 34, 35, 46, 39, 43, 47,
306 51, 50, 55, 59, 63, 62, 54, 58 };
307
34ab69dd 308 Int_t rowcol = kCh[chno];
309 Int_t irownew = rowcol/4;
310 Int_t icolnew = rowcol%4;
a09a2da4 311
34ab69dd 312 if (ddlno == 0)
a09a2da4 313 {
34ab69dd 314 if (pbusid <= 2)
315 {
316 if (mcmno >= 12)
317 {
318 row = startRowBus[pbusid] + irownew;
319 col = startColBus[pbusid] + (mcmno-12)*4 + icolnew;
320 }
321 else
322 {
323 // Add 16 to skip the 1st 15 rows
324 row = startRowBus[pbusid] + irownew + 16;
325 col = startColBus[pbusid] + mcmno*4 + icolnew;
326 }
327 }
328 else if (pbusid > 2)
329 {
330 row = startRowBus[pbusid] + irownew;
331 col = startColBus[pbusid] + mcmno*4 + icolnew;
332
333 }
a09a2da4 334 }
34ab69dd 335 else if (ddlno == 1)
a09a2da4 336 {
34ab69dd 337 if (pbusid <= 2)
a09a2da4 338 {
34ab69dd 339 if (mcmno >= 12)
340 {
341 row = endRowBus[pbusid] - (15 - irownew);
342 col = startColBus[pbusid] + (mcmno-12)*4 + icolnew;
343 }
344 else
345 {
346 // Subtract 16 to skip the 1st 15 rows
347 row = endRowBus[pbusid] - 16 - (15 - irownew) ;
348 col = startColBus[pbusid] + mcmno*4 + icolnew;
349 }
a09a2da4 350 }
34ab69dd 351 else if (pbusid > 2)
a09a2da4 352 {
34ab69dd 353 row = endRowBus[pbusid] - (15 - irownew);
354 col = startColBus[pbusid] + mcmno*4 + icolnew;
a09a2da4 355 }
a09a2da4 356 }
34ab69dd 357 else if (ddlno == 2)
e54787da 358 {
34ab69dd 359 row = startRowBus[pbusid] + irownew;
360 col = endColBus[pbusid] - mcmno*4 - (3 - icolnew);
361 }
362 else if (ddlno == 3)
363 {
364 row = endRowBus[pbusid] - (15 - irownew);
365 col = endColBus[pbusid] - mcmno*4 - (3 - icolnew);
e54787da 366 }
34ab69dd 367 else if (ddlno == 4)
e54787da 368 {
34ab69dd 369 if (pbusid <= 16)
e54787da 370 {
34ab69dd 371 if (mcmno >= 12)
372 {
373 row = startRowBus[pbusid] + irownew;
374 col = startColBus[pbusid] + (mcmno-12)*4 + icolnew;
375 }
376 else
377 {
378 // Add 16 to skip the 1st 15 rows
379 row = startRowBus[pbusid] + irownew + 16;
380 col = startColBus[pbusid] + mcmno*4 + icolnew;
381 }
e54787da 382 }
34ab69dd 383 else if (pbusid > 16 && pbusid <= 20)
e54787da 384 {
34ab69dd 385 row = startRowBus[pbusid] + irownew;
386 col = startColBus[pbusid] + mcmno*4 + icolnew;
387
388 }
389 else if(pbusid > 20)
390 {
391 row = endRowBus[pbusid] - (15 - irownew);
392 col = endColBus[pbusid] - mcmno*4 - (3 - icolnew);
e54787da 393 }
e54787da 394 }
34ab69dd 395 else if (ddlno == 5)
e54787da 396 {
34ab69dd 397 if (pbusid <= 16)
398 {
399 if (mcmno >= 12)
400 {
401 row = endRowBus[pbusid] - (15 - irownew);
402 col = startColBus[pbusid] + (mcmno-12)*4 + icolnew;
403 }
404 else
405 {
406 // Subtract 16 to skip the 1st 15 rows
407 row = endRowBus[pbusid] - 16 - (15 - irownew) ;
408 col = startColBus[pbusid] + mcmno*4 + icolnew;
409 }
410 }
411 else if (pbusid > 16 && pbusid <= 20)
e54787da 412 {
34ab69dd 413 row = endRowBus[pbusid] - (15 - irownew);
414 col = startColBus[pbusid] + mcmno*4 + icolnew;
e54787da 415 }
34ab69dd 416 else if (pbusid > 20)
e54787da 417 {
34ab69dd 418 row = startRowBus[pbusid] + irownew;
419 col = endColBus[pbusid] - mcmno*4 - (3 - icolnew);
e54787da 420 }
34ab69dd 421 }
422}
423//_____________________________________________________________________________
424void AliPMDRawStream::ConvertDDL2SMN(Int_t iddl, Int_t imodule,
425 Int_t &smn, Int_t &detector) const
426{
427 // This converts the DDL number (0 to 5), Module Number (0-47)
428 // to Serial module number in one detector (SMN : 0-23) and
429 // detector number (0:PRE plane, 1:CPV plane)
430 if (iddl < 4)
431 {
432 smn = imodule;
433 detector = 0;
434 }
435 else
436 {
437 smn = imodule - 24;
e54787da 438 detector = 1;
439 }
440}
441//_____________________________________________________________________________
442void AliPMDRawStream::TransformH2S(Int_t smn, Int_t &row, Int_t &col) const
443{
34ab69dd 444 // This does the transformation of the hardware coordinate to
445 // software
446 // i.e., For SuperModule 0 &1, instead of 96x48(hardware),
447 // it is 48x96 (software)
e54787da 448 // For Supermodule 3 & 4, 48x96
449
e54787da 450 Int_t irownew = 0;
451 Int_t icolnew = 0;
34ab69dd 452
e54787da 453 if(smn < 12)
454 {
34ab69dd 455 irownew = col;
456 icolnew = row;
e54787da 457 }
34ab69dd 458 else if(smn >= 12 && smn < 24)
e54787da 459 {
34ab69dd 460 irownew = row;
461 icolnew = col;
e54787da 462 }
463
464 row = irownew;
465 col = icolnew;
466}
467//_____________________________________________________________________________