AlcapDAQ  1
Macros | Functions | Variables
new_mevb.cpp File Reference
#include <stdio.h>
#include "midas.h"
#include "mevb.h"
#include "msystem.h"
#include "ybos.h"

Go to the source code of this file.

Macros

#define SERVER_CACHE_SIZE   100000 /* event cache before buffer */
 
#define ODB_UPDATE_TIME   1000 /* 1 seconds for ODB update */
 
#define DEFAULT_FE_TIMEOUT   60000 /* 60 seconds for watchdog timeout */
 
#define EQUIPMENT_COMMON_STR   "\Event ID = WORD : 0\n\Trigger mask = WORD : 0\n\Buffer = STRING : [32] SYSTEM\n\Type = INT : 0\n\Source = INT : 0\n\Format = STRING : [8] FIXED\n\Enabled = BOOL : 0\n\Read on = INT : 0\n\Period = INT : 0\n\Event limit = DOUBLE : 0\n\Num subevents = DWORD : 0\n\Log history = INT : 0\n\Frontend host = STRING : [32] \n\Frontend name = STRING : [32] \n\Frontend file name = STRING : [256] \n\"
 
#define EQUIPMENT_STATISTICS_STR   "\Events sent = DOUBLE : 0\n\Events per sec. = DOUBLE : 0\n\kBytes per sec. = DOUBLE : 0\n\"
 

Functions

INT handFlush (void)
 
INT source_booking (void)
 
INT source_unbooking (void)
 
INT close_buffers (void)
 
INT source_scan (INT fmt, EQUIPMENT_INFO *eq_info)
 
INT eb_mfragment_add (char *pdest, char *psrce, INT *size)
 
INT eb_yfragment_add (char *pdest, char *psrce, INT *size)
 
INT eb_begin_of_run (INT, char *, char *)
 
INT eb_end_of_run (INT, char *)
 
INT eb_user (INT, BOOL mismatch, EBUILDER_CHANNEL *, EVENT_HEADER *, void *, INT *)
 
INT load_fragment (void)
 
INT scan_fragment (void)
 
INT ebuilder_init (void)
 
INT ebuilder_exit (void)
 
INT ebuilder_loop (void)
 
INT ybos_event_swap (DWORD *pevt)
 
INT register_equipment (void)
 
INT tr_start (INT rn, char *error)
 
INT tr_stop (INT rn, char *error)
 
void free_event_buffer (INT nfrag)
 
int main (unsigned int argc, char **argv)
 

Variables

EBUILDER_SETTINGS ebset
 
EBUILDER_CHANNEL ebch [MAX_CHANNELS]
 
INT run_state
 
INT run_number
 
DWORD last_time
 
DWORD actual_time
 
DWORD actual_millitime
 
char host_name [HOST_NAME_LENGTH]
 
char expt_name [NAME_LENGTH]
 
char full_frontend_name [256]
 
char buffer_name [NAME_LENGTH]
 
INT nfragment
 
char * dest_event
 
HNDLE hDB
 
HNDLE hKey
 
HNDLE hStatKey
 
HNDLE hSubkey
 
HNDLE hEqKey
 
HNDLE hESetKey
 
BOOL debug = FALSE
 
BOOL debug1 = FALSE
 
BOOL wheel = FALSE
 
char bars [] = "|\\-/"
 
int i_bar
 
BOOL abort_requested = FALSE
 
BOOL stop_requested = TRUE
 
DWORD stop_time = 0
 
DWORD request_stop_time = 0
 
INT(* meb_fragment_add )(char *, char *, INT *)
 
char * frontend_name
 
char * frontend_file_name
 
BOOL frontend_call_loop
 
INT max_event_size
 
INT max_event_size_frag
 
INT event_buffer_size
 
INT display_period
 
EQUIPMENT equipment []
 

Macro Definition Documentation

#define DEFAULT_FE_TIMEOUT   60000 /* 60 seconds for watchdog timeout */

Definition at line 78 of file new_mevb.cpp.

#define EQUIPMENT_COMMON_STR   "\Event ID = WORD : 0\n\Trigger mask = WORD : 0\n\Buffer = STRING : [32] SYSTEM\n\Type = INT : 0\n\Source = INT : 0\n\Format = STRING : [8] FIXED\n\Enabled = BOOL : 0\n\Read on = INT : 0\n\Period = INT : 0\n\Event limit = DOUBLE : 0\n\Num subevents = DWORD : 0\n\Log history = INT : 0\n\Frontend host = STRING : [32] \n\Frontend name = STRING : [32] \n\Frontend file name = STRING : [256] \n\"

Definition at line 135 of file new_mevb.cpp.

Referenced by register_equipment().

#define EQUIPMENT_STATISTICS_STR   "\Events sent = DOUBLE : 0\n\Events per sec. = DOUBLE : 0\n\kBytes per sec. = DOUBLE : 0\n\"

Definition at line 153 of file new_mevb.cpp.

Referenced by register_equipment().

#define ODB_UPDATE_TIME   1000 /* 1 seconds for ODB update */

Definition at line 76 of file new_mevb.cpp.

#define SERVER_CACHE_SIZE   100000 /* event cache before buffer */

dox

Definition at line 74 of file new_mevb.cpp.

Referenced by register_equipment().

Function Documentation

INT close_buffers ( void  )
INT eb_begin_of_run ( INT  ,
char *  ,
char *   
)

Hook to the event builder task at PreStart transition.

Parameters
rnrun number
UserFieldargument from /Ebuilder/Settings
errorerror string to be passed back to the system.
Returns
EB_SUCCESS
eb_begin_of_run()

Hook to the event builder task at PreStart transition. {verbatim} {verbatim}

Parameters
rnrun number
UserFieldargument from /Ebuilder/Settings
errorerror string to be passed back to the system.
Returns
EB_SUCCESS
eb_begin_of_run()

Hook to the event builder task at PreStart transition. {verbatim} {verbatim}

Parameters
rnrun number
UserFieldargument from /Ebuilder/Settings
errorerror string to be passed back to the system.
Returns
EB_SUCCESS

Definition at line 145 of file ebuser.cpp.

146 {
147 #if 0
148  extern EBUILDER_SETTINGS ebset;
150  extern HNDLE hDB;
151 
152  int n;
153  int mask = 0;
154 
155  char keyName[256];
156  BOOL enabled;
157  int size;
158 
159  /*
160  * Determine which crates are enabled and set up the mask
161  * accordingly.
162  */
163  for(n = 1; n <= NUMCRATES; n++) {
164  sprintf(keyName, "/Equipment/Crate %d/Settings/Enabled", n);
165  size = sizeof(enabled);
166  db_get_value(hDB, 0, keyName, &enabled, &size, TID_BOOL, FALSE);
167  if(size == sizeof(enabled) && enabled) {
168  ebch[n-1].trigger_mask = (1 << (n-1));
169  mask |= ebch[n-1].trigger_mask;
170  } else {
171  ebch[n-1].trigger_mask = 0;
172  }
173  }
174 
175  cm_msg(MINFO, "eb_begin_of_run", "Setting event mask to 0x%x", mask);
176  ebset.trigger_mask = mask;
177 #endif
178 
179  // Initialize online compression
181 
182  return EB_SUCCESS;
183 }
INT eb_end_of_run ( INT  ,
char *   
)

Hook to the event builder task at completion of event collection after receiving the Stop transition.

Parameters
rnrun number
errorerror string to be passed back to the system.
Returns
EB_SUCCESS
eb_end_of_run()

Hook to the event builder task at completion of event collection after receiving the Stop transition. {verbatim} {verbatim}

Parameters
rnrun number
errorerror string to be passed back to the system.
Returns
EB_SUCCESS
eb_end_of_run()

Hook to the event builder task at completion of event collection after receiving the Stop transition. {verbatim} {verbatim}

Parameters
rnrun number
errorerror string to be passed back to the system.
Returns
EB_SUCCESS

Definition at line 193 of file ebuser.cpp.

194 {
195  return EB_SUCCESS;
196 }
INT eb_mfragment_add ( char *  pdest,
char *  psrce,
INT *  size 
)
INT eb_user ( INT  nfrag,
BOOL  mismatch,
EBUILDER_CHANNEL ebch,
EVENT_HEADER *  pheader,
void *  pevent,
INT *  dest_size 
)

Hook to the event builder task after the reception of all fragments of the same serial number. The destination event has already the final EVENT_HEADER setup with the data size set to 0. It is than possible to add private data at this point using the proper bank calls.

The ebch[] array structure points to nfragment channel structure with the following content:

typedef struct {
char name[32]; // Fragment name (Buffer name).
DWORD serial; // Serial fragment number.
char *pfragment; // Pointer to fragment (EVENT_HEADER *)
...

The correct code for including your own MIDAS bank is shown below where TID_xxx is one of the valid Bank type starting with TID_ for midas format or xxx_BKTYPE for Ybos data format. bank_name is a 4 character descriptor. pdata has to be declared accordingly with the bank type. Refers to the ebuser.c source code for further description.

It is not possible to mix within the same destination event different event format!

// Event is empty, fill it with BANK_HEADER
// If you need to add your own bank at this stage
bk_init(pevent);
bk_create(pevent, bank_name, TID_xxxx, &pdata);
pdata++ = ...;
dest_size = bk_close(pevent, pdata);
pheader->data_size = *dest_size + sizeof(EVENT_HEADER);

For YBOS format, use the following example.

ybk_init(pevent);
ybk_create(pevent, "EBBK", I4_BKTYPE, &pdata);
pdata++ = 0x12345678;
pdata++ = 0x87654321;
dest_size = ybk_close(pevent, pdata);
dest_size *= 4;
pheader->data_size = *dest_size + sizeof(YBOS_BANK_HEADER);
Parameters
nfragNumber of fragment.
mismatchMidas Serial number mismatch flag.
ebchStructure to all the fragments.
pheaderDestination pointer to the header.
peventDestination pointer to the bank header.
dest_sizeDestination event size in bytes.
Returns
EB_SUCCESS

Definition at line 259 of file ebuser.cpp.

References compress_event(), EB_SUCCESS, EB_USER_ERROR, i, EBUILDER_CHANNEL::pfragment, and printf().

Referenced by source_scan().

261 {
262  if (mismatch){
263  printf("Serial number do not match across fragments\n");
264  for (int i = 0; i < nfrag; i++) {
265  int serial = ((EVENT_HEADER *) ebch[i].pfragment)->serial_number;
266  printf("Ser[%i]:%d ", i + 1, serial);
267  }
268  printf("\n");
269  return EB_USER_ERROR;
270  }
271 
272  // Initialize output event
273  bk_init32(pevent);
274 
275  // Loop over the event fragments, performing compression into the output event
276  for(int i = 0; i < nfrag; i++) {
277  void *fragment = ebch[i].pfragment;
278 
279  if(fragment != NULL) {
280  compress_event(((EVENT_HEADER *) fragment) + 1, pevent);
281  pheader->serial_number =
282  ((EVENT_HEADER *) ebch[i].pfragment)->serial_number;
283  }
284  }
285 
286  // Set the size of the output event properly
287  pheader->data_size = *dest_size = bk_size(pevent);
288 
289  // printf("Returning size %d\n", pheader->data_size);
290 
291  return EB_SUCCESS;
292 
293 }
INT eb_yfragment_add ( char *  pdest,
char *  psrce,
INT *  size 
)
INT ebuilder_exit ( void  )

Definition at line 126 of file ebuser.cpp.

References EB_SUCCESS.

Referenced by main().

127 {
128  return EB_SUCCESS;
129 }
INT ebuilder_init ( void  )

Definition at line 120 of file ebuser.cpp.

References EB_SUCCESS.

Referenced by main().

121 {
122  return EB_SUCCESS;
123 }
INT ebuilder_loop ( void  )

Definition at line 132 of file ebuser.cpp.

References EB_SUCCESS.

133 {
134  return EB_SUCCESS;
135 }
void free_event_buffer ( INT  nfrag)

Definition at line 701 of file new_mevb.cpp.

References i, and EBUILDER_CHANNEL::pfragment.

702 {
703  INT i;
704  for (i = 0; i < nfrag; i++) {
705  if (ebch[i].pfragment) {
706  free(ebch[i].pfragment);
707  ebch[i].pfragment = NULL;
708  }
709  }
710 }
INT handFlush ( void  )
INT load_fragment ( void  )
int main ( unsigned int  argc,
char **  argv 
)

Definition at line 1067 of file new_mevb.cpp.

References buffer_name, cm_get_environment(), debug, EB_SUCCESS, ebuilder_exit(), ebuilder_init(), expt_name, FALSE, free_event_buffer(), frontend_name, full_frontend_name, hDB, hKey, host_name, i, load_fragment(), EBUILDER_SETTINGS::nfragment, printf(), register_equipment(), scan_fragment(), source_unbooking(), status, SUCCESS, tr_start(), tr_stop, TRUE, usage(), and wheel.

1068 {
1069  INT status;
1070  unsigned int i;
1071  BOOL daemon = FALSE;
1072 
1073  /* init structure */
1074  memset(&ebch[0], 0, sizeof(ebch));
1075 
1076  /* set default */
1078 
1079  /* get parameters */
1080  for (i = 1; i < argc; i++) {
1081  if (argv[i][0] == '-' && argv[i][1] == 'd')
1082  debug = TRUE;
1083  else if (argv[i][0] == '-' && argv[i][1] == 'D')
1084  daemon = TRUE;
1085  else if (argv[i][0] == '-' && argv[i][1] == 'w')
1086  wheel = TRUE;
1087  else if (argv[i][0] == '-') {
1088  if (i + 1 >= argc || argv[i + 1][0] == '-')
1089  goto usage;
1090  if (strncmp(argv[i], "-e", 2) == 0)
1091  strcpy(expt_name, argv[++i]);
1092  else if (strncmp(argv[i], "-h", 2) == 0)
1093  strcpy(host_name, argv[++i]);
1094  else if (strncmp(argv[i], "-b", 2) == 0)
1095  strcpy(buffer_name, argv[++i]);
1096  } else {
1097 usage:
1098  printf("usage: mevb [-h <Hostname>] [-e <Experiment>] -b <buffername> [-d debug]\n");
1099  printf(" -w show wheel -D to start as a daemon\n\n");
1100  return 0;
1101  }
1102  }
1103 
1104  printf("Program mevb version 5 started\n\n");
1105  if (daemon) {
1106  printf("Becoming a daemon...\n");
1107  ss_daemon_init(FALSE);
1108  }
1109 
1110  /* Check buffer arg */
1111  if (buffer_name[0] == 0) {
1112  printf("Buffer name must be specified with -b argument\n");
1113  goto exit;
1114  }
1115 
1116  /* Compose frontend name */
1118 
1119  /* Connect to experiment */
1120  status = cm_connect_experiment(host_name, expt_name, full_frontend_name, NULL);
1121  if (status != CM_SUCCESS) {
1122  ss_sleep(5000);
1123  goto exit;
1124  }
1125 
1126  if (debug)
1127  cm_set_watchdog_params(TRUE, 0);
1128 
1129  /* Connect to ODB */
1130  status = cm_get_experiment_database(&hDB, &hKey);
1131  if (status != EB_SUCCESS) {
1132  ss_sleep(5000);
1133  goto exit;
1134  }
1135 
1136  /* check if Ebuilder is already running */
1137  status = cm_exist(full_frontend_name, TRUE);
1138  if (status == CM_SUCCESS) {
1139  cm_msg(MERROR, "Ebuilder", "%s running already!.", full_frontend_name);
1140  cm_disconnect_experiment();
1141  goto exit;
1142  }
1143 
1144  if (ebuilder_init() != SUCCESS) {
1145  cm_disconnect_experiment();
1146  /* let user read message before window might close */
1147  ss_sleep(5000);
1148  goto exit;
1149  }
1150 
1151  /* Register single equipment */
1152  status = register_equipment();
1153  if (status != EB_SUCCESS) {
1154  ss_sleep(5000);
1155  goto exit;
1156  }
1157 
1158  /* Load Fragment info */
1159  status = load_fragment();
1160  if (status != EB_SUCCESS) {
1161  ss_sleep(5000);
1162  goto exit;
1163  }
1164 
1165  /* Register transition for reset counters */
1166  if (cm_register_transition(TR_START, tr_start, 300) != CM_SUCCESS)
1167  return status;
1168  if (cm_register_transition(TR_STOP, tr_stop, 700) != CM_SUCCESS)
1169  goto exit;
1170 
1171  /* Scan fragments... will stay in */
1172  status = scan_fragment();
1173  printf("%s-Out of scan_fragment\n", full_frontend_name);
1174 
1175  /* Detach all source from midas */
1176  printf("%s-Unbooking\n", full_frontend_name);
1177  source_unbooking();
1178 
1179  ebuilder_exit();
1180 
1181 exit:
1182  /* Free local memory */
1184 
1185  /* Clean disconnect from midas */
1186  cm_disconnect_experiment();
1187  return 0;
1188 }
INT register_equipment ( void  )

Definition at line 160 of file new_mevb.cpp.

References EB_SUCCESS, equipment, EQUIPMENT_COMMON_STR, EQUIPMENT_STATISTICS_STR, frontend_file_name, full_frontend_name, hDB, hKey, printf(), run_number, run_state, SERVER_CACHE_SIZE, size, sprintf(), status, SUCCESS, and TRUE.

161 {
162  INT index, size, status;
163  char str[256];
164  EQUIPMENT_INFO *eq_info;
165  EQUIPMENT_STATS *eq_stats;
166  HNDLE hKey;
167 
168  /* get current ODB run state */
169  size = sizeof(run_state);
170  run_state = STATE_STOPPED;
171  db_get_value(hDB, 0, "/Runinfo/State", &run_state, &size, TID_INT, TRUE);
172  size = sizeof(run_number);
173  run_number = 1;
174  status = db_get_value(hDB, 0, "/Runinfo/Run number", &run_number, &size, TID_INT, TRUE);
175  assert(status == SUCCESS);
176 
177  /* scan EQUIPMENT table from mevb.C */
178  for (index = 0; equipment[index].name[0]; index++) {
179  eq_info = &equipment[index].info;
180  eq_stats = &equipment[index].stats;
181 
182  if (eq_info->event_id == 0) {
183  printf("\nEvent ID 0 for %s not allowed\n", equipment[index].name);
184  cm_disconnect_experiment();
185  ss_sleep(5000);
186  exit(0);
187  }
188 
189  /* init status */
190  equipment[index].status = EB_SUCCESS;
191 
192  sprintf(str, "/Equipment/%s/Common", equipment[index].name);
193 
194  /* get last event limit from ODB */
195  if (eq_info->eq_type != EQ_SLOW) {
196  db_find_key(hDB, 0, str, &hKey);
197  size = sizeof(double);
198  if (hKey)
199  db_get_value(hDB, hKey, "Event limit", &eq_info->event_limit, &size,
200  TID_DOUBLE, TRUE);
201  }
202 
203  /* Create common subtree */
204  status = db_check_record(hDB, 0, str, EQUIPMENT_COMMON_STR, TRUE);
205  if (status != DB_SUCCESS) {
206  printf("Cannot check equipment record, status = %d\n", status);
207  ss_sleep(3000);
208  }
209  db_find_key(hDB, 0, str, &hKey);
210 
211  if (equal_ustring(eq_info->format, "YBOS"))
212  equipment[index].format = FORMAT_YBOS;
213  else if (equal_ustring(eq_info->format, "FIXED"))
214  equipment[index].format = FORMAT_FIXED;
215  else /* default format is MIDAS */
216  equipment[index].format = FORMAT_MIDAS;
217 
218  gethostname(eq_info->frontend_host, sizeof(eq_info->frontend_host));
219  strcpy(eq_info->frontend_name, full_frontend_name);
220  strcpy(eq_info->frontend_file_name, frontend_file_name);
221 
222  /* set record from equipment[] table in frontend.c */
223  db_set_record(hDB, hKey, eq_info, sizeof(EQUIPMENT_INFO), 0);
224 
225  /* get record once at the start equipment info */
226  size = sizeof(EQUIPMENT_INFO);
227  db_get_record(hDB, hKey, eq_info, &size, 0);
228 
229  /*---- Create just the key , leave it empty ---------------------------------*/
230  sprintf(str, "/Equipment/%s/Variables", equipment[index].name);
231  db_create_key(hDB, 0, str, TID_KEY);
232  db_find_key(hDB, 0, str, &hKey);
233  equipment[index].hkey_variables = hKey;
234 
235  /*---- Create and initialize statistics tree -------------------*/
236  sprintf(str, "/Equipment/%s/Statistics", equipment[index].name);
237 
238  status = db_check_record(hDB, 0, str, EQUIPMENT_STATISTICS_STR, TRUE);
239  if (status != DB_SUCCESS) {
240  printf("Cannot create/check statistics record, error %d\n", status);
241  ss_sleep(3000);
242  }
243 
244  status = db_find_key(hDB, 0, str, &hKey);
245  if (status != DB_SUCCESS) {
246  printf("Cannot find statistics record, error %d\n", status);
247  ss_sleep(3000);
248  }
249 
250  eq_stats->events_sent = 0;
251  eq_stats->events_per_sec = 0;
252  eq_stats->kbytes_per_sec = 0;
253 
254  /* open hot link to statistics tree */
255  status = db_open_record(hDB, hKey, eq_stats, sizeof(EQUIPMENT_STATS)
256  , MODE_WRITE, NULL, NULL);
257  if (status != DB_SUCCESS) {
258  cm_msg(MERROR, "register_equipment",
259  "Cannot open statistics record, error %d. Probably other FE is using it",
260  status);
261  ss_sleep(3000);
262  }
263 
264  /*---- open event buffer ---------------------------------------*/
265  if (eq_info->buffer[0]) {
266  status = bm_open_buffer(eq_info->buffer, EVENT_BUFFER_SIZE,
267  &equipment[index].buffer_handle);
268  if (status != BM_SUCCESS && status != BM_CREATED) {
269  cm_msg(MERROR, "register_equipment",
270  "Cannot open event buffer. Try to reduce EVENT_BUFFER_SIZE in midas.h \
271  and rebuild the system.");
272  return 0;
273  }
274 
275  /* set the default buffer cache size */
276  bm_set_cache_size(equipment[index].buffer_handle, 0, SERVER_CACHE_SIZE);
277  } else {
278  cm_msg(MERROR, "register_equipment", "Destination buffer must be present");
279  ss_sleep(3000);
280  exit(0);
281  }
282  }
283  return SUCCESS;
284 }
INT scan_fragment ( void  )
INT source_booking ( void  )
INT source_scan ( INT  fmt,
EQUIPMENT_INFO *  eq_info 
)

Scan all the fragment source once per call.

  1. This will retrieve the full midas event not swapped (except the MIDAS_HEADER) for each fragment if possible. The fragment will be stored in the channel event pointer.
  2. if after a full nfrag path some frag are still not cellected, it returns with the frag# missing for timeout check.
  3. If ALL fragments are present it will check the midas serial# for a full match across all the fragments.
  4. If the serial check fails it returns with "event mismatch" and will abort the event builder but not stop the run for now.
  5. If the serial check is passed, it will call the user_build function where the destination event is going to be composed.
Parameters
fmtFragment format type
eq_infoEquipement pointer
dest_hBufDestination buffer handle
Returns
EB_NO_MORE_EVENT, EB_COMPOSE_TIMEOUT if different then SUCCESS (bm_compose, rpc_sent error)
INT source_unbooking ( void  )
INT tr_start ( INT  rn,
char *  error 
)

Definition at line 588 of file new_mevb.cpp.

References abort_requested, eb_begin_of_run(), EB_SUCCESS, EBUILDER, equipment, FALSE, full_frontend_name, hDB, hKey, i, key, EBUILDER_SETTINGS::nfragment, nfragment, EBUILDER_SETTINGS::preqfrag, printf(), EBUILDER_SETTINGS::received, run_number, run_state, size, source_booking(), sprintf(), status, stop_requested, SUCCESS, TRUE, EBUILDER_SETTINGS::user_build, and EBUILDER_SETTINGS::user_field.

589 {
590  EBUILDER(ebuilder_str);
591  INT status, size, i;
592  char str[128];
593  KEY key;
594  HNDLE hKey, hEqkey, hEqFRkey;
595  EQUIPMENT_INFO *eq_info;
596 
597 
598  eq_info = &equipment[0].info;
599 
600  /* Get update eq_info from ODB */
601  sprintf(str, "/Equipment/%s/Common", equipment[0].name);
602  status = db_find_key(hDB, 0, str, &hKey);
603  size = sizeof(EQUIPMENT_INFO);
604  db_get_record(hDB, hKey, eq_info, &size, 0);
605 
607 
608  /* reset serial numbers */
609  for (i = 0; equipment[i].name[0]; i++) {
610  equipment[i].serial_number = 1;
611  equipment[i].subevent_number = 0;
612  equipment[i].stats.events_sent = 0;
613  equipment[i].odb_in = equipment[i].odb_out = 0;
614  }
615 
616  /* Get / Set Settings */
617  sprintf(str, "/Equipment/%s/Settings", equipment[0].name);
618  if (db_find_key(hDB, 0, str, &hEqkey) != DB_SUCCESS) {
619  status = db_create_record(hDB, 0, str, strcomb(ebuilder_str));
620  }
621 
622  /* Keep Key on Ebuilder/Settings */
623  sprintf(str, "/Equipment/%s/Settings", equipment[0].name);
624  if (db_find_key(hDB, 0, str, &hEqkey) != DB_SUCCESS) {
625  cm_msg(MINFO, "load_fragment", "/Equipment/%s/Settings not found", equipment[0].name);
626  }
627 
628  /* Update or Create User_field */
629  size = sizeof(ebset.user_field);
630  status = db_get_value(hDB, hEqkey, "User Field", ebset.user_field, &size, TID_STRING, TRUE);
631 
632  /* Update or Create User_Build */
633  size = sizeof(ebset.user_build);
634  status = db_get_value(hDB, hEqkey, "User Build", &ebset.user_build, &size, TID_BOOL, TRUE);
635 
636  /* update ODB */
637  size = sizeof(INT);
638  status = db_set_value(hDB, hEqkey, "Number of Fragment", &ebset.nfragment, size, 1, TID_INT);
639 
640  /* Create or update the fragment request list */
641  status = db_find_key(hDB, hEqkey, "Fragment Required", &hEqFRkey);
642  status = db_get_key (hDB, hEqFRkey, &key);
643  if (key.num_values != ebset.nfragment) {
644  cm_msg(MINFO, "mevb", "Number of Fragment mismatch ODB:%d - CUR:%d", key.num_values, ebset.nfragment);
645  free (ebset.preqfrag);
646  size = ebset.nfragment*sizeof(BOOL);
647  ebset.preqfrag = malloc(size);
648  for (i=0 ; i<ebset.nfragment ; i++)
649  ebset.preqfrag[i] = TRUE;
650  status = db_set_value(hDB, hEqkey, "Fragment Required", ebset.preqfrag, size, ebset.nfragment, TID_BOOL);
651  } else { // Take from ODBedit
652  size = key.total_size;
653  free (ebset.preqfrag);
654  ebset.preqfrag = malloc(size);
655  status = db_get_data(hDB, hEqkey, ebset.preqfrag, &size, TID_BOOL);
656  }
657  /* Cleanup fragment flags */
658  free (ebset.received);
659  ebset.received = malloc(size);
660  for (i=0 ; i < ebset.nfragment ; i++)
661  ebset.received[i] = FALSE;
662 
663  /* Call BOR user function */
664  status = eb_begin_of_run(run_number, ebset.user_field, error);
665  if (status != EB_SUCCESS) {
666  cm_msg(MERROR, "eb_prestart", "run start aborted due to eb_begin_of_run (%d)",
667  status);
668  return status;
669  }
670 
671  /* Book all fragment */
672  status = source_booking();
673  if (status != SUCCESS)
674  return status;
675 
676  /* local run state */
677  run_state = STATE_RUNNING;
678  run_number = rn;
681  printf("%s-Starting New Run: %d\n", full_frontend_name, rn);
682 
683  /* Reset global trigger mask */
684  return CM_SUCCESS;
685 }
INT tr_stop ( INT  rn,
char *  error 
)

Definition at line 688 of file new_mevb.cpp.

References full_frontend_name, printf(), request_stop_time, stop_requested, and TRUE.

689 {
690  printf("\n%s-Stopping Run: %d detected\n", full_frontend_name, rn);
691 
692  /* local stop */
694 
695  /* local stop time */
696  request_stop_time = ss_millitime();
697  return CM_SUCCESS;
698 }
INT ybos_event_swap ( DWORD pevt)

Variable Documentation

BOOL abort_requested = FALSE

Definition at line 101 of file new_mevb.cpp.

DWORD actual_millitime

Definition at line 87 of file new_mevb.cpp.

DWORD actual_time

Definition at line 86 of file new_mevb.cpp.

char bars[] = "|\\-/"

Definition at line 99 of file new_mevb.cpp.

char buffer_name[NAME_LENGTH]

Definition at line 92 of file new_mevb.cpp.

BOOL debug = FALSE

Definition at line 96 of file new_mevb.cpp.

BOOL debug1 = FALSE

Definition at line 96 of file new_mevb.cpp.

char* dest_event

Definition at line 94 of file new_mevb.cpp.

INT display_period

Definition at line 81 of file new_mevb.cpp.

Definition at line 80 of file new_mevb.cpp.

EQUIPMENT equipment[]
INT event_buffer_size

Definition at line 53 of file crate.cpp.

Referenced by main().

char expt_name[NAME_LENGTH]

Definition at line 90 of file new_mevb.cpp.

BOOL frontend_call_loop

Definition at line 39 of file crate.cpp.

Referenced by scheduler().

char* frontend_file_name

Definition at line 36 of file crate.cpp.

Referenced by register_equipment().

char* frontend_name
char full_frontend_name[256]

Definition at line 91 of file new_mevb.cpp.

HNDLE hDB

Definition at line 95 of file new_mevb.cpp.

HNDLE hEqKey

Definition at line 95 of file new_mevb.cpp.

HNDLE hESetKey

Definition at line 95 of file new_mevb.cpp.

HNDLE hKey

Definition at line 95 of file new_mevb.cpp.

char host_name[HOST_NAME_LENGTH]

Definition at line 89 of file new_mevb.cpp.

HNDLE hStatKey

Definition at line 95 of file new_mevb.cpp.

HNDLE hSubkey

Definition at line 95 of file new_mevb.cpp.

int i_bar

Definition at line 100 of file new_mevb.cpp.

DWORD last_time

Definition at line 85 of file new_mevb.cpp.

INT max_event_size
INT max_event_size_frag

Definition at line 50 of file crate.cpp.

Referenced by main(), and send_event().

INT(* meb_fragment_add)(char *, char *, INT *)

Definition at line 104 of file new_mevb.cpp.

INT nfragment

Definition at line 93 of file new_mevb.cpp.

DWORD request_stop_time = 0

Definition at line 102 of file new_mevb.cpp.

INT run_number

Definition at line 84 of file new_mevb.cpp.

INT run_state

PROGRAM: crate.cpp DESCRIPTION: Control and readout of CAEN V1724 digitizers. author: V.Tishchenko date: 12-Aug-2012

Modifications:

Definition at line 83 of file new_mevb.cpp.

BOOL stop_requested = TRUE

Definition at line 101 of file new_mevb.cpp.

DWORD stop_time = 0

Definition at line 102 of file new_mevb.cpp.

BOOL wheel = FALSE

Definition at line 98 of file new_mevb.cpp.