EigerCamera.cpp 28.7 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
132
Camera::Camera(const std::string& detector_ip)	///< [in] Ip address of the detector server
  : 		m_image_number(0),
133
                m_latency_time(0.),
134
135
136
137
138
                m_detectorImageType(Bpp16),
		m_initilize_state(IDLE),
		m_trigger_state(IDLE),
		m_serie_id(0),
                m_requests(new Requests(detector_ip)),
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
139
140
                m_exp_time(1.),
		m_detector_ip(detector_ip)
141
142
{
    DEB_CONSTRUCTOR();
143
    DEB_PARAM() << DEB_VAR1(detector_ip);
144
    // Init EigerAPI
145
146
147
148
149
150
151
152
153
154
155
    try
      {
	initialiseController();
      }
    catch(Exception& e)
      {
	DEB_ALWAYS() << "Could not get configuration parameters, try to initialize";
	EIGER_SYNC_CMD_TIMEOUT(Requests::INITIALIZE,5*60);
	initialiseController();
      }
    
156
157
158
159
160
161
162
163
164

    // 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;
165

166
167
168
169
170
171
172
173
174
}


//-----------------------------------------------------------------------------
///  Dtor
//-----------------------------------------------------------------------------
Camera::~Camera()
{
    DEB_DESTRUCTOR();
175
    delete m_requests;
176
177
178
}


179
180
181
182
183
184
185
186
187
188
189
190
191
192
//----------------------------------------------------------------------------
// initialize detector
//----------------------------------------------------------------------------
void Camera::initialize()
{
  // 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);

  std::shared_ptr<CurlLoop::FutureRequest::Callback> cbk(new InitCallback(*this));
  async_initialise->register_callback(cbk);
}
193
194
195
196
197
//-----------------------------------------------------------------------------
/// Set detector for single image acquisition
//-----------------------------------------------------------------------------
void Camera::prepareAcq()
{
198
199
200
201
  DEB_MEMBER_FUNCT();
  AutoMutex aLock(m_cond.mutex());
  if(m_trigger_state != IDLE)
    EIGER_SYNC_CMD(Requests::DISARM);
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
  
  int nb_frames;
  unsigned nb_trigger;
  switch(m_trig_mode)
    {
    case IntTrig:
    case ExtTrigSingle:
      nb_frames = m_nb_frames,nb_trigger = 1;break;
    case IntTrigMult:
    case ExtTrigMult:
    case ExtGate:
      nb_frames = 1,nb_trigger = m_nb_frames;break;
    default:
      THROW_HW_ERROR(Error) << "Very weird can't be in this case";
    }

218
219
220
221
222
223
224
225
226
227
228
  double frame_time = m_exp_time + m_readout_time + m_latency_time;
  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 << ")";
    }
  std::shared_ptr<Requests::Param> frame_time_req=
    m_requests->set_param(Requests::FRAME_TIME,frame_time);
229
230
231
232
233
234
235
  std::shared_ptr<Requests::Param> nimages_req =
    m_requests->set_param(Requests::NIMAGES,nb_frames);
  std::shared_ptr<Requests::Param> ntrigger_req =
    m_requests->set_param(Requests::NTRIGGER,nb_trigger);

  try
    {
236
      frame_time_req->wait();
237
238
239
240
241
242
243
      nimages_req->wait();
      ntrigger_req->wait();
    }
  catch(const eigerapi::EigerException &e)
    {
      HANDLE_EIGERERROR(e.what());
    }
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258

  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);
      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;
259
260
261
262
263
264
265
266
}


//-----------------------------------------------------------------------------
///  start the acquisition
//-----------------------------------------------------------------------------
void Camera::startAcq()
{
267
268
269
270
271
272
273
274
275
276
277
278
279
280
  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);
      std::shared_ptr<CurlLoop::FutureRequest::Callback> cbk(new AcqCallback(*this));
      trigger->register_callback(cbk);
      m_trigger_state = RUNNING;
    }
  
281
282
283
284
285
286
287
288
}


//-----------------------------------------------------------------------------
/// stop the acquisition
//-----------------------------------------------------------------------------
void Camera::stopAcq()
{
289
  DEB_MEMBER_FUNCT();
290
  EIGER_SYNC_CMD(Requests::ABORT);
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
}


//-----------------------------------------------------------------------------
/// 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
{
309
310
311
312
313
314
315
316
317
318
  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);
319
320
321
322
323
324
325
326
}


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

329
    type = m_detectorImageType;    
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
365
366
367
368
369
370
371
372
}


//-----------------------------------------------------------------------------
//! 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
{
373
374
375
376
377
  DEB_MEMBER_FUNCT();
  DEB_PARAM() << DEB_VAR1(trig_mode);
  switch(trig_mode)
    {
    case IntTrig:
378
    case IntTrigMult:
379
380
381
382
383
384
385
    case ExtTrigSingle:
    case ExtTrigMult:
    case ExtGate:
      return true;
    default:
      return false;
    }
386
387
388
389
390
391
}


//-----------------------------------------------------------------------------
/// Set the new trigger mode
//-----------------------------------------------------------------------------
392
void Camera::setTrigMode(TrigMode trig_mode) ///< [in] lima trigger mode to set
393
{
394
395
396
397
398
399
400
  DEB_MEMBER_FUNCT();
  DEB_PARAM() << DEB_VAR1(trig_mode);

  const char *trig_name;
  switch(trig_mode)
    {
    case IntTrig:
401
    case IntTrigMult:
402
403
404
      trig_name = "ints";break;
    case ExtTrigSingle:
    case ExtTrigMult:
405
      trig_name = "exts";break;
406
407
408
409
410
411
412
413
    case ExtGate:
      trig_name = "exte";break;
    default:
      THROW_HW_ERROR(NotSupported) << DEB_VAR1(trig_mode);
    }
  
  EIGER_SYNC_SET_PARAM(Requests::TRIGGER_MODE,trig_name);
  m_trig_mode = trig_mode;
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
}


//-----------------------------------------------------------------------------
/// 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
//-----------------------------------------------------------------------------
void Camera::setExpTime(double exp_time) ///< [in] exposure time to set
{
434
435
436
437
438
  DEB_MEMBER_FUNCT();
  DEB_PARAM() << DEB_VAR1(exp_time);

  EIGER_SYNC_SET_PARAM(Requests::EXPOSURE,exp_time);
  m_exp_time = exp_time;
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
}


//-----------------------------------------------------------------------------
/// 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
{
460
461
462
463
464
  DEB_MEMBER_FUNCT();
  DEB_PARAM() << DEB_VAR1(lat_time);

  m_latency_time = lat_time;
  setExpTime(m_exp_time);
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
}


//-----------------------------------------------------------------------------
/// 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();
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
  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();
  Requests::Param::Value max_val = exp_time->get_max();
  
  min_expo = min_val.data.double_val;
  max_expo = max_val.data.double_val;
506
507
508
509
510
511
512
513
514
515
516
517
518
519
  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
520
521
522
523
  min_lat = m_readout_time;
  double min_exp,max_exp;
  getExposureTimeRange(min_exp,max_exp);
  max_lat = max_exp;
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541

  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.");
    }

542
    m_nb_frames = nb_frames;
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
}


//-----------------------------------------------------------------------------
/// 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
{
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
  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;
}
//----------------------------------------------------------------------------
// Get camera hardware status
//----------------------------------------------------------------------------
std::string Camera::getCamStatus()
{
  DEB_MEMBER_FUNCT();
  std::string status;
  EIGER_SYNC_GET_PARAM(Requests::DETECTOR_STATUS,status);
  return status;
}
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
637
//-----------------------------------------------------------------------------
/// 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;
}
*/

//-----------------------------------------------------------------------------
638
///    initialise controller
639
640
641
//-----------------------------------------------------------------------------
void Camera::initialiseController()
{
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
  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));

  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));
  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));
660
661
662
  
  unsigned nb_trigger;
  synchro_list.push_back(m_requests->get_param(Requests::NTRIGGER,nb_trigger));
663

664
665
666
  std::shared_ptr<Requests::Param> frame_time_req = m_requests->get_param(Requests::FRAME_TIME);
  synchro_list.push_back(frame_time_req);
  
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
  //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());
    }

683
  m_detectorImageType = Bpp32;
684
685
686

  //Trigger mode
  if(trig_name == "ints")
687
    m_trig_mode = nb_trigger > 1 ? IntTrigMult : IntTrig;
688
  else if(trig_name == "exts")
689
    m_trig_mode = nb_trigger > 1 ? ExtTrigMult : ExtTrigSingle;
690
691
692
693
694
  else if(trig_name == "exte")
    m_trig_mode = ExtGate;
  else
    THROW_HW_ERROR(InvalidValue) << "Unexpected trigger mode: " << DEB_VAR1(trig_name);
  
695
696
  Requests::Param::Value min_frame_time = frame_time_req->get_min();
  m_min_frame_time = min_frame_time.data.double_val;
697
 }
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
/*----------------------------------------------------------------------------
	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;
}
718
719
720
721
722
723
//-----------------------------------------------------------------------------
/// Returns the temperature of the detector
/*!
@return temperature value
*/
//-----------------------------------------------------------------------------
724
void Camera::getTemperature(double &temp)
725
{
726
727
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_GET_PARAM(Requests::TEMP,temp);
728
729
730
731
732
733
734
735
736
}


//-----------------------------------------------------------------------------
/// Returns the humidity of the detector
/*!
@return humidity value
*/
//-----------------------------------------------------------------------------
737
void Camera::getHumidity(double &humidity)
738
{
739
740
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_GET_PARAM(Requests::HUMIDITY,humidity);
741
742
743
744
745
746
}


//-----------------------------------------------------------------------------
///  Count rate correction setter
//-----------------------------------------------------------------------------
747
void Camera::setCountrateCorrection(bool value) ///< [in] true:enabled, false:disabled
748
{
749
750
    DEB_MEMBER_FUNCT();
    EIGER_SYNC_SET_PARAM(Requests::COUNTRATE_CORRECTION,value);
751
752
753
754
755
756
757
758
}


//-----------------------------------------------------------------------------
///  Count rate correction getter
//-----------------------------------------------------------------------------
void Camera::getCountrateCorrection(bool& value)  ///< [out] true:enabled, false:disabled
{
759
760
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_GET_PARAM(Requests::COUNTRATE_CORRECTION,value);
761
762
763
764
765
766
}


//-----------------------------------------------------------------------------
///  FlatfieldCorrection setter
//-----------------------------------------------------------------------------
767
void Camera::setFlatfieldCorrection(bool value) ///< [in] true:enabled, false:disabled
768
{
769
770
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_SET_PARAM(Requests::COUNTRATE_CORRECTION,value);
771
772
773
774
775
776
777
778
}


//-----------------------------------------------------------------------------
///  FlatfieldCorrection getter
//-----------------------------------------------------------------------------
void Camera::getFlatfieldCorrection(bool& value) ///< [out] true:enabled, false:disabled
{
779
780
    DEB_MEMBER_FUNCT();
    EIGER_SYNC_GET_PARAM(Requests::COUNTRATE_CORRECTION,value);
781
782
783
784
785
786
}


//-----------------------------------------------------------------------------
///  PixelMask setter
//-----------------------------------------------------------------------------
787
void Camera::setPixelMask(bool value) ///< [in] true:enabled, false:disabled
788
{
789
790
    DEB_MEMBER_FUNCT();
    EIGER_SYNC_SET_PARAM(Requests::PIXEL_MASK,value);
791
792
793
794
795
796
797
798
}


//-----------------------------------------------------------------------------
///  PixelMask getter
//-----------------------------------------------------------------------------
void Camera::getPixelMask(bool& value) ///< [out] true:enabled, false:disabled
{
799
800
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_GET_PARAM(Requests::PIXEL_MASK,value);
801
802
803
804
805
}

//-----------------------------------------------------------------------------
/// EfficiencyCorrection setter
//-----------------------------------------------------------------------------
806
void Camera::setEfficiencyCorrection(bool enabled) ///< [in] true:enabled, false:disabled
807
{
808
809
    DEB_MEMBER_FUNCT();
    EIGER_SYNC_SET_PARAM(Requests::EFFICIENCY_CORRECTION,enabled);
810
811
812
813
814
815
816
817
}


//-----------------------------------------------------------------------------
/// EfficiencyCorrection getter
//-----------------------------------------------------------------------------
void Camera::getEfficiencyCorrection(bool& value)  ///< [out] true:enabled, false:disabled
{
818
819
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_GET_PARAM(Requests::EFFICIENCY_CORRECTION,value);
820
821
822
823
824
825
}


//-----------------------------------------------------------------------------
///  ThresholdEnergy setter
//-----------------------------------------------------------------------------
826
void Camera::setThresholdEnergy(double value) ///< [in] true:enabled, false:disabled
827
{
828
829
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_SET_PARAM(Requests::THRESHOLD_ENERGY,value);
830
831
832
833
834
835
836
837
}


//-----------------------------------------------------------------------------
///  ThresholdEnergy getter
//-----------------------------------------------------------------------------
void Camera::getThresholdEnergy(double& value) ///< [out] true:enabled, false:disabled
{
838
839
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_GET_PARAM(Requests::THRESHOLD_ENERGY,value);
840
841
842
843
844
845
}


//-----------------------------------------------------------------------------
///  VirtualPixelCorrection setter
//-----------------------------------------------------------------------------
846
void Camera::setVirtualPixelCorrection(bool value) ///< [in] true:enabled, false:disabled
847
{
848
849
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_SET_PARAM(Requests::VIRTUAL_PIXEL_CORRECTION,value);
850
851
852
853
854
855
856
857
}


//-----------------------------------------------------------------------------
///  VirtualPixelCorrection getter
//-----------------------------------------------------------------------------
void Camera::getVirtualPixelCorrection(bool& value) ///< [out] true:enabled, false:disabled
{
858
859
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_GET_PARAM(Requests::VIRTUAL_PIXEL_CORRECTION,value);
860
861
862
863
864
865
}


//-----------------------------------------------------------------------------
///  PhotonEnergy setter
//-----------------------------------------------------------------------------
866
void Camera::setPhotonEnergy(double value) ///< [in] true:enabled, false:disabled
867
{
868
869
    DEB_MEMBER_FUNCT();
    EIGER_SYNC_SET_PARAM(Requests::PHOTON_ENERGY,value);
870
871
872
873
874
875
876
877
}


//-----------------------------------------------------------------------------
///  PhotonEnergy getter
//-----------------------------------------------------------------------------
void Camera::getPhotonEnergy(double& value) ///< [out] true:enabled, false:disabled
{
878
879
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_GET_PARAM(Requests::PHOTON_ENERGY,value);
880
881
}

882

Arafat Noureddine's avatar
Arafat Noureddine committed
883
884
885
886
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void Camera::getCompression(bool& value) ///< [out] true:enabled, false:disabled
{
887
888
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_GET_PARAM(Requests::FILEWRITER_COMPRESSION,value);
Arafat Noureddine's avatar
Arafat Noureddine committed
889
890
891
892
893
}


//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
894
void Camera::setCompression(bool value)
Arafat Noureddine's avatar
Arafat Noureddine committed
895
{
896
897
  DEB_MEMBER_FUNCT();
  EIGER_SYNC_SET_PARAM(Requests::FILEWRITER_COMPRESSION,value);
Arafat Noureddine's avatar
Arafat Noureddine committed
898
}
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928

void Camera::getSerieId(int& serie_id)
{
  DEB_MEMBER_FUNCT();
  serie_id = m_serie_id;
  DEB_RETURN() << DEB_VAR1(serie_id);
}

void Camera::deleteMemoryFiles()
{
  DEB_MEMBER_FUNCT();
  std::shared_ptr<Requests::Param> files_req = 
    m_requests->get_param(Requests::FILEWRITER_LS);
  Requests::Param::Value value;
 try
  {
    value = files_req->get();
  }
 catch(const eigerapi::EigerException &e)
   {
     HANDLE_EIGERERROR(e.what());
   }

 for(std::vector<std::string>::iterator i = value.string_array.begin();
     i != value.string_array.end();++i)
   {
     DEB_TRACE() << "delete file: " << *i;
     m_requests->delete_file(*i);
   }
}
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
929
930
931
932
933

const std::string& Camera::getDetectorIp() const
{
  return m_detector_ip;
}