1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // this program adds a mini header to a binary file //
22 // type "addMiniHeader -?" to get a description of the arguments //
24 ///////////////////////////////////////////////////////////////////////////////
30 #include "AliMiniHeader.h"
33 //_____________________________________________________________________________
34 int main(int argc, char** argv)
36 if ((argc < 2) || (argc > 4) || (strcmp(argv[1], "-?") == 0) ||
37 (strcmp(argv[1], "-h") == 0) || (strcmp(argv[1], "--help") == 0)) {
38 printf("\nUsage: addMiniHeader fileName [detectorID [DDLID]]\n\n");
39 printf(" fileName : name of the raw data file\n");
40 printf(" detectorID : number of the detector (default 0xFF)\n");
41 printf(" DDLID : number of the DDL (default 0xFFFF)\n\n");
45 // prepare the mini header
47 header.fMagicWord[2] = 0x12;
48 header.fMagicWord[1] = 0x34;
49 header.fMagicWord[0] = 0x56;
50 header.fDetectorID = 0xFF;
51 header.fDDLID = 0xFFFF;
52 header.fCompressionFlag = 0;
55 // open the raw data file
56 FILE* file = fopen(argv[1], "rb");
58 ::Fatal("addMiniHeader", "could not open file %s", argv[1]);
61 // set the correct raw data size in the mini header
62 fseek(file, 0, SEEK_END);
63 header.fSize = ftell(file);
64 fseek(file, 0, SEEK_SET);
66 // set the detector and DDL id if they are given
68 header.fDetectorID = atoi(argv[2]);
71 header.fDDLID = atoi(argv[3]);
74 // open a temporary file and write the mini header to it
75 char tmpFileName[] = "tmpXXXXXX";
76 Int_t tmpID = mkstemp(tmpFileName);
78 ::Fatal("addMiniHeader", "could not open temporary file");
80 FILE* tmp = fdopen(tmpID, "w");
81 fwrite(&header, sizeof(header), 1, tmp);
83 // copy the raw data to the temporary file
85 while (Int_t size = fread(buffer, 1, 256, file)) {
86 fwrite(buffer, size, 1, tmp);
91 // replace the original file by the temporary one
92 gSystem->Rename(tmpFileName, argv[1]);