ACQ2XX_API
AcqType.h
Go to the documentation of this file.
00001 /* ------------------------------------------------------------------------- */
00002 /* file AcqType.h                                                            */
00003 /* ------------------------------------------------------------------------- */
00004 /*   Copyright (C) 2009 Peter Milne, D-TACQ Solutions Ltd
00005  *                      <Peter dot Milne at D hyphen TACQ dot com>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of Version 2 of the GNU General Public License
00009     as published by the Free Software Foundation;
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
00019 /* ------------------------------------------------------------------------- */
00020 
00021 /** @file AcqType.h Encapsulates ACQ2xx product design details .
00022         . like channel mapping
00023  * Refs: see ICD for frame definition
00024 */
00025 
00026 
00027 #ifndef __ACQTYPE_H__
00028 #define __ACQTYPE_H__
00029 
00030 using namespace std;
00031 #include <string>
00032 
00033 class Acq2xx;
00034 
00035 class NewEventSignature {
00036 
00037 protected:
00038         short *raw;
00039         const unsigned long sample_cursor;
00040         bool has_timestamp;
00041         int rowlen;
00042 
00043         NewEventSignature(short _raw[], unsigned long _sample_cursor,
00044                         int _rowlen):
00045                 raw(0),
00046                 sample_cursor(_sample_cursor),
00047                 has_timestamp(false),
00048                 rowlen(_rowlen)
00049         {
00050 
00051         }
00052 
00053         NewEventSignature(bool _has_timestamp):
00054                 raw(0),
00055                 sample_cursor(0),
00056                 has_timestamp(_has_timestamp),
00057                 rowlen(0)
00058         {
00059 
00060         }
00061 
00062 public:
00063         virtual ~NewEventSignature() {}
00064         const short* getRaw(void) const {
00065                 return raw;
00066         }
00067 
00068         bool hasTimeStamp(void) const {
00069                 return has_timestamp;
00070         }
00071         virtual unsigned long long getTimeStamp(void) const = 0;
00072         virtual double timeInSeconds(void) const = 0;
00073 
00074         unsigned long getSampleCursor() {
00075                 return sample_cursor;
00076         }
00077 };
00078 
00079 
00080 class AcqType {
00081 
00082 protected:
00083         AcqType(const string _model, int _nchan, int _word_size) :
00084                 model(_model), nchan(_nchan), word_size(_word_size)
00085         {}
00086 
00087         AcqType(const char* _model, int _nchan, int _word_size) :
00088                 model(_model),
00089                         nchan(_nchan), word_size(_word_size)
00090         {}
00091 
00092                 static const AcqType& _getAcqType(
00093                         const char personality[], Acq2xx* card = 0);
00094         /**< Factory: builds AcqType instance from env array. */
00095 
00096 public:
00097         virtual ~AcqType() {}
00098         const string model;
00099         const int nchan;
00100         const int word_size;
00101 
00102         int getNumChannels() const {
00103                 return nchan;
00104         }
00105         int getWordSize() const {
00106                 return word_size;
00107         }
00108         int getSampleSize() const {
00109                 return getNumChannels() * getWordSize();
00110         }
00111 
00112         virtual int getChannelOffset(int physchan) const = 0;
00113 
00114         static const AcqType& getAcqType(Acq2xx& card);
00115         /**< Factory: build AcqType instance by querying card. */
00116         static const AcqType& getAcqType(const char* fname);
00117         /**< Factory: build AcqType instance from ini file. */
00118 
00119         virtual NewEventSignature* createES (
00120                         short _raw[], unsigned long _sample_cursor) const
00121         {
00122                                 return 0;
00123         }
00124 };
00125 
00126 class Clock {
00127 public:
00128         static double sample_clock_ns;
00129         static double es_clock_ns;
00130 };
00131 
00132 
00133 class UserEventSignature: public NewEventSignature {
00134         const double start_time;
00135 public:
00136         UserEventSignature(double _start_time):
00137                 NewEventSignature(true),
00138                 start_time(_start_time)
00139         {
00140 
00141         }
00142         virtual unsigned long long getTimeStamp(void) const {
00143                 return (unsigned long long)(Clock::sample_clock_ns * start_time);
00144         }
00145         virtual double timeInSeconds(void) const {
00146                 return start_time;
00147         }
00148 };
00149 
00150 class DualRate {
00151 public:
00152         static int div0;
00153         static int div1;
00154 
00155         static bool isDualRate(void) {
00156                 return div0 != 0 && div1 !=0;
00157         }
00158 };
00159 
00160 class File 
00161 {
00162         FILE *fp;
00163         string path;
00164 public:
00165         File(string root, string ext, const char* mode = "a");
00166         virtual ~File();
00167         
00168         FILE *getFp() { return fp; }
00169 
00170         const string getPath() const { return path; }
00171 
00172         int write(double* aDouble);
00173         int write(short* aShort);
00174         int writeln(const char* aline);
00175 };
00176 
00177 
00178 struct Pair {
00179         float p1;
00180         float p2;
00181 };
00182 
00183 #define DEFAULT_CAL     ""
00184 class AcqCal {
00185 protected:
00186         const AcqType& acq_type;
00187 
00188 public:
00189         AcqCal(const AcqType& _acq_type, string _base_name);
00190         virtual ~AcqCal() {}
00191         
00192         virtual int getCal(int ch, double& gain_v, double& offset_v) const = 0;
00193         /** ch index from 1 */
00194 
00195         static AcqCal* create(
00196                 const AcqType& _acq_type, 
00197                 string _base_name = string(DEFAULT_CAL));
00198 
00199         static void destroy(AcqCal* acq_cal);
00200 };
00201 
00202 class DumpDef {
00203 public:
00204         enum { PP_NONE, PP_ALL };
00205 
00206         string root;
00207         unsigned event_sample_start; /* start samples from beginning of shot */
00208         unsigned event_offset;       /* offset samples from beginning this data */
00209         unsigned pre;
00210         unsigned post;
00211         bool dump_timebase;
00212         bool appending;
00213 
00214         DumpDef(string _root,
00215                 unsigned _ess = 0, unsigned _esoff = 0,
00216                 int _pre = PP_NONE, int _post = PP_ALL):
00217                 root(_root), event_sample_start(_ess),
00218                 event_offset(_esoff), pre(_pre), post(_post),
00219                 dump_timebase(true),
00220                 appending(false)
00221         {}
00222         void print();
00223         bool specifiesFullSet() const {
00224                 return pre == PP_NONE && post == PP_ALL;
00225         }
00226 
00227         void setAppending(bool _appending){
00228                 appending = _appending;
00229         }
00230         static bool common_timebase;
00231 };
00232 #endif /* __ACQTYPE_H__ */