FACT++  1.0
fitsselect.cc
Go to the documentation of this file.
1 #include "Configuration.h"
2 
3 #include "externals/factfits.h"
4 #include "externals/factofits.h"
5 
6 using namespace std;
7 
8 void 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 
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 
37 int main(int argc, const char** argv)
38 {
39  Configuration conf(argv[0]);
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 }
std::map< std::string, Column > Columns
Definition: fits.h:113
void PrintUsage()
Definition: fitsselect.cc:8
int i
Definition: db_dim_client.c:21
int64_t second
offset of this column in the tile, from the start of the heap area
Definition: zofits.h:27
void SetPrintUsage(const std::function< void(void)> &func)
T Get(const std::string &var)
STL namespace.
void SetArgumentPositions(const po::positional_options_description &desc)
int64_t first
Size of this column in the tile.
Definition: zofits.h:26
char outfile[]
Definition: rshServer.cxx:13
void SetDrsCalibration(const std::vector< float > &calib)
assign a given drs offset calibration
Definition: factofits.h:48
void AddOptions(const po::options_description &opt, bool visible=true)
Definition: Configuration.h:92
Commandline parsing, resource file parsing and database access.
Definition: Configuration.h:9
int buffer[BUFFSIZE]
Definition: db_dim_client.c:14
int count
Definition: db_dim_server.c:18
int main(int argc, const char **argv)
Definition: fitsselect.cc:37
void SetupConfiguration(Configuration &conf)
Definition: fitsselect.cc:19
bool DoParse(int argc, const char **argv, const std::function< void()> &func=std::function< void()>())
std::string unit
Definition: fits.h:108