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