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