@@ -88,13 +88,23 @@ namespace Archon {
8888 this ->frame .buftimestamp .resize ( Archon::nbufs );
8989 this ->frame .bufretimestamp .resize ( Archon::nbufs );
9090 this ->frame .buffetimestamp .resize ( Archon::nbufs );
91+
92+ image_output_type = " disk" ;
9193 }
9294
9395 // Archon::Interface deconstructor
9496 //
9597 Interface::~Interface () = default ;
9698
9799
100+ ImageOutput* Interface::get_image_output () {
101+ if (!image_output) {
102+ output_handler = ImageOutputFactory::create_image_output (image_output_type);
103+ image_output = dynamic_cast <SaveToDisk*>(output_handler.get ());
104+ }
105+ return image_output;
106+ }
107+
98108 /* *************** Archon::Interface::interface ******************************/
99109 long Interface::interface (std::string &iface) {
100110 std::string function = " Archon::Interface::interface" ;
@@ -1340,7 +1350,7 @@ namespace Archon {
13401350 *
13411351 */
13421352 long Interface::load_acf (std::string acffile) {
1343- std::string function = " Archon::Interface::load_acf" ;
1353+ const std::string function ( " Archon::Interface::load_acf" ) ;
13441354 std::stringstream message;
13451355 std::fstream filestream; // I/O stream class
13461356 std::string line; // the line read from the acffile
@@ -1750,11 +1760,13 @@ namespace Archon {
17501760 logwrite (function, " loaded Archon config file OK" );
17511761 this ->firmwareloaded = true ;
17521762
1753- // add to systemkeys keyword database
1763+ // add firmware filename and checksum to systemkeys keyword database
17541764 //
1755- std::stringstream keystr;
1756- keystr << " FIRMWARE=" << acffile << " // controller firmware" ;
1757- this ->systemkeys .addkey ( keystr.str () );
1765+ this ->systemkeys .addkey ( " FIRMWARE=" + acffile + " // controller firmware" );
1766+
1767+ std::string hash;
1768+ md5_file ( acffile, hash );
1769+ this ->systemkeys .addkey ( " FIRM_MD5=" + hash + " // MD5 checksum of firmware" );
17581770 }
17591771
17601772 // If there was an Archon error then read the Archon error log
@@ -3300,7 +3312,7 @@ namespace Archon {
33003312 logwrite ( function, message.str () );
33013313 #endif
33023314
3303- error = this ->fits_file . write_image (fext, this ->camera_info ); // write the image to disk
3315+ error = this ->get_image_output ()-> write_image (fext, this ->camera_info );
33043316 this ->camera_info .extension ++; // increment extension for cubes
33053317 if ( fext != nullptr ) { delete [] fext; fext=nullptr ; } // dynamic object not automatic so must be destroyed
33063318
@@ -3326,7 +3338,7 @@ namespace Archon {
33263338 }
33273339
33283340// error = fits_file.write_image(fbuf, this->fits_info); // write the image to disk //TODO
3329- error = this ->fits_file . write_image (fbuf, this ->camera_info ); // write the image to disk
3341+ error = this ->get_image_output ()-> write_image (fbuf, this ->camera_info );
33303342 if ( error != NO_ERROR ) { this ->camera .log_error ( function, " writing 32-bit image to disk" ); }
33313343 delete [] fbuf;
33323344 }
@@ -3339,7 +3351,7 @@ namespace Archon {
33393351 if (this ->camera_info .datatype == USHORT_IMG) { // raw
33403352 cbuf16 = (uint16_t *)this ->image_data ; // cast to 16b unsigned int
33413353// error = fits_file.write_image(cbuf16, this->fits_info); // write the image to disk //TODO
3342- error = this ->fits_file . write_image (cbuf16, this ->camera_info ); // write the image to disk
3354+ error = this ->get_image_output ()-> write_image (cbuf16, this ->camera_info );
33433355 if ( error != NO_ERROR ) { this ->camera .log_error ( function, " writing 16-bit raw image to disk" ); }
33443356
33453357 } else if (this ->camera_info .datatype == SHORT_IMG) {
@@ -3349,7 +3361,7 @@ namespace Archon {
33493361 for (long pix=0 ; pix < this ->camera_info .section_size ; pix++) {
33503362 ibuf[pix] = cbuf16s[pix] - 32768 ; // subtract 2^15 from every pixel
33513363 }
3352- error = this ->fits_file . write_image (ibuf, this ->camera_info ); // write the image to disk
3364+ error = this ->get_image_output ()-> write_image (ibuf, this ->camera_info );
33533365 if ( error != NO_ERROR ) { this ->camera .log_error ( function, " writing 16-bit image to disk" ); }
33543366 delete [] ibuf;
33553367
@@ -3925,7 +3937,7 @@ namespace Archon {
39253937 #ifdef LOGLEVEL_DEBUG
39263938 logwrite ( function, " [DEBUG] opening fits file for multi-exposure sequence data cube" );
39273939 #endif
3928- error = this ->fits_file . open_file (this ->camera .writekeys_when == " before" , this ->camera_info );
3940+ error = this ->get_image_output ()-> open (this ->camera .writekeys_when == " before" , this ->camera_info );
39293941 if ( error != NO_ERROR ) {
39303942 this ->camera .log_error ( function, " couldn't open fits file" );
39313943 return error;
@@ -4006,8 +4018,7 @@ namespace Archon {
40064018 // reset the extension number and open the fits file
40074019 //
40084020 this ->camera_info .extension = 0 ;
4009- error = this ->fits_file .open_file (
4010- this ->camera .writekeys_when == " before" , this ->camera_info );
4021+ error = this ->get_image_output ()->open (this ->camera .writekeys_when == " before" , this ->camera_info );
40114022 if ( error != NO_ERROR ) {
40124023 this ->camera .log_error ( function, " couldn't open fits file" );
40134024 return error;
@@ -4028,14 +4039,14 @@ namespace Archon {
40284039
40294040 if ( error != NO_ERROR ) {
40304041 logwrite ( function, " ERROR: waiting for readout" );
4031- this ->fits_file . close_file (this ->camera .writekeys_when == " after" , this ->camera_info );
4042+ this ->get_image_output ()-> close (this ->camera .writekeys_when == " after" , this ->camera_info );
40324043 return error;
40334044 }
40344045
40354046 error = read_frame (); // then read the frame buffer to host (and write file) when frame ready.
40364047 if ( error != NO_ERROR ) {
40374048 logwrite ( function, " ERROR: reading frame buffer" );
4038- this ->fits_file . close_file (this ->camera .writekeys_when == " after" , this ->camera_info );
4049+ this ->get_image_output ()-> close (this ->camera .writekeys_when == " after" , this ->camera_info );
40394050 return error;
40404051 }
40414052
@@ -4045,7 +4056,7 @@ namespace Archon {
40454056 #ifdef LOGLEVEL_DEBUG
40464057 logwrite ( function, " [DEBUG] closing fits file (1)" );
40474058 #endif
4048- this ->fits_file . close_file ( this ->camera .writekeys_when == " after" , this ->camera_info ); // close the file when not using datacubes
4059+ this ->get_image_output ()-> close ( this ->camera .writekeys_when == " after" , this ->camera_info );
40494060 this ->camera .increment_imnum (); // increment image_num when fitsnaming == "number"
40504061
40514062 // ASYNC status message on completion of each file
@@ -4076,13 +4087,13 @@ namespace Archon {
40764087
40774088 this ->copy_keydb (); // copy the ACF and userkeys databases into camera_info
40784089
4079- error = this ->fits_file . open_file (this ->camera .writekeys_when == " before" , this ->camera_info );
4090+ error = this ->get_image_output ()-> open (this ->camera .writekeys_when == " before" , this ->camera_info );
40804091 if ( error != NO_ERROR ) {
40814092 this ->camera .log_error ( function, " couldn't open fits file" );
40824093 return error;
40834094 }
40844095 error = read_frame (); // For raw mode just read immediately
4085- this ->fits_file . close_file (this ->camera .writekeys_when == " after" , this ->camera_info );
4096+ this ->get_image_output ()-> open (this ->camera .writekeys_when == " after" , this ->camera_info );
40864097 this ->camera .increment_imnum (); // increment image_num when fitsnaming == "number"
40874098 }
40884099
@@ -4092,7 +4103,7 @@ namespace Archon {
40924103 #ifdef LOGLEVEL_DEBUG
40934104 logwrite ( function, " [DEBUG] closing fits file (2)" );
40944105 #endif
4095- this ->fits_file . close_file (this ->camera .writekeys_when == " after" , this ->camera_info );
4106+ this ->get_image_output ()-> close (this ->camera .writekeys_when == " after" , this ->camera_info );
40964107 this ->camera .increment_imnum (); // increment image_num when fitsnaming == "number"
40974108
40984109 // ASYNC status message on completion of each file
@@ -4917,7 +4928,7 @@ namespace Archon {
49174928 #ifdef LOGLEVEL_DEBUG
49184929 logwrite ( function, " [DEBUG] opening fits file for multi-exposure sequence data cube" );
49194930 #endif
4920- error = this ->fits_file . open_file (
4931+ error = this ->get_image_output ()-> open (
49214932 this ->camera .writekeys_when == " before" , this ->camera_info );
49224933 if ( error != NO_ERROR ) {
49234934 this ->camera .log_error ( function, " couldn't open fits file" );
@@ -4999,7 +5010,7 @@ namespace Archon {
49995010 // reset the extension number and open the fits file
50005011 //
50015012 this ->camera_info .extension = 0 ;
5002- error = this ->fits_file . open_file (
5013+ error = this ->get_image_output ()-> open (
50035014 this ->camera .writekeys_when == " before" , this ->camera_info );
50045015 if ( error != NO_ERROR ) {
50055016 this ->camera .log_error ( function, " couldn't open fits file" );
@@ -5021,15 +5032,15 @@ namespace Archon {
50215032
50225033 if ( error != NO_ERROR ) {
50235034 logwrite ( function, " ERROR: waiting for readout" );
5024- this ->fits_file . close_file (
5035+ this ->get_image_output ()-> close (
50255036 this ->camera .writekeys_when == " after" , this ->camera_info );
50265037 return error;
50275038 }
50285039
50295040 error = read_frame (); // then read the frame buffer to host (and write file) when frame ready.
50305041 if ( error != NO_ERROR ) {
50315042 logwrite ( function, " ERROR: reading frame buffer" );
5032- this ->fits_file . close_file (
5043+ this ->get_image_output ()-> close (
50335044 this ->camera .writekeys_when == " after" , this ->camera_info );
50345045 return error;
50355046 }
@@ -5040,7 +5051,7 @@ namespace Archon {
50405051 #ifdef LOGLEVEL_DEBUG
50415052 logwrite ( function, " [DEBUG] closing fits file (1)" );
50425053 #endif
5043- this ->fits_file . close_file (
5054+ this ->get_image_output ()-> close (
50445055 this ->camera .writekeys_when == " after" , this ->camera_info ); // close the file when not using datacubes
50455056 this ->camera .increment_imnum (); // increment image_num when fitsnaming == "number"
50465057
@@ -5072,14 +5083,14 @@ namespace Archon {
50725083
50735084 this ->copy_keydb (); // copy the ACF and userkeys databases into camera_info
50745085
5075- error = this ->fits_file . open_file (
5086+ error = this ->get_image_output ()-> open (
50765087 this ->camera .writekeys_when == " before" , this ->camera_info );
50775088 if ( error != NO_ERROR ) {
50785089 this ->camera .log_error ( function, " couldn't open fits file" );
50795090 return error;
50805091 }
50815092 error = read_frame (); // For raw mode just read immediately
5082- this ->fits_file . close_file (this ->camera .writekeys_when == " after" , this ->camera_info );
5093+ this ->get_image_output ()-> close (this ->camera .writekeys_when == " after" , this ->camera_info );
50835094 this ->camera .increment_imnum (); // increment image_num when fitsnaming == "number"
50845095 }
50855096
@@ -5089,7 +5100,7 @@ namespace Archon {
50895100 #ifdef LOGLEVEL_DEBUG
50905101 logwrite ( function, " [DEBUG] closing fits file (2)" );
50915102 #endif
5092- this ->fits_file . close_file (this ->camera .writekeys_when == " after" , this ->camera_info );
5103+ this ->get_image_output ()-> close (this ->camera .writekeys_when == " after" , this ->camera_info );
50935104 this ->camera .increment_imnum (); // increment image_num when fitsnaming == "number"
50945105
50955106 // ASYNC status message on completion of each file
@@ -6044,16 +6055,16 @@ namespace Archon {
60446055 this ->add_filename_key (); // add filename to system keys database
60456056 this ->camera_info .systemkeys .keydb = this ->systemkeys .keydb ; // copy the systemkeys database into camera_info
60466057 if (this ->camera .writekeys_when ==" before" ) this ->copy_keydb (); // copy the ACF and userkeys database into camera_info
6047- error = this ->fits_file . open_file (this ->camera .writekeys_when == " before" , this ->camera_info );
6058+ error = this ->get_image_output ()-> open (this ->camera .writekeys_when == " before" , this ->camera_info );
60486059 logwrite ( function, " untimed exposure trigger enabled" );
60496060 return error;
60506061 }
60516062
60526063 // For "disable" there's nothing more to do right now (except close any open FITS file)
60536064 //
60546065 if ( error == NO_ERROR && this ->trigin_state == " disable" ) {
6055- if ( this ->fits_file . isopen () ) { // "untimed" could have opened a FITS file
6056- this ->fits_file . close_file ( false , this ->camera_info ); // close the FITS file container
6066+ if ( this ->get_image_output ()-> is_open () ) { // "untimed" could have opened a FITS file
6067+ this ->get_image_output ()-> close ( false , this ->camera_info ); // close the FITS file container
60576068 std::remove ( this ->camera_info .fits_name .c_str () ); // remove the (empty) file it created
60586069 }
60596070 logwrite ( function, " untimed exposure trigger disabled" );
@@ -6094,7 +6105,7 @@ namespace Archon {
60946105 if (error==NO_ERROR) error = this ->wait_for_readout (); // Wait for the readout into frame buffer,
60956106 if (error==NO_ERROR) error = read_frame (); // then read the frame buffer to host (and write file) when frame ready.
60966107
6097- this ->fits_file . close_file (this ->camera .writekeys_when == " after" , this ->camera_info ); // close the file when not using datacubes
6108+ this ->get_image_output ()-> close (this ->camera .writekeys_when == " after" , this ->camera_info ); // close the file when not using datacubes
60986109 this ->camera .increment_imnum (); // increment image_num when fitsnaming == "number"
60996110
61006111 // ASYNC status message on completion of each file
@@ -6145,7 +6156,7 @@ namespace Archon {
61456156 // Open the FITS file now for cubes
61466157 //
61476158 if ( this ->camera .datacube () ) {
6148- error = this ->fits_file . open_file (
6159+ error = this ->get_image_output ()-> open (
61496160 this ->camera .writekeys_when == " before" , this ->camera_info );
61506161 if ( error != NO_ERROR ) {
61516162 this ->camera .log_error ( function, " couldn't open fits file" );
@@ -6177,7 +6188,7 @@ namespace Archon {
61776188 return error;
61786189 }
61796190 this ->add_filename_key (); // add filename to system keys database
6180- error = this ->fits_file . open_file (
6191+ error = this ->get_image_output ()-> open (
61816192 this ->camera .writekeys_when == " before" , this ->camera_info );
61826193 if ( error != NO_ERROR ) {
61836194 this ->camera .log_error ( function, " couldn't open fits file" );
@@ -6193,7 +6204,7 @@ namespace Archon {
61936204 if (error==NO_ERROR) error = read_frame (); // then read the frame buffer to host (and write file) when frame ready.
61946205
61956206 if ( !this ->camera .datacube () ) { // Error or not, close the file.
6196- this ->fits_file . close_file (this ->camera .writekeys_when == " after" , this ->camera_info ); // close the file when not using datacubes
6207+ this ->get_image_output ()-> close (this ->camera .writekeys_when == " after" , this ->camera_info ); // close the file when not using datacubes
61976208 this ->camera .increment_imnum (); // increment image_num when fitsnaming == "number"
61986209
61996210 // ASYNC status message on completion of each file
@@ -6210,16 +6221,16 @@ namespace Archon {
62106221 error = this ->get_frame_status (); // Get the current frame buffer status
62116222 if (error==NO_ERROR) error = this ->camera .get_fitsname ( this ->camera_info .fits_name ); // Assemble the FITS filename
62126223 this ->add_filename_key (); // add filename to system keys database
6213- if (error==NO_ERROR) error = this ->fits_file . open_file (
6224+ if (error==NO_ERROR) error = this ->get_image_output ()-> open (
62146225 this ->camera .writekeys_when == " before" , this ->camera_info );
62156226 if (error==NO_ERROR) error = read_frame (); // For raw mode just read immediately
6216- this ->fits_file . close_file (this ->camera .writekeys_when == " after" , this ->camera_info );
6227+ this ->get_image_output ()-> close (this ->camera .writekeys_when == " after" , this ->camera_info );
62176228 this ->camera .increment_imnum (); // increment image_num when fitsnaming == "number"
62186229 }
62196230 // for cubes, close the FITS file now that they've all been written
62206231 //
62216232 if ( this ->camera .datacube () ) {
6222- this ->fits_file . close_file (this ->camera .writekeys_when == " after" , this ->camera_info );
6233+ this ->get_image_output ()-> close (this ->camera .writekeys_when == " after" , this ->camera_info );
62236234 this ->camera .increment_imnum (); // increment image_num when fitsnaming == "number"
62246235
62256236 // ASYNC status message on completion of each file
@@ -8006,7 +8017,7 @@ namespace Archon {
80068017 // open the file now for datacubes
80078018 //
80088019 if ( this ->camera .datacube () ) {
8009- error = this ->fits_file . open_file (
8020+ error = this ->get_image_output ()-> open (
80108021 this ->camera .writekeys_when == " before" , this ->camera_info );
80118022 if ( error != NO_ERROR ) {
80128023 this ->camera .log_error ( function, " couldn't open fits file" );
@@ -8042,7 +8053,7 @@ namespace Archon {
80428053 }
80438054 this ->add_filename_key (); // add filename to system keys database
80448055
8045- error = this ->fits_file . open_file (
8056+ error = this ->get_image_output ()-> open (
80468057 this ->camera .writekeys_when == " before" , this ->camera_info );
80478058 if ( error != NO_ERROR ) {
80488059 this ->camera .log_error ( function, " couldn't open fits file" );
@@ -8065,7 +8076,7 @@ namespace Archon {
80658076 if (error==NO_ERROR && ro) error = this ->read_frame (Camera::FRAME_IMAGE); // read image frame directly with no write
80668077 if (error==NO_ERROR && rw) error = this ->read_frame (); // read image frame directly with no write
80678078 if (error==NO_ERROR && rw && !this ->camera .datacube ()) {
8068- this ->fits_file . close_file (this ->camera .writekeys_when == " after" , this ->camera_info );
8079+ this ->get_image_output ()-> close (this ->camera .writekeys_when == " after" , this ->camera_info );
80698080 this ->camera .increment_imnum (); // increment image_num when fitsnaming == "number"
80708081 }
80718082 if (error==NO_ERROR) frames_read++;
@@ -8076,7 +8087,7 @@ namespace Archon {
80768087 // (or any time there is an error)
80778088 //
80788089 if ( rw && ( this ->camera .datacube () || (error==ERROR) ) ) {
8079- this ->fits_file . close_file (this ->camera .writekeys_when == " after" , this ->camera_info );
8090+ this ->get_image_output ()-> close (this ->camera .writekeys_when == " after" , this ->camera_info );
80808091 this ->camera .increment_imnum (); // increment image_num when fitsnaming == "number"
80818092 }
80828093
0 commit comments