/* msu.c */ /* 95/03/30 tl; first try, based on gs_skim.c */ /* 95/07/02 tl; reworked, most bugs squashed */ #include #include #include #include #include "msu.h" /*-------------------------------------------------------*/ get_msu_ev(evlen, ev) unsigned short int *evlen, ev[]; { /* declarations */ static int nbl = TAPE_REOPEN; /* block counter */ static int exa = 0; /* exabyte dev handle */ static unsigned short int eb[DATASIZE]; static int st = 1; /*--------------------*/ /* reopen tape drive? */ /*--------------------*/ if (nbl >= TAPE_REOPEN) { nbl = 0; /* first close tapedrive (ignore error if not open) */ printf("(re)open tape drive, closing... "); fflush(stdout); close(exa); printf("- done\n"); fflush(stdout); /* open tape drives */ #if(INTAPE==8) exa = open("/dev/nrst8", O_RDONLY, 0); if (exa == -1) { printf("get_msu_ev/could not open in-tape drive: /dev/nrst8\n"); fflush(stdout); close(exa); return (-1); } else { printf("in-tape drive open (%i) @ ", exa); time_stamp(); fflush(stdout); }; #elif(INTAPE==9) exa = open("/dev/nrst9", O_RDONLY, 0); if (exa == -1) { printf("get_msu_ev/could not open in-tape drive: /dev/nrst9\n"); fflush(stdout); close(exa); return (-1); } else { printf("in-tape drive open (%i) @ ", exa); time_stamp(); fflush(stdout); }; #else printf("INTAPE must be define as 8 or 9 in makefile\n"); exit(0); #endif }; /*---------------------*/ /* read a new eb ? */ /*---------------------*/ if (st != 0) { /* read a new eb */ st = get_msu_buffer(exa, eb); nbl++; } /*----------------------------*/ /* process eb data event */ /*----------------------------*/ if (st == 0) st = get_ev(eb, evlen, ev); /* done */ return (st); } /*---------------------------------------------------------*/ get_msu_buffer(exa, eb) int exa; unsigned short int eb[DATASIZE]; { /* declarations */ int siz, j; char *p, *strstr(); static nbl = 0; static int neof = 0; unsigned short int buffer[DATASIZE]; /* local read buffer */ /* read block of data */ siz = read(exa, (char *) buffer, DATASIZE); nbl++; /* what did we get? */ switch (siz) { case ERROR_MARK: printf("**read error: siz=-1, nbl= %i\n", nbl); return (ERROR_MARK); case EOF_MARK: printf("EOF encountered\n"); neof++; printf("__number of eof encoutered: %i\n", neof); printf("__number of files encoutered: %i\n", neof / 3 + 1); return (FILEMARK); case ANSI_MARK: if ((p = strstr((char *) buffer, "VOL1")) != NULL) { printf("ansi VOL1 mark encountered\n"); } else if ((p = strstr((char *) buffer, "HDR1")) != NULL) { printf("ansi HDR1 mark encountered\n"); } else if ((p = strstr((char *) buffer, "HDR2")) != NULL) { printf("ansi HDR2 mark encountered\n"); } else if ((p = strstr((char *) buffer, "EOF1")) != NULL) { printf("ansi EOF1 mark encountered\n"); } else if ((p = strstr((char *) buffer, "EOF2")) != NULL) { printf("ansi EOF2 mark encountered\n"); } return (4); case DATASIZE: /* printf("[data]"); */ /* swab bytes from the DEC thing */ for (j = 0; j < siz / 2; j++) swab((char *) &buffer[j], (char *) &eb[j], 2); /* buffer */ if (eb[1] > FE_K_SCALER_PEEK) { switch (eb[1]) { case FE_K_START: printf("FE_K_START datablock, title:\n"); print_msu_header(eb); printf("[%80.80s]\n", &buffer[16]); return (4); break; case FE_K_STOP: printf("FE_K_STOP datablock\n"); print_msu_header(eb); printf("[%80.80s]\n", &buffer[16]); return (4); break; case FE_K_PAUSE: printf("FE_K_PAUSE datablock\n"); print_msu_header(eb); printf("[%80.80s]\n", &buffer[16]); return (4); break; case FE_K_RESUME: printf("FE_K_RESUME datablock\n"); print_msu_header(eb); printf("[%80.80s]\n", &buffer[16]); return (4); break; } } else /* regular data */ return (0); break; default: printf("unknown size: %i\n", siz); printf("___ this should not happen...\n"); printf("___ please e-mail: torben@anl.gov!\n"); return (-1); } } /*---------------------------------------------------------*/ int get_ev(eb, evlen, ev) unsigned short int eb[DATASIZE]; unsigned short int *evlen, ev[]; /* this is where we pull events of the current active */ /* buffer. if we run out of events, we return a non-zero */ /* value (1) to signal a new buffer read */ /* always set st and return st, st is static! */ { /* declarations */ static int st = 1, start = 0; int i, j, k, hi; static unsigned int nowords; /* debug print */ /* if new buffer then */ if (st != 0) { nowords = eb[0]; /* check the # words MSU claims is in buffer */ if (nowords > DATASIZE) { st = 11; return (st); }; /* skip to the data */ start = 16; } /* event length */ *evlen = eb[start] - 2; if (*evlen > MAXEV) { *evlen = 0; st = 8; return (st); } /* check we didn't fall of the end of the buffer */ if ((start + eb[start]) >= DATASIZE) { *evlen = 0; st = 9; return (st); } /* or that MSU claims to short an event */ if (eb[start] < 2) { *evlen = 0; st = 12; return (st); } /* generate the event (would like to send pointer */ /* back; but haven't made that work yet...) */ j = 0; for (i = start + 1; i < (start + eb[start]); i++) ev[j++] = eb[i]; /* find next start of event */ start += eb[start]; /* check trailer/buffer position/good_event */ if (eb[start - 1] != 0xdead) { *evlen = 0; st = 10; } else if (start >= nowords) { *evlen = 0; st = 1; } else st = 0; /* ....good event */ /* done, send back appropriate error code */ return (st); }; /*-------------------------------------------------------*/ int err_print(num) int num; /* print the error codes we have. User does not */ /* need to know what the code numbers are to use them */ { switch (num) { case 0: printf("valid events.............: "); break; case 1: printf("buffer reads.............: "); break; case 2: printf("file headers.............: "); break; case FILEMARK: printf("end of files (eof).......: "); break; case 4: printf("various headers..........: "); break; case 5: printf("not assigned.............: "); break; case 6: printf("no begin event markings..: "); break; case 7: printf("header overflow of event.: "); break; case 8: printf("event too long (> MAXEV).: "); break; case 9: printf("event overflow of event..: "); break; case 10: printf("no end of event marking..: "); break; case 11: printf("block size too large.....: "); break; case 12: printf("event too short..........: "); break; default: printf("unknown error..??........: "); break; } }; /*---------------------------------------------*/ MSU_eb_scaler(eb) unsigned short int eb[DATASIZE]; { /* declarations */ static int firsttime = 1; int t1, t2, tmp, j, start; if (firsttime) { firsttime = 0; printf(">>SCALER<<\n"); print_msu_header(eb); }; /* start of real data */ start = 16; /* find t1 and t2 */ t1 = (int) eb[start] | ((int) eb[start + 1] << 16); t2 = (int) eb[start + 5] | ((int) eb[start + 6] << 16); /* swab the words in the scalers */ start += 10; for (j = 0; j < eb[6]; j++) { tmp = eb[j * 2 + start]; eb[j * 2 + start] = eb[j * 2 + 1 + start]; eb[j * 2 + 1 + start] = tmp; } /* eh, don't know what to do with this information... */ /* so I do nothing */ /* done */ return (0); } /*----------------------------------------------------------------*/ print_msu_header(hdr) struct MSU_HEADER hdr; { /* print relevant information */ printf("num_words..: %4i, ", hdr.num_words); printf("type.......: %4i, ", hdr.type); printf("checksum...: %u\n", hdr.checksum); printf("run_no.....: %4i, ", hdr.run_no); printf("Buff_seq...: %u \n", hdr.Buff_seq); printf("num_ev.....: %4i, ", hdr.num_ev); printf("num_LAM....: %4i, ", hdr.num_LAM); printf("num_CPU....: %4i, ", hdr.num_CPU); printf("num_BITREGS: %4i\n", hdr.num_BITREGS); printf("buf_rev....: %4i, ", hdr.buf_rev); printf("time.......: %12u\n", hdr.time); /* done */ return (0); }; /*-------------------------------------------*/ int print_event(evlen, ev) unsigned short int *evlen, ev[]; /* print the event */ { /* declarations */ int i, j, k; /* print */ for (i = 0; i < *evlen; i++) { printf("_%3i>dec:{%6i} hex:{0x%4.4x} bit: |", i + 1, ev[i], ev[i]); j = 32768; for (k = 0; k < 16; k++) { if ((ev[i] & j) == j) printf("1"); else printf("0"); j = j / 2; if ((k + 1) % 4 == 0) printf("|"); }; printf("\n"); } printf("+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+\n"); fflush(stdout); /* done */ return (0); }