source: trunk/FACT++/src/fitsselect.cc@ 18795

Last change on this file since 18795 was 18121, checked in by tbretz, 10 years ago
set::emplace is not known for the LP compiler.
File size: 3.5 KB
Line 
1#include "Configuration.h"
2
3#include "externals/factfits.h"
4#include "externals/factofits.h"
5
6using namespace std;
7
8void PrintUsage()
9{
10 cout <<
11 "fitsselect is....\n"
12 "\n"
13 "Usage: fitsselect rawfile eventlist outfile\n"
14 "\n"
15 ;
16 cout << endl;
17}
18
19void SetupConfiguration(Configuration& conf)
20{
21 po::options_description configs("Fitsdump options");
22 configs.add_options()
23 ("infile", var<string>()->required(), "")
24 ("outfile", var<string>()->required(), "")
25 ("eventlist", var<string>()->required(), "")
26 ;
27
28 po::positional_options_description p;
29 p.add("infile", 1); // The first positional options
30 p.add("eventlist", 1); // The second positional options
31 p.add("outfile", -1); // All others
32
33 conf.AddOptions(configs);
34 conf.SetArgumentPositions(p);
35}
36
37int main(int argc, const char** argv)
38{
39 Configuration conf(argv[0]);
40 conf.SetPrintUsage(PrintUsage);
41 SetupConfiguration(conf);
42
43 if (!conf.DoParse(argc, argv))//, PrintHelp))
44 return -1;
45
46 const string infile = conf.Get<string>("infile");
47
48 const string outfile = conf.Get<string>("outfile");
49 const string eventlist = conf.Get<string>("eventlist");
50
51 set<uint32_t> list;
52 ifstream fin(eventlist.c_str());
53 while (1)
54 {
55 uint32_t evt;
56 fin >> evt;
57 if (!fin)
58 break;
59
60 list.insert(evt);
61 }
62
63 factfits inf(infile.c_str(), "Events", false);
64 factofits outf(outfile.c_str());
65
66 outf.SetDrsCalibration(inf.GetOffsetCalibration());
67
68 uint32_t rowWidth = inf.HasKey("ZNAXIS1") ? inf.GetUInt("ZNAXIS1") : inf.GetUInt("ZNAXIS2");
69
70 vector<char> buffer(rowWidth);
71
72 outf.CopyKeys(inf);
73
74 vector<pair<void*, char*>> pointers;
75
76 unsigned int count = 0;
77
78 uint32_t *evtNum = 0;
79
80 const fits::Table::Columns& columns = inf.GetColumns();
81 for (fits::Table::Columns::const_iterator it=columns.begin(); it!=columns.end(); it++)
82 {
83 const fits::Table::Column &col = it->second;
84
85 if (it->first=="Data" || it->first=="TimeMarker")
86 {
87 vector<uint16_t> processing(2);
88 processing[0] = FITS::kFactSmoothing;
89 processing[1] = FITS::kFactHuffman16;
90
91 const FITS::Compression comp(processing, FITS::kOrderByRow);
92
93 outf.AddColumn(comp, col.num, col.type, it->first, col.unit, "");
94 }
95 else
96 outf.AddColumn(col.num, col.type, it->first, col.unit, "");
97
98 void *ptr = inf.SetPtrAddress(it->first);
99 pointers.emplace_back(ptr, buffer.data()+count);
100 count += col.num*col.size;
101
102 if (it->first=="EventNum")
103 evtNum = reinterpret_cast<uint32_t*>(ptr);
104 }
105
106 if (evtNum==0)
107 throw runtime_error("Colum EventNum not found.");
108
109 if (count!=rowWidth)
110 throw runtime_error("Size mismatch.");
111
112 inf.PrintColumns();
113
114 outf.WriteTableHeader(inf.GetStr("EXTNAME").c_str());
115
116 while (inf.GetNextRow())
117 {
118 if (list.find(*evtNum)==list.end())
119 continue;
120
121 int i=0;
122 for (fits::Table::Columns::const_iterator it=columns.begin(); it!= columns.end(); it++, i++)
123 memcpy(pointers[i].second, pointers[i].first, it->second.num*it->second.size);
124
125 outf.WriteRow(buffer.data(), rowWidth);
126 if (!outf)
127 throw runtime_error("Write stream failure.");
128 }
129
130 if (!inf.good())
131 throw runtime_error("Read stream failure.");
132
133 if (!outf.close())
134 throw runtime_error("Write stream failure.");
135
136 return 0;
137}
Note: See TracBrowser for help on using the repository browser.