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