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