Line data Source code
1 : /* Copyright (c) 1993 TRIUMF Data Acquistion Group
2 : * Please leave this header in any reproduction of that distribution
3 : *
4 : * TRIUMF Data Acquisition Group, 4004 Wesbrook Mall, Vancouver, B.C. V6T 2A3
5 : * Email: online@triumf.ca Tel: (604) 222-1047 Fax: (604) 222-1074
6 : * amaudruz@triumf.ca Local: 6234
7 : * ---------------------------------------------------------------------------
8 : * $Id$
9 : *
10 : * Description : mdsupport.c :
11 : * contains support for the mdump and lazylogger data support.
12 : * related to event writing, reading, display
13 : */
14 :
15 : /**dox***************************************************************/
16 : /** @file mdsupport.cxx
17 : The Midas Dump support file
18 : */
19 :
20 : /**dox***************************************************************/
21 : /** @addtogroup mdsupportincludecode
22 : *
23 : * @{ */
24 :
25 : /**dox***************************************************************/
26 : #ifndef DOXYGEN_SHOULD_SKIP_THIS
27 :
28 :
29 : /* include files */
30 : /* moved #define HAVE_FTPLIB into makefile (!vxWorks) */
31 :
32 : #define TRACE
33 :
34 : #include "midas.h"
35 : #include "msystem.h"
36 : #include "mstrlcpy.h"
37 :
38 : #ifdef HAVE_FTPLIB
39 :
40 : #include "ftplib.h"
41 :
42 : FTP_CON *ftp_con;
43 : #endif
44 :
45 : #include "zlib.h"
46 :
47 : #include "mdsupport.h"
48 :
49 : INT md_dev_os_read(INT handle, INT type, void *prec, DWORD nbytes, DWORD *nread);
50 :
51 : INT md_dev_os_write(INT handle, INT type, void *prec, DWORD nbytes, DWORD *written);
52 :
53 : void md_bank_event_display(const void *pevent, INT data_fmt, INT dsp_fmt, INT dsp_mode, const char *bn);
54 :
55 : void md_raw_event_display(const void *pevent, INT data_fmt, INT dsp_fmt);
56 :
57 : void md_raw_bank_display(void *pbank, INT data_fmt, INT dsp_fmt);
58 :
59 : INT midas_event_get(void **pevent, DWORD *size);
60 :
61 : INT midas_physrec_get(void *prec, DWORD *readn);
62 :
63 : INT midas_event_skip(INT evtn);
64 :
65 : void midas_bank_display(BANK *pbk, INT dsp_fmt);
66 :
67 : template<typename T>
68 : void midas_bank_display32(T *pbk, INT dsp_fmt);
69 :
70 : struct stat *filestat;
71 : char *ptopmrd;
72 :
73 : gzFile filegz;
74 :
75 : /* General MIDAS struct for util */
76 : typedef struct {
77 : INT handle; /* file handle */
78 : char name[128]; /* Device name (/dev/nrmt0h) */
79 :
80 : char *pmp; /* ptr to a physical TAPE_BUFFER_SIZE block */
81 : EVENT_HEADER *pmh; /* ptr to Midas event (midas bank_header) */
82 : EVENT_HEADER *pme; /* ptr to Midas content (event+1) (midas bank_header) */
83 : char *pmrd; /* current point in the phyical record */
84 :
85 : DWORD evtn; /* current event number */
86 : DWORD serial; /* serial event number */
87 : DWORD evtlen; /* current event length (-1 if not available) */
88 : DWORD size; /* midas max_evt_size */
89 : DWORD recn; /* current physical record number */
90 : INT fmt; /* contains FORMAT type */
91 : INT type; /* Device type (tape, disk, ...) */
92 : DWORD runn; /* run number */
93 : BOOL zipfile;
94 : } MY;
95 :
96 : MY my;
97 : /**dox***************************************************************/
98 : #endif /* DOXYGEN_SHOULD_SKIP_THIS */
99 :
100 : #ifdef HAVE_FTPLIB
101 :
102 : /*------------------------------------------------------------------*/
103 0 : INT mftp_open(char *destination, FTP_CON **con) {
104 : INT status;
105 0 : short port = 0;
106 : char *token, host_name[HOST_NAME_LENGTH],
107 : user[256], pass[256], directory[256], file_name[256], file_mode[256];
108 :
109 : /*
110 : destination should have the form:
111 : host, port, user, password, directory, run%05d.mid, file_mode, command, ...
112 : */
113 :
114 : /* break destination in components */
115 0 : token = strtok(destination, ",");
116 0 : if (token)
117 0 : strcpy(host_name, token);
118 :
119 0 : token = strtok(NULL, ",");
120 0 : if (token)
121 0 : port = atoi(token);
122 :
123 0 : token = strtok(NULL, ",");
124 0 : if (token)
125 0 : strcpy(user, token);
126 :
127 0 : token = strtok(NULL, ",");
128 0 : if (token)
129 0 : strcpy(pass, token);
130 :
131 0 : token = strtok(NULL, ",");
132 0 : if (token)
133 0 : strcpy(directory, token);
134 :
135 0 : token = strtok(NULL, ",");
136 0 : if (token)
137 0 : strcpy(file_name, token);
138 :
139 0 : token = strtok(NULL, ",");
140 0 : file_mode[0] = 0;
141 0 : if (token)
142 0 : strcpy(file_mode, token);
143 :
144 0 : status = ftp_login(con, host_name, port, user, pass, "");
145 0 : if (status >= 0)
146 0 : return status;
147 :
148 0 : status = ftp_chdir(*con, directory);
149 0 : if (status >= 0) {
150 : /* directory does not exist -> create it */
151 0 : ftp_mkdir(*con, directory);
152 0 : status = ftp_chdir(*con, directory);
153 : }
154 0 : if (status >= 0)
155 0 : return status;
156 0 : status = ftp_binary(*con);
157 0 : if (status >= 0)
158 0 : return status;
159 :
160 0 : if (file_mode[0]) {
161 0 : status = ftp_command(*con, "umask %s", file_mode, 200, 250, EOF);
162 0 : if (status >= 0)
163 0 : return status;
164 : }
165 :
166 0 : while (token) {
167 0 : token = strtok(NULL, ",");
168 0 : if (token) {
169 0 : status = ftp_command(*con, token, NULL, 200, 250, EOF);
170 0 : if (status >= 0)
171 0 : return status;
172 : }
173 : }
174 :
175 0 : if (ftp_open_write(*con, file_name) >= 0)
176 0 : return (*con)->err_no;
177 :
178 0 : return SS_SUCCESS;
179 : }
180 :
181 : #endif // HAVE_FTPLIB
182 :
183 : /*------------------------------------------------------------------*/
184 0 : INT md_file_ropen(char *infile, INT data_fmt, INT openzip, INT max_event_size)
185 : /********************************************************************\
186 : Routine: external md_any_file_ropen
187 : Purpose: Open data file for replay for the given data format.
188 : It uses the local "my" structure.
189 : Input:
190 : INT data_fmt : YBOS or MIDAS
191 : char * infile : Data file name
192 : Output:
193 : none
194 : Function value:
195 : status : from lower function
196 : \********************************************************************/
197 : {
198 : /* fill up record with file name */
199 0 : strcpy(my.name, infile);
200 :
201 : /* find out what dev it is ? : check on /dev */
202 0 : my.zipfile = FALSE;
203 0 : if ((strncmp(my.name, "/dev", 4) == 0) || (strncmp(my.name, "\\\\.\\", 4) == 0)) {
204 : /* tape device */
205 0 : my.type = LOG_TYPE_TAPE;
206 : } else {
207 : /* disk device */
208 0 : my.type = LOG_TYPE_DISK;
209 0 : if (strncmp(infile + strlen(infile) - 3, ".gz", 3) == 0) {
210 : // FALSE will for now prevent the mdump to see inside the .gz
211 : // But lazylogger will NOT unzip during copy!
212 0 : if (openzip == 0) my.zipfile = FALSE; // ignore zip, copy blindly blocks
213 0 : else my.zipfile = TRUE; // Open Zip file
214 : }
215 : }
216 :
217 : /* open file */
218 0 : if (!my.zipfile) {
219 0 : if (my.type == LOG_TYPE_TAPE) {
220 0 : ss_tape_open(my.name, O_RDONLY | O_BINARY, &my.handle);
221 0 : } else if ((my.handle = open(my.name, O_RDONLY | O_BINARY | O_LARGEFILE, 0644)) == -1) {
222 0 : printf("dev name :%s Handle:%d \n", my.name, my.handle);
223 0 : return (SS_FILE_ERROR);
224 : }
225 : } else {
226 0 : if (my.type == LOG_TYPE_TAPE) {
227 0 : printf(" Zip on tape not yet supported \n");
228 0 : return (SS_FILE_ERROR);
229 : }
230 0 : filegz = gzopen(my.name, "rb");
231 0 : my.handle = 0;
232 0 : if (filegz == NULL) {
233 0 : printf("dev name :%s gzopen error:%d \n", my.name, my.handle);
234 0 : return (SS_FILE_ERROR);
235 : }
236 : }
237 :
238 0 : if (data_fmt == FORMAT_MIDAS) {
239 0 : my.fmt = FORMAT_MIDAS;
240 0 : my.size = TAPE_BUFFER_SIZE;
241 0 : my.pmp = (char *) malloc(my.size);
242 0 : if (my.pmp == NULL)
243 0 : return SS_NO_MEMORY;
244 0 : my.pme = (EVENT_HEADER *) my.pmp;
245 :
246 : /* allocate memory for one full event */
247 0 : if (my.pmrd != NULL)
248 0 : free(my.pmrd);
249 0 : my.pmrd = (char *) malloc(5 * max_event_size); /* in bytes */
250 0 : ptopmrd = my.pmrd;
251 0 : if (my.pmrd == NULL)
252 0 : return SS_NO_MEMORY;
253 0 : memset((char *) my.pmrd, -1, 5 * max_event_size);
254 0 : my.pmh = (EVENT_HEADER *) my.pmrd;
255 : } else {
256 0 : assert(!"unsupported data_fmt, sorry!");
257 : }
258 :
259 : /* initialize pertinent variables */
260 0 : my.recn = -1;
261 0 : my.evtn = 0;
262 0 : return (MD_SUCCESS);
263 : }
264 :
265 : /*------------------------------------------------------------------*/
266 0 : INT md_file_rclose(INT data_fmt)
267 : /********************************************************************
268 : Routine: external md_any_file_rclose
269 : Purpose: Close a data file used for replay for the given data format
270 : Input:
271 : INT data_fmt : YBOS or MIDAS
272 : Output:
273 : none
274 : Function value:
275 : status : from lower function
276 : *******************************************************************/
277 : {
278 0 : switch (my.type) {
279 0 : case LOG_TYPE_TAPE:
280 : case LOG_TYPE_DISK:
281 : /* close file */
282 0 : if (my.zipfile) {
283 0 : gzclose(filegz);
284 : } else {
285 0 : if (my.handle != 0)
286 0 : close(my.handle);
287 : }
288 0 : break;
289 : }
290 0 : if (ptopmrd != NULL)
291 0 : free(ptopmrd);
292 0 : if (my.pmp != NULL)
293 0 : free(my.pmp);
294 0 : my.pmp = NULL;
295 0 : my.pmh = NULL;
296 0 : ptopmrd = NULL;
297 0 : my.pmrd = NULL; /* ptopmrd and my.pmrd point to the same place. K.O. 25-FEB-2005 */
298 0 : return (MD_SUCCESS);
299 : }
300 :
301 : /*------------------------------------------------------------------*/
302 0 : INT md_file_wopen(INT type, INT data_fmt, char *filename, INT *hDev)
303 : /********************************************************************
304 : Routine: external md_file_wopen
305 : Purpose: Open a data file for the given data format
306 : Input:
307 : INT type : Tape or Disk
308 : INT data_fmt : YBOS or MIDAS
309 : char * filename : file to open
310 : Output:
311 : INT * hDev : file handle
312 : Function value:
313 : status : from lower function
314 : *******************************************************************/
315 : {
316 0 : INT status = 0;
317 :
318 0 : if (type == LOG_TYPE_DISK)
319 : /* takes care of TapeLX/NT under ss_tape_open , DiskLX/NT here */
320 : {
321 0 : if (data_fmt == FORMAT_MIDAS) {
322 : #ifdef OS_WINNT
323 : *hDev =
324 : (int) CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ,
325 : NULL, CREATE_ALWAYS,
326 : FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH | FILE_FLAG_SEQUENTIAL_SCAN, 0);
327 : #else
328 0 : *hDev = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE, 0644);
329 : #endif
330 0 : status = *hDev < 0 ? SS_FILE_ERROR : SS_SUCCESS;
331 : } else {
332 0 : assert(!"unsupported data_fmt, sorry!");
333 : }
334 0 : } else if (type == LOG_TYPE_TAPE) {
335 0 : if (data_fmt == FORMAT_MIDAS) {
336 0 : status = ss_tape_open(filename, O_WRONLY | O_CREAT | O_TRUNC, hDev);
337 : } else {
338 0 : assert(!"unsupported data_fmt, sorry!");
339 : }
340 0 : } else if (type == LOG_TYPE_FTP) {
341 : #ifdef HAVE_FTPLIB
342 0 : status = mftp_open(filename, (FTP_CON **) &ftp_con);
343 0 : if (status != SS_SUCCESS) {
344 0 : *hDev = 0;
345 0 : return status;
346 : } else
347 0 : *hDev = 1;
348 : #else
349 : cm_msg(MERROR, "mdsupport", "FTP support not included");
350 : return SS_FILE_ERROR;
351 : #endif
352 : }
353 :
354 0 : return status;
355 : }
356 :
357 : /*------------------------------------------------------------------*/
358 0 : INT md_file_wclose(INT handle, INT type, INT data_fmt, char *destination)
359 : /********************************************************************
360 : Routine: external md_file_wclose
361 : Purpose: Close a data file used for replay for the given data format
362 : Input:
363 : INT data_fmt : YBOS or MIDAS
364 : Output:
365 : none
366 : Function value:
367 : status : from lower function
368 : *******************************************************************/
369 : {
370 : INT status;
371 :
372 0 : status = SS_SUCCESS;
373 0 : switch (type) {
374 0 : case LOG_TYPE_TAPE:
375 : /* writing EOF mark on tape Fonly */
376 0 : status = ss_tape_write_eof(handle);
377 0 : ss_tape_close(handle);
378 0 : break;
379 0 : case LOG_TYPE_DISK:
380 : /* close file */
381 0 : if (handle != 0)
382 : #ifdef OS_WINNT
383 : CloseHandle((HANDLE) handle);
384 : #else
385 0 : close(handle);
386 : #endif
387 0 : break;
388 0 : case LOG_TYPE_FTP:
389 : #ifdef HAVE_FTPLIB
390 : {
391 : char *p, filename[256];
392 : int i;
393 :
394 0 : ftp_close(ftp_con);
395 :
396 : /*
397 : destination should have the form:
398 : host, port, user, password, directory, run%05d.mid, file_mode, command, ...
399 : */
400 0 : p = destination;
401 0 : for (i = 0; i < 5 && p != NULL; i++) {
402 0 : p = strchr(p, ',');
403 0 : if (*p == ',')
404 0 : p++;
405 : }
406 0 : if (p != NULL) {
407 0 : mstrlcpy(filename, p, sizeof(filename));
408 0 : if (strchr(filename, ','))
409 0 : *strchr(filename, ',') = 0;
410 : } else
411 0 : mstrlcpy(filename, destination, sizeof(filename));
412 :
413 : /* if filename starts with a '.' rename it */
414 0 : if (filename[0] == '.')
415 0 : ftp_move(ftp_con, filename, filename + 1);
416 :
417 0 : ftp_bye(ftp_con);
418 : }
419 : #endif
420 0 : break;
421 : }
422 0 : if (status != SS_SUCCESS)
423 0 : return status;
424 0 : return (MD_SUCCESS);
425 : }
426 :
427 : /*------------------------------------------------------------------*/
428 0 : INT md_dev_os_read(INT handle, INT type, void *prec, DWORD nbytes, DWORD *readn)
429 : /********************************************************************\
430 : Routine: md_dev_os_read
431 : Purpose: read nbytes from the type device.
432 : Input:
433 : INT handle file handler
434 : INT type Type of device (TAPE or DISK)
435 : void * prec pointer to the record
436 : DWORD nbytes # of bytes to read
437 : Output:
438 : DWORD *readn # of bytes read
439 : Function value:
440 : MD_DONE No more record to read
441 : MD_SUCCESS Ok
442 : \********************************************************************/
443 : {
444 : INT status;
445 0 : if (type == LOG_TYPE_DISK)
446 : /* --------- DISK ---------- */
447 : {
448 0 : *readn = read(handle, prec, nbytes);
449 0 : if (*readn <= 0)
450 0 : status = SS_FILE_ERROR;
451 : else
452 0 : status = SS_SUCCESS;
453 0 : return status;
454 : }
455 : /* --------- TAPE ---------- */
456 : #ifdef OS_UNIX
457 0 : else if (type == LOG_TYPE_TAPE) {
458 0 : *readn = read(handle, prec, nbytes);
459 0 : if (*readn <= 0)
460 0 : status = SS_FILE_ERROR;
461 : else
462 0 : status = SS_SUCCESS;
463 0 : return status;
464 : }
465 : #endif
466 :
467 : #ifdef OS_WINNT
468 : else if (type == LOG_TYPE_TAPE) {
469 : if (!ReadFile((HANDLE) handle, prec, nbytes, readn, NULL))
470 : status = GetLastError();
471 : else
472 : status = SS_SUCCESS;
473 : if (status == ERROR_NO_DATA_DETECTED)
474 : status = SS_END_OF_TAPE;
475 :
476 : return status;
477 : }
478 : #endif /* OS_WINNT */
479 : else
480 0 : return SS_SUCCESS;
481 : }
482 :
483 : /*------------------------------------------------------------------*/
484 0 : INT md_dev_os_write(INT handle, INT type, void *prec, DWORD nbytes, DWORD *written)
485 : /********************************************************************\
486 : Routine: md_dev_os_write
487 : Purpose: write nbytes to the device.
488 : Input:
489 : INT handle file handler
490 : INT type Type of device (TAPE or DISK)
491 : void * prec pointer to the record
492 : DWORD nbytes record length to be written
493 : Output:
494 : DWORD *written # of written bytes
495 : Function value:
496 : INT status # of written bytes or ERROR
497 : SS_FILE_ERROR write error
498 : SS_SUCCESS Ok
499 : \********************************************************************/
500 : {
501 : INT status;
502 0 : if (type == LOG_TYPE_DISK)
503 : #ifdef OS_WINNT
504 : { /* --------- DISK ---------- */
505 : WriteFile((HANDLE) handle, (char *) prec, nbytes, written, NULL);
506 : status = *written == nbytes ? SS_SUCCESS : SS_FILE_ERROR;
507 : return status; /* return for DISK */
508 : }
509 : #else
510 : { /* --------- DISK ---------- */
511 0 : status = *written = write(handle, (char *) prec, nbytes) == (INT) nbytes ? SS_SUCCESS : SS_FILE_ERROR;
512 0 : return status; /* return for DISK */
513 : }
514 : #endif
515 0 : else if (type == LOG_TYPE_TAPE) { /* --------- TAPE ---------- */
516 : #ifdef OS_UNIX
517 : do {
518 0 : status = write(handle, (char *) prec, nbytes);
519 0 : } while (status == -1 && errno == EINTR);
520 0 : *written = status;
521 0 : if (*written != nbytes) {
522 0 : cm_msg(MERROR, "any_dev_os_write", "write() status %d, errno %d (%s)", status, errno, strerror(errno));
523 0 : if (errno == EIO)
524 0 : return SS_IO_ERROR;
525 0 : if (errno == ENOSPC)
526 0 : return SS_NO_SPACE;
527 : else
528 0 : return SS_TAPE_ERROR;
529 : }
530 : #endif /* OS_UNIX */
531 :
532 : #ifdef OS_WINNT
533 : WriteFile((HANDLE) handle, (char *) prec, nbytes, written, NULL);
534 : if (*written != nbytes) {
535 : status = GetLastError();
536 : cm_msg(MERROR, "any_dev_os_write", "error %d", status);
537 : return SS_IO_ERROR;
538 : }
539 : return SS_SUCCESS; /* return for TAPE */
540 : #endif /* OS_WINNT */
541 0 : } else if (type == LOG_TYPE_FTP)
542 : #ifdef HAVE_FTPLIB
543 : {
544 0 : *written = status = ftp_send(ftp_con->data, (char *) prec,
545 0 : (int) nbytes) == (int) nbytes ? SS_SUCCESS : SS_FILE_ERROR;
546 0 : return status;
547 : }
548 : #else
549 : {
550 : cm_msg(MERROR, "mdsupport", "FTP support not included");
551 : return SS_IO_ERROR;
552 : }
553 : #endif
554 0 : return SS_SUCCESS;
555 : }
556 :
557 : /*------------------------------------------------------------------*/
558 0 : INT md_physrec_get(INT data_fmt, void **precord, DWORD *readn)
559 : /********************************************************************\
560 : Routine: external md_physrec_get
561 : Purpose: Retrieve a physical record for the given data format
562 : Input:
563 : INT data_fmt : YBOS or MIDAS
564 : Output:
565 : void ** precord pointer to the record
566 : DWORD * readn record length in bytes
567 : Function value:
568 : status : from lower function
569 : \********************************************************************/
570 : {
571 0 : *precord = my.pmp;
572 0 : if (data_fmt == FORMAT_MIDAS) {
573 0 : return midas_physrec_get(*precord, readn);
574 : } else
575 0 : return MD_UNKNOWN_FORMAT;
576 : }
577 :
578 : /*------------------------------------------------------------------*/
579 0 : INT md_log_write(INT handle, INT data_fmt, INT type, void *prec, DWORD nbytes)
580 : /********************************************************************\
581 : Routine: external md_log_write
582 : Purpose: Write a physical record to the out device.
583 :
584 : Input:
585 : void handle : file handle
586 : INT data_fmt : YBOS or MIDAS
587 : INT type : Tape or disk
588 : void *prec : record pointer
589 : DWORD nbytes : record length to be written
590 : Output:
591 : none
592 : Function value:
593 : status : from lower function SS_SUCCESS, SS_FILE_ERROR
594 : \********************************************************************/
595 : {
596 : INT status;
597 : DWORD written;
598 :
599 0 : status = data_fmt; /* avoid compiler warning */
600 : /* write record */
601 0 : status = md_dev_os_write(handle, type, prec, nbytes, &written);
602 0 : return status;
603 : }
604 :
605 : #if 0 // OBSOLETE, NOT USED ANYMORE
606 : /*------------------------------------------------------------------*/
607 : INT md_physrec_skip(INT data_fmt, INT bl)
608 : /********************************************************************\
609 : Routine: external md_physrec_skip
610 : Purpose: Skip physical record until block = bl for the given data
611 : format, Under midas the skip is an event as no physical
612 : record is present under that format,
613 : Input:
614 : INT data_fmt : YBOS or MIDAS
615 : INT bl: block number (-1==all, 0 = first block)
616 : in case of MIDAS the bl represent an event
617 : Output:
618 : none
619 : Function value:
620 : status : from lower function
621 : \********************************************************************/
622 : {
623 : if (data_fmt == FORMAT_MIDAS) {
624 : midas_event_skip(bl);
625 : return MD_SUCCESS;
626 : } else
627 : return MD_UNKNOWN_FORMAT;
628 : }
629 : #endif
630 :
631 : #if 0 // NOT USED
632 : /*------------------------------------------------------------------*/
633 : INT midas_event_skip(INT evtn)
634 : /********************************************************************\
635 : Routine: midas_event_skip
636 : Purpose: skip event on a MIDAS file.
637 : Input:
638 : INT evtn event record number. (start at 0)
639 : if evt = -1 : skip skiping
640 : Output:
641 : none
642 : Function value:
643 : MD_SUCCESS Ok
644 : \********************************************************************/
645 : {
646 : void *pevent;
647 : DWORD size;
648 :
649 : size = 0;
650 : if (evtn == -1) {
651 : /* if(midas_event_get(&pevent, &size) == MD_SUCCESS) */
652 : return MD_SUCCESS;
653 : }
654 : while (midas_event_get(&pevent, &size) == MD_SUCCESS) {
655 : if ((INT) my.evtn < evtn) {
656 : printf("Skipping event_# ... ");
657 : printf("%d \r", my.evtn);
658 : fflush(stdout);
659 : } else {
660 : printf("\n");
661 : return MD_SUCCESS;
662 : }
663 : }
664 : return MD_DONE;
665 : }
666 : #endif
667 :
668 : /*------------------------------------------------------------------*/
669 0 : INT md_all_info_display(INT what)
670 : /********************************************************************\
671 : Routine: md_all_info_display
672 : Purpose: display on screen all the info about "what".
673 : Input:
674 : INT what type of display.
675 : Output:
676 : none
677 : Function value:
678 : INT MD_SUCCESS
679 : MD_DONE
680 : \********************************************************************/
681 : {
682 0 : if (my.fmt == FORMAT_MIDAS) {
683 : DWORD mbn, run, ser;
684 : WORD id, msk;
685 0 : mbn = my.evtn;
686 0 : run = my.runn;
687 0 : id = my.pmh->event_id;
688 0 : msk = my.pmh->trigger_mask;
689 0 : ser = my.pmh->serial_number;
690 0 : switch (what) {
691 0 : case D_RECORD:
692 : case D_HEADER:
693 0 : printf(">>> No physical record structure for Midas format <<<\n");
694 0 : return MD_DONE;
695 : break;
696 0 : case D_EVTLEN:
697 0 : printf("Evt#%d- ", my.evtn);
698 0 : printf("%irun 0x%4.4uxid 0x%4.4uxmsk %5dmevt#", run, id, msk, mbn);
699 0 : printf("%5del/x%x %5dserial\n", my.evtlen, my.evtlen, ser);
700 0 : break;
701 : }
702 : } else {
703 0 : assert(!"unsupported data format, sorry!");
704 : }
705 :
706 0 : return MD_SUCCESS;
707 : }
708 :
709 : /*------------------------------------------------------------------*/
710 0 : INT md_event_swap(INT data_fmt, void *pevent)
711 : /********************************************************************\
712 : Routine: external md_event_swap
713 : Purpose: Swap an event from the given data format.
714 : Input:
715 : INT data_fmt : YBOS or MIDAS
716 : void * pevent : pointer to either plrl or pheader
717 : Output:
718 : none
719 : Function value:
720 : status : from the lower function
721 : \********************************************************************/
722 : {
723 : INT status;
724 : BANK_HEADER *pbh;
725 :
726 0 : if (data_fmt == FORMAT_MIDAS) {
727 0 : if ((((EVENT_HEADER *) pevent)->event_id == EVENTID_BOR) ||
728 0 : (((EVENT_HEADER *) pevent)->event_id == EVENTID_EOR) ||
729 0 : (((EVENT_HEADER *) pevent)->event_id == EVENTID_MESSAGE))
730 0 : return SS_SUCCESS;
731 0 : pbh = (BANK_HEADER *) (((EVENT_HEADER *) pevent) + 1);
732 0 : status = bk_swap(pbh, FALSE);
733 0 : return status == CM_SUCCESS ? MD_EVENT_NOT_SWAPPED : MD_SUCCESS;
734 : } else {
735 0 : return MD_UNKNOWN_FORMAT;
736 : }
737 : }
738 :
739 : /*------------------------------------------------------------------*/
740 0 : void md_event_display(const void *pevent, INT data_fmt, INT dsp_mode, INT dsp_fmt, const char *bn)
741 : /********************************************************************\
742 : Routine: external md_event_display
743 : Purpose: display on screen the event data in either Decimal or Hexadecimal.
744 : Input:
745 : void * pevent pointer to either plrl or pheader.
746 : INT data_fmt uses the YBOS or MIDAS event structure
747 : INT dsp_mode display in RAW or Bank mode
748 : INT dsp_fmt display format (DSP_DEC/HEX)
749 : Output:
750 : none
751 : Function value:
752 : none
753 : \********************************************************************/
754 : {
755 0 : if (dsp_mode == DSP_RAW)
756 0 : md_raw_event_display(pevent, data_fmt, dsp_fmt);
757 0 : else if ((dsp_mode == DSP_BANK) || (dsp_mode == DSP_BANK_SINGLE))
758 0 : md_bank_event_display(pevent, data_fmt, dsp_fmt, dsp_mode, bn);
759 : else
760 0 : printf("mdsupport- Unknown format:%i\n", dsp_fmt);
761 0 : return;
762 : }
763 :
764 : /*------------------------------------------------------------------*/
765 0 : void md_raw_event_display(const void *pevent, INT data_fmt, INT dsp_fmt)
766 : /********************************************************************\
767 : Routine: md_raw_event_display
768 : Purpose: display on screen the RAW data of MIDAS format.
769 : Input:
770 : DWORD * pevent points to either plrl or pheader
771 : INT data_fmt uses the YBOS or MIDAS event structure
772 : INT dsp_fmt display format (DSP_DEC/HEX)
773 : Output:
774 : none
775 : Function value:
776 : none
777 : \********************************************************************/
778 : {
779 0 : DWORD lrl = 0, *pevt = NULL, j, i, total = 0;
780 :
781 0 : if (data_fmt == FORMAT_MIDAS) {
782 0 : lrl = ((((EVENT_HEADER *) pevent)->data_size) + sizeof(EVENT_HEADER)) /
783 : sizeof(DWORD); /* in I*4 for raw including the header */
784 0 : pevt = (DWORD *) pevent; /* local copy starting from the pheader */
785 : } else {
786 0 : assert(!"unsupported data_fmt, sorry!");
787 : }
788 :
789 0 : for (i = 0; i < lrl; i += NLINE) {
790 0 : printf("%6.0d->: ", total);
791 0 : for (j = 0; j < NLINE; j++) {
792 0 : if ((i + j) < lrl) {
793 0 : if (dsp_fmt == DSP_DEC)
794 0 : printf("%8.i ", *pevt);
795 : else
796 0 : printf("%8.8x ", *pevt);
797 0 : pevt++;
798 : }
799 : }
800 0 : total += NLINE;
801 0 : printf("\n");
802 : }
803 0 : }
804 :
805 : /*------------------------------------------------------------------*/
806 0 : void md_bank_event_display(const void *pevent, INT data_fmt, INT dsp_fmt, INT dsp_mode, const char *bn)
807 : /********************************************************************\
808 : Routine: md_bank_event_display
809 : Purpose: display on screen the event header, bank list and bank content
810 : for midas format.)
811 : Input:
812 : void * pevent points to either plrl or pheader
813 : INT data_fmt uses the YBOS or MIDAS event structure
814 : INT dsp_fmt display format (DSP_DEC/HEX)
815 : Output:
816 : none
817 : Function value:
818 : none
819 : \********************************************************************/
820 : {
821 : char banklist[MD_STRING_BANKLIST_MAX + STRING_BANKLIST_MAX];
822 : DWORD *pdata, *pdata1;
823 0 : BANK_HEADER *pbh = NULL;
824 : BANK *pmbk;
825 : BANK32 *pmbk32;
826 : BANK32A *pmbk32a;
827 : EVENT_HEADER *pheader;
828 0 : INT status, single = 0;
829 :
830 0 : if (data_fmt == FORMAT_MIDAS) {
831 : /* skip these special events (NO bank structure) */
832 0 : pheader = (EVENT_HEADER *) pevent;
833 0 : if (pheader->event_id == EVENTID_BOR ||
834 0 : pheader->event_id == EVENTID_EOR || pheader->event_id == EVENTID_MESSAGE)
835 0 : return;
836 :
837 : /* check if format is MIDAS or FIXED */
838 0 : pbh = (BANK_HEADER *) (pheader + 1);
839 :
840 : /* Check for single bank display request */
841 0 : if (dsp_mode == DSP_BANK_SINGLE) {
842 0 : bk_locate(pbh, bn, &pdata1);
843 0 : single = 1;
844 : }
845 : /* event header (skip it if in single bank display) */
846 0 : if (!single)
847 0 : printf("Evid:%4.4x- Mask:%4.4x- Serial:%i- Time:0x%x- Dsize:%i/0x%x",
848 0 : (WORD) pheader->event_id, (WORD) pheader->trigger_mask,
849 : pheader->serial_number, pheader->time_stamp, pheader->data_size, pheader->data_size);
850 :
851 0 : if ((pbh->data_size + 8) == pheader->data_size) {
852 : /* bank list */
853 0 : if (!single) {
854 : /* Skip list if in single bank display */
855 0 : status = bk_list((BANK_HEADER *) (pheader + 1), banklist);
856 0 : printf("\n#banks:%i - Bank list:-%s-\n", status, banklist);
857 : }
858 :
859 : /* display bank content */
860 0 : if (bk_is32a(pbh)) {
861 0 : pmbk32a = NULL;
862 : do {
863 0 : bk_iterate32a(pbh, &pmbk32a, &pdata);
864 0 : if (pmbk32a != NULL)
865 0 : if (single && (pdata == pdata1))
866 0 : midas_bank_display32<BANK32A>(pmbk32a, dsp_fmt);
867 0 : if (!single)
868 0 : if (pmbk32a != NULL)
869 0 : midas_bank_display32<BANK32A>(pmbk32a, dsp_fmt);
870 0 : } while (pmbk32a != NULL);
871 0 : } else if (bk_is32(pbh)) {
872 0 : pmbk32 = NULL;
873 : do {
874 0 : bk_iterate32(pbh, &pmbk32, &pdata);
875 0 : if (pmbk32 != NULL)
876 0 : if (single && (pdata == pdata1))
877 0 : midas_bank_display32<BANK32>(pmbk32, dsp_fmt);
878 0 : if (!single)
879 0 : if (pmbk32 != NULL)
880 0 : midas_bank_display32<BANK32>(pmbk32, dsp_fmt);
881 0 : } while (pmbk32 != NULL);
882 : } else {
883 0 : pmbk = NULL;
884 : do {
885 0 : bk_iterate(pbh, &pmbk, &pdata);
886 0 : if (pmbk != NULL)
887 0 : if (single && (pdata == pdata1))
888 0 : midas_bank_display(pmbk, dsp_fmt);
889 0 : if (!single)
890 0 : if (pmbk != NULL)
891 0 : midas_bank_display(pmbk, dsp_fmt);
892 0 : } while (pmbk != NULL);
893 : }
894 : } else {
895 0 : printf("\nFIXED event with Midas Header\n");
896 0 : md_raw_event_display(pevent, data_fmt, dsp_fmt);
897 : }
898 : } else {
899 0 : assert(!"unsupported data_fmt, sorry!");
900 : }
901 :
902 0 : return;
903 : }
904 :
905 : /*------------------------------------------------------------------*/
906 0 : void md_bank_display(void *pmbh, void *pbk, INT data_fmt, INT dsp_mode, INT dsp_fmt)
907 : /********************************************************************\
908 : Routine: external md_bank_display
909 : Purpose: display on screen the given bank.
910 : Input:
911 : void * pbk pointer to the bank
912 : INT data_fmt YBOS or MIDAS
913 : INT dsp_mode display mode (RAW/BANK)
914 : INT dsp_fmt display format (DSP_DEC/HEX)
915 : Output:
916 : none
917 : Function value:
918 : none
919 : \********************************************************************/
920 : {
921 0 : if (dsp_mode == DSP_RAW)
922 0 : md_raw_bank_display(pbk, data_fmt, dsp_fmt);
923 : else {
924 0 : if (data_fmt == FORMAT_MIDAS) {
925 0 : if (bk_is32a(pmbh)) {
926 0 : midas_bank_display32<BANK32A>((BANK32A *) pbk, dsp_fmt);
927 0 : } else if (bk_is32(pmbh)) {
928 0 : midas_bank_display32<BANK32>((BANK32 *) pbk, dsp_fmt);
929 : } else {
930 0 : midas_bank_display((BANK *) pbk, dsp_fmt);
931 : }
932 : } else {
933 0 : assert(!"unsupported data_fmt, sorry!");
934 : }
935 : }
936 0 : return;
937 : }
938 :
939 : /*------------------------------------------------------------------*/
940 0 : void md_raw_bank_display(void *pbank, INT data_fmt, INT dsp_fmt)
941 : /********************************************************************\
942 : Routine: md__raw_bank_display
943 : Purpose: display on screen the RAW data of a given YBOS/MIDAS bank.
944 : Input:
945 : void * pbank pointer to the bank name
946 : INT data_fmt uses the YBOS or MIDAS event structure
947 : INT dsp_fmt display format (DSP_DEC/HEX)
948 : Output:
949 : none
950 : Function value:
951 : none
952 : \********************************************************************/
953 : {
954 0 : DWORD *pdata = NULL, lrl = 0, j, i;
955 :
956 0 : if (data_fmt == FORMAT_MIDAS) {
957 0 : lrl = ((BANK *) pbank)->data_size >> 2; /* in DWORD */
958 0 : pdata = (DWORD *) ((BANK *) (pbank) + 1);
959 : } else {
960 0 : assert(!"unsupported data_fmt, sorry!");
961 : }
962 :
963 0 : for (i = 0; i < lrl; i += NLINE) {
964 0 : j = 0;
965 0 : printf("\n%4i-> ", i + j + 1);
966 0 : for (j = 0; j < NLINE; j++) {
967 0 : if ((i + j) < lrl) {
968 0 : if (dsp_fmt == DSP_DEC)
969 0 : printf("%8.i ", *((DWORD *) pdata));
970 0 : if (dsp_fmt == DSP_ASC)
971 0 : printf("%8.8x ", *((DWORD *) pdata));
972 0 : if (dsp_fmt == DSP_HEX)
973 0 : printf("%8.8x ", *((DWORD *) pdata));
974 0 : pdata++;
975 : }
976 : }
977 : }
978 0 : }
979 :
980 : #if 0 // OBSOLETE, NOT USED ANYMORE
981 : /*------------------------------------------------------------------*/
982 : INT midas_event_get(void **pevent, DWORD *readn)
983 : /********************************************************************\
984 : Routine: midas_event_get
985 : Purpose: read one MIDAS event.
986 : Will detect:
987 : The first pass in getting the record number being -1
988 : The last pass in checking the midas_physrec_get() readn
989 : being different then the my.size then flushing the current
990 : buffer until pointer goes beyond last event.
991 : Input:
992 : void ** pevent points to MIDAS HEADER
993 : Output:
994 : DWORD * readn event size in bytes (MIDAS)
995 : Function value:
996 : MD_DONE No more record to read
997 : MD_SUCCESS Ok
998 : \********************************************************************/
999 : {
1000 : INT status, leftover;
1001 : DWORD fpart;
1002 : static DWORD size = 0;
1003 :
1004 : /* save pointer */
1005 : *pevent = (char *) my.pmh;
1006 : if (size == 0)
1007 : size = my.size;
1008 :
1009 : /* first time in get physrec once */
1010 : if ((int) my.recn == -1) {
1011 : status = midas_physrec_get((void *) my.pmp, &size);
1012 : if (status != MD_SUCCESS)
1013 : return (MD_DONE);
1014 : }
1015 :
1016 : /*-PAA- Jul 12/2002
1017 : if (((my.pmp+size) - (char *)my.pme) == 0)
1018 : return (MD_DONE);
1019 : */
1020 :
1021 : /* copy header only */
1022 : if (((my.pmp + size) - (char *) my.pme) < (int) sizeof(EVENT_HEADER)) {
1023 : fpart = (my.pmp + my.size) - (char *) my.pme;
1024 : memcpy(my.pmh, my.pme, fpart);
1025 : my.pmh = (EVENT_HEADER *) (((char *) my.pmh) + fpart);
1026 : leftover = sizeof(EVENT_HEADER) - fpart;
1027 : status = midas_physrec_get((void *) my.pmp, &size);
1028 : if (status != MD_SUCCESS)
1029 : return (MD_DONE);
1030 : memset(my.pmp + size, -1, my.size - size);
1031 : my.pme = (EVENT_HEADER *) my.pmp;
1032 : memcpy(my.pmh, my.pme, leftover);
1033 : my.pme = (EVENT_HEADER *) (((char *) my.pme) + leftover);
1034 : my.pmh = (EVENT_HEADER *) *pevent;
1035 : } else {
1036 : memcpy(my.pmh, my.pme, sizeof(EVENT_HEADER));
1037 : my.pme = (EVENT_HEADER *) (((char *) my.pme) + sizeof(EVENT_HEADER));
1038 : }
1039 : /* leave with pmh to destination header
1040 : pmrd to destination event (pmh+1)
1041 : pme to source event
1042 : */
1043 : my.pmrd = (char *) (my.pmh + 1);
1044 :
1045 : /* check for end of file */
1046 : if (my.pmh->event_id == -1)
1047 : return MD_DONE;
1048 :
1049 : /* copy event (without header) */
1050 : leftover = my.pmh->data_size;
1051 :
1052 : /* check for block crossing */
1053 : while (((my.pmp + size) - (char *) my.pme) < leftover) {
1054 : fpart = (my.pmp + my.size) - (char *) my.pme;
1055 : memcpy(my.pmrd, my.pme, fpart);
1056 : my.pmrd += fpart;
1057 : leftover -= fpart;
1058 : status = midas_physrec_get((void *) my.pmp, &size);
1059 : if (status != MD_SUCCESS)
1060 : return (MD_DONE);
1061 : memset(my.pmp + size, -1, my.size - size);
1062 : my.pme = (EVENT_HEADER *) my.pmp;
1063 : }
1064 :
1065 : /* copy left over or full event if no Xing */
1066 : *readn = my.evtlen = my.pmh->data_size + sizeof(EVENT_HEADER);
1067 : memcpy(my.pmrd, my.pme, leftover);
1068 : my.pme = (EVENT_HEADER *) (((char *) my.pme) + leftover);
1069 : my.evtn++;
1070 : return MD_SUCCESS;
1071 : }
1072 : #endif
1073 :
1074 : /*------------------------------------------------------------------*/
1075 0 : INT midas_physrec_get(void *prec, DWORD *readn)
1076 : /********************************************************************\
1077 : Routine: midas_physrec_get
1078 : Purpose: read one physical record.from a MIDAS run
1079 : This is a "fake" physical record as Midas is
1080 : not block structured. This function is used for
1081 : reading a my.size record size. The return readn if different
1082 : then my.size, will indicate a end of run. An extra read will
1083 : indicate an eof.
1084 :
1085 : Input:
1086 : void * prec pointer to the record
1087 : Output:
1088 : DWORD *readn retrieve number of bytes
1089 : Function value:
1090 : MD_DONE No more record to read
1091 : MD_SUCCESS Ok
1092 : \********************************************************************/
1093 : {
1094 0 : INT status = 0;
1095 :
1096 : /* read one block of data */
1097 0 : if (!my.zipfile) {
1098 0 : status = md_dev_os_read(my.handle, my.type, prec, my.size, readn);
1099 : } else {
1100 0 : *readn = gzread(filegz, (char *) prec, my.size);
1101 0 : if (*readn <= 0)
1102 0 : status = SS_FILE_ERROR;
1103 : else
1104 0 : status = SS_SUCCESS;
1105 : }
1106 :
1107 0 : if (status != SS_SUCCESS) {
1108 0 : return (MD_DONE);
1109 : } else {
1110 : /* count blocks */
1111 0 : my.recn++;
1112 0 : return (MD_SUCCESS);
1113 : }
1114 : }
1115 :
1116 : /*------------------------------------------------------------------*/
1117 0 : void midas_bank_display(BANK *pbk, INT dsp_fmt)
1118 : /******************************* *************************************\
1119 : Routine: midas_bank_display
1120 : Purpose: display on screen the pointed MIDAS bank data using MIDAS Bank structure.
1121 : Input:
1122 : BANK * pbk pointer to the BANK
1123 : INT dsp_fmt display format (DSP_DEC/HEX)
1124 : Output:
1125 : none
1126 : Function value:
1127 : none
1128 : \********************************************************************/
1129 : {
1130 : char bank_name[5], strbktype[32];
1131 : char *pdata, *pendbk;
1132 0 : DWORD length_type = 0, lrl;
1133 : INT type, i, j;
1134 :
1135 0 : lrl = pbk->data_size; /* in bytes */
1136 0 : type = pbk->type & 0xff;
1137 0 : bank_name[4] = 0;
1138 0 : memcpy(bank_name, (char *) (pbk->name), 4);
1139 0 : pdata = (char *) (pbk + 1);
1140 :
1141 0 : j = 64; /* elements within line */
1142 0 : i = 1; /* data counter */
1143 0 : strcpy(strbktype, "Unknown format");
1144 0 : if (type == TID_DOUBLE) {
1145 0 : length_type = sizeof(double);
1146 0 : strcpy(strbktype, "double*8");
1147 : }
1148 0 : if (type == TID_FLOAT) {
1149 0 : length_type = sizeof(float);
1150 0 : strcpy(strbktype, "Real*4 (FMT machine dependent)");
1151 : }
1152 0 : if (type == TID_UINT64) {
1153 0 : length_type = sizeof(uint64_t);
1154 0 : strcpy(strbktype, "Unsigned Integer*8");
1155 : }
1156 0 : if (type == TID_INT64) {
1157 0 : length_type = sizeof(int64_t);
1158 0 : strcpy(strbktype, "Signed Integer*8");
1159 : }
1160 0 : if (type == TID_DWORD) {
1161 0 : length_type = sizeof(DWORD);
1162 0 : strcpy(strbktype, "Unsigned Integer*4");
1163 : }
1164 0 : if (type == TID_INT) {
1165 0 : length_type = sizeof(INT);
1166 0 : strcpy(strbktype, "Signed Integer*4");
1167 : }
1168 0 : if (type == TID_WORD) {
1169 0 : length_type = sizeof(WORD);
1170 0 : strcpy(strbktype, "Unsigned Integer*2");
1171 : }
1172 0 : if (type == TID_SHORT) {
1173 0 : length_type = sizeof(short);
1174 0 : strcpy(strbktype, "Signed Integer*2");
1175 : }
1176 0 : if (type == TID_BYTE) {
1177 0 : length_type = sizeof(BYTE);
1178 0 : strcpy(strbktype, "Unsigned Bytes");
1179 : }
1180 0 : if (type == TID_SBYTE) {
1181 0 : length_type = sizeof(BYTE);
1182 0 : strcpy(strbktype, "Signed Bytes");
1183 : }
1184 0 : if (type == TID_BOOL) {
1185 0 : length_type = sizeof(DWORD);
1186 0 : strcpy(strbktype, "Boolean");
1187 : }
1188 0 : if (type == TID_CHAR) {
1189 0 : length_type = sizeof(char);
1190 0 : strcpy(strbktype, "8 bit ASCII");
1191 : }
1192 0 : if (type == TID_STRUCT) {
1193 0 : length_type = sizeof(char);
1194 0 : strcpy(strbktype, "STRUCT (not supported->8 bits)");
1195 : }
1196 0 : if (type == TID_STRING) {
1197 0 : length_type = sizeof(char);
1198 0 : strcpy(strbktype, "String 8bit ASCII");
1199 : }
1200 :
1201 0 : printf("\nBank:%s Length: %i(I*1)/%i(I*4)/%i(Type) Type:%s",
1202 0 : bank_name, lrl, lrl >> 2, lrl / (length_type == 0 ? 1 : length_type), strbktype);
1203 :
1204 0 : pendbk = pdata + lrl;
1205 0 : while (pdata < pendbk) {
1206 0 : switch (type) {
1207 0 : case TID_DOUBLE:
1208 0 : if (j > 3) {
1209 0 : printf("\n%4i-> ", i);
1210 0 : j = 0;
1211 0 : i += 4;
1212 : }
1213 0 : printf("%15.5le ", *((double *) pdata));
1214 0 : pdata = (char *) (((double *) pdata) + 1);
1215 0 : j++;
1216 0 : break;
1217 0 : case TID_FLOAT:
1218 0 : if (j > 7) {
1219 0 : printf("\n%4i-> ", i);
1220 0 : j = 0;
1221 0 : i += 8;
1222 : }
1223 0 : if ((dsp_fmt == DSP_DEC) || (dsp_fmt == DSP_UNK))
1224 0 : printf("%8.3e ", *((float *) pdata));
1225 0 : if (dsp_fmt == DSP_HEX)
1226 0 : printf("0x%8.8x ", *((DWORD *) pdata));
1227 0 : pdata = (char *) (((DWORD *) pdata) + 1);
1228 0 : j++;
1229 0 : break;
1230 0 : case TID_UINT64:
1231 0 : if (j > 7) {
1232 0 : printf("\n%4i-> ", i);
1233 0 : j = 0;
1234 0 : i += 8;
1235 : }
1236 0 : if (dsp_fmt == DSP_DEC)
1237 0 : printf("%16.1llu ", (long long unsigned) *((uint64_t *) pdata));
1238 0 : if ((dsp_fmt == DSP_HEX) || (dsp_fmt == DSP_UNK))
1239 0 : printf("0x%16.16llx ", (long long unsigned) *((uint64_t *) pdata));
1240 0 : pdata = (char *) (((uint64_t *) pdata) + 1);
1241 0 : j++;
1242 0 : break;
1243 0 : case TID_INT64:
1244 0 : if (j > 7) {
1245 0 : printf("\n%4i-> ", i);
1246 0 : j = 0;
1247 0 : i += 8;
1248 : }
1249 0 : if ((dsp_fmt == DSP_DEC) || (dsp_fmt == DSP_UNK))
1250 0 : printf("%16.1lli ", (long long int) *((int64_t *) pdata));
1251 0 : if (dsp_fmt == DSP_HEX)
1252 0 : printf("0x%16.16llx ", (long long unsigned int) *((int64_t *) pdata));
1253 0 : pdata = (char *) (((int64_t *) pdata) + 1);
1254 0 : j++;
1255 0 : break;
1256 0 : case TID_DWORD:
1257 0 : if (j > 7) {
1258 0 : printf("\n%4i-> ", i);
1259 0 : j = 0;
1260 0 : i += 8;
1261 : }
1262 0 : if (dsp_fmt == DSP_DEC)
1263 0 : printf("%8.1i ", *((DWORD *) pdata));
1264 0 : if ((dsp_fmt == DSP_HEX) || (dsp_fmt == DSP_UNK))
1265 0 : printf("0x%8.8x ", *((DWORD *) pdata));
1266 0 : pdata = (char *) (((DWORD *) pdata) + 1);
1267 0 : j++;
1268 0 : break;
1269 0 : case TID_INT:
1270 0 : if (j > 7) {
1271 0 : printf("\n%4i-> ", i);
1272 0 : j = 0;
1273 0 : i += 8;
1274 : }
1275 0 : if ((dsp_fmt == DSP_DEC) || (dsp_fmt == DSP_UNK))
1276 0 : printf("%8.1i ", *((DWORD *) pdata));
1277 0 : if (dsp_fmt == DSP_HEX)
1278 0 : printf("0x%8.8x ", *((DWORD *) pdata));
1279 0 : pdata = (char *) (((DWORD *) pdata) + 1);
1280 0 : j++;
1281 0 : break;
1282 0 : case TID_WORD:
1283 0 : if (j > 7) {
1284 0 : printf("\n%4i-> ", i);
1285 0 : j = 0;
1286 0 : i += 8;
1287 : }
1288 0 : if (dsp_fmt == DSP_DEC)
1289 0 : printf("%5.1i ", *((WORD *) pdata));
1290 0 : if ((dsp_fmt == DSP_HEX) || (dsp_fmt == DSP_UNK))
1291 0 : printf("0x%4.4x ", *((WORD *) pdata));
1292 0 : pdata = (char *) (((WORD *) pdata) + 1);
1293 0 : j++;
1294 0 : break;
1295 0 : case TID_SHORT:
1296 0 : if (j > 7) {
1297 0 : printf("\n%4i-> ", i);
1298 0 : j = 0;
1299 0 : i += 8;
1300 : }
1301 0 : if ((dsp_fmt == DSP_DEC) || (dsp_fmt == DSP_UNK))
1302 0 : printf("%5.1i ", *((short *) pdata));
1303 0 : if (dsp_fmt == DSP_HEX)
1304 0 : printf("0x%4.4x ", *((short *) pdata));
1305 0 : pdata = (char *) (((short *) pdata) + 1);
1306 0 : j++;
1307 0 : break;
1308 0 : case TID_BYTE:
1309 : case TID_STRUCT:
1310 0 : if (j > 15) {
1311 0 : printf("\n%4i-> ", i);
1312 0 : j = 0;
1313 0 : i += 16;
1314 : }
1315 0 : if (dsp_fmt == DSP_DEC)
1316 0 : printf("%4.i ", *((BYTE *) pdata));
1317 0 : if ((dsp_fmt == DSP_HEX) || (dsp_fmt == DSP_UNK))
1318 0 : printf("0x%2.2x ", *((BYTE *) pdata));
1319 0 : pdata++;
1320 0 : j++;
1321 0 : break;
1322 0 : case TID_SBYTE:
1323 0 : if (j > 15) {
1324 0 : printf("\n%4i-> ", i);
1325 0 : j = 0;
1326 0 : i += 16;
1327 : }
1328 0 : if ((dsp_fmt == DSP_DEC) || (dsp_fmt == DSP_UNK))
1329 0 : printf("%4.i ", *((BYTE *) pdata));
1330 0 : if (dsp_fmt == DSP_HEX)
1331 0 : printf("0x%2.2x ", *((BYTE *) pdata));
1332 0 : pdata++;
1333 0 : j++;
1334 0 : break;
1335 0 : case TID_BOOL:
1336 0 : if (j > 15) {
1337 0 : printf("\n%4i-> ", i);
1338 0 : j = 0;
1339 0 : i += 16;
1340 : }
1341 0 : (*((BOOL *) pdata) != 0) ? printf("Y ") : printf("N ");
1342 0 : pdata = (char *) (((DWORD *) pdata) + 1);
1343 0 : j++;
1344 0 : break;
1345 0 : case TID_CHAR:
1346 : case TID_STRING:
1347 0 : if (j > 15) {
1348 0 : printf("\n%4i-> ", i);
1349 0 : j = 0;
1350 0 : i += 16;
1351 : }
1352 0 : if (dsp_fmt == DSP_DEC)
1353 0 : printf("%3.i ", *((BYTE *) pdata));
1354 0 : if ((dsp_fmt == DSP_ASC) || (dsp_fmt == DSP_UNK))
1355 0 : printf("%1.1s ", (char *) pdata);
1356 0 : if (dsp_fmt == DSP_HEX)
1357 0 : printf("0x%2.2x ", *((BYTE *) pdata));
1358 0 : pdata++;
1359 0 : j++;
1360 0 : break;
1361 0 : default:
1362 0 : printf("bank type not supported (%d)\n", type);
1363 0 : return;
1364 : break;
1365 : }
1366 : } /* end of bank */
1367 0 : printf("\n");
1368 0 : return;
1369 : }
1370 :
1371 : /*------------------------------------------------------------------*/
1372 : template<typename T>
1373 0 : void midas_bank_display32(T *pbk, INT dsp_fmt)
1374 : /********************************************************************\
1375 : Routine: midas_bank_display32
1376 : Purpose: display on screen the pointed MIDAS bank data using MIDAS Bank structure.
1377 : for 32bit length banks
1378 : Input:
1379 : BANK32 * pbk pointer to the BANK
1380 : INT dsp_fmt display format (DSP_DEC/HEX)
1381 : Output:
1382 : none
1383 : Function value:
1384 : none
1385 : \********************************************************************/
1386 : {
1387 : char bank_name[5], strbktype[32];
1388 : char *pdata, *pendbk;
1389 0 : DWORD length_type = 0, lrl;
1390 : INT type, i, j;
1391 :
1392 0 : lrl = pbk->data_size; /* in bytes */
1393 0 : type = pbk->type & 0xff;
1394 0 : bank_name[4] = 0;
1395 0 : memcpy(bank_name, (char *) (pbk->name), 4);
1396 0 : pdata = (char *) (pbk + 1);
1397 :
1398 0 : j = 64; /* elements within line */
1399 0 : i = 1; /* data counter */
1400 0 : strcpy(strbktype, "Unknown format");
1401 0 : if (type == TID_DOUBLE) {
1402 0 : length_type = sizeof(double);
1403 0 : strcpy(strbktype, "double*8");
1404 : }
1405 0 : if (type == TID_FLOAT) {
1406 0 : length_type = sizeof(float);
1407 0 : strcpy(strbktype, "Real*4 (FMT machine dependent)");
1408 : }
1409 0 : if (type == TID_UINT64) {
1410 0 : length_type = sizeof(uint64_t);
1411 0 : strcpy(strbktype, "Unsigned Integer*8");
1412 : }
1413 0 : if (type == TID_INT64) {
1414 0 : length_type = sizeof(int64_t);
1415 0 : strcpy(strbktype, "Signed Integer*8");
1416 : }
1417 0 : if (type == TID_DWORD) {
1418 0 : length_type = sizeof(DWORD);
1419 0 : strcpy(strbktype, "Unsigned Integer*4");
1420 : }
1421 0 : if (type == TID_INT) {
1422 0 : length_type = sizeof(INT);
1423 0 : strcpy(strbktype, "Signed Integer*4");
1424 : }
1425 0 : if (type == TID_WORD) {
1426 0 : length_type = sizeof(WORD);
1427 0 : strcpy(strbktype, "Unsigned Integer*2");
1428 : }
1429 0 : if (type == TID_SHORT) {
1430 0 : length_type = sizeof(short);
1431 0 : strcpy(strbktype, "Signed Integer*2");
1432 : }
1433 0 : if (type == TID_BYTE) {
1434 0 : length_type = sizeof(BYTE);
1435 0 : strcpy(strbktype, "Unsigned Bytes");
1436 : }
1437 0 : if (type == TID_SBYTE) {
1438 0 : length_type = sizeof(BYTE);
1439 0 : strcpy(strbktype, "Signed Bytes");
1440 : }
1441 0 : if (type == TID_BOOL) {
1442 0 : length_type = sizeof(DWORD);
1443 0 : strcpy(strbktype, "Boolean");
1444 : }
1445 0 : if (type == TID_CHAR) {
1446 0 : length_type = sizeof(char);
1447 0 : strcpy(strbktype, "8 bit ASCII");
1448 : }
1449 0 : if (type == TID_STRUCT) {
1450 0 : length_type = sizeof(char);
1451 0 : strcpy(strbktype, "STRUCT (not supported->8 bits)");
1452 : }
1453 0 : if (type == TID_STRING) {
1454 0 : length_type = sizeof(char);
1455 0 : strcpy(strbktype, "String 8bit ASCI");
1456 : }
1457 :
1458 0 : printf("\nBank:%s Length: %i(I*1)/%i(I*4)/%i(Type) Type:%s",
1459 0 : bank_name, lrl, lrl >> 2, lrl / (length_type == 0 ? 1 : length_type), strbktype);
1460 :
1461 0 : pendbk = pdata + lrl;
1462 0 : while (pdata < pendbk) {
1463 0 : switch (type) {
1464 0 : case TID_DOUBLE:
1465 0 : if (j > 3) {
1466 0 : printf("\n%4i-> ", i);
1467 0 : j = 0;
1468 0 : i += 4;
1469 : }
1470 0 : printf("%15.5e ", *((double *) pdata));
1471 0 : pdata = (char *) (((double *) pdata) + 1);
1472 0 : j++;
1473 0 : break;
1474 0 : case TID_FLOAT:
1475 0 : if (j > 7) {
1476 0 : printf("\n%4i-> ", i);
1477 0 : j = 0;
1478 0 : i += 8;
1479 : }
1480 0 : if ((dsp_fmt == DSP_DEC) || (dsp_fmt == DSP_UNK))
1481 0 : printf("%8.3e ", *((float *) pdata));
1482 0 : if (dsp_fmt == DSP_HEX)
1483 0 : printf("0x%8.8x ", *((DWORD *) pdata));
1484 0 : pdata = (char *) (((DWORD *) pdata) + 1);
1485 0 : j++;
1486 0 : break;
1487 0 : case TID_UINT64:
1488 0 : if (j > 7) {
1489 0 : printf("\n%4i-> ", i);
1490 0 : j = 0;
1491 0 : i += 8;
1492 : }
1493 0 : if (dsp_fmt == DSP_DEC)
1494 0 : printf("%16.1llu ", (long long unsigned int) *((uint64_t *) pdata));
1495 0 : if ((dsp_fmt == DSP_HEX) || (dsp_fmt == DSP_UNK))
1496 0 : printf("0x%16.16llx ", (long long unsigned int) *((uint64_t *) pdata));
1497 0 : pdata = (char *) (((uint64_t *) pdata) + 1);
1498 0 : j++;
1499 0 : break;
1500 0 : case TID_INT64:
1501 0 : if (j > 7) {
1502 0 : printf("\n%4i-> ", i);
1503 0 : j = 0;
1504 0 : i += 8;
1505 : }
1506 0 : if ((dsp_fmt == DSP_DEC) || (dsp_fmt == DSP_UNK))
1507 0 : printf("%16.1lli ", (long long int) *((int64_t *) pdata));
1508 0 : if (dsp_fmt == DSP_HEX)
1509 0 : printf("0x%16.16llx ", (long long unsigned int) *((int64_t *) pdata));
1510 0 : pdata = (char *) (((int64_t *) pdata) + 1);
1511 0 : j++;
1512 0 : break;
1513 0 : case TID_DWORD:
1514 0 : if (j > 7) {
1515 0 : printf("\n%4i-> ", i);
1516 0 : j = 0;
1517 0 : i += 8;
1518 : }
1519 0 : if (dsp_fmt == DSP_DEC)
1520 0 : printf("%8.1i ", *((DWORD *) pdata));
1521 0 : if ((dsp_fmt == DSP_HEX) || (dsp_fmt == DSP_UNK))
1522 0 : printf("0x%8.8x ", *((DWORD *) pdata));
1523 0 : pdata = (char *) (((DWORD *) pdata) + 1);
1524 0 : j++;
1525 0 : break;
1526 0 : case TID_INT:
1527 0 : if (j > 7) {
1528 0 : printf("\n%4i-> ", i);
1529 0 : j = 0;
1530 0 : i += 8;
1531 : }
1532 0 : if ((dsp_fmt == DSP_DEC) || (dsp_fmt == DSP_UNK))
1533 0 : printf("%8.1i ", *((DWORD *) pdata));
1534 0 : if (dsp_fmt == DSP_HEX)
1535 0 : printf("0x%8.8x ", *((DWORD *) pdata));
1536 0 : pdata = (char *) (((DWORD *) pdata) + 1);
1537 0 : j++;
1538 0 : break;
1539 0 : case TID_WORD:
1540 0 : if (j > 7) {
1541 0 : printf("\n%4i-> ", i);
1542 0 : j = 0;
1543 0 : i += 8;
1544 : }
1545 0 : if (dsp_fmt == DSP_DEC)
1546 0 : printf("%5.1i ", *((WORD *) pdata));
1547 0 : if ((dsp_fmt == DSP_HEX) || (dsp_fmt == DSP_UNK))
1548 0 : printf("0x%4.4x ", *((WORD *) pdata));
1549 0 : pdata = (char *) (((WORD *) pdata) + 1);
1550 0 : j++;
1551 0 : break;
1552 0 : case TID_SHORT:
1553 0 : if (j > 7) {
1554 0 : printf("\n%4i-> ", i);
1555 0 : j = 0;
1556 0 : i += 8;
1557 : }
1558 0 : if ((dsp_fmt == DSP_DEC) || (dsp_fmt == DSP_UNK))
1559 0 : printf("%5.1i ", *((short *) pdata));
1560 0 : if (dsp_fmt == DSP_HEX)
1561 0 : printf("0x%4.4x ", *((short *) pdata));
1562 0 : pdata = (char *) (((short *) pdata) + 1);
1563 0 : j++;
1564 0 : break;
1565 0 : case TID_BYTE:
1566 : case TID_STRUCT:
1567 0 : if (j > 15) {
1568 0 : printf("\n%4i-> ", i);
1569 0 : j = 0;
1570 0 : i += 16;
1571 : }
1572 0 : if (dsp_fmt == DSP_DEC)
1573 0 : printf("%4.i ", *((BYTE *) pdata));
1574 0 : if ((dsp_fmt == DSP_HEX) || (dsp_fmt == DSP_UNK))
1575 0 : printf("0x%2.2x ", *((BYTE *) pdata));
1576 0 : pdata++;
1577 0 : j++;
1578 0 : break;
1579 0 : case TID_SBYTE:
1580 0 : if (j > 15) {
1581 0 : printf("\n%4i-> ", i);
1582 0 : j = 0;
1583 0 : i += 16;
1584 : }
1585 0 : if ((dsp_fmt == DSP_DEC) || (dsp_fmt == DSP_UNK))
1586 0 : printf("%4.i ", *((BYTE *) pdata));
1587 0 : if (dsp_fmt == DSP_HEX)
1588 0 : printf("0x%2.2x ", *((BYTE *) pdata));
1589 0 : pdata++;
1590 0 : j++;
1591 0 : break;
1592 0 : case TID_BOOL:
1593 0 : if (j > 15) {
1594 0 : printf("\n%4i-> ", i);
1595 0 : j = 0;
1596 0 : i += 16;
1597 : }
1598 0 : (*((BOOL *) pdata) != 0) ? printf("Y ") : printf("N ");
1599 0 : pdata = (char *) (((DWORD *) pdata) + 1);
1600 0 : j++;
1601 0 : break;
1602 0 : case TID_CHAR:
1603 : case TID_STRING:
1604 0 : if (j > 15) {
1605 0 : printf("\n%4i-> ", i);
1606 0 : j = 0;
1607 0 : i += 16;
1608 : }
1609 0 : if (dsp_fmt == DSP_DEC)
1610 0 : printf("%3.i ", *((BYTE *) pdata));
1611 0 : if (dsp_fmt == DSP_ASC || (dsp_fmt == DSP_UNK))
1612 0 : printf("%1.1s ", (char *) pdata);
1613 0 : if (dsp_fmt == DSP_HEX)
1614 0 : printf("0x%2.2x ", *((BYTE *) pdata));
1615 0 : pdata++;
1616 0 : j++;
1617 0 : break;
1618 0 : default:
1619 0 : printf("bank type not supported (%d)\n", type);
1620 0 : return;
1621 : break;
1622 : }
1623 : } /* end of bank */
1624 0 : printf("\n");
1625 0 : return;
1626 : }
1627 :
1628 : /*------------------------------------------------------------------*/
1629 : /*--END of MDSUPPORT.C----------------------------------------------*/
1630 : /*------------------------------------------------------------------*/
1631 :
1632 : /**dox***************************************************************/
1633 : /** @} *//* end of mdsupportincludecode */
|