forked from padsley/k600analyser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyzer.c
executable file
·355 lines (271 loc) · 9.49 KB
/
analyzer.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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/********************************************************************\
Name: analyzer.c
Created by: Roger Fearick
Contents: System part of Analyzer code for K600
\********************************************************************/
/* standard includes */
#include <stdio.h>
#include <string.h>
#include <time.h>
/* midas includes */
#include "midas.h"
#include "experim.h"
#include "analyzer.h"
/* cernlib includes */
#ifdef OS_WINNT
#define VISUAL_CPLUSPLUS
#endif
#ifdef __linux__
#define f2cFortran
#endif
/* root includes */
#include <TTree.h>
#include <TFile.h>
/* home-made includes */
#include "Parameters.h"
/* // what is this!?! I thought we are working with ROOT?
#ifdef HAVE_HBOOK
#include <cfortran.h>
#include <hbook.h>
PAWC_DEFINE(2000000);
#endif // HAVE_HBOOK
*/
/*-- Globals -------------------------------------------------------*/
// ODB structures : what is this doing?
RUNINFO runinfo;
EXP_PARAM exp_param;
//GLOBAL_PARAM globals; //these are useless here? I need them in f-plane.c, which is outside this scope
// The analyzer name (client name) as seen by other MIDAS clients
char *analyzer_name = "Analyzer";
// analyzer_loop is called with this interval in ms (0 to disable)
INT analyzer_loop_period = 0;
// default ODB size
INT odb_size = DEFAULT_ODB_SIZE;
// counters used in f-plane to look at bad tdc events: either empty or too large
int toolarge_tdc_event_counter=0;
int empty_tdc_counter=0;
int qdc_counter1=0, qdc_counter2=0;
int adc_counter1=0, adc_counter2=0;
int tdc_counter=0;
int scaler_counter=0;
int beamline_counter=0;
int trailer_TDCERR_counter=0;
int trailer_triglost_counter=0;
int trailer_bufoverflow_counter=0;
//int skipcounter=0;
//int runnr=0;
/*-- Module declarations -------------------------------------------*/
extern ANA_MODULE scaler_accum_module;
extern ANA_MODULE main_module;
extern ANA_MODULE qdc_module;
extern ANA_MODULE adc_module;
extern ANA_MODULE beamline_module;
ANA_MODULE *beam_module[] = {
&beamline_module,
NULL
};
ANA_MODULE *scaler_module[] = {
&scaler_accum_module,
NULL
};
ANA_MODULE *trigger_module[] = {
&adc_module,
&qdc_module,
&main_module,
NULL
};
/*-- Bank definitions ----------------------------------------------*/
BANK_LIST ana_trigger_bank_list[] = {
// online banks
{"ADC0", TID_DWORD, N_ADC, NULL},
{"QDC0", TID_DWORD, N_QDC, NULL},
{"TDC0", TID_DWORD, N_TDC, NULL},
// calculated banks
//{"CADC", TID_FLOAT, N_ADC, NULL},
//{"ASUM", TID_STRUCT, sizeof(ASUM_BANK), asum_bank_str},
{""},
};
BANK_LIST ana_scaler_bank_list[] = {
// online banks
{"SCLR", TID_DWORD, N_SCLR, NULL},
// calculated banks
// {"ACUM", TID_DOUBLE, N_ADC, NULL},
{""},
};
BANK_LIST ana_beam_bank_list[] = {
// online banks
{"MSRD", TID_FLOAT, N_MSRD, NULL},
{""},
};
/*-- Event request list --------------------------------------------*/
ANALYZE_REQUEST analyze_request[] = {
{"Trigger", /* equipment name */
{1, /* event ID */
TRIGGER_ALL, /* trigger mask */
GET_SOME, /* get some events */
"SYSTEM", /* event buffer */
TRUE, /* enabled */
"", "",}
,
NULL, /* analyzer routine */
trigger_module, /* module list */
ana_trigger_bank_list, /* bank list */
1000, /* RWNT buffer size */
TRUE, /* Use tests for this event */
}
,
{"Scaler", /* equipment name */
{2, /* event ID */
TRIGGER_ALL, /* trigger mask */
GET_ALL, /* get all events */
"SYSTEM", /* event buffer */
TRUE, /* enabled */
"", "",}
,
NULL, /* analyzer routine */
scaler_module, /* module list */
ana_scaler_bank_list, /* bank list */
100, /* RWNT buffer size */
}
,
{"Beamline", /* equipment name */
{3, /* event ID */
TRIGGER_ALL, /* trigger mask */
GET_ALL, /* get all events */
"SYSTEM", /* event buffer */
TRUE, /* enabled */
"", "",}
,
NULL, /* analyzer routine */
beam_module, /* module list */
ana_beam_bank_list, /* bank list */
100, /* RWNT buffer size */
}
,
{""}
,
};
/*-- Analyzer Init -------------------------------------------------*/
INT analyzer_init()
{
HNDLE hDB, hKey;
char str[80];
RUNINFO_STR(runinfo_str); // RUNINFO_STR in experim.h rn: not true !?!?!
EXP_PARAM_STR(exp_param_str); // EXP_PARAM_STR in experim.h rn: not true !!?!?!
//GLOBAL_PARAM_STR(global_param_str); // GLOBAL_PARAM_STR in experim.h
/* open ODB structures */
cm_get_experiment_database(&hDB, NULL);
db_create_record(hDB, 0, "/Runinfo", strcomb(runinfo_str));
db_find_key(hDB, 0, "/Runinfo", &hKey);
if (db_open_record(hDB, hKey, &runinfo, sizeof(runinfo), MODE_READ, NULL, NULL) !=
DB_SUCCESS) {
cm_msg(MERROR, "analyzer_init", "Cannot open \"/Runinfo\" tree in ODB");
return 0;
}
db_create_record(hDB, 0, "/Experiment/Run Parameters", strcomb(exp_param_str));
db_find_key(hDB, 0, "/Experiment/Run Parameters", &hKey);
if (db_open_record(hDB, hKey, &exp_param, sizeof(exp_param), MODE_READ, NULL, NULL) !=
DB_SUCCESS) {
cm_msg(MERROR, "analyzer_init",
"Cannot open \"/Experiment/Run Parameters\" tree in ODB");
return 0;
}
//printf("\n---testing testing 123----------------------------------------------- %i \n\n\n\n ",runinfo.run_number);
//runnr=runinfo.run_number;
ParameterInit();
return SUCCESS;
}
/*-- Analyzer Exit -------------------------------------------------*/
INT analyzer_exit()
{
return CM_SUCCESS;
}
/*-- Begin of Run --------------------------------------------------*/
INT ana_begin_of_run(INT run_number, char *error)
{
return CM_SUCCESS;
}
/*-- End of Run ----------------------------------------------------*/
INT ana_end_of_run(INT run_number, char *error)
{
FILE *f;
time_t now;
char str[256];
int size;
double n;
HNDLE hDB;
BOOL flag;
cm_get_experiment_database(&hDB, NULL);
/* update run log if run was written and running online */
size = sizeof(flag);
db_get_value(hDB, 0, "/Logger/Write data", &flag, &size, TID_BOOL, TRUE);
if (flag && runinfo.online_mode == 1) {
/* update run log */
size = sizeof(str);
str[0] = 0;
db_get_value(hDB, 0, "/Logger/Data Dir", str, &size, TID_STRING, TRUE);
if (str[0] != 0)
if (str[strlen(str) - 1] != DIR_SEPARATOR)
strcat(str, DIR_SEPARATOR_STR);
strcat(str, "runlog.txt");
f = fopen(str, "a");
time(&now);
strcpy(str, ctime(&now));
str[10] = 0;
fprintf(f, "%s\t%3d\t", str, runinfo.run_number);
strcpy(str, runinfo.start_time);
str[19] = 0;
fprintf(f, "%s\t", str + 11);
strcpy(str, ctime(&now));
str[19] = 0;
fprintf(f, "%s\t", str + 11);
size = sizeof(n);
db_get_value(hDB, 0, "/Equipment/Trigger/Statistics/Events sent", &n, &size,
TID_DOUBLE, TRUE);
fprintf(f, "%5.1lfk\t", n / 1000);
fprintf(f, "%s\n", exp_param.comment);
fclose(f);
}
printf("\n------------------------------------------------------");
printf("\n| |");
printf("\n| TDC Events: %i ",tdc_counter);
printf("\n| QDC Events: %i ",qdc_counter1);
printf("\n| ADC Events: %i ",adc_counter1);
printf("\n| Scaler Events %i ",scaler_counter);
// printf("\n| ");
// printf("\n| Events with skips %i ",skipcounter);
printf("\n| ");
printf("\n| Events with no TDC datawords : %i ",empty_tdc_counter);
printf("\n| Events with too many TDC datawords : %i ",toolarge_tdc_event_counter);
printf("\n| Events with no QDC datawords: %i ",qdc_counter2);
printf("\n| Events with no ADC datawords: %i ",adc_counter2);
printf("\n| ");
printf("\n| TDC chip ERRORS: %i ",trailer_TDCERR_counter); // counter in TDC trailer
printf("\n| TDC triggers lost: %i ",trailer_triglost_counter); // counter in TDC trailer
printf("\n| TDC buffer overflow: %i ",trailer_bufoverflow_counter); // counter in TDC trailer
printf("\n| |");
printf("\n------------------------------------------------------\n");
// close the root file (that containst the trees) created in f-plane.c
extern TFile *f1; // declared in main.c
extern TTree *t1; // declared in main.c
f1->cd();
f1->Write();
f1->Close();
return CM_SUCCESS;
}
/*-- Pause Run -----------------------------------------------------*/
INT ana_pause_run(INT run_number, char *error)
{
return CM_SUCCESS;
}
/*-- Resume Run ----------------------------------------------------*/
INT ana_resume_run(INT run_number, char *error)
{
return CM_SUCCESS;
}
/*-- Analyzer Loop -------------------------------------------------*/
INT analyzer_loop()
{
return CM_SUCCESS;
}
/*------------------------------------------------------------------*/