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

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