executables addMiniHeader, printMiniHeader and raw2date added
authortkuhr <tkuhr@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 14 Nov 2003 13:01:34 +0000 (13:01 +0000)
committertkuhr <tkuhr@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 14 Nov 2003 13:01:34 +0000 (13:01 +0000)
RAW/addMiniHeader.cxx [new file with mode: 0644]
RAW/binaddMiniHeader.pkg [new file with mode: 0644]
RAW/binprintMiniHeader.pkg [new file with mode: 0644]
RAW/binraw2date.pkg [new file with mode: 0644]
RAW/printMiniHeader.cxx [new file with mode: 0644]
RAW/raw2date.c [new file with mode: 0644]

diff --git a/RAW/addMiniHeader.cxx b/RAW/addMiniHeader.cxx
new file mode 100644 (file)
index 0000000..4ee4dd4
--- /dev/null
@@ -0,0 +1,96 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/* $Id$ */
+
+///////////////////////////////////////////////////////////////////////////////
+//                                                                           //
+// this program adds a mini header to a binary file                          //
+//                                                                           //
+// type "addMiniHeader -?" to get a description of the arguments             //
+//                                                                           //
+///////////////////////////////////////////////////////////////////////////////
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/sendfile.h>
+#include <TError.h>
+#include <TSystem.h>
+#include "AliMiniHeader.h"
+
+
+//_____________________________________________________________________________
+int main(int argc, char** argv)
+{
+  if ((argc < 2) || (argc > 4) || (strcmp(argv[1], "-?") == 0) || 
+      (strcmp(argv[1], "-h") == 0) || (strcmp(argv[1], "--help") == 0)) {
+    printf("\nUsage: addMiniHeader fileName [detectorID [DDLID]]\n\n");
+    printf("         fileName   : name of the raw data file\n");
+    printf("         detectorID : number of the detector (default 0xFF)\n");
+    printf("         DDLID      : number of the DDL (default 0xFFFF)\n\n");
+    return 0;
+  }
+
+  // prepare the mini header
+  AliMiniHeader header;
+  header.fMagicWord[2] = 0x12;
+  header.fMagicWord[1] = 0x34;
+  header.fMagicWord[0] = 0x56;
+  header.fDetectorID = 0xFF;
+  header.fDDLID = 0xFFFF;
+  header.fCompressionFlag = 0;
+  header.fVersion = 1;
+
+  // open the raw data file
+  FILE* file = fopen(argv[1], "rb");
+  if (!file) {
+    ::Fatal("addMiniHeader", "could not open file %s", argv[1]);
+  }
+
+  // set the correct raw data size in the mini header
+  fseek(file, 0, SEEK_END);
+  header.fSize = ftell(file);
+  fseek(file, 0, SEEK_SET);
+
+  // set the detector and DDL id if they are given
+  if (argc > 2) {
+    header.fDetectorID = atoi(argv[2]);
+  }
+  if (argc > 3) {
+    header.fDDLID = atoi(argv[3]);
+  }
+
+  // open a temporary file and write the mini header to it
+  char tmpFileName[] = "tmpXXXXXX";
+  Int_t tmpID = mkstemp(tmpFileName);
+  if (tmpID < 0) {
+    ::Fatal("addMiniHeader", "could not open temporary file");
+  }
+  FILE* tmp = fdopen(tmpID, "w");
+  fwrite(&header, sizeof(header), 1, tmp);
+
+  // copy the raw data to the temporary file
+  char buffer[256];
+  while (Int_t size = fread(buffer, 1, 256, file)) {
+    fwrite(buffer, size, 1, tmp);
+  }
+  fclose(file);
+  fclose(tmp);
+
+  // replace the original file by the temporary one
+  gSystem->Rename(tmpFileName, argv[1]);
+
+  return 0;
+}
diff --git a/RAW/binaddMiniHeader.pkg b/RAW/binaddMiniHeader.pkg
new file mode 100644 (file)
index 0000000..038573f
--- /dev/null
@@ -0,0 +1,3 @@
+SRCS:=addMiniHeader.cxx
+
+ELIBS:= pythia6 pdf microcern
diff --git a/RAW/binprintMiniHeader.pkg b/RAW/binprintMiniHeader.pkg
new file mode 100644 (file)
index 0000000..a85a657
--- /dev/null
@@ -0,0 +1,3 @@
+SRCS:=printMiniHeader.cxx
+
+ELIBS:= pythia6 pdf microcern
diff --git a/RAW/binraw2date.pkg b/RAW/binraw2date.pkg
new file mode 100644 (file)
index 0000000..bc352cc
--- /dev/null
@@ -0,0 +1,3 @@
+CSRCS:=raw2date.c
+
+ELIBS:= pythia6 pdf microcern
diff --git a/RAW/printMiniHeader.cxx b/RAW/printMiniHeader.cxx
new file mode 100644 (file)
index 0000000..2f99ff6
--- /dev/null
@@ -0,0 +1,97 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/* $Id$ */
+
+///////////////////////////////////////////////////////////////////////////////
+//                                                                           //
+// this program prints the mini headers in a raw data file                   //
+//                                                                           //
+// type "printMiniHeader -?" to get a description of the arguments           //
+//                                                                           //
+///////////////////////////////////////////////////////////////////////////////
+
+#include <stdlib.h>
+#include <string.h>
+#include <TError.h>
+#include <TSystem.h>
+#include "AliMiniHeader.h"
+
+
+//_____________________________________________________________________________
+int main(int argc, char** argv)
+{
+  if ((argc < 2) || (argc > 2) || (strcmp(argv[1], "-?") == 0) || 
+      (strcmp(argv[1], "-h") == 0) || (strcmp(argv[1], "--help") == 0)) {
+    printf("\nUsage: printMiniHeader fileName\n\n");
+    printf("         fileName   : name of the raw data file\n\n");
+    return 0;
+  }
+
+  // open the raw data file
+  FILE* file = fopen(argv[1], "rb");
+  if (!file) {
+    ::Fatal("readMiniHeader", "could not open file %s", argv[1]);
+  }
+  fseek(file, 0, SEEK_END);
+  Int_t size = ftell(file);
+  fseek(file, 0, SEEK_SET);
+
+  // read the mini headers
+  AliMiniHeader header;
+  while (!feof(file)) {
+    if (!fread(&header, sizeof(header), 1, file)) {
+      if (!feof(file)) {
+       ::Error("readMiniHeader", "could not read mini header at position %d", 
+               ftell(file));
+      }
+      break;
+    }
+
+    // check the magic word
+    if ((header.fMagicWord[2] != 0x12) ||
+       (header.fMagicWord[1] != 0x34) ||
+       (header.fMagicWord[0] != 0x56)) {
+      ::Error("readMiniHeader", "the magic word is wrong %2x%2x%2x", 
+             header.fMagicWord[2], header.fMagicWord[1], 
+             header.fMagicWord[0]);
+      break;
+    }
+
+    // check the size
+    Int_t bytesLeft = size-ftell(file);
+    if ((Int_t)header.fSize > bytesLeft) {
+      ::Error("readMiniHeader", 
+             "the raw data size exceeds the file size by %d bytes",
+             header.fSize - bytesLeft);
+    }
+
+    // print the header information
+    printf("size        : %d\n", header.fSize);
+    printf("detector ID : %d\n", header.fDetectorID);
+    printf("DDL ID      : %d\n", header.fDDLID);
+    printf("compressed  : %d\n", header.fCompressionFlag);
+    printf("version     : %d\n", header.fVersion);
+    printf("\n");
+
+    // go to next mini header
+    if ((Int_t)header.fSize > bytesLeft) break;
+    fseek(file, header.fSize, SEEK_CUR);
+  }
+
+  fclose(file);
+
+  return 0;
+}
diff --git a/RAW/raw2date.c b/RAW/raw2date.c
new file mode 100644 (file)
index 0000000..ca488a0
--- /dev/null
@@ -0,0 +1,262 @@
+/* raw2date.c
+**
+** Take a raw data file and produce a DATE-formatted data file
+**
+** Revision history:
+**  19/03/03 RD                Created
+*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "DateEvent.h"
+
+#ifndef TRUE
+# define TRUE (0 == 0)
+#endif
+#ifndef FALSE
+# define FALSE (0 == 1)
+#endif
+
+const char *whoAmI;
+int numFiles = 0;
+char **fileNames = NULL;
+int   *dataBlockSizes = NULL;
+void **dataBlocks = NULL;
+int doSor = FALSE;
+int doEor = FALSE;
+int numLoops = 1;
+struct eventHeaderStruct h;
+struct eventHeaderStruct sh;
+struct equipmentHeaderStruct eh;
+
+int usage() {
+  fprintf( stderr, "Usage: %s [-s][-e][-#=N] FILE [FILE]...\n",
+          whoAmI );
+  return FALSE;
+}
+
+int handleArgs( const int argc, char * const * const argv ) {
+  int inFile = FALSE;
+  int arg;
+  
+  if ( argc <= 1 ) return usage();
+
+  for ( arg = 1; arg < argc; arg++ ) {
+    if ( !inFile ) {
+      if ( strcmp( argv[arg], "--" ) == 0 ) {
+       inFile = TRUE;
+       continue;
+      }
+      if ( strcmp( argv[arg], "-s" ) == 0 ) {
+       doSor = TRUE;
+       continue;
+      }
+      if ( strcmp( argv[arg], "-e" ) == 0 ) {
+       doEor = TRUE;
+       continue;
+      }
+      if ( strncmp( argv[arg], "-#=", 3 ) == 0 ) {
+       if ( sscanf( &argv[arg][3], "%d", &numLoops ) != 1 ) {
+         fprintf( stderr,
+                  "Failed to scan \"%s\" (expected: -#=number)\n",
+                  argv[arg] );
+         return usage();
+       }
+       continue;
+      }
+      if ( argv[arg][0] == '-' ) return usage();
+      inFile = TRUE;
+    }
+    if ( (fileNames = realloc( fileNames,
+                              ++numFiles * sizeof( char* ) )) == NULL ) {
+      perror( "malloc failed " );
+      return FALSE;
+    }
+    if ( (fileNames[ numFiles-1 ] = strdup( argv[arg] )) == NULL ) {
+      perror( "strdup failed " );
+      return FALSE;
+    }
+  }
+
+  if ( numFiles < 1 ) return usage();
+  return TRUE;
+}
+
+int readData() {
+  int f;
+
+  if ( (dataBlockSizes = malloc( sizeof(int) * numFiles )) == NULL ) {
+    perror( "malloc failed " );
+    return FALSE;
+  }
+  if ( (dataBlocks = malloc( sizeof( void * ) * numFiles )) == NULL ) {
+    perror( "malloc failed" );
+    return FALSE;
+  }
+  for ( f = 0; f != numFiles; f++ ) {
+    FILE *in;
+    struct stat statData;
+
+    if ( stat( fileNames[f], &statData ) != 0 ) {
+      fprintf( stderr, "Cannot stat file \"%s\"", fileNames[f] );
+      perror( " " );
+      return FALSE;
+    }
+
+    if ( (dataBlockSizes[f] = statData.st_size) < 0 ) {
+      fprintf( stderr,
+              "Stat for file \"%s\" returns size: %d\n",
+              fileNames[f], (int)statData.st_size );
+      return FALSE;
+    }
+    if ( dataBlockSizes[f] == 0 ) {
+      dataBlocks[f] = NULL;
+      continue;
+    }
+    if ( (dataBlocks[f] = malloc( dataBlockSizes[f] )) == NULL ) {
+      fprintf( stderr,
+              "Failed to malloc for file \"%s\" size:%d",
+              fileNames[f], dataBlockSizes[f] );
+      perror( " " );
+      return FALSE;
+    }
+    if ( (in = fopen( fileNames[f], "r" )) == NULL ) {
+      fprintf( stderr, "Failed to open input file \"%s\"", fileNames[f] );
+      perror( " " );
+      return FALSE;
+    }
+    if ( fread( dataBlocks[f],
+               dataBlockSizes[f],
+               1, in ) != 1 ) {
+      fprintf( stderr,
+              "Failed to read from file \"%s\"",
+              fileNames[f] );
+      perror( " " );
+      return FALSE;
+    }
+    fclose( in );
+  }
+  return TRUE;
+}
+
+void initStructs() {
+  h.eventMagic = EVENT_MAGIC_NUMBER;
+  h.eventHeadSize = EVENT_HEAD_BASE_SIZE;
+  h.eventVersion = EVENT_CURRENT_VERSION;
+  h.eventRunNb = 1;
+  ZERO_TRIGGER_PATTERN( h.eventTriggerPattern );
+  ZERO_DETECTOR_PATTERN( h.eventDetectorPattern );
+  RESET_ATTRIBUTES( h.eventTypeAttribute );
+  h.eventLdcId = h.eventGdcId = VOID_ID;
+  memcpy( &sh, &h, sizeof( h ) );
+
+  eh.equipmentType = 0;
+  eh.equipmentId = 0;
+  RESET_ATTRIBUTES( eh.equipmentTypeAttribute );
+  eh.equipmentBasicElementSize = 1;
+}
+
+void dumpDummy( const int size ) {
+  int i;
+  char pat;
+
+  for ( i = 0, pat = 0; i != size; i++, pat++ )
+    fwrite( &pat, 1, 1, stdout );
+}
+
+void createSorEor( eventTypeType eventType ) {
+  int l;
+  int i;
+
+  sh.eventSize = 10872;
+  h.eventType = sh.eventType = eventType;
+  LOAD_RAW_EVENT_ID( h.eventId, 1, 0, 1 );
+  LOAD_RAW_EVENT_ID( sh.eventId, 1, 0, 1 );
+  RESET_ATTRIBUTES( h.eventTypeAttribute );
+  RESET_ATTRIBUTES( sh.eventTypeAttribute );
+  SET_SYSTEM_ATTRIBUTE( h.eventTypeAttribute, ATTR_P_START );
+  SET_SYSTEM_ATTRIBUTE( sh.eventTypeAttribute, ATTR_P_START );
+  h.eventGdcId = sh.eventGdcId = 0;
+
+  for ( i = 0; i != 2; i++ ) {
+    h.eventSize = sh.eventSize;
+    CLEAR_SYSTEM_ATTRIBUTE( h.eventTypeAttribute, ATTR_SUPER_EVENT );
+    fwrite( &h, sizeof(h), 1, stdout );
+    dumpDummy( h.eventSize - EVENT_HEAD_BASE_SIZE );
+
+    SET_SYSTEM_ATTRIBUTE( h.eventTypeAttribute, ATTR_SUPER_EVENT );
+    h.eventSize = sh.eventSize + EVENT_HEAD_BASE_SIZE;
+  
+    for ( l = 0; l != numFiles; l++ ) {
+      fwrite( &h, sizeof(h), 1, stdout );
+      sh.eventLdcId = l;
+      fwrite( &sh, sizeof(sh), 1, stdout );
+      dumpDummy( sh.eventSize - EVENT_HEAD_BASE_SIZE );
+    }
+    CLEAR_SYSTEM_ATTRIBUTE( h.eventTypeAttribute, ATTR_P_START );
+    CLEAR_SYSTEM_ATTRIBUTE( sh.eventTypeAttribute, ATTR_P_START );
+    SET_SYSTEM_ATTRIBUTE( h.eventTypeAttribute, ATTR_P_END );
+    SET_SYSTEM_ATTRIBUTE( sh.eventTypeAttribute, ATTR_P_END );
+  }
+}
+
+void createSor() {
+  createSorEor( START_OF_RUN );
+}
+
+void createEor() {
+  createSorEor( END_OF_RUN );
+}
+
+void createData( const int loopNo ) {
+  int n;
+  int l;
+  int totSize;
+
+  for ( totSize = EVENT_HEAD_BASE_SIZE, l = 0;
+       l != numFiles;
+       l++ )
+    totSize += EVENT_HEAD_BASE_SIZE + sizeof( eh ) + dataBlockSizes[l];
+  
+  h.eventSize = totSize;
+  h.eventType = sh.eventType = PHYSICS_EVENT;
+  RESET_ATTRIBUTES( h.eventTypeAttribute );
+  SET_SYSTEM_ATTRIBUTE( h.eventTypeAttribute, ATTR_SUPER_EVENT );
+  RESET_ATTRIBUTES( sh.eventTypeAttribute );
+  h.eventGdcId = sh.eventGdcId = 0;
+  
+  for ( n = 0; n != loopNo; n++ ) {
+    LOAD_RAW_EVENT_ID( h.eventId, n, 0, n );
+    LOAD_RAW_EVENT_ID( sh.eventId, n, 0, n );
+    fwrite( &h, sizeof(h), 1, stdout );
+
+    for ( l = 0; l != numFiles; l++ ) {
+      sh.eventLdcId = l;
+      sh.eventSize = EVENT_HEAD_BASE_SIZE + sizeof( eh ) + dataBlockSizes[l];
+      eh.equipmentSize = dataBlockSizes[l];
+      fwrite( &sh, sizeof(sh), 1, stdout );
+      fwrite( &eh, sizeof(eh), 1, stdout );
+      fwrite( dataBlocks[l], dataBlockSizes[l], 1, stdout );
+    }
+  }
+}
+
+void createStream() {
+  if ( doSor ) createSor();
+  createData( numLoops );
+  if ( doEor ) createEor();
+}
+
+int main( int argc, char **argv ) {
+  whoAmI = argv[0];
+
+  if ( !handleArgs( argc, argv ) ) return 1;
+  if ( !readData() ) return 1;
+  initStructs();
+  createStream();
+  return 0;
+}