EigerCamera.cpp 35.3 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
28
///###########################################################################
// 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>
#include "EigerCamera.h"
29
#include <eigerapi/Requests.h>
30
#include "lima/Timestamp.h"
31
32
33
34

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

Arafat Noureddine's avatar
Arafat Noureddine committed
37

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#define HANDLE_EIGERERROR(__errMsg__) {		\
THROW_HW_ERROR(Error) << __errMsg__;		\
}

#define EIGER_SYNC_CMD_TIMEOUT(CommandType,timeout)			\
  {									\
    std::shared_ptr<Requests::Command> cmd =				\
      m_requests->get_command(CommandType);				\
    try									\
      {									\
	cmd->wait(timeout);						\
      }									\
    catch(const eigerapi::EigerException &e)				\
      {									\
	m_requests->cancel(cmd);					\
	HANDLE_EIGERERROR(e.what());					\
      }									\
  }

#define EIGER_SYNC_CMD(CommandType)		\
  EIGER_SYNC_CMD_TIMEOUT(CommandType,CurlLoop::FutureRequest::TIMEOUT)
  
#define EIGER_SYNC_SET_PARAM(ParamType,value)				\
  {									\
    std::shared_ptr<Requests::Param> req =				\
      m_requests->set_param(ParamType,value);				\
    try									\
      {									\
	req->wait();							\
      }									\
    catch(const eigerapi::EigerException &e)				\
      {									\
	HANDLE_EIGERERROR(e.what());					\
      }									\
  }

#define EIGER_SYNC_GET_PARAM(ParamType,value)				\
  {									\
    std::shared_ptr<Requests::Param> req =				\
      m_requests->get_param(ParamType,value);				\
    try									\
      {									\
	req->wait();							\
      }									\
    catch(const eigerapi::EigerException &e)				\
      {									\
	m_requests->cancel(req);					\
	HANDLE_EIGERERROR(e.what());					\
      }									\
  }

/*----------------------------------------------------------------------------
			    Callback class
 ----------------------------------------------------------------------------*/
class Camera::AcqCallback : public CurlLoop::FutureRequest::Callback
{
public:
  AcqCallback(Camera& cam) : m_cam(cam) {}

  void status_changed(CurlLoop::FutureRequest::Status status)
  {
    m_cam._acquisition_finished(status == CurlLoop::FutureRequest::OK);
  }
private:
  Camera& m_cam;
};

class Camera::InitCallback : public CurlLoop::FutureRequest::Callback
{	
  DEB_CLASS_NAMESPC(DebModCamera, "Camera", "Eiger::InitCallback");
public:
  InitCallback(Camera& cam) : m_cam(cam) {}

  void status_changed(CurlLoop::FutureRequest::Status status)
  {
    DEB_MEMBER_FUNCT();
    DEB_PARAM() << DEB_VAR1(status);

    AutoMutex lock(m_cam.m_cond.mutex());
    if(status == CurlLoop::FutureRequest::OK)
      m_cam.m_initilize_state= Camera::IDLE;
    else
      m_cam.m_initilize_state = Camera::ERROR;

    DEB_ALWAYS() << "Initialize finished";
  }
private:
  Camera& m_cam;
};

128
129
130
//-----------------------------------------------------------------------------
///  Ctor
//-----------------------------------------------------------------------------
131
Camera::Camera(const std::string& detector_ip, 	///< [in] Ip address of the detector server
132
	       ApiGeneration api)
133
134
  : 		m_api(api),
		m_image_number(0),
135
                m_latency_time(0.),
136
137
138
139
140
                m_detectorImageType(Bpp16),
		m_initilize_state(IDLE),
		m_trigger_state(IDLE),
		m_serie_id(0),
                m_requests(new Requests(detector_ip)),
141
                m_exp_time(1.),
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
142
		m_detector_ip(detector_ip)
143
144
{
    DEB_CONSTRUCTOR();
145
    DEB_PARAM() << DEB_VAR1(detector_ip);
146
    // Init EigerAPI
147
148
149
150
151
152
153
154
155
156
157
    try
      {
	initialiseController();
      }
    catch(Exception& e)
      {
	DEB_ALWAYS() << "Could not get configuration parameters, try to initialize";
	EIGER_SYNC_CMD_TIMEOUT(Requests::INITIALIZE,5*60);
	initialiseController();
      }
    
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176

    // 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();
177
    delete m_requests;
178
179
180
}


181
182
183
184
185
//----------------------------------------------------------------------------
// initialize detector
//----------------------------------------------------------------------------
void Camera::initialize()
{
186
  DEB_MEMBER_FUNCT();
187
188
189
190
191
  // Finally initialize the detector
  AutoMutex lock(m_cond.mutex());
  m_initilize_state = RUNNING;
  std::shared_ptr<Requests::Command> async_initialise =
    m_requests->get_command(Requests::INITIALIZE);
192
  lock.unlock();
193
194
195
196

  std::shared_ptr<CurlLoop::FutureRequest::Callback> cbk(new InitCallback(*this));
  async_initialise->register_callback(cbk);
}
197
198
199
200
201
//-----------------------------------------------------------------------------
/// Set detector for single image acquisition
//-----------------------------------------------------------------------------
void Camera::prepareAcq()
{
202
203
204
205
  DEB_MEMBER_FUNCT();
  AutoMutex aLock(m_cond.mutex());
  if(m_trigger_state != IDLE)
    EIGER_SYNC_CMD(Requests::DISARM);
206
  
207
  unsigned nb_images, nb_triggers;
208
209
210
211
  switch(m_trig_mode)
    {
    case IntTrig:
    case ExtTrigSingle:
212
      nb_images = m_nb_frames, nb_triggers = 1; break;
213
214
215
    case IntTrigMult:
    case ExtTrigMult:
    case ExtGate:
216
      nb_images = 1, nb_triggers = m_nb_frames; break;
217
218
219
    default:
      THROW_HW_ERROR(Error) << "Very weird can't be in this case";
    }
220
  double frame_time = m_exp_time + m_latency_time;
221
222
223
224
225
226
227
228
  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 << ")";
    }
229
230
231

  bool parallel_sync_cmds = (m_api == Eiger1);
  
232
233
  try
    {
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
      DEB_PARAM() << DEB_VAR1(frame_time);
      std::shared_ptr<Requests::Param> frame_time_req;
      if (m_frame_time.changed(frame_time)) {
	frame_time_req = m_requests->set_param(Requests::FRAME_TIME,frame_time);
	if (!parallel_sync_cmds)
	  frame_time_req->wait();
      }
      std::shared_ptr<Requests::Param> nimages_req;
      if (m_nb_images.changed(nb_images)) {
	nimages_req = m_requests->set_param(Requests::NIMAGES,nb_images);
	if (!parallel_sync_cmds)
	  nimages_req->wait();
      }
      std::shared_ptr<Requests::Param> ntrigger_req;
      if (m_nb_triggers.changed(nb_triggers)) {
	ntrigger_req = m_requests->set_param(Requests::NTRIGGER,nb_triggers);
	if (!parallel_sync_cmds)
	  ntrigger_req->wait();
      }
253
      if (parallel_sync_cmds) {
254
255
256
	if (frame_time_req) frame_time_req->wait();
	if (nimages_req) nimages_req->wait();
	if (ntrigger_req) ntrigger_req->wait();
257
      }
258
259
260
261
262
    }
  catch(const eigerapi::EigerException &e)
    {
      HANDLE_EIGERERROR(e.what());
    }
263

264
  DEB_TRACE() << "Arm start";
265
266
267
268
269
270
  double timeout = 5 * 60.; // 5 min timeout
  std::shared_ptr<Requests::Command> arm_cmd =
    m_requests->get_command(Requests::ARM);
  try
    {
      arm_cmd->wait(timeout);
271
      DEB_TRACE() << "Arm end";
272
273
274
275
276
277
278
279
      m_serie_id = arm_cmd->get_serie_id();
    }
  catch(const eigerapi::EigerException &e)
    {
      m_requests->cancel(arm_cmd);
      HANDLE_EIGERERROR(e.what());
    }
  m_image_number = 0;
280
281
282
283
284
285
286
287
}


//-----------------------------------------------------------------------------
///  start the acquisition
//-----------------------------------------------------------------------------
void Camera::startAcq()
{
288
289
290
291
292
293
294
295
296
  DEB_MEMBER_FUNCT();
  AutoMutex lock(m_cond.mutex());


  if(m_trig_mode == IntTrig ||
     m_trig_mode == IntTrigMult)
    {
      std::shared_ptr<Requests::Command> trigger =
	m_requests->get_command(Requests::TRIGGER);
297
298
299
      m_trigger_state = RUNNING;
      lock.unlock();

300
301
302
303
      std::shared_ptr<CurlLoop::FutureRequest::Callback> cbk(new AcqCallback(*this));
      trigger->register_callback(cbk);
    }
  
304
305
306
307
308
309
310
311
}


//-----------------------------------------------------------------------------
/// stop the acquisition
//-----------------------------------------------------------------------------
void Camera::stopAcq()
{
312
  DEB_MEMBER_FUNCT();
313
  EIGER_SYNC_CMD(Requests::ABORT);
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
}


//-----------------------------------------------------------------------------
/// 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
{
332
333
334
335
336
337
338
339
340
341
  DEB_MEMBER_FUNCT();

  std::shared_ptr<Requests::Param> width_request = 
    m_requests->get_param(Requests::DETECTOR_WITDH);
  std::shared_ptr<Requests::Param> height_request = 
    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);
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
}


//-----------------------------------------------------------------------------
/// 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
{
396
397
398
399
400
  DEB_MEMBER_FUNCT();
  DEB_PARAM() << DEB_VAR1(trig_mode);
  switch(trig_mode)
    {
    case IntTrig:
401
    case IntTrigMult:
402
403
404
405
406
407
408
    case ExtTrigSingle:
    case ExtTrigMult:
    case ExtGate:
      return true;
    default:
      return false;
    }
409
410
411
412
413
414
415
416
}


//-----------------------------------------------------------------------------
/// Set the new trigger mode
//-----------------------------------------------------------------------------
void Camera::setTrigMode(TrigMode trig_mode) ///< [in] lima trigger mode to set
{
417
418
419
420
421
422
423
  DEB_MEMBER_FUNCT();
  DEB_PARAM() << DEB_VAR1(trig_mode);

  const char *trig_name;
  switch(trig_mode)
    {
    case IntTrig:
424
    case IntTrigMult:
425
426
427
      trig_name = "ints";break;
    case ExtTrigSingle:
    case ExtTrigMult:
428
      trig_name = "exts";break;
429
430
431
432
433
    case ExtGate:
      trig_name = "exte";break;
    default:
      THROW_HW_ERROR(NotSupported) << DEB_VAR1(trig_mode);
    }
434
435
436

  if (m_trig_mode.changed(trig_mode))
    EIGER_SYNC_SET_PARAM(Requests::TRIGGER_MODE,trig_name);
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
}


//-----------------------------------------------------------------------------
/// 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
//-----------------------------------------------------------------------------
455
456
void Camera::setExpTime(double exp_time, ///< [in] exposure time to set
			bool force)
457
{
458
459
460
  DEB_MEMBER_FUNCT();
  DEB_PARAM() << DEB_VAR1(exp_time);

461
462
  if (m_exp_time.changed(exp_time) || force)
    EIGER_SYNC_SET_PARAM(Requests::EXPOSURE, exp_time);
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
}


//-----------------------------------------------------------------------------
/// 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
{
484
485
486
  DEB_MEMBER_FUNCT();
  DEB_PARAM() << DEB_VAR1(lat_time);

487
  bool force_exp = (lat_time != m_latency_time);
488
  m_latency_time = lat_time;
489
  setExpTime(m_exp_time, force_exp);
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
}


//-----------------------------------------------------------------------------
/// 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();
514
515
516
517
518
519
520
521
522
523
524
525
526
  std::shared_ptr<Requests::Param> exp_time = 
    m_requests->get_param(Requests::EXPOSURE);
  try
    {
      exp_time->wait();
    }
  catch(const eigerapi::EigerException &e)
    {
      m_requests->cancel(exp_time);
      HANDLE_EIGERERROR(e.what());
    }

  Requests::Param::Value min_val = exp_time->get_min();
527
528
529
530
531
532
  Requests::Param::Value max_val;
  if (m_api == Eiger1)
    max_val = exp_time->get_max();
  else
    max_val.data.double_val = 1800;

533
534
  min_expo = min_val.data.double_val;
  max_expo = max_val.data.double_val;
535
536
537
538
539
540
541
542
543
544
545
546
547
548
  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
549
550
551
552
  min_lat = m_readout_time;
  double min_exp,max_exp;
  getExposureTimeRange(min_exp,max_exp);
  max_lat = max_exp;
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570

  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)
    {
        HANDLE_EIGERERROR("video mode is not supported.");
    }

571
    m_nb_frames = nb_frames;
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
}


//-----------------------------------------------------------------------------
/// 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
{ 
  DEB_MEMBER_FUNCT();    
  nb_acq_frames = m_image_number;
}


//-----------------------------------------------------------------------------
/// Get the camera status
//-----------------------------------------------------------------------------
Camera::Status Camera::getStatus() ///< [out] current camera status
{
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
  DEB_MEMBER_FUNCT();

  Camera::Status status;
  AutoMutex lock(m_cond.mutex());
  if(m_initilize_state == ERROR ||
     m_trigger_state == ERROR)
    status = Fault;
  else if(m_trigger_state == RUNNING)
    status = Exposure;
  else if(m_initilize_state == RUNNING)
    status = Initialising;
  else
    status = Ready;

  DEB_RETURN() << DEB_VAR1(status);
  return status;
617
}
618
619
620
621
622
623
624
625
626
627
//----------------------------------------------------------------------------
// Get camera hardware status
//----------------------------------------------------------------------------
std::string Camera::getCamStatus()
{
  DEB_MEMBER_FUNCT();
  std::string status;
  EIGER_SYNC_GET_PARAM(Requests::DETECTOR_STATUS,status);
  return status;
}
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
//-----------------------------------------------------------------------------
/// 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;
}
*/

//-----------------------------------------------------------------------------
///    initialise controller
//-----------------------------------------------------------------------------
void Camera::initialiseController()
{
671
672
673
674
675
676
677
678
679
680
681
682
683
  DEB_MEMBER_FUNCT();
  DEB_TRACE() << "initialiseController()";

  std::list<std::shared_ptr<Requests::Param> > synchro_list;
  std::string trig_name;
  synchro_list.push_back(m_requests->get_param(Requests::TRIGGER_MODE,trig_name));
  
  synchro_list.push_back(m_requests->get_param(Requests::X_PIXEL_SIZE,m_x_pixelsize));
  synchro_list.push_back(m_requests->get_param(Requests::Y_PIXEL_SIZE,m_y_pixelsize));

  synchro_list.push_back(m_requests->get_param(Requests::DETECTOR_WITDH,m_maxImageWidth));
  synchro_list.push_back(m_requests->get_param(Requests::DETECTOR_HEIGHT,m_maxImageHeight));

684
685
686
687
688
689
690
  if (m_api == Eiger1) {
    synchro_list.push_back(m_requests->get_param(Requests::DETECTOR_READOUT_TIME,m_readout_time));
    synchro_list.push_back(m_requests->get_param(Requests::DESCRIPTION,m_detector_model));
  } else {
    m_readout_time = 100e-9;
    m_detector_model = "Eiger2 X";
  }
691
692
693

  synchro_list.push_back(m_requests->get_param(Requests::DETECTOR_NUMBER,m_detector_type));
  synchro_list.push_back(m_requests->get_param(Requests::EXPOSURE,m_exp_time));
694
  synchro_list.push_back(m_requests->get_param(Requests::NIMAGES,m_nb_images));
695
  
696
  synchro_list.push_back(m_requests->get_param(Requests::NTRIGGER,m_nb_triggers));
697

698
699
  std::shared_ptr<Requests::Param> frame_time_req = m_requests->get_param(Requests::FRAME_TIME);
  synchro_list.push_back(frame_time_req);
700
701
702
703

  bool auto_summation;
  synchro_list.push_back(m_requests->get_param(Requests::AUTO_SUMMATION,
					       auto_summation));
704
  
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
  //Synchro
  try
    {
      for(std::list<shared_ptr<Requests::Param> >::iterator i = synchro_list.begin();
	  i != synchro_list.end();++i)
	(*i)->wait();
    } 
  catch(const eigerapi::EigerException &e)
    {
      for(std::list<shared_ptr<Requests::Param> >::iterator i = synchro_list.begin();
	  i != synchro_list.end();++i)
	m_requests->cancel(*i);

        HANDLE_EIGERERROR(e.what());
    }

721
  m_detectorImageType = auto_summation ? Bpp32 : Bpp16;
722
723
724

  //Trigger mode
  if(trig_name == "ints")
725
    m_trig_mode = m_nb_triggers > 1 ? IntTrigMult : IntTrig;
726
  else if(trig_name == "exts")
727
    m_trig_mode = m_nb_triggers > 1 ? ExtTrigMult : ExtTrigSingle;
728
729
730
731
732
  else if(trig_name == "exte")
    m_trig_mode = ExtGate;
  else
    THROW_HW_ERROR(InvalidValue) << "Unexpected trigger mode: " << DEB_VAR1(trig_name);
  
733
734
  Requests::Param::Value min_frame_time = frame_time_req->get_min();
  m_min_frame_time = min_frame_time.data.double_val;
735
 }
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
/*----------------------------------------------------------------------------
	This method is called when the acquisition is finished
  ----------------------------------------------------------------------------*/
void Camera::_acquisition_finished(bool ok)
{
  DEB_MEMBER_FUNCT();
  DEB_PARAM() << DEB_VAR1(ok);
  
  std::string error_msg;

  //First we will disarm
  if(ok)
    std::shared_ptr<Requests::Command> disarm = 
      m_requests->get_command(Requests::DISARM);

  AutoMutex lock(m_cond.mutex());
  m_trigger_state = ok ? IDLE : ERROR;
  if(!error_msg.empty())
    DEB_ERROR() << error_msg;
}
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770


//-----------------------------------------------------------------------------
/// 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);
}

771
772
773
774
775
776
//-----------------------------------------------------------------------------
/// Returns the temperature of the detector
/*!
@return temperature value
*/
//-----------------------------------------------------------------------------
777
void Camera::getTemperature(double &temp)
778
{
779
780
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_GET_PARAM(Requests::TEMP,temp);
781
782
783
784
785
786
787
788
789
}


//-----------------------------------------------------------------------------
/// Returns the humidity of the detector
/*!
@return humidity value
*/
//-----------------------------------------------------------------------------
790
void Camera::getHumidity(double &humidity)
791
{
792
793
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_GET_PARAM(Requests::HUMIDITY,humidity);
794
795
796
797
798
799
}


//-----------------------------------------------------------------------------
///  Count rate correction setter
//-----------------------------------------------------------------------------
800
void Camera::setCountrateCorrection(bool value) ///< [in] true:enabled, false:disabled
801
{
802
803
    DEB_MEMBER_FUNCT();
    EIGER_SYNC_SET_PARAM(Requests::COUNTRATE_CORRECTION,value);
804
805
806
807
808
809
810
811
}


//-----------------------------------------------------------------------------
///  Count rate correction getter
//-----------------------------------------------------------------------------
void Camera::getCountrateCorrection(bool& value)  ///< [out] true:enabled, false:disabled
{
812
813
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_GET_PARAM(Requests::COUNTRATE_CORRECTION,value);
814
815
816
817
818
819
}


//-----------------------------------------------------------------------------
///  FlatfieldCorrection setter
//-----------------------------------------------------------------------------
820
void Camera::setFlatfieldCorrection(bool value) ///< [in] true:enabled, false:disabled
821
{
822
  DEB_MEMBER_FUNCT();
823
  EIGER_SYNC_SET_PARAM(Requests::FLATFIELD_CORRECTION,value);
824
825
826
827
828
829
830
831
832
833
834
}


//-----------------------------------------------------------------------------
///  FlatfieldCorrection getter
//-----------------------------------------------------------------------------
void Camera::getFlatfieldCorrection(bool& value) ///< [out] true:enabled, false:disabled
{
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_GET_PARAM(Requests::FLATFIELD_CORRECTION,value);
}
835
836

//----------------------------------------------------------------------------
837
// Auto Summation setter
838
839
840
841
842
843
844
845
846
847
848
849
//----------------------------------------------------------------------------
void Camera::setAutoSummation(bool value)
{
  DEB_MEMBER_FUNCT();
  DEB_PARAM() << DEB_VAR1(value);
  EIGER_SYNC_SET_PARAM(Requests::AUTO_SUMMATION,value);

  Size image_size;
  getDetectorImageSize(image_size);
  m_detectorImageType = value ? Bpp32 : Bpp16;
  maxImageSizeChanged(image_size,m_detectorImageType);
}
850
851
852
853

//----------------------------------------------------------------------------
// Auto Summation getter
//----------------------------------------------------------------------------
854
855
856
857
858
859
void Camera::getAutoSummation(bool& value)
{
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_GET_PARAM(Requests::AUTO_SUMMATION,value);
  DEB_RETURN() << DEB_VAR1(value);
}
860
861
862
//-----------------------------------------------------------------------------
///  PixelMask setter
//-----------------------------------------------------------------------------
863
void Camera::setPixelMask(bool value) ///< [in] true:enabled, false:disabled
864
{
865
866
    DEB_MEMBER_FUNCT();
    EIGER_SYNC_SET_PARAM(Requests::PIXEL_MASK,value);
867
868
869
870
871
872
873
874
}


//-----------------------------------------------------------------------------
///  PixelMask getter
//-----------------------------------------------------------------------------
void Camera::getPixelMask(bool& value) ///< [out] true:enabled, false:disabled
{
875
876
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_GET_PARAM(Requests::PIXEL_MASK,value);
877
878
879
880
881
}

//-----------------------------------------------------------------------------
/// EfficiencyCorrection setter
//-----------------------------------------------------------------------------
882
void Camera::setEfficiencyCorrection(bool enabled) ///< [in] true:enabled, false:disabled
883
{
884
    DEB_MEMBER_FUNCT();
885
886
887
888
889
    if (m_api == Eiger1) {
        EIGER_SYNC_SET_PARAM(Requests::EFFICIENCY_CORRECTION,enabled);
    } else {
        DEB_WARNING() << "Efficiency correction is not implemented";
    }
890
891
892
893
894
895
896
897
}


//-----------------------------------------------------------------------------
/// EfficiencyCorrection getter
//-----------------------------------------------------------------------------
void Camera::getEfficiencyCorrection(bool& value)  ///< [out] true:enabled, false:disabled
{
898
  DEB_MEMBER_FUNCT();
899
900
901
902
903
904
  if (m_api == Eiger1) {
    EIGER_SYNC_GET_PARAM(Requests::EFFICIENCY_CORRECTION,value);
  } else {
    DEB_WARNING() << "Efficiency correction is not implemented";
    value = false;
  }
905
906
907
908
909
910
}


//-----------------------------------------------------------------------------
///  ThresholdEnergy setter
//-----------------------------------------------------------------------------
911
void Camera::setThresholdEnergy(double value) ///< [in] true:enabled, false:disabled
912
{
913
914
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_SET_PARAM(Requests::THRESHOLD_ENERGY,value);
915
916
917
918
919
920
921
922
}


//-----------------------------------------------------------------------------
///  ThresholdEnergy getter
//-----------------------------------------------------------------------------
void Camera::getThresholdEnergy(double& value) ///< [out] true:enabled, false:disabled
{
923
924
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_GET_PARAM(Requests::THRESHOLD_ENERGY,value);
925
926
927
928
929
930
}


//-----------------------------------------------------------------------------
///  VirtualPixelCorrection setter
//-----------------------------------------------------------------------------
931
void Camera::setVirtualPixelCorrection(bool value) ///< [in] true:enabled, false:disabled
932
{
933
934
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_SET_PARAM(Requests::VIRTUAL_PIXEL_CORRECTION,value);
935
936
937
938
939
940
941
942
}


//-----------------------------------------------------------------------------
///  VirtualPixelCorrection getter
//-----------------------------------------------------------------------------
void Camera::getVirtualPixelCorrection(bool& value) ///< [out] true:enabled, false:disabled
{
943
944
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_GET_PARAM(Requests::VIRTUAL_PIXEL_CORRECTION,value);
945
946
947
948
949
950
}


//-----------------------------------------------------------------------------
///  PhotonEnergy setter
//-----------------------------------------------------------------------------
951
void Camera::setPhotonEnergy(double value) ///< [in] true:enabled, false:disabled
952
{
953
954
    DEB_MEMBER_FUNCT();
    EIGER_SYNC_SET_PARAM(Requests::PHOTON_ENERGY,value);
955
956
957
958
959
960
961
962
}


//-----------------------------------------------------------------------------
///  PhotonEnergy getter
//-----------------------------------------------------------------------------
void Camera::getPhotonEnergy(double& value) ///< [out] true:enabled, false:disabled
{
963
964
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_GET_PARAM(Requests::PHOTON_ENERGY,value);
965
966
967
968
969
970
971
972
}

//-----------------------------------------------------------------------------
///  Wavelength setter
//-----------------------------------------------------------------------------
void Camera::setWavelength(double value) ///< [in] true:enabled, false:disabled
{
    DEB_MEMBER_FUNCT();
973
    EIGER_SYNC_SET_PARAM(Requests::HEADER_WAVELENGTH,value);
974
975
976
977
978
979
980
981
982
}


//-----------------------------------------------------------------------------
///  Wavelength getter
//-----------------------------------------------------------------------------
void Camera::getWavelength(double& value) ///< [out] true:enabled, false:disabled
{
  DEB_MEMBER_FUNCT();
983
  EIGER_SYNC_GET_PARAM(Requests::HEADER_WAVELENGTH,value);
984
985
986
987
988
989
990
991
992
}


//-----------------------------------------------------------------------------
///  BeamCenterX setter
//-----------------------------------------------------------------------------
void Camera::setBeamCenterX(double value) ///< [in] 
{
    DEB_MEMBER_FUNCT();
993
    EIGER_SYNC_SET_PARAM(Requests::HEADER_BEAM_CENTER_X,value);
994
995
996
997
998
999
1000
}

//-----------------------------------------------------------------------------
///  BeamCenterX getter
//-----------------------------------------------------------------------------
void Camera::getBeamCenterX(double& value) ///< [out] 
{
For faster browsing, not all history is shown. View entire blame