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