Adding macro to plot <Ncoll>
[u/mrichter/AliRoot.git] / FIT / AliFITRawData.cxx
CommitLineData
c1c44db3 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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// //
20// FIT raw data conversion class //
21// //
22///////////////////////////////////////////////////////////////////////////////
23
24//#include <Riostream.h>
25//#include <TTree.h>
26#include <TMap.h>
27#include "AliFIT.h"
28#include "AliFITRawData.h"
29#include "AliFITDigit.h"
30#include "AliBitPacking.h"
31#include "AliRawDataHeader.h"
32#include "AliRawDataHeaderSim.h"
33#include "AliBitPacking.h"
34#include "AliFstream.h"
35#include "AliRunLoader.h"
36#include "AliDAQ.h"
37
38using std::cout;
39using std::endl;
5e2539d9 40using std::ios_base;
41
c1c44db3 42ClassImp(AliFITRawData)
43
44//_____________________________________________________________________________
45 AliFITRawData::AliFITRawData():TObject(),
46 fFITdigitArray(NULL),
47 fVerbose(0),
48 fIndex(-1) ,
49 fEventNumber(0),
50 fDataHeaderPos(0),
51 fFile(0x0)
52
53{
54 /*
55 - 160 channels (2 words each as in TOF DDL) for :
56 word 1 :0-5bit number of PMT; word 2: 0-7 error sign, 8-31 TDC
57 and the same but for amplified signal. Now I wrote the same time because
58 CDF are not ready and differences didn't measured yet.
59
60 - 160x2 channel for amplitude: very preliminary, QTC features are not
61 known now, preliminary i put as T1 time signal for this PMT in first
62 channel and T1+A in second, where A=Log(Amplitude);
63 and the same for amplified but A=Log(10*Amplitude).
64
65 - Or FIT-A and Or FIT-C 2 channels
66 - FITA-FITC vertex information
67 - Time Meaner (FITA+FITC)/2
68 - 4 MPD multiplicity signals sum amp both sides
69 */
70 //open the output file
71 // char fileName[15];
72 TString fileName = Form("%s",AliDAQ::DdlFileName("FIT",0));
73 fFile = new AliFstream(fileName.Data());
74 memset(fBuffer,0,512*sizeof(UInt_t));
75
76 //get event number
77 AliRunLoader *runloader = AliRunLoader::Instance();
78 if (runloader) {
79 fEventNumber = runloader->GetEventNumber();
80 }
75b7ee5e 81 for ( Int_t k=0; k<500; k++) fAllData[k] = -1;
82
c1c44db3 83}
84
85//_____________________________________________________________________________
86
87AliFITRawData::AliFITRawData(const AliFITRawData &r):TObject(),
88 fFITdigitArray(NULL),
89 fVerbose(0),
90 fIndex(-1) ,
91 fEventNumber(0),
92 fDataHeaderPos(0),
93 fFile(0x0)
94{
95 //
96 // AliFITrawData copy constructor
97 //
98
99 ((AliFITRawData &) r).Copy(*this);
75b7ee5e 100 for ( Int_t k=0; k<500; k++) fAllData[k] = -1;
101
c1c44db3 102
103}
104
105//_____________________________________________________________________________
106AliFITRawData::~AliFITRawData()
107{
108 //
109 // Destructor
110 //
111}
112
113//_____________________________________________________________________________
114AliFITRawData &AliFITRawData::operator=(const AliFITRawData &r)
115{
116 //
117 // Assignment operator
118 //
119
120 if (this != &r) ((AliFITRawData &) r).Copy(*this);
121 return *this;
122
123}
124
125//_____________________________________________________________________________
126void AliFITRawData::GetDigits()
127{
128
129 //This method packs the FIT digits in a proper 32 bits structure
130
131 //read FIT digits and fill TDC and ADC arrays
132
133 Int_t digit = -1;
134 Int_t ndigits = fFITdigitArray->GetEntries();
135 AliDebug(2, Form(" Number of read digits = %d",ndigits));
136 AliFITDigit *digs;
137 for(Int_t i=0; i<500; i++) fAllData[i]=-1;
138 // loop on FIT digits
139 for (digit=0; digit<ndigits; digit++) {
140 digs = (AliFITDigit*)fFITdigitArray->UncheckedAt(digit);
141 Int_t pmt = digs->NPMT();
142 fAllData[pmt] = digs->TimeCFD();
143 fAllData[pmt+160] = digs->TimeQT0();
144 fAllData[pmt+320] = digs->TimeQT1();
145 }
146 // Int_t error=0;
147
148}
149//---------------------------------------------------------------------------------------
150
151Int_t AliFITRawData::RawDataFIT(TBranch* branch)
152{
153 //This method creates the Raw data files for FIT detector
154
155
156 //max number of digits per DDL file times 2
157 // UInt_t fBuffer[kSize];
158 // UInt_t baseWord;
159 // UInt_t word;
160 cout.setf( ios_base::hex, ios_base::basefield );
161
162 fIndex=-1;
163 Int_t ch[4] = {0,2,4,6};
164
165 fFITdigitArray = * (TClonesArray**) branch->GetAddress();
166
167 AliRawDataHeaderSim header;
168 WriteDataHeader(kTRUE, kFALSE);
169
170 branch->GetEvent();
171
172 GetDigits();
173
174 Int_t time, positionOfTRMHeader, iTDC, channel;
175 //space for DRM header
176 fIndex += 6;
177 Int_t trm1words=0;
178
179 for (Int_t itrm=0; itrm <4 ; itrm++) {
180 Int_t startTRM=fIndex;
181 //space for 1st TRM header
182 fIndex ++;
183 positionOfTRMHeader= fIndex;
184
185 for (Int_t chain=0; chain <2 ; chain++) {
186 // space for chain header
187 fIndex ++;
188 WriteChainDataHeader(chain+1, 1); //
189 //data TRM 1 chain 1
190 for (Int_t det = 0; det < 60; det++) {
191 time = fAllData[det + itrm*120 + chain*60];
192 if (time >0 && time !=999999) {
193 fIndex++;
194 iTDC = det / 4;
195 channel = ch[det - iTDC*4];
196 AliDebug(2, Form("det %i alldata %i trm %i chain %i tdc %i channel %i \n",det, det + itrm*120 + chain*60, itrm, chain, iTDC, det - iTDC*4) );
197 FillTime(channel,iTDC, time);
198 }
199 }
200 fIndex++;
201 WriteChainDataTrailer (chain+1);
202 }
203 fIndex++;
204 WriteTrailer(15, 0,fEventNumber,5); // 1st TRM trailer
205
206 trm1words = fIndex - startTRM;
207 WriteTRMDataHeader(itrm, trm1words , positionOfTRMHeader);
208 }
209
210 //DRM trailer
211 fIndex++;
212 WriteTrailer(1,0,fEventNumber,5);
213 WriteDRMDataHeader();
214
215 //write packing digits
216 fFile->WriteBuffer((char*) fBuffer,((fIndex+1)*sizeof(UInt_t)));
217 //write real data header on its place
218 WriteDataHeader(kFALSE, kFALSE);
219
220
221 //end for
222
223 return 0;
224
225}
226
227//_____________________________________________________________________________
228
229void AliFITRawData::WriteDRMDataHeader()
230{
231 //Write a (dummy or real) DDL DRM data header,
232 //set the compression bit if compressed
233 // UInt_t drmheader[4];
234 cout.setf( ios_base::hex, ios_base::basefield );
235 UInt_t word;
236 UInt_t baseWord=0;
237 //fill DRM headers
238 //DRM Global Header
239 word = 1;
240 AliBitPacking::PackWord(word,baseWord,0, 3); // 0001
241 word = fIndex ;
242 AliBitPacking::PackWord(word,baseWord,4, 20); // event words
243 word=124;
244 AliBitPacking::PackWord(word,baseWord, 21, 27); // event words
245 word=4;
246 AliBitPacking::PackWord(word,baseWord,28, 31);// 0100 marks header
247 fBuffer[0]= baseWord;
248 //DRM status header 1
249 word = 1;
250 AliBitPacking::PackWord(word,baseWord,0, 3); // 0001
251 word = 1;
252 AliBitPacking::PackWord(word,baseWord,4, 14); // slotID now 0000000001
253 word = 1;
254 AliBitPacking::PackWord(word,baseWord,15, 15); //if 1 LHC clock is coorectly recieved from CPDM
255 word=0;
256 AliBitPacking::PackWord(word,baseWord,16,27); // reserve for future use
257 word=4;
258 AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
259 fBuffer[1] = baseWord;
260
261 word=0;
262 baseWord=0;
263
264 //DRM status header 2
265 word = 1;
266 AliBitPacking::PackWord(word,baseWord, 0, 3); // 0001
267 word = 3;
268 AliBitPacking::PackWord(word,baseWord, 4, 14); //enable slotID now 00000000011
269 word = 0;
270 AliBitPacking::PackWord(word,baseWord, 15, 15); // something
271 word=0;
272 AliBitPacking::PackWord(word,baseWord, 16, 27); // fault ID for simulation 0
273 word=4;
274 AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
275 fBuffer[2]= baseWord;
276
277 word=0;
278 baseWord=0;
279 //DRM status header 3
280 word = 1;
281 AliBitPacking::PackWord(word,baseWord,0, 3); // 0001
282 word = 0;
283 AliBitPacking::PackWord(word,baseWord,4, 27); // TTC event counter
284 word=4;
285 AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
286 fBuffer[3]= baseWord;
287
288 // new DRM format
289 fBuffer[4]= baseWord;
290 fBuffer[5]= baseWord;
291
292 word=0;
293 baseWord=0;
294
295}
296
297//_____________________________________________________________________________
298
299void AliFITRawData::WriteTRMDataHeader(UInt_t slotID, Int_t nWordsInTRM,
300 Int_t positionOfTRMHeader)
301{
302 //Write a (dummy or real) DDL TRM data header,
303 //set the compression bit if compressed
304 // UInt_t trmheader;
305 UInt_t word;
306 UInt_t baseWord=0;
307 //fill TRM headers
308 //TRM Global Header
309 word = slotID;
310 AliBitPacking::PackWord(word,baseWord,0, 3); // slotID
311 word = nWordsInTRM;
312 //+this word - DRM header
313
314 AliBitPacking::PackWord(word,baseWord,4, 16); // event words
315 word=0;
316 AliBitPacking::PackWord(word,baseWord,17,18); // ACQ
317 word=0;
318 AliBitPacking::PackWord(word,baseWord,19,19); // L SEY inside LUT
319 word=0;
320 AliBitPacking::PackWord(word,baseWord,20,27); // MBZ
321 word=4;
322 AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
323 fBuffer[positionOfTRMHeader] = baseWord;
324 word=0;
325 baseWord=0;
326}
327
328//_____________________________________________________________________________
329
330void AliFITRawData::WriteChainDataHeader(UInt_t chainNumber,UInt_t slotID)
331{
332 //Write a (dummy or real) DDL Chain data header,
333 //set the compression bit if compressed
334 // chainNumber 00 or 10
335 UInt_t word;
336 UInt_t baseWord=0;
337 //fill TRM headers
338 //TRM Global Header
339 word = slotID; // ask Tatiana 7 or 9
340 AliBitPacking::PackWord(word,baseWord,0, 3); // slotID
341 word = 0;
342 AliBitPacking::PackWord(word,baseWord,4, 15); // bunchID
343 word=0;
344 AliBitPacking::PackWord(word,baseWord,16,23); // PB24 temperature
345 word=0;
346 AliBitPacking::PackWord(word,baseWord,24,26); // PB24 ID
347 word=0;
348 AliBitPacking::PackWord(word,baseWord,27,27); // TS
349 word=chainNumber;
350 AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
351 fBuffer[fIndex] = baseWord;
352 word=0;
353 baseWord=0;
354}
355//_____________________________________________________________________________
356
357void AliFITRawData::WriteChainDataTrailer(UInt_t chainNumber )
358{
359 //Write a (dummy or real) DDL Chain data trailer
360 //set the compression bit if compressed
361 // chainNumber 00 or 10
362 UInt_t word;
363 UInt_t baseWord=0;
364 word = 0; // ask Tatiana 7 or 9
365 AliBitPacking::PackWord(word,baseWord,0, 3); // status
366 word = 0;
367 AliBitPacking::PackWord(word,baseWord,4, 15); // MBZ
368 word=fEventNumber;
369 AliBitPacking::PackWord(word,baseWord,16,27); // event counter
370 word=chainNumber;
371 AliBitPacking::PackWord(word,baseWord,28,31); // chain number
372 // fIndex++;
373 fBuffer[fIndex] = baseWord;
374
375 word=0;
376 baseWord=0;
377}
378//_____________________________________________________________________________
379
380void AliFITRawData::WriteDataHeader(Bool_t dummy, Bool_t compressed)
381{
382 //Write a (dummy or real) DDL data header,
383 //set the compression bit if compressed
384
385 AliRawDataHeaderSim header;
386
387 if (dummy) {
388 //if size=0 it means that this data header is a dummy data header
389 fDataHeaderPos = fFile->Tellp();
390 fFile->WriteBuffer((char*)(&header), sizeof(header));
391 } else {
392 UInt_t currentFilePos = fFile->Tellp();
393 fFile->Seekp(fDataHeaderPos);
394 header.fSize = currentFilePos-fDataHeaderPos;
395 header.SetAttribute(0); // valid data
396 if (compressed) header.SetAttribute(1);
397 fFile->WriteBuffer((char*)(&header), sizeof(header));
398 fFile->Seekp(currentFilePos);
399 }
400
401}
402
403//___ __________________________________________________________________________
404void AliFITRawData::WriteTrailer(UInt_t slot, Int_t word1, UInt_t word2, UInt_t word3)
405{
406 //Write a (dummy or real) DDL Chain data trailer
407
408 UInt_t word;
409 UInt_t baseWord=0;
410 word = slot;
411 AliBitPacking::PackWord(word,baseWord,0, 3); // 0001
412 word=word1;
413 AliBitPacking::PackWord(word,baseWord,4, 15); // CRC ?
414 word = word2;
415 AliBitPacking::PackWord(word,baseWord,16,27); // event counter
416 word=word3;
417 AliBitPacking::PackWord(word,baseWord,28,31); // marks trailer
418 fBuffer[fIndex] = baseWord;
419 word=0;
420 baseWord=0;
421
422}
423
424//---------------------------------------------------------------------------------------
425void AliFITRawData::FillTime(Int_t ch, Int_t iTDC, Int_t time)
426{
427 // put all time fields thother in 1 word
428
429 UInt_t word;
430 UInt_t baseWord=0;
431
432 word=time;
433 AliBitPacking::PackWord(word,baseWord, 0, 20); // Time
434
435 word=ch;
436 AliBitPacking::PackWord(word,baseWord, 21, 23); // number of channel
437 word=iTDC;
438 AliBitPacking::PackWord(word,baseWord, 24, 27); // TDC ID
439
440 word=0;
441 AliBitPacking::PackWord(word,baseWord, 28, 28); // E = 0 in simulation
442 word=0;
443 AliBitPacking::PackWord(word,baseWord, 29, 30); // PS bit data 00
444 word=1;
445 AliBitPacking::PackWord(word,baseWord, 31, 31); // 1
446 fBuffer[fIndex]=baseWord;
447 word=0;
448 baseWord=0;
449}