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