void scfe_error(const char *error) { char str[256]; printf("why dis\n"); strlcpy(str, error, sizeof(str)); cm_msg(MERROR, "scfe_error", str); al_trigger_alarm("MSCB", str, "MSCB Alarm", "Communication Problem", AT_INTERNAL); }
INT master_ODB_init(void) { INT ret = SUCCESS; INT status; char str[MAX_ODB_PATH]; // char str_aux[MAX_ODB_PATH]; HNDLE hKey; sprintf(master_settings_odb.trigger_source, "Fake"); //Default to self-generated fake trigger signals master_settings_odb.rate = 12; sprintf(master_settings_odb.readout_name, "AMC13"); sprintf(master_settings_odb.sim_name, "CaloSimulatorAMC13"); dbprintf(str,"/Equipment/MasterGM2/Settings/Globals"); sprintf(str,"/Equipment/MasterGM2/Settings/Globals"); // create ODB structure if it doesn't exist status = db_check_record(hDB, 0, str, MASTER_SETTINGS_ODB_STR, TRUE); if( status != DB_SUCCESS ) { cm_msg(MERROR, __FILE__, "Cannot create [%s] entry in ODB, err = %i\n",str,status); return FE_ERR_ODB; } // returns key handle "hDB" to ODB name "str" for fast access status = db_find_key(hDB, 0, str, &hKey); if ( status != DB_SUCCESS ) { cm_msg(MERROR, __FILE__, "Cannot find [%s] key in ODB, err = %i",str,status); return FE_ERR_ODB; } // creates hotlink of ODB subtree to structure master_settings_odb that's automatically updated if (db_open_record(hDB, hKey, &master_settings_odb, sizeof(MASTER_SETTINGS_ODB), MODE_READ, master_ODB_update, NULL) != DB_SUCCESS) { cm_msg(MERROR, __FILE__, "Cannot open [%s] settings in ODB",str); return FE_ERR_ODB; } print(str); return ret; }
/*------------------------------------------------------------------*/ INT md_file_wopen(INT type, INT data_fmt, char *filename, INT * hDev) /******************************************************************** Routine: external md_file_wopen Purpose: Open a data file for the given data format Input: INT type : Tape or Disk INT data_fmt : YBOS or MIDAS char * filename : file to open Output: INT * hDev : file handle Function value: status : from lower function *******************************************************************/ { INT status = 0; if (type == LOG_TYPE_DISK) /* takes care of TapeLX/NT under ss_tape_open , DiskLX/NT here */ { if (data_fmt == FORMAT_YBOS) { assert(!"YBOS not supported anymore"); } else if (data_fmt == FORMAT_MIDAS) { #ifdef OS_WINNT *hDev = (int) CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH | FILE_FLAG_SEQUENTIAL_SCAN, 0); #else *hDev = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE, 0644); #endif status = *hDev < 0 ? SS_FILE_ERROR : SS_SUCCESS; } } else if (type == LOG_TYPE_TAPE) { if (data_fmt == FORMAT_YBOS) { assert(!"YBOS not supported anymore"); } else if (data_fmt == FORMAT_MIDAS) status = ss_tape_open(filename, O_WRONLY | O_CREAT | O_TRUNC, hDev); } else if (type == LOG_TYPE_FTP) { #ifdef HAVE_FTPLIB status = mftp_open(filename, (FTP_CON **) & ftp_con); if (status != SS_SUCCESS) { *hDev = 0; return status; } else *hDev = 1; #else cm_msg(MERROR, "mdsupport", "FTP support not included"); return SS_FILE_ERROR; #endif } return status; }
void mscb_define(char *submaster, char *equipment, char *devname, DEVICE_DRIVER *driver, int address, unsigned char var_index, char *name, double threshold) { int i, dev_index, chn_index, chn_total; char str[256]; float f_threshold; HNDLE hDB; cm_get_experiment_database(&hDB, NULL); //printf(hDB+"\n"); if (submaster && submaster[0]) { sprintf(str, "/Equipment/%s/Settings/Devices/%s/Device", equipment, devname); db_set_value(hDB, 0, str, submaster, 32, 1, TID_STRING); sprintf(str, "/Equipment/%s/Settings/Devices/%s/Pwd", equipment, devname); db_set_value(hDB, 0, str, "mscb174", 32, 1, TID_STRING); } /* find device in device driver */ for (dev_index=0 ; driver[dev_index].name[0] ; dev_index++) if (equal_ustring(driver[dev_index].name, devname)) break; if (!driver[dev_index].name[0]) { cm_msg(MERROR, "Device \"%s\" not present in device driver list", devname); return; } /* count total number of channels */ for (i=chn_total=0 ; i<=dev_index ; i++) chn_total += driver[i].channels; chn_index = driver[dev_index].channels; sprintf(str, "/Equipment/%s/Settings/Devices/%s/MSCB Address", equipment, devname); db_set_value_index(hDB, 0, str, &address, sizeof(int), chn_index, TID_INT, TRUE); sprintf(str, "/Equipment/%s/Settings/Devices/%s/MSCB Index", equipment, devname); db_set_value_index(hDB, 0, str, &var_index, sizeof(char), chn_index, TID_BYTE, TRUE); if (threshold != -1) { sprintf(str, "/Equipment/%s/Settings/Update Threshold", equipment); f_threshold = (float) threshold; db_set_value_index(hDB, 0, str, &f_threshold, sizeof(float), chn_total, TID_FLOAT, TRUE); } if (name && name[0]) { sprintf(str, "/Equipment/%s/Settings/Names Input", equipment); db_set_value_index(hDB, 0, str, name, 32, chn_total, TID_STRING, TRUE); } /* increment number of channels for this driver */ driver[dev_index].channels++; }
/*-- 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; }
int fb_frc(int paddr, int saddr, DWORD * data) /* read control space */ { int status; SFI_OUT(SFI_WRITE_VME2SEQ_FIFO_BASE + PRIM_CSR, paddr); status = SFI_IN(SFI_SEQUENCER_STATUS_REGISTER); if (status & 0x20) cm_msg(MERROR, "fb_frc", "Arbitration error on Primary Address Cycle"); SFI_OUT(SFI_WRITE_VME2SEQ_FIFO_BASE + SECAD_W, saddr); SFI_OUT(SFI_WRITE_VME2SEQ_FIFO_BASE + RNDM_R_DIS, 0); return fb_fifo_read(data); }
/* this dispatchers forwards RPC calls to the destination functions */ INT rpc_dispatch(INT index, void *prpc_param[]) { INT status; switch (index) { case RPC_MYTEST: status = rpc_mytest(CBYTE(0), CWORD(1), CINT(2), CFLOAT(3), CDOUBLE(4), CPBYTE(5), CPWORD(6), CPINT(7), CPFLOAT(8), CPDOUBLE(9)); break; default: cm_msg(MERROR, "rpc_dispatch", "received unrecognized command"); } return status; }
int ps7106_set(int crate, int slot, double thresh_value) /********************************************************************\ Sets the threshold of a Phillips 7106 discriminator to the given <thresh_value> in millivolts. \********************************************************************/ { INT q; WORD data, threshold; // Convert threshold value to register value if (thresh_value > 1033) thresh_value = 1033; if (thresh_value < 10) thresh_value = 10; threshold = (unsigned int) (thresh_value - 10); /* Set remote mode */ camo(crate, slot, 0, SET_REMOTE_7106, 0); /* Verify Remote mode */ camc_q(crate, slot, 0, TEST_REMOTE_7106, &q); if (!q) { cm_msg(MERROR, "ps7106_set", "Error setting remote mode on crate %d, slot %d.\n", crate, slot); // printf("Error setting remote mode on crate %d, slot %d.\n", crate, slot); return -1; } /* unmask all channels */ camo(crate, slot, 0, 16, 0xFFFF); /* Write threshold */ camo(crate, slot, 0, WRITE_THRESH_7106, threshold); ss_sleep(10); /* Verify threshold */ cami(crate, slot, 0, READ_THRESH_7106, &data); data = data & 0x3FF; if (data != threshold) { cm_msg(MERROR, "ps7106_set", "Error setting threshold:\ requested %d (%4.0f mV), read %d", threshold, thresh_value, data); // printf("Error setting threshold:\ // requested %d (%4.0f mV), read %d", threshold, thresh_value, data); return -1; }
INT frontend_init() { /* hardware initialization */ INT status; char set_str[80]; /* Book Setting space */ TRIGGER_SETTINGS_STR(trigger_settings_str); /* Map /equipment/Trigger/settings for the sequencer */ sprintf(set_str, "/Equipment/Trigger/Settings"); status = db_create_record(hDB, 0, set_str, strcomb(trigger_settings_str)); status = db_find_key (hDB, 0, set_str, &hSet); if (status != DB_SUCCESS) cm_msg(MINFO,"FE","Key %s not found", set_str); rs232(CMD_INIT, hSet, &info); /* print message and return FE_ERR_HW if frontend should not be started */ return SUCCESS; }
/** Hook to the event builder task at PreStart transition. @param rn run number @param UserField argument from /Ebuilder/Settings @param error error string to be passed back to the system. @return EB_SUCCESS */ INT eb_begin_of_run(INT rn, char *UserField, char *error) { #if 0 extern EBUILDER_SETTINGS ebset; extern EBUILDER_CHANNEL ebch[MAX_CHANNELS]; extern HNDLE hDB; int n; int mask = 0; char keyName[256]; BOOL enabled; int size; /* * Determine which crates are enabled and set up the mask * accordingly. */ for(n = 1; n <= NUMCRATES; n++) { sprintf(keyName, "/Equipment/Crate %d/Settings/Enabled", n); size = sizeof(enabled); db_get_value(hDB, 0, keyName, &enabled, &size, TID_BOOL, FALSE); if(size == sizeof(enabled) && enabled) { ebch[n-1].trigger_mask = (1 << (n-1)); mask |= ebch[n-1].trigger_mask; } else { ebch[n-1].trigger_mask = 0; } } cm_msg(MINFO, "eb_begin_of_run", "Setting event mask to 0x%x", mask); ebset.trigger_mask = mask; #endif // Initialize online compression compress_load_all(); return EB_SUCCESS; }
/*------------------------------------------------------------------*/ INT md_file_ropen(char *infile, INT data_fmt, INT openzip) /********************************************************************\ Routine: external md_any_file_ropen Purpose: Open data file for replay for the given data format. It uses the local "my" structure. Input: INT data_fmt : YBOS or MIDAS char * infile : Data file name Output: none Function value: status : from lower function \********************************************************************/ { INT status; /* fill up record with file name */ strcpy(my.name, infile); /* find out what dev it is ? : check on /dev */ my.zipfile = FALSE; if ((strncmp(my.name, "/dev", 4) == 0) || (strncmp(my.name, "\\\\.\\", 4) == 0)) { /* tape device */ my.type = LOG_TYPE_TAPE; } else { /* disk device */ my.type = LOG_TYPE_DISK; if (strncmp(infile + strlen(infile) - 3, ".gz", 3) == 0) { // FALSE will for now prevent the mdump to see inside the .gz // But lazylogger will NOT unzip during copy! if (openzip == 0) my.zipfile = FALSE; // ignore zip, copy blindly blocks else my.zipfile = TRUE; // Open Zip file } } /* open file */ if (!my.zipfile) { if (my.type == LOG_TYPE_TAPE) { status = ss_tape_open(my.name, O_RDONLY | O_BINARY, &my.handle); } else if ((my.handle = open(my.name, O_RDONLY | O_BINARY | O_LARGEFILE, 0644)) == -1) { printf("dev name :%s Handle:%d \n", my.name, my.handle); return (SS_FILE_ERROR); } } else { #ifdef HAVE_ZLIB if (my.type == LOG_TYPE_TAPE) { printf(" Zip on tape not yet supported \n"); return (SS_FILE_ERROR); } filegz = gzopen(my.name, "rb"); my.handle = 0; if (filegz == NULL) { printf("dev name :%s gzopen error:%d \n", my.name, my.handle); return (SS_FILE_ERROR); } #else cm_msg(MERROR, "mdsupport", "Zlib not included ... gz file not supported"); return (SS_FILE_ERROR); #endif } if (data_fmt == FORMAT_YBOS) { assert(!"YBOS support not supported anymore"); } else if (data_fmt == FORMAT_MIDAS) { my.fmt = FORMAT_MIDAS; my.size = TAPE_BUFFER_SIZE; my.pmp = (char *) malloc(my.size); if (my.pmp == NULL) return SS_NO_MEMORY; my.pme = (EVENT_HEADER *) my.pmp; /* allocate memory for one full event */ if (my.pmrd != NULL) free(my.pmrd); my.pmrd = (char *) malloc(5 * MAX_EVENT_SIZE); /* in bytes */ ptopmrd = my.pmrd; if (my.pmrd == NULL) return SS_NO_MEMORY; memset((char *) my.pmrd, -1, 5 * MAX_EVENT_SIZE); my.pmh = (EVENT_HEADER *) my.pmrd; } /* initialize pertinent variables */ my.recn = -1; my.evtn = 0; return (MD_SUCCESS); }
/** * This routine is called when a run is resumed. * Should enable trigger events. * Pause/resume mechanism is not implemented in our DAQ. * * @param run_number * @param error * * @return always returns CM_INVALID_TRANSITION */ INT resume_run(INT run_number, char *error) { cm_msg(MERROR, "resume_run", "This functionality is not implemented"); return CM_INVALID_TRANSITION; }
INT rpc_g2_end_of_fill(INT index, void *prpc_param[]) { int status; struct timeval tv_rpc, tv_amc; status = gettimeofday( &tv_rpc, NULL); if ( status != 0) { printf("ERROR! gettimeofday() failed\n"); tv_rpc.tv_sec = 0; tv_rpc.tv_usec = 0; } trigger_info.time_slave_got_eof_s = tv_rpc.tv_sec; trigger_info.time_slave_got_eof_us = tv_rpc.tv_usec; //trigger_nr,trigger_mask,time_s,time_us); trigger_info.trigger_nr = CDWORD(0); trigger_info.trigger_mask = CDWORD(1); trigger_info.time_master_got_eof_s = CDWORD(2); trigger_info.time_master_got_eof_us = CDWORD(3); long int dt_s = trigger_info.time_slave_got_eof_s; dt_s -= trigger_info.time_master_got_eof_s; long int dt_us = trigger_info.time_slave_got_eof_us; dt_us -= trigger_info.time_master_got_eof_us; if ( dt_us < 0 ) { dt_s -= 1; dt_us += 1000000; } printf("rpc_g2_eof: end of spill #%i, master-slave interval dt = %li s %li us\n", trigger_info.trigger_nr, dt_s, dt_us); /* status = gettimeofday( &tv_rpc, NULL); if ( status != 0) { printf("ERROR! gettimeofday() failed\n"); tv_rpc.tv_sec = 0; tv_rpc.tv_usec = 0; } dt_s = tv_rpc.tv_sec; dt_s -= trigger_info.time_slave_got_eof_s; dt_us = tv_rpc.tv_usec; dt_us -= trigger_info.time_slave_got_eof_us; if ( dt_us < 0 ) { dt_s -= 1; dt_us += 1000000; } printf("rpc_g2_eof: end of spill #%i, rpc_ready delay dt = %li s %li us\n", trigger_info.trigger_nr, dt_s, dt_us); */ /* disabled for AMC13 based readout // send data to the tcp readout frontend status = tcp_write(); if ( status != 0 ) { cm_msg(MERROR, __FILE__, "TCP send data failed, err = %i", status); return FE_ERR_HW; } */ // makes amc13 send event printf(" before amc13 write\n"); //int nSubEvents = 54 * 30; // no. of sub-events in each fill, ~ nsegments x ( 2bytes*6e5ns*0.8samples/ns / 32kB payload ) //int nSubEvents = 54; // testing int nSubEvents = 1; // testing int iSubEvents; int write_stat; if (amc13_amc13_odb.enableSoftwareTrigger){ for (iSubEvents = 0; iSubEvents < nSubEvents; iSubEvents++){ printf(" software trigger enabled, writing AMC event %i\n",iSubEvents); write_stat = amc13lib.AMC13_Write(amc13); printf(" software trigger enabled, wrote AMC event %i\n",iSubEvents); if (write_stat==0) printf("STOP! Write to AMC13 failed!\n"); } } status = gettimeofday( &tv_amc, NULL); if ( status != 0) { printf("ERROR! gettimeofday() failed\n"); tv_amc.tv_sec = 0; tv_amc.tv_usec = 0; } dt_s = tv_amc.tv_sec; dt_s -= trigger_info.time_master_got_eof_s; dt_us = tv_amc.tv_usec; dt_us -= trigger_info.time_master_got_eof_us; if ( dt_us < 0 ) { dt_s -= 1; dt_us += 1000000; } printf("rpc_g2_eof: end of spill #%i, amc write - slave interval dt = %li s %li us\n", trigger_info.trigger_nr, dt_s, dt_us); // have EOF set data available so poll will succeed data_avail = TRUE; // 14 August 2014 // try quick fix to send ready on tcp_client_send() // and remove data_avail so wont make any events //rpc_g2_ready( frontend_index + frontend_index_offset ); // Finally figured out that Fast TCP communications // via rpc_call_client() return after send, i.e. dont // block until "success" from remote routine //send_event(0,0); /** equipment id: 0, manual trigger: 0 */ // *** unlock VME thread which will start data readout *** /* do quick stuff here */ /* get control over vme interface */ //pthread_mutex_lock( &vme_thread_info.mutex_vme ); #if 0 // Arm sampling logic status = sis3350_ArmSamplingOnAlternateBank(); if ( status != 0 ) { /** \todo handle errors */ /* must not send RPC from this function */ //cm_msg(MERROR, "read_trigger_event", "Error arming sampling on alternate bank, err = %i", status); } #endif #if 0 // send back extern HNDLE rpc_master_hndle; #define RPC_READY 2202 status = rpc_client_call(rpc_master_hndle, RPC_READY, frontend_index); if(status != RPC_SUCCESS ) { cm_msg(MERROR, "rpc_call", "No RPC to master"); } #endif #if 0 rpc_g2_ready(); #endif #ifdef USE_GPU pthread_mutex_unlock( &(gpu_thread_1_info.mutex) ); #endif return SUCCESS; }
int main(int argc, char *argv[]) { BOOL daemon = FALSE; INT status, i, ch; char host_name[HOST_NAME_LENGTH]; char exp_name[NAME_LENGTH]; char *speech_program = SPEECH_PROGRAM; /* get default from environment */ cm_get_environment(host_name, sizeof(host_name), exp_name, sizeof(exp_name)); #ifdef OS_DARWIN strlcpy(mtTalkStr, "afplay $MIDASSYS/utils/notify.wav", sizeof(mtTalkStr)); strlcpy(mtUserStr, "afplay $MIDASSYS/utils/notify.wav", sizeof(mtTalkStr)); #endif /* parse command line parameters */ for (i = 1; i < argc; i++) { if (argv[i][0] == '-' && argv[i][1] == 'D') daemon = TRUE; else if (argv[i][0] == '-') { if (i + 1 >= argc || argv[i + 1][0] == '-') goto usage; if (argv[i][1] == 'e') strcpy(exp_name, argv[++i]); else if (argv[i][1] == 'h') strcpy(host_name, argv[++i]); else if (argv[i][1] == 'c') speech_program = argv[++i]; else if (argv[i][1] == 't') strcpy(mtTalkStr, argv[++i]); else if (argv[i][1] == 'u') strcpy(mtUserStr, argv[++i]); else if (argv[i][1] == 's') shutupTime = atoi(argv[++i]); else { usage: printf ("usage: mlxspeaker [-h Hostname] [-e Experiment] [-c command] [-D] daemon\n"); printf(" [-t mt_talk] Specify the mt_talk alert command\n"); printf(" [-u mt_user] Specify the mt_user alert command\n"); printf(" [-s shut up time] Specify the min time interval between alert [s]\n"); printf(" The -t & -u switch require a command equivalent to:\n"); printf(" '-t play --volume=0.3 file.wav'\n"); printf(" [-c command] Used to start the speech synthesizer,\n"); printf(" which should read text from it's standard input.\n"); printf(" eg: mlxspeaker -c 'festival --tts -'\n\n"); return 0; } } } if (daemon) { printf("Becoming a daemon...\n"); ss_daemon_init(FALSE); } /* Handle SIGPIPE signals generated from errors on the pipe */ signal(SIGPIPE, sigpipehandler); signal(SIGINT, siginthandler); fp = popen(speech_program, "w"); if (fp == NULL) { cm_msg(MERROR, "Speaker", "Unable to start \"%s\": %s\n", speech_program, strerror(errno)); cm_disconnect_experiment(); exit(2); } /* now connect to server */ status = cm_connect_experiment(host_name, exp_name, "Speaker", NULL); if (status != CM_SUCCESS) return 1; cm_msg_register(receive_message); printf("Midas Message Speaker connected to %s. Press \"!\" to exit.\n", host_name[0] ? host_name : "local host"); /* initialize terminal */ ss_getchar(0); do { status = cm_yield(1000); while (ss_kbhit()) { ch = ss_getchar(0); if (ch == -1) ch = getchar(); if (ch == '!') status = RPC_SHUTDOWN; } } while (status != SS_ABORT && status != RPC_SHUTDOWN); /* reset terminal */ ss_getchar(TRUE); pclose(fp); cm_disconnect_experiment(); return 1; }
INT frontend_init() { /* hardware initialization */ INT status; // have simulator start last after master / readout to make sure readout gets all data/triggers cm_set_transition_sequence( TR_START, 501); // have simulator stop first before master / readout to make sure readout gets all data/triggers cm_set_transition_sequence( TR_STOP, 499); // MIDAS thread //TG pthread_mutex_lock( &mutex_midas ); #ifdef USE_CALO_SIMULATOR if ( calo_simulator_init() != 0 ) { cm_msg(MERROR, __FILE__, "Cannot start calorimeter simulator"); return FE_ERR_HW; } #endif #ifdef USE_GPU if ( gpu_thread_init() != 0 ) { cm_msg(MERROR, __FILE__, "Cannot start gpu thread"); return FE_ERR_HW; } #endif // initialize TCP simulator settings from ODB if ( amc13_ODB_init() != SUCCESS ) { return FE_ERR_ODB; } // get TCP readout settings from ODB if ( amc13_ODB_get() != SUCCESS ) { return FE_ERR_ODB; } /* disabled for AMC13 based readout // initialize TCP Calo emulator (TCP server) status = tcp_server_init(); if ( status != 0 ) { cm_msg(MERROR, __FILE__, "TCP initialization failed, err = %i", status); return FE_ERR_HW; } dbprintf("%s(%d): TCP initialization done \n", __func__, __LINE__); */ // initialize RPC communication interface with master status = frontend_rpc_init(); if ( status != SUCCESS ) { cm_msg(MERROR, __FILE__, "RPC initialization failed, err = %i", status); return FE_ERR_HW; } dbprintf("%s(%d): RPC initialization done \n", __func__, __LINE__); //initialize AMC13 disableLogging();//disable uHal logging int serialNo =1; //int serialNo =33; int slot = 13; int usingControlHub= 0; /* std::string T2ip = "192.168.1.252"; std::string T1ip = "192.168.1.253"; std::string addrTab1="/home/gohn/gm2daq/amc13/map/AMC13_AddressTable_S6.xml"; std::string addrTab2="/home/gohn/gm2daq/amc13/map/AMC13_AddressTable_K7.xml"; */ std::string T2ip = "192.168.1.252"; std::string T1ip = "192.168.1.253"; std::string addrTab1="/home/daq/gm2daq/amc13/map/AMC13_AddressTable_S6.xml"; std::string addrTab2="/home/daq/gm2daq/amc13/map/AMC13_AddressTable_K7.xml"; Aeo = new AMC13_env(&Auo, serialNo, slot, usingControlHub); Aeo->setIPAddresses(T2ip,T1ip); Aeo->setAddressTables(addrTab1,addrTab2); amc13 = new cms::AMC13(Aeo); return SUCCESS; }
unsigned int tcp_write(void) { unsigned int TCPheadersize = amc13_amc13_odb.header_size; if (TCPheadersize > TCPheadersizemax) { cm_msg(MERROR, __FILE__, "TCPheadersize too large"); return FE_ERR_HW; } dbprintf("%s(%d): header size [bytes] %d\n", __func__, __LINE__, TCPheadersize ); #ifdef USE_CALO_SIMULATOR unsigned int TCPdatasize = calo_simulator_thread_info.data_size*sizeof(calo_simulator_thread_info.data[0]); #else unsigned int TCPdatasize = amc13_amc13_odb[0].data_size; #endif if (TCPdatasize > TCPdatasizemax) { cm_msg(MERROR, __FILE__, "TCPdatasize too large"); return FE_ERR_HW; } dbprintf("%s(%d): data size [bytes] %d\n", __func__, __LINE__, TCPdatasize ); unsigned int TCPtailsize = amc13_amc13_odb.tail_size; if (TCPtailsize > TCPtailsizemax) { cm_msg(MERROR, __FILE__, "TCPtailsize too large"); return FE_ERR_HW; } dbprintf("%s(%d): trailer size [bytes] %d\n", __func__, __LINE__, TCPtailsize ); int ndata, ih, it; /* #ifdef USE_CALO_SIMULATOR pthread_mutex_lock( &(calo_simulator_thread_info.mutex_data) ); ndata = write( datasockfd, calo_simulator_thread_info.data, TCPdatasize); pthread_mutex_unlock( &(calo_simulator_thread_info.mutex_data) ); #else unsigned int *data; data = (unsigned short int*) malloc( TCPdatasize ); memset(data, 0, TCPdatasize ); ndata = write( datasockfd, data, TCPdatasize ); #endif if (ndata < 0) { cm_msg(MERROR, __FILE__, "Cannot write data to socket"); return FE_ERR_HW; } dbprintf("%s(%d): write data, data socket %d, write return %d, data size [bytes] %d\n", __func__, __LINE__, datasockfd, ndata, TCPdatasize); */ //int TCPtotalsize = TCPdatasize+TCPheadersize+TCPtailsize; // for refresh logic static int first = 0; // for refresh logic, static keyword prevents reinitialization static int amc13_data_size_first = 0; // for refresh logic, static keyword prevents reinitialization uint64_t NEW_CDF_header = 0; // for refreshing data header uint64_t delimiter = 0x5; // for refreshing data header uint64_t fillnum = EMULATORfillnumber; // for refreshing data header static uint64_t *amc13_packed_data; int amc13_data_size = 0; if (first == 0) { // only malloc() if first fill data amc13_packed_data = (uint64_t*) malloc( 2*TCPdatasize ); } pthread_mutex_lock( &(calo_simulator_thread_info.mutex_data) ); /*printf("%s(%d): got mutex_data lock, calo_simulator_thread_info.mutex_data: 0x%.16"PRIx64" , 0x%.16"PRIx64"\n", __func__, __LINE__, *(calo_simulator_thread_info.data), *(calo_simulator_thread_info.data+1) ); */ dbprintf("%s(%d): Data packing started, bytes = %d \n", __func__, __LINE__, amc13_data_size); // copy truth data from simulator thread to temporary buffer before filling MIDAS databank *truthdata = calo_simulator_hits; //std::cout << "calo_simulator_hits = " << calo_simulator_hits << std::endl; //std::cout << "simulator_event[10].elab = " << simulator_event[10].elab << std::endl; memcpy( (truthdata+1), &simulator_event[0], (int)calo_simulator_hits*sizeof(CALO_SIMULATOR_EVENT)); //std::copy(simulator_event.begin(), simulator_event.end(), truthdata); //std::cout << "truthdata[41] = " << truthdata[41] << std::endl; // AMC13 reformat and copy waveforms to tcp socket if(!amc13simulator_settings_odb.repeat_first_event){ amc13_data_size = pack_amc13_data(amc13_packed_data, EMULATORfillnumber ); if( amc13_data_size <= 0 ) { printf("Error calling packing function\n"); } dbprintf("%s(%d):Different data fill-to-fill, bytes = %d \n", __func__, __LINE__, amc13_data_size); }else{ if ( first == 0 ) { amc13_data_size_first = pack_amc13_data(amc13_packed_data, EMULATORfillnumber ); if( amc13_data_size_first <= 0 ) { printf("Error calling packing function\n"); } first = 1; // causes no freeing of amc13_packed_data memory } else { // if using stale data new to update fill counter - added TG 21 April 2015 NEW_CDF_header = (delimiter<<60) | (fillnum<<32); *amc13_packed_data = htobe64(NEW_CDF_header); //htobe64 converts to big endian to mimick amc13 } amc13_data_size = amc13_data_size_first; dbprintf("%s(%d): Same data fill-to-fill, bytes = %d, data[0] 0x%016llX \n", __func__, __LINE__, amc13_data_size, *amc13_packed_data ); } /* int ip; dbprintf("first 16 64-bit words to tcp socket\n"); for (ip = 0; ip<16; ip++){ dbprintf(" ... amc13_packed_data %p *amc13_packed_data+%d 0x%016llX \n", amc13_packed_data+ip, ip, *(amc13_packed_data+ip) ); } int ioff = amc13_data_size / sizeof(uint64_t) - 16; dbprintf("last 16 64-bit words to tcp socket\n"); for (ip = 0; ip<16; ip++){ dbprintf(" ... amc13_packed_data %p *amc13_packed_data+%d 0x%016llX \n", amc13_packed_data+ip+ioff, ip, *(amc13_packed_data+ip+ioff) ); } */ printf("%s(%d): release mutex_data lock, start TCP data write, data size [bytes] %d\n", __func__, __LINE__, amc13_data_size); pthread_mutex_unlock( &(calo_simulator_thread_info.mutex_data) ); printf("tcp_write: release mutex for calo simulator to generate data\n"); pthread_mutex_unlock( &(calo_simulator_thread_info.mutex) ); ndata = write( datasockfd, amc13_packed_data, amc13_data_size); if (ndata < 0) { printf("TCP write error: ndata = %d, errno = %d\n",ndata,errno); cm_msg(MERROR, __FILE__, "Cannot write data to socket"); return FE_ERR_HW; } dbprintf("%s(%d): wrote data, data socket %d, write return %d, data size [bytes] %d\n", __func__, __LINE__, datasockfd, ndata, amc13_data_size); if (first == 0) free(amc13_packed_data); // only free() if refreshing fill data EMULATORfillnumber++; return 0; }
INT amc13simulator_ODB_set() { INT status; HNDLE hKey; char str[MAX_ODB_PATH]; char str_aux[MAX_ODB_PATH]; int i; sprintf(str_aux,"/Equipment/AMC13Simulator%02d/Settings/Globals",frontend_index); sprintf(str, str_aux, frontend_index); // create ODB structure /Equipment/%s/Settings/Globals if doesn't exist status = db_check_record(hDB, 0, str, AMC13SIMULATOR_SETTINGS_ODB_STR, TRUE); if (status != DB_SUCCESS) { cm_msg(MERROR, __FILE__, "Cannot create [%s] entry in ODB, err = %i",str,status); ss_sleep(3000); } // returns key handle "hDB" to ODB name "str" for fast access status = db_find_key(hDB, 0, str, &hKey); if ( status != DB_SUCCESS ) { cm_msg(MERROR, __FILE__, "Cannot find [%s] key in ODB, err = %i",str,status); return FE_ERR_ODB; } // Copy a set of keys from local memory to the database db_set_record(hDB, hKey, &amc13simulator_settings_odb, sizeof(AMC13SIMULATOR_SETTINGS_ODB), 0); dbprintf("%s(%d): %s sync %d\n", __func__, __LINE__, str, amc13simulator_settings_odb.sync ); for (i=0; i<AMC13SIMULATOR_NUM; i++) { sprintf(str,"/Equipment/AMC13Simulator%02d/Settings/Channel%02d",frontend_index,i+1); // create ODB structure /Equipment/%s/Settings/Channel%02d if doesn't exist status = db_check_record(hDB, 0, str, AMC13SIMULATOR_CHANNEL_ODB_STR, TRUE); if (status != DB_SUCCESS) { cm_msg(MERROR, __FILE__, "Cannot create [%s] entry in ODB, err = %i",str,status); ss_sleep(3000); } // returns key handle "hDB" to ODB name "str" for fast access status = db_find_key(hDB, 0, str, &hKey); if ( status != DB_SUCCESS ) { cm_msg(MERROR, __FILE__, "Cannot find [%s] key in ODB, err = %i",str,status); return FE_ERR_ODB; } // Copy a set of keys from local memory to the database db_set_record(hDB, hKey, &amc13simulator_channel_odb[i], sizeof(AMC13SIMULATOR_CHANNEL_ODB), 0); dbprintf("%s(%d): %s enabled %d\n", __func__, __LINE__, str, amc13simulator_channel_odb[i].enabled ); dbprintf("%s(%d): %s port no %d\n", __func__, __LINE__, str, amc13simulator_channel_odb[i].port_no ); dbprintf("%s(%d): %s ip addr %s\n", __func__, __LINE__, str, amc13simulator_channel_odb[i].ip_addr ); } return SUCCESS; }
INT amc13simulator_ODB_get() { INT status; HNDLE hKey; char str[MAX_ODB_PATH]; char str_aux[MAX_ODB_PATH]; int size; sprintf(str_aux,"/Equipment/AMC13Simulator%02d/Settings/Globals",frontend_index); sprintf(str, str_aux, frontend_index); // create ODB structure /Equipment/%s/Settings/Globals if doesn't exist status = db_check_record(hDB, 0, str, AMC13SIMULATOR_SETTINGS_ODB_STR, TRUE); if (status != DB_SUCCESS) { cm_msg(MERROR, __FILE__, "Cannot create [%s] entry in ODB, err = %i",str,status); ss_sleep(3000); } // returns key handle "hDB" to ODB name "str" for fast access status = db_find_key(hDB, 0, str, &hKey); if ( status != DB_SUCCESS ) { cm_msg(MERROR, __FILE__, "Cannot find [%s] key in ODB, err = %i",str,status); return FE_ERR_ODB; } // Copy a set of keys from local memory to the database size = sizeof(AMC13SIMULATOR_SETTINGS_ODB); db_get_record(hDB, hKey, &amc13simulator_settings_odb, &size, 0); dbprintf("%s(%d): %s sync %d\n", __func__, __LINE__, str, amc13simulator_settings_odb.sync ); dbprintf("%s(%d): %s write_root %d\n", __func__, __LINE__, str, amc13simulator_settings_odb.write_root ); dbprintf("%s(%d): %s rider_header %d\n", __func__, __LINE__, str, amc13simulator_settings_odb.rider_header ); dbprintf("%s(%d): %s n_seg_x %d\n", __func__, __LINE__, str, amc13simulator_settings_odb.n_seg_x ); dbprintf("%s(%d): %s n_seg_y %d\n", __func__, __LINE__, str, amc13simulator_settings_odb.n_seg_y ); dbprintf("%s(%d): %s seg_size %d\n", __func__, __LINE__, str, amc13simulator_settings_odb.seg_size ); dbprintf("%s(%d): %s waveform length %d\n", __func__, __LINE__, str, amc13simulator_settings_odb.waveform_length ); dbprintf("%s(%d): %s n_muons_mean %d\n", __func__, __LINE__, str, amc13simulator_settings_odb.n_muons_mean ); dbprintf("%s(%d): %s Emax %f\n", __func__, __LINE__, str, amc13simulator_settings_odb.Emax ); dbprintf("%s(%d): %s Elab_max %f\n", __func__, __LINE__, str, amc13simulator_settings_odb.Elab_max ); dbprintf("%s(%d): %s omega_a %f\n", __func__, __LINE__, str, amc13simulator_settings_odb.omega_a ); dbprintf("%s(%d): %s repeat_first_event %d\n",__func__,__LINE__,str,amc13simulator_settings_odb.repeat_first_event); dbprintf("%s(%d): %s laser_pulse %d\n",__func__,__LINE__,str,amc13simulator_settings_odb.laser_pulse); /* int i; for (i=0; i<AMC13SIMULATOR_NUM; i++) { sprintf(str,"/Equipment/AMC13Simulator%02d/Settings/Channel%02d",frontend_index,i+1); // create ODB structure /Equipment/%s/Settings/Channel%02d if doesn't exist status = db_check_record(hDB, 0, str, AMC13SIMULATOR_CHANNEL_ODB_STR, TRUE); if (status != DB_SUCCESS) { cm_msg(MERROR, __FILE__, "Cannot create [%s] entry in ODB, err = %i",str,status); ss_sleep(3000); } // returns key handle "hDB" to ODB name "str" for fast access status = db_find_key(hDB, 0, str, &hKey); if ( status != DB_SUCCESS ) { cm_msg(MERROR, __FILE__, "Cannot find [%s] key in ODB, err = %i",str,status); return FE_ERR_ODB; } // Copy a set of keys from local memory to the database size = sizeof(AMC13SIMULATOR_CHANNEL_ODB); db_get_record(hDB, hKey, &amc13simulator_channel_odb[i], &size, 0); dbprintf("%s(%d): %s enabled %d\n", __func__, __LINE__, str, amc13simulator_channel_odb[i].enabled ); dbprintf("%s(%d): %s port no %d\n", __func__, __LINE__, str, amc13simulator_channel_odb[i].port_no ); dbprintf("%s(%d): %s ip addr %s\n", __func__, __LINE__, str, amc13simulator_channel_odb[i].ip_addr ); } */ return SUCCESS; }
INT amc13simulator_ODB_init(void) { INT ret = SUCCESS; INT status; char str[MAX_ODB_PATH]; char str_aux[MAX_ODB_PATH]; HNDLE hKey; /* reset channel info information */ int i; amc13simulator_settings_odb.sync = 0; for (i=0; i<AMC13SIMULATOR_NUM; i++){ amc13simulator_channel_odb[i].enabled = 0; amc13simulator_channel_odb[i].port_no = 0; sprintf(amc13simulator_channel_odb[i].ip_addr,"000.000.0.000"); sprintf(amc13simulator_channel_odb[i].host_name,""); } dbprintf(str,"/Equipment/AMC13Simulator%02d/Settings/Globals",frontend_index); sprintf(str,"/Equipment/AMC13Simulator%02d/Settings/Globals",frontend_index); // create ODB structure /Equipment/%s/Settings/Globals if doesn't exist status = db_check_record(hDB, 0, str, AMC13SIMULATOR_SETTINGS_ODB_STR, TRUE); if ( status != DB_SUCCESS ) { cm_msg(MERROR, __FILE__, "Cannot create [%s] entry in ODB, err = %i",str,status); return FE_ERR_ODB; } // returns key handle "hDB" to ODB name "str" for fast access status = db_find_key(hDB, 0, str, &hKey); if ( status != DB_SUCCESS ) { cm_msg(MERROR, __FILE__, "Cannot find [%s] key in ODB, err = %i",str,status); return FE_ERR_ODB; } // creates hotlink of ODB subtree to structure amc13simulator_settings_odb that's automatically updated if (db_open_record(hDB, hKey, &amc13simulator_settings_odb, sizeof(AMC13SIMULATOR_SETTINGS_ODB), MODE_READ, amc13simulator_ODB_update, NULL) != DB_SUCCESS) { cm_msg(MERROR, __FILE__, "Cannot open [%s] settings in ODB",str); return FE_ERR_ODB; } dbprintf("%s(%d): %s sync %d\n", __func__, __LINE__, str, amc13simulator_settings_odb.sync ); for (i=0; i<AMC13SIMULATOR_NUM; i++){ sprintf(str,"/Equipment/AMC13Simulator%02d/Settings/Channel%02d",frontend_index,i+1); // create ODB structure /Equipment/%s/Settings/Channel%02d if doesn't exist status = db_check_record(hDB, 0, str, AMC13SIMULATOR_CHANNEL_ODB_STR, TRUE); if ( status != DB_SUCCESS ) { cm_msg(MERROR, __FILE__, "Cannot create [%s] entry in ODB, err = %i",str,status); return FE_ERR_ODB; } // returns key handle "hDB" to ODB name "str" for fast access status = db_find_key(hDB, 0, str, &hKey); if ( status != DB_SUCCESS ) { cm_msg(MERROR, __FILE__, "Cannot find [%s] key in ODB, err = %i",str,status); return FE_ERR_ODB; } // creates hotlink of ODB subtree to structure amc13simulator_channel_odb[i] that's automatically update if (db_open_record(hDB, hKey, &amc13simulator_channel_odb[i], sizeof(AMC13SIMULATOR_CHANNEL_ODB), MODE_READ, amc13simulator_ODB_update, NULL) != DB_SUCCESS) { cm_msg(MERROR, __FILE__, "Cannot open [%s] settings in ODB",str); return FE_ERR_ODB; } dbprintf("%s(%d): %s enabled %d\n", __func__, __LINE__, str, amc13simulator_channel_odb[i].enabled ); dbprintf("%s(%d): %s port no %d\n", __func__, __LINE__, str, amc13simulator_channel_odb[i].port_no ); dbprintf("%s(%d): %s ip addr %s\n", __func__, __LINE__, str, amc13simulator_channel_odb[i].ip_addr ); } return ret; }
/** Scan ODB for alarms. @return AL_SUCCESS */ INT al_check() { if (rpc_is_remote()) return rpc_call(RPC_AL_CHECK); #ifdef LOCAL_ROUTINES { INT i, status, size, semaphore; HNDLE hDB, hkeyroot, hkey; KEY key; ALARM a; char str[256], value[256]; time_t now; PROGRAM_INFO program_info; BOOL flag; ALARM_CLASS_STR(alarm_class_str); ALARM_ODB_STR(alarm_odb_str); ALARM_PERIODIC_STR(alarm_periodic_str); cm_get_experiment_database(&hDB, NULL); if (hDB == 0) return AL_SUCCESS; /* called from server not yet connected */ /* check online mode */ flag = TRUE; size = sizeof(flag); db_get_value(hDB, 0, "/Runinfo/Online Mode", &flag, &size, TID_INT, TRUE); if (!flag) return AL_SUCCESS; /* check global alarm flag */ flag = TRUE; size = sizeof(flag); db_get_value(hDB, 0, "/Alarms/Alarm system active", &flag, &size, TID_BOOL, TRUE); if (!flag) return AL_SUCCESS; /* request semaphore */ cm_get_experiment_semaphore(&semaphore, NULL, NULL, NULL); status = ss_semaphore_wait_for(semaphore, 100); if (status == SS_TIMEOUT) return AL_SUCCESS; /* someone else is doing alarm business */ if (status != SS_SUCCESS) { printf("al_check: Something is wrong with our semaphore, ss_semaphore_wait_for() returned %d, aborting.\n", status); //abort(); // DOES NOT RETURN printf("al_check: Cannot abort - this will lock you out of odb. From this point, MIDAS will not work correctly. Please read the discussion at https://midas.triumf.ca/elog/Midas/945\n"); // NOT REACHED return AL_SUCCESS; } /* check ODB alarms */ db_find_key(hDB, 0, "/Alarms/Alarms", &hkeyroot); if (!hkeyroot) { /* create default ODB alarm */ status = db_create_record(hDB, 0, "/Alarms/Alarms/Demo ODB", strcomb(alarm_odb_str)); db_find_key(hDB, 0, "/Alarms/Alarms", &hkeyroot); if (!hkeyroot) { ss_semaphore_release(semaphore); return AL_SUCCESS; } status = db_create_record(hDB, 0, "/Alarms/Alarms/Demo periodic", strcomb(alarm_periodic_str)); db_find_key(hDB, 0, "/Alarms/Alarms", &hkeyroot); if (!hkeyroot) { ss_semaphore_release(semaphore); return AL_SUCCESS; } /* create default alarm classes */ status = db_create_record(hDB, 0, "/Alarms/Classes/Alarm", strcomb(alarm_class_str)); status = db_create_record(hDB, 0, "/Alarms/Classes/Warning", strcomb(alarm_class_str)); if (status != DB_SUCCESS) { ss_semaphore_release(semaphore); return AL_SUCCESS; } } for (i = 0;; i++) { status = db_enum_key(hDB, hkeyroot, i, &hkey); if (status == DB_NO_MORE_SUBKEYS) break; db_get_key(hDB, hkey, &key); size = sizeof(a); status = db_get_record(hDB, hkey, &a, &size, 0); if (status != DB_SUCCESS || a.type < 1 || a.type > AT_LAST) { /* make sure alarm record has right structure */ db_check_record(hDB, hkey, "", strcomb(alarm_odb_str), TRUE); size = sizeof(a); status = db_get_record(hDB, hkey, &a, &size, 0); if (status != DB_SUCCESS || a.type < 1 || a.type > AT_LAST) { cm_msg(MERROR, "al_check", "Cannot get alarm record"); continue; } } /* check periodic alarm only when active */ if (a.active && a.type == AT_PERIODIC && a.check_interval > 0 && (INT) ss_time() - (INT) a.checked_last > a.check_interval) { /* if checked_last has not been set, set it to current time */ if (a.checked_last == 0) { a.checked_last = ss_time(); db_set_record(hDB, hkey, &a, size, 0); } else al_trigger_alarm(key.name, a.alarm_message, a.alarm_class, "", AT_PERIODIC); } /* check alarm only when active and not internal */ if (a.active && a.type == AT_EVALUATED && a.check_interval > 0 && (INT) ss_time() - (INT) a.checked_last > a.check_interval) { /* if condition is true, trigger alarm */ if (al_evaluate_condition(a.condition, value)) { sprintf(str, a.alarm_message, value); al_trigger_alarm(key.name, str, a.alarm_class, "", AT_EVALUATED); } else { a.checked_last = ss_time(); status = db_set_value(hDB, hkey, "Checked last", &a.checked_last, sizeof(DWORD), 1, TID_DWORD); if (status != DB_SUCCESS) { cm_msg(MERROR, "al_check", "Cannot change alarm record"); continue; } } } } /* check /programs alarms */ db_find_key(hDB, 0, "/Programs", &hkeyroot); if (hkeyroot) { for (i = 0;; i++) { status = db_enum_key(hDB, hkeyroot, i, &hkey); if (status == DB_NO_MORE_SUBKEYS) break; db_get_key(hDB, hkey, &key); /* don't check "execute on xxx" */ if (key.type != TID_KEY) continue; size = sizeof(program_info); status = db_get_record(hDB, hkey, &program_info, &size, 0); if (status != DB_SUCCESS) { cm_msg(MERROR, "al_check", "Cannot get program info record"); continue; } now = ss_time(); rpc_get_name(str); str[strlen(key.name)] = 0; if (!equal_ustring(str, key.name) && cm_exist(key.name, FALSE) == CM_NO_CLIENT) { if (program_info.first_failed == 0) { program_info.first_failed = (DWORD) now; db_set_record(hDB, hkey, &program_info, sizeof(program_info), 0); } /* fire alarm when not running for more than what specified in check interval */ if (now - program_info.first_failed >= program_info.check_interval / 1000) { /* if not running and alarm calss defined, trigger alarm */ if (program_info.alarm_class[0]) { sprintf(str, "Program %s is not running", key.name); al_trigger_alarm(key.name, str, program_info.alarm_class, "Program not running", AT_PROGRAM); } /* auto restart program */ if (program_info.auto_restart && program_info.start_command[0]) { ss_system(program_info.start_command); program_info.first_failed = 0; cm_msg(MTALK, "al_check", "Program %s restarted", key.name); } } } else { if (program_info.first_failed != 0) { program_info.first_failed = 0; db_set_record(hDB, hkey, &program_info, sizeof(program_info), 0); } } } } ss_semaphore_release(semaphore); } #endif /* LOCAL_COUTINES */ return SUCCESS; }
INT amc13simulator_ODB_init(void) { INT ret = SUCCESS; INT status; char str[MAX_ODB_PATH]; char str_aux[MAX_ODB_PATH]; HNDLE hKey; /* reset channel info information */ int i; amc13simulator_settings_odb.sync = 1; amc13simulator_settings_odb.write_root = 1; amc13simulator_settings_odb.rider_header = 0; amc13simulator_settings_odb.n_seg_x = 9; amc13simulator_settings_odb.n_seg_y = 6; amc13simulator_settings_odb.seg_size = 3; amc13simulator_settings_odb.waveform_length = 589824; amc13simulator_settings_odb.n_muons_mean = 400; amc13simulator_settings_odb.Emax = 52.8; amc13simulator_settings_odb.Elab_max = 3.1; amc13simulator_settings_odb.omega_a = 1.438e6; amc13simulator_settings_odb.repeat_first_event = 1; amc13simulator_settings_odb.laser_pulse = 0; amc13simulator_settings_odb.send_to_event_builder = 0; /* for (i=0; i<AMC13SIMULATOR_NUM; i++){ amc13simulator_channel_odb[i].enabled = 0; amc13simulator_channel_odb[i].port_no = 0; sprintf(amc13simulator_channel_odb[i].ip_addr,"000.000.0.000"); sprintf(amc13simulator_channel_odb[i].host_name,""); } */ dbprintf(str,"/Equipment/AMC13Simulator%02d/Settings/Globals",frontend_index); sprintf(str,"/Equipment/AMC13Simulator%02d/Settings/Globals",frontend_index); // create ODB structure /Equipment/%s/Settings/Globals if doesn't exist status = db_check_record(hDB, 0, str, AMC13SIMULATOR_SETTINGS_ODB_STR, TRUE); if ( status != DB_SUCCESS ) { cm_msg(MERROR, __FILE__, "Cannot create [%s] entry in ODB, err = %i",str,status); return FE_ERR_ODB; } // returns key handle "hDB" to ODB name "str" for fast access status = db_find_key(hDB, 0, str, &hKey); if ( status != DB_SUCCESS ) { cm_msg(MERROR, __FILE__, "Cannot find [%s] key in ODB, err = %i",str,status); return FE_ERR_ODB; } // creates hotlink of ODB subtree to structure amc13simulator_settings_odb that's automatically updated if (db_open_record(hDB, hKey, &amc13simulator_settings_odb, sizeof(AMC13SIMULATOR_SETTINGS_ODB), MODE_READ, amc13simulator_ODB_update, NULL) != DB_SUCCESS) { cm_msg(MERROR, __FILE__, "Cannot open [%s] settings in ODB",str); return FE_ERR_ODB; } dbprintf("%s(%d): %s sync %d\n", __func__, __LINE__, str, amc13simulator_settings_odb.sync ); dbprintf("%s(%d): %s write_root %d\n", __func__, __LINE__, str, amc13simulator_settings_odb.write_root ); dbprintf("%s(%d): %s rider_header %d\n", __func__, __LINE__, str, amc13simulator_settings_odb.rider_header ); dbprintf("%s(%d): %s n_seg_x %d\n", __func__, __LINE__, str, amc13simulator_settings_odb.n_seg_x ); dbprintf("%s(%d): %s n_seg_y %d\n", __func__, __LINE__, str, amc13simulator_settings_odb.n_seg_y ); dbprintf("%s(%d): %s seg_size %d\n", __func__, __LINE__, str, amc13simulator_settings_odb.seg_size ); dbprintf("%s(%d): %s waveform length %d\n", __func__, __LINE__, str, amc13simulator_settings_odb.waveform_length ); dbprintf("%s(%d): %s n_muons_mean %d\n", __func__, __LINE__, str, amc13simulator_settings_odb.n_muons_mean ); dbprintf("%s(%d): %s Emax %f\n", __func__, __LINE__, str, amc13simulator_settings_odb.Emax ); dbprintf("%s(%d): %s Elab_max %f\n", __func__, __LINE__, str, amc13simulator_settings_odb.Elab_max ); dbprintf("%s(%d): %s omega_a %f\n", __func__, __LINE__, str, amc13simulator_settings_odb.omega_a ); dbprintf("%s(%d): %s repeat_first_event %d\n",__func__,__LINE__,str,amc13simulator_settings_odb.repeat_first_event); dbprintf("%s(%d): %s laser_pulse %d\n",__func__,__LINE__,str,amc13simulator_settings_odb.laser_pulse); /* for (i=0; i<AMC13SIMULATOR_NUM; i++){ sprintf(str,"/Equipment/AMC13Simulator%02d/Settings/Channel%02d",frontend_index,i+1); // create ODB structure /Equipment/%s/Settings/Channel%02d if doesn't exist status = db_check_record(hDB, 0, str, AMC13SIMULATOR_CHANNEL_ODB_STR, TRUE); if ( status != DB_SUCCESS ) { cm_msg(MERROR, __FILE__, "Cannot create [%s] entry in ODB, err = %i",str,status); return FE_ERR_ODB; } // returns key handle "hDB" to ODB name "str" for fast access status = db_find_key(hDB, 0, str, &hKey); if ( status != DB_SUCCESS ) { cm_msg(MERROR, __FILE__, "Cannot find [%s] key in ODB, err = %i",str,status); return FE_ERR_ODB; } // creates hotlink of ODB subtree to structure amc13simulator_channel_odb[i] that's automatically update if (db_open_record(hDB, hKey, &amc13simulator_channel_odb[i], sizeof(AMC13SIMULATOR_CHANNEL_ODB), MODE_READ, amc13simulator_ODB_update, NULL) != DB_SUCCESS) { cm_msg(MERROR, __FILE__, "Cannot open [%s] settings in ODB",str); return FE_ERR_ODB; } dbprintf("%s(%d): %s enabled %d\n", __func__, __LINE__, str, amc13simulator_channel_odb[i].enabled ); dbprintf("%s(%d): %s port no %d\n", __func__, __LINE__, str, amc13simulator_channel_odb[i].port_no ); dbprintf("%s(%d): %s ip addr %s\n", __func__, __LINE__, str, amc13simulator_channel_odb[i].ip_addr ); } */ return ret; }
INT fgd_init(EQUIPMENT * pequipment) { int status, size, i, j, index, offset; char str[256]; HNDLE hDB, hKey, hNames, hThreshold; FGD_INFO *fgd_info; /* allocate private data */ pequipment->cd_info = calloc(1, sizeof(FGD_INFO)); fgd_info = (FGD_INFO *) pequipment->cd_info; /* get class driver root key */ cm_get_experiment_database(&hDB, NULL); sprintf(str, "/Equipment/%s", pequipment->name); db_create_key(hDB, 0, str, TID_KEY); db_find_key(hDB, 0, str, &fgd_info->hKeyRoot); /* save event format */ size = sizeof(str); db_get_value(hDB, fgd_info->hKeyRoot, "Common/Format", str, &size, TID_STRING, TRUE); if (equal_ustring(str, "Fixed")) fgd_info->format = FORMAT_FIXED; else if (equal_ustring(str, "MIDAS")) fgd_info->format = FORMAT_MIDAS; else if (equal_ustring(str, "YBOS")) fgd_info->format = FORMAT_YBOS; /* count total number of channels */ for (i = 0, fgd_info->num_channels = 0; pequipment->driver[i].name[0]; i++) { if (pequipment->driver[i].channels == 0) { cm_msg(MERROR, "fgd_init", "Driver with zero channels not allowed"); return FE_ERR_ODB; } fgd_info->num_channels += pequipment->driver[i].channels; } if (fgd_info->num_channels == 0) { cm_msg(MERROR, "fgd_init", "No channels found in device driver list"); return FE_ERR_ODB; } /* Allocate memory for buffers */ fgd_info->names = (char *) calloc(fgd_info->num_channels, NAME_LENGTH); fgd_info->demand = (float *) calloc(fgd_info->num_channels, sizeof(float)); fgd_info->measured = (float *) calloc(fgd_info->num_channels, sizeof(float)); fgd_info->temp1 = (float *) calloc(fgd_info->num_channels, sizeof(float)); fgd_info->temp2 = (float *) calloc(fgd_info->num_channels, sizeof(float)); fgd_info->temp3 = (float *) calloc(fgd_info->num_channels, sizeof(float)); fgd_info->update_threshold = (float *) calloc(fgd_info->num_channels, sizeof(float)); fgd_info->demand_mirror = (float *) calloc(fgd_info->num_channels, sizeof(float)); fgd_info->measured_mirror = (float *) calloc(fgd_info->num_channels, sizeof(float)); fgd_info->channel_offset = (INT *) calloc(fgd_info->num_channels, sizeof(INT)); fgd_info->driver = (void *) calloc(fgd_info->num_channels, sizeof(void *)); if (!fgd_info->driver) { cm_msg(MERROR, "hv_init", "Not enough memory"); return FE_ERR_ODB; } /*---- Initialize device drivers ----*/ /* call init method */ for (i = 0; pequipment->driver[i].name[0]; i++) { sprintf(str, "Settings/Devices/%s", pequipment->driver[i].name); status = db_find_key(hDB, fgd_info->hKeyRoot, str, &hKey); if (status != DB_SUCCESS) { db_create_key(hDB, fgd_info->hKeyRoot, str, TID_KEY); status = db_find_key(hDB, fgd_info->hKeyRoot, str, &hKey); if (status != DB_SUCCESS) { cm_msg(MERROR, "hv_init", "Cannot create %s entry in online database", str); free_mem(fgd_info); return FE_ERR_ODB; } } status = device_driver(&pequipment->driver[i], CMD_INIT, hKey); if (status != FE_SUCCESS) { free_mem(fgd_info); return status; } } /* compose device driver channel assignment */ for (i = 0, j = 0, index = 0, offset = 0; i < fgd_info->num_channels; i++, j++) { while (j >= pequipment->driver[index].channels && pequipment->driver[index].name[0]) { offset += j; index++; j = 0; } fgd_info->driver[i] = &pequipment->driver[index]; fgd_info->channel_offset[i] = offset; } /*---- create demand variables ----*/ /* get demand from ODB */ status = db_find_key(hDB, fgd_info->hKeyRoot, "Variables/Demand", &fgd_info->hKeyDemand); if (status == DB_SUCCESS) { size = sizeof(float) * fgd_info->num_channels; db_get_data(hDB, fgd_info->hKeyDemand, fgd_info->demand, &size, TID_FLOAT); } /* let device driver overwrite demand values, if it supports it */ for (i = 0; i < fgd_info->num_channels; i++) { if (fgd_info->driver[i]->flags & DF_PRIO_DEVICE) { device_driver(fgd_info->driver[i], CMD_GET_DEMAND, i - fgd_info->channel_offset[i], &fgd_info->demand[i]); fgd_info->demand_mirror[i] = fgd_info->demand[i]; } else fgd_info->demand_mirror[i] = -12345.f; /* use -12345 as invalid value */ } /* write back demand values */ status = db_find_key(hDB, fgd_info->hKeyRoot, "Variables/Demand", &fgd_info->hKeyDemand); if (status != DB_SUCCESS) { db_create_key(hDB, fgd_info->hKeyRoot, "Variables/Demand", TID_FLOAT); db_find_key(hDB, fgd_info->hKeyRoot, "Variables/Demand", &fgd_info->hKeyDemand); } size = sizeof(float) * fgd_info->num_channels; db_set_data(hDB, fgd_info->hKeyDemand, fgd_info->demand, size, fgd_info->num_channels, TID_FLOAT); db_open_record(hDB, fgd_info->hKeyDemand, fgd_info->demand, fgd_info->num_channels * sizeof(float), MODE_READ, fgd_demand, pequipment); /*---- create measured variables ----*/ db_merge_data(hDB, fgd_info->hKeyRoot, "Variables/Current Measured", fgd_info->measured, sizeof(float) * fgd_info->num_channels, fgd_info->num_channels, TID_FLOAT); db_find_key(hDB, fgd_info->hKeyRoot, "Variables/Current Measured", &fgd_info->hKeyMeasured); memcpy(fgd_info->measured_mirror, fgd_info->measured, fgd_info->num_channels * sizeof(float)); /*---- create Temp1 measured variables ----*/ db_merge_data(hDB, fgd_info->hKeyRoot, "Variables/Temp1", fgd_info->temp1, sizeof(float) * fgd_info->num_channels, fgd_info->num_channels, TID_FLOAT); db_find_key(hDB, fgd_info->hKeyRoot, "Variables/Temp1", &fgd_info->hKeyTemp1); /*---- create Temp2 measured variables ----*/ db_merge_data(hDB, fgd_info->hKeyRoot, "Variables/Temp2", fgd_info->temp2, sizeof(float) * fgd_info->num_channels, fgd_info->num_channels, TID_FLOAT); db_find_key(hDB, fgd_info->hKeyRoot, "Variables/Temp2", &fgd_info->hKeyTemp2); /*---- create Temp3 measured variables ----*/ db_merge_data(hDB, fgd_info->hKeyRoot, "Variables/Temp3", fgd_info->temp3, sizeof(float) * fgd_info->num_channels, fgd_info->num_channels, TID_FLOAT); db_find_key(hDB, fgd_info->hKeyRoot, "Variables/Temp3", &fgd_info->hKeyTemp3); /*---- get default names from device driver ----*/ for (i = 0; i < fgd_info->num_channels; i++) { sprintf(fgd_info->names + NAME_LENGTH * i, "Default%%CH %d", i); device_driver(fgd_info->driver[i], CMD_GET_LABEL, i - fgd_info->channel_offset[i], fgd_info->names + NAME_LENGTH * i); } db_merge_data(hDB, fgd_info->hKeyRoot, "Settings/Names", fgd_info->names, NAME_LENGTH * fgd_info->num_channels, fgd_info->num_channels, TID_STRING); /*---- set labels form midas SC names ----*/ for (i = 0; i < fgd_info->num_channels; i++) { fgd_info = (FGD_INFO *) pequipment->cd_info; device_driver(fgd_info->driver[i], CMD_SET_LABEL, i - fgd_info->channel_offset[i], fgd_info->names + NAME_LENGTH * i); } /* open hotlink on channel names */ if (db_find_key(hDB, fgd_info->hKeyRoot, "Settings/Names", &hNames) == DB_SUCCESS) db_open_record(hDB, hNames, fgd_info->names, NAME_LENGTH*fgd_info->num_channels, MODE_READ, fgd_update_label, pequipment); /*---- get default update threshold from device driver ----*/ for (i = 0; i < fgd_info->num_channels; i++) { fgd_info->update_threshold[i] = 1.f; /* default 1 unit */ device_driver(fgd_info->driver[i], CMD_GET_THRESHOLD, i - fgd_info->channel_offset[i], &fgd_info->update_threshold[i]); } db_merge_data(hDB, fgd_info->hKeyRoot, "Settings/Update Threshold Measured", fgd_info->update_threshold, sizeof(float)*fgd_info->num_channels, fgd_info->num_channels, TID_FLOAT); /* open hotlink on update threshold */ if (db_find_key(hDB, fgd_info->hKeyRoot, "Settings/Update Threshold Measured", &hThreshold) == DB_SUCCESS) db_open_record(hDB, hThreshold, fgd_info->update_threshold, sizeof(float)*fgd_info->num_channels, MODE_READ, NULL, NULL); /*---- set initial demand values ----*/ // fgd_demand(hDB, fgd_info->hKeyDemand, pequipment); /* initially read all channels */ for (i = 0; i < fgd_info->num_channels; i++) fgd_read(pequipment, i); return FE_SUCCESS; }
unsigned int tcp_write(void) { unsigned int TCPheadersize = amc13_amc13_odb.header_size; if (TCPheadersize > TCPheadersizemax) { cm_msg(MERROR, __FILE__, "TCPheadersize too large"); return FE_ERR_HW; } dbprintf("%s(%d): header size [bytes] %d\n", __func__, __LINE__, TCPheadersize ); #ifdef USE_CALO_SIMULATOR unsigned int TCPdatasize = calo_simulator_thread_info.data_size*sizeof(calo_simulator_thread_info.data[0]); #else unsigned int TCPdatasize = amc13_amc13_odb.data_size; #endif if (TCPdatasize > TCPdatasizemax) { cm_msg(MERROR, __FILE__, "TCPdatasize too large"); return FE_ERR_HW; } dbprintf("%s(%d): data size [bytes] %d\n", __func__, __LINE__, TCPdatasize ); unsigned int TCPtailsize = amc13_amc13_odb.tail_size; if (TCPtailsize > TCPtailsizemax) { cm_msg(MERROR, __FILE__, "TCPtailsize too large"); return FE_ERR_HW; } dbprintf("%s(%d): trailer size [bytes] %d\n", __func__, __LINE__, TCPtailsize ); int ndata, ih, it; unsigned int *header; header = (unsigned int*) malloc( TCPheadersize ); for (ih = 0; ih < TCPheadersize/sizeof(header[0]); ih++){ header[ih] = 0; } header[0] = TCPdatasize; header[1] = EMULATORfillnumber; header[2] = 0; header[3] = trigger_info.time_master_got_eof_s; header[4] = trigger_info.time_master_got_eof_us; header[5] = trigger_info.time_slave_got_eof_s; header[6] = trigger_info.time_slave_got_eof_us; header[7] = BODdelimiter; ndata = write( datasockfd, header, TCPheadersize ); if (ndata < 0) { cm_msg(MERROR, __FILE__, "Cannot write header to socket"); return FE_ERR_HW; } dbprintf("%s(%d): write header, data socket %d, write return %d, header size [bytes] %d, data size [bytes] %d, event num %d, delimiter 0x%08x\n", __func__, __LINE__, datasockfd, ndata, TCPheadersize, header[0], header[1], header[7]); #ifdef USE_CALO_SIMULATOR pthread_mutex_lock( &(calo_simulator_thread_info.mutex_data) ); ndata = write( datasockfd, calo_simulator_thread_info.data, TCPdatasize); pthread_mutex_unlock( &(calo_simulator_thread_info.mutex_data) ); #else unsigned int *data; data = (unsigned short int*) malloc( TCPdatasize ); memset(data, 0, TCPdatasize ); ndata = write( datasockfd, data, TCPdatasize ); #endif if (ndata < 0) { cm_msg(MERROR, __FILE__, "Cannot write data to socket"); return FE_ERR_HW; } dbprintf("%s(%d): write data, data socket %d, write return %d, data size [bytes] %d\n", __func__, __LINE__, datasockfd, ndata, TCPdatasize); unsigned int *tail; tail = (unsigned int*) malloc( TCPtailsize ); for (it = 0; it < TCPtailsize/sizeof(tail[0]); it++){ tail[it] = 0; } tail[0] = TCPdatasize; tail[1] = EMULATORfillnumber; tail[2] = 0; tail[3] = trigger_info.time_master_got_eof_s; tail[4] = trigger_info.time_master_got_eof_us; tail[5] = trigger_info.time_slave_got_eof_s; tail[6] = trigger_info.time_slave_got_eof_us; tail[7] = EODdelimiter; ndata = write( datasockfd, tail, TCPtailsize ); if (ndata < 0) { cm_msg(MERROR, __FILE__, "Cannot write tail to socket"); return FE_ERR_HW; } dbprintf("%s(%d): write trailer, data socket %d, write return %d, trailer size [bytes] %d, data size [bytes] %d, event num %d, delimiter 0x%08x\n", __func__, __LINE__, datasockfd, ndata, TCPtailsize, tail[0], tail[1], tail[7]); free(header); #ifndef USE_CALO_SIMULATOR free(data); #endif free(tail); EMULATORfillnumber++; return 0; }
INT multi_init(EQUIPMENT * pequipment) { int status, size, i, j, index, ch_offset; char str[256]; HNDLE hDB, hKey, hNamesIn, hNamesOut; MULTI_INFO *m_info; BOOL partially_disabled; /* allocate private data */ pequipment->cd_info = calloc(1, sizeof(MULTI_INFO)); m_info = (MULTI_INFO *) pequipment->cd_info; /* get class driver root key */ cm_get_experiment_database(&hDB, NULL); sprintf(str, "/Equipment/%s", pequipment->name); db_create_key(hDB, 0, str, TID_KEY); db_find_key(hDB, 0, str, &m_info->hKeyRoot); /* save event format */ size = sizeof(str); db_get_value(hDB, m_info->hKeyRoot, "Common/Format", str, &size, TID_STRING, TRUE); if (equal_ustring(str, "Fixed")) m_info->format = FORMAT_FIXED; else if (equal_ustring(str, "MIDAS")) m_info->format = FORMAT_MIDAS; else if (equal_ustring(str, "YBOS")) m_info->format = FORMAT_YBOS; /* count total number of channels */ for (i = m_info->num_channels_input = m_info->num_channels_output = 0; pequipment->driver[i].name[0]; i++) { if (pequipment->driver[i].flags & DF_INPUT) m_info->num_channels_input += pequipment->driver[i].channels; if (pequipment->driver[i].flags & DF_OUTPUT) m_info->num_channels_output += pequipment->driver[i].channels; } if (m_info->num_channels_input == 0 && m_info->num_channels_output == 0) { cm_msg(MERROR, "multi_init", "No channels found in device driver list"); return FE_ERR_ODB; } /* Allocate memory for buffers */ if (m_info->num_channels_input) { m_info->names_input = (char *) calloc(m_info->num_channels_input, NAME_LENGTH); m_info->var_input = (float *) calloc(m_info->num_channels_input, sizeof(float)); m_info->update_threshold = (float *) calloc(m_info->num_channels_input, sizeof(float)); m_info->offset_input = (float *) calloc(m_info->num_channels_input, sizeof(float)); m_info->factor_input = (float *) calloc(m_info->num_channels_input, sizeof(float)); m_info->input_mirror = (float *) calloc(m_info->num_channels_input, sizeof(float)); m_info->channel_offset_input = (INT *) calloc(m_info->num_channels_input, sizeof(INT)); m_info->driver_input = (void *) calloc(m_info->num_channels_input, sizeof(void *)); } if (m_info->num_channels_output) { m_info->names_output = (char *) calloc(m_info->num_channels_output, NAME_LENGTH); m_info->var_output = (float *) calloc(m_info->num_channels_output, sizeof(float)); m_info->offset_output = (float *) calloc(m_info->num_channels_output, sizeof(float)); m_info->factor_output = (float *) calloc(m_info->num_channels_output, sizeof(float)); m_info->output_mirror = (float *) calloc(m_info->num_channels_output, sizeof(float)); m_info->channel_offset_output = (INT *) calloc(m_info->num_channels_output, sizeof(DWORD)); m_info->driver_output = (void *) calloc(m_info->num_channels_output, sizeof(void *)); } /*---- Create/Read settings ----*/ if (m_info->num_channels_input) { /* Update threshold */ for (i = 0; i < m_info->num_channels_input; i++) m_info->update_threshold[i] = 0.1f; /* default 0.1 */ db_merge_data(hDB, m_info->hKeyRoot, "Settings/Update Threshold", m_info->update_threshold, m_info->num_channels_input * sizeof(float), m_info->num_channels_input, TID_FLOAT); db_find_key(hDB, m_info->hKeyRoot, "Settings/Update Threshold", &hKey); db_open_record(hDB, hKey, m_info->update_threshold, m_info->num_channels_input * sizeof(float), MODE_READ, NULL, NULL); /* Offset */ for (i = 0; i < m_info->num_channels_input; i++) m_info->offset_input[i] = 0.f; /* default 0 */ db_merge_data(hDB, m_info->hKeyRoot, "Settings/Input Offset", m_info->offset_input, m_info->num_channels_input * sizeof(float), m_info->num_channels_input, TID_FLOAT); db_find_key(hDB, m_info->hKeyRoot, "Settings/Input Offset", &hKey); db_open_record(hDB, hKey, m_info->offset_input, m_info->num_channels_input * sizeof(float), MODE_READ, NULL, NULL); } for (i = 0; i < m_info->num_channels_output; i++) m_info->offset_output[i] = 0.f; if (m_info->num_channels_output) { db_merge_data(hDB, m_info->hKeyRoot, "Settings/Output Offset", m_info->offset_output, m_info->num_channels_output * sizeof(float), m_info->num_channels_output, TID_FLOAT); db_find_key(hDB, m_info->hKeyRoot, "Settings/Output Offset", &hKey); db_open_record(hDB, hKey, m_info->offset_output, m_info->num_channels_output * sizeof(float), MODE_READ, NULL, NULL); } /* Factor */ for (i = 0; i < m_info->num_channels_input; i++) m_info->factor_input[i] = 1.f; /* default 1 */ if (m_info->num_channels_input) { db_merge_data(hDB, m_info->hKeyRoot, "Settings/Input Factor", m_info->factor_input, m_info->num_channels_input * sizeof(float), m_info->num_channels_input, TID_FLOAT); db_find_key(hDB, m_info->hKeyRoot, "Settings/Input factor", &hKey); db_open_record(hDB, hKey, m_info->factor_input, m_info->num_channels_input * sizeof(float), MODE_READ, NULL, NULL); } if (m_info->num_channels_output) { for (i = 0; i < m_info->num_channels_output; i++) m_info->factor_output[i] = 1.f; db_merge_data(hDB, m_info->hKeyRoot, "Settings/Output Factor", m_info->factor_output, m_info->num_channels_output * sizeof(float), m_info->num_channels_output, TID_FLOAT); db_find_key(hDB, m_info->hKeyRoot, "Settings/Output factor", &hKey); db_open_record(hDB, hKey, m_info->factor_output, m_info->num_channels_output * sizeof(float), MODE_READ, NULL, NULL); } /*---- Create/Read variables ----*/ /* Input */ if (m_info->num_channels_input) { db_merge_data(hDB, m_info->hKeyRoot, "Variables/Input", m_info->var_input, m_info->num_channels_input * sizeof(float), m_info->num_channels_input, TID_FLOAT); db_find_key(hDB, m_info->hKeyRoot, "Variables/Input", &m_info->hKeyInput); memcpy(m_info->input_mirror, m_info->var_input, m_info->num_channels_input * sizeof(float)); } /* Output */ if (m_info->num_channels_output) { db_merge_data(hDB, m_info->hKeyRoot, "Variables/Output", m_info->var_output, m_info->num_channels_output * sizeof(float), m_info->num_channels_output, TID_FLOAT); db_find_key(hDB, m_info->hKeyRoot, "Variables/Output", &m_info->hKeyOutput); } /*---- Initialize device drivers ----*/ /* call init method */ partially_disabled = FALSE; for (i = 0; pequipment->driver[i].name[0]; i++) { sprintf(str, "Settings/Devices/%s", pequipment->driver[i].name); status = db_find_key(hDB, m_info->hKeyRoot, str, &hKey); if (status != DB_SUCCESS) { db_create_key(hDB, m_info->hKeyRoot, str, TID_KEY); status = db_find_key(hDB, m_info->hKeyRoot, str, &hKey); if (status != DB_SUCCESS) { cm_msg(MERROR, "multi_init", "Cannot create %s entry in online database", str); free_mem(m_info); return FE_ERR_ODB; } } /* check enabled flag */ size = sizeof(pequipment->driver[i].enabled); pequipment->driver[i].enabled = 1; sprintf(str, "Settings/Devices/%s/Enabled", pequipment->driver[i].name); status = db_get_value(hDB, m_info->hKeyRoot, str, &pequipment->driver[i].enabled, &size, TID_BOOL, TRUE); if (status != DB_SUCCESS) return FE_ERR_ODB; if (pequipment->driver[i].enabled) { status = device_driver(&pequipment->driver[i], CMD_INIT, hKey); if (status != FE_SUCCESS) { free_mem(m_info); return status; } } else partially_disabled = TRUE; } /* compose device driver channel assignment */ for (i = 0, j = 0, index = 0, ch_offset = 0; i < m_info->num_channels_input; i++, j++) { while (pequipment->driver[index].name[0] && (j >= pequipment->driver[index].channels || (pequipment->driver[index].flags & DF_INPUT) == 0)) { ch_offset += j; index++; j = 0; } m_info->driver_input[i] = &pequipment->driver[index]; m_info->channel_offset_input[i] = ch_offset; } for (i = 0, j = 0, index = 0, ch_offset = 0; i < m_info->num_channels_output; i++, j++) { while (pequipment->driver[index].name[0] && (j >= pequipment->driver[index].channels || (pequipment->driver[index].flags & DF_OUTPUT) == 0)) { ch_offset += j; index++; j = 0; } m_info->driver_output[i] = &pequipment->driver[index]; m_info->channel_offset_output[i] = ch_offset; } /*---- get default names from device driver ----*/ if (m_info->num_channels_input) { for (i = 0; i < m_info->num_channels_input; i++) { sprintf(m_info->names_input + NAME_LENGTH * i, "Input Channel %d", i); device_driver(m_info->driver_input[i], CMD_GET_LABEL, i - m_info->channel_offset_input[i], m_info->names_input + NAME_LENGTH * i); /* merge existing names with labels from driver */ status = db_find_key(hDB, m_info->hKeyRoot, "Settings/Names Input", &hKey); if (status != DB_SUCCESS) { db_create_key(hDB, m_info->hKeyRoot, "Settings/Names Input", TID_STRING); db_find_key(hDB, m_info->hKeyRoot, "Settings/Names Input", &hKey); db_set_data(hDB, hKey, m_info->names_input, NAME_LENGTH, 1, TID_STRING); } else { size = sizeof(str); db_get_data_index(hDB, hKey, str, &size, i, TID_STRING); if (!str[0]) db_set_data_index(hDB, hKey, m_info->names_input+NAME_LENGTH*i, NAME_LENGTH, i, TID_STRING); } } } if (m_info->num_channels_output) { for (i = 0; i < m_info->num_channels_output; i++) { sprintf(m_info->names_output + NAME_LENGTH * i, "Output Channel %d", i); device_driver(m_info->driver_output[i], CMD_GET_LABEL, i - m_info->channel_offset_output[i], m_info->names_output + NAME_LENGTH * i); /* merge existing names with labels from driver */ status = db_find_key(hDB, m_info->hKeyRoot, "Settings/Names Output", &hKey); if (status != DB_SUCCESS) { db_create_key(hDB, m_info->hKeyRoot, "Settings/Names Output", TID_STRING); db_find_key(hDB, m_info->hKeyRoot, "Settings/Names Output", &hKey); db_set_data(hDB, hKey, m_info->names_input, NAME_LENGTH, 1, TID_STRING); } else { size = sizeof(str); db_get_data_index(hDB, hKey, str, &size, i, TID_STRING); if (!str[0]) db_set_data_index(hDB, hKey, m_info->names_input+NAME_LENGTH*i, NAME_LENGTH, i, TID_STRING); } } } /*---- set labels from midas SC names ----*/ if (m_info->num_channels_input) { for (i = 0; i < m_info->num_channels_input; i++) { device_driver(m_info->driver_input[i], CMD_SET_LABEL, i - m_info->channel_offset_input[i], m_info->names_input + NAME_LENGTH * i); } /* open hotlink on input channel names */ if (db_find_key(hDB, m_info->hKeyRoot, "Settings/Names Input", &hNamesIn) == DB_SUCCESS) db_open_record(hDB, hNamesIn, m_info->names_input, NAME_LENGTH * m_info->num_channels_input, MODE_READ, multi_update_label, pequipment); } for (i = 0; i < m_info->num_channels_output; i++) { device_driver(m_info->driver_output[i], CMD_SET_LABEL, i - m_info->channel_offset_output[i], m_info->names_output + NAME_LENGTH * i); } /* open hotlink on output channel names */ if (m_info->num_channels_output) { if (db_find_key(hDB, m_info->hKeyRoot, "Settings/Names Output", &hNamesOut) == DB_SUCCESS) db_open_record(hDB, hNamesOut, m_info->names_output, NAME_LENGTH * m_info->num_channels_output, MODE_READ, multi_update_label, pequipment); /* open hot link to output record */ db_open_record(hDB, m_info->hKeyOutput, m_info->var_output, m_info->num_channels_output * sizeof(float), MODE_READ, multi_output, pequipment); } /* set initial demand values */ for (i = 0; i < m_info->num_channels_output; i++) { if (pequipment->driver[index].flags & DF_PRIO_DEVICE) { /* read default value directly from device bypassing multi-thread buffer */ device_driver(m_info->driver_output[i], CMD_GET_DEMAND, i - m_info->channel_offset_output[i], &m_info->output_mirror[i]); } else { /* use default value from ODB */ m_info->output_mirror[i] = m_info->var_output[i] * m_info->factor_output[i] - m_info->offset_output[i]; device_driver(m_info->driver_output[i], CMD_SET, i - m_info->channel_offset_output[i], m_info->output_mirror[i]); } } if (m_info->num_channels_output) db_set_record(hDB, m_info->hKeyOutput, m_info->output_mirror, m_info->num_channels_output * sizeof(float), 0); /* initially read all input channels */ if (m_info->num_channels_input) multi_read(pequipment, -1); if (partially_disabled) return FE_PARTIALLY_DISABLED; return FE_SUCCESS; }
INT register_equipment(void) { INT index, size, status; char str[256]; EQUIPMENT_INFO *eq_info; EQUIPMENT_STATS *eq_stats; HNDLE hKey; /* get current ODB run state */ size = sizeof(run_state); run_state = STATE_STOPPED; db_get_value(hDB, 0, "/Runinfo/State", &run_state, &size, TID_INT, TRUE); size = sizeof(run_number); run_number = 1; status = db_get_value(hDB, 0, "/Runinfo/Run number", &run_number, &size, TID_INT, TRUE); assert(status == SUCCESS); /* scan EQUIPMENT table from mevb.C */ for (index = 0; equipment[index].name[0]; index++) { eq_info = &equipment[index].info; eq_stats = &equipment[index].stats; if (eq_info->event_id == 0) { printf("\nEvent ID 0 for %s not allowed\n", equipment[index].name); cm_disconnect_experiment(); ss_sleep(5000); exit(0); } /* init status */ equipment[index].status = EB_SUCCESS; sprintf(str, "/Equipment/%s/Common", equipment[index].name); /* get last event limit from ODB */ if (eq_info->eq_type != EQ_SLOW) { db_find_key(hDB, 0, str, &hKey); size = sizeof(double); if (hKey) db_get_value(hDB, hKey, "Event limit", &eq_info->event_limit, &size, TID_DOUBLE, TRUE); } /* Create common subtree */ status = db_check_record(hDB, 0, str, EQUIPMENT_COMMON_STR, TRUE); if (status != DB_SUCCESS) { printf("Cannot check equipment record, status = %d\n", status); ss_sleep(3000); } db_find_key(hDB, 0, str, &hKey); if (equal_ustring(eq_info->format, "FIXED")) equipment[index].format = FORMAT_FIXED; else /* default format is MIDAS */ equipment[index].format = FORMAT_MIDAS; gethostname(eq_info->frontend_host, sizeof(eq_info->frontend_host)); strcpy(eq_info->frontend_name, frontend_name); strcpy(eq_info->frontend_file_name, frontend_file_name); /* set record from equipment[] table in frontend.c */ db_set_record(hDB, hKey, eq_info, sizeof(EQUIPMENT_INFO), 0); /* get record once at the start equipment info */ size = sizeof(EQUIPMENT_INFO); db_get_record(hDB, hKey, eq_info, &size, 0); /*---- Create just the key , leave it empty ---------------------------------*/ sprintf(str, "/Equipment/%s/Variables", equipment[index].name); db_create_key(hDB, 0, str, TID_KEY); db_find_key(hDB, 0, str, &hKey); equipment[index].hkey_variables = hKey; /*---- Create and initialize statistics tree -------------------*/ sprintf(str, "/Equipment/%s/Statistics", equipment[index].name); status = db_check_record(hDB, 0, str, EQUIPMENT_STATISTICS_STR, TRUE); if (status != DB_SUCCESS) { printf("Cannot create/check statistics record, error %d\n", status); ss_sleep(3000); } status = db_find_key(hDB, 0, str, &hKey); if (status != DB_SUCCESS) { printf("Cannot find statistics record, error %d\n", status); ss_sleep(3000); } eq_stats->events_sent = 0; eq_stats->events_per_sec = 0; eq_stats->kbytes_per_sec = 0; /* open hot link to statistics tree */ status = db_open_record(hDB, hKey, eq_stats, sizeof(EQUIPMENT_STATS) , MODE_WRITE, NULL, NULL); if (status != DB_SUCCESS) { cm_msg(MERROR, "register_equipment", "Cannot open statistics record, error %d. Probably other FE is using it", status); ss_sleep(3000); } /*---- open event buffer ---------------------------------------*/ if (eq_info->buffer[0]) { status = bm_open_buffer(eq_info->buffer, 2 * max_event_size, &equipment[index].buffer_handle); if (status != BM_SUCCESS && status != BM_CREATED) { cm_msg(MERROR, "register_equipment", "Cannot open event buffer. Try to reduce EVENT_BUFFER_SIZE in midas.h \ and rebuild the system."); return 0; } if (1) { int level = 0; bm_get_buffer_level(equipment[index].buffer_handle, &level); printf("Buffer %s, level %d, info: \n", eq_info->buffer, level); } /* set the default buffer cache size */ bm_set_cache_size(equipment[index].buffer_handle, 0, SERVER_CACHE_SIZE); } else {
int fb_init() { bt_error_t status; /* Bit 3 library error return type */ char devname[BT_MAX_DEV_NAME]; /* Device to open */ bt_devdata_t flag; /* Open the device in A24 space */ bt_gen_name(0, BT_DEV_A24, devname, BT_MAX_DEV_NAME); status = bt_open(&btd, devname, BT_RDWR); if (status != BT_SUCCESS) { cm_msg(MERROR, "fb_init", "Cannot open Bit3 device driver"); return FALSE; } bt_init(btd); bt_clrerr(btd); /* map SFI memory */ status = bt_mmap(btd, &_sfi, SFI_ADDRESS, SFI_SIZE, BT_RDWR, BT_SWAP_DEFAULT); if (status != BT_SUCCESS) { cm_msg(MERROR, "fb_init", "Cannot map VME memory"); bt_close(btd); return FALSE; } /* Open the device in local memory */ bt_gen_name(0, BT_DEV_LM, devname, BT_MAX_DEV_NAME); status = bt_open(&btd_lm, devname, BT_RDWR); if (status != BT_SUCCESS) { cm_msg(MERROR, "fb_init", "Cannot open Bit3 device for local memory"); return FALSE; } bt_clrerr(btd_lm); /* map local memory */ status = bt_mmap(btd_lm, &remote_ram_buffer, 0, REMOTE_RAM_SIZE, BT_RDWR, BT_SWAP_DEFAULT); if (status != BT_SUCCESS) { cm_msg(MERROR, "fb_init", "Cannot map local memory"); bt_close(btd); return FALSE; } /* clear local memory */ memset(remote_ram_buffer, 0, REMOTE_RAM_SIZE); /* force D32 mode */ bt_get_info(btd, BT_INFO_MMAP_AMOD, &flag); flag = BT_AMOD_A24_SD; bt_set_info(btd, BT_INFO_MMAP_AMOD, flag); /* sequencer reset */ SFI_OUT(SFI_SEQUENCER_RESET, 0); /* arbitration level */ // SFI_OUT(SFI_FASTBUS_ARBITRATION_LEVEL_REGISTER, 0x15); SFI_OUT(SFI_FASTBUS_ARBITRATION_LEVEL_REGISTER, 0xBF); /* timeout */ SFI_OUT(SFI_FASTBUS_TIMEOUT_REGISTER, 0x73); /* sequencer enable */ SFI_OUT(SFI_SEQUENCER_ENABLE, 0); /* switch off all output */ SFI_OUT(SFI_CLEAR_BOTH_LCA1_TEST_REGISTER, 0); /* clear registers */ SFI_OUT(SFI_RESET_REGISTER_GROUP_LCA2, 0); return SUCCESS; }
unsigned int tcp_server_init(void) { int i, status; /* get configured network interfaces from ODB */ int eth_nused[TCP_THREAD_NUM_MAX]; for (i=0; i<TCP_THREAD_NUM_MAX; i++) { eth_nused[i] = 0; } eth_nused[0] = 1; // quick fix, one interface for (i=0; i<TCP_THREAD_NUM_MAX; i++) { if ( eth_nused[i] == 0 ) continue; serversockfd = socket(AF_INET, SOCK_STREAM, 0); if (serversockfd < 0) { cm_msg(MERROR, __FILE__, "Cannot obtain a socket"); return FE_ERR_HW; } dbprintf("%s(%d): obtain socket, return file descriptor %d \n", __func__, __LINE__, serversockfd ); struct sockaddr_in serv_addr; bzero((char *) &serv_addr, sizeof(serv_addr)); inet_aton( amc13_link_odb[i].readout_ip, &serv_addr.sin_addr); serv_addr.sin_port = htons(amc13_link_odb[i].port_no); status = bind( serversockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)); if (status < 0 ) { cm_msg(MERROR, __FILE__, "Cannot bind to socket"); return FE_ERR_HW; } dbprintf("%s(%d): socket bind, ip address %s, port no %d, status %d \n", __func__, __LINE__, amc13_link_odb[i].readout_ip, amc13_link_odb[i].port_no, status ); status = listen(serversockfd,5); if (status < 0 ) { cm_msg(MERROR, __FILE__, "Cannot listen to socket"); return FE_ERR_HW; } dbprintf("%s(%d): socket listen, ip address %s, port no %d, status %d \n", __func__, __LINE__, amc13_link_odb[i].readout_ip, amc13_link_odb[i].port_no, status ); struct sockaddr_in cli_addr; socklen_t clilen = sizeof(cli_addr); datasockfd = accept(serversockfd, (struct sockaddr *) &cli_addr, &clilen); // blocks until client connects if (datasockfd < 0) { cm_msg(MERROR, __FILE__, "Cannot accept on socket"); return FE_ERR_HW; } dbprintf("%s(%d): socket accept, return file descriptor %d \n", __func__, __LINE__, datasockfd); } return 0; }
unsigned int tcp_server_init(void) { int i, status; /* get configured network interfaces from ODB */ int eth_nused[TCP_THREAD_NUM_MAX]; for (i=0; i<TCP_THREAD_NUM_MAX; i++) { eth_nused[i] = 0; } eth_nused[0] = 1; // quick fix, one interface for (i=0; i<TCP_THREAD_NUM_MAX; i++) { if ( eth_nused[i] == 0 ) continue; serversockfd = socket(AF_INET, SOCK_STREAM, 0); if (serversockfd < 0) { cm_msg(MERROR, __FILE__, "Cannot obtain a socket"); return FE_ERR_HW; } dbprintf("%s(%d): obtain socket, return file descriptor %d \n", __func__, __LINE__, serversockfd ); // set the size in bytes of the receive buffer for large events. Default values // are set in /proc/sys/net/core/rmem_default and /proc/sys/net/core/rmem_max // use /sbin/sysctl -w net.ipv4.tcp_rmem='4096 87380 536870912' to modify int iSocketOption = 0x20000000, iSocketOptionGet = 0; socklen_t iSocketOptionLen = sizeof(int); if ( setsockopt( serversockfd, SOL_SOCKET, SO_SNDBUF, (const char *) &iSocketOption, iSocketOptionLen ) < 0 ){ cm_msg(MERROR, __FILE__, "Cannot set socket buffer size"); return FE_ERR_HW; } if ( getsockopt( serversockfd, SOL_SOCKET, SO_SNDBUF, (char *)&iSocketOptionGet, &iSocketOptionLen ) < 0){ cm_msg(MERROR, __FILE__, "Cannot get socket buffer size"); return FE_ERR_HW; } dbprintf("%s(%d): getsockopt send buffer size set %d size get %d \n", __func__, __LINE__, iSocketOption, iSocketOptionGet ); struct sockaddr_in serv_addr; bzero((char *) &serv_addr, sizeof(serv_addr)); inet_aton( amc13_link_odb[i].source_ip, &serv_addr.sin_addr); serv_addr.sin_port = htons(amc13_link_odb[i].source_port); status = bind( serversockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)); if (status < 0 ) { cm_msg(MERROR, __FILE__, "Cannot bind to socket"); return FE_ERR_HW; } dbprintf("%s(%d): socket bind, ip address %s, port no %d, status %d \n", __func__, __LINE__, amc13_link_odb[i].source_ip, amc13_link_odb[i].source_port, status ); status = listen(serversockfd,5); if (status < 0 ) { cm_msg(MERROR, __FILE__, "Cannot listen to socket"); return FE_ERR_HW; } dbprintf("%s(%d): socket listen, ip address %s, port no %d, status %d \n", __func__, __LINE__, amc13_link_odb[i].source_ip, amc13_link_odb[i].source_port, status ); struct sockaddr_in cli_addr; socklen_t clilen = sizeof(cli_addr); datasockfd = accept(serversockfd, (struct sockaddr *) &cli_addr, &clilen); // blocks until client connects if (datasockfd < 0) { cm_msg(MERROR, __FILE__, "Cannot accept on socket"); return FE_ERR_HW; } dbprintf("%s(%d): socket accept, return file descriptor %d \n", __func__, __LINE__, datasockfd); } // allocate array for adding rider headers to segment waveforms //truthdata = (float*) malloc( sizeof(float) + (int)CALO_SIMULATOR_EVENT_MAX*sizeof(CALO_SIMULATOR_EVENT) ); //std::cout << "Allocating memory " << simulator_event.size() <<" * " << sizeof(CALO_SIMULATOR_EVENT) << std::endl; truthdata = (float*) malloc( sizeof(float) + (int)simulator_event.size()*sizeof(CALO_SIMULATOR_EVENT) ); // calo_simulator_thread_info.data_size has size of island_length * number of calo segments // rider_info.data_size has size of nAMC*nCHAN*island_length + nAMC*(3*4+4*4*nCHAN) rider_info.data_size = calo_simulator_thread_info.waveform_length*nAMC*nCHAN; rider_info.data_size += nAMC*(3*4+4*4*nCHAN); // rider header / trailer accounting dbprintf("pack_rider_data: calo_simulator_thread_info.data_size %i rider_info.data_size %i\n", calo_simulator_thread_info.data_size, rider_info.data_size); rider_info.data = (int16_t*) malloc( rider_info.data_size * sizeof( int16_t ) ); if ( rider_info.data == NULL ) { printf("***ERROR! Cannot allocate memory for rider data"); return -1; } return 0; }
/*! * <p>Constructs the administration class object. This class holds all ODB and * path related variables. * * \param host name of the host * \param exp name of the experiment */ PHvAdmin::PHvAdmin(char *host, char *exp) { fHost = QString(host).stripWhiteSpace(); fExp = QString(exp).stripWhiteSpace(); // initialize flags for ODB pathes fb_DefaultDirHvSettings = false; fb_DefaultDirDocu = false; fb_TerminationTimeout = false; fb_DemandInVPresent = false; fb_MidasOdbHvRoot = false; fb_MidasOdbHvNames = false; fb_MidasOdbHvDemand = false; fb_MidasOdbHvMeasured = false; fb_MidasOdbHvCurrent = false; fb_MidasOdbHvCurrentLimit = false; // init counters fNoOdbRoots = 0; // init termination timeout to a 15 (min) default fTerminationTimeout = 15; // init demand in V default fDemandInV = true; // init ODB path strings to some sensible defaults QString str("/Equipment/HV"); fMidasOdbHvRoot = new QPtrList<QString>(); fMidasOdbHvRoot->setAutoDelete(true); fMidasOdbHvRoot->append(new QString(str)); QString midasRoot; if (getenv("MIDASSYS")) midasRoot = QString(getenv("MIDASSYS")); else midasRoot = QString("."); fDefaultDirHvSettings = midasRoot + QString("/gui/hvedit/qt-3.3/hvEdit/hv_settings"); fDefaultDirDocu = midasRoot + QString("/gui/hvedit/qt-3.3/hvEdit/doc"); fMidasOdbHvNames = QString("Settings/Names"); fMidasOdbHvDemand = QString("Variables/Demand"); fMidasOdbHvMeasured = QString("Variables/Measured"); fMidasOdbHvCurrent = QString("Variables/Current"); fMidasOdbHvCurrentLimit = QString("Settings/Current Limit"); // XML Parser part QString fln = midasRoot+"/gui/hvedit/qt-3.3/hvEdit/bin/xmls/hvEdit-"+fExp+".xml"; if (!QFile::exists(fln)) { // administrations file not found cm_msg(MINFO, "PHvAdmin", "hvEdit: Warning: couldn't find startup administration file (%s), will try some default stuff.", fln.ascii()); } else { PHvAdminXMLParser handler(this); QFile xmlFile(fln); QXmlInputSource source( &xmlFile ); QXmlSimpleReader reader; reader.setContentHandler( &handler ); reader.parse( source ); } // check if XML startup file could be read if (fNoOdbRoots == 0) { fNoOdbRoots = 1; cm_msg(MINFO, "PHvAdmin", "hvEdit: Warning: Number of ODB HV roots is 0, will try 1."); } if (!fb_MidasOdbHvRoot) { cm_msg(MINFO, "PHvAdmin", "hvEdit: Warning: Couldn't read ODB HV root path settings, will " "try '%s' instead.", fMidasOdbHvRoot->at(0)->ascii()); } if (!fb_MidasOdbHvNames) { cm_msg(MINFO, "PHvAdmin", "hvEdit: Warning: Couldn't read ODB HV names path settings, will " "try '%s' instead.", fMidasOdbHvNames.ascii()); } if (!fb_MidasOdbHvDemand) { cm_msg(MINFO, "PHvAdmin", "hvEdit: Warning: Couldn't read ODB HV demand path settings, will " "try '%s' instead.", fMidasOdbHvDemand.ascii()); } if (!fb_MidasOdbHvMeasured) { cm_msg(MINFO, "PHvAdmin", "hvEdit: Warning: Couldn't read ODB HV measured path settings, will " "try '%s' instead.", fMidasOdbHvMeasured.ascii()); } if (!fb_MidasOdbHvCurrent) { cm_msg(MINFO, "PHvAdmin", "hvEdit: Warning: Couldn't read ODB HV current path settings, will " "try '%s' instead.", fMidasOdbHvCurrent.ascii()); } if (!fb_MidasOdbHvCurrentLimit) { cm_msg(MINFO, "PHvAdmin", "hvEdit: Warning: Couldn't read ODB HV demand path settings, will " "try '%s' instead.", fMidasOdbHvCurrentLimit.ascii()); } if (!fb_TerminationTimeout) { cm_msg(MINFO, "PHvAdmin", "hvEdit: Warning: Couldn't read termination timeout, will " "try '%d' instead.", fTerminationTimeout); } if (!fb_DemandInVPresent) { cm_msg(MINFO, "PHvAdmin", "hvEdit: Warning: Couldn't read 'demand in V' flag, will " "try '%d' instead.", fDemandInV); } }
/** Reset (acknoledge) alarm. @param alarm_name Alarm name, defined in /alarms/alarms @return AL_SUCCESS, AL_RESETE, AL_INVALID_NAME */ INT al_reset_alarm(const char *alarm_name) { int status, size, i; HNDLE hDB, hkeyalarm, hkeyclass, hsubkey; KEY key; char str[256]; ALARM a; ALARM_CLASS ac; cm_get_experiment_database(&hDB, NULL); if (alarm_name == NULL) { /* reset all alarms */ db_find_key(hDB, 0, "/Alarms/Alarms", &hkeyalarm); if (hkeyalarm) { for (i = 0;; i++) { db_enum_link(hDB, hkeyalarm, i, &hsubkey); if (!hsubkey) break; db_get_key(hDB, hsubkey, &key); al_reset_alarm(key.name); } } return AL_SUCCESS; } /* find alarm and alarm class */ sprintf(str, "/Alarms/Alarms/%s", alarm_name); db_find_key(hDB, 0, str, &hkeyalarm); if (!hkeyalarm) { /*cm_msg(MERROR, "al_reset_alarm", "Alarm %s not found in ODB", alarm_name);*/ return AL_INVALID_NAME; } size = sizeof(a); status = db_get_record(hDB, hkeyalarm, &a, &size, 0); if (status != DB_SUCCESS) { cm_msg(MERROR, "al_reset_alarm", "Cannot get alarm record"); return AL_ERROR_ODB; } sprintf(str, "/Alarms/Classes/%s", a.alarm_class); db_find_key(hDB, 0, str, &hkeyclass); if (!hkeyclass) { cm_msg(MERROR, "al_reset_alarm", "Alarm class %s not found in ODB", a.alarm_class); return AL_INVALID_NAME; } size = sizeof(ac); status = db_get_record(hDB, hkeyclass, &ac, &size, 0); if (status != DB_SUCCESS) { cm_msg(MERROR, "al_reset_alarm", "Cannot get alarm class record"); return AL_ERROR_ODB; } if (a.triggered) { a.triggered = 0; a.time_triggered_first[0] = 0; a.time_triggered_last[0] = 0; a.checked_last = 0; ac.system_message_last = 0; ac.execute_last = 0; status = db_set_record(hDB, hkeyalarm, &a, sizeof(a), 0); if (status != DB_SUCCESS) { cm_msg(MERROR, "al_reset_alarm", "Cannot update alarm record"); return AL_ERROR_ODB; } status = db_set_record(hDB, hkeyclass, &ac, sizeof(ac), 0); if (status != DB_SUCCESS) { cm_msg(MERROR, "al_reset_alarm", "Cannot update alarm class record"); return AL_ERROR_ODB; } cm_msg(MINFO, "al_reset_alarm", "Alarm \"%s\" reset", alarm_name); return AL_RESET; } return AL_SUCCESS; }