#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define MAX_SEGS 8 /* max. number of segments to take in events */ #define MAX_PARS (8*MAX_SEGS+1) /* max. number of parameters to fit */ #define MAX_INTPTS (2*MAX_SEGS) /* max. number of interaction points */ #define MAXDATASIZE 3000 #define PMODE 0644 #define GEB_TYPE_DECOMP 1 /*----------*/ /* format-2 */ /*----------*/ typedef struct DCR_INTPTS2 { float x, y, z, e; /* here e refers to the fraction */ int seg; /* segment hit */ float seg_ener; /* energy of hit segment */ } DCR_INTPTS2; struct crys_intpts2 { int type; /* typically: abcd1234 */ int crystal_id; int num; float tot_e; long long int timestamp; long long trig_time; float t0; float cfd; float chisq; float norm_chisq; float baseline; int pad; /* to ensure 8-byte alignment of struct */ DCR_INTPTS2 intpts[MAX_INTPTS]; }; /*----------*/ /* format-3 */ /*----------*/ typedef struct DCR_INTPTS3 { float x, y, z, e; /* here e refers to the fraction */ int seg; /* segment hit */ float seg_ener; /* energy of hit segment */ } DCR_INTPTS3; struct crys_intpts3 { int type; /* defined as abcd5678 */ int crystal_id; int num; /* # of int pts from decomp, or # of nets on decomp error */ float tot_e; /* dnl corrected */ int core_e[4]; /* 4 raw core energies from FPGA filter (no shift) */ long long int timestamp; long long trig_time; /* not yet impl */ float t0; float cfd; float chisq; float norm_chisq; float baseline; float prestep; /* avg trace value before step */ float poststep; /* avg trace value following step */ int pad; /* non-0 on decomp error, value gives error type */ DCR_INTPTS3 intpts[MAX_INTPTS]; }; struct gebData { int type; /* type of data following */ int length; long long timestamp; }; typedef struct crys_intpts2 CRYS_INTPTS2; typedef struct crys_intpts3 CRYS_INTPTS3; typedef struct gebData GEBDATA; /*-----------------------------------------------------------------------------*/ int main (int argc, char **argv) { /* declarations */ off_t inData; /* input file */ off_t outData; /* input file */ GEBDATA *gd; int siz; CRYS_INTPTS2 *payload2; CRYS_INTPTS3 *payload3; long long int nn = 0; /* initialize */ gd = (GEBDATA *) calloc (1, sizeof (GEBDATA)); payload2 = (CRYS_INTPTS2 *) calloc (1, MAXDATASIZE); payload3 = (CRYS_INTPTS3 *) calloc (1, MAXDATASIZE); /* open input file */ inData = 0; inData = open ((char *) argv[1], O_RDONLY); if (inData == 0) { printf ("could not open input data file %s, quit!\n", argv[1]); exit (1); }; printf ("input data file %s is open\n", argv[1]); /* open output file */ outData = 0; outData = open ((char *) argv[2], O_WRONLY | O_CREAT | O_TRUNC, PMODE); if (outData == 0) { printf ("could not open output data file %s, quit!\n", argv[2]); exit (1); }; printf ("output data file \"%s\" is open\n", argv[2]); fflush (stdout); /* read and convert */ while (1) { /*------------------------*/ /* read next data segment */ /*------------------------*/ /* read the gebHeader */ siz = read (inData, (char *) gd, sizeof (GEBDATA)); if (siz != sizeof (GEBDATA)) { printf ("cannot read GEBDATA, got siz=%i, not %i as expected\n", siz, sizeof (GEBDATA)); printf ("read %lli payload2s\n", nn); exit (1); }; if (nn < 100) printf ("%4lli: read header: %i bytes; ", nn, siz); /* read the payload2 */ if (gd->length >= MAXDATASIZE) { printf ("gd->length= %i > %i (MAXDATASIZE)\n", gd->length, MAXDATASIZE); exit (2); }; siz = read (inData, (char *) payload2, gd->length); if (siz != gd->length) { printf ("readHit: read error siz=%i != gd->length=%i\n", siz, gd->length); return (3); }; if (nn < 100) printf ("read payload2: %i bytes; type=%i\n", siz, gd->type); if (gd->type == GEB_TYPE_DECOMP) { /* go through the GT event */ gd->length = sizeof (CRYS_INTPTS3); bzero ((void *) payload3, sizeof (CRYS_INTPTS3)); /* Pass on as much as we have of the the header. */ /* What we can't/don't pass will be zero */ payload3->type = payload2->type; payload3->crystal_id = payload2->crystal_id; payload3->num = payload2->num; payload3->tot_e = payload2->tot_e; payload3->timestamp = payload2->timestamp; payload3->trig_time = payload2->trig_time; payload3->t0 = payload2->t0; payload3->cfd = payload2->cfd; payload3->chisq = payload2->chisq; payload3->norm_chisq = payload2->norm_chisq; payload3->baseline = payload2->baseline; payload3->pad = payload2->pad; /* pass on the interaction points */ memcpy ((char *) &payload3->intpts[0], (char *) &payload2->intpts[0], sizeof (DCR_INTPTS3) * MAX_INTPTS); /* writeout new format event */ siz = write (outData, (char *) gd, sizeof (GEBDATA)); siz = write (outData, (char *) payload3, gd->length); } else { /* just pass on the data untouched */ siz = write (outData, (char *) gd, sizeof (GEBDATA)); siz = write (outData, (char *) payload2, gd->length); }; nn++; }; /* done */ return (0); };