source: fact/tools/rootmacros/openFits.c@ 13501

Last change on this file since 13501 was 12512, checked in by neise, 13 years ago
debugged typo
  • Property svn:executable set to *
File size: 3.8 KB
Line 
1// Opens FACT Fits Raw Data -- for more Info refer to header file
2size_t openDataFits(
3 const char *datafilename, // path to fits file containing FACT raw data
4 fits * * datafile, // ptr to pointer, where to return the fits object
5 vector<int16_t> &Data, // vector, which will be filled with raw data
6 vector<int16_t> &StartCells, // vector, which will be filled with DRS start positions
7 unsigned int &EventID, // index of the current event
8 UInt_t &RegionOfInterest, // Width of the Region, read out of the DRS
9 UInt_t &NumberOfPixels, // Total number of pixel, read out of the camera
10 size_t &PXLxROI, // Size of column "Data" = #Pixel x ROI
11 // this can be used, to x-check RegionOfInterest and NumberOfPixels
12 int VerbosityLevel //
13) {
14 size_t NumberOfEvents;
15 *datafile = new fits(datafilename);
16 if (!(*(*datafile))) {
17 if (VerbosityLevel > 0)
18 cout << "Couldn't properly open the datafile: " << datafilename << endl;
19 return 0;
20 }
21
22 NumberOfEvents = (*datafile)->GetNumRows();
23 if (NumberOfEvents < 1){
24 if (VerbosityLevel > 0){
25 cout << "Warning in FOpenDataFile of file: " << datafilename << endl;
26 cout << "the file contains no events." << endl;
27 }
28 }
29
30 RegionOfInterest = (*datafile)->GetUInt("NROI");
31 NumberOfPixels = (*datafile)->GetUInt("NPIX");
32
33 // I am not really sure, why anybody should be interested in this number
34 // It can be used for the sanity check, which follows only ... I guess.
35 PXLxROI = (*datafile)->GetN("Data");
36
37 if ( RegionOfInterest * NumberOfPixels != PXLxROI) // something in the file went wrong
38 {
39 if (VerbosityLevel > 0){
40 cout << "Warning in FOpenDataFile of file: " << datafilename << endl;
41 cout << "RegionOfInterest * NumberOfPixels != PXLxROI" << endl;
42 cout << "--> " << RegionOfInterest;
43 cout << " * " << NumberOfPixels;
44 cout << " = " << RegionOfInterest * NumberOfPixels;
45 cout << ", but PXLxROI =" << PXLxROI << endl;
46 }
47 return 0;
48 }
49
50 //Set the sizes of the data vectors
51 Data.resize(PXLxROI, 0);
52 StartCells.resize(NumberOfPixels, 0);
53
54 //Link the data to variables
55 (*datafile)->SetRefAddress("EventNum", EventID);
56 (*datafile)->SetVecAddress("Data", Data);
57 (*datafile)->SetVecAddress("StartCellData", StartCells);
58
59 return NumberOfEvents;
60}
61
62size_t openCalibFits(
63 const char *FileName, // path to fits file
64 vector<float> &Offset,
65 vector<float> &Gain,
66 vector<float> &TriggerOffset,
67 size_t &TriggerOffsetROI,
68 int VerbosityLevel
69)
70{
71 size_t NumberOfEvents = 0;
72
73 // sizes of the data vectors
74 size_t Offset_size;
75 size_t Gain_size;
76 size_t TriggerOffset_size;
77
78 fits * datafile = new fits( FileName );
79 if (!(*datafile)) {
80 if (VerbosityLevel > 0)
81 cout << "Couldn't properly open the file: " << FileName << endl;
82 return 0;
83 }
84
85 NumberOfEvents = datafile->GetNumRows();
86 if (NumberOfEvents < 1){
87 if (VerbosityLevel > 0){
88 cout << "Warning during open of file: " << FileName << endl;
89 cout << "the file contains no events." << endl;
90 return 0;
91 }
92 }
93
94 // only if the user really wants, this stuff is output
95 if (VerbosityLevel > 1){
96 cout << "----------------- DRS Calib Header -----------------" << endl;
97 datafile->PrintKeys();
98 cout << "---------------- DRS Calib Columns -----------------" << endl;
99 datafile->PrintColumns();
100 }
101
102 Offset_size = datafile->GetN("BaselineMean");
103 Gain_size = datafile->GetN("GainMean");
104 TriggerOffset_size = datafile->GetN("TriggerOffsetMean");
105
106 Offset.resize(Offset_size, 0);
107 Gain.resize(Gain_size, 0);
108 TriggerOffset.resize(TriggerOffset_size, 0);
109
110 TriggerOffsetROI = (size_t)datafile->GetUInt("NROI");
111 datafile->SetVecAddress("BaselineMean", Offset);
112 datafile->SetVecAddress("GainMean", Gain);
113 datafile->SetVecAddress("TriggerOffsetMean", TriggerOffset);
114 datafile->GetRow(0); //Read the calibration data
115
116 return NumberOfEvents;
117}
Note: See TracBrowser for help on using the repository browser.