/* Simple test program for mc2coda Library */ #include #include #include #include #include #include "mc2coda.h" main (int argc, char **argv) { uint32_t int1 = 0xda002244; uint64_t int2 = 0xfa113355aabbccddLLU; uint32_t int3, int4, int5[2]; int ii, status, ncrates, nhits, nwords; unsigned short evtype; uint64_t eventno, trigtime = 0x11002200; CODA_EXP_INFO *expID = NULL; CODA_EVENT_INFO *eventID = NULL; CODA_HIT_INFO hit[10]; uint32_t data[20]; /* Sample Crate information */ int nmod1 = 2; int modules1[] = {VMECPU, 0, FADC250, FADC250,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,TID}; int detid1[] = {0, 0, 1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0}; int nmod2 = 1; int modules2[] = {VMECPU, 0, 0, F1TDC32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,TID}; int detid2[] = {0, 0, 0, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0}; /* Sample Hit information */ hit[0].hit_id = 1; hit[0].det_id = 1; hit[0].crate_id = 1; hit[0].slot_id = 3; hit[0].chan_id = 5; hit[0].module_id = FADC250; hit[0].module_mode = FADC250_MODE_IP; hit[0].nwords = 2; /* hit[0].hdata = (uint32_t *) malloc((hit[0].nwords)*4); hit[0].hdata[0] = 500; hit[0].hdata[1] = trigtime - 200; */ hit[0].hdata = &data[0]; data[0] = 500; data[1] = trigtime - 200; hit[1].hit_id = 2; hit[1].det_id = 1; hit[1].crate_id = 1; hit[1].slot_id = 4; hit[1].chan_id = 8; hit[1].module_id = FADC250; hit[1].module_mode = FADC250_MODE_IP; hit[1].nwords = 2; /* hit[1].hdata = (uint32_t *) malloc((hit[1].nwords)*4); hit[1].hdata[0] = 800; hit[1].hdata[1] = trigtime - 250; */ hit[1].hdata = &data[2]; data[2] = 800; data[3] = trigtime - 250; hit[2].hit_id = 3; hit[2].det_id = 1; hit[2].crate_id = 1; hit[2].slot_id = 4; hit[2].chan_id = 13; hit[2].module_id = FADC250; hit[2].module_mode = FADC250_MODE_IP; hit[2].nwords = 2; hit[2].hdata = (uint32_t *) malloc((hit[2].nwords)*4); hit[2].hdata[0] = 1200; hit[2].hdata[1] = trigtime - 220; /* F1TDC Hit */ hit[3].hit_id = 4; hit[3].det_id = 1; hit[3].crate_id = 2; hit[3].slot_id = 4; hit[3].chan_id = 17; hit[3].module_id = F1TDC32; hit[3].module_mode = 0; hit[3].nwords = 1; hit[3].hdata = (uint32_t *) malloc((hit[2].nwords)*4); hit[3].hdata[0] = trigtime - 290; nhits = 4; if(argc < 5) { printf("Incorrect number of arguments:\n"); printf(" usage: mc2coda \n"); exit(-1); } ncrates = atoi(argv[2]); if (ncrates < 2) ncrates = 2; eventno = atoll(argv[3]); evtype = atoi(argv[4]); /*printf("%d %llu %d\n",ncrates, eventno, nhits); */ /* Setup experiment and crates. For testing put the same modules in each crate*/ expID = mc2codaInitExp(ncrates,argv[1]); if(expID != NULL) { printf("Set Crates\n"); for (ii=1; ii<=ncrates; ii++) { if(ii == 2) status = mc2codaSetCrate(expID, ii, nmod2, modules2, detid2); else status = mc2codaSetCrate(expID, ii, nmod1, modules1, detid1); if(status<=0) { printf("ERROR mc2codaSetCrate\n"); exit(-1); } } printf("mc2coda: Initialized experiment %s using %d crates\n",argv[1],ncrates); }else{ printf("ERROR mc2codaInitExp()\n"); exit(-1); } /* Open a new event */ eventID = mc2codaOpenEvent(expID, eventno, trigtime, evtype, MAX_EVENT_SIZE); if(eventID == NULL) { printf("ERROR mc2codaOpenEvent\n"); exit(-1); } /* Add hits */ status = mc2codaWrite(eventID, nhits, (struct coda_hit_info *)&hit[0]); if(status != nhits) { printf("ERROR: mc2codaWrite\n"); exit(-1); }else{ printf("Wrote %d hit(s) to event\n",nhits); } /* Reset Event and then Add Hits again */ status = mc2codaResetEvent(eventID, eventno, trigtime, evtype); if(status !=0) { printf("ERROR: mc2codaResetEvent\n"); exit(-1); } status = mc2codaWrite(eventID, nhits, (struct coda_hit_info *)&hit[0]); if(status != nhits) { printf("ERROR: mc2codaWrite\n"); exit(-1); }else{ printf("Wrote %d hit(s) to event (again)\n",nhits); } /* Print Stats */ mc2codaStats(eventID,0); /* Close event to Hits */ nwords = mc2codaCloseEvent(eventID); if(nwords <=0) { printf("ERROR mc2codaCloseEvent\n"); exit(-1); } else { /* Print Event */ printf("Total Words in Event = %d\n",nwords); printf("DATA:\n"); for(ii=0;iievbuf[ii]); } } /* Free Event */ mc2codaFreeEvent(eventID); /* Free Experiment */ mc2codaFree(expID); exit(0); }