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