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