AlcapDAQ  1
Data Structures | Typedefs | Functions | Variables
frontend.c File Reference
#include <stdio.h>
#include "midas.h"

Go to the source code of this file.

Data Structures

struct  SEPARATOR_DATA_Struct
 

Typedefs

typedef struct
SEPARATOR_DATA_Struct 
SEPARATOR_DATA
 

Functions

INT read_separator_event (char *pevent, INT off)
 
INT pre_begin_of_run ()
 
INT frontend_early_init ()
 
INT poll_event (INT source[], INT count, BOOL test)
 
INT interrupt_configure (INT cmd, INT source[], PTYPE adr)
 
INT frontend_init ()
 
INT frontend_exit ()
 
INT frontend_loop ()
 
INT begin_of_run (INT run_number, char *error)
 
INT end_of_run (INT run_number, char *error)
 
INT pause_run (INT run_number, char *error)
 
INT resume_run (INT run_number, char *error)
 

Variables

INT crate_number =0
 
HNDLE hDB
 
HNDLE hKey
 
int size
 
int sepDemand
 
char Alarm [128] = "/Equipment/SeparatorMonitor/Variables/Alarm_Triggered"
 
char * frontend_name = "SeparatorMonitor"
 
char * frontend_file_name = __FILE__
 
BOOL frontend_call_loop = TRUE
 
INT display_period = 1000
 
INT max_event_size = 10000
 
INT max_event_size_frag = 5 * 1024 * 1024
 
INT event_buffer_size = 10 * 10000
 
BANK_LIST separator_bank_list []
 
EQUIPMENT equipment []
 

Typedef Documentation

Function Documentation

INT begin_of_run ( INT  run_number,
char *  error 
)

Definition at line 198 of file frontend.c.

199 {
200  return CM_SUCCESS;
201 }
INT end_of_run ( INT  run_number,
char *  error 
)

Definition at line 205 of file frontend.c.

206 {
207  return CM_SUCCESS;
208 }
INT frontend_early_init ( void  )

Definition at line 145 of file crate.cpp.

146 {
147  // Determine our crate ID by comparing against a list of hostnames
148  printf("Entering frontend_early_init ... \n");
149  //char *hostnames[] = {"fe1", "fe2", "fe3", "turtle", "fe5", "fe6"};
150  //char *hostnames[] = {"fe1", "fe2", "daq2.MuSIC", "fe4", "fe5", "fe6", "fe7"};
151  //int crate_numbers[] = {1, 2, 3, 4, 5, 6, 9};
152  //char *hostnames[] = {"daq2.MuSIC"};
153  //int crate_numbers[] = {3};
154  //BOOL crate_has_periodic[] = {FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE};
155 
156  //int num_hostnames = sizeof(hostnames)/sizeof(char *);
157 
158  //char my_hostname[256];
159 
160  //gethostname(my_hostname, sizeof(my_hostname));
161 
162 #if 0
163  BOOL has_periodic = FALSE;
164  for(int i = 0; i < num_hostnames; i++) {
165  if(!strcmp(my_hostname, hostnames[i])) {
166  crate_number = crate_numbers[i];
167  has_periodic = crate_has_periodic[i];
168  }
169  }
170 #endif
171 
172  crate_number = 3;
173  BOOL has_periodic = FALSE;
174 
175  printf("Hostname and crate cumber defined, crate number = %d ... \n",crate_number);
176 
177  if(crate_number > 0) {
178  frontend_name = new char[32];
179  strcpy(frontend_name, "Crate ");
180 
181 
182 #if 0
183  sprintf(equipment[0].name, "Crate %d", crate_number);
184  sprintf(equipment[0].info.buffer, "BUF%d", crate_number);
185  equipment[0].info.event_id = 1000 + crate_number;
186 #endif
188 
189  printf("Crate number = %d\n",crate_number);
190 
191  if(has_periodic) {
192  sprintf(equipment[1].name, "Periodic %d", crate_number);
193  equipment[1].info.event_id = 2000 + crate_number;
194  } else {
195  sprintf(equipment[1].name, "");
196  }
197  }
198  printf("Frontend early init returns success \n");
199  return SUCCESS;
200 }
INT frontend_exit ( void  )

Definition at line 183 of file frontend.c.

184 {
185  return CM_SUCCESS;
186 }
INT frontend_init ( void  )

Definition at line 168 of file frontend.c.

References Alarm, hDB, hKey, and SUCCESS.

169 {
170 
171  // get the LabView filename
172  cm_get_experiment_database(&hDB, NULL);
173 
174  if(db_find_key(hDB, 0, Alarm, &hKey) != SUCCESS){
175  db_create_key(hDB,0,Alarm,TID_INT);
176  }
177 
178  return CM_SUCCESS;
179 }
INT frontend_loop ( void  )

Definition at line 190 of file frontend.c.

191 {
192  ss_sleep(100);
193  return CM_SUCCESS;
194 }
INT interrupt_configure ( INT  cmd,
INT  source[],
PTYPE  adr 
)

Definition at line 161 of file frontend.c.

162 {
163  return 1;
164 };
INT pause_run ( INT  run_number,
char *  error 
)

Definition at line 212 of file frontend.c.

213 {
214  return CM_SUCCESS;
215 }
INT poll_event ( INT  source[],
INT  count,
BOOL  test 
)

Definition at line 157 of file frontend.c.

158 {
159  return 1;
160 };
INT pre_begin_of_run ( )
INT read_separator_event ( char *  pevent,
INT  off 
)

Definition at line 226 of file frontend.c.

References Alarm, SEPARATOR_DATA_Struct::current, frontend_name, hDB, SEPARATOR_DATA_Struct::hv, i, printf(), SEPARATOR_DATA_Struct::sep_stat, sepDemand, size, and SEPARATOR_DATA_Struct::vac.

226  {
227  static SEPARATOR_DATA separator_data;
228 
229  static char oldtimestamp[80];
230  char timestamp[80];
231  char timestring[80];
232  FILE *infile=NULL;
233  float *pdata;
234  static float lastHVs[4] = {-1., -1., -1., -1.};
235  static int initDone = 0;
236  int i;
237 
238  size = sizeof(sepDemand);
239  db_get_value(hDB,0, "/Experiment/Edit on start/Separator HV",
240  &sepDemand, &size, TID_INT, 1);
241 
242  timestamp[0]='\0';
243 
244  infile=fopen("/tmp/separator.txt","r");
245  if (infile==NULL){
246  cm_msg(MERROR,frontend_name,
247  "Could not open tempfile. separator_daemon.pl not running?");
248  separator_data.hv =-1;
249  separator_data.vac =-1;
250  separator_data.sep_stat =-1;
251  }
252  else{
253  fscanf(infile,"%s\n%f\n%f\n%f\n%f",timestamp,&separator_data.hv,
254  &separator_data.current,&separator_data.vac,
255  &separator_data.sep_stat);
256  fclose(infile);
257 
258  if(!strcmp(oldtimestamp, timestamp)){
259  separator_data.hv=-1;
260  separator_data.vac=-1;
261  separator_data.sep_stat=-1;
262  }
263  }
264 
265  if(initDone == 0){
266  for(i=0; i<4; i++) lastHVs[i] = separator_data.hv;
267  initDone = 1;
268  }
269  else{
270  for(i=0; i<3; i++) lastHVs[i] = lastHVs[i+1];
271  lastHVs[3] = separator_data.hv;
272  }
273 
274  //for(i=0; i<4; i++) printf("HV[%d]=%d\n",i,(int)lastHVs[i]);
275  //printf("Demand = %d\n", sepDemand);
276 
277  //Send to midas:
278  bk_init(pevent);
279  bk_create(pevent,"SEPA",TID_FLOAT,&pdata);
280  pdata[0] = separator_data.hv;
281  pdata[1] = separator_data.current;
282  pdata[2] = separator_data.vac;
283  pdata[3] = separator_data.sep_stat;
284  bk_close(pevent,pdata+4);
285 
286  int sepError = 1;
287 
288  for(i=0; i<4; i++){
289  if((int)lastHVs[i] == sepDemand) sepError = 0;
290  }
291 
292  if(sepError==1){
293  if(strcmp(oldtimestamp, timestamp)){
294  cm_msg(MERROR,frontend_name,"Separator high voltage not same as demand!");
295  printf("Demand = %d", sepDemand);
296  }
297  else{
298  cm_msg(MERROR,frontend_name,"Old and new timestamps identical."
299  " Refresh too high or separator_daemon.pl not running.");
300  }
301  int on = 1;
302  db_set_value(hDB, 0, Alarm, &on, sizeof(on), 1, TID_INT);
303  }
304  else{
305  int off = 0;
306  db_set_value(hDB, 0, Alarm, &off, sizeof(off), 1, TID_INT);
307  }
308 
309  strcpy(oldtimestamp,timestamp);
310 
311  return bk_size(pevent);
312 }
INT resume_run ( INT  run_number,
char *  error 
)

Definition at line 219 of file frontend.c.

220 {
221  return CM_SUCCESS;
222 }

Variable Documentation

char Alarm[128] = "/Equipment/SeparatorMonitor/Variables/Alarm_Triggered"

Definition at line 74 of file frontend.c.

Referenced by frontend_init(), and read_separator_event().

INT crate_number =0

Definition at line 68 of file frontend.c.

INT display_period = 1000

Definition at line 91 of file frontend.c.

EQUIPMENT equipment[]
Initial value:
= {
{"SeparatorMonitor",
{ 22, 0,
"SYSTEM",
EQ_PERIODIC,
0,
"MIDAS",
TRUE,
RO_ALWAYS|RO_ODB,
50000,
0,
0,
0,
"", "", "", },
NULL, NULL,
},
{""}
}

Definition at line 118 of file frontend.c.

INT event_buffer_size = 10 * 10000

Definition at line 100 of file frontend.c.

BOOL frontend_call_loop = TRUE

Definition at line 88 of file frontend.c.

char* frontend_file_name = __FILE__

Definition at line 85 of file frontend.c.

char* frontend_name = "SeparatorMonitor"

Definition at line 83 of file frontend.c.

HNDLE hDB

Definition at line 70 of file frontend.c.

HNDLE hKey

Definition at line 71 of file frontend.c.

INT max_event_size = 10000

Definition at line 94 of file frontend.c.

INT max_event_size_frag = 5 * 1024 * 1024

Definition at line 97 of file frontend.c.

BANK_LIST separator_bank_list[]
Initial value:
= {
{ "SEPA", TID_FLOAT, 4, NULL },
{ "" },
}

Definition at line 104 of file frontend.c.

int sepDemand

Definition at line 73 of file frontend.c.

Referenced by read_separator_event().

int size

Definition at line 72 of file frontend.c.

Referenced by allocate_dma_buffer(), caen_load(), caenV767_fifo_read(), caenV767_poll1(), cnaf_callback(), comp_load(), directio_give_port(), directio_lock_port(), dl40x_read(), dma_read(), dma_write(), eb_begin_of_run(), eb_mfragment_add(), eb_yfragment_add(), epics_ca_get(), fadc_load(), TOctalFADCIsland::FitGauss(), G__DataLibraryDict_412_0_7(), G__DataLibraryDict_417_0_11(), G__DataLibraryDict_507_0_11(), G__DataLibraryDict_518_0_7(), G__DataLibraryDict_523_0_11(), G__DataLibraryDict_528_0_7(), G__DataLibraryDict_532_0_7(), G__DataLibraryDict_533_0_11(), G__DataLibraryDict_537_0_11(), G__RootanaDataClasses_432_0_7(), G__RootanaDataClasses_446_0_11(), G__RootanaDataClasses_591_0_7(), G__RootanaDataClasses_597_0_11(), G__RootanaDataClasses_606_0_11(), ge_ln2_read(), handFlush(), hits_load(), load_fragment(), load_huffman(), logger_root(), main(), MCaenCompProcessRaw_init(), MDQ_DAQLivetime_eor(), MDQ_DigitizerOverflow_init(), MDQ_FADCBufferOverflow_init(), MDQ_FADCPacketLoss_init(), MDQ_IslandRate_eor(), MDQ_RunTime_eor(), MDQ_TDCCheck_eor(), MDQ_Thresholds_eor(), MMuSCAnalysisC_init(), module_init(), module_init_sort_and_stitch(), n2fadc_ndet_load(), n2fadc_tpc_load(), newSegment(), nfadc_load(), odb_get_bool(), odb_get_boolarray(), odb_get_dword(), odb_get_int(), odb_get_word(), pci_scan(), pio_read(), pio_write(), print_diag_output(), process_event(), SimpleHistograms::ProcessEntry(), read_separator_event(), register_equipment(), save_huffman(), SaveDigitalProbe(), SaveWaveform(), scheduler(), send_event(), sis3600_fifo_read(), sis3600_poll1(), source_scan(), stck_load(), tdc400_load(), tr_prestart(), tr_start(), WireMap::UniqueFixes(), update_odb(), UpdateDetectorBankNameMap(), vme_dma_read(), vme_dma_write(), vmedrv_mmap(), and X742_DecodeEvent().