]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/AliTPCDDLRawData.cxx
Float_t replaced by Double_t
[u/mrichter/AliRoot.git] / TPC / AliTPCDDLRawData.cxx
CommitLineData
2e9f335b 1/**************************************************************************
2 * Copyright(c) 1998-2003, 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 **************************************************************************/
30c1018e 15/* $Id$ */
a79660fb 16
3f1ed77a 17
a79660fb 18//This class conteins all the methods to create raw data
19//as par a given DDL.
20//It produces DDL with both compressed and uncompressed format.
21//For compression we use the optimized table wich needs
22//to be provided.
23
2e9f335b 24
25#include "TObjArray.h"
26#include "Riostream.h"
27#include <stdio.h>
28#include <stdlib.h>
29#include "AliTPCCompression.h"
30#include "AliTPCBuffer160.h"
31#include "AliTPCDDLRawData.h"
2e9f335b 32
33ClassImp(AliTPCDDLRawData)
34////////////////////////////////////////////////////////////////////////////////////////
35
36AliTPCDDLRawData::AliTPCDDLRawData(const AliTPCDDLRawData &source){
37 // Copy Constructor
38 return;
39}
40
41AliTPCDDLRawData& AliTPCDDLRawData::operator=(const AliTPCDDLRawData &source){
42 //Assigment operator
43 return *this;
44}
45
46
47////////////////////////////////////////////////////////////////////////////
48void AliTPCDDLRawData::RawData(Int_t LDCsNumber){
a79660fb 49 //Raw data slides generation
2e9f335b 50 //Number of DDL=2*36+4*36=216
51 //2 DDL for each inner sector
52 //4 DDL for each outer sector
a79660fb 53 Int_t ddlPerFile=216/LDCsNumber;
2e9f335b 54 Int_t offset=1;
a79660fb 55 if (216%LDCsNumber) ddlPerFile++;
56 cout<<"Number of DDL per slide: "<<ddlPerFile<<endl;
2e9f335b 57 ifstream f;
30c1018e 58#ifndef __DECCXX
2e9f335b 59 f.open("AliTPCDDL.dat",ios::binary);
30c1018e 60#else
61 f.open("AliTPCDDL.dat");
62#endif
2e9f335b 63 if(!f){cout<<"File doesn't exist !!"<<endl;return;}
64 struct DataPad{
65 Int_t Sec;
66 Int_t SubSec;
67 Int_t Row;
68 Int_t Pad;
69 Int_t Dig;
70 Int_t Time;
71 };
72 DataPad data;
73
74 //AliTPCBuffer160 is used in write mode to generate AltroFormat.dat file
a79660fb 75 Int_t sliceNumber=1;
2e9f335b 76 char filename[15];
a79660fb 77 sprintf(filename,"TPCslice%d",sliceNumber);
2e9f335b 78 cout<<" Creating "<<filename<<endl;
a79660fb 79 AliTPCBuffer160 *buffer=new AliTPCBuffer160(filename,1);
2e9f335b 80
a79660fb 81 ULong_t count=0;
82 Int_t pSecNumber=-1; //Previous Sector number
83 Int_t pRowNumber=-1; //Previous Row number
84 Int_t pPadNumber=-1; //Previous Pad number
85 Int_t pTimeBin=-1; //Previous Time-Bin
86 Int_t pSubSector=-1; //Previous Sub Sector
87 Int_t bunchLength=0;
88 Int_t countDDL=0;
2e9f335b 89 Int_t nwords=0;
90 ULong_t numPackets=0;
91 while (f.read((char*)(&data),sizeof(data))){
a79660fb 92 count++;
93 if (pPadNumber==-1){
94 pSecNumber=data.Sec;
95 pRowNumber=data.Row;
96 pPadNumber=data.Pad;
97 pTimeBin=data.Time;
98 pSubSector=data.SubSec;
2e9f335b 99 //size magic word sector number sub-sector number 0 for TPC 0 for uncompressed
a79660fb 100 buffer->WriteMiniHeader(0,pSecNumber,pSubSector,0,0);//Dummy;
101 bunchLength=1;
102 buffer->FillBuffer(data.Dig-offset);
2e9f335b 103 nwords++;
104 }//end if
105 else{
a79660fb 106 if ( (data.Time==(pTimeBin+1)) &&
107 (pPadNumber==data.Pad) &&
108 (pRowNumber==data.Row) &&
109 (pSecNumber==data.Sec)){
110 bunchLength++;
2e9f335b 111 }//end if
112 else{
a79660fb 113 buffer->FillBuffer(pTimeBin);
114 buffer->FillBuffer(bunchLength+2);
2e9f335b 115 nwords+=2;
a79660fb 116 if ((pPadNumber!=data.Pad)||(pRowNumber!=data.Row)||(pSecNumber!=data.Sec)){
2e9f335b 117 //Trailer is formatted and inserted!!
a79660fb 118 buffer->WriteTrailer(nwords,pPadNumber,pRowNumber,pSecNumber);
2e9f335b 119 numPackets++;
120 nwords=0;
121
a79660fb 122 if(pSubSector!=data.SubSec){
123 countDDL++;
124 if(countDDL==ddlPerFile){
2e9f335b 125 //size magic word sector number sub-sector number 0 for TPC 0 for uncompressed
a79660fb 126 buffer->Flush();
127 buffer->WriteMiniHeader(1,pSecNumber,pSubSector,0,0);
2e9f335b 128 //cout<<"Mini header for DDL:"<<PSecNumber<<" Sub-sec:"<<PSubSector<<endl;
a79660fb 129 delete buffer;
130 sliceNumber++;
131 sprintf(filename,"TPCslice%d",sliceNumber);
2e9f335b 132 cout<<" Creating "<<filename<<endl;
a79660fb 133 buffer=new AliTPCBuffer160(filename,1);
134 buffer->WriteMiniHeader(0,data.Sec,data.SubSec,0,0);//Dummy;
135 countDDL=0;
2e9f335b 136 }//end if
137 else{
a79660fb 138 buffer->Flush();
139 buffer->WriteMiniHeader(1,pSecNumber,pSubSector,0,0);
140 buffer->WriteMiniHeader(0,data.Sec,data.SubSec,0,0);//Dummy;
2e9f335b 141 }
a79660fb 142 pSubSector=data.SubSec;
2e9f335b 143 }//end if
2e9f335b 144 }//end if
145
a79660fb 146 bunchLength=1;
147 pPadNumber=data.Pad;
148 pRowNumber=data.Row;
149 pSecNumber=data.Sec;
2e9f335b 150 }//end else
a79660fb 151 pTimeBin=data.Time;
152 buffer->FillBuffer(data.Dig-offset);
2e9f335b 153 nwords++;
154 }//end else
155 }//end while
a79660fb 156 buffer->FillBuffer(pTimeBin);
157 buffer->FillBuffer(bunchLength+2);
2e9f335b 158 nwords+=2;
a79660fb 159 buffer->WriteTrailer(nwords,pPadNumber,pRowNumber,pSecNumber);
2e9f335b 160 //write the M.H.
a79660fb 161 buffer->Flush();
162 buffer->WriteMiniHeader(1,pSecNumber,pSubSector,0,0);
163 //cout<<"Mini header for D D L:"<<pSecNumber<<" Sub-sec:"<<pSubSector<<endl;
164 delete buffer;
165 cout<<"Number of digits: "<<count<<endl;
2e9f335b 166 f.close();
167 return;
168}
169////////////////////////////////////////////////////////////////////////////
170////////////////////////////////////////////////////////////////////////////
a79660fb 171
2e9f335b 172
173Int_t AliTPCDDLRawData::RawDataCompDecompress(Int_t LDCsNumber,Int_t Comp){
a79660fb 174 //This method is used to compress and decompress the slides
175 static const Int_t kNumTables=5;
2e9f335b 176 char filename[20];
177 char dest[20];
178 fstream f;
a79660fb 179 ULong_t size=0;
2e9f335b 180 //Int_t MagicWord,DDLNumber,SecNumber,SubSector,Detector;
a79660fb 181 Int_t flag=0;
2e9f335b 182 for(Int_t i=1;i<=LDCsNumber;i++){
183 if(!Comp){
184 sprintf(filename,"TPCslice%d",i);
185 sprintf(dest,"TPCslice%d.comp",i);
186 }
187 else{
188 sprintf(filename,"TPCslice%d.comp",i);
189 sprintf(dest,"TPCslice%d.decomp",i);
190 }
30c1018e 191#ifndef __DECCXX
2e9f335b 192 f.open(filename,ios::binary|ios::in);
30c1018e 193#else
194 f.open(filename,ios::in);
195#endif
2e9f335b 196 if(!f){cout<<"File doesn't exist \n";exit(1);}
197 cout<<filename<<" "<<dest<<endl;
198 ofstream fdest;
30c1018e 199#ifndef __DECCXX
2e9f335b 200 fdest.open(dest,ios::binary);
30c1018e 201#else
202 fdest.open(dest);
203#endif
2e9f335b 204 //loop over the DDL block
205 //Each block contains a Mini Header followed by raw data (ALTRO FORMAT)
206 //The number of block is ceil(216/LDCsNumber)
a79660fb 207 ULong_t miniHeader[3];
2e9f335b 208 //here the Mini Header is read
a79660fb 209 while( (f.read((char*)(miniHeader),sizeof(ULong_t)*3)) ){
210 size=miniHeader[0];
2e9f335b 211 //Int_t dim=sizeof(ULong_t)+sizeof(Int_t)*5;
a79660fb 212 //cout<<" Sec "<<SecNumber<<" SubSector "<<SubSector<<" size "<<size<<endl;
2e9f335b 213 //open the temporay File
214 ofstream fo;
215 char temp[15]="TempFile";
30c1018e 216#ifndef __DECCXX
2e9f335b 217 fo.open(temp,ios::binary);
30c1018e 218#else
219 fo.open(temp);
220#endif
2e9f335b 221 Int_t car=0;
a79660fb 222 for(ULong_t j=0;j<size;j++){
2e9f335b 223 f.read((char*)(&car),1);
224 fo.write((char*)(&car),1);
225 }//end for
226 fo.close();
227 //The temp file is compressed or decompressed
228 AliTPCCompression *util = new AliTPCCompression();
3f1ed77a 229 // util->SetVerbose(1);
2e9f335b 230 if(!Comp)
a79660fb 231 util->CompressDataOptTables(kNumTables,temp,"TempCompDecomp");
2e9f335b 232 else
a79660fb 233 util->DecompressDataOptTables(kNumTables,temp,"TempCompDecomp");
2e9f335b 234 delete util;
235 //the temp compressed file is open and copied to the final file fdest
236 ifstream fi;
30c1018e 237#ifndef __DECCXX
2e9f335b 238 fi.open("TempCompDecomp",ios::binary);
30c1018e 239#else
240 fi.open("TempCompDecomp");
241#endif
2e9f335b 242 fi.seekg(0,ios::end);
a79660fb 243 size=fi.tellg();
2e9f335b 244 fi.seekg(0);
a79660fb 245 //The Mini Header is updated (size and Compressed flag)
2e9f335b 246 //and written into the output file
a79660fb 247 miniHeader[0]=size;
2e9f335b 248 if(!Comp)
a79660fb 249 flag=1;
2e9f335b 250 else
a79660fb 251 flag=0;
3f1ed77a 252 ULong_t aux=0x0;
253 flag<<=8;
a79660fb 254 aux|=flag;
3f1ed77a 255 miniHeader[2]=miniHeader[2]|aux;
a79660fb 256 fdest.write((char*)(miniHeader),sizeof(ULong_t)*3);
2e9f335b 257 //The compressem temp file is copied into the output file fdest
a79660fb 258 for(ULong_t j=0;j<size;j++){
2e9f335b 259 fi.read((char*)(&car),1);
260 fdest.write((char*)(&car),1);
261 }//end for
262 fi.close();
263 }//end while
cd43b5e1 264 f.clear();
2e9f335b 265 f.close();
266 fdest.close();
267 remove("TempFile");
268 remove("TempCompDecomp");
269 }//end for
270 return 0;
271}
272
273/////////////////////////////////////////////////////////////////////////////////
a79660fb 274void AliTPCDDLRawData::RawDataAltro()const{
275 //This method is used to build the Altro format from AliTPCDDL.dat
276 //It is used to debug the code and create the tables used in the compresseion phase
2e9f335b 277 Int_t offset=1;
278 ifstream f;
30c1018e 279#ifndef __DECCXX
2e9f335b 280 f.open("AliTPCDDL.dat",ios::binary);
30c1018e 281#else
282 f.open("AliTPCDDL.dat");
283#endif
2e9f335b 284 if(!f){cout<<"File doesn't exist !!"<<endl;return;}
285 struct DataPad{
286 Int_t Sec;
287 Int_t SubSec;
288 Int_t Row;
289 Int_t Pad;
290 Int_t Dig;
291 Int_t Time;
292 };
293 DataPad data;
294
295 //AliTPCBuffer160 is used in write mode to generate AltroFormat.dat file
296 char filename[30]="AltroFormatDDL.dat";
297 cout<<" Creating "<<filename<<endl;
a79660fb 298 AliTPCBuffer160 *buffer=new AliTPCBuffer160(filename,1);
2e9f335b 299
a79660fb 300 ULong_t count=0;
301 Int_t pSecNumber=-1; //Previous Sector number
302 Int_t pRowNumber=-1; //Previous Row number
303 Int_t pPadNumber=-1; //Previous Pad number
304 Int_t pTimeBin=-1; //Previous Time-Bin
305 Int_t bunchLength=0;
2e9f335b 306 Int_t nwords=0;
307 ULong_t numPackets=0;
308 while (f.read((char*)(&data),sizeof(data))){
a79660fb 309 count++;
310 if (pPadNumber==-1){
311 pSecNumber=data.Sec;
312 pRowNumber=data.Row;
313 pPadNumber=data.Pad;
314 pTimeBin=data.Time;
315 bunchLength=1;
316 buffer->FillBuffer(data.Dig-offset);
2e9f335b 317 nwords++;
318 }//end if
319 else{
a79660fb 320 if ( (data.Time==(pTimeBin+1)) &&
321 (pPadNumber==data.Pad) &&
322 (pRowNumber==data.Row) &&
323 (pSecNumber==data.Sec)){
324 bunchLength++;
2e9f335b 325 }//end if
326 else{
a79660fb 327 buffer->FillBuffer(pTimeBin);
328 buffer->FillBuffer(bunchLength+2);
2e9f335b 329 nwords+=2;
a79660fb 330 if ((pPadNumber!=data.Pad)||(pRowNumber!=data.Row)||(pSecNumber!=data.Sec)){
2e9f335b 331 //Trailer is formatted and inserted!!
a79660fb 332 buffer->WriteTrailer(nwords,pPadNumber,pRowNumber,pSecNumber);
2e9f335b 333 numPackets++;
334 nwords=0;
335 }//end if
336
a79660fb 337 bunchLength=1;
338 pPadNumber=data.Pad;
339 pRowNumber=data.Row;
340 pSecNumber=data.Sec;
2e9f335b 341 }//end else
a79660fb 342 pTimeBin=data.Time;
343 buffer->FillBuffer(data.Dig-offset);
2e9f335b 344 nwords++;
345 }//end else
346 }//end while
a79660fb 347 buffer->FillBuffer(pTimeBin);
348 buffer->FillBuffer(bunchLength+2);
2e9f335b 349 nwords+=2;
a79660fb 350 buffer->WriteTrailer(nwords,pPadNumber,pRowNumber,pSecNumber);
351 delete buffer;
352 cout<<"Number of digits: "<<count<<endl;
2e9f335b 353 f.close();
354 return;
355}
356
a79660fb 357/////////////////////////////////////////////////////////////////////////
2e9f335b 358void AliTPCDDLRawData::RawDataAltroDecode(Int_t LDCsNumber,Int_t Comp){
a79660fb 359 //This method merges the slides in only one file removing at the same
360 //time all the mini headers. The file so obtained must be Altro format
361 //complaiant.
362 //It is used mainly in the debugging phase
2e9f335b 363 char filename[15];
364 char dest[30];
365 fstream f;
366 if(!Comp)
367 sprintf(dest,"AltroDDLRecomposed.dat");
368 else
369 sprintf(dest,"AltroDDLRecomposedDec.dat");
370 ofstream fdest;
cd43b5e1 371
30c1018e 372#ifndef __DECCXX
2e9f335b 373 fdest.open(dest,ios::binary);
30c1018e 374#else
375 fdest.open(dest);
376#endif
a79660fb 377 ULong_t size=0;
378 //Int_t MagicWord,DDLNumber,SecNumber,SubSector,Detector,flag=0;
2e9f335b 379 for(Int_t i=1;i<=LDCsNumber;i++){
cd43b5e1 380 if(!Comp)
2e9f335b 381 sprintf(filename,"TPCslice%d",i);
382 else
383 sprintf(filename,"TPCslice%d.decomp",i);
30c1018e 384#ifndef __DECCXX
2e9f335b 385 f.open(filename,ios::binary|ios::in);
30c1018e 386#else
387 f.open(filename,ios::in);
388#endif
cd43b5e1 389 if(!f){cout<<"The file doesn't exist"<<endl;exit(1);}
2e9f335b 390 //loop over the DDL block
391 //Each block contains a Mini Header followed by raw data (ALTRO FORMAT)
392 //The number of block is ceil(216/LDCsNumber)
a79660fb 393 ULong_t miniHeader[3];
2e9f335b 394 //here the Mini Header is read
a79660fb 395 while( (f.read((char*)(miniHeader),sizeof(ULong_t)*3)) ){
396 //cout<<"Mini header dimension "<<miniHeader[0]<<endl;
2e9f335b 397 Int_t car=0;
a79660fb 398 size=miniHeader[0];
399 for(ULong_t j=0;j<size;j++){
2e9f335b 400 f.read((char*)(&car),1);
401 fdest.write((char*)(&car),1);
402 }//end for
403 }//end while
cd43b5e1 404 f.clear();
2e9f335b 405 f.close();
406 }//end for
407 fdest.close();
408 return;
409}
410