1 /***************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 #include <Riostream.h>
17 #include <TClonesArray.h>
25 #include "AliRawDataHeader.h"
26 #include "AliBitPacking.h"
27 #include "AliPMDdigit.h"
28 #include "AliPMDRawStream.h"
29 #include "AliPMDDDLRawData.h"
32 ClassImp(AliPMDDDLRawData)
34 AliPMDDDLRawData::AliPMDDDLRawData():
35 fDigits(new TClonesArray("AliPMDdigit", 1000))
37 // Default Constructor
41 //____________________________________________________________________________
42 AliPMDDDLRawData::AliPMDDDLRawData(const AliPMDDDLRawData& ddlraw):
44 fDigits(ddlraw.fDigits)
48 //____________________________________________________________________________
49 AliPMDDDLRawData & AliPMDDDLRawData::operator=(const AliPMDDDLRawData& ddlraw)
54 fDigits = ddlraw.fDigits;
59 //____________________________________________________________________________
61 AliPMDDDLRawData::~AliPMDDDLRawData()
68 //____________________________________________________________________________
69 void AliPMDDDLRawData::WritePMDRawData(TTree *treeD)
71 // write digits into raw data format
75 TBranch *branch = treeD->GetBranch("PMDDigit");
78 AliError("PMD Digit branch not found");
81 branch->SetAddress(&fDigits);
83 Int_t nmodules = (Int_t) treeD->GetEntries();
84 AliDebug(1,Form("Number of modules inside treeD = %d",nmodules));
86 const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
87 Int_t modulePerDDL = 0;
90 AliRawDataHeader header;
91 UInt_t sizeRawData = 0;
93 const Int_t kSize = 1536;
96 UInt_t busPatch[50][1536];
98 Int_t contentsBus[50];
104 for(Int_t iddl = 0; iddl < kDDL; iddl++)
106 strcpy(filename,AliDAQ::DdlFileName("PMD",iddl));
108 outfile.open(filename,ios::binary);
110 outfile.open(filename);
131 // Write the Dummy Data Header into the file
132 Int_t bHPosition = outfile.tellp();
133 outfile.write((char*)(&header),sizeof(header));
135 for (Int_t ibus = 0; ibus < 50; ibus++)
137 contentsBus[ibus] = 0;
138 for (Int_t ich = 0; ich < 1536; ich++)
140 busPatch[ibus][ich] = 0;
144 for(Int_t ium = 0; ium < modulePerDDL; ium++)
146 if (iddl == 4 && ium == 6) mmodule = 42;
148 // Extract energy deposition per cell and pack it
149 // in a 32-bit word and returns all the total words
150 // per one unit-module
152 GetUMDigitsData(treeD, mmodule, iddl, contentsBus, busPatch);
161 for (Int_t i = 0; i < 10; i++)
165 for (Int_t ibus=0; ibus < 5; ibus++)
167 if (contentsBus[ij] > 0)
169 dsp[i] += contentsBus[ij];
174 // Add the patch Bus header to the DSP contents
175 dsp[i] += 4*dspBus[i];
178 Int_t dspBlockARDL = 0;
179 Int_t dspBlockBRDL = 0;
181 for (Int_t i = 0; i < 5; i++)
184 Int_t iodd = 2*i + 1;
187 dspBlockARDL += dsp[ieven];
192 dspBlockBRDL += dsp[iodd];
197 // Start writing the DDL file
199 UInt_t dspBlockHeader[8];
201 UInt_t patchBusHeader[4];
204 for (Int_t iblock = 0; iblock < 2; iblock++)
208 for (Int_t i=0; i<8; i++)
210 dspBlockHeader[i] = 0;
215 dspBlockHeader[1] = (UInt_t) dspBlockARDL;
217 else if (iblock == 1)
219 dspBlockHeader[1] = (UInt_t) dspBlockBRDL;
224 outfile.write((char*)(&dspBlockHeader),8*sizeof(UInt_t));
234 else if (iblock == 1)
243 for (Int_t idsp = 0; idsp < 5; idsp++)
250 dspRDL = (UInt_t) dsp[dspno];
252 else if (iblock == 1)
255 dspRDL = (UInt_t) dsp[dspno];
258 for (Int_t i=0; i<8; i++)
262 dspHeader[1] = dspRDL;
263 dspHeader[6] = dspno;
264 outfile.write((char*)(&dspHeader),8*sizeof(UInt_t));
266 for (Int_t ibus = 0; ibus < 5; ibus++)
269 Int_t busno = iskip[idsp] + ibus;
270 Int_t patchbusRDL = contentsBus[busno];
272 for (Int_t i=0; i<4; i++)
274 patchBusHeader[i] = 0;
276 patchBusHeader[1] = (UInt_t) patchbusRDL;
277 patchBusHeader[2] = (UInt_t) busno;
279 outfile.write((char*)(&patchBusHeader),4*sizeof(UInt_t));
281 for (Int_t iword = 0; iword < patchbusRDL; iword++)
283 buffer[iword] = busPatch[busno][iword];
286 outfile.write((char*)buffer,patchbusRDL*sizeof(UInt_t));
293 // Write real data header
294 // take the pointer to the beginning of the data header
295 // write the total number of words per ddl and bring the
296 // pointer to the current file position and close it
297 UInt_t cFPosition = outfile.tellp();
298 sizeRawData = cFPosition - bHPosition - sizeof(header);
300 header.fSize = cFPosition - bHPosition;
301 header.SetAttribute(0); // valid data
302 outfile.seekp(bHPosition);
303 outfile.write((char*)(&header),sizeof(header));
304 outfile.seekp(cFPosition);
311 //____________________________________________________________________________
312 void AliPMDDDLRawData::GetUMDigitsData(TTree *treeD, Int_t imodule,
313 Int_t ddlno, Int_t *contentsBus,
314 UInt_t busPatch[][1536])
316 // Retrives digits data UnitModule by UnitModule
320 Int_t det, smn, irow, icol;
322 const Int_t kMaxBus = 50;
323 Int_t totPatchBus, bPatchBus, ePatchBus;
324 Int_t ibus, totmcm, rows, cols, rowe, cole;
327 Int_t patchBusNo[kMaxBus], mcmperBus[kMaxBus];
328 Int_t startRowBus[kMaxBus], startColBus[kMaxBus];
329 Int_t endRowBus[kMaxBus], endColBus[kMaxBus];
331 Int_t beginPatchBus = -1;
332 Int_t endPatchBus = -1;
333 for(Int_t i = 0; i < kMaxBus; i++)
342 Int_t modulePerDDL = 0;
347 else if (ddlno == 4 || ddlno == 5)
356 TString fileName(gSystem->Getenv("ALICE_ROOT"));
360 fileName += "/PMD/PMD_Mapping_ddl0.dat";
364 fileName += "/PMD/PMD_Mapping_ddl1.dat";
368 fileName += "/PMD/PMD_Mapping_ddl2.dat";
372 fileName += "/PMD/PMD_Mapping_ddl3.dat";
376 fileName += "/PMD/PMD_Mapping_ddl4.dat";
380 fileName += "/PMD/PMD_Mapping_ddl5.dat";
384 infile.open(fileName.Data(), ios::in); // ascii file
386 AliError(Form("Could not read the mapping file for DDL No = %d",ddlno));
388 for (Int_t im = 0; im < modulePerDDL; im++)
391 infile >> totPatchBus >> bPatchBus >> ePatchBus;
393 if (moduleno == imodule)
395 beginPatchBus = bPatchBus;
396 endPatchBus = ePatchBus;
399 for(Int_t i=0; i<totPatchBus; i++)
401 infile >> ibus >> totmcm >> rows >> rowe >> cols >> cole;
403 if (moduleno == imodule)
405 patchBusNo[ibus] = ibus;
406 mcmperBus[ibus] = totmcm;
407 startRowBus[ibus] = rows;
408 startColBus[ibus] = cols;
409 endRowBus[ibus] = rowe;
410 endColBus[ibus] = cole;
418 treeD->GetEntry(imodule);
419 Int_t nentries = fDigits->GetLast();
420 Int_t totword = nentries+1;
422 AliPMDdigit *fPMDdigit;
425 for (Int_t ient = 0; ient < totword; ient++)
427 fPMDdigit = (AliPMDdigit*)fDigits->UncheckedAt(ient);
429 det = fPMDdigit->GetDetector();
430 smn = fPMDdigit->GetSMNumber();
431 irow = fPMDdigit->GetRow();
432 icol = fPMDdigit->GetColumn();
433 adc = (UInt_t) fPMDdigit->GetADC();
435 TransformS2H(smn,irow,icol);
437 GetMCMCh(ddlno, irow, icol, beginPatchBus, endPatchBus,
438 mcmperBus, startRowBus, startColBus,
439 endRowBus, endColBus, busno, mcmno, chno);
442 AliBitPacking::PackWord(adc,baseword,0,11);
443 AliBitPacking::PackWord(chno,baseword,12,17);
444 AliBitPacking::PackWord(mcmno,baseword,18,28);
445 AliBitPacking::PackWord(0,baseword,29,30);
446 AliBitPacking::PackWord(1,baseword,31,31);
448 Int_t jj = contentsBus[busno];
449 busPatch[busno][jj] = baseword;
451 contentsBus[busno]++;
456 //____________________________________________________________________________
457 void AliPMDDDLRawData::TransformS2H(Int_t smn, Int_t &irow, Int_t &icol)
459 // Does the Software to Hardware coordinate transformation
465 // First in digits we have all dimension 48x96
466 // Transform into the realistic one, i.e, For SM 0&1 96(row)x48(col)
467 // and for SM 2&3 48(row)x96(col)
474 else if( smn >= 12 && smn < 24)
480 // In the new geometry always Geant (0,0) and Hardware (0,0) start
481 // from the top left corner
489 //____________________________________________________________________________
491 void AliPMDDDLRawData::GetMCMCh(Int_t ddlno, Int_t row, Int_t col,
492 Int_t beginPatchBus, Int_t endPatchBus,
494 Int_t *startRowBus, Int_t *startColBus,
495 Int_t *endRowBus, Int_t *endColBus,
496 Int_t & busno, UInt_t &mcmno, UInt_t &chno)
498 // This part will be modified once the final track layout on the PCB is
499 // designed. This will only change the coordinate of the individual cell
501 static const UInt_t kCh[16][4] = { {12, 13, 18, 19},
518 Int_t irownew = row%16;
519 Int_t icolnew = col%4;
521 chno = kCh[irownew][icolnew];
524 for (Int_t ibus = beginPatchBus; ibus <= endPatchBus; ibus++)
526 Int_t srow = startRowBus[ibus];
527 Int_t erow = endRowBus[ibus];
528 Int_t scol = startColBus[ibus];
529 Int_t ecol = endColBus[ibus];
530 Int_t tmcm = mcmperBus[ibus];
531 if ((row >= srow && row <= erow) && (col >= scol && col <= ecol))
535 // Find out the MCM Number
538 if (ddlno == 0 || ddlno == 1)
540 // PRE plane, SU Mod = 0, 1
541 Int_t rowdiff = endRowBus[ibus] - startRowBus[ibus];
544 Int_t midrow = srow + 16;
545 if(row >= srow && row < midrow)
547 mcmno = 12 + (col-scol)/4;
549 else if(row >= midrow && row < erow)
551 mcmno = (col-scol)/4;
556 mcmno = (col-scol)/4;
558 } // end of ddl 0 and 1
561 // PRE plane, SU Mod = 2
563 Int_t icolnew = (col - scol)/4;
564 mcmno = tmcm - 1 - icolnew;
568 // PRE plane, SU Mod = 3
570 Int_t icolnew = (col - scol)/4;
571 mcmno = tmcm - 1 - icolnew;
575 // CPV plane, SU Mod = 0, 3 : ddl = 4
579 Int_t rowdiff = endRowBus[ibus] - startRowBus[ibus];
582 Int_t midrow = srow + 16;
583 if(row >= srow && row < midrow)
585 mcmno = 12 + (col-scol)/4;
587 else if(row >= midrow && row < erow)
589 mcmno = (col-scol)/4;
594 mcmno = (col-scol)/4;
599 Int_t icolnew = (col - scol)/4;
600 mcmno = tmcm - 1 - icolnew;
605 // CPV plane, SU Mod = 2, 1 : ddl = 5
609 Int_t rowdiff = endRowBus[ibus] - startRowBus[ibus];
612 Int_t midrow = srow + 16;
613 if(row >= srow && row < midrow)
615 mcmno = 12 + (col-scol)/4;
617 else if(row >= midrow && row < erow)
619 mcmno = (col-scol)/4;
624 mcmno = (col-scol)/4;
629 Int_t icolnew = (col - scol)/4;
630 mcmno = tmcm - 1 - icolnew;
637 //____________________________________________________________________________