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>
22 #include "AliRawDataHeader.h"
23 #include "AliBitPacking.h"
24 #include "AliPMDdigit.h"
25 #include "AliPMDRawStream.h"
26 #include "AliPMDDDLRawData.h"
29 ClassImp(AliPMDDDLRawData)
31 AliPMDDDLRawData::AliPMDDDLRawData():
32 fDigits(new TClonesArray("AliPMDdigit", 1000))
34 // Default Constructor
38 //____________________________________________________________________________
40 AliPMDDDLRawData::~AliPMDDDLRawData()
47 //____________________________________________________________________________
48 void AliPMDDDLRawData::WritePMDRawData(TTree *treeD)
50 // write digits into raw data format
54 TBranch *branch = treeD->GetBranch("PMDDigit");
56 branch->SetAddress(&fDigits);
58 // Int_t nmodules = (Int_t) treeD->GetEntries();
59 // cout << " nmodules = " << nmodules << endl;
61 const Int_t kSize = 4608;
63 Int_t modulePerDDL = 0;
66 AliRawDataHeader header;
67 UInt_t sizeRawData = 0;
75 for(Int_t iddl = 0; iddl < kDDL; iddl++)
77 sprintf(filename,"PMD_%d.ddl",AliPMDRawStream::kDDLOffset+iddl);
79 outfile.open(filename,ios::binary);
81 outfile.open(filename);
101 // Write the Dummy Data Header into the file
102 Int_t bHPosition = outfile.tellp();
103 outfile.write((char*)(&header),sizeof(header));
106 for(Int_t ium = 0; ium < modulePerDDL; ium++)
109 if (iddl == 4 && ium == 6) mmodule = 36;
110 if (iddl == 5 && ium == 6) mmodule = 42;
112 for (Int_t i = 0; i < kSize; i++)
116 // Extract energy deposition per cell and pack it
117 // in a 32-bit word and returns all the total words
118 // per one unit-module
120 GetUMDigitsData(treeD, mmodule, ium, iddl, totword, buffer);
122 outfile.write((char*)buffer,totword*sizeof(UInt_t));
128 // Write real data header
129 // take the pointer to the beginning of the data header
130 // write the total number of words per ddl and bring the
131 // pointer to the current file position and close it
132 UInt_t cFPosition = outfile.tellp();
133 sizeRawData = cFPosition - bHPosition - sizeof(header);
134 header.fSize = cFPosition - bHPosition;
135 header.SetAttribute(0); // valid data
136 outfile.seekp(bHPosition);
137 outfile.write((char*)(&header),sizeof(header));
138 outfile.seekp(cFPosition);
145 //____________________________________________________________________________
146 void AliPMDDDLRawData::GetUMDigitsData(TTree *treeD, Int_t imodule, Int_t ium,
147 Int_t ddlno, Int_t & totword,
150 // Retrives digits data UnitModule by UnitModule
154 Int_t det, smn, irow, icol;
156 treeD->GetEntry(imodule);
157 Int_t nentries = fDigits->GetLast();
158 totword = nentries+1;
160 for (Int_t ient = 0; ient < totword; ient++)
162 fPMDdigit = (AliPMDdigit*)fDigits->UncheckedAt(ient);
164 det = fPMDdigit->GetDetector();
165 smn = fPMDdigit->GetSMNumber();
166 irow = fPMDdigit->GetRow();
167 icol = fPMDdigit->GetColumn();
168 adc = (UInt_t) fPMDdigit->GetADC();
170 TransformS2H(smn,irow,icol);
171 GetMCMCh(ddlno, ium, irow, icol, mcmno, chno);
174 AliBitPacking::PackWord(adc,baseword,0,11);
175 AliBitPacking::PackWord(chno,baseword,12,17);
176 AliBitPacking::PackWord(mcmno,baseword,18,28);
177 AliBitPacking::PackWord(0,baseword,29,30);
178 AliBitPacking::PackWord(1,baseword,31,31);
180 buffer[ient] = baseword;
185 //____________________________________________________________________________
186 void AliPMDDDLRawData::TransformS2H(Int_t smn, Int_t &irow, Int_t &icol)
188 // Does the Software to Hardware coordinate transformation
195 // First in digits we have all dimension 48x96
196 // Transform into the realistic one, i.e, For SM 1&2 96x48
197 // and for SM 3&4 48x96
204 else if( smn >= 12 && smn < 24)
209 // This is the transformation of Geant (0,0) to the Hardware (0,0)
210 // which is always at the top left corner. This may change in future.
211 // Then accordingly we have to transform it.
214 irownew = 95 - irownew1;
217 else if(smn >= 6 && smn < 12)
220 icolnew = 47 - icolnew1;
222 else if(smn >= 12 && smn < 18)
224 irownew = 47 - irownew1;
227 else if(smn >= 18 && smn < 24)
230 icolnew = 95 - icolnew1;
239 //____________________________________________________________________________
241 void AliPMDDDLRawData::GetMCMCh(Int_t ddlno, Int_t um,
242 Int_t row, Int_t col,
243 UInt_t &mcmno, UInt_t &chno)
245 // This part will be modified once the final track layout on the PCB is
246 // designed. This will only change the coordinate of the individual cell
248 static const UInt_t kCh[16][4] = { {12, 13, 18, 19},
265 if (ddlno == 0 || ddlno == 1)
267 // PRE plane, SU Mod = 1, 2
268 Int_t irownew = row%16;
269 Int_t icolnew = col%4;
270 Int_t irowdiv = row/16;
271 Int_t icoldiv = col/4;
273 mcmno = 72*um + 12*irowdiv + icoldiv;
274 chno = kCh[irownew][icolnew];
276 else if (ddlno == 2 || ddlno == 3)
278 // PRE plane, SU Mod = 3, 4
279 Int_t irownew = row%16;
280 Int_t icolnew = col%4;
281 Int_t irowdiv = row/16;
282 Int_t icoldiv = col/4;
284 mcmno = 72*um + 24*irowdiv + icoldiv;
285 chno = kCh[irownew][icolnew];
287 else if (ddlno == 4 || ddlno == 5)
289 // CPV plane, SU Mod = 1, 3 : ddl = 4
290 // CPV plane, SU Mod = 2, 4 : ddl = 5
292 Int_t irownew = row%16;
293 Int_t icolnew = col%4;
294 Int_t irowdiv = row/16;
295 Int_t icoldiv = col/4;
299 mcmno = 72*um + 12*irowdiv + icoldiv;
303 mcmno = 72*um + 24*irowdiv + icoldiv;
305 chno = kCh[irownew][icolnew];
309 //____________________________________________________________________________