]>
Commit | Line | Data |
---|---|---|
5990c064 | 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 | ||
88cb7938 | 16 | /* $Id$ */ |
5990c064 | 17 | |
18 | /////////////////////////////////////////////////////////////////////////////// | |
19 | // // | |
20 | // TRD raw data conversion class // | |
21 | // // | |
22 | /////////////////////////////////////////////////////////////////////////////// | |
23 | ||
a2cb5b3d | 24 | #include <Riostream.h> |
5990c064 | 25 | |
26 | #include "AliTRDrawData.h" | |
27 | #include "AliTRDdigitsManager.h" | |
28 | #include "AliTRDgeometryFull.h" | |
29 | #include "AliTRDparameter.h" | |
30 | #include "AliTRDdataArrayI.h" | |
b864d801 | 31 | #include "AliTRDRawStream.h" |
32 | #include "AliRawDataHeader.h" | |
928e9fae | 33 | #include "AliRawReader.h" |
5990c064 | 34 | |
35 | ClassImp(AliTRDrawData) | |
36 | ||
37 | //_____________________________________________________________________________ | |
38 | AliTRDrawData::AliTRDrawData():TObject() | |
39 | { | |
b864d801 | 40 | // |
41 | // Default constructor | |
42 | // | |
5990c064 | 43 | |
44 | fDebug = 0; | |
5990c064 | 45 | |
46 | } | |
47 | ||
48 | //_____________________________________________________________________________ | |
b864d801 | 49 | AliTRDrawData::AliTRDrawData(const AliTRDrawData &r):TObject() |
5990c064 | 50 | { |
51 | // | |
52 | // AliTRDrawData copy constructor | |
53 | // | |
54 | ||
55 | ((AliTRDrawData &) r).Copy(*this); | |
56 | ||
57 | } | |
58 | ||
59 | //_____________________________________________________________________________ | |
60 | AliTRDrawData::~AliTRDrawData() | |
61 | { | |
62 | // | |
63 | // Destructor | |
64 | // | |
65 | ||
5990c064 | 66 | } |
67 | ||
68 | //_____________________________________________________________________________ | |
69 | AliTRDrawData &AliTRDrawData::operator=(const AliTRDrawData &r) | |
70 | { | |
71 | // | |
72 | // Assignment operator | |
73 | // | |
74 | ||
75 | if (this != &r) ((AliTRDrawData &) r).Copy(*this); | |
76 | return *this; | |
77 | ||
78 | } | |
79 | ||
80 | //_____________________________________________________________________________ | |
e0d47c25 | 81 | void AliTRDrawData::Copy(TObject &r) const |
5990c064 | 82 | { |
83 | // | |
84 | // Copy function | |
85 | // | |
86 | ||
87 | ((AliTRDrawData &) r).fDebug = fDebug; | |
5990c064 | 88 | |
89 | } | |
90 | ||
91 | //_____________________________________________________________________________ | |
b864d801 | 92 | Bool_t AliTRDrawData::Digits2Raw(TTree *digitsTree) |
5990c064 | 93 | { |
94 | // | |
95 | // Convert the digits to raw data byte stream. The output is written | |
b864d801 | 96 | // into the the binary files TRD_<DDL number>.ddl. |
5990c064 | 97 | // |
98 | // The pseudo raw data format is currently defined like this: | |
99 | // | |
b864d801 | 100 | // DDL data header |
5990c064 | 101 | // |
102 | // Subevent (= single chamber) header (8 bytes) | |
103 | // FLAG | |
104 | // Detector number (2 bytes) | |
105 | // Number of data bytes (2 bytes) | |
106 | // Number of pads with data (2 bytes) | |
107 | // 1 empty byte | |
108 | // | |
109 | // Data bank | |
110 | // | |
111 | ||
b864d801 | 112 | const Int_t kNumberOfDDLs = 18; |
5990c064 | 113 | const Int_t kSubeventHeaderLength = 8; |
5990c064 | 114 | const Int_t kSubeventDummyFlag = 0xBB; |
928e9fae | 115 | int headerSubevent[3]; |
5990c064 | 116 | |
b864d801 | 117 | ofstream *outputFile[kNumberOfDDLs]; |
118 | UInt_t bHPosition[kNumberOfDDLs]; | |
119 | Int_t ntotalbyte[kNumberOfDDLs]; | |
5990c064 | 120 | Int_t nbyte = 0; |
121 | Int_t npads = 0; | |
b864d801 | 122 | unsigned char *bytePtr; |
123 | unsigned char *headerPtr; | |
5990c064 | 124 | |
b864d801 | 125 | AliTRDdigitsManager* digitsManager = new AliTRDdigitsManager(); |
126 | digitsManager->SetDebug(fDebug); | |
5990c064 | 127 | |
128 | // Read in the digit arrays | |
b864d801 | 129 | if (!digitsManager->ReadDigits(digitsTree)) { |
130 | delete digitsManager; | |
5990c064 | 131 | return kFALSE; |
132 | } | |
133 | ||
b864d801 | 134 | AliTRDgeometryFull *geo = new AliTRDgeometryFull(); |
135 | AliTRDparameter *par = new AliTRDparameter("TRDparameter" | |
136 | ,"TRD parameter class"); | |
137 | AliTRDdataArrayI *digits; | |
5990c064 | 138 | |
b864d801 | 139 | // the event header |
140 | AliRawDataHeader header; | |
5990c064 | 141 | |
b864d801 | 142 | // Open the output files |
143 | for (Int_t iDDL = 0; iDDL < kNumberOfDDLs; iDDL++) { | |
144 | char name[20]; | |
145 | sprintf(name, "TRD_%d.ddl", iDDL + AliTRDRawStream::kDDLOffset); | |
146 | #ifndef __DECCXX | |
147 | outputFile[iDDL] = new ofstream(name, ios::binary); | |
148 | #else | |
149 | outputFile[iDDL] = new ofstream(name); | |
150 | #endif | |
151 | ||
152 | // Write a dummy data header | |
153 | bHPosition[iDDL] = outputFile[iDDL]->tellp(); | |
154 | outputFile[iDDL]->write((char*)(&header),sizeof(header)); | |
155 | ntotalbyte[iDDL] = 0; | |
5990c064 | 156 | } |
157 | ||
158 | // Loop through all detectors | |
159 | for (Int_t det = 0; det < AliTRDgeometry::Ndet(); det++) { | |
160 | ||
161 | Int_t cham = geo->GetChamber(det); | |
162 | Int_t plan = geo->GetPlane(det); | |
163 | Int_t sect = geo->GetSector(det); | |
164 | Int_t rowMax = par->GetRowMax(plan,cham,sect); | |
165 | Int_t colMax = par->GetColMax(plan); | |
928e9fae | 166 | Int_t timeTotal = par->GetTimeTotal(); |
167 | Int_t bufferMax = rowMax*colMax*timeTotal; | |
5990c064 | 168 | int *buffer = new int[bufferMax]; |
169 | ||
b864d801 | 170 | npads = 0; |
171 | nbyte = 0; | |
172 | bytePtr = (unsigned char *) buffer; | |
5990c064 | 173 | |
b864d801 | 174 | Int_t iDDL = sect; |
5990c064 | 175 | |
176 | // Get the digits array | |
b864d801 | 177 | digits = digitsManager->GetDigits(det); |
5990c064 | 178 | digits->Expand(); |
179 | ||
180 | // Loop through the detector pixel | |
181 | for (Int_t col = 0; col < colMax; col++) { | |
182 | for (Int_t row = 0; row < rowMax; row++) { | |
183 | ||
184 | // Check whether data exists for this pad | |
185 | Bool_t dataflag = kFALSE; | |
928e9fae | 186 | for (Int_t time = 0; time < timeTotal; time++) { |
5990c064 | 187 | Int_t data = digits->GetDataUnchecked(row,col,time); |
188 | if (data) { | |
189 | dataflag = kTRUE; | |
190 | break; | |
191 | } | |
192 | } | |
193 | ||
194 | if (dataflag) { | |
195 | ||
196 | npads++; | |
197 | ||
198 | // The pad row number | |
b864d801 | 199 | *bytePtr++ = row + 1; |
5990c064 | 200 | // The pad column number |
b864d801 | 201 | *bytePtr++ = col + 1; |
5990c064 | 202 | nbyte += 2; |
203 | ||
204 | Int_t nzero = 0; | |
928e9fae | 205 | for (Int_t time = 0; time < timeTotal; time++) { |
5990c064 | 206 | |
207 | Int_t data = digits->GetDataUnchecked(row,col,time); | |
208 | ||
209 | if (!data) { | |
210 | nzero++; | |
211 | if ((nzero == 256) || | |
928e9fae | 212 | (time == timeTotal-1)) { |
b864d801 | 213 | *bytePtr++ = 0; |
214 | *bytePtr++ = nzero-1; | |
5990c064 | 215 | nbyte += 2; |
216 | nzero = 0; | |
217 | } | |
218 | } | |
219 | else { | |
220 | if (nzero) { | |
b864d801 | 221 | *bytePtr++ = 0; |
222 | *bytePtr++ = nzero-1; | |
5990c064 | 223 | nbyte += 2; |
224 | nzero = 0; | |
225 | } | |
226 | // High byte (MSB always set) | |
b864d801 | 227 | *bytePtr++ = ((data >> 8) | 128); |
5990c064 | 228 | // Low byte |
b864d801 | 229 | *bytePtr++ = (data & 0xff); |
5990c064 | 230 | nbyte += 2; |
231 | } | |
232 | ||
233 | } | |
234 | ||
235 | } | |
236 | ||
237 | } | |
238 | ||
239 | } | |
240 | ||
241 | // Fill the end of the buffer with zeros | |
242 | while (nbyte % 4) { | |
b864d801 | 243 | *bytePtr++ = 0; |
5990c064 | 244 | nbyte++; |
245 | } | |
246 | ||
247 | if (fDebug > 1) { | |
b864d801 | 248 | Info("Digits2Raw","det = %d, nbyte = %d (%d)",det,nbyte,bufferMax); |
5990c064 | 249 | } |
250 | ||
251 | // Write the subevent header | |
b864d801 | 252 | bytePtr = (unsigned char *) headerSubevent; |
253 | headerPtr = bytePtr; | |
254 | *bytePtr++ = kSubeventDummyFlag; | |
255 | *bytePtr++ = (det & 0xff); | |
256 | *bytePtr++ = (det >> 8); | |
257 | *bytePtr++ = (nbyte & 0xff); | |
258 | *bytePtr++ = (nbyte >> 8); | |
928e9fae | 259 | *bytePtr++ = (nbyte >> 16); |
b864d801 | 260 | *bytePtr++ = (npads & 0xff); |
261 | *bytePtr++ = (npads >> 8); | |
b864d801 | 262 | outputFile[iDDL]->write((char*)headerPtr,kSubeventHeaderLength); |
5990c064 | 263 | |
264 | // Write the buffer to the file | |
b864d801 | 265 | bytePtr = (unsigned char *) buffer; |
266 | outputFile[iDDL]->write((char*)bytePtr,nbyte); | |
5990c064 | 267 | |
b864d801 | 268 | ntotalbyte[iDDL] += nbyte + kSubeventHeaderLength; |
5990c064 | 269 | |
270 | delete buffer; | |
271 | ||
272 | } | |
273 | ||
274 | if (fDebug) { | |
b864d801 | 275 | for (Int_t iDDL = 0; iDDL < kNumberOfDDLs; iDDL++) { |
276 | Info("Digits2Raw","Total size: DDL %d = %d",iDDL,ntotalbyte[iDDL]); | |
277 | } | |
5990c064 | 278 | } |
279 | ||
b864d801 | 280 | // Update the data headers and close the output files |
281 | for (Int_t iDDL = 0; iDDL < kNumberOfDDLs; iDDL++) { | |
282 | header.fSize = UInt_t(outputFile[iDDL]->tellp()) - bHPosition[iDDL]; | |
283 | header.SetAttribute(0); // valid data | |
284 | outputFile[iDDL]->seekp(bHPosition[iDDL]); | |
285 | outputFile[iDDL]->write((char*)(&header),sizeof(header)); | |
286 | ||
287 | outputFile[iDDL]->close(); | |
288 | delete outputFile[iDDL]; | |
289 | } | |
5990c064 | 290 | |
291 | delete geo; | |
292 | delete par; | |
b864d801 | 293 | delete digitsManager; |
5990c064 | 294 | |
295 | return kTRUE; | |
296 | ||
297 | } | |
298 | ||
299 | //_____________________________________________________________________________ | |
b864d801 | 300 | AliTRDdigitsManager* AliTRDrawData::Raw2Digits(AliRawReader* rawReader) |
5990c064 | 301 | { |
b864d801 | 302 | // |
303 | // Read the raw data digits and put them into the returned digits manager | |
304 | // | |
5990c064 | 305 | |
5990c064 | 306 | AliTRDdataArrayI *digits = 0; |
928e9fae | 307 | AliTRDdataArrayI *track0 = 0; |
308 | AliTRDdataArrayI *track1 = 0; | |
309 | AliTRDdataArrayI *track2 = 0; | |
5990c064 | 310 | |
311 | AliTRDgeometryFull *geo = new AliTRDgeometryFull(); | |
312 | AliTRDparameter *par = new AliTRDparameter("TRDparameter" | |
313 | ,"TRD parameter class"); | |
314 | ||
315 | // Create the digits manager | |
b864d801 | 316 | AliTRDdigitsManager* digitsManager = new AliTRDdigitsManager(); |
317 | digitsManager->SetDebug(fDebug); | |
318 | digitsManager->CreateArrays(); | |
5990c064 | 319 | |
928e9fae | 320 | AliTRDRawStream input(rawReader,par); |
5990c064 | 321 | |
b864d801 | 322 | // Loop through the digits |
323 | while (input.Next()) { | |
5990c064 | 324 | |
b864d801 | 325 | Int_t det = input.GetDetector(); |
326 | Int_t npads = input.GetNPads(); | |
5990c064 | 327 | |
b864d801 | 328 | if (input.IsNewDetector()) { |
329 | ||
330 | if (digits) digits->Compress(1,0); | |
928e9fae | 331 | if (track0) track0->Compress(1,0); |
332 | if (track1) track1->Compress(1,0); | |
333 | if (track2) track2->Compress(1,0); | |
5990c064 | 334 | |
5990c064 | 335 | if (fDebug > 2) { |
b864d801 | 336 | Info("Raw2Digits","Subevent header:"); |
337 | Info("Raw2Digits","\tdet = %d",det); | |
338 | Info("Raw2Digits","\tnpads = %d",npads); | |
5990c064 | 339 | } |
340 | ||
341 | // Create the data buffer | |
342 | Int_t cham = geo->GetChamber(det); | |
343 | Int_t plan = geo->GetPlane(det); | |
344 | Int_t sect = geo->GetSector(det); | |
345 | Int_t rowMax = par->GetRowMax(plan,cham,sect); | |
346 | Int_t colMax = par->GetColMax(plan); | |
928e9fae | 347 | Int_t timeTotal = par->GetTimeTotal(); |
5990c064 | 348 | |
349 | // Add a container for the digits of this detector | |
b864d801 | 350 | digits = digitsManager->GetDigits(det); |
928e9fae | 351 | track0 = digitsManager->GetDictionary(det,0); |
352 | track1 = digitsManager->GetDictionary(det,1); | |
353 | track2 = digitsManager->GetDictionary(det,2); | |
5990c064 | 354 | // Allocate memory space for the digits buffer |
355 | if (digits->GetNtime() == 0) { | |
928e9fae | 356 | digits->Allocate(rowMax,colMax,timeTotal); |
357 | track0->Allocate(rowMax,colMax,timeTotal); | |
358 | track1->Allocate(rowMax,colMax,timeTotal); | |
359 | track2->Allocate(rowMax,colMax,timeTotal); | |
5990c064 | 360 | } |
361 | ||
5990c064 | 362 | } |
928e9fae | 363 | |
b864d801 | 364 | digits->SetDataUnchecked(input.GetRow(),input.GetColumn(), |
365 | input.GetTime(),input.GetSignal()); | |
928e9fae | 366 | track0->SetDataUnchecked(input.GetRow(),input.GetColumn(), |
367 | input.GetTime(), -1); | |
368 | track1->SetDataUnchecked(input.GetRow(),input.GetColumn(), | |
369 | input.GetTime(), -1); | |
370 | track2->SetDataUnchecked(input.GetRow(),input.GetColumn(), | |
371 | input.GetTime(), -1); | |
5990c064 | 372 | } |
373 | ||
b864d801 | 374 | if (digits) digits->Compress(1,0); |
928e9fae | 375 | if (track0) track0->Compress(1,0); |
376 | if (track1) track1->Compress(1,0); | |
377 | if (track2) track2->Compress(1,0); | |
b864d801 | 378 | |
5990c064 | 379 | delete geo; |
380 | delete par; | |
381 | ||
b864d801 | 382 | return digitsManager; |
5990c064 | 383 | |
384 | } |