FACT++  1.0
int main ( int  argc,
const char **  argv 
)

Definition at line 37 of file fitsselect.cc.

References buffer, count, Configuration::DoParse(), first, Configuration::Get(), i, FITS::kFactHuffman16, FITS::kFactSmoothing, FITS::kOrderByRow, fits::Table::Column::num, outfile, PrintUsage(), second, factofits::SetDrsCalibration(), Configuration::SetPrintUsage(), SetupConfiguration(), fits::Table::Column::size, fits::Table::Column::type, and fits::Table::Column::unit.

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 }
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
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
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
void SetupConfiguration(Configuration &conf)
Definition: fitsselect.cc:19
std::string unit
Definition: fits.h:108

+ Here is the call graph for this function: