-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriteTrack_repeat.c
303 lines (154 loc) · 5.01 KB
/
writeTrack_repeat.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include "ctk.h"
#include "gdecomp.h"
#define DEBUG 0
/* globals */
volatile extern TRACKINGPAR Pars;
/*----------------------------------------------------------------------------*/
int
writeTrack_repeat (TRACK_STRUCT * track)
{
/* this function first writes the original data to the */
/* output data sream, then it writes the tracked data. */
/* this function is for offline use. online the serializeTrack */
/* is used */
/* declarations */
static int nwritten = 0;
int siz, iCluster, i1, ng, nmTS;
float rn, rn1;
unsigned int grnum = 0;
char str[128];
long long int mTS[1000];
int wo[1000];
#if(DEBUG)
int nobytes = 0;
#endif
PAYLOAD *ptinp;
GEBDATA *ptgd;
CRYS_INTPTS *gtinp;
GEBDATA trackGeb;
char *payLoad;
TRACKED_GAMMA_RAY tgr;
long long int dTS;
static long long int oldTS;
static int nn = 0;
int checksum, *iptr;
int i, j;
if (Pars.trackDataStream > 0)
{
/*-------------------------*/
/* write the original data */
/*-------------------------*/
/* simple echo of input data to the tracking task. */
/* It may contain external data for all we know */
/* o we will not echo any old tracked data */
/* o we do not pass on the multiplicity information */
ptgd = track->gd;
ptinp = track->payload;
for (i = 0; i < track->n; i++)
{
/* only repeat non tracked data */
if (ptgd->type != GEB_TYPE_TRACK)
{
assert(Pars.trackDataStream!=NULL);
// siz = write (Pars.trackDataStream, (char *) ptgd, sizeof (GEBDATA));
siz = fwrite((char *) ptgd,1,sizeof (GEBDATA),Pars.trackDataStream);
// printf("wrote gebheader, length=%i, %i\n",sizeof (GEBDATA) , siz); fflush(stdout);
// assert (siz == sizeof (GEBDATA));
// siz = write (Pars.trackDataStream, (char *) ptinp, ptgd->length);
siz = fwrite ((char *) ptinp, 1, ptgd->length, Pars.trackDataStream);
// printf("wrote data of type %i, length=%i, %i\n", ptgd->type, ptgd->length, siz); fflush(stdout);
assert (siz == ptgd->length);
};
ptgd++;
ptinp++;
};
// fprintf (stderr,"done\n");
// fflush (stdout);
// fprintf (stderr,"wrote event # %i out\n", nwritten);
// nwritten++;
return (0);
};
return (0);
}
/*----------------------------------------------------------------------------*/
#if(0)
/*--------------------------------------------------------*/
/* Here is Carls new CRYS_INTPTS *gtinp;
fancy data output routine. Even..... */
/* though I don't use it directly, we keep it here so.... */
/* it follows my updates. Wed 12 Jan 2011 02:43:28 PM CST */
/*--------------------------------------------------------*/
/* this function is out of date!!!!! */
void *
serializeTrack (TRACK_STRUCT * track, CLUSTER_INTPTS Clstr[MAXCLUSTERHITS], int *nClusters, int *bufferlen)
{
/* this produces an output buffer identical to what writeTrack would write */
/* declarations */
int iCluster, i1, nValidClusters, ninteractions;
char *retval, *bptr;
int retsize = 0;
CRYS_INTPTS *ptinp;
GEBDATA *ptgd;
int i, j;
retsize = track->n * (sizeof (CRYS_INTPTS) + sizeof (GEBDATA));
retsize += sizeof (int);
/* find number of valid clusters */
nValidClusters = 0;
for (iCluster = 0; iCluster < *nClusters; iCluster++)
if (Clstr[iCluster].valid)
nValidClusters++;
/* calculate how much buffer space we need */
/* for the clusters */
retsize = retsize + nValidClusters * sizeof (CLUSTER_INTPTS) + sizeof (int);
/* and allocate space */
retval = (char *) malloc (retsize);
if (!retval)
{
*bufferlen = 0;
return 0;
}
bptr = retval;
/*----------*/
/* raw data */
/*----------*/
/* first write multiplicity of event */
memcpy (bptr, (char *) &track->n, sizeof (int));
bptr += sizeof (int);
/* then write the rest of the event */
ptgd = track->gd;
ptinp = track->inp;
for (i = 0; i < track->n; i++)
{
memcpy (bptr, (char *) ptgd, sizeof (GEBDATA));
bptr += sizeof (GEBDATA);
memcpy (bptr, (char *) ptinp, ptgd->length);
bptr += ptgd->length;
ptgd++;
ptinp++;
};
/*--------------*/
/* tracked data */
/*--------------*/
/* first write multiplicity of event */
/* we of course only write valid clusters */
/* out, skipping discarded ones */
/* nValidClusters already determined above */
memcpy (bptr, (char *) &nValidClusters, sizeof (int));
bptr += sizeof (int);
/* now write the data */
for (iCluster = 0; iCluster < *nClusters; iCluster++)
if (Clstr[iCluster].valid)
{
memcpy (bptr, (char *) &Clstr[iCluster], sizeof (CLUSTER_INTPTS));
bptr += sizeof (CLUSTER_INTPTS);
}
*bufferlen = retsize;
return retval;
}
#endif