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 "AliPMDdigit.h"
24 #include "AliPMDRawStream.h"
25 #include "AliPMDDDLRawData.h"
28 ClassImp(AliPMDDDLRawData)
30 AliPMDDDLRawData::AliPMDDDLRawData():
31 fDigits(new TClonesArray("AliPMDdigit", 1000))
33 // Default Constructor
37 //____________________________________________________________________________
39 AliPMDDDLRawData::~AliPMDDDLRawData()
46 //____________________________________________________________________________
47 void AliPMDDDLRawData::WritePMDRawData(TTree *treeD)
49 // write digits into raw data format
53 TBranch *branch = treeD->GetBranch("PMDDigit");
55 branch->SetAddress(&fDigits);
57 // Int_t nmodules = (Int_t) treeD->GetEntries();
58 // cout << " nmodules = " << nmodules << endl;
60 const Int_t kSize = 4608;
62 Int_t modulePerDDL = 0;
65 AliRawDataHeader header;
66 UInt_t sizeRawData = 0;
74 for(Int_t iddl = 0; iddl < kDDL; iddl++)
76 sprintf(filename,"PMD_%d.ddl",AliPMDRawStream::kDDLOffset+iddl);
78 outfile.open(filename,ios::binary);
80 outfile.open(filename);
100 // Write the Dummy Data Header into the file
101 Int_t bHPosition = outfile.tellp();
102 outfile.write((char*)(&header),sizeof(header));
105 for(Int_t ium = 0; ium < modulePerDDL; ium++)
108 if (iddl == 4 && ium == 6) mmodule = 36;
109 if (iddl == 5 && ium == 6) mmodule = 42;
111 for (Int_t i = 0; i < kSize; i++)
115 // Extract energy deposition per cell and pack it
116 // in a 32-bit word and returns all the total words
117 // per one unit-module
119 GetUMDigitsData(treeD, mmodule, ium, iddl, totword, buffer);
121 outfile.write((char*)buffer,totword*sizeof(UInt_t));
127 // Write real data header
128 // take the pointer to the beginning of the data header
129 // write the total number of words per ddl and bring the
130 // pointer to the current file position and close it
131 UInt_t cFPosition = outfile.tellp();
132 sizeRawData = cFPosition - bHPosition - sizeof(header);
133 header.fSize = cFPosition - bHPosition;
134 header.SetAttribute(0); // valid data
135 outfile.seekp(bHPosition);
136 outfile.write((char*)(&header),sizeof(header));
137 outfile.seekp(cFPosition);
144 //____________________________________________________________________________
145 void AliPMDDDLRawData::GetUMDigitsData(TTree *treeD, Int_t imodule, Int_t ium,
146 Int_t ddlno, Int_t & totword,
150 UInt_t dataword, baseword;
158 Int_t det, smn, irow, icol;
161 treeD->GetEntry(imodule);
162 Int_t nentries = fDigits->GetLast();
163 totword = nentries+1;
165 for (Int_t ient = 0; ient < totword; ient++)
167 fPMDdigit = (AliPMDdigit*)fDigits->UncheckedAt(ient);
169 det = fPMDdigit->GetDetector();
170 smn = fPMDdigit->GetSMNumber();
171 irow = fPMDdigit->GetRow();
172 icol = fPMDdigit->GetColumn();
173 adc = (UInt_t) fPMDdigit->GetADC();
175 // cout << " imodule = " << imodule << " smn = " << smn << endl;
182 else if( smn >= 12 && smn < 24)
190 irownew = 95 - irownew1;
193 else if(smn >= 6 && smn < 12)
196 icolnew = 47 - icolnew1;
198 else if(smn >= 12 && smn < 18)
200 irownew = 47 - irownew1;
203 else if(smn >= 18 && smn < 24)
206 icolnew = 95 - icolnew1;
211 GetMCMCh(ddlno, ium, irownew, icolnew, mcmno, chno);
215 PackWord(0, 11,dataword,baseword);
217 PackWord(12,17,dataword,baseword);
219 PackWord(18,28,dataword,baseword);
221 PackWord(29,29,dataword,baseword);
223 PackWord(30,30,dataword,baseword);
225 PackWord(31,31,dataword,baseword);
227 buffer[ient] = baseword;
233 //____________________________________________________________________________
234 void AliPMDDDLRawData::GetMCMCh(Int_t ddlno, Int_t um,
235 Int_t row, Int_t col,
236 UInt_t &mcmno, UInt_t &chno)
238 // This part will be modified once the final track layout on the PCB is
239 // designed. This will only change the coordinate of the individual cell
241 static const UInt_t kCh[16][4] = { {12, 13, 18, 19},
258 if (ddlno == 0 || ddlno == 1)
260 // PRE plane, SU Mod = 1, 2
261 Int_t irownew = row%16;
262 Int_t icolnew = col%4;
263 Int_t irowdiv = row/16;
264 Int_t icoldiv = col/4;
266 mcmno = 72*um + 12*irowdiv + icoldiv;
267 chno = kCh[irownew][icolnew];
269 else if (ddlno == 2 || ddlno == 3)
271 // PRE plane, SU Mod = 3, 4
272 Int_t irownew = row%16;
273 Int_t icolnew = col%4;
274 Int_t irowdiv = row/16;
275 Int_t icoldiv = col/4;
277 mcmno = 72*um + 24*irowdiv + icoldiv;
278 chno = kCh[irownew][icolnew];
280 else if (ddlno == 4 || ddlno == 5)
282 // CPV plane, SU Mod = 1, 3 : ddl = 4
283 // CPV plane, SU Mod = 2, 4 : ddl = 5
285 Int_t irownew = row%16;
286 Int_t icolnew = col%4;
287 Int_t irowdiv = row/16;
288 Int_t icoldiv = col/4;
292 mcmno = 72*um + 12*irowdiv + icoldiv;
296 mcmno = 72*um + 24*irowdiv + icoldiv;
298 chno = kCh[irownew][icolnew];
302 //____________________________________________________________________________
304 void AliPMDDDLRawData::PackWord(UInt_t startbit, UInt_t stopbit,
305 UInt_t dataword, UInt_t &packedword)
307 UInt_t bitLength = stopbit - startbit + 1;
308 UInt_t bitContent = (UInt_t) (TMath::Power(2,bitLength) - 1);
309 if(bitContent < dataword)
311 cout << " *** ERROR *** bitContent is less than the dataword" << endl;
314 UInt_t packedBits = 0;
316 packedBits = (UInt_t) (TMath::Log(packedword)/TMath::Log(2));
319 if (packedBits <= stopbit)
321 counter = 31 - stopbit;
325 counter = 31 - packedBits;
327 UInt_t dummyword = 0xFFFFFFFF;
328 dummyword >>= counter;
329 UInt_t lword = dataword << startbit;
330 UInt_t nword = lword | packedword;
331 packedword = dummyword & nword;
335 //____________________________________________________________________________
336 void AliPMDDDLRawData::UnpackWord(UInt_t startbit, UInt_t stopbit,
337 UInt_t &dataword, UInt_t packedword)
339 UInt_t bitLength = stopbit - startbit + 1;
340 UInt_t bitContent = (UInt_t) (TMath::Power(2,bitLength) - 1);
341 bitContent <<= startbit;
342 dataword = packedword & bitContent;
343 dataword >>= startbit;
346 //____________________________________________________________________________