history_midas.cxx File Reference

Go to the source code of this file.

Data Structures

class  MidasHistory

Defines

#define STRLCPY(dst, src)   strlcpy(dst, src, sizeof(dst))

Functions

static WORD get_variable_id (DWORD ltime, const char *evname, const char *tagname)
static WORD get_variable_id_tags (const char *evname, const char *tagname)
static int get_event_id (const char *event_name)
MidasHistoryInterfaceMakeMidasHistory ()


Define Documentation

#define STRLCPY ( dst,
src   )     strlcpy(dst, src, sizeof(dst))

Definition at line 23 of file history_midas.cxx.

Referenced by add_vars(), build_log_list(), get_event_id(), MidasHistory::GetTagsFromEquipment(), MidasHistory::GetTagsFromOdb(), SqlHistory::hs_get_tags(), hs_get_tags_odbc(), load_vars_odb(), load_vars_param(), and show_hist_config_page().


Function Documentation

static int get_event_id ( const char *  event_name  )  [static]

Definition at line 179 of file history_midas.cxx.

Referenced by MidasHistory::hs_define_event(), and open_history().

00180 {
00181    HNDLE hDB, hKeyRoot;
00182    int status, i;
00183    char name[256];
00184    STRLCPY(name, event_name);
00185    char *s = strchr(name, '/');
00186    if (s)
00187       *s = ':';
00188 
00189    //printf("Looking for event id for \'%s\'\n", name);
00190 
00191    cm_get_experiment_database(&hDB, NULL);
00192    
00193    status = db_find_key(hDB, 0, "/History/Events", &hKeyRoot);
00194    if (status == DB_SUCCESS) {
00195       for (i = 0;; i++) {
00196          HNDLE hKey;
00197          KEY key;
00198          WORD evid;
00199          int size;
00200          char tmp[NAME_LENGTH+NAME_LENGTH+2];
00201          
00202          status = db_enum_key(hDB, hKeyRoot, i, &hKey);
00203          if (status != DB_SUCCESS)
00204            break;
00205          
00206          status = db_get_key(hDB, hKey, &key);
00207          assert(status == DB_SUCCESS);
00208          
00209          //printf("key \'%s\'\n", key.name);
00210          
00211          evid = (WORD) strtol(key.name, NULL, 0);
00212          if (evid == 0)
00213             continue;
00214 
00215          size = sizeof(tmp);
00216          status = db_get_data(hDB, hKey, tmp, &size, TID_STRING);
00217          //printf("status %d\n", status);
00218          assert(status == DB_SUCCESS);
00219 
00220          //printf("got %d \'%s\' looking for \'%s\'\n", evid, tmp, name);
00221 
00222          if (equal_ustring(name, tmp))
00223             return evid;
00224       }
00225    }
00226 
00227    int max_id = 100;
00228 
00229    // special event id for run transitions
00230    if (strcmp(name, "Run transitions")==0) {
00231       status = db_set_value(hDB, 0, "/History/Events/0", name, strlen(name)+1, 1, TID_STRING);
00232       assert(status == DB_SUCCESS);
00233       return 0;
00234    }
00235 
00236    while (1) {
00237       char tmp[NAME_LENGTH+NAME_LENGTH+2];
00238       HNDLE hKey;
00239       WORD evid = max_id + 1;
00240 
00241       sprintf(tmp,"/History/Events/%d", evid);
00242 
00243       status = db_find_key(hDB, 0, tmp, &hKey);
00244       if (status == DB_SUCCESS) {
00245          max_id = evid;
00246          assert(max_id < 65000);
00247          continue;
00248       }
00249 
00250       status = db_set_value(hDB, 0, tmp, name, strlen(name)+1, 1, TID_STRING);
00251       assert(status == DB_SUCCESS);
00252 
00253       return evid;
00254    }
00255 
00256    /* not reached */
00257    return -1;
00258 }

static WORD get_variable_id ( DWORD  ltime,
const char *  evname,
const char *  tagname 
) [static]

Definition at line 25 of file history_midas.cxx.

Referenced by MidasHistory::xhs_event_id().

00026 {
00027    HNDLE hDB, hKeyRoot;
00028    int status, i;
00029 
00030    cm_get_experiment_database(&hDB, NULL);
00031    
00032    status = db_find_key(hDB, 0, "/History/Events", &hKeyRoot);
00033    if (status != DB_SUCCESS) {
00034       return 0;
00035    }
00036 
00037    for (i = 0;; i++) {
00038       HNDLE hKey;
00039       KEY key;
00040       WORD evid;
00041       char buf[256];
00042       int size;
00043       char *s;
00044       int j;
00045       int ntags = 0;
00046       TAG* tags = NULL;
00047       char event_name[NAME_LENGTH];
00048 
00049       status = db_enum_key(hDB, hKeyRoot, i, &hKey);
00050       if (status != DB_SUCCESS)
00051          break;
00052 
00053       status = db_get_key(hDB, hKey, &key);
00054       assert(status == DB_SUCCESS);
00055 
00056       if (!isdigit(key.name[0]))
00057          continue;
00058 
00059       evid = atoi(key.name);
00060 
00061       assert(key.item_size < (int)sizeof(buf));
00062 
00063       size = sizeof(buf);
00064       status = db_get_data(hDB, hKey, buf, &size, TID_STRING);
00065       assert(status == DB_SUCCESS);
00066 
00067       strlcpy(event_name, buf, sizeof(event_name));
00068 
00069       s = strchr(buf,':');
00070       if (s)
00071          *s = 0;
00072 
00073       //printf("Found event %d, event [%s] name [%s], looking for [%s][%s]\n", evid, event_name, buf, evname, tagname);
00074 
00075       if (!equal_ustring((char *)evname, buf))
00076          continue;
00077 
00078       status = hs_get_tags(ltime, evid, event_name, &ntags, &tags);
00079 
00080       //printf("status %d, ntags %d\n", status, ntags);
00081 
00082       //status = hs_get_tags(ltime, evid, event_name, &ntags, &tags);
00083 
00084       for (j=0; j<ntags; j++) {
00085          //printf("at %d [%s] looking for [%s]\n", j, tags[j].name, tagname);
00086 
00087          if (equal_ustring((char *)tagname, tags[j].name)) {
00088             if (tags)
00089                free(tags);
00090             return evid;
00091          }
00092       }
00093 
00094       if (tags)
00095          free(tags);
00096       tags = NULL;
00097    }
00098 
00099    return 0;
00100 }

static WORD get_variable_id_tags ( const char *  evname,
const char *  tagname 
) [static]

Definition at line 102 of file history_midas.cxx.

Referenced by MidasHistory::xhs_event_id().

00103 {
00104    HNDLE hDB, hKeyRoot;
00105    int status, i;
00106 
00107    cm_get_experiment_database(&hDB, NULL);
00108    
00109    status = db_find_key(hDB, 0, "/History/Tags", &hKeyRoot);
00110    if (status != DB_SUCCESS) {
00111       return 0;
00112    }
00113 
00114    for (i = 0;; i++) {
00115       HNDLE hKey;
00116       KEY key;
00117       WORD evid;
00118       char buf[256];
00119       int size;
00120       char *s;
00121       int j;
00122 
00123       status = db_enum_key(hDB, hKeyRoot, i, &hKey);
00124       if (status != DB_SUCCESS)
00125          break;
00126 
00127       status = db_get_key(hDB, hKey, &key);
00128       assert(status == DB_SUCCESS);
00129 
00130       if (key.type != TID_STRING)
00131          continue;
00132 
00133       if (!isdigit(key.name[0]))
00134          continue;
00135 
00136       evid = atoi(key.name);
00137 
00138       assert(key.item_size < (int)sizeof(buf));
00139 
00140       size = sizeof(buf);
00141       status = db_get_data_index(hDB, hKey, buf, &size, 0, TID_STRING);
00142       assert(status == DB_SUCCESS);
00143 
00144       s = strchr(buf,'/');
00145       if (s)
00146          *s = 0;
00147 
00148       //printf("Found event %d, name [%s], looking for [%s][%s]\n", evid, buf, evname, tagname);
00149 
00150       if (!equal_ustring((char *)evname, buf))
00151          continue;
00152 
00153       for (j=1; j<key.num_values; j++) {
00154          size = sizeof(buf);
00155          status = db_get_data_index(hDB, hKey, buf, &size, j, TID_STRING);
00156          assert(status == DB_SUCCESS);
00157 
00158          if (!isdigit(buf[0]))
00159             continue;
00160 
00161          s = strchr(buf,' ');
00162          if (!s)
00163             continue;
00164 
00165          s++;
00166  
00167          //printf("at %d [%s] [%s] compare to [%s]\n", j, buf, s, tagname);
00168 
00169          if (equal_ustring((char *)tagname, s)) {
00170             //printf("Found evid %d\n", evid);
00171             return evid;
00172          }
00173       }
00174    }
00175 
00176    return 0;
00177 }

MidasHistoryInterface* MakeMidasHistory (  ) 

Definition at line 1144 of file history_midas.cxx.

Referenced by set_history_path().

01145 {
01146    // midas history is a singleton class
01147    static MidasHistory* gh = NULL;
01148    if (!gh)
01149       gh = new MidasHistory;
01150    return gh;
01151 }


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