// program used to read raw data files and produce hardware ntuple files // July 14, 2008 Ed May // read t979 rawdata file run_0NN.txt from inRaw // write to outfile file run_0NN.tup via outTup // inRaw and outTup assigned a logical file name/ptr via processing script(s) #include #include #define DLINES 1000000 #define DEBUG1 1 #define DEBUG2 1 unsigned getbits( unsigned x, unsigned p, unsigned n) { /* get n bits from position p */ return (( x >> (p+1-n)) & ~(~0 << n)); } int main() { FILE *data_file,*output_file; char infile[20] = ("inRaw"); char outfile[20] = ("outTup"); int data1,data2,data3,adcdata[16]; int i,j; int TAC1data,TAC2data,TAC3data; int foundTAC1,foundTAC2,foundTAC3; int ioret; int lineCount=0; int countTAC1=0, countTAC2=0, countTAC3=0; int countMultiTAC1=0, countMultiTAC2=0, countMultiTAC3=0; int count4300Header=0; int blockCount=0; int iMax=0, iscaler=0, scalerTotal[4]={0,0,0,0}, scalerValue[4]; int runType=0, runNumb=0, lrClock=0, hrClock=0, crateID=0, blockSize=0; unsigned int usInt=0; unsigned int chanCount=0; unsigned int chanID=0; unsigned int adcdataIn[16]; int firstTime=1; // is true int tupleNum=0; int iblk=0; // index for reading raw data blocks int channelPop[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; int missingAdcChFlag = 0; // counts number of missing adc channels in each event int multiTACflag = 0; data_file = fopen(infile,"r"); // infile is char array containing inRaw if ( data_file == NULL ) { printf("Failed to open an input file!\n"); return 1;} output_file = fopen(outfile,"w"); // outfile is char array containing outTup if ( output_file == NULL ) { printf("Failed to open an output file!\n"); return 1;} /* reset event */ adcdata[0]=0; adcdata[1]=0; adcdata[2]=0; adcdata[3]=0; TAC1data=0; TAC2data=0; TAC3data=0; foundTAC1=0; foundTAC2=0; foundTAC3=0; runNumb=0; runType=0; lrClock=0; hrClock=0; blockSize=0; //fprintf(output_file, "adc1 adc2 tac1 tac2 tac3\n"); //fprintf(output_file, "ramp1\tramp2\tadc1\tadc2\ttac1\ttac2\ttac3\n"); fprintf(output_file,"runType\trunNum\tblkCnt\ttuplNum\tscaler1\tscaler2\tscaler3\tramp1\tramp2\tadc1\tadc2\ttac1\ttac2\ttac3\thrClock\tlrClock\n"); // Read raw data blocks and do integrety checks... for (;;) { ioret = fscanf(data_file,"%d %x %d",&data1,&data2,&data3); lineCount++; if ( ioret == EOF ) {printf("EOF found, break from for loop.\n"); break;} if ( data1 != -7 ) { printf("Failed to find Scaler header!\n"); printf("lineCount=%d Data= %d %x %d\n", lineCount, data1, data2, data3); printf("Exit!\n"); return 2; } else { blockCount++; iMax=data3; // how many scaler elements for ( iscaler=0; iscaler