/* main clustering and tracking program */ /* ~simulating Carl's event builder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "ctk.h" #define DEBUGGETEVENT 0 off_t inData; /* input file */ TRACKINGPAR Pars; /*--------------------------------------------------*/ /*-----------------------------------------------------------*/ int find_target_pos (float target_pos[3]) { /* declarations */ int i; /* find target position from external data */ for (i = 0; i < 3; i++) target_pos[i] = 0; /* done */ return (0); } /*-----------------------------------------------------------*/ int main (int argc, char **argv) { /* declarations */ int ncalls = 0, haveTrack = 0, trackStatus = 1, i, i1, j; int returnCodes[1000]; /* the input track structure */ TRACK_STRUCT track; /* collection of former global variables */ /* which we now keep in the stack so */ /* we can run independent threads in the cores */ struct tms timesThen; STAT ctkStat; SHELLHIT shellhit; int nClusters; CLUSTER_INTPTS Clstr[MAXCLUSTERHITS]; float target_pos[3]; /*------*/ /* help */ /*------*/ if (argc != 3) { printf ("use: %s chatfile datafile\n", argv[0]); printf ("\n"); printf ("almost everything that has to do\n"); printf ("with specifying parameters for how\n"); printf ("to do the tracking is specified in the\n"); printf ("chat file. This file is ~selfdocumenting.\n"); printf ("\n"); exit (0); }; /*------------*/ /* initialize */ /*------------*/ // system ("ulimit -a"); for (i = 0; i < 1000; i++) returnCodes[i] = 0; /* allocate space for track structure */ track.gd = (GEBDATA *) calloc (MAXTRACK, sizeof (GEBDATA)); track.payload = (PAYLOAD *) calloc (MAXTRACK, sizeof (PAYLOAD)); memset ((void *) &ctkStat, 0, sizeof (STAT)); /* open data file */ inData = 0; /* + name of data file */ /* | */ inData = open ((char *) argv[2], O_RDONLY); if (inData == 0) { printf ("could not open input data file %s, quit!\n", argv[2]); exit (1); }; printf ("input data file %s is open\n", argv[2]); // printf("inData=0x%x\n", inData); /* do all necessary initializations */ /* for the clustering/tracking code */ setupTrack (×Then, &ctkStat, &shellhit); /* read chat script for tracking parameters */ /* this input format could be changed in the future */ /* but for now this is how we input the */ /* parameters we need for tracking */ /* + name of chat file */ /* | */ readChatFile (argv[1]); /* for debug purpuses only:: here we */ /* skip through a number of events */ /* to get to an interesting one in */ /* a hurry; not for production version */ i1 = 0; for (i = 0; i < i1; i++) getEvent (&track); printf ("trackMain: skipped %i events\n", i1); /*---------------------------------------------*/ /* loop: get event, cluster&track, write event */ /*---------------------------------------------*/ haveTrack = 0; printf ("start...\n"); fflush (stdout); while (haveTrack == 0) { /* zero out (should not be necessary) */ #if(1) for (j = 0; j < MAXCLUSTERHITS; j++) memset ((void *) &Clstr[j], 0, sizeof (CLUSTER_INTPTS)); #endif /* get an event to pass on */ /* to the tracking code */ haveTrack = getEvent (&track); // printf("haveTrack = %i\n", haveTrack); // trapbad ("trackMain",&track); if (haveTrack == 0) { ncalls++; // printf ("trackMain: ncalls %i\n", ncalls); // fflush (stdout); find_target_pos (target_pos); /* send it to the tracking code */ // printf ("trackMain: trackEvent\n"); // fflush (stdout); trackStatus = trackEvent (target_pos, &track, &ctkStat, &shellhit, Clstr, &nClusters); // printf("trackStatus = %i\n", trackStatus); // printf ("ev# %i: ", ctkStat.nEvents); // fflush (stdout); returnCodes[trackStatus]++; /* log every so often where we are */ if (ncalls % 100000 == 0) { printf ("trackMain: ncalls= %i\n", ncalls); fflush (stdout); }; /* always write out if even if the tarcking failed */ /* write this event out. */ /* Both original event data and tracked */ /* information is written out; BUT the Original */ /* data has been modified to have global */ /* rather than crystal coordinates! */ writeTrack (trackStatus, &track, Clstr, &nClusters, &ctkStat); if (Pars.nprint > 0) { printf ("trackEvent failed at ev# %i: ", ctkStat.nEvents); switch (trackStatus) { case MODULENOOUTOFRANGE: printf ("returned: Detector number out of range\n"); break; case CRYSTALNOOUTOFRANGE: printf ("returned: crystal number out of range\n"); break; case DEBUGSTOP: printf ("returned: debug termination\n"); break; case TOOMANYHITS: printf ("returned: too many hits\n"); break; case BADPAD: printf ("returned: bad decomp PAD value\n"); break; default: printf ("treturned: unknown error = %i\n", trackStatus); break; }; fflush (stdout); }; }; }; printf ("\n"); printf ("read %i hits\n", ncalls); printf ("\n"); /* tracking statistics and closeout */ ctkStats (×Then, &ctkStat); fflush (stdout); fflush (stdout); system ("ulimit -a| grep stack"); /* done */ printf ("done...\n"); for (i = 0; i < 1000; i++) if (returnCodes[i] > 0) printf ("returnCodes %3i: %i\n", i, returnCodes[i]); return (0); }