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