1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.1.2.1 2002/10/11 07:26:37 hristov
19 Updating VirtualMC to v3-09-02
21 Revision 1.1 2002/09/13 14:33:52 cblume
22 Add conversion class to produce fake raw data
26 ///////////////////////////////////////////////////////////////////////////////
28 // TRD raw data conversion class //
30 ///////////////////////////////////////////////////////////////////////////////
34 #include "AliTRDrawData.h"
35 #include "AliTRDdigitsManager.h"
36 #include "AliTRDgeometryFull.h"
37 #include "AliTRDparameter.h"
38 #include "AliTRDdataArrayI.h"
39 #include "AliTRDarrayI.h"
41 ClassImp(AliTRDrawData)
43 //_____________________________________________________________________________
44 AliTRDrawData::AliTRDrawData():TObject()
48 fDigitsManager = NULL;
52 //_____________________________________________________________________________
53 AliTRDrawData::AliTRDrawData(const AliTRDrawData &r)
56 // AliTRDrawData copy constructor
59 ((AliTRDrawData &) r).Copy(*this);
63 //_____________________________________________________________________________
64 AliTRDrawData::~AliTRDrawData()
71 delete fDigitsManager;
72 fDigitsManager = NULL;
77 //_____________________________________________________________________________
78 AliTRDrawData &AliTRDrawData::operator=(const AliTRDrawData &r)
81 // Assignment operator
84 if (this != &r) ((AliTRDrawData &) r).Copy(*this);
89 //_____________________________________________________________________________
90 void AliTRDrawData::Copy(TObject &r)
96 ((AliTRDrawData &) r).fDebug = fDebug;
97 ((AliTRDrawData &) r).fDigitsManager = NULL;
101 //_____________________________________________________________________________
102 Bool_t AliTRDrawData::OpenInput(const Char_t *name)
105 // Opens a ROOT-file with the TRD digits
108 // Create the digits manager
109 if (fDigitsManager) {
110 delete fDigitsManager;
112 fDigitsManager = new AliTRDdigitsManager();
113 fDigitsManager->SetDebug(fDebug);
115 // Open the input file
116 return fDigitsManager->Open(name);
120 //_____________________________________________________________________________
121 Bool_t AliTRDrawData::Digit2Raw(const Char_t *name1, const Char_t *name2)
124 // Convert the digits to raw data byte stream. The output is written
125 // into the the binary files <name1> and <name2>.
127 // The pseudo raw data format is currently defined like this:
129 // LDC header (8 bytes)
132 // Number of detectors with data (not yet implemented)
135 // Subevent (= single chamber) header (8 bytes)
137 // Detector number (2 bytes)
138 // Number of data bytes (2 bytes)
139 // Number of pads with data (2 bytes)
145 const Int_t kLDCHeaderLength = 8;
146 const Int_t kSubeventHeaderLength = 8;
148 const Int_t kLDCDummyFlag = 0xAA;
149 const Int_t kSubeventDummyFlag = 0xBB;
152 int headerSubevent[2];
154 Int_t ntotalbyte[2] = { 0 };
157 unsigned char *byte_p;
158 unsigned char *header_p;
160 AliTRDgeometryFull *geo = new AliTRDgeometryFull();
161 AliTRDparameter *par = new AliTRDparameter("TRDparameter"
162 ,"TRD parameter class");
163 AliTRDdataArrayI *digits;
166 Info("Digit2Raw","Open the LDC output files %s, %s"
169 ofstream *outputFile1 = new ofstream(name1, ios::out | ios::binary);
170 ofstream *outputFile2 = new ofstream(name2, ios::out | ios::binary);
171 ofstream *outputFile;
173 if (!fDigitsManager) {
174 Error("Digit2Raw","No input file open\n");
178 // Read in the digit arrays
179 if (!fDigitsManager->ReadDigits()) {
183 // Count the number of chambers with data
188 Info("Digit2Raw","Write the LDC headers");
191 // Write the LDC header 1
192 byte_p = (unsigned char *) headerLDC;
194 *byte_p++ = kLDCDummyFlag;
196 *byte_p++ = ndetLDC0;
202 outputFile1->write(header_p,kLDCHeaderLength);
203 ntotalbyte[0] += kLDCHeaderLength;
206 Info("Digit2Raw","LDC header 0 = %d, %d",headerLDC[0],headerLDC[1]);
209 // Write the LDC header 1
210 byte_p = (unsigned char *) headerLDC;
212 *byte_p++ = kLDCDummyFlag;
214 *byte_p++ = ndetLDC1;
220 outputFile2->write(header_p,kLDCHeaderLength);
221 ntotalbyte[1] += kLDCHeaderLength;
224 Info("Digit2Raw","LDC header 1 = %d, %d",headerLDC[0],headerLDC[1]);
227 // Loop through all detectors
228 for (Int_t det = 0; det < AliTRDgeometry::Ndet(); det++) {
230 Int_t cham = geo->GetChamber(det);
231 Int_t plan = geo->GetPlane(det);
232 Int_t sect = geo->GetSector(det);
233 Int_t rowMax = par->GetRowMax(plan,cham,sect);
234 Int_t colMax = par->GetColMax(plan);
235 Int_t timeMax = par->GetTimeMax();
236 Int_t bufferMax = rowMax*colMax*timeMax;
237 int *buffer = new int[bufferMax];
241 byte_p = (unsigned char *) buffer;
243 // Determine the LDC (resp. output file)
246 outputFile = outputFile1;
250 outputFile = outputFile2;
254 // Get the digits array
255 digits = fDigitsManager->GetDigits(det);
258 // Loop through the detector pixel
259 for (Int_t col = 0; col < colMax; col++) {
260 for (Int_t row = 0; row < rowMax; row++) {
262 // Check whether data exists for this pad
263 Bool_t dataflag = kFALSE;
264 for (Int_t time = 0; time < timeMax; time++) {
265 Int_t data = digits->GetDataUnchecked(row,col,time);
276 // The pad row number
278 // The pad column number
283 for (Int_t time = 0; time < timeMax; time++) {
285 Int_t data = digits->GetDataUnchecked(row,col,time);
289 if ((nzero == 256) ||
290 (time == timeMax-1)) {
304 // High byte (MSB always set)
305 *byte_p++ = ((data >> 8) | 128);
307 *byte_p++ = (data & 0xff);
319 // Fill the end of the buffer with zeros
326 Info("Digit2Raw","LDC = %d, det = %d, nbyte = %d (%d)",ldc,det,nbyte,bufferMax);
329 // Write the subevent header
330 byte_p = (unsigned char *) headerSubevent;
332 *byte_p++ = kSubeventDummyFlag;
333 *byte_p++ = (det & 0xff);
334 *byte_p++ = (det >> 8);
335 *byte_p++ = (nbyte & 0xff);
336 *byte_p++ = (nbyte >> 8);
337 *byte_p++ = (npads & 0xff);
338 *byte_p++ = (npads >> 8);
340 outputFile->write(header_p,kSubeventHeaderLength);
342 // Write the buffer to the file
343 byte_p = (unsigned char *) buffer;
344 outputFile->write(byte_p,nbyte);
346 ntotalbyte[ldc] += nbyte + kSubeventHeaderLength;
353 Info("Digit2Raw","Total size: LDC0 = %d, LDC1 = %d",ntotalbyte[0],ntotalbyte[1]);
356 outputFile1->close();
357 outputFile2->close();
368 //_____________________________________________________________________________
369 Bool_t AliTRDrawData::Raw2Digit(const Char_t *name1, const Char_t *name2)
372 const Int_t kLDCHeaderLength = 8;
373 const Int_t kSubeventHeaderLength = 8;
375 const Int_t kNldc = 2;
376 const Char_t *name = 0;
379 int headerSubevent[2];
383 unsigned char *byte_p;
384 ifstream *inputFile = 0;
385 AliTRDdataArrayI *digits = 0;
387 AliTRDgeometryFull *geo = new AliTRDgeometryFull();
388 AliTRDparameter *par = new AliTRDparameter("TRDparameter"
389 ,"TRD parameter class");
391 // Create the digits manager
392 if (fDigitsManager) {
393 delete fDigitsManager;
395 fDigitsManager = new AliTRDdigitsManager();
396 fDigitsManager->SetDebug(fDebug);
397 fDigitsManager->CreateArrays();
399 for (Int_t ldc = 0; ldc < kNldc; ldc++) {
408 Info("Raw2Digit","Open the LDC input file %s",name);
410 inputFile = new ifstream(name, ios::in | ios::binary);
412 // Read the LDC header
413 byte_p = (unsigned char *) headerLDC;
414 inputFile->read(byte_p,kLDCHeaderLength);
417 Info("Raw2Digit","LDC header no. %d:",ldc);
418 Info("Raw2Digit","\tflag = %d",*byte_p++);
419 Info("Raw2Digit","\tldc no = %d",*byte_p++);
420 Info("Raw2Digit","\tndet = %d",*byte_p++);
421 Info("Raw2Digit","\tempty = %d",*byte_p++);
422 Info("Raw2Digit","\tempty = %d",*byte_p++);
423 Info("Raw2Digit","\tempty = %d",*byte_p++);
424 Info("Raw2Digit","\tempty = %d",*byte_p++);
425 Info("Raw2Digit","\tempty = %d",*byte_p++);
428 // Loop through the subevents
429 byte_p = (unsigned char *) headerSubevent;
430 while (inputFile->read(byte_p,kSubeventHeaderLength)) {
432 Int_t flag = *byte_p++;
433 Int_t detl = *byte_p++;
434 Int_t deth = *byte_p++;
435 Int_t det = detl + (deth << 8);
436 Int_t nbytel = *byte_p++;
437 Int_t nbyteh = *byte_p++;
438 nbyte = nbytel + (nbyteh << 8);
439 Int_t npadsl = *byte_p++;
440 Int_t npadsh = *byte_p++;
441 npads = npadsl + (npadsh << 8);
443 Info("Raw2Digit","Subevent header:");
444 Info("Raw2Digit","\tflag = %d",flag);
445 Info("Raw2Digit","\tdet = %d",det);
446 Info("Raw2Digit","\tnbyte = %d",nbyte);
447 Info("Raw2Digit","\tnpads = %d",npads);
448 Info("Raw2Digit","\tempty = %d",*byte_p++);
451 // Create the data buffer
452 Int_t cham = geo->GetChamber(det);
453 Int_t plan = geo->GetPlane(det);
454 Int_t sect = geo->GetSector(det);
455 Int_t rowMax = par->GetRowMax(plan,cham,sect);
456 Int_t colMax = par->GetColMax(plan);
457 Int_t timeMax = par->GetTimeMax();
458 Int_t bufferMax = rowMax*colMax*timeMax;
459 int *buffer = new int[bufferMax];
460 byte_p = (unsigned char *) buffer;
461 memset(buffer,0,bufferMax*sizeof(int));
463 // Add a container for the digits of this detector
464 digits = fDigitsManager->GetDigits(det);
465 // Allocate memory space for the digits buffer
466 if (digits->GetNtime() == 0) {
467 digits->Allocate(rowMax,colMax,timeMax);
471 inputFile->read(byte_p,nbyte);
480 // Decompress the data
483 // The pad row number
484 Int_t row = (*byte_p++) - 1;
485 // The pad column number
486 Int_t col = (*byte_p++) - 1;
491 while ((time < timeMax) &&
499 // signal for given timebim
502 signal = low + (high << 8);
503 if ((row < 0) || (col < 0) || (time < 0) ||
504 (row >= rowMax) || (col >= colMax) || (time >= timeMax)) {
506 ,"row=%d(%d) col=%d(%d) time=%d(%d)"
507 ,row,rowMax,col,colMax,time,timeMax);
510 digits->SetDataUnchecked(row,col,time,signal);
534 digits->Compress(1,0);
538 byte_p = (unsigned char *) headerSubevent;