]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/programs/convcosmicsfile.cxx
Changing name of libRAW into libRAWData
[u/mrichter/AliRoot.git] / HLT / programs / convcosmicsfile.cxx
1 // $Id$
2
3 // Author: Constantin Loizides <loizides@ikf.uni-frankfurt.de>
4 //*-- Copyright &copy ALICE HLT Group
5
6 /**
7  Program to convert big <-> little endian cosmics data of 02/2003.
8 */
9
10 #include "AliL3StandardIncludes.h"
11 #include "AliL3RootTypes.h"
12
13 #if __GNUC__ == 3
14 using namespace std;
15 #endif
16
17 //#define DEBUG
18 //#define NOCONV
19
20 //this flag is for the cosmics/pubsub test
21 //#define ADDFILESIZE
22
23 #ifdef ADDFILESIZE
24 #include <sys/stat.h>
25 struct stat stat_results;
26 #endif
27
28 Int_t Convert4(Int_t i)
29 { //BigEndian i0i1i2i3 -> LittleEndian i3i2i1i0
30 #ifdef NOCONV
31   return i;
32 #else
33   Char_t *p=(Char_t*)&i;
34
35   Char_t temp[4];
36   temp[0]=p[3];
37   temp[1]=p[2];
38   temp[2]=p[1];
39   temp[3]=p[0];
40
41   return (*(Int_t*)temp);
42 #endif
43 }
44
45 Short_t Convert2(Short_t s)
46 { //BigEndian i0i1 -> LittleEndian i1i0
47 #ifdef NOCONV
48   return s;
49 #else
50   Char_t *p=(Char_t*)&s;
51
52   Char_t temp[2];
53   temp[0]=p[1];
54   temp[1]=p[0];
55
56   return (*(Short_t*)temp);
57 #endif
58 }
59
60 int main(Int_t argc, Char_t **argv)
61 {
62   //p1 -> filename
63   //p2 -> file is in little endian
64   Int_t islittle=0;
65
66   if((sizeof(Int_t) != 4) || (sizeof(Short_t) != 2)) {
67     cerr << "Check architecture to run the conversion on! Int_t should be 32 and Short_t should be 16 bit." << endl;
68     exit(1);
69   }
70
71   Char_t fname[1024];
72   if(argc==1)
73     sprintf(fname,"%s","/home/loizides/tmp/cosmics/run0013/evt0000");
74   else if(argc==2)
75     strcpy(fname,argv[1]);
76   else if(argc>2){
77     strcpy(fname,argv[1]);
78     islittle=1;
79   }
80
81   ifstream *in = new ifstream();
82   in->open(fname,fstream::binary);
83   if(!in->is_open()){
84     cerr << "Error opening input file " << fname << endl;
85     exit(1);
86   }
87
88   Char_t sname[1024];
89 #ifdef ADDFILESIZE
90   sprintf(sname,"%s.added",fname);
91 #else
92   sprintf(sname,"%s.conv",fname);
93 #endif
94   ofstream *out = new ofstream();
95   out->open(sname,fstream::in | fstream::out | fstream::binary | fstream::trunc);
96   if(!in->is_open()){
97     cerr << "Error opening output file " << sname << endl;
98     exit(1);
99   }
100
101
102   Int_t dummy4;
103   Short_t dummy2;
104 #ifdef ADDFILESIZE
105   if (stat(fname, &stat_results) == 0){
106     dummy4=stat_results.st_size/4;
107     cout << "Add file size: " << dummy4 << endl;
108   } else {
109     cerr << "Error stating input file " << fname << endl;
110     exit(1);
111   }
112   out->write((Char_t*)&dummy4,sizeof(dummy4));
113 #endif
114
115   in->read((Char_t*)&dummy4,sizeof(dummy4));
116   const Int_t knumofChannels = Convert4(dummy4);
117 #ifdef DEBUG
118   cout << knumofChannels << endl;
119 #endif
120   out->write((Char_t*)&knumofChannels,sizeof(knumofChannels));
121
122   Int_t channelloop=knumofChannels;
123   if(islittle) channelloop=dummy4;
124   for(Int_t i = 0 ; i < channelloop ; i++){
125     in->read((Char_t*)&dummy2,sizeof(dummy2));
126     Short_t channel = Convert2(dummy2);
127     out->write((Char_t*)&channel,sizeof(channel));
128 #ifdef DEBUG
129     cout << channel << " ";
130 #endif
131   }
132 #ifdef DEBUG
133   cout << endl;
134 #endif
135
136   in->read((Char_t*)&dummy4,sizeof(dummy4));
137   const Int_t numofChannelsTest = Convert4(dummy4);
138 #ifdef DEBUG
139   cout << numofChannelsTest << endl;
140 #endif
141   out->write((Char_t*)&numofChannelsTest,sizeof(numofChannelsTest));
142
143   if (knumofChannels != numofChannelsTest){
144     cerr << "Error in File format: \"channels " << knumofChannels << " must be channels-test " << numofChannelsTest << "\" "<< endl;
145   }
146
147   in->read((Char_t*)&dummy4,sizeof(dummy4));
148   const Int_t knumofTimebins = Convert4(dummy4);
149 #ifdef DEBUG
150   cout << knumofTimebins << endl;
151 #endif
152   out->write((Char_t*)&knumofTimebins,sizeof(knumofTimebins));
153
154   Int_t timeloop=knumofTimebins;
155   if(islittle) timeloop=dummy4;
156
157   cout << "Input:  " << fname << endl;
158   cout << "Output: " << sname << endl;
159   cout << "Channels: " << knumofChannels << endl;
160   cout << "Timebins: " << knumofTimebins << endl;
161
162   for(int channel = 0; channel < channelloop; channel++){
163     for(int timebin = 0 ; timebin < timeloop ; timebin++){
164       in->read((Char_t*)&dummy2,sizeof(dummy2));
165       Short_t charge = Convert2(dummy2);
166 #ifdef DEBUG
167       cout << charge << " ";
168 #endif
169       out->write((Char_t*)&charge,sizeof(charge));
170     }
171 #ifdef DEBUG
172     cout << endl;
173 #endif
174   }
175
176   in->close();
177   out->close();
178 }
179
180
181
182 /*
183   Data format as of 28/01/2003 R. Bramm explained,
184   sorry for the German text, too lazy to translate now
185
186   Die Files beinhalten 512 Kanaele (Altrokanäle also 32 Altros)
187   mit je 999 Timebins. -> depends on detailed setting of the test
188
189   Format ist
190   Anzahl der Kaenaele als int32
191   Liste der Kanaele je int16
192   Anzahl der Kaenaele als int32
193   Anzahl der Timebins
194
195   und dann vollkommenformatlos
196   Anzahl der Kaenaele * Anzahl der Timebins (512*1000 values)
197
198   Bezogen auf das Mapping:
199 ----------------------------
200   Die Kanalnummer, die die nehmen, ist Spalte 0 oder 9 also der 
201   Altrochannel. Die GSI nimmt aber einfach die "FEC Channels" 
202   was einfach die Anschlusse des Kabels durchgezaehlt sind ... 
203   dummerweise ist FECChannel != Altrochannel
204
205   FEC ist Front End Card
206   FEC Channel ist die Kanalnummer ... 
207   Altro channel ist durchnummeriert vom 0 bis 511 also fuer 32 Altros. 
208   (insofern ist der Name falsch ... weils mehrere altros sind.)
209
210   es geht aber mit 
211   8,9,10,11,12,13,14,15,7,6,5,4,3,2,1,0 (alles + 16)
212   weiter weil der Altro auf der Unterseite liegt
213
214   pad und row kann man umrechnen (steht nicht die formel im .doc ?) in x,y 
215   timebin ist "komplizierter" denn da brauchtm an driftgeschw. + samplingfreq
216   ja, aber in meiner tabelle mit den Altrochannels steht alles mit drin.
217
218   es existiert noch
219   http://137.138.45.89:8080/svn/repos/TPCMapping/trunk/MappingData/mappingRowPad.data
220   dadrin steht die anzahl der pads pro row, rownummer, liste der pads
221   die pads sind in "altrochannel" codiert ... war einfacher das so einzuwurschteln 
222   ... brauche ich aber nur fuer die Row view und ich hatte keinen Bock, das 
223   jedes mal aus dem Ulifile zu erzeugen ...
224
225   wenn du in http://mactpc01.cern.ch:8080
226   /svn/repos/TPCMapping/trunk/MappingData/mapping32313029.data
227   schaust, dann ist das erste die "altrochannelnummer" und in spalte 7 
228   (c array zaehlweise) 
229   steht der FEC channel. in den Events steht also immer 999 mal n adc value 
230   fuer jeden "altrochannel" in genau der reihenfolge wie in dem obigen file.
231
232   Im OM.C loope ich von 
233   Zeile 124 bis 175 uebers file 
234   interessant ist nur das einlesen
235   von 124 bis 127
236   dann berechne ich die baseline
237   128 - 132
238   dann kommt maxadc
239   134 - 143
240   dann rudimentaeres Clusterfindeing abe das ist unwichtig
241   143 - 163
242   dann kommt das fuellen des TPC Topviews, wo auch das "mapping " drinsteckt
243   171-174
244
245   du solltest lesen 
246   512 als int32
247   0 als int16
248   1 als int16
249   2 als int16
250   3 als int16
251   ...
252   511 als int16
253   512 als int32
254   999 als int32
255   dann int16 ...
256
257
258   So zur frage wer ordert:
259   Luciano und ich haben gebraeinstormed und kamen zum ergebnis, dass es 
260   auch kein Problem waere die RCU pad by pad auslesen zu lassen ... 
261   also "komplett korrekt" gemapped.
262   man braucht nur nen lookuptable. Da ist keine Latenz, die es problematisch 
263   macht, das man 
264   fee 1 channel 1 = pad 1 
265   fee 1 channel 2 = pad 2
266   fee 1 channel 4 = pad 3
267   fee 1 channel 3 = pad 4
268   fee 2 channel 1 = pad 5
269   ...
270 */