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