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

Last change on this file since 13501 was 12368, checked in by neise, 13 years ago
added another Function to open a Datafile ... see example use in fpeak_cfd.C
File size: 3.4 KB
Line 
1
2
3
4//#include "FOpenDataFile.h"
5
6int FOpenDataFile(
7 fits &datafile,
8 vector<int16_t> &data,
9 vector<int16_t> &data_offset,
10 unsigned int &data_num,
11 size_t &data_n,
12 UInt_t &data_roi,
13 UInt_t &data_px
14){
15//-------------------------------------------
16//Print the header
17//-------------------------------------------
18/* cout << "-------------------- Data Header -------------------" << endl;
19 datafile.PrintKeys();
20 cout << "------------------- Data Columns -------------------" << endl;
21 datafile.PrintColumns();
22 */
23//-------------------------------------------
24//Get the size of the data column
25//-------------------------------------------
26 data_roi = datafile.GetUInt("NROI"); // Value from header
27 data_px = datafile.GetUInt("NPIX");
28 data_n = datafile.GetN("Data"); //Size of column "Data" = #Pixel x ROI
29
30//-------------------------------------------
31//Set the sizes of the data vectors
32//-------------------------------------------
33 data.resize(data_n,0);
34 data_offset.resize(data_px,0);
35
36//-------------------------------------------
37//Link the data to variables
38//-------------------------------------------
39 datafile.SetRefAddress("EventNum", data_num);
40 datafile.SetVecAddress("Data", data);
41 datafile.SetVecAddress("StartCellData", data_offset);
42 datafile.GetRow(0);
43
44 cout << "Opening data file successful..." << endl;
45 return 0;
46}
47
48size_t OpenDataFile(
49 const char *datafilename, // path to fits file containing FACT raw data
50 fits * * datafile, // ptr to pointer, where to return the fits object
51 vector<int16_t> &Data, // vector, which will be filled with raw data
52 vector<int16_t> &StartCells, // vector, which will be filled with DRS start positions
53 unsigned int &EventID, // index of the current event
54 UInt_t &RegionOfInterest, // Width of the Region, read out of the DRS
55 UInt_t &NumberOfPixels, // Total number of pixel, read out of the camera
56 size_t &PXLxROI, // Size of column "Data" = #Pixel x ROI
57 // this can be used, to x-check RegionOfInterest and NumberOfPixels
58 int VerbosityLevel //
59) {
60 size_t NumberOfEvents;
61 *datafile = new fits(datafilename);
62 if (!(*(*datafile))) {
63 if (VerbosityLevel > 0)
64 cout << "Couldn't properly open the datafile: " << datafilename << endl;
65 return 0;
66 }
67
68 NumberOfEvents = (*datafile)->GetNumRows();
69 if (NumberOfEvents < 1){
70 if (VerbosityLevel > 0){
71 cout << "Warning in FOpenDataFile of file: " << datafilename << endl;
72 cout << "the file contains no events." << endl;
73 }
74 }
75
76 RegionOfInterest = (*datafile)->GetUInt("NROI");
77 NumberOfPixels = (*datafile)->GetUInt("NPIX");
78 PXLxROI = (*datafile)->GetN("Data");
79
80 if ( RegionOfInterest * NumberOfPixels != PXLxROI) // something in the file went wrong
81 {
82 if (VerbosityLevel > 0){
83 cout << "Warning in FOpenDataFile of file: " << datafilename << endl;
84 cout << "RegionOfInterest * NumberOfPixels != PXLxROI" << endl;
85 cout << "--> " << RegionOfInterest;
86 cout << " * " << NumberOfPixels;
87 cout << " = " << RegionOfInterest * NumberOfPixels;
88 cout << ", but PXLxROI =" << PXLxROI << endl;
89 }
90 return 0;
91 }
92
93 //Set the sizes of the data vectors
94 Data.resize(PXLxROI, 0);
95 StartCells.resize(NumberOfPixels, 0);
96
97 //Link the data to variables
98 (*datafile)->SetRefAddress("EventNum", EventID);
99 (*datafile)->SetVecAddress("Data", Data);
100 (*datafile)->SetVecAddress("StartCellData", StartCells);
101
102 return NumberOfEvents;
103}
104
Note: See TracBrowser for help on using the repository browser.