MIDAS
Loading...
Searching...
No Matches
analyzer.cxx
Go to the documentation of this file.
1/********************************************************************\
2
3 Name: analyzer.c
4 Created by: Stefan Ritt
5
6 Contents: System part of Analyzer code for sample experiment
7
8 $Id$
9
10\********************************************************************/
11
12/* standard includes */
13#include <stdio.h>
14#include <string.h>
15#include <time.h>
16
17/* midas includes */
18#include "midas.h"
19#include "experim.h"
20#include "analyzer.h"
21
22/* cernlib includes */
23#ifdef OS_WINNT
24#define VISUAL_CPLUSPLUS
25#endif
26#ifdef __linux__
27#define f2cFortran
28#endif
29
30#ifdef HAVE_HBOOK
31#include <cfortran.h>
32#include <hbook.h>
33
34PAWC_DEFINE(1000000);
35#endif /* HAVE_HBOOK */
36
37/*-- Globals -------------------------------------------------------*/
38
39/* The analyzer name (client name) as seen by other MIDAS clients */
40const char *analyzer_name = "Analyzer";
41
42/* analyzer_loop is called with this interval in ms (0 to disable) */
44
45/* default ODB size */
47
48/* ODB structures */
53
54/*-- Module declarations -------------------------------------------*/
55
59
64
70
71/*-- Bank definitions ----------------------------------------------*/
72
74
76
77 /* online banks */
78 {"ADC0", TID_UINT32, N_ADC, NULL},
79 {"TDC0", TID_UINT32, N_TDC, NULL},
80
81 /* calculated banks */
82 {"CADC", TID_FLOAT, N_ADC, NULL},
83 {"ASUM", TID_STRUCT, sizeof(ASUM_BANK), (char **)asum_bank_str},
84
85 {""},
86};
87
89 /* online banks */
90 {"SCLR", TID_UINT32, N_ADC, NULL},
91
92 /* calculated banks */
93 {"ACUM", TID_DOUBLE, N_ADC, NULL},
94 {""},
95};
96
97/*-- Event request list --------------------------------------------*/
98
100 {"Trigger", /* equipment name */
101 {1, /* event ID */
102 TRIGGER_ALL, /* trigger mask */
103 GET_NONBLOCKING, /* get events without blocking producer */
104 "SYSTEM", /* event buffer */
105 TRUE, /* enabled */
106 "", "",}
107 ,
108 NULL, /* analyzer routine */
109 trigger_module, /* module list */
110 ana_trigger_bank_list, /* bank list */
111 1000, /* RWNT buffer size */
112 TRUE, /* Use tests for this event */
113 }
114 ,
115
116 {"Scaler", /* equipment name */
117 {2, /* event ID */
118 TRIGGER_ALL, /* trigger mask */
119 GET_ALL, /* get all events */
120 "SYSTEM", /* event buffer */
121 TRUE, /* enabled */
122 "", "",}
123 ,
124 NULL, /* analyzer routine */
125 scaler_module, /* module list */
126 ana_scaler_bank_list, /* bank list */
127 100, /* RWNT buffer size */
128 }
129 ,
130
131 {""}
132 ,
133};
134
135/*-- Analyzer Init -------------------------------------------------*/
136
138{
139 HNDLE hDB, hKey;
140 char str[80];
141
146
147 /* open ODB structures */
149 db_create_record(hDB, 0, "/Runinfo", strcomb1((const char **)runinfo_str).c_str());
150 db_find_key(hDB, 0, "/Runinfo", &hKey);
151 if (db_open_record(hDB, hKey, &runinfo, sizeof(runinfo), MODE_READ, NULL, NULL) !=
152 DB_SUCCESS) {
153 cm_msg(MERROR, "analyzer_init", "Cannot open \"/Runinfo\" tree in ODB");
154 return 0;
155 }
156
157 db_create_record(hDB, 0, "/Experiment/Run Parameters", strcomb1((const char **)exp_param_str).c_str());
158 db_find_key(hDB, 0, "/Experiment/Run Parameters", &hKey);
160 DB_SUCCESS) {
161 cm_msg(MERROR, "analyzer_init",
162 "Cannot open \"/Experiment/Run Parameters\" tree in ODB");
163 return 0;
164 }
165
166 sprintf(str, "/%s/Parameters/Global", analyzer_name);
167 db_create_record(hDB, 0, str, strcomb1((const char **)global_param_str).c_str());
168 db_find_key(hDB, 0, str, &hKey);
171 NULL) != DB_SUCCESS) {
172 cm_msg(MERROR, "analyzer_init", "Cannot open \"%s\" tree in ODB", str);
173 return 0;
174 }
175
176 db_create_record(hDB, 0, "/Equipment/Trigger/Settings", strcomb1((const char **)trigger_settings_str).c_str());
177 db_find_key(hDB, 0, "/Equipment/Trigger/Settings", &hKey);
178
181 NULL) != DB_SUCCESS) {
182 cm_msg(MERROR, "analyzer_init",
183 "Cannot open \"/Equipment/Trigger/Settings\" tree in ODB");
184 return 0;
185 }
186
187 return SUCCESS;
188}
189
190/*-- Analyzer Exit -------------------------------------------------*/
191
193{
194 return CM_SUCCESS;
195}
196
197/*-- Begin of Run --------------------------------------------------*/
198
200{
201 return CM_SUCCESS;
202}
203
204/*-- End of Run ----------------------------------------------------*/
205
207{
208 FILE *f;
209 time_t now;
210 char str[256];
211 int size;
212 double n;
213 HNDLE hDB;
214 BOOL flag;
215
217
218 /* update run log if run was written and running online */
219
220 size = sizeof(flag);
221 db_get_value(hDB, 0, "/Logger/Write data", &flag, &size, TID_BOOL, TRUE);
222 if (flag && runinfo.online_mode == 1) {
223 /* update run log */
224 size = sizeof(str);
225 str[0] = 0;
226 db_get_value(hDB, 0, "/Logger/Data Dir", str, &size, TID_STRING, TRUE);
227 if (str[0] != 0)
228 if (str[strlen(str) - 1] != DIR_SEPARATOR)
230 strcat(str, "runlog.txt");
231
232 f = fopen(str, "a");
233
234 time(&now);
235 strcpy(str, ctime(&now));
236 str[10] = 0;
237
238 fprintf(f, "%s\t%3d\t", str, runinfo.run_number);
239
240 strcpy(str, runinfo.start_time);
241 str[19] = 0;
242 fprintf(f, "%s\t", str + 11);
243
244 strcpy(str, ctime(&now));
245 str[19] = 0;
246 fprintf(f, "%s\t", str + 11);
247
248 size = sizeof(n);
249 db_get_value(hDB, 0, "/Equipment/Trigger/Statistics/Events sent", &n, &size,
251
252 fprintf(f, "%5.1lfk\t", n / 1000);
253 fprintf(f, "%s\n", exp_param.comment);
254
255 fclose(f);
256 }
257
258 return CM_SUCCESS;
259}
260
261/*-- Pause Run -----------------------------------------------------*/
262
264{
265 return CM_SUCCESS;
266}
267
268/*-- Resume Run ----------------------------------------------------*/
269
271{
272 return CM_SUCCESS;
273}
274
275/*-- Analyzer Loop -------------------------------------------------*/
276
278{
279 return CM_SUCCESS;
280}
281
282/*------------------------------------------------------------------*/
TRIGGER_SETTINGS trigger_settings
Definition analyzer.cxx:52
INT ana_begin_of_run(INT run_number, char *error)
Definition analyzer.cxx:199
INT ana_resume_run(INT run_number, char *error)
Definition analyzer.cxx:270
GLOBAL_PARAM global_param
Definition analyzer.cxx:50
ANA_MODULE scaler_accum_module
Definition scaler.cxx:32
ANA_MODULE adc_summing_module
Definition adcsum.cxx:54
const char * analyzer_name
Definition analyzer.cxx:40
ANA_MODULE adc_calib_module
Definition adccalib.cxx:49
BANK_LIST ana_scaler_bank_list[]
Definition analyzer.cxx:88
EXP_PARAM exp_param
Definition analyzer.cxx:51
INT analyzer_loop()
Definition analyzer.cxx:277
INT odb_size
Definition analyzer.cxx:46
INT analyzer_exit()
Definition analyzer.cxx:192
ANA_MODULE * trigger_module[]
Definition analyzer.cxx:65
INT ana_pause_run(INT run_number, char *error)
Definition analyzer.cxx:263
ANA_MODULE * scaler_module[]
Definition analyzer.cxx:60
INT ana_end_of_run(INT run_number, char *error)
Definition analyzer.cxx:206
INT analyzer_loop_period
Definition analyzer.cxx:43
ANALYZE_REQUEST analyze_request[]
Definition analyzer.cxx:99
BANK_LIST ana_trigger_bank_list[]
Definition analyzer.cxx:75
RUNINFO runinfo
Definition analyzer.cxx:49
INT analyzer_init()
Definition analyzer.cxx:137
#define N_TDC
Definition deferredfe.c:50
#define N_ADC
Definition deferredfe.c:49
#define ASUM_BANK_STR(_name)
Definition experim.h:113
#define EXP_PARAM_STR(_name)
Definition experim.h:30
#define GLOBAL_PARAM_STR(_name)
Definition experim.h:96
#define TRIGGER_SETTINGS_STR(_name)
Definition experim.h:166
INT cm_get_experiment_database(HNDLE *hDB, HNDLE *hKeyClient)
Definition midas.cxx:3011
#define CM_SUCCESS
Definition midas.h:582
#define DB_SUCCESS
Definition midas.h:631
#define SUCCESS
Definition mcstd.h:54
#define GET_NONBLOCKING
Definition midas.h:322
#define TID_DOUBLE
Definition midas.h:343
#define GET_ALL
Definition midas.h:321
#define TID_BOOL
Definition midas.h:340
#define TRIGGER_ALL
Definition midas.h:538
#define TID_STRUCT
Definition midas.h:348
#define TID_STRING
Definition midas.h:346
#define MERROR
Definition midas.h:559
#define MODE_READ
Definition midas.h:370
#define TID_UINT32
Definition midas.h:337
#define TID_FLOAT
Definition midas.h:341
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
Definition midas.cxx:915
INT db_get_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, void *data, INT *buf_size, DWORD type, BOOL create)
Definition odb.cxx:5415
INT db_open_record(HNDLE hDB, HNDLE hKey, void *ptr, INT rec_size, WORD access_mode, void(*dispatcher)(INT, INT, void *), void *info)
Definition odb.cxx:13291
std::string strcomb1(const char **list)
Definition odb.cxx:598
INT db_find_key(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
Definition odb.cxx:4079
INT db_create_record(HNDLE hDB, HNDLE hKey, const char *orig_key_name, const char *init_str)
Definition odb.cxx:12800
HNDLE hKey
INT run_number[2]
Definition mana.cxx:246
DWORD n[4]
Definition mana.cxx:247
HNDLE hDB
main ODB handle
Definition mana.cxx:207
#define DIR_SEPARATOR
Definition midas.h:193
INT HNDLE
Definition midas.h:132
DWORD BOOL
Definition midas.h:105
#define DIR_SEPARATOR_STR
Definition midas.h:194
int INT
Definition midas.h:129
#define PAWC_DEFINE(size)
Definition midas.h:1569
#define TRUE
Definition midas.h:182
#define DEFAULT_ODB_SIZE
Definition midas.h:270
#define RUNINFO_STR(_name)
Definition midas.h:1410
#define ctime
Definition msystem.h:264
char str[256]
Definition odbhist.cxx:33
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
char comment[80]
Definition experim.h:27
char start_time[32]
Definition midas.h:1404
INT online_mode
Definition midas.h:1399
INT run_number
Definition midas.h:1400