1 /**************************************************************************
2 * Copyright(c) 1998-2003, 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 //This class conteins all the methods to create raw data
20 //It produces DDL with both compressed and uncompressed format.
21 //For compression we use the optimized table wich needs
25 #include "TObjArray.h"
26 #include "Riostream.h"
29 #include "AliTPCCompression.h"
30 #include "AliTPCBuffer160.h"
31 #include "AliTPCDDLRawData.h"
33 ClassImp(AliTPCDDLRawData)
34 ////////////////////////////////////////////////////////////////////////////////////////
36 AliTPCDDLRawData::AliTPCDDLRawData(const AliTPCDDLRawData &source){
38 fVerbose=source.fVerbose;
42 AliTPCDDLRawData& AliTPCDDLRawData::operator=(const AliTPCDDLRawData &source){
44 fVerbose=source.fVerbose;
49 ////////////////////////////////////////////////////////////////////////////
50 void AliTPCDDLRawData::RawData(Int_t LDCsNumber){
51 //Raw data slides generation
52 //Number of DDL=2*36+4*36=216
53 //2 DDL for each inner sector
54 //4 DDL for each outer sector
55 Int_t ddlPerFile=216/LDCsNumber;
57 if (216%LDCsNumber) ddlPerFile++;
58 cout<<"Number of DDL per slide: "<<ddlPerFile<<endl;
61 f.open("AliTPCDDL.dat",ios::binary);
63 f.open("AliTPCDDL.dat");
65 if(!f){cout<<"File doesn't exist !!"<<endl;return;}
76 //AliTPCBuffer160 is used in write mode to generate AltroFormat.dat file
79 sprintf(filename,"TPCslice%d",sliceNumber);
80 cout<<" Creating "<<filename<<endl;
81 AliTPCBuffer160 *buffer=new AliTPCBuffer160(filename,1);
84 Int_t pSecNumber=-1; //Previous Sector number
85 Int_t pRowNumber=-1; //Previous Row number
86 Int_t pPadNumber=-1; //Previous Pad number
87 Int_t pTimeBin=-1; //Previous Time-Bin
88 Int_t pSubSector=-1; //Previous Sub Sector
93 while (f.read((char*)(&data),sizeof(data))){
100 pSubSector=data.SubSec;
101 //size magic word sector number sub-sector number 0 for TPC 0 for uncompressed
102 buffer->WriteMiniHeader(0,pSecNumber,pSubSector,0,0);//Dummy;
104 buffer->FillBuffer(data.Dig-offset);
108 if ( (data.Time==(pTimeBin+1)) &&
109 (pPadNumber==data.Pad) &&
110 (pRowNumber==data.Row) &&
111 (pSecNumber==data.Sec)){
115 buffer->FillBuffer(pTimeBin);
116 buffer->FillBuffer(bunchLength+2);
118 if ((pPadNumber!=data.Pad)||(pRowNumber!=data.Row)||(pSecNumber!=data.Sec)){
119 //Trailer is formatted and inserted!!
120 buffer->WriteTrailer(nwords,pPadNumber,pRowNumber,pSecNumber);
124 if(pSubSector!=data.SubSec){
126 if(countDDL==ddlPerFile){
127 //size magic word sector number sub-sector number 0 for TPC 0 for uncompressed
129 buffer->WriteMiniHeader(1,pSecNumber,pSubSector,0,0);
130 //cout<<"Mini header for DDL:"<<PSecNumber<<" Sub-sec:"<<PSubSector<<endl;
133 sprintf(filename,"TPCslice%d",sliceNumber);
134 cout<<" Creating "<<filename<<endl;
135 buffer=new AliTPCBuffer160(filename,1);
136 buffer->WriteMiniHeader(0,data.Sec,data.SubSec,0,0);//Dummy;
141 buffer->WriteMiniHeader(1,pSecNumber,pSubSector,0,0);
142 buffer->WriteMiniHeader(0,data.Sec,data.SubSec,0,0);//Dummy;
144 pSubSector=data.SubSec;
154 buffer->FillBuffer(data.Dig-offset);
158 buffer->FillBuffer(pTimeBin);
159 buffer->FillBuffer(bunchLength+2);
161 buffer->WriteTrailer(nwords,pPadNumber,pRowNumber,pSecNumber);
164 buffer->WriteMiniHeader(1,pSecNumber,pSubSector,0,0);
165 //cout<<"Mini header for D D L:"<<pSecNumber<<" Sub-sec:"<<pSubSector<<endl;
167 cout<<"Number of digits: "<<count<<endl;
171 ////////////////////////////////////////////////////////////////////////////
172 ////////////////////////////////////////////////////////////////////////////
175 Int_t AliTPCDDLRawData::RawDataCompDecompress(Int_t LDCsNumber,Int_t Comp){
176 //This method is used to compress and decompress the slides
177 static const Int_t kNumTables=5;
182 //Int_t MagicWord,DDLNumber,SecNumber,SubSector,Detector;
184 for(Int_t i=1;i<=LDCsNumber;i++){
186 sprintf(filename,"TPCslice%d",i);
187 sprintf(dest,"TPCslice%d.comp",i);
190 sprintf(filename,"TPCslice%d.comp",i);
191 sprintf(dest,"TPCslice%d.decomp",i);
194 f.open(filename,ios::binary|ios::in);
196 f.open(filename,ios::in);
198 if(!f){cout<<"BE CAREFUL!! There isn't enough data to generate "<<LDCsNumber<<" slices"<<endl;break;}
199 cout<<filename<<" "<<dest<<endl;
202 fdest.open(dest,ios::binary);
206 //loop over the DDL block
207 //Each block contains a Mini Header followed by raw data (ALTRO FORMAT)
208 //The number of block is ceil(216/LDCsNumber)
209 ULong_t miniHeader[3];
210 //here the Mini Header is read
211 while( (f.read((char*)(miniHeader),sizeof(ULong_t)*3)) ){
213 // cout<<"Data size:"<<size<<endl;
214 //Int_t dim=sizeof(ULong_t)+sizeof(Int_t)*5;
215 //cout<<" Sec "<<SecNumber<<" SubSector "<<SubSector<<" size "<<size<<endl;
216 //open the temporay File
218 char temp[15]="TempFile";
220 fo.open(temp,ios::binary);
225 for(ULong_t j=0;j<size;j++){
226 f.read((char*)(&car),1);
227 fo.write((char*)(&car),1);
230 //The temp file is compressed or decompressed
231 AliTPCCompression *util = new AliTPCCompression();
234 util->CompressDataOptTables(kNumTables,temp,"TempCompDecomp");
237 util->DecompressDataOptTables(kNumTables,temp,"TempCompDecomp");
239 //the temp compressed file is open and copied to the final file fdest
242 fi.open("TempCompDecomp",ios::binary);
244 fi.open("TempCompDecomp");
246 fi.seekg(0,ios::end);
249 //The Mini Header is updated (size and Compressed flag)
250 //and written into the output file
259 miniHeader[2]=miniHeader[2]|aux;
260 fdest.write((char*)(miniHeader),sizeof(ULong_t)*3);
261 //The compressem temp file is copied into the output file fdest
262 for(ULong_t j=0;j<size;j++){
263 fi.read((char*)(&car),1);
264 fdest.write((char*)(&car),1);
272 remove("TempCompDecomp");
277 /////////////////////////////////////////////////////////////////////////////////
278 void AliTPCDDLRawData::RawDataAltro()const{
279 //This method is used to build the Altro format from AliTPCDDL.dat
280 //It is used to debug the code and creates the tables used in the compresseion phase
284 f.open("AliTPCDDL.dat",ios::binary);
286 f.open("AliTPCDDL.dat");
288 if(!f){cout<<"File doesn't exist !!"<<endl;return;}
299 //AliTPCBuffer160 is used in write mode to generate AltroFormat.dat file
300 char filename[30]="AltroFormatDDL.dat";
301 cout<<" Creating "<<filename<<endl;
302 AliTPCBuffer160 *buffer=new AliTPCBuffer160(filename,1);
305 Int_t pSecNumber=-1; //Previous Sector number
306 Int_t pRowNumber=-1; //Previous Row number
307 Int_t pPadNumber=-1; //Previous Pad number
308 Int_t pTimeBin=-1; //Previous Time-Bin
311 ULong_t numPackets=0;
312 while (f.read((char*)(&data),sizeof(data))){
320 buffer->FillBuffer(data.Dig-offset);
324 if ( (data.Time==(pTimeBin+1)) &&
325 (pPadNumber==data.Pad) &&
326 (pRowNumber==data.Row) &&
327 (pSecNumber==data.Sec)){
331 buffer->FillBuffer(pTimeBin);
332 buffer->FillBuffer(bunchLength+2);
334 if ((pPadNumber!=data.Pad)||(pRowNumber!=data.Row)||(pSecNumber!=data.Sec)){
335 //Trailer is formatted and inserted!!
336 buffer->WriteTrailer(nwords,pPadNumber,pRowNumber,pSecNumber);
347 buffer->FillBuffer(data.Dig-offset);
351 buffer->FillBuffer(pTimeBin);
352 buffer->FillBuffer(bunchLength+2);
354 buffer->WriteTrailer(nwords,pPadNumber,pRowNumber,pSecNumber);
356 cout<<"Number of digits: "<<count<<endl;
361 /////////////////////////////////////////////////////////////////////////
362 void AliTPCDDLRawData::RawDataAltroDecode(Int_t LDCsNumber,Int_t Comp){
363 //This method merges the slides in only one file removing at the same
364 //time all the mini headers. The file so obtained must be Altro format
366 //It is used mainly in the debugging phase
371 sprintf(dest,"AltroDDLRecomposed.dat");
373 sprintf(dest,"AltroDDLRecomposedDec.dat");
377 fdest.open(dest,ios::binary);
382 //Int_t MagicWord,DDLNumber,SecNumber,SubSector,Detector,flag=0;
383 for(Int_t i=1;i<=LDCsNumber;i++){
385 sprintf(filename,"TPCslice%d",i);
387 sprintf(filename,"TPCslice%d.decomp",i);
389 f.open(filename,ios::binary|ios::in);
391 f.open(filename,ios::in);
393 if(!f){cout<<"BE CAREFUL!! There isn't enough data to generate "<<LDCsNumber<<" slices"<<endl;break;}
394 //loop over the DDL block
395 //Each block contains a Mini Header followed by raw data (ALTRO FORMAT)
396 //The number of block is ceil(216/LDCsNumber)
397 ULong_t miniHeader[3];
398 //here the Mini Header is read
399 //cout<<filename<<endl;
400 while( (f.read((char*)(miniHeader),sizeof(ULong_t)*3)) ){
403 for(ULong_t j=0;j<size;j++){
404 f.read((char*)(&car),1);
405 fdest.write((char*)(&car),1);