]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/AliTPCDDLRawData.cxx
Bug fix
[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>
0d08c0d0 25#include <TString.h>
26#include <TSystem.h>
b62e2a95 27#include <Riostream.h>
2e9f335b 28#include <stdio.h>
29#include <stdlib.h>
ba42285c 30#include "AliAltroBuffer.h"
0d08c0d0 31#include "AliTPCAltroMapping.h"
2e9f335b 32#include "AliTPCDDLRawData.h"
0421c3d1 33#include "AliRawDataHeader.h"
2e9f335b 34
35ClassImp(AliTPCDDLRawData)
36////////////////////////////////////////////////////////////////////////////////////////
37
0b3c7dfc 38AliTPCDDLRawData::AliTPCDDLRawData(const AliTPCDDLRawData &source):
39 TObject(source)
40{
2e9f335b 41 // Copy Constructor
9f992f70 42 fVerbose=source.fVerbose;
2e9f335b 43 return;
44}
45
46AliTPCDDLRawData& AliTPCDDLRawData::operator=(const AliTPCDDLRawData &source){
47 //Assigment operator
9f992f70 48 fVerbose=source.fVerbose;
2e9f335b 49 return *this;
50}
51
52
53////////////////////////////////////////////////////////////////////////////
0421c3d1 54void AliTPCDDLRawData::RawData(const char* inputFileName){
55 //Raw data generation
2e9f335b 56 //Number of DDL=2*36+4*36=216
57 //2 DDL for each inner sector
58 //4 DDL for each outer sector
2e9f335b 59 ifstream f;
30c1018e 60#ifndef __DECCXX
0421c3d1 61 f.open(inputFileName,ios::binary);
30c1018e 62#else
0421c3d1 63 f.open(inputFileName);
30c1018e 64#endif
0421c3d1 65 if(!f){Error("RawData", "File doesn't exist !!");return;}
2e9f335b 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
ba42285c 76 //AliAltroBuffer is used in write mode to generate raw data file
2e9f335b 77 char filename[15];
0421c3d1 78 Int_t ddlNumber=0;
ba42285c 79 AliAltroBuffer *buffer=NULL;
a79660fb 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;
2e9f335b 86 Int_t nwords=0;
0b3c7dfc 87 UInt_t numPackets=0;
0421c3d1 88
0d08c0d0 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
2e9f335b 101 while (f.read((char*)(&data),sizeof(data))){
a79660fb 102 if (pPadNumber==-1){
103 pSecNumber=data.Sec;
104 pRowNumber=data.Row;
105 pPadNumber=data.Pad;
106 pTimeBin=data.Time;
107 pSubSector=data.SubSec;
0421c3d1 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);
0d08c0d0 114 Int_t patchIndex = data.SubSec;
115 if(data.Sec>=36) patchIndex += 2;
4c846604 116 buffer=new AliAltroBuffer(filename,mapping[patchIndex]);
2e9f335b 117 //size magic word sector number sub-sector number 0 for TPC 0 for uncompressed
0421c3d1 118 buffer->WriteDataHeader(kTRUE,kFALSE);//Dummy;
a79660fb 119 bunchLength=1;
b27ca38e 120 buffer->FillBuffer(data.Dig);
2e9f335b 121 nwords++;
122 }//end if
123 else{
a79660fb 124 if ( (data.Time==(pTimeBin+1)) &&
125 (pPadNumber==data.Pad) &&
126 (pRowNumber==data.Row) &&
127 (pSecNumber==data.Sec)){
128 bunchLength++;
2e9f335b 129 }//end if
130 else{
a79660fb 131 buffer->FillBuffer(pTimeBin);
132 buffer->FillBuffer(bunchLength+2);
2e9f335b 133 nwords+=2;
a79660fb 134 if ((pPadNumber!=data.Pad)||(pRowNumber!=data.Row)||(pSecNumber!=data.Sec)){
2e9f335b 135 //Trailer is formatted and inserted!!
a79660fb 136 buffer->WriteTrailer(nwords,pPadNumber,pRowNumber,pSecNumber);
2e9f335b 137 numPackets++;
138 nwords=0;
139
a79660fb 140 if(pSubSector!=data.SubSec){
0421c3d1 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);
0d08c0d0 152 Int_t patchIndex = data.SubSec;
153 if(data.Sec>=36) patchIndex += 2;
4c846604 154 buffer=new AliAltroBuffer(filename,mapping[patchIndex]);
0421c3d1 155 buffer->WriteDataHeader(kTRUE,kFALSE);//Dummy;
a79660fb 156 pSubSector=data.SubSec;
2e9f335b 157 }//end if
2e9f335b 158 }//end if
159
a79660fb 160 bunchLength=1;
161 pPadNumber=data.Pad;
162 pRowNumber=data.Row;
163 pSecNumber=data.Sec;
2e9f335b 164 }//end else
a79660fb 165 pTimeBin=data.Time;
b27ca38e 166 buffer->FillBuffer(data.Dig);
2e9f335b 167 nwords++;
168 }//end else
169 }//end while
0421c3d1 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 }
0d08c0d0 181
182 for(Int_t i = 0; i < 6; i++) delete mapping[i];
183
2e9f335b 184 f.close();
185 return;
186}