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