]>
Commit | Line | Data |
---|---|---|
3e87ef69 | 1 | // $Id$ |
2 | ||
3 | // Author: Constantin Loizides <loizides@ikf.uni-frankfurt.de> | |
02f030e3 | 4 | //*-- Copyright © ALICE HLT Group |
3e87ef69 | 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 | ||
0bd0c1ef | 13 | #if __GNUC__ == 3 |
3e87ef69 | 14 | using namespace std; |
15 | #endif | |
16 | ||
17 | //#define DEBUG | |
18 | //#define NOCONV | |
19 | ||
de3c3890 | 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 | ||
3e87ef69 | 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 | ||
3e87ef69 | 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 | ||
3e87ef69 | 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 | ||
de3c3890 | 88 | Char_t sname[1024]; |
89 | #ifdef ADDFILESIZE | |
90 | sprintf(sname,"%s.added",fname); | |
91 | #else | |
92 | sprintf(sname,"%s.conv",fname); | |
93 | #endif | |
3e87ef69 | 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 | ||
de3c3890 | 101 | |
3e87ef69 | 102 | Int_t dummy4; |
103 | Short_t dummy2; | |
de3c3890 | 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 | |
3e87ef69 | 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 |