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