- // Bogdan's raw simulator (offline use only)
- //
- // Convert the digits to raw data byte stream. The output is written
- // into the the binary files TRD_<DDL number>.ddl.
- //
- // The pseudo raw data format is currently defined like this:
- //
- // DDL data header
- //
- // Subevent (= single chamber) header (8 bytes)
- // FLAG
- // Detector number (2 bytes)
- // Number of data bytes (2 bytes)
- // Number of pads with data (2 bytes)
- // 1 empty byte
- //
- // Data bank
- //
-
- const Int_t kSubeventHeaderLength = 8;
- const Int_t kSubeventDummyFlag = 0xBB;
- Int_t headerSubevent[3];
-
- ofstream **outputFile = new ofstream* [fNumberOfDDLs];
- UInt_t *bHPosition = new UInt_t [fNumberOfDDLs];
- Int_t *ntotalbyte = new Int_t [fNumberOfDDLs];
- Int_t nbyte = 0;
- Int_t npads = 0;
- unsigned char *bytePtr;
- unsigned char *headerPtr;
-
- AliTRDdataArrayI *digits;
- AliRawDataHeader header; // The event header
-
- // Open the output files
- for (Int_t iDDL = 0; iDDL < fNumberOfDDLs; iDDL++) {
-
- char name[20];
- sprintf(name, "TRD_%d.ddl", iDDL + AliTRDRawStream::kDDLOffset);
-#ifndef __DECCXX
- outputFile[iDDL] = new ofstream(name, ios::binary);
-#else
- outputFile[iDDL] = new ofstream(name);
-#endif
-
- // Write a dummy data header
- bHPosition[iDDL] = outputFile[iDDL]->tellp();
- outputFile[iDDL]->write((char *) (& header),sizeof(header));
- ntotalbyte[iDDL] = 0;
-
- }
-
- // Loop through all detectors
- for (Int_t det = 0; det < AliTRDgeometry::Ndet(); det++) {
-
- Int_t cham = fGeo->GetChamber(det);
- Int_t plan = fGeo->GetPlane(det);
- Int_t sect = fGeo->GetSector(det);
- Int_t rowMax = fCommonParam->GetRowMax(plan,cham,sect);
- Int_t colMax = fCommonParam->GetColMax(plan);
- Int_t timeTotal = fCalibration->GetNumberOfTimeBins();
- Int_t bufferMax = rowMax * colMax * timeTotal;
- Int_t *buffer = new Int_t[bufferMax];
-
- npads = 0;
- nbyte = 0;
- bytePtr = (unsigned char *) buffer;
-
- Int_t iDDL = sect;
-
- // Get the digits array
- digits = digitsManager->GetDigits(det);
- digits->Expand();
- // This is to take care of switched off super modules
- if (digits->GetNtime() == 0) {
- continue;
- }
-
- // Loop through the detector pixel
- for (Int_t col = 0; col < colMax; col++) {
- for (Int_t row = 0; row < rowMax; row++) {
-
- // Check whether data exists for this pad
- Bool_t dataflag = kFALSE;
- for (Int_t time = 0; time < timeTotal; time++) {
- Int_t data = digits->GetDataUnchecked(row,col,time);
- if (data) {
- dataflag = kTRUE;
- break;
- }
- }
-
- if (dataflag) {
-
- npads++;
-
- // The pad row number
- *bytePtr++ = row + 1;
- // The pad column number
- *bytePtr++ = col + 1;
- nbyte += 2;
-
- Int_t nzero = 0;
- for (Int_t time = 0; time < timeTotal; time++) {
-
- Int_t data = digits->GetDataUnchecked(row,col,time);
-
- if (!data) {
- nzero++;
- if ((nzero == 256) ||
- (time == timeTotal-1)) {
- *bytePtr++ = 0;
- *bytePtr++ = nzero-1;
- nbyte += 2;
- nzero = 0;
- }
- }
- else {
- if (nzero) {
- *bytePtr++ = 0;
- *bytePtr++ = nzero-1;
- nbyte += 2;
- nzero = 0;
- }
- // High byte (MSB always set)
- *bytePtr++ = ((data >> 8) | 128);
- // Low byte
- *bytePtr++ = (data & 0xff);
- nbyte += 2;
- }
-
- }
-
- }
-
- }
-
- }
-
- // Fill the end of the buffer with zeros
- while (nbyte % 4) {
- *bytePtr++ = 0;
- nbyte++;
- }
-
- AliDebug(1,Form("det = %d, nbyte = %d (%d)",det,nbyte,bufferMax));
-
- // Write the subevent header
- bytePtr = (unsigned char *) headerSubevent;
- headerPtr = bytePtr;
- *bytePtr++ = kSubeventDummyFlag;
- *bytePtr++ = (det & 0xff);
- *bytePtr++ = (det >> 8);
- *bytePtr++ = (nbyte & 0xff);
- *bytePtr++ = (nbyte >> 8);
- *bytePtr++ = (nbyte >> 16);
- *bytePtr++ = (npads & 0xff);
- *bytePtr++ = (npads >> 8);
- outputFile[iDDL]->write((char *) headerPtr,kSubeventHeaderLength);
-
- // Write the buffer to the file
- bytePtr = (unsigned char *) buffer;
- outputFile[iDDL]->write((char *) bytePtr,nbyte);
-
- ntotalbyte[iDDL] += nbyte + kSubeventHeaderLength;
-
- delete buffer;
-
- }
-
- // Update the data headers and close the output files
- for (Int_t iDDL = 0; iDDL < fNumberOfDDLs; iDDL++) {
-
- header.fSize = UInt_t(outputFile[iDDL]->tellp()) - bHPosition[iDDL];
- header.SetAttribute(0); // valid data
- outputFile[iDDL]->seekp(bHPosition[iDDL]);
- outputFile[iDDL]->write((char *) (&header),sizeof(header));
-
- outputFile[iDDL]->close();
- delete outputFile[iDDL];
-
- }
-
- delete [] outputFile;
- delete [] bHPosition;
- delete [] ntotalbyte;
-
- return kTRUE;
-}
-
-//_____________________________________________________________________________
-Bool_t AliTRDrawData::Digits2RawV1(AliTRDdigitsManager *digitsManager)
-{
- //
- // Raw data simulator version 1.