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 //____________________________________________________________________________
43 AliPMDDDLRawData::~AliPMDDDLRawData()
50 //____________________________________________________________________________
51 void AliPMDDDLRawData::WritePMDRawData(TTree *treeD)
53 // write digits into raw data format
57 TBranch *branch = treeD->GetBranch("PMDDigit");
60 AliError("PMD Digit branch not found");
63 branch->SetAddress(&fDigits);
65 Int_t nmodules = (Int_t) treeD->GetEntries();
66 AliDebug(1,Form("Number of modules inside treeD = %d",nmodules));
68 const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
69 Int_t modulePerDDL = 0;
72 AliRawDataHeader header;
73 UInt_t sizeRawData = 0;
75 const Int_t kSize = 1536;
78 UInt_t busPatch[50][1536];
80 Int_t contentsBus[50];
86 for(Int_t iddl = 0; iddl < kDDL; iddl++)
88 strcpy(filename,AliDAQ::DdlFileName("PMD",iddl));
90 outfile.open(filename,ios::binary);
92 outfile.open(filename);
113 // Write the Dummy Data Header into the file
114 Int_t bHPosition = outfile.tellp();
115 outfile.write((char*)(&header),sizeof(header));
117 for (Int_t ibus = 0; ibus < 50; ibus++)
119 contentsBus[ibus] = 0;
120 for (Int_t ich = 0; ich < 1536; ich++)
122 busPatch[ibus][ich] = 0;
126 for(Int_t ium = 0; ium < modulePerDDL; ium++)
128 if (iddl == 4 && ium == 6) mmodule = 42;
130 // Extract energy deposition per cell and pack it
131 // in a 32-bit word and returns all the total words
132 // per one unit-module
134 GetUMDigitsData(treeD, mmodule, iddl, contentsBus, busPatch);
143 for (Int_t i = 0; i < 10; i++)
147 for (Int_t ibus=0; ibus < 5; ibus++)
149 if (contentsBus[ij] > 0)
151 dsp[i] += contentsBus[ij];
156 // Add the patch Bus header to the DSP contents
157 dsp[i] += 4*dspBus[i];
160 Int_t dspBlockARDL = 0;
161 Int_t dspBlockBRDL = 0;
163 for (Int_t i = 0; i < 5; i++)
166 Int_t iodd = 2*i + 1;
169 dspBlockARDL += dsp[ieven];
174 dspBlockBRDL += dsp[iodd];
179 // Start writing the DDL file
181 UInt_t dspBlockHeader[8];
183 UInt_t patchBusHeader[4];
186 for (Int_t iblock = 0; iblock < 2; iblock++)
190 for (Int_t i=0; i<8; i++)
192 dspBlockHeader[i] = 0;
197 dspBlockHeader[1] = (UInt_t) dspBlockARDL;
199 else if (iblock == 1)
201 dspBlockHeader[1] = (UInt_t) dspBlockBRDL;
206 outfile.write((char*)(&dspBlockHeader),8*sizeof(UInt_t));
216 else if (iblock == 1)
225 for (Int_t idsp = 0; idsp < 5; idsp++)
232 dspRDL = (UInt_t) dsp[dspno];
234 else if (iblock == 1)
237 dspRDL = (UInt_t) dsp[dspno];
240 for (Int_t i=0; i<8; i++)
244 dspHeader[1] = dspRDL;
245 dspHeader[6] = dspno;
246 outfile.write((char*)(&dspHeader),8*sizeof(UInt_t));
248 for (Int_t ibus = 0; ibus < 5; ibus++)
251 Int_t busno = iskip[idsp] + ibus;
252 Int_t patchbusRDL = contentsBus[busno];
254 for (Int_t i=0; i<4; i++)
256 patchBusHeader[i] = 0;
258 patchBusHeader[1] = (UInt_t) patchbusRDL;
259 patchBusHeader[2] = (UInt_t) busno;
261 outfile.write((char*)(&patchBusHeader),4*sizeof(UInt_t));
263 for (Int_t iword = 0; iword < patchbusRDL; iword++)
265 buffer[iword] = busPatch[busno][iword];
268 outfile.write((char*)buffer,patchbusRDL*sizeof(UInt_t));
275 // Write real data header
276 // take the pointer to the beginning of the data header
277 // write the total number of words per ddl and bring the
278 // pointer to the current file position and close it
279 UInt_t cFPosition = outfile.tellp();
280 sizeRawData = cFPosition - bHPosition - sizeof(header);
282 header.fSize = cFPosition - bHPosition;
283 header.SetAttribute(0); // valid data
284 outfile.seekp(bHPosition);
285 outfile.write((char*)(&header),sizeof(header));
286 outfile.seekp(cFPosition);
293 //____________________________________________________________________________
294 void AliPMDDDLRawData::GetUMDigitsData(TTree *treeD, Int_t imodule,
295 Int_t ddlno, Int_t *contentsBus,
296 UInt_t busPatch[][1536])
298 // Retrives digits data UnitModule by UnitModule
302 Int_t det, smn, irow, icol;
304 const Int_t kMaxBus = 50;
305 Int_t totPatchBus, bPatchBus, ePatchBus;
306 Int_t ibus, totmcm, rows, cols, rowe, cole;
309 Int_t patchBusNo[kMaxBus], mcmperBus[kMaxBus];
310 Int_t startRowBus[kMaxBus], startColBus[kMaxBus];
311 Int_t endRowBus[kMaxBus], endColBus[kMaxBus];
313 Int_t beginPatchBus = -1;
314 Int_t endPatchBus = -1;
315 for(Int_t i = 0; i < kMaxBus; i++)
324 Int_t modulePerDDL = 0;
329 else if (ddlno == 4 || ddlno == 5)
338 TString fileName(gSystem->Getenv("ALICE_ROOT"));
342 fileName += "/PMD/PMD_Mapping_ddl0.dat";
346 fileName += "/PMD/PMD_Mapping_ddl1.dat";
350 fileName += "/PMD/PMD_Mapping_ddl2.dat";
354 fileName += "/PMD/PMD_Mapping_ddl3.dat";
358 fileName += "/PMD/PMD_Mapping_ddl4.dat";
362 fileName += "/PMD/PMD_Mapping_ddl5.dat";
366 infile.open(fileName.Data(), ios::in); // ascii file
368 AliError(Form("Could not read the mapping file for DDL No = %d",ddlno));
370 for (Int_t im = 0; im < modulePerDDL; im++)
373 infile >> totPatchBus >> bPatchBus >> ePatchBus;
375 if (moduleno == imodule)
377 beginPatchBus = bPatchBus;
378 endPatchBus = ePatchBus;
381 for(Int_t i=0; i<totPatchBus; i++)
383 infile >> ibus >> totmcm >> rows >> rowe >> cols >> cole;
385 if (moduleno == imodule)
387 patchBusNo[ibus] = ibus;
388 mcmperBus[ibus] = totmcm;
389 startRowBus[ibus] = rows;
390 startColBus[ibus] = cols;
391 endRowBus[ibus] = rowe;
392 endColBus[ibus] = cole;
400 treeD->GetEntry(imodule);
401 Int_t nentries = fDigits->GetLast();
402 Int_t totword = nentries+1;
404 for (Int_t ient = 0; ient < totword; ient++)
406 fPMDdigit = (AliPMDdigit*)fDigits->UncheckedAt(ient);
408 det = fPMDdigit->GetDetector();
409 smn = fPMDdigit->GetSMNumber();
410 irow = fPMDdigit->GetRow();
411 icol = fPMDdigit->GetColumn();
412 adc = (UInt_t) fPMDdigit->GetADC();
414 TransformS2H(smn,irow,icol);
416 GetMCMCh(ddlno, irow, icol, beginPatchBus, endPatchBus,
417 mcmperBus, startRowBus, startColBus,
418 endRowBus, endColBus, busno, mcmno, chno);
421 AliBitPacking::PackWord(adc,baseword,0,11);
422 AliBitPacking::PackWord(chno,baseword,12,17);
423 AliBitPacking::PackWord(mcmno,baseword,18,28);
424 AliBitPacking::PackWord(0,baseword,29,30);
425 AliBitPacking::PackWord(1,baseword,31,31);
427 Int_t jj = contentsBus[busno];
428 busPatch[busno][jj] = baseword;
430 contentsBus[busno]++;
435 //____________________________________________________________________________
436 void AliPMDDDLRawData::TransformS2H(Int_t smn, Int_t &irow, Int_t &icol)
438 // Does the Software to Hardware coordinate transformation
444 // First in digits we have all dimension 48x96
445 // Transform into the realistic one, i.e, For SM 0&1 96(row)x48(col)
446 // and for SM 2&3 48(row)x96(col)
453 else if( smn >= 12 && smn < 24)
459 // In the new geometry always Geant (0,0) and Hardware (0,0) start
460 // from the top left corner
468 //____________________________________________________________________________
470 void AliPMDDDLRawData::GetMCMCh(Int_t ddlno, Int_t row, Int_t col,
471 Int_t beginPatchBus, Int_t endPatchBus,
473 Int_t *startRowBus, Int_t *startColBus,
474 Int_t *endRowBus, Int_t *endColBus,
475 Int_t & busno, UInt_t &mcmno, UInt_t &chno)
477 // This part will be modified once the final track layout on the PCB is
478 // designed. This will only change the coordinate of the individual cell
480 static const UInt_t kCh[16][4] = { {12, 13, 18, 19},
497 Int_t irownew = row%16;
498 Int_t icolnew = col%4;
500 chno = kCh[irownew][icolnew];
503 for (Int_t ibus = beginPatchBus; ibus <= endPatchBus; ibus++)
505 Int_t srow = startRowBus[ibus];
506 Int_t erow = endRowBus[ibus];
507 Int_t scol = startColBus[ibus];
508 Int_t ecol = endColBus[ibus];
509 Int_t tmcm = mcmperBus[ibus];
510 if ((row >= srow && row <= erow) && (col >= scol && col <= ecol))
514 // Find out the MCM Number
517 if (ddlno == 0 || ddlno == 1)
519 // PRE plane, SU Mod = 0, 1
520 Int_t rowdiff = endRowBus[ibus] - startRowBus[ibus];
523 Int_t midrow = srow + 16;
524 if(row >= srow && row < midrow)
526 mcmno = 12 + (col-scol)/4;
528 else if(row >= midrow && row < erow)
530 mcmno = (col-scol)/4;
535 mcmno = (col-scol)/4;
537 } // end of ddl 0 and 1
540 // PRE plane, SU Mod = 2
542 Int_t icolnew = (col - scol)/4;
543 mcmno = tmcm - 1 - icolnew;
547 // PRE plane, SU Mod = 3
549 Int_t icolnew = (col - scol)/4;
550 mcmno = tmcm - 1 - icolnew;
554 // CPV plane, SU Mod = 0, 3 : ddl = 4
558 Int_t rowdiff = endRowBus[ibus] - startRowBus[ibus];
561 Int_t midrow = srow + 16;
562 if(row >= srow && row < midrow)
564 mcmno = 12 + (col-scol)/4;
566 else if(row >= midrow && row < erow)
568 mcmno = (col-scol)/4;
573 mcmno = (col-scol)/4;
578 Int_t icolnew = (col - scol)/4;
579 mcmno = tmcm - 1 - icolnew;
584 // CPV plane, SU Mod = 2, 1 : ddl = 5
588 Int_t rowdiff = endRowBus[ibus] - startRowBus[ibus];
591 Int_t midrow = srow + 16;
592 if(row >= srow && row < midrow)
594 mcmno = 12 + (col-scol)/4;
596 else if(row >= midrow && row < erow)
598 mcmno = (col-scol)/4;
603 mcmno = (col-scol)/4;
608 Int_t icolnew = (col - scol)/4;
609 mcmno = tmcm - 1 - icolnew;
616 //____________________________________________________________________________