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