Database.h
1//-*-C++-*-
2/***************************************************************************
3 *
4 * Copyright (C) 2004 by Willem van Straten
5 * Licensed under the Academic Free License version 2.1
6 *
7 ***************************************************************************/
8
9// psrchive/More/Polarimetry/Pulsar/Database.h
10
11#ifndef __Pulsar_Database_h
12#define __Pulsar_Database_h
13
14#include "Pulsar/Calibrator.h"
15#include "Pulsar/Config.h"
16
17#include "MEAL/Complex2.h"
18
19#include "sky_coord.h"
20#include "MJD.h"
21#include "Types.h"
22
23#include <iostream>
24
25namespace Pulsar {
26
27 // forward declarations
28 class FluxCalibrator;
29 class PolnCalibrator;
30 class HybridCalibrator;
32 class Archive;
33
35 class Database : public Reference::Able {
36
37 public:
38
40 static bool cache_last_cal;
41
43 static bool match_verbose;
44
47
50
53
56
59
61 static const Pulsar::Archive* any;
62
64
74
76 Database ();
77
79 Database (const std::string& path, const std::string& metafile);
80
82 Database (const std::string& path, const std::vector<std::string>& exts);
83
85 Database (const std::string& filename);
86
88 ~Database ();
89
91 void merge (const Database*);
92
94 void construct (const std::vector<std::string>& filenames);
95
97 void unload (const std::string& dbase_filename);
98
100 void load (const std::string& dbase_filename);
101
103 void add (const Pulsar::Archive* archive);
104
107 const Calibrator::Type* m);
108
110 FluxCalibrator* generateFluxCalibrator (const Archive*, bool allow_raw=false);
111
114
116 void set_feed (MEAL::Complex2* xform) { feed = xform; }
117
119 std::string get_path () const;
120
122 unsigned size () const { return entries.size(); }
123
125 class Entry : public Reference::Able
126 {
127
128 public:
129
131
132 Signal::Source obsType; // FluxCal, PolnCal, Pulsar, etc.
133 sky_coord position; // Where the telescope was pointing
134 double bandwidth; // Bandwidth of observation
135 double frequency; // Centre frequency of observation
136
137 std::string instrument; // name of backend
138 std::string receiver; // name of receiver
139 std::string filename; // full path of file
140
142 Entry (const Archive* arch);
143
145 ~Entry();
146
147 // factory constructs new Entry from ascii string
148 static Entry* load (const std::string& str);
149
150 // factory constructs new Entry from Archive
151 static Entry* create (const Archive*);
152
153 // unload ascii string
154 virtual void unload (std::string& str);
155
156 // return full path to filename
157 std::string get_filename () const;
158
159 virtual bool less_than (const Entry*) const;
160 virtual bool equals (const Entry*) const;
161
162 virtual MJD get_effective_time () const = 0;
163 virtual std::string get_time_str () const = 0;
164 virtual std::string get_nchan_str () const = 0;
165
166 protected:
167
169 void init ();
170 };
171
172 class StaticEntry : public Entry
173 {
174 public:
175 MJD time; // Mid time of observation
176 unsigned nchan; // Number of channels across bandwidth
177
179 StaticEntry (const Archive* arch = 0);
180
181 bool equals (const Entry*) const;
182
183 MJD get_effective_time () const { return time; }
184 std::string get_time_str () const;
185 std::string get_nchan_str () const;
186
187 protected:
188
190 void init ();
191 };
192
193 class InterpolatorEntry : public Entry
194 {
195 public:
196 MJD start_time; // earliest time spanned by interpolator
197 MJD end_time; // latest time spanned by interpolator
198
200 InterpolatorEntry (const Archive* arch = 0);
201
202 bool equals (const Entry*) const;
203
204 MJD get_effective_time () const { return start_time; }
205 std::string get_time_str () const;
206 std::string get_nchan_str () const;
207 };
208
210 class Criteria : public Reference::Able {
211
212 public:
213
216
219 Sequence get_sequence () const { return sequence; }
220
221 double minutes_apart;
222 double deg_apart;
223
224 bool check_receiver;
225 bool check_instrument;
226 bool check_frequency;
227 bool check_bandwidth;
228 bool check_obs_type;
229 bool check_time;
230 bool check_coordinates;
231 bool check_frequency_array;
232
234 Criteria ();
235
237 void no_data ();
238
240 bool match (const Entry* entry) const;
241
247
249 mutable std::string match_report;
250
252 mutable unsigned match_count;
253
255 mutable double diff_minutes;
256
258 mutable double diff_degrees;
259
261
263 const Entry* best (const Entry* a, const Entry* b) const;
264
266 static Criteria closest (const Criteria& a, const Criteria& b);
267
268 protected:
269
272
273 template<typename T, typename U, typename Predicate>
274 void compare (const std::string& name,
275 const T& want, const U& have,
276 Predicate equal ) const
277 {
278 match_report += "\t" + name
279 + " want=" + tostring(want) + " have=" + tostring(have) + " ... ";
280
281 if ( equal (want, have) )
282 {
283 match_report += "match \n";
284 match_count ++;
285 }
286 else
287 {
288 match_report += "no match \n";
289 throw false;
290 }
291 }
292
293 template<typename T>
294 void compare (const std::string& name,
295 const T& want, const T& have) const
296 {
297 compare (name, want, have, std::equal_to<T>());
298 }
299
300 bool compare_times (const MJD& want,
301 const MJD& have) const;
302
303 bool bracketed_time (const MJD& want,
304 const std::pair<MJD,MJD>& have) const;
305
306 bool compare_coordinates (const sky_coord& want,
307 const sky_coord& have) const;
308 };
309
310
312 static Criteria get_default_criteria ();
313
315 static void set_default_criteria (const Criteria&);
316
318 const Entry* best_match (const Criteria&) const;
319
321 void all_matching (const Criteria&,
322 std::vector<const Entry*>& matches) const;
323
325 Criteria criteria (const Pulsar::Archive* arch,
326 Signal::Source obsType) const;
327
329 Criteria criteria (const Pulsar::Archive* archive,
330 const Calibrator::Type* calType) const;
331
333 std::string get_filename (const Entry*) const;
334
336 void add (Entry* entry);
337
339 void shorten_filename (Entry* entry);
340
342 void expand_filename (Entry* entry);
343
345 std::string get_closest_match_report () const;
346
347 protected:
348
349 // list of entries in the database
350 std::vector< Reference::To<Entry> > entries;
351 std::string path;
352
353 template<class Cal> class Cache
354 {
355 public:
357 Reference::To<Cal> calibrator;
358
359 void cache (const Entry* _entry, Cal* cal)
360 { entry = _entry; calibrator = cal; }
361 };
362
363 Cache<PolnCalibrator> lastPolnCal;
364 Cache<HybridCalibrator> lastHybridCal;
365 Cache<FluxCalibrator> lastFluxCal;
366
368 FluxCalibrator* rawFluxCalibrator (const Archive* a);
369
372
375 };
376
377 std::ostream& operator << (std::ostream& os, Database::Sequence);
378
379 std::istream& operator >> (std::istream& is, Database::Sequence&);
380
381 bool less_than (const Pulsar::Database::Entry* A,
382 const Pulsar::Database::Entry* B);
383}
384
385#endif
The primary interface to pulsar observational data.
Definition Archive.h:46
The primary interface to pulsar observational data.
Definition Archive.h:46
Definition CalibratorType.h:26
Describes Database matching criteria.
Definition Database.h:210
void set_sequence(Sequence s)
The sequence of matching calibrator and pulsar observations.
Definition Database.h:218
bool match(const Entry *entry) const
Return true if entry matches within the criteria.
Definition Database.C:662
void compare(const std::string &name, const T &want, const U &have, Predicate equal) const
log of the attributes compared and the result of the comparison
Definition Database.h:274
Criteria()
Default constructor.
Definition Database.C:562
const Entry * best(const Entry *a, const Entry *b) const
Return the best of two entries.
Definition Database.C:1116
unsigned match_count
count of the number of match conditions that tested positive
Definition Database.h:252
Sequence sequence
The sequence of matching calibrator and pulsar observations.
Definition Database.h:271
double diff_minutes
time between calibrator and requested epoch (in minutes)
Definition Database.h:255
Reference::To< StaticEntry > entry
The parameters to match.
Definition Database.h:215
double diff_degrees
distance between calibrator and requested position (in degrees)
Definition Database.h:258
bool bracketed_time(const MJD &want, const std::pair< MJD, MJD > &have) const
log of the attributes compared and the result of the comparison
Definition Database.C:633
void no_data()
Called when no observation parameters are to be matched.
Definition Database.C:582
std::string match_report
log of the attributes compared and the result of the comparison
Definition Database.h:249
void compare(const std::string &name, const T &want, const T &have) const
log of the attributes compared and the result of the comparison
Definition Database.h:294
bool compare_times(const MJD &want, const MJD &have) const
log of the attributes compared and the result of the comparison
Definition Database.C:607
static Criteria closest(const Criteria &a, const Criteria &b)
Return the criteria that came closest to matching.
Definition Database.C:1145
bool compare_coordinates(const sky_coord &want, const sky_coord &have) const
log of the attributes compared and the result of the comparison
Definition Database.C:643
Pulsar Database Entry.
Definition Database.h:126
Entry(const Archive *arch)
Construct from a Pulsar::Archive.
Definition Database.C:148
~Entry()
Destructor.
Definition Database.C:247
void init()
Clean slate.
Definition Database.C:129
std::string get_filename() const
Returns the full pathname of the Entry filename.
Definition Database.C:409
Pulsar Observation Database.
Definition Database.h:35
Criteria closest_match
The criteria that last came closest to matching.
Definition Database.h:374
unsigned size() const
Returns the number of entries in the database.
Definition Database.h:122
std::string get_closest_match_report() const
Get the closest match report.
Definition Database.C:1108
void shorten_filename(Entry *entry)
Remove the preceding path from the Entry filename, if applicable.
Definition Database.C:1004
static void set_default_criteria(const Criteria &)
Set the default matching criteria for all observations.
Definition Database.C:1179
void set_feed(MEAL::Complex2 *xform)
Set the feed transformation to be incorporated into PolnCalibrator.
Definition Database.h:116
void add(const Pulsar::Archive *archive)
Add the given Archive to the database.
Definition Database.C:979
Database()
Null constructor.
Definition Database.C:759
static Option< double > max_bandwidth_difference
Maximum difference between calibrator and pulsar bandwidths.
Definition Database.h:58
PolnCalibrator * generatePolnCalibrator(const Archive *, const Calibrator::Type *m)
Return a pointer to a new PolnCalibrator for the given archive.
Definition Database.C:1433
Reference::To< MEAL::Complex2 > feed
If set, this model of the feed is incorporated into all solutions.
Definition Database.h:371
Sequence
Calibrator matching sequence.
Definition Database.h:66
@ CalibratorAfter
Use only calibrators recorded after the observation.
Definition Database.h:72
@ Any
Use the nearest calibrator (default)
Definition Database.h:68
@ CalibratorBefore
Use only calibrators recorded before the observation.
Definition Database.h:70
static Criteria get_default_criteria()
Get the default matching criteria for all observations.
Definition Database.C:1171
static Option< double > max_angular_separation
Maximum angular separation between calibrator and pulsar.
Definition Database.h:52
static const Pulsar::Archive * any
Pass this to the criteria methods to retrieve any or all matches.
Definition Database.h:61
void load(const std::string &dbase_filename)
Read a text file summary and construct a database.
Definition Database.C:884
void unload(const std::string &dbase_filename)
Write a text file representing the database to disk for storage.
Definition Database.C:954
void merge(const Database *)
Merge with another database.
Definition Database.C:947
static bool cache_last_cal
Cache the last calibrator?
Definition Database.h:40
~Database()
Destructor.
Definition Database.C:879
const Entry * best_match(const Criteria &) const
Returns the best Entry that matches the given Criteria.
Definition Database.C:1086
static bool match_verbose
Print verbose matching information.
Definition Database.h:43
std::string get_path() const
Returns the full path to the database summary file.
Definition Database.C:1656
static Option< double > max_centre_frequency_difference
Maximum difference between calibrator and pulsar centre frequencies.
Definition Database.h:55
FluxCalibrator * rawFluxCalibrator(const Archive *a)
Return a pointer to a new FluxCalibrator for the given archive.
Definition Database.C:1390
Criteria criteria(const Pulsar::Archive *arch, Signal::Source obsType) const
Return the Criteria for the specified Pulsar::Archive.
Definition Database.C:1191
void all_matching(const Criteria &, std::vector< const Entry * > &matches) const
Fills a vector with Entry instances that match the given Criteria.
Definition Database.C:1046
static Option< double > long_time_scale
Time scale over which calibrator flux and cross-coupling remain stable.
Definition Database.h:46
FluxCalibrator * generateFluxCalibrator(const Archive *, bool allow_raw=false)
Return a pointer to a new FluxCalibrator for the given archive.
Definition Database.C:1351
void expand_filename(Entry *entry)
Add path to Entry filename, if applicable.
Definition Database.C:996
void construct(const std::vector< std::string > &filenames)
Construct from the list of filenames.
Definition Database.C:846
HybridCalibrator * generateHybridCalibrator(ReferenceCalibrator *, const Archive *)
Return a pointer to a new HybridCalibrator.
Definition Database.C:1568
std::string get_filename(const Entry *) const
Returns the full pathname of the Entry filename.
Definition Database.C:1644
static Option< double > short_time_scale
Time scale over which differential gain and phase remain stable.
Definition Database.h:49
Calibrates flux using standard candles and artificial sources.
Definition FluxCalibrator.h:24
Supplements a SystemCalibrator with a SingleAxisCalibrator.
Definition HybridCalibrator.h:27
Configuration option.
Definition Config.h:69
Polarimetric calibrators.
Definition PolnCalibrator.h:37
Calibrators derived from reference source observations.
Definition ReferenceCalibrator.h:27
Defines the PSRCHIVE library.
Definition CalSource.h:17

Generated using doxygen 1.14.0