]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/printMiniHeader.cxx
protection against truncated data
[u/mrichter/AliRoot.git] / RAW / printMiniHeader.cxx
CommitLineData
5b7dab70 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// this program prints the mini headers in a raw data file //
21// //
22// type "printMiniHeader -?" to get a description of the arguments //
23// //
24///////////////////////////////////////////////////////////////////////////////
25
26#include <stdlib.h>
27#include <string.h>
28#include <TError.h>
29#include <TSystem.h>
30#include "AliMiniHeader.h"
31
32
33//_____________________________________________________________________________
34int main(int argc, char** argv)
35{
36 if ((argc < 2) || (argc > 2) || (strcmp(argv[1], "-?") == 0) ||
37 (strcmp(argv[1], "-h") == 0) || (strcmp(argv[1], "--help") == 0)) {
38 printf("\nUsage: printMiniHeader fileName\n\n");
39 printf(" fileName : name of the raw data file\n\n");
40 return 0;
41 }
42
43 // open the raw data file
44 FILE* file = fopen(argv[1], "rb");
45 if (!file) {
46 ::Fatal("readMiniHeader", "could not open file %s", argv[1]);
47 }
48 fseek(file, 0, SEEK_END);
49 Int_t size = ftell(file);
50 fseek(file, 0, SEEK_SET);
51
52 // read the mini headers
53 AliMiniHeader header;
54 while (!feof(file)) {
55 if (!fread(&header, sizeof(header), 1, file)) {
56 if (!feof(file)) {
57 ::Error("readMiniHeader", "could not read mini header at position %d",
58 ftell(file));
59 }
60 break;
61 }
62
63 // check the magic word
64 if ((header.fMagicWord[2] != 0x12) ||
65 (header.fMagicWord[1] != 0x34) ||
66 (header.fMagicWord[0] != 0x56)) {
67 ::Error("readMiniHeader", "the magic word is wrong %2x%2x%2x",
68 header.fMagicWord[2], header.fMagicWord[1],
69 header.fMagicWord[0]);
70 break;
71 }
72
73 // check the size
74 Int_t bytesLeft = size-ftell(file);
75 if ((Int_t)header.fSize > bytesLeft) {
76 ::Error("readMiniHeader",
77 "the raw data size exceeds the file size by %d bytes",
78 header.fSize - bytesLeft);
79 }
80
81 // print the header information
82 printf("size : %d\n", header.fSize);
83 printf("detector ID : %d\n", header.fDetectorID);
84 printf("DDL ID : %d\n", header.fDDLID);
85 printf("compressed : %d\n", header.fCompressionFlag);
86 printf("version : %d\n", header.fVersion);
87 printf("\n");
88
89 // go to next mini header
90 if ((Int_t)header.fSize > bytesLeft) break;
91 fseek(file, header.fSize, SEEK_CUR);
92 }
93
94 fclose(file);
95
96 return 0;
97}