EigerCamera.cpp 34.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
///###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2014
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//############################################################################

#include <sstream>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
28
#include <pthread.h>
29
#include "EigerCamera.h"
30
#include "EigerCameraRequests.h"
31
#include "lima/Timestamp.h"
32
33
34
35

using namespace lima;
using namespace lima::Eiger;
using namespace std;
36
using namespace eigerapi;
37

38
39
#define sendCommand(cmd)			\
  sendEigerCommand(*this, cmd)
40

41
42
#define setParam(param, value)			\
  setEigerParam(*this, param, value)
43

44
45
#define getParam(param, value)			\
  getEigerParam(*this, param, value)
46
47


48
49
50
/*----------------------------------------------------------------------------
			    Callback class
 ----------------------------------------------------------------------------*/
51
class Camera::TriggerCallback : public Callback
52
{
53
  DEB_CLASS_NAMESPC(DebModCamera, "Camera::TriggerCallback", "Eiger");
54
public:
55
  TriggerCallback(Camera& cam) : m_cam(cam) {}
56

57
58
  void status_changed(CurlLoop::FutureRequest::Status status,
		      std::string error)
59
  {
60
61
62
63
64
65
    DEB_MEMBER_FUNCT();
    DEB_PARAM() << DEB_VAR2(status, error);
    bool ok = (status == CurlLoop::FutureRequest::OK);
    if (!ok)
      DEB_ERROR() << DEB_VAR1(error); 
    m_cam._trigger_finished(ok);
66
67
68
69
70
  }
private:
  Camera& m_cam;
};

71
class Camera::InitCallback : public Callback
72
{	
73
  DEB_CLASS_NAMESPC(DebModCamera, "Camera::InitCallback", "Eiger");
74
75
76
public:
  InitCallback(Camera& cam) : m_cam(cam) {}

77
78
  void status_changed(CurlLoop::FutureRequest::Status status,
		      std::string error)
79
80
  {
    DEB_MEMBER_FUNCT();
81
    DEB_PARAM() << DEB_VAR2(status, error);
82
    bool ok = (status == CurlLoop::FutureRequest::OK);
83
84
85
    if (!ok)
      DEB_ERROR() << DEB_VAR1(error); 
    m_cam._initialization_finished(ok);
86
  }
87

88
89
90
91
private:
  Camera& m_cam;
};

92
93
94
//-----------------------------------------------------------------------------
///  Ctor
//-----------------------------------------------------------------------------
95
Camera::Camera(const std::string& detector_ip, 	///< [in] Ip address of the detector server
96
	       ApiGeneration api)
97
98
  : 		m_api(api),
		m_image_number(0),
99
                m_latency_time(0.),
100
                m_detectorImageType(Bpp16),
101
		m_initialize_state(IDLE),
102
		m_trigger_state(IDLE),
103
		m_armed(false),
104
105
		m_serie_id(0),
                m_requests(new Requests(detector_ip)),
106
                m_exp_time(1.),
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
107
		m_detector_ip(detector_ip)
108
109
{
    DEB_CONSTRUCTOR();
110
    DEB_PARAM() << DEB_VAR1(detector_ip);
111
    // Init EigerAPI
112
113
    try
      {
114
	_synchronize();
115
116
117
118
      }
    catch(Exception& e)
      {
	DEB_ALWAYS() << "Could not get configuration parameters, try to initialize";
119
120
121
122
	initialize();
	AutoMutex lock(m_cond.mutex());
	while (m_initialize_state == RUNNING)
	  m_cond.wait();
123
      }
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

    // Display max image size
    DEB_TRACE() << "Detector max width: " << m_maxImageWidth;
    DEB_TRACE() << "Detector max height:" << m_maxImageHeight;

    // --- Set detector for software single image mode    
    setTrigMode(IntTrig);

    m_nb_frames = 1;

}


//-----------------------------------------------------------------------------
///  Dtor
//-----------------------------------------------------------------------------
Camera::~Camera()
{
    DEB_DESTRUCTOR();
143
    delete m_requests;
144
145
146
}


147
148
149
150
151
//----------------------------------------------------------------------------
// initialize detector
//----------------------------------------------------------------------------
void Camera::initialize()
{
152
  DEB_MEMBER_FUNCT();
153
154
  // Finally initialize the detector
  AutoMutex lock(m_cond.mutex());
155
156
  DEB_ALWAYS() << "Initializing detector ... ";
  m_initialize_state = RUNNING;
157
  CommandReq async_initialize = m_requests->get_command(Requests::INITIALIZE);
158
  lock.unlock();
159

160
  CallbackPtr cbk(new InitCallback(*this));
161
  async_initialize->register_callback(cbk, true);
162
}
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

void Camera::_initialization_finished(bool ok)
{
  DEB_MEMBER_FUNCT();
  DEB_PARAM() << DEB_VAR1(ok);

  const char *status_desc = ok ? "OK" : "Error";
  DEB_ALWAYS() << "Initialize finished: " << status_desc;

  if (ok) {
    try {
      DEB_ALWAYS() << "Synchronizing with detector ...";
      _synchronize();
      DEB_ALWAYS() << "Done!";
    } catch (const lima::Exception& e) {
      ok = false;
    }
  }
    
  AutoMutex lock(m_cond.mutex());
  m_initialize_state = ok ? Camera::IDLE : Camera::ERROR;
  m_cond.signal();
}

187
188
189
190
191
//-----------------------------------------------------------------------------
/// Set detector for single image acquisition
//-----------------------------------------------------------------------------
void Camera::prepareAcq()
{
192
193
  DEB_MEMBER_FUNCT();
  AutoMutex aLock(m_cond.mutex());
194
195
  if(m_armed)
    THROW_HW_ERROR(Error) << "Camera already armed";
196
  
197
  unsigned nb_images, nb_triggers;
198
199
200
201
  switch(m_trig_mode)
    {
    case IntTrig:
    case ExtTrigSingle:
202
      nb_images = m_nb_frames, nb_triggers = 1; break;
203
204
205
    case IntTrigMult:
    case ExtTrigMult:
    case ExtGate:
206
      nb_images = 1, nb_triggers = m_nb_frames; break;
207
208
209
    default:
      THROW_HW_ERROR(Error) << "Very weird can't be in this case";
    }
210
  double frame_time = m_exp_time + m_latency_time;
211
212
213
214
215
216
217
218
  if(frame_time < m_min_frame_time)
    {    
      if(m_latency_time <= m_readout_time)
	frame_time = m_min_frame_time;
      else
	THROW_HW_ERROR(Error) << "This detector can't go at this frame rate (" << 1 / frame_time
			      << ") is limited to (" << 1 / m_min_frame_time << ")";
    }
219

220
221
  DEB_PARAM() << DEB_VAR3(frame_time, nb_images, nb_triggers);

222
  MultiParamRequest synchro(*this);
223
224
225
226
227
228
229
  if (m_frame_time.changed(frame_time))
    synchro.addSet(Requests::FRAME_TIME, frame_time);
  if (m_nb_images.changed(nb_images))
    synchro.addSet(Requests::NIMAGES, nb_images);
  if (m_nb_triggers.changed(nb_triggers))
    synchro.addSet(Requests::NTRIGGER, nb_triggers);
  synchro.wait();
230

231
  DEB_TRACE() << "Arm start";
232
  double timeout = 5 * 60.; // 5 min timeout
233
  CommandReq arm_cmd = m_requests->get_command(Requests::ARM);
234
235
236
  try
    {
      arm_cmd->wait(timeout);
237
      DEB_TRACE() << "Arm end";
238
      m_serie_id = arm_cmd->get_serie_id();
239
      m_armed = true;
240
241
242
243
    }
  catch(const eigerapi::EigerException &e)
    {
      m_requests->cancel(arm_cmd);
244
      HANDLE_EIGERERROR(arm_cmd, e);
245
246
    }
  m_image_number = 0;
247
248
249
250
251
252
253
254
}


//-----------------------------------------------------------------------------
///  start the acquisition
//-----------------------------------------------------------------------------
void Camera::startAcq()
{
255
256
257
258
259
260
  DEB_MEMBER_FUNCT();
  AutoMutex lock(m_cond.mutex());

  if(m_trig_mode == IntTrig ||
     m_trig_mode == IntTrigMult)
    {
261
262
263
      bool disarm_at_end = ((m_trig_mode == IntTrig) ||
			    (m_image_number == m_nb_frames - 1));
      DEB_TRACE() << "Trigger start: " << DEB_VAR1(disarm_at_end);
264
      CommandReq trigger = m_requests->get_command(Requests::TRIGGER);
265
266
267
      m_trigger_state = RUNNING;
      lock.unlock();

268
      CallbackPtr cbk(new TriggerCallback(*this));
269
      trigger->register_callback(cbk, disarm_at_end);
270
271
    }
  
272
273
274
275
276
277
278
279
}


//-----------------------------------------------------------------------------
/// stop the acquisition
//-----------------------------------------------------------------------------
void Camera::stopAcq()
{
280
  DEB_MEMBER_FUNCT();
281
  AutoMutex lock(m_cond.mutex());
282
  sendCommand(Requests::ABORT);
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
}


//-----------------------------------------------------------------------------
/// return the detector Max image size 
//-----------------------------------------------------------------------------
void Camera::getDetectorMaxImageSize(Size& size) ///< [out] image dimensions
{
	DEB_MEMBER_FUNCT();
	size = Size(m_maxImageWidth, m_maxImageHeight);
}


//-----------------------------------------------------------------------------
/// return the detector image size 
//-----------------------------------------------------------------------------
void Camera::getDetectorImageSize(Size& size) ///< [out] image dimensions
{
301
302
  DEB_MEMBER_FUNCT();

303
  ParamReq width_request = 
304
    m_requests->get_param(Requests::DETECTOR_WITDH);
305
  ParamReq height_request = 
306
307
308
309
310
    m_requests->get_param(Requests::DETECTOR_HEIGHT);

  Requests::Param::Value width = width_request->get();
  Requests::Param::Value height = height_request->get();
  size = Size(width.data.int_val, height.data.int_val);
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
}


//-----------------------------------------------------------------------------
/// Get the image type
//-----------------------------------------------------------------------------
void Camera::getImageType(ImageType& type) ///< [out] image type
{
    DEB_MEMBER_FUNCT();

    type = m_detectorImageType;    
}


//-----------------------------------------------------------------------------
//! Camera::setImageType()
//-----------------------------------------------------------------------------
void Camera::setImageType(ImageType type) ///< [in] image type
{
	DEB_MEMBER_FUNCT();
	DEB_TRACE() << "Camera::setImageType - " << DEB_VAR1(type);
}


//-----------------------------------------------------------------------------
/// return the detector type
//-----------------------------------------------------------------------------
void Camera::getDetectorType(string& type) ///< [out] detector type
{
  DEB_MEMBER_FUNCT();

  type = m_detector_type;
}


//-----------------------------------------------------------------------------
/// return the detector model
//-----------------------------------------------------------------------------
void Camera::getDetectorModel(string& model) ///< [out] detector model
{
  DEB_MEMBER_FUNCT();

  model = m_detector_model;
}


//-----------------------------------------------------------------------------
/// Checks trigger mode
/*!
@return true if the given trigger mode is supported
*/
//-----------------------------------------------------------------------------
bool Camera::checkTrigMode(TrigMode trig_mode) ///< [in] trigger mode to check
{
365
366
367
368
369
  DEB_MEMBER_FUNCT();
  DEB_PARAM() << DEB_VAR1(trig_mode);
  switch(trig_mode)
    {
    case IntTrig:
370
    case IntTrigMult:
371
372
373
374
375
376
377
    case ExtTrigSingle:
    case ExtTrigMult:
    case ExtGate:
      return true;
    default:
      return false;
    }
378
379
380
381
382
383
384
385
}


//-----------------------------------------------------------------------------
/// Set the new trigger mode
//-----------------------------------------------------------------------------
void Camera::setTrigMode(TrigMode trig_mode) ///< [in] lima trigger mode to set
{
386
387
388
389
390
391
392
  DEB_MEMBER_FUNCT();
  DEB_PARAM() << DEB_VAR1(trig_mode);

  const char *trig_name;
  switch(trig_mode)
    {
    case IntTrig:
393
    case IntTrigMult:
394
395
396
      trig_name = "ints";break;
    case ExtTrigSingle:
    case ExtTrigMult:
397
      trig_name = "exts";break;
398
399
400
401
402
    case ExtGate:
      trig_name = "exte";break;
    default:
      THROW_HW_ERROR(NotSupported) << DEB_VAR1(trig_mode);
    }
403
404

  if (m_trig_mode.changed(trig_mode))
405
    setParam(Requests::TRIGGER_MODE,trig_name);
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
}


//-----------------------------------------------------------------------------
/// Get the current trigger mode
//-----------------------------------------------------------------------------
void Camera::getTrigMode(TrigMode& mode) ///< [out] current trigger mode
{
  DEB_MEMBER_FUNCT();
  mode = m_trig_mode;

  DEB_RETURN() << DEB_VAR1(mode);
}


//-----------------------------------------------------------------------------
/// Set the new exposure time
//-----------------------------------------------------------------------------
424
425
void Camera::setExpTime(double exp_time, ///< [in] exposure time to set
			bool force)
426
{
427
428
429
  DEB_MEMBER_FUNCT();
  DEB_PARAM() << DEB_VAR1(exp_time);

430
  if (m_exp_time.changed(exp_time) || force)
431
    setParam(Requests::EXPOSURE, exp_time);
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
}


//-----------------------------------------------------------------------------
/// Get the current exposure time
//-----------------------------------------------------------------------------
void Camera::getExpTime(double& exp_time) ///< [out] current exposure time
{
 DEB_MEMBER_FUNCT();

 exp_time = m_exp_time;

 DEB_RETURN() << DEB_VAR1(exp_time);
}


//-----------------------------------------------------------------------------
/// Set the new latency time between images
//-----------------------------------------------------------------------------
void Camera::setLatTime(double lat_time) ///< [in] latency time
{
453
454
455
  DEB_MEMBER_FUNCT();
  DEB_PARAM() << DEB_VAR1(lat_time);

456
  bool force_exp = (lat_time != m_latency_time);
457
  m_latency_time = lat_time;
458
  setExpTime(m_exp_time, force_exp);
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
}


//-----------------------------------------------------------------------------
/// Get the current latency time
//-----------------------------------------------------------------------------
void Camera::getLatTime(double& lat_time) ///< [out] current latency time
{
  DEB_MEMBER_FUNCT();
  
  lat_time = m_latency_time;

  DEB_RETURN() << DEB_VAR1(lat_time);
}


//-----------------------------------------------------------------------------
/// Get the exposure time range
//-----------------------------------------------------------------------------
void Camera::getExposureTimeRange(double& min_expo,	///< [out] minimum exposure time
                                  double& max_expo)   ///< [out] maximum exposure time
const
{
  DEB_MEMBER_FUNCT();
483
  ParamReq exp_time = 
484
485
486
487
488
489
490
491
    m_requests->get_param(Requests::EXPOSURE);
  try
    {
      exp_time->wait();
    }
  catch(const eigerapi::EigerException &e)
    {
      m_requests->cancel(exp_time);
492
      HANDLE_EIGERERROR(exp_time, e);
493
494
495
    }

  Requests::Param::Value min_val = exp_time->get_min();
496
497
498
499
500
501
  Requests::Param::Value max_val;
  if (m_api == Eiger1)
    max_val = exp_time->get_max();
  else
    max_val.data.double_val = 1800;

502
503
  min_expo = min_val.data.double_val;
  max_expo = max_val.data.double_val;
504
505
506
507
508
509
510
511
512
513
514
515
516
517
  DEB_RETURN() << DEB_VAR2(min_expo, max_expo);
}


//-----------------------------------------------------------------------------
///  Get the latency time range
//-----------------------------------------------------------------------------
void Camera::getLatTimeRange(double& min_lat, ///< [out] minimum latency
                             double& max_lat) ///< [out] maximum latency
const
{
  DEB_MEMBER_FUNCT();

    // --- no info on min latency
518
519
520
521
  min_lat = m_readout_time;
  double min_exp,max_exp;
  getExposureTimeRange(min_exp,max_exp);
  max_lat = max_exp;
522
523
524
525
526
527
528
529
530
531
532
533
534
535

  DEB_RETURN() << DEB_VAR2(min_lat, max_lat);
}


//-----------------------------------------------------------------------------
/// Set the number of frames to be taken
//-----------------------------------------------------------------------------
void Camera::setNbFrames(int nb_frames) ///< [in] number of frames to take
{
    DEB_MEMBER_FUNCT();
    DEB_PARAM() << DEB_VAR1(nb_frames);

    if (0==nb_frames)
536
      THROW_HW_ERROR(NotSupported) << "video mode is not supported";
537

538
    m_nb_frames = nb_frames;
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
}


//-----------------------------------------------------------------------------
/// Get the number of frames to be taken
//-----------------------------------------------------------------------------
void Camera::getNbFrames(int& nb_frames) ///< [out] current number of frames to take
{
  DEB_MEMBER_FUNCT();
  nb_frames = m_nb_frames;
  DEB_RETURN() << DEB_VAR1(nb_frames);
}


//-----------------------------------------------------------------------------
/// Get the current acquired frames
//-----------------------------------------------------------------------------
void Camera::getNbHwAcquiredFrames(int &nb_acq_frames) ///< [out] number of acquired files
{ 
558
559
  DEB_MEMBER_FUNCT();
  AutoMutex lock(m_cond.mutex());
560
561
562
563
564
565
566
567
568
  nb_acq_frames = m_image_number;
}


//-----------------------------------------------------------------------------
/// Get the camera status
//-----------------------------------------------------------------------------
Camera::Status Camera::getStatus() ///< [out] current camera status
{
569
570
571
572
  DEB_MEMBER_FUNCT();

  Camera::Status status;
  AutoMutex lock(m_cond.mutex());
573
  if(m_initialize_state == ERROR ||
574
575
576
577
     m_trigger_state == ERROR)
    status = Fault;
  else if(m_trigger_state == RUNNING)
    status = Exposure;
578
579
  else if(m_armed)
    status = Armed;
580
581
  else if(m_initialize_state == RUNNING)
    status = Initializing;
582
583
584
585
586
  else
    status = Ready;

  DEB_RETURN() << DEB_VAR1(status);
  return status;
587
}
588
589
590
591
592
593
594
//----------------------------------------------------------------------------
// Get camera hardware status
//----------------------------------------------------------------------------
std::string Camera::getCamStatus()
{
  DEB_MEMBER_FUNCT();
  std::string status;
595
  getParam(Requests::DETECTOR_STATUS,status);
596
597
  return status;
}
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
//-----------------------------------------------------------------------------
/// Tells if binning is available
/*!
@return always false, hw binning mode is not supported
*/
//-----------------------------------------------------------------------------
bool Camera::isBinningAvailable()
{
  DEB_MEMBER_FUNCT();
  return false;
}


//-----------------------------------------------------------------------------
/// return the detector pixel size in meter
//-----------------------------------------------------------------------------
void Camera::getPixelSize(double& sizex,	///< [out] horizontal pixel size
                          double& sizey)	///< [out] vertical   pixel size
{
  DEB_MEMBER_FUNCT();

  sizex = m_x_pixelsize;
  sizey = m_y_pixelsize;
  DEB_RETURN() << DEB_VAR2(sizex, sizey); 
}


//-----------------------------------------------------------------------------
/// reset the camera, no hw reset available on Eiger camera
//-----------------------------------------------------------------------------
/*
void Camera::reset()
{
    DEB_MEMBER_FUNCT();
    return;
}
*/

//-----------------------------------------------------------------------------
637
///    synchronize with controller
638
//-----------------------------------------------------------------------------
639
void Camera::_synchronize()
640
{
641
  DEB_MEMBER_FUNCT();
642
643
644
645
  DEB_TRACE() << "_synchronize()";

  AutoMutex lock(m_cond.mutex());

646
  MultiParamRequest synchro(*this);
647
648

  std::string trig_name;
649
  synchro.addGet(Requests::TRIGGER_MODE, trig_name);
650
  
651
652
  synchro.addGet(Requests::X_PIXEL_SIZE, m_x_pixelsize);
  synchro.addGet(Requests::Y_PIXEL_SIZE, m_y_pixelsize);
653

654
655
  synchro.addGet(Requests::DETECTOR_WITDH, m_maxImageWidth);
  synchro.addGet(Requests::DETECTOR_HEIGHT, m_maxImageHeight);
656

657
  synchro.addGet(Requests::DETECTOR_READOUT_TIME, m_readout_time);
658

659
660
661
662
  synchro.addGet(Requests::DESCRIPTION, m_detector_model);
  synchro.addGet(Requests::DETECTOR_NUMBER, m_detector_type);
  synchro.addGet(Requests::EXPOSURE, m_exp_time);
  synchro.addGet(Requests::NIMAGES, m_nb_images);
663
  
664
665
  synchro.addGet(Requests::NTRIGGER, m_nb_triggers);
  synchro.addGet(Requests::FRAME_TIME, m_frame_time);
666
667

  bool auto_summation;
668
  synchro.addGet(Requests::AUTO_SUMMATION, auto_summation);
669
670
671

  std::string compression_type;
  synchro.addGet(Requests::COMPRESSION_TYPE, compression_type);
672
  
673
  //Synchro
674
  synchro.wait();
675

676
  m_detectorImageType = auto_summation ? Bpp32 : Bpp16;
677
  _updateImageSize();
678
679
680

  //Trigger mode
  if(trig_name == "ints")
681
    m_trig_mode = m_nb_triggers > 1 ? IntTrigMult : IntTrig;
682
  else if(trig_name == "exts")
683
    m_trig_mode = m_nb_triggers > 1 ? ExtTrigMult : ExtTrigSingle;
684
685
686
  else if(trig_name == "exte")
    m_trig_mode = ExtGate;
  else
687
688
    THROW_HW_ERROR(InvalidValue) << "Unexpected trigger mode: "
				 << DEB_VAR1(trig_name);
689
  
690
  Requests::Param::Value min_frame_time = synchro[Requests::FRAME_TIME]->get_min();
691
  m_min_frame_time = min_frame_time.data.double_val;
692
693
694
695
696
697
698
699
700
701

  if (compression_type == "none")
    m_compression_type = NoCompression;
  else if (compression_type == "lz4")
    m_compression_type = LZ4;
  else if (compression_type == "bslz4")
    m_compression_type = BSLZ4;
  else
    THROW_HW_ERROR(InvalidValue) << "Unexpected compression type: "
				 << DEB_VAR1(compression_type);
702
703
704
705
706
707
708
709
710
711
712
713
714
715
}

//----------------------------------------------------------------------------
//	ImageSizeChanged hook
//----------------------------------------------------------------------------
void Camera::_updateImageSize()
{
  DEB_MEMBER_FUNCT();
  Size image_size;
  getDetectorImageSize(image_size);
  DEB_TRACE() << DEB_VAR2(image_size,m_detectorImageType);
  maxImageSizeChanged(image_size,m_detectorImageType);
}

716
/*----------------------------------------------------------------------------
717
	This method is called when the trigger is finished
718
  ----------------------------------------------------------------------------*/
719
void Camera::_trigger_finished(bool ok)
720
721
722
723
{
  DEB_MEMBER_FUNCT();
  DEB_PARAM() << DEB_VAR1(ok);
  
724
  DEB_TRACE() << "Trigger end";
725
  if(!ok)
726
    DEB_ERROR() << "Error in trigger command";
727
  else if(allFramesAcquired())
728
729
    try { disarm(); }
    catch (...) { ok = false; }
730
731
732
733

  AutoMutex lock(m_cond.mutex());
  m_trigger_state = ok ? IDLE : ERROR;
}
734

735
736
737
738
739
740
741
742
void Camera::newFrameAcquired()
{
  DEB_MEMBER_FUNCT();
  AutoMutex lock(m_cond.mutex());
  m_image_number++;
  DEB_TRACE() << DEB_VAR1(m_image_number);
}

743
bool Camera::allFramesAcquired()
744
745
746
{
  DEB_MEMBER_FUNCT();
  AutoMutex lock(m_cond.mutex());
747
748
  DEB_PARAM() << DEB_VAR2(m_image_number, m_nb_frames);
  bool finished = (m_image_number == m_nb_frames);
749
750
751
  DEB_RETURN() << DEB_VAR1(finished);
  return finished;
}
752
753
754
755
756
757
758
759
760
761
762
763
764
765

//-----------------------------------------------------------------------------
/// Returns the API generation of the detector
/*!
@return temperature value
*/
//-----------------------------------------------------------------------------
void Camera::getApiGeneration(ApiGeneration& api)
{
  DEB_MEMBER_FUNCT();
  api = m_api;
  DEB_RETURN() << DEB_VAR1(api);
}

766
767
768
769
770
771
//-----------------------------------------------------------------------------
/// Returns the temperature of the detector
/*!
@return temperature value
*/
//-----------------------------------------------------------------------------
772
void Camera::getTemperature(double &temp)
773
{
774
  DEB_MEMBER_FUNCT();
775
  getParam(Requests::TEMP,temp);
776
777
778
779
780
781
782
783
784
}


//-----------------------------------------------------------------------------
/// Returns the humidity of the detector
/*!
@return humidity value
*/
//-----------------------------------------------------------------------------
785
void Camera::getHumidity(double &humidity)
786
{
787
  DEB_MEMBER_FUNCT();
788
  getParam(Requests::HUMIDITY,humidity);
789
790
791
792
793
794
}


//-----------------------------------------------------------------------------
///  Count rate correction setter
//-----------------------------------------------------------------------------
795
void Camera::setCountrateCorrection(bool value) ///< [in] true:enabled, false:disabled
796
{
797
    DEB_MEMBER_FUNCT();
798
    setParam(Requests::COUNTRATE_CORRECTION,value);
799
800
801
802
803
804
805
806
}


//-----------------------------------------------------------------------------
///  Count rate correction getter
//-----------------------------------------------------------------------------
void Camera::getCountrateCorrection(bool& value)  ///< [out] true:enabled, false:disabled
{
807
  DEB_MEMBER_FUNCT();
808
  getParam(Requests::COUNTRATE_CORRECTION,value);
809
810
811
812
813
814
}


//-----------------------------------------------------------------------------
///  FlatfieldCorrection setter
//-----------------------------------------------------------------------------
815
void Camera::setFlatfieldCorrection(bool value) ///< [in] true:enabled, false:disabled
816
{
817
  DEB_MEMBER_FUNCT();
818
  setParam(Requests::FLATFIELD_CORRECTION,value);
819
820
821
822
823
824
825
826
827
}


//-----------------------------------------------------------------------------
///  FlatfieldCorrection getter
//-----------------------------------------------------------------------------
void Camera::getFlatfieldCorrection(bool& value) ///< [out] true:enabled, false:disabled
{
  DEB_MEMBER_FUNCT();
828
  getParam(Requests::FLATFIELD_CORRECTION,value);
829
}
830
831

//----------------------------------------------------------------------------
832
// Auto Summation setter
833
834
835
836
837
//----------------------------------------------------------------------------
void Camera::setAutoSummation(bool value)
{
  DEB_MEMBER_FUNCT();
  DEB_PARAM() << DEB_VAR1(value);
838
  setParam(Requests::AUTO_SUMMATION,value);
839
  m_detectorImageType = value ? Bpp32 : Bpp16;
840
  _updateImageSize();
841
}
842
843
844
845

//----------------------------------------------------------------------------
// Auto Summation getter
//----------------------------------------------------------------------------
846
847
848
void Camera::getAutoSummation(bool& value)
{
  DEB_MEMBER_FUNCT();
849
  getParam(Requests::AUTO_SUMMATION,value);
850
851
  DEB_RETURN() << DEB_VAR1(value);
}
852
853
854
//-----------------------------------------------------------------------------
///  PixelMask setter
//-----------------------------------------------------------------------------
855
void Camera::setPixelMask(bool value) ///< [in] true:enabled, false:disabled
856
{
857
    DEB_MEMBER_FUNCT();
858
    setParam(Requests::PIXEL_MASK,value);
859
860
861
862
863
864
865
866
}


//-----------------------------------------------------------------------------
///  PixelMask getter
//-----------------------------------------------------------------------------
void Camera::getPixelMask(bool& value) ///< [out] true:enabled, false:disabled
{
867
  DEB_MEMBER_FUNCT();
868
  getParam(Requests::PIXEL_MASK,value);
869
870
871
872
873
}

//-----------------------------------------------------------------------------
/// EfficiencyCorrection setter
//-----------------------------------------------------------------------------
874
void Camera::setEfficiencyCorrection(bool enabled) ///< [in] true:enabled, false:disabled
875
{
876
    DEB_MEMBER_FUNCT();
877
    if (m_api == Eiger1) {
878
        setParam(Requests::EFFICIENCY_CORRECTION,enabled);
879
880
881
    } else {
        DEB_WARNING() << "Efficiency correction is not implemented";
    }
882
883
884
885
886
887
888
889
}


//-----------------------------------------------------------------------------
/// EfficiencyCorrection getter
//-----------------------------------------------------------------------------
void Camera::getEfficiencyCorrection(bool& value)  ///< [out] true:enabled, false:disabled
{
890
  DEB_MEMBER_FUNCT();
891
  if (m_api == Eiger1) {
892
    getParam(Requests::EFFICIENCY_CORRECTION,value);
893
894
895
896
  } else {
    DEB_WARNING() << "Efficiency correction is not implemented";
    value = false;
  }
897
898
899
900
901
902
}


//-----------------------------------------------------------------------------
///  ThresholdEnergy setter
//-----------------------------------------------------------------------------
903
void Camera::setThresholdEnergy(double value) ///< [in] true:enabled, false:disabled
904
{
905
  DEB_MEMBER_FUNCT();
906
  setParam(Requests::THRESHOLD_ENERGY,value);
907
908
909
910
911
912
913
914
}


//-----------------------------------------------------------------------------
///  ThresholdEnergy getter
//-----------------------------------------------------------------------------
void Camera::getThresholdEnergy(double& value) ///< [out] true:enabled, false:disabled
{
915
  DEB_MEMBER_FUNCT();
916
  getParam(Requests::THRESHOLD_ENERGY,value);
917
918
919
920
921
922
}


//-----------------------------------------------------------------------------
///  VirtualPixelCorrection setter
//-----------------------------------------------------------------------------
923
void Camera::setVirtualPixelCorrection(bool value) ///< [in] true:enabled, false:disabled
924
{
925
  DEB_MEMBER_FUNCT();
926
  setParam(Requests::VIRTUAL_PIXEL_CORRECTION,value);
927
928
929
930
931
932
933
934
}


//-----------------------------------------------------------------------------
///  VirtualPixelCorrection getter
//-----------------------------------------------------------------------------
void Camera::getVirtualPixelCorrection(bool& value) ///< [out] true:enabled, false:disabled
{
935
  DEB_MEMBER_FUNCT();
936
  getParam(Requests::VIRTUAL_PIXEL_CORRECTION,value);
937
938
939
940
941
942
}


//-----------------------------------------------------------------------------
///  PhotonEnergy setter
//-----------------------------------------------------------------------------
943
void Camera::setPhotonEnergy(double value) ///< [in] true:enabled, false:disabled
944
{
945
    DEB_MEMBER_FUNCT();
946
    setParam(Requests::PHOTON_ENERGY,value);
947
948
949
950
951
952
953
954
}


//-----------------------------------------------------------------------------
///  PhotonEnergy getter
//-----------------------------------------------------------------------------
void Camera::getPhotonEnergy(double& value) ///< [out] true:enabled, false:disabled
{
955
  DEB_MEMBER_FUNCT();
956
  getParam(Requests::PHOTON_ENERGY,value);
957
958
959
960
961
962
963
964
}

//-----------------------------------------------------------------------------
///  Wavelength setter
//-----------------------------------------------------------------------------
void Camera::setWavelength(double value) ///< [in] true:enabled, false:disabled
{
    DEB_MEMBER_FUNCT();
965
    setParam(Requests::HEADER_WAVELENGTH,value);
966
967
968
969
970
971
972
973
974
}


//-----------------------------------------------------------------------------
///  Wavelength getter
//-----------------------------------------------------------------------------
void Camera::getWavelength(double& value) ///< [out] true:enabled, false:disabled
{
  DEB_MEMBER_FUNCT();
975
  getParam(Requests::HEADER_WAVELENGTH,value);
976
977
978
979
980
981
982
983
984
}


//-----------------------------------------------------------------------------
///  BeamCenterX setter
//-----------------------------------------------------------------------------
void Camera::setBeamCenterX(double value) ///< [in] 
{
    DEB_MEMBER_FUNCT();
985
    setParam(Requests::HEADER_BEAM_CENTER_X,value);
986
987
988
989
990
991
992
993
}

//-----------------------------------------------------------------------------
///  BeamCenterX getter
//-----------------------------------------------------------------------------
void Camera::getBeamCenterX(double& value) ///< [out] 
{
  DEB_MEMBER_FUNCT();
994
  getParam(Requests::HEADER_BEAM_CENTER_X,value);
995
996
997
998
999
1000
}

//-----------------------------------------------------------------------------
///  BeamCenterY setter
//-----------------------------------------------------------------------------
void Camera::setBeamCenterY(double value) ///< [in] 
For faster browsing, not all history is shown. View entire blame