GetClusterFast function implemented (No getter before) (Marian)
[u/mrichter/AliRoot.git] / TPC / AliTPCDDLRawData.cxx
... / ...
CommitLineData
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 **************************************************************************/
15/* $Id$ */
16
17
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
24#include <TObjArray.h>
25#include <TString.h>
26#include <TSystem.h>
27#include <Riostream.h>
28#include <stdio.h>
29#include <stdlib.h>
30#include "AliAltroBuffer.h"
31#include "AliTPCAltroMapping.h"
32#include "AliTPCDDLRawData.h"
33#include "AliRawDataHeader.h"
34
35ClassImp(AliTPCDDLRawData)
36////////////////////////////////////////////////////////////////////////////////////////
37
38AliTPCDDLRawData::AliTPCDDLRawData(const AliTPCDDLRawData &source):
39 TObject(source)
40{
41 // Copy Constructor
42 fVerbose=source.fVerbose;
43 return;
44}
45
46AliTPCDDLRawData& AliTPCDDLRawData::operator=(const AliTPCDDLRawData &source){
47 //Assigment operator
48 fVerbose=source.fVerbose;
49 return *this;
50}
51
52
53////////////////////////////////////////////////////////////////////////////
54void AliTPCDDLRawData::RawData(const char* inputFileName){
55 //Raw data generation
56 //Number of DDL=2*36+4*36=216
57 //2 DDL for each inner sector
58 //4 DDL for each outer sector
59 ifstream f;
60#ifndef __DECCXX
61 f.open(inputFileName,ios::binary);
62#else
63 f.open(inputFileName);
64#endif
65 if(!f){Error("RawData", "File doesn't exist !!");return;}
66 struct DataPad{
67 Int_t Sec;
68 Int_t SubSec;
69 Int_t Row;
70 Int_t Pad;
71 Int_t Dig;
72 Int_t Time;
73 };
74 DataPad data;
75
76 //AliAltroBuffer is used in write mode to generate raw data file
77 char filename[15];
78 Int_t ddlNumber=0;
79 AliAltroBuffer *buffer=NULL;
80 Int_t pSecNumber=-1; //Previous Sector number
81 Int_t pRowNumber=-1; //Previous Row number
82 Int_t pPadNumber=-1; //Previous Pad number
83 Int_t pTimeBin=-1; //Previous Time-Bin
84 Int_t pSubSector=-1; //Previous Sub Sector
85 Int_t bunchLength=0;
86 Int_t nwords=0;
87 UInt_t numPackets=0;
88
89 TString path = gSystem->Getenv("ALICE_ROOT");
90 path += "/TPC/mapping/Patch";
91 TString path2;
92 AliTPCAltroMapping *mapping[6];
93 for(Int_t i = 0; i < 6; i++) {
94 path2 = path;
95 path2 += i;
96 path2 += ".data";
97 mapping[i] = new AliTPCAltroMapping(path2.Data());
98 }
99
100
101 while (f.read((char*)(&data),sizeof(data))){
102 if (pPadNumber==-1){
103 pSecNumber=data.Sec;
104 pRowNumber=data.Row;
105 pPadNumber=data.Pad;
106 pTimeBin=data.Time;
107 pSubSector=data.SubSec;
108
109 if(data.Sec<36)
110 ddlNumber=data.Sec*2+data.SubSec;
111 else
112 ddlNumber=72+(data.Sec-36)*4+data.SubSec;
113 sprintf(filename,"TPC_%d.ddl",ddlNumber+kDDLOffset);
114 Int_t patchIndex = data.SubSec;
115 if(data.Sec>=36) patchIndex += 2;
116 buffer=new AliAltroBuffer(filename,mapping[patchIndex]);
117 //size magic word sector number sub-sector number 0 for TPC 0 for uncompressed
118 buffer->WriteDataHeader(kTRUE,kFALSE);//Dummy;
119 bunchLength=1;
120 buffer->FillBuffer(data.Dig);
121 nwords++;
122 }//end if
123 else{
124 if ( (data.Time==(pTimeBin+1)) &&
125 (pPadNumber==data.Pad) &&
126 (pRowNumber==data.Row) &&
127 (pSecNumber==data.Sec)){
128 bunchLength++;
129 }//end if
130 else{
131 buffer->FillBuffer(pTimeBin);
132 buffer->FillBuffer(bunchLength+2);
133 nwords+=2;
134 if ((pPadNumber!=data.Pad)||(pRowNumber!=data.Row)||(pSecNumber!=data.Sec)){
135 //Trailer is formatted and inserted!!
136 buffer->WriteTrailer(nwords,pPadNumber,pRowNumber,pSecNumber);
137 numPackets++;
138 nwords=0;
139
140 if(pSubSector!=data.SubSec){
141 //size magic word sector number sub-sector number 0 for TPC 0 for uncompressed
142 buffer->Flush();
143 buffer->WriteDataHeader(kFALSE,kFALSE);
144 //cout<<"Data header for DDL:"<<PSecNumber<<" Sub-sec:"<<PSubSector<<endl;
145 delete buffer;
146
147 if(data.Sec<36)
148 ddlNumber=data.Sec*2+data.SubSec;
149 else
150 ddlNumber=72+(data.Sec-36)*4+data.SubSec;
151 sprintf(filename,"TPC_%d.ddl",ddlNumber+kDDLOffset);
152 Int_t patchIndex = data.SubSec;
153 if(data.Sec>=36) patchIndex += 2;
154 buffer=new AliAltroBuffer(filename,mapping[patchIndex]);
155 buffer->WriteDataHeader(kTRUE,kFALSE);//Dummy;
156 pSubSector=data.SubSec;
157 }//end if
158 }//end if
159
160 bunchLength=1;
161 pPadNumber=data.Pad;
162 pRowNumber=data.Row;
163 pSecNumber=data.Sec;
164 }//end else
165 pTimeBin=data.Time;
166 buffer->FillBuffer(data.Dig);
167 nwords++;
168 }//end else
169 }//end while
170 if (buffer) {
171 buffer->FillBuffer(pTimeBin);
172 buffer->FillBuffer(bunchLength+2);
173 nwords+=2;
174 buffer->WriteTrailer(nwords,pPadNumber,pRowNumber,pSecNumber);
175 //write the D.H.
176 buffer->Flush();
177 buffer->WriteDataHeader(kFALSE,kFALSE);
178 //cout<<"Data header for D D L:"<<pSecNumber<<" Sub-sec:"<<pSubSector<<endl;
179 delete buffer;
180 }
181
182 for(Int_t i = 0; i < 6; i++) delete mapping[i];
183
184 f.close();
185 return;
186}