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