source: tools/inspectrawfile/inspectrawfile.cpp@ 8550

Last change on this file since 8550 was 62, checked in by ogrimm, 16 years ago
Updated for event data format
File size: 1.8 KB
Line 
1/********************************************************************\
2
3 inspectrawfile.cpp
4
5 Reads DAQ raw data file and prints run and event headers and data.
6 Main purpose is to demonstrate the procedure to read raw files.
7
8 Oliver Grimm
9
10\********************************************************************/
11
12#include <stdlib.h>
13#include <limits.h>
14#include "RawDataCTX.h"
15
16int main(int argc, char *argv[]) {
17
18 int NumEvents, NumBins, EventCount=0;
19
20 // Check command line syntax
21 if (argc<2 || argc>4) {
22 printf("Usage: %s <rawfile> [Number of events to display] [Number of data bins to display]\n", argv[0]);
23 exit(EXIT_SUCCESS);
24 }
25
26 NumEvents = argc>2 ? atoi(argv[2]) : INT_MAX;
27 RawDataCTX *RD = new RawDataCTX();
28
29 // Open data file, read and print run header, and loop through all events
30 if (RD->OpenDataFile(argv[1], stdout) != CTX_OK) {
31 printf("Error accessing file: %s\n", argv[1]);
32 }
33 else {
34 NumBins = argc==4 && atoi(argv[3])<RD->RHeader->Samples ? atoi(argv[3]) : RD->RHeader->Samples;
35
36 while (EventCount++ < NumEvents && RD->ReadEvent(0,stdout) == CTX_OK) {
37 printf("Trigger cells: ");
38 for (int i=0; i<RD->RHeader->NBoards*RD->RHeader->NChips; i++) {
39 printf("%d ", *((int *) RD->Data + i));
40 }
41 for(int i=0; i<RD->RHeader->NBoards; i++) {
42 for(int j=0; j<RD->RHeader->NChips*RD->RHeader->NChannels; j++) {
43 if (NumBins>0) printf("\nBoard %d, channel %d\t", i,j);
44 for(int k=0; k<NumBins ; k++)
45 printf("%.1f ",*((short *) (RD->Data + RD->RHeader->NBoards*RD->RHeader->NChips*sizeof(int)) + i*RD->RHeader->NChips*RD->RHeader->NChannels*RD->RHeader->Samples +
46 j*RD->RHeader->Samples+k)*RD->BStruct[i].ScaleFactor);
47 }
48 }
49 printf("\n\n");
50 }
51 }
52
53 delete RD;
54 return EXIT_SUCCESS;
55}
56
Note: See TracBrowser for help on using the repository browser.