00001 /* call_drms_in.c 00002 * Gets the wd of the ARG_DATA_IN datasets 00003 */ 00004 #include <stdio.h> 00005 #include <drms.h> 00006 #include <drms_names.h> 00007 #include <soi_key.h> 00008 #include <printk.h> 00009 00010 extern DRMS_Env_t *drms_env; 00011 extern void printkey (KEY *key); 00012 extern void abortit(); 00013 extern int ampexflg; // 1 = retrieve from tape 00014 00015 static KEY *alist; 00016 00017 #define out_namespace "sha.dsds" 00018 /* 00019 #define out_namespace "dsds" 00020 #define out_namespace "su_production" 00021 */ 00022 /************************OLD************************************************* 00023 //Take the su dir and convert to the corresponding ds_index (i.e. sunum) 00024 int path2index(char *path, ulong *dsindex) { 00025 char pathx[DRMS_MAXPATHLEN]; 00026 char *cptr, *cptr2; 00027 00028 strcpy(pathx, path); 00029 cptr = strstr(pathx, "/D"); //find first /D 00030 if(!cptr) { 00031 printk("**Error: no /D in path %s\n", pathx); 00032 printk("**Use the -A flag if need to bring data on-line\n"); 00033 return(1); 00034 } 00035 //if there's a second /D then that is the orig one that we want 00036 cptr2 = strstr(cptr+1, "/D"); 00037 if(cptr2) cptr = cptr2; 00038 cptr2 = index(cptr+1, '/'); //elim an other '/' after sunum 00039 if(cptr2) *cptr = NULL; 00040 cptr2 = cptr+2; //skip the /D 00041 *dsindex = strtoul(cptr2, NULL, 0); 00042 return(0); 00043 } 00044 ************************OLD*************************************************/ 00045 00046 00047 /* 00048 * Here an example of a keylist received here: 00049 * (the args are given by arg_data_in_0, arg_data_in_1, etc) 00050 * 00051 *lago_tid: KEYTYP_INT 0 00052 *pds_host: KEYTYP_STRING d00 00053 *dsds_uid: KEYTYP_UINT 0 00054 *alsoin_2_basename: KEYTYP_STRING fd_V_01h.029795 00055 *alsoin_2_wd: KEYTYP_STRING /tmp40/jim/tmp/lev1.5/fd_V_01h/29795 00056 *alsoin_2_rule: KEYTYP_STRING wd:{dbase}/{level}/{series}/{#%04d#series};bn:{series}.{#%06d#series} 00057 *alsoin_1_basename: KEYTYP_STRING fd_V_01h.029794 00058 *alsoin_1_wd: KEYTYP_STRING /tmp40/jim/tmp/lev1.5/fd_V_01h/29794 00059 *alsoin_1_rule: KEYTYP_STRING wd:{dbase}/{level}/{series}/{#%04d#series};bn:{series}.{#%06d#series} 00060 *alsoin_0_basename: KEYTYP_STRING fd_V_01h.029793 00061 *alsoin_0_wd: KEYTYP_STRING /tmp40/jim/tmp/lev1.5/fd_V_01h/29793 00062 *alsoin_0_rule: KEYTYP_STRING wd:{dbase}/{level}/{series}/{#%04d#series};bn:{series}.{#%06d#series} 00063 *alsoin_2_dbase: KEYTYP_STRING /tmp40/jim/tmp 00064 *alsoin_1_dbase: KEYTYP_STRING /tmp40/jim/tmp 00065 *alsoin_0_dbase: KEYTYP_STRING /tmp40/jim/tmp 00066 *alsoin_0_series_sn: KEYTYP_INT 29793 00067 *alsoin_0_fmt: KEYTYP_STRING %04d 00068 *alsoin_0_incr: KEYTYP_INT 1 00069 *alsoin_0_lsn: KEYTYP_INT -1 00070 *alsoin_0_fsn: KEYTYP_INT 0 00071 *alsoin_0_data: KEYTYP_STRING prog:mdi,level:lev1.5,series:fd_V_01h[29793-29795] 00072 *alsoin_0_prog: KEYTYP_STRING mdi 00073 *alsoin_0_level: KEYTYP_STRING lev1.5 00074 *alsoin_0_series: KEYTYP_STRING fd_V_01h 00075 *alsoin_0_series_range: KEYTYP_STRING 29793,29794,29795 00076 *alsoin_1_series_sn: KEYTYP_INT 29794 00077 *alsoin_1_fmt: KEYTYP_STRING %04d 00078 *alsoin_1_incr: KEYTYP_INT 1 00079 *alsoin_1_lsn: KEYTYP_INT -1 00080 *alsoin_1_fsn: KEYTYP_INT 0 00081 *alsoin_1_data: KEYTYP_STRING prog:mdi,level:lev1.5,series:fd_V_01h[29793-29795] 00082 *alsoin_1_prog: KEYTYP_STRING mdi 00083 *alsoin_1_level: KEYTYP_STRING lev1.5 00084 *alsoin_1_series: KEYTYP_STRING fd_V_01h 00085 *alsoin_1_series_range: KEYTYP_STRING 29793,29794,29795 00086 *alsoin_2_series_sn: KEYTYP_INT 29795 00087 *alsoin_2_fmt: KEYTYP_STRING %04d 00088 *alsoin_2_incr: KEYTYP_INT 1 00089 *alsoin_2_lsn: KEYTYP_INT -1 00090 *alsoin_2_fsn: KEYTYP_INT 0 00091 *alsoin_2_data: KEYTYP_STRING prog:mdi,level:lev1.5,series:fd_V_01h[29793-29795] 00092 *alsoin_2_prog: KEYTYP_STRING mdi 00093 *alsoin_2_level: KEYTYP_STRING lev1.5 00094 *alsoin_2_series: KEYTYP_STRING fd_V_01h 00095 *alsoin_2_series_range: KEYTYP_STRING 29793,29794,29795 00096 *alsoin_nsets: KEYTYP_INT 3 00097 *alsoin_dbase: KEYTYP_STRING /tmp40/jim/tmp 00098 *arg_data_in_1: KEYTYP_STRING alsoin 00099 *in_0_basename: KEYTYP_STRING 00100 *in_0_wd: KEYTYP_STRING . 00101 *in_basename: KEYTYP_STRING 00102 *in_wd: KEYTYP_STRING . 00103 *in_0_dbase: KEYTYP_STRING /tmp40/jim/tmp 00104 *in_0_series_sn: KEYTYP_INT -1 00105 *in_0_fmt: KEYTYP_STRING %04d 00106 *in_0_incr: KEYTYP_INT 1 00107 *in_0_lsn: KEYTYP_INT -1 00108 *in_0_fsn: KEYTYP_INT 0 00109 *in_0_data: KEYTYP_STRING prog:mdi_klist,level:copy,series:vw_V[-1] 00110 *in_0_prog: KEYTYP_STRING mdi_klist 00111 *in_0_level: KEYTYP_STRING copy 00112 *in_0_series: KEYTYP_STRING vw_V 00113 *in_0_series_range: KEYTYP_STRING -1 00114 *in_fmt: KEYTYP_STRING %04d 00115 *in_incr: KEYTYP_INT 1 00116 *in_lsn: KEYTYP_INT -1 00117 *in_fsn: KEYTYP_INT 0 00118 *in_data: KEYTYP_STRING prog:mdi_klist,level:copy,series:vw_V[-1] 00119 *in_prog: KEYTYP_STRING mdi_klist 00120 *in_level: KEYTYP_STRING copy 00121 *in_series: KEYTYP_STRING vw_V 00122 *in_series_sn: KEYTYP_INT -1 00123 *in_series_range: KEYTYP_STRING -1 00124 *in_nsets: KEYTYP_INT 1 00125 *in_dbase: KEYTYP_STRING /tmp40/jim/tmp 00126 *arg_data_in_0: KEYTYP_STRING in 00127 *dlocalflg: KEYTYP_INT 0 00128 *db: KEYTYP_STRING mdi_2 00129 *anotherout: KEYTYP_STRING prog:mdi,level:tmp,series:test[666] 00130 *out: KEYTYP_STRING prog:mdi_raw,level:tlm,series:nxt2ser[3006,3007] 00131 *alsoin: KEYTYP_STRING prog:mdi,level:lev1.5,series:fd_V_01h[29793-29795] 00132 *in: KEYTYP_STRING prog:mdi_klist,level:copy,series:vw_V[-1] 00133 *T_FIRST: KEYTYP_STRING '1999.11.06_00:01:00_TAI' 00134 */ 00135 00136 KEY *call_drms_in(KEY *list, int dbflg) 00137 { 00138 char drmsname[MAX_STR]; 00139 char cmd[128], buf[128]; 00140 char path[DRMS_MAXPATHLEN] = {0}; 00141 char *stmp, *cptr; 00142 DRMS_RecordSet_t *rset; 00143 DRMS_Record_t *rec; 00144 FILE *fin; 00145 char argname[MAX_STR], inname[MAX_STR], ext[MAX_STR]; 00146 double dbytes; 00147 ulong dsindex; 00148 int i, loop, innsets, rstatus, touch; 00149 int restoreenv = 0; 00150 int num_ds = 0; /* total # of ds queried */ 00151 int ntmp; 00152 00153 alist = newkeylist(); 00154 for(loop = 0; ; loop++) { 00155 sprintf(ext, "arg_data_in_%d", loop); 00156 if(!findkey(list, ext)) break; /* all done, exit for(loop)*/ 00157 strcpy(argname, GETKEY_str(list, ext)); /* e.g. "in" */ 00158 strcpy(inname, argname); strcat(inname, "_nsets"); 00159 innsets = getkey_int(list, inname); 00160 for(i=0; i < innsets; i++) { /* do for each dataset */ 00161 sprintf(ext, "_%d", i); 00162 strcpy(inname, argname); strcat(inname, ext); /* e.g. "in_0" */ 00163 setkey_str(&alist, "inname", inname); 00164 sprintf(ext, "inname_%d", num_ds); 00165 setkey_str(&alist, ext, inname); /* also make unique inname*/ 00166 sprintf(ext, "%s_prog", inname); //e.g. in_0_prog 00167 stmp = GETKEY_str(list, ext); 00168 if (!strcmp(stmp, "")) continue; //not a ds name 00169 sprintf (drmsname, "%s[%s]", out_namespace, stmp); 00170 /* sprintf(drmsname, "%s__", stmp); */ 00171 sprintf (ext, "%s_level", inname); 00172 stmp = GETKEY_str (list, ext); 00173 sprintf (drmsname, "%s[%s]", drmsname, stmp); 00174 /* sprintf(drmsname, "%s__", stmp); */ 00175 sprintf (ext, "%s_series", inname); 00176 stmp = GETKEY_str (list, ext); 00177 sprintf (drmsname, "%s[%s]", drmsname, stmp); 00178 /* 00179 sprintf(drmsname, "%s%s", drmsname, stmp); 00180 sprintf(cmd, "echo \"%s\" | sed 's/\\\./_/g' | sed 's/-/__/g'", drmsname); 00181 fin = popen(cmd, "r"); 00182 fgets(buf, sizeof buf, fin); 00183 cptr = rindex(buf, '\n'); 00184 if(cptr) *cptr = NULL; 00185 */ 00186 sprintf (ext, "%s_series_sn", inname); 00187 if (findkey (list, ext)) ntmp = getkey_int (list, ext); 00188 else ntmp = -1; 00189 sprintf (drmsname, "%s[%d]", drmsname, ntmp); 00190 /* 00191 sprintf(buf, "%s[%d]", buf, ntmp); 00192 sprintf(drmsname, "%s.%s", out_namespace, buf); 00193 */ 00194 00195 if(findkey(list, ext)) 00196 setkey_int(&alist, ext, getkey_int(list, ext)); 00197 if(findkey(list, "touch")) { 00198 touch = getkey_int(list, "touch"); 00199 setkey_int(&alist, "touch", touch); 00200 restoreenv = drms_env->retention; 00201 drms_env->retention = touch; 00202 } 00203 if(findkey(list, "ampex_tid")) 00204 setkey_int(&alist, "ampex_tid", getkey_int(list, "ampex_tid")); 00205 00206 //printf("drmsname=%s\nThe keylist for call_drms_in():\n",drmsname);//!!TEMP 00207 //keyiterate(printkey, list); 00208 00209 rset = drms_open_records(drms_env, drmsname, &rstatus); 00210 if(rstatus) { 00211 printk("Can't do drms_open_records(%s)\n", drmsname); 00212 return(NULL); 00213 } 00214 sprintf(ext, "%s_wd", inname); 00215 if(!rset || rset->n == 0) { 00216 printk("No prev ds for %s\n", drmsname); 00217 setkey_str(&alist, ext, ""); //send back empty wd 00218 } 00219 else { 00220 if(rstatus = drms_stage_records(rset, 0, 1)) { 00221 printk("Can't do drms_stage_records() for %s\n", drmsname); 00222 return(NULL); 00223 } 00224 rec = rset->records[0]; /* !!TBD fix 0 when more than one */ 00225 if(!ampexflg) { 00226 rstatus = drms_record_directory (rec, path, 0); 00227 } else { 00228 printk("Possible wait for drms retrieve from tape...\n"); 00229 rstatus = drms_record_directory (rec, path, 1); 00230 } 00231 setkey_str(&alist, ext, path); 00232 sprintf(ext, "status_%d", num_ds); 00233 setkey_int(&alist, ext, rstatus); 00234 dbytes = du_dir(path); 00235 sprintf(ext, "%s_bytes", inname); 00236 setkey_double(&alist, ext, dbytes); 00237 dsindex = rec->sunum; 00238 sprintf(ext, "%s_ds_index", inname); 00239 setkey_ulong(&alist, ext, dsindex); 00240 //printk("In call_drms_in() ext=%s dsindex=%u\n", ext, dsindex); 00241 //keyiterate(printkey, alist); //!!TEMP 00242 } 00243 num_ds++; 00244 } 00245 if(restoreenv != 0) drms_env->retention = restoreenv; 00246 } 00247 return(alist); 00248 }