SDD raw data treatment: same format for real and simulated data
[u/mrichter/AliRoot.git] / ITS / AliITSDDLRawData.cxx
CommitLineData
2e9f335b 1/**************************************************************************
2 * Copyright(c) 1998-2003, 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 **************************************************************************/
9f992f70 15
30c1018e 16/* $Id$ */
a79660fb 17
9f992f70 18
a79660fb 19//This class contains all the necessary methods to create the Raw Data
20//files (slides) for the ITS data challenges for:
21//SPD
22//SDD
23//SSD
2e9f335b 24
25#include <stdlib.h>
2e9f335b 26#include <TClonesArray.h>
27#include <TTree.h>
7d62fb64 28#include "AliITSdigit.h"
2e9f335b 29#include "AliITSDDLRawData.h"
0421c3d1 30#include "AliRawDataHeader.h"
31#include "AliITSRawStreamSPD.h"
32#include "AliITSRawStreamSDD.h"
33#include "AliITSRawStreamSSD.h"
113c12f1 34#include "AliBitPacking.h"
362c9d61 35#include "AliDAQ.h"
2e9f335b 36
37ClassImp(AliITSDDLRawData)
38
39////////////////////////////////////////////////////////////////////////////////////////
e56160b8 40AliITSDDLRawData::AliITSDDLRawData():
41fVerbose(0),
42fIndex(-1),
43fHalfStaveModule(-1){
a79660fb 44 //Default constructor
e56160b8 45
2e9f335b 46}
47
48////////////////////////////////////////////////////////////////////////////////////////
49
ac74f489 50AliITSDDLRawData::AliITSDDLRawData(const AliITSDDLRawData &source) :
e56160b8 51 TObject(source),
52fVerbose(source.fVerbose),
53fIndex(source.fIndex),
54fHalfStaveModule(source.fHalfStaveModule){
a79660fb 55 //Copy Constructor
2e9f335b 56}
57
58////////////////////////////////////////////////////////////////////////////////////////
59
60AliITSDDLRawData& AliITSDDLRawData::operator=(const AliITSDDLRawData &source){
61 //Assigment operator
62 this->fIndex=source.fIndex;
63 this->fHalfStaveModule=source.fHalfStaveModule;
9f992f70 64 this->fVerbose=source.fVerbose;
2e9f335b 65 return *this;
66}
67
68////////////////////////////////////////////////////////////////////////////////////////
69//STRIP
70//
71
0b3c7dfc 72void AliITSDDLRawData::GetDigitsSSD(TClonesArray *ITSdigits,Int_t mod,Int_t modR,Int_t ddl,UInt_t *buf){
a79660fb 73 //This method packs the SSD digits in a proper 32 bits structure
2e9f335b 74 Int_t ix;
75 Int_t iz;
76 Int_t is;
0b3c7dfc 77 UInt_t word;
78 UInt_t baseWord;
2e9f335b 79 Int_t ndigits = ITSdigits->GetEntries();
80 AliITSdigit *digs;
9f992f70 81 ofstream ftxt;
2e9f335b 82 if(ndigits){
9f992f70 83 if (fVerbose==2){
84 ftxt.open("SSDdigits.txt",ios::app);
85 }
2e9f335b 86 for (Int_t digit=0;digit<ndigits;digit++) {
87 digs = (AliITSdigit*)ITSdigits->UncheckedAt(digit);
ecee53fc 88 iz=digs->GetCoord1(); // If iz==0, N side and if iz=1 P side
89 ix=digs->GetCoord2(); // Strip Numbar
7f1a504b 90 is=digs->GetCompressedSignal(); // ADC Signal
2e9f335b 91 // cout<<" Module:"<<mod-500<<" N/P side:"<<iz<<" Strip Number:"<<ix<<" Amplidute:"<<is-1<<endl;
9f992f70 92 if (fVerbose==2)
93 ftxt<<"DDL:"<<ddl<<" Mod: "<<modR<<" N/P: "<<iz<<" Strip: "<<ix<<" Value: "<<is-1<<endl;
a79660fb 94 baseWord=0;
95 word=is-1;
113c12f1 96 AliBitPacking::PackWord(word,baseWord,0,9);//ADC data
a79660fb 97 word=ix;
113c12f1 98 AliBitPacking::PackWord(word,baseWord,10,19);//Strip Number
a79660fb 99 word=iz;
113c12f1 100 AliBitPacking::PackWord(word,baseWord,20,20);//ADC Channel ID (N or P side)
a79660fb 101 word=mod;
113c12f1 102 AliBitPacking::PackWord(word,baseWord,21,31);//ADC module ID
2e9f335b 103 fIndex++;
a79660fb 104 buf[fIndex]=baseWord;
2e9f335b 105 }//end for
106 }//end if
9f992f70 107 if (fVerbose==2)
108 ftxt.close();
2e9f335b 109 return;
110}//end GetDigitsSSD
111
112////////////////////////////////////////////////////////////////////////////////////////
113//Silicon Drift Detector
114//
115
0b3c7dfc 116void AliITSDDLRawData::GetDigitsSDD(TClonesArray *ITSdigits,Int_t mod,Int_t modR,Int_t ddl,UInt_t *buf){
a97b3678 117 //This method packs the SDD digits in a proper 32 bits structure
2e9f335b 118 Int_t ix;
119 Int_t iz;
120 Int_t is;
a97b3678 121 UInt_t word=0;
122 UInt_t baseWord=0;
2e9f335b 123 Int_t ndigits = ITSdigits->GetEntries();
124 AliITSdigit *digs;
9f992f70 125 ofstream ftxt;
a97b3678 126 Int_t digarr[512][256];
127 for(Int_t i=0;i<512;i++){
128 for(Int_t j=0;j<256;j++){
129 digarr[i][j]=0;
130 }
131 }
132 //word to select the 12 carlos for the 12 modules
133 UInt_t carlosid=0;
134 if(mod==0) carlosid=805306368;
135 if(mod==1) carlosid=805306369;
136 if(mod==2) carlosid=805306370;
137 if(mod==3) carlosid=805306371;
138 if(mod==4) carlosid=805306372;
139 if(mod==5) carlosid=805306373;
140 if(mod==6) carlosid=805306374;
141 if(mod==7) carlosid=805306375;
142 if(mod==8) carlosid=805306376;
143 if(mod==9) carlosid=805306377;
144 if(mod==10) carlosid=805306378;
145 if(mod==11) carlosid=805306379;
146
147 fIndex++;
148 buf[fIndex]=carlosid;
149 Int_t first=0;
150 Int_t last=0;
151 Int_t diff=0;
152 Int_t nbit=0;
153 UInt_t word2=0;
154 Bool_t flag = kFALSE;
155 baseWord=0;
156 Int_t bitinfo1[4] = {3,8,3,7}; //vector with info on bit for timebin info
157 Int_t wordinfo1[4]= {0,0,0,0}; //vector with word info for timebin info
158 Int_t bitinfo2[2] = {3,18}; //vector with info on bit for EOR (end of row) info
159 Int_t wordinfo2[3]= {1,65593}; //vector with word info for anode info
160
161 /* for time bin info: word n bits meaning
162 0 3 next info is timebin
163 8 3 next word is 8 bit long
164 tb value 8 timebin value
165 n (2->7) 3 next info is n bit long
166 signal n signal value
167
168 for anode info: 1 3 next 18 bits are for EOR
169 increments the anode value
170
171 EOR 18 error codes + other info
172 */
173
2e9f335b 174 if(ndigits){
9f992f70 175 if (fVerbose==2)
176 ftxt.open("SDDdigits.txt",ios::app);
2e9f335b 177 for (Int_t digit=0;digit<ndigits;digit++) {
178 digs = (AliITSdigit*)ITSdigits->UncheckedAt(digit);
ecee53fc 179 iz=digs->GetCoord1(); // Anode
180 ix=digs->GetCoord2(); // Time
7f1a504b 181 is=digs->GetCompressedSignal(); // ADC Signal
a97b3678 182 digarr[iz][ix]=is;
183 if (fVerbose==2)
9f992f70 184 ftxt<<"DDL:"<<ddl<<" MID:"<<modR<<" An:"<<iz<<" T:"<<ix<<" A:"<<is<<endl;
0421c3d1 185 if (is>255){Error("GetDigitsSDD", "bits words is needed)!!!");}
a97b3678 186 }
2e9f335b 187
a97b3678 188 for(Int_t anode=0;anode<512;anode++){
189 if(flag){
190 last = first+diff-1;
191 AliBitPacking::PackWord(word2,baseWord,first,last);
192 flag = kFALSE;
193 first = last+1;
194 diff=0;
195 }
196
197
198 if(anode == 256){
199 last = 0;
200 first = 0;
201 flag = kFALSE;
202 diff = 0;
203 word2=0;
204
205 }
206
207 for(Int_t tb=0;tb<256;tb++){
208 if(digarr[anode][tb]!=0){
209 if(flag){
210 last = first+diff-1;
211 AliBitPacking::PackWord(word2,baseWord,first,last);
212 flag = kFALSE;
213 first = last+1;
214 diff=0;
215 }
216 wordinfo1[1] = tb;
217 //non lossy compression as it is done in Carlos
218 //(data are already 10to8bit compressed by AMBRA
219
220 /* if value < 8 value = value - (1 << 2) (word is 2 bit long)
221 if value < 16 value = value - (1 << 3) (word is 3 bit long)
222 if value < 32 value = value - (1 << 4) (word is 4 bit long)
223 if value < 64 value = value - (1 << 5) (word is 5 bit long)
224 if value <128 value = value - (1 << 6) (word is 6 bit long)
225 if value >=128value = value - (1 << 7) (word is 7 bit long)
226
227 */
228 if(digarr[anode][tb]<8){
229 bitinfo1[3] = 2;
230 wordinfo1[2] = 2;
231 wordinfo1[3] = digarr[anode][tb]-(1 << bitinfo1[3]);
232 }
233 if(digarr[anode][tb]>=8 && digarr[anode][tb]<16){
234 bitinfo1[3] = 3;
235 wordinfo1[2] = 3;
236 wordinfo1[3] = digarr[anode][tb]-(1 << bitinfo1[3]);
237 }
238 if(digarr[anode][tb]>=16 && digarr[anode][tb]<32){
239 bitinfo1[3] = 4;
240 wordinfo1[2] = 4;
241 wordinfo1[3] = digarr[anode][tb]-(1 << bitinfo1[3]);
242 }
243 if(digarr[anode][tb]>=32 && digarr[anode][tb]<64){
244 bitinfo1[3] = 5;
245 wordinfo1[2] = 5;
246 wordinfo1[3] = digarr[anode][tb]-(1 << bitinfo1[3]);
247 }
248 if(digarr[anode][tb]>=64 && digarr[anode][tb]<128){
249 bitinfo1[3] = 6;
250 wordinfo1[2] = 6;
251 wordinfo1[3] = digarr[anode][tb]-(1 << bitinfo1[3]);
252 }
253 if(digarr[anode][tb]>=128){
254 bitinfo1[3] = 7;
255 wordinfo1[2] = 7;
256 wordinfo1[3] = digarr[anode][tb]-(1 << bitinfo1[3]);
257 }
258
259 for(Int_t ie=0;ie<4;ie++){
260
261 if(flag){
262 last = first+diff-1;
263 AliBitPacking::PackWord(word2,baseWord,first,last);
264 flag = kFALSE;
265 first = last+1;
266 diff=0;
267 }
268 last = first+bitinfo1[ie]-1;
269 if(first < 30 && last < 30){
270 AliBitPacking::PackWord(wordinfo1[ie],baseWord,first,last);
271 first = last+1;
272 }
273 else{
274 if(first<=29){
275 UInt_t w = AliBitPacking::UnpackWord(wordinfo1[ie],0,29-first);
276 AliBitPacking::PackWord(w,baseWord,first,29);
277 Int_t lb = 29-first+1;
278 diff = bitinfo1[ie]-lb;
279 word2 = AliBitPacking::UnpackWord(wordinfo1[ie],lb,lb+diff-1);
280 flag = kTRUE;
281 if(anode<256) word = 2;//channel 0 of carlos
282 else word = 3; //channel 1 of carlos
283 AliBitPacking::PackWord(word,baseWord,30,31);
284 fIndex++;
285 buf[fIndex]=baseWord;
286 first=0;
287 last = 0;
288 baseWord=0;
289 word = 0;
290 }
291 else{
292 word2 = wordinfo1[ie];
293 diff = bitinfo1[ie];
294 flag = kTRUE;
295 if(anode<256) word = 2; //channel 0 of carlos
296 else word = 3; //channel 1 of carlos
297 AliBitPacking::PackWord(word,baseWord,30,31);
298 fIndex++;
299 buf[fIndex]=baseWord;
300 first=0;
301 last=0;
302 baseWord=0;
303 word = 0;
304 }
305 }
306 }
307
308 }//END IF
309
310 }//end loop on tb
311
312 for(Int_t i=0;i<2;i++){
313 if(flag){
314 last = first+diff-1;
315 AliBitPacking::PackWord(word2,baseWord,first,last);
316 flag = kFALSE;
317 first = last+1;
318 diff=0;
319 }
320
321 word = wordinfo2[i];
322 nbit = bitinfo2[i];
323 last = first+nbit-1;
324 if(first < 30 && last < 30){
325 AliBitPacking::PackWord(word,baseWord,first,last); //3 bit code =1 -> next 18 bits for EOR
326 first = last+1;
327 }
328
329 else{
330 if(first<=29){
331 UInt_t w = AliBitPacking::UnpackWord(word,0,29-first);
332 AliBitPacking::PackWord(w,baseWord,first,29);
333 Int_t lb = 29-first+1;
334 diff = nbit-lb;
335 word2 = AliBitPacking::UnpackWord(word,lb,lb+diff-1);
336 flag = kTRUE;
337 if(anode<256) word = 2;
338 else word = 3;
339 AliBitPacking::PackWord(word,baseWord,30,31);
340 fIndex++;
341 buf[fIndex]=baseWord;
342 first=0;
343 last = 0;
344 baseWord=0;
345 if(anode==255){
346 flag=kFALSE;
347 word2=0;
348 }
349 }
350 else{
351 word2 = word;
352 diff = nbit;
353 flag = kTRUE;
354 if(anode<256) word = 2;
355 else word = 3;
356 AliBitPacking::PackWord(word,baseWord,30,31);
357 fIndex++;
358 buf[fIndex]=baseWord;
359 first=0;
360 last=0;
361 baseWord=0;
362 if(anode==255){
363 flag=kFALSE;
364 word2=0;
365 }
366 }
367 }
368 }
369 } //end for
370
371 }
9f992f70 372 if(fVerbose==2)
373 ftxt.close();
2e9f335b 374 return;
375}//end GetDigitsSDD
376
377////////////////////////////////////////////////////////////////////////////////////////
378//PIXEL
379//
380
0b3c7dfc 381void AliITSDDLRawData::GetDigitsSPD(TClonesArray *ITSdigits,Int_t mod,Int_t ddl, UInt_t *buf){
9f992f70 382 //This method packs the SPD digits in a proper 32 structure
383 //Since data is zero suppressed,the coordinates for the chip having zero digits
384 //doesn't get listed in the galice.root file. However the SPD format requires
385 //the empty chip to be written with chip header and chip trailer.
a643f6be 386 //The index of the half stave is calculated as (mod/2).
2e9f335b 387 Int_t ix;
388 Int_t iz;
a79660fb 389 Int_t chipNo=0;
0b3c7dfc 390 UInt_t baseWord=0;
391 UInt_t hitRow=0;
a79660fb 392 Int_t chipHitCount=0; //Number of Hit in the current chip
393 Int_t previousChip=-1; //Previuos chip respect to the actual aone
2e9f335b 394 Int_t ndigits = ITSdigits->GetEntries(); //number of digits in the current module
395 //cout<<" Number of digits in the current module:"<<ndigits<<" module:"<<mod<<endl;
396 AliITSdigit *digs;
397 fHalfStaveModule++; //It's a private variable used to distinguish between the firs
398 //and the second module of an Half Stave Module
9f992f70 399 ofstream ftxt;
2e9f335b 400 if(ndigits){
401 //loop over digits
9f992f70 402 if (fVerbose==2)
403 ftxt.open("SPDdigits.txt",ios::app);
2e9f335b 404 for (Int_t digit=0;digit<ndigits;digit++){
405 digs = (AliITSdigit*)ITSdigits->UncheckedAt(digit);
406 /*---------------------------------------------------------------------------
407 * Each module contains 5 read out chips of 256 rows and 32 columns.
9f992f70 408 * So, the cell number in Z direction varies from 0 to 159. Therefore,
2e9f335b 409 * to get the chip address (0 to 4), we need to divide column number by 32.
410 * ---------------------------------------------------------------------*/
ecee53fc 411 iz=digs->GetCoord1(); // Cell number in Z direction
412 ix=digs->GetCoord2(); // Cell number in X direction
a79660fb 413 chipNo=iz/32;
9f992f70 414 if(fVerbose==2)
415 ftxt<<"DDL:"<<ddl<<" Mod:"<<mod<<" Row:"<<ix<<" Col:"<<iz<<endl;
a79660fb 416 hitRow=iz-chipNo*32;
2e9f335b 417 if(fHalfStaveModule){
a79660fb 418 chipNo+=5;
2e9f335b 419 fHalfStaveModule=-1;
420 }//end if
a79660fb 421 if(previousChip==-1){
2e9f335b 422 //loop over chip without digits
423 //Even if there aren't digits for a given chip
424 //the chip header and the chip trailer are stored
425 for(Int_t i=0;i<(iz/32);i++){
a79660fb 426 if(chipNo>4)
427 WriteChipHeader(i+5,(mod/2),baseWord);
2e9f335b 428 else
a79660fb 429 WriteChipHeader(i,(mod/2),baseWord);
430 WriteChipTrailer(buf,chipHitCount,baseWord);
9f992f70 431 chipHitCount=0;
2e9f335b 432 }//end for
a79660fb 433 WriteChipHeader(chipNo,(mod/2),baseWord);
434 chipHitCount++;
435 WriteHit(buf,ix,hitRow,baseWord);
9f992f70 436 previousChip=chipNo;
2e9f335b 437 }//end if
438 else{
a79660fb 439 if(previousChip!=chipNo){
9f992f70 440 WriteChipTrailer(buf,chipHitCount,baseWord);
441 chipHitCount=0;
a79660fb 442 for(Int_t i=previousChip+1;i<chipNo;i++){
443 WriteChipHeader(i,(mod/2),baseWord);
444 WriteChipTrailer(buf,0,baseWord);
9f992f70 445 chipHitCount=0;
2e9f335b 446 }//end for
a79660fb 447 WriteChipHeader(chipNo,(mod/2),baseWord);
448 previousChip=chipNo;
2e9f335b 449 }//end if
9f992f70 450 chipHitCount++;
a79660fb 451 WriteHit(buf,ix,hitRow,baseWord);
2e9f335b 452 }//end else
453 }//end for
454 //Even if there aren't digits for a given chip
455 //the chip header and the chip trailer are stored
a79660fb 456 Int_t end=4;
457 if(chipNo>4)end+=5;
458 WriteChipTrailer(buf,chipHitCount,baseWord);
9f992f70 459 chipHitCount=0;
a79660fb 460 for(Int_t i=chipNo+1;i<=end;i++){
461 WriteChipHeader(i,(mod/2),baseWord);
462 WriteChipTrailer(buf,0,baseWord);
9f992f70 463 chipHitCount=0;
2e9f335b 464 }//end for
465 }//end if
466 else{
467 //In this module there aren't digits but
468 //the chip header and chip trailer are store anyway
469 if(fHalfStaveModule){
a79660fb 470 chipNo=5;
2e9f335b 471 fHalfStaveModule=-1;
472 }//end if
473 for(Int_t i=0;i<5;i++){
a79660fb 474 WriteChipHeader(chipNo+i,(mod/2),baseWord);
475 WriteChipTrailer(buf,chipHitCount,baseWord);
9f992f70 476 chipHitCount=0;
2e9f335b 477 }//end for
478 }//end else
9f992f70 479 if(fVerbose==2)
480 ftxt.close();
2e9f335b 481 return;
482}//end GetDigitsSPD
483
2e9f335b 484/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
485
0421c3d1 486Int_t AliITSDDLRawData::RawDataSPD(TBranch* branch){
a79660fb 487 //This method creates the Raw data files for SPD detectors
a79660fb 488 const Int_t kSize=21000; //256*32*5=40960 max number of digits per module
0b3c7dfc 489 UInt_t buf[kSize]; //One buffer cell can contain 2 digits
2e9f335b 490 fIndex=-1;
2e9f335b 491
0421c3d1 492 TClonesArray*& digits = * (TClonesArray**) branch->GetAddress();
2e9f335b 493 char fileName[15];
2e9f335b 494 ofstream outfile; // logical name of the output file
0421c3d1 495 AliRawDataHeader header;
496
497 //loop over DDLs
362c9d61 498 for(Int_t i=0;i<AliDAQ::NumberOfDdls("ITSSPD");i++){
499 strcpy(fileName,AliDAQ::DdlFileName("ITSSPD",i)); //The name of the output file.
30c1018e 500#ifndef __DECCXX
0421c3d1 501 outfile.open(fileName,ios::binary);
30c1018e 502#else
0421c3d1 503 outfile.open(fileName);
30c1018e 504#endif
0421c3d1 505 //write Dummy DATA HEADER
506 UInt_t dataHeaderPosition=outfile.tellp();
507 outfile.write((char*)(&header),sizeof(header));
2e9f335b 508 //Loops over Modules of a particular DDL
0421c3d1 509 for (Int_t mod=0; mod<AliITSRawStreamSPD::kModulesPerDDL; mod++){
510 Int_t moduleNumber = AliITSRawStreamSPD::GetModuleNumber(i, mod);
511 digits->Clear();
512 branch->GetEvent(moduleNumber);
2e9f335b 513 //For each Module, buf contains the array of data words in Binary format
514 //fIndex gives the number of 32 bits words in the buffer for each module
a643f6be 515 GetDigitsSPD(digits,mod,i,buf);
0b3c7dfc 516 outfile.write((char *)buf,((fIndex+1)*sizeof(UInt_t)));
2e9f335b 517 for(Int_t i=0;i<(fIndex+1);i++){
518 buf[i]=0;
519 }//end for
520 fIndex=-1;
521 }//end for
522
0421c3d1 523 //Write REAL DATA HEADER
0b3c7dfc 524 UInt_t currentFilePosition=outfile.tellp();
0421c3d1 525 outfile.seekp(dataHeaderPosition);
526 header.fSize=currentFilePosition-dataHeaderPosition;
0421c3d1 527 outfile.write((char*)(&header),sizeof(header));
528 outfile.close();
2e9f335b 529 }//end for
0421c3d1 530
2e9f335b 531 return 0;
532}
533
534/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
535
0421c3d1 536Int_t AliITSDDLRawData::RawDataSSD(TBranch* branch){
a97b3678 537
a79660fb 538 //This method creates the Raw data files for SSD detectors
a79660fb 539 const Int_t kSize=1536;//768*2 Number of stripe * number of sides(N and P)
0b3c7dfc 540 UInt_t buf[kSize];
2e9f335b 541 fIndex=-1;
0421c3d1 542
543 TClonesArray*& digits = * (TClonesArray**) branch->GetAddress();
2e9f335b 544 char fileName[15];
0421c3d1 545 ofstream outfile; // logical name of the output file
546 AliRawDataHeader header;
2e9f335b 547
0421c3d1 548 //loop over DDLs
362c9d61 549 for(Int_t i=0;i<AliDAQ::NumberOfDdls("ITSSSD");i++){
550 strcpy(fileName,AliDAQ::DdlFileName("ITSSSD",i)); //The name of the output file.
30c1018e 551#ifndef __DECCXX
0421c3d1 552 outfile.open(fileName,ios::binary);
30c1018e 553#else
0421c3d1 554 outfile.open(fileName);
30c1018e 555#endif
0421c3d1 556 //write Dummy DATA HEADER
557 UInt_t dataHeaderPosition=outfile.tellp();
558 outfile.write((char*)(&header),sizeof(header));
2e9f335b 559
560 //Loops over Modules of a particular DDL
0421c3d1 561 for (Int_t mod=0; mod<AliITSRawStreamSSD::kModulesPerDDL; mod++){
562 Int_t moduleNumber = AliITSRawStreamSSD::GetModuleNumber(i, mod);
563 if(moduleNumber!=-1){
564 digits->Clear();
565 branch->GetEvent(moduleNumber);
2e9f335b 566 //For each Module, buf contains the array of data words in Binary format
567 //fIndex gives the number of 32 bits words in the buffer for each module
0421c3d1 568 GetDigitsSSD(digits,mod,moduleNumber,i,buf);
0b3c7dfc 569 outfile.write((char *)buf,((fIndex+1)*sizeof(UInt_t)));
2e9f335b 570 fIndex=-1;
571 }//end if
572 }//end for
0421c3d1 573
574 //Write REAL DATA HEADER
0b3c7dfc 575 UInt_t currentFilePosition=outfile.tellp();
0421c3d1 576 outfile.seekp(dataHeaderPosition);
577 header.fSize=currentFilePosition-dataHeaderPosition;
578 header.SetAttribute(0); // valid data
579 outfile.write((char*)(&header),sizeof(header));
580 outfile.close();
2e9f335b 581 }//end for
0421c3d1 582
2e9f335b 583 return 0;
584}
585
586/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
587
0421c3d1 588Int_t AliITSDDLRawData::RawDataSDD(TBranch* branch){
a79660fb 589 //This method creates the Raw data files for SDD detectors
a79660fb 590 const Int_t kSize=131072; //256*512
0b3c7dfc 591 UInt_t buf[kSize];
2e9f335b 592 fIndex=-1;
2e9f335b 593
0421c3d1 594 TClonesArray*& digits = * (TClonesArray**) branch->GetAddress();
595 char fileName[15];
2e9f335b 596 ofstream outfile; // logical name of the output file
0421c3d1 597 AliRawDataHeader header;
a97b3678 598 UInt_t skippedword = AliBitPacking::PackWord(2,skippedword,0,31);
0421c3d1 599
600 //loop over DDLs
362c9d61 601 for(Int_t i=0;i<AliDAQ::NumberOfDdls("ITSSDD");i++){
602 strcpy(fileName,AliDAQ::DdlFileName("ITSSDD",i)); //The name of the output file.
30c1018e 603#ifndef __DECCXX
0421c3d1 604 outfile.open(fileName,ios::binary);
30c1018e 605#else
0421c3d1 606 outfile.open(fileName);
30c1018e 607#endif
0421c3d1 608 //write Dummy DATA HEADER
609 UInt_t dataHeaderPosition=outfile.tellp();
610 outfile.write((char*)(&header),sizeof(header));
611
a97b3678 612 //first 8 "dummy" words to be skipped
613 for(Int_t iw=0;iw<8;iw++){
614 outfile.write((char*)&skippedword,sizeof(skippedword));
615 }
616
2e9f335b 617 //Loops over Modules of a particular DDL
0421c3d1 618 for (Int_t mod=0; mod<AliITSRawStreamSDD::kModulesPerDDL; mod++){
619 Int_t moduleNumber = AliITSRawStreamSDD::GetModuleNumber(i, mod);
620 if(moduleNumber!=-1){
621 digits->Clear();
622 branch->GetEvent(moduleNumber);
a97b3678 623
2e9f335b 624 //For each Module, buf contains the array of data words in Binary format
625 //fIndex gives the number of 32 bits words in the buffer for each module
a79660fb 626 // cout<<"MODULE NUMBER:"<<mapSDD[i][mod]<<endl;
0421c3d1 627 GetDigitsSDD(digits,mod,moduleNumber,i,buf);
0b3c7dfc 628 outfile.write((char *)buf,((fIndex+1)*sizeof(UInt_t)));
2e9f335b 629 fIndex=-1;
630 }//end if
631 }//end for
632
0421c3d1 633 //Write REAL DATA HEADER
0b3c7dfc 634 UInt_t currentFilePosition=outfile.tellp();
0421c3d1 635 outfile.seekp(dataHeaderPosition);
636 header.fSize=currentFilePosition-dataHeaderPosition;
637 header.SetAttribute(0); // valid data
638 outfile.write((char*)(&header),sizeof(header));
a97b3678 639
0421c3d1 640 outfile.close();
2e9f335b 641 }//end for
0421c3d1 642
2e9f335b 643 return 0;
644}
645
646/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
647
a643f6be 648void AliITSDDLRawData::WriteChipHeader(Int_t ChipAddr,Int_t halfStave,UInt_t &BaseWord){
a79660fb 649 //This method writes a chip header
a643f6be 650 //cout<<"Chip: "<<ChipAddr<<" Half Stave module:"<<halfStave<<endl;
2e9f335b 651 BaseWord=0;
a643f6be 652 AliBitPacking::PackWord(ChipAddr,BaseWord,16,19);
653 // At the moment the event count is always 0 (bits 20-26)
654 AliBitPacking::PackWord(0,BaseWord,20,26);
655 AliBitPacking::PackWord(halfStave,BaseWord,27,29);
656 AliBitPacking::PackWord(0x1,BaseWord,30,31);
2e9f335b 657 return;
658}//end WriteChipHeader
659
660/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
661
0b3c7dfc 662void AliITSDDLRawData::WriteChipTrailer(UInt_t *buf,Int_t ChipHitCount,UInt_t &BaseWord){
a79660fb 663 //This method writes a chip trailer
2e9f335b 664 //pixel fill word
665 if((ChipHitCount%2)!=0){
a643f6be 666 AliBitPacking::PackWord(0xC000,BaseWord,16,31);
2e9f335b 667 }
a643f6be 668 AliBitPacking::PackWord(ChipHitCount,BaseWord,0,13);
669 AliBitPacking::PackWord(0x0,BaseWord,14,15);
2e9f335b 670 fIndex++;
671 buf[fIndex]=BaseWord;
672 BaseWord=0;
673 return;
674}//end WriteChipTrailer
675
676/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
677
0b3c7dfc 678void AliITSDDLRawData::WriteHit(UInt_t *buf,Int_t RowAddr,Int_t HitAddr,UInt_t &BaseWord){
a79660fb 679 //This method writs an hit
2e9f335b 680 if(!BaseWord){
113c12f1 681 AliBitPacking::PackWord(HitAddr,BaseWord,16,20);
682 AliBitPacking::PackWord(RowAddr,BaseWord,21,28);
683 AliBitPacking::PackWord(2,BaseWord,30,31);
a643f6be 684 }//end if
685 else{
686 AliBitPacking::PackWord(HitAddr,BaseWord,0,4);
687 AliBitPacking::PackWord(RowAddr,BaseWord,5,12);
688 AliBitPacking::PackWord(2,BaseWord,14,15);
2e9f335b 689 fIndex++;
690 buf[fIndex]=BaseWord;
691 BaseWord=0;
692 }//end else
693 return;
694}//end WriteHit
695