analyzer.c

Go to the documentation of this file.
00001 /********************************************************************\
00002 
00003   Name:         analyzer.c
00004   Created by:   Stefan Ritt
00005 
00006   Contents:     System part of Analyzer code for sample experiment
00007 
00008   $Id: analyzer.c 2753 2005-10-07 14:55:31Z ritt $
00009 
00010 \********************************************************************/
00011 
00012 /* standard includes */
00013 #include <stdio.h>
00014 #include <string.h>
00015 #include <time.h>
00016 
00017 /* midas includes */
00018 #include "midas.h"
00019 #include "experim.h"
00020 #include "analyzer.h"
00021 
00022 /* cernlib includes */
00023 #ifdef OS_WINNT
00024 #define VISUAL_CPLUSPLUS
00025 #endif
00026 #ifdef __linux__
00027 #define f2cFortran
00028 #endif
00029 
00030 #ifdef HAVE_HBOOK
00031 #include <cfortran.h>
00032 #include <hbook.h>
00033 
00034 PAWC_DEFINE(1000000);
00035 #endif                          /* HAVE_HBOOK */
00036 
00037 /*-- Globals -------------------------------------------------------*/
00038 
00039 /* The analyzer name (client name) as seen by other MIDAS clients   */
00040 char *analyzer_name = "Analyzer";
00041 
00042 /* analyzer_loop is called with this interval in ms (0 to disable)  */
00043 INT analyzer_loop_period = 0;
00044 
00045 /* default ODB size */
00046 INT odb_size = DEFAULT_ODB_SIZE;
00047 
00048 /* ODB structures */
00049 RUNINFO runinfo;
00050 GLOBAL_PARAM global_param;
00051 EXP_PARAM exp_param;
00052 TRIGGER_SETTINGS trigger_settings;
00053 
00054 /*-- Module declarations -------------------------------------------*/
00055 
00056 extern ANA_MODULE scaler_accum_module;
00057 extern ANA_MODULE adc_calib_module;
00058 extern ANA_MODULE adc_summing_module;
00059 
00060 ANA_MODULE *scaler_module[] = {
00061    &scaler_accum_module,
00062    NULL
00063 };
00064 
00065 ANA_MODULE *trigger_module[] = {
00066    &adc_calib_module,
00067    &adc_summing_module,
00068    NULL
00069 };
00070 
00071 /*-- Bank definitions ----------------------------------------------*/
00072 
00073 ASUM_BANK_STR(asum_bank_str);
00074 
00075 BANK_LIST ana_trigger_bank_list[] = {
00076 
00077    /* online banks */
00078    {"ADC0", TID_WORD, N_ADC, NULL},
00079    {"TDC0", TID_WORD, N_TDC, NULL},
00080 
00081    /* calculated banks */
00082    {"CADC", TID_FLOAT, N_ADC, NULL},
00083    {"ASUM", TID_STRUCT, sizeof(ASUM_BANK), asum_bank_str},
00084 
00085    {""},
00086 };
00087 
00088 BANK_LIST ana_scaler_bank_list[] = {
00089    /* online banks */
00090    {"SCLR", TID_DWORD, N_ADC, NULL},
00091 
00092    /* calculated banks */
00093    {"ACUM", TID_DOUBLE, N_ADC, NULL},
00094    {""},
00095 };
00096 
00097 /*-- Event request list --------------------------------------------*/
00098 
00099 ANALYZE_REQUEST analyze_request[] = {
00100    {"Trigger",                  /* equipment name */
00101     {1,                         /* event ID */
00102      TRIGGER_ALL,               /* trigger mask */
00103      GET_SOME,                  /* get some events */
00104      "SYSTEM",                  /* event buffer */
00105      TRUE,                      /* enabled */
00106      "", "",}
00107     ,
00108     NULL,                       /* analyzer routine */
00109     trigger_module,             /* module list */
00110     ana_trigger_bank_list,      /* bank list */
00111     1000,                       /* RWNT buffer size */
00112     TRUE,                       /* Use tests for this event */
00113     }
00114    ,
00115 
00116    {"Scaler",                   /* equipment name */
00117     {2,                         /* event ID */
00118      TRIGGER_ALL,               /* trigger mask */
00119      GET_ALL,                   /* get all events */
00120      "SYSTEM",                  /* event buffer */
00121      TRUE,                      /* enabled */
00122      "", "",}
00123     ,
00124     NULL,                       /* analyzer routine */
00125     scaler_module,              /* module list */
00126     ana_scaler_bank_list,       /* bank list */
00127     100,                        /* RWNT buffer size */
00128     }
00129    ,
00130 
00131    {""}
00132    ,
00133 };
00134 
00135 /*-- Analyzer Init -------------------------------------------------*/
00136 
00137 INT analyzer_init()
00138 {
00139    HNDLE hDB, hKey;
00140    char str[80];
00141 
00142    RUNINFO_STR(runinfo_str);
00143    EXP_PARAM_STR(exp_param_str);
00144    GLOBAL_PARAM_STR(global_param_str);
00145    TRIGGER_SETTINGS_STR(trigger_settings_str);
00146 
00147    /* open ODB structures */
00148    cm_get_experiment_database(&hDB, NULL);
00149    db_create_record(hDB, 0, "/Runinfo", strcomb(runinfo_str));
00150    db_find_key(hDB, 0, "/Runinfo", &hKey);
00151    if (db_open_record(hDB, hKey, &runinfo, sizeof(runinfo), MODE_READ, NULL, NULL) !=
00152        DB_SUCCESS) {
00153       cm_msg(MERROR, "analyzer_init", "Cannot open \"/Runinfo\" tree in ODB");
00154       return 0;
00155    }
00156 
00157    db_create_record(hDB, 0, "/Experiment/Run Parameters", strcomb(exp_param_str));
00158    db_find_key(hDB, 0, "/Experiment/Run Parameters", &hKey);
00159    if (db_open_record(hDB, hKey, &exp_param, sizeof(exp_param), MODE_READ, NULL, NULL) !=
00160        DB_SUCCESS) {
00161       cm_msg(MERROR, "analyzer_init",
00162              "Cannot open \"/Experiment/Run Parameters\" tree in ODB");
00163       return 0;
00164    }
00165 
00166    sprintf(str, "/%s/Parameters/Global", analyzer_name);
00167    db_create_record(hDB, 0, str, strcomb(global_param_str));
00168    db_find_key(hDB, 0, str, &hKey);
00169    if (db_open_record
00170        (hDB, hKey, &global_param, sizeof(global_param), MODE_READ, NULL,
00171         NULL) != DB_SUCCESS) {
00172       cm_msg(MERROR, "analyzer_init", "Cannot open \"%s\" tree in ODB", str);
00173       return 0;
00174    }
00175 
00176    db_create_record(hDB, 0, "/Equipment/Trigger/Settings", strcomb(trigger_settings_str));
00177    db_find_key(hDB, 0, "/Equipment/Trigger/Settings", &hKey);
00178 
00179    if (db_open_record
00180        (hDB, hKey, &trigger_settings, sizeof(trigger_settings), MODE_READ, NULL,
00181         NULL) != DB_SUCCESS) {
00182       cm_msg(MERROR, "analyzer_init",
00183              "Cannot open \"/Equipment/Trigger/Settings\" tree in ODB");
00184       return 0;
00185    }
00186 
00187    return SUCCESS;
00188 }
00189 
00190 /*-- Analyzer Exit -------------------------------------------------*/
00191 
00192 INT analyzer_exit()
00193 {
00194    return CM_SUCCESS;
00195 }
00196 
00197 /*-- Begin of Run --------------------------------------------------*/
00198 
00199 INT ana_begin_of_run(INT run_number, char *error)
00200 {
00201    return CM_SUCCESS;
00202 }
00203 
00204 /*-- End of Run ----------------------------------------------------*/
00205 
00206 INT ana_end_of_run(INT run_number, char *error)
00207 {
00208    FILE *f;
00209    time_t now;
00210    char str[256];
00211    int size;
00212    double n;
00213    HNDLE hDB;
00214    BOOL flag;
00215 
00216    cm_get_experiment_database(&hDB, NULL);
00217 
00218    /* update run log if run was written and running online */
00219 
00220    size = sizeof(flag);
00221    db_get_value(hDB, 0, "/Logger/Write data", &flag, &size, TID_BOOL, TRUE);
00222    if (flag && runinfo.online_mode == 1) {
00223       /* update run log */
00224       size = sizeof(str);
00225       str[0] = 0;
00226       db_get_value(hDB, 0, "/Logger/Data Dir", str, &size, TID_STRING, TRUE);
00227       if (str[0] != 0)
00228          if (str[strlen(str) - 1] != DIR_SEPARATOR)
00229             strcat(str, DIR_SEPARATOR_STR);
00230       strcat(str, "runlog.txt");
00231 
00232       f = fopen(str, "a");
00233 
00234       time(&now);
00235       strcpy(str, ctime(&now));
00236       str[10] = 0;
00237 
00238       fprintf(f, "%s\t%3d\t", str, runinfo.run_number);
00239 
00240       strcpy(str, runinfo.start_time);
00241       str[19] = 0;
00242       fprintf(f, "%s\t", str + 11);
00243 
00244       strcpy(str, ctime(&now));
00245       str[19] = 0;
00246       fprintf(f, "%s\t", str + 11);
00247 
00248       size = sizeof(n);
00249       db_get_value(hDB, 0, "/Equipment/Trigger/Statistics/Events sent", &n, &size,
00250                    TID_DOUBLE, TRUE);
00251 
00252       fprintf(f, "%5.1lfk\t", n / 1000);
00253       fprintf(f, "%s\n", exp_param.comment);
00254 
00255       fclose(f);
00256    }
00257 
00258    return CM_SUCCESS;
00259 }
00260 
00261 /*-- Pause Run -----------------------------------------------------*/
00262 
00263 INT ana_pause_run(INT run_number, char *error)
00264 {
00265    return CM_SUCCESS;
00266 }
00267 
00268 /*-- Resume Run ----------------------------------------------------*/
00269 
00270 INT ana_resume_run(INT run_number, char *error)
00271 {
00272    return CM_SUCCESS;
00273 }
00274 
00275 /*-- Analyzer Loop -------------------------------------------------*/
00276 
00277 INT analyzer_loop()
00278 {
00279    return CM_SUCCESS;
00280 }
00281 
00282 /*------------------------------------------------------------------*/

Midas DOC Version 1.9.5 ---- PSI Stefan Ritt ----
Contributions: Pierre-Andre Amaudruz - Sergio Ballestrero - Suzannah Daviel - Doxygen - Peter Green - Qing Gu - Greg Hackman - Gertjan Hofman - Paul Knowles - Rudi Meier - Glenn Moloney - Dave Morris - John M O'Donnell - Konstantin Olchanski - Renee Poutissou - Tamsen Schurman - Andreas Suter - Jan M.Wouters - Piotr Adam Zolnierczuk