EigerInterface.cpp 6.25 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
//###########################################################################
// 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 "EigerInterface.h"
#include "EigerCamera.h"
#include "EigerDetInfoCtrlObj.h"
#include "EigerSyncCtrlObj.h"
26
#include "EigerEventCtrlObj.h"
27
#include "EigerSavingCtrlObj.h"
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
28
29
#include "EigerStream.h"
#include "EigerDecompress.h"
30
31
32
33
34
35
36
37
38
39
40

using namespace lima;
using namespace lima::Eiger;
using namespace std;


//-----------------------------------------------------
// @brief Ctor
//-----------------------------------------------------
Interface::Interface(Camera& cam) : m_cam(cam) 
{
41
42
43
44
45
46
47
48
49
50
  DEB_CONSTRUCTOR();
  m_det_info = new DetInfoCtrlObj(cam);
  m_cap_list.push_back(HwCap(m_det_info));

  m_sync     = new SyncCtrlObj(cam);
  m_cap_list.push_back(HwCap(m_sync));

  m_saving = new SavingCtrlObj(cam);
  m_cap_list.push_back(HwCap(m_saving));

51
52
53
  m_event = new EventCtrlObj(cam);
  m_cap_list.push_back(HwCap(m_event));

Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
54
55
56
  m_stream = new Stream(cam);
  
  HwBufferCtrlObj* buffer = m_stream->getBufferCtrlObj();
57
  m_cap_list.push_back(HwCap(buffer));	
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
58
59
60

  m_decompress = new Decompress(*m_stream);
  m_cap_list.push_back(HwCap(m_decompress));
61
62
63
64
65
66
67
68
}

//-----------------------------------------------------
// @brief Dtor
//-----------------------------------------------------
Interface::~Interface()
{
    DEB_DESTRUCTOR();
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
69
70
71
72
73
    delete m_det_info;
    delete m_sync;
    delete m_saving;
    delete m_stream;
    delete m_decompress;
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
}

//-----------------------------------------------------
// @brief return the capability list
//-----------------------------------------------------
void Interface::getCapList(HwInterface::CapList &cap_list) const
{
    DEB_MEMBER_FUNCT();
    cap_list = m_cap_list;
}

//-----------------------------------------------------
// @brief reset the interface, stop the acqisition
//-----------------------------------------------------
void Interface::reset(ResetLevel reset_level)
{
    DEB_MEMBER_FUNCT();
    DEB_PARAM() << DEB_VAR1(reset_level);

    stopAcq();
}

//-----------------------------------------------------
// @brief do nothing
//-----------------------------------------------------
void Interface::prepareAcq()
{
    DEB_MEMBER_FUNCT();
102
103
104
105

    if (m_cam.getStatus() == Camera::Armed)
      m_cam.disarm();

106
107
108
109
    bool use_filewriter = m_saving->isActive(); 
    m_stream->setActive(!use_filewriter);
    m_decompress->setActive(!use_filewriter);

110
111
    m_stream->release_all_msgs();

112
113
114
    m_cam.prepareAcq();
    int serie_id; m_cam.getSerieId(serie_id);
    m_saving->setSerieId(serie_id);
115
116
117
118
    if (!use_filewriter) {
      double stream_armed_timeout = 5.0;
      m_stream->waitArmed(stream_armed_timeout);
    }
119
120
121
122
123
124
125
126
}

//-----------------------------------------------------
// @brief start the camera acquisition
//-----------------------------------------------------
void Interface::startAcq()
{
    DEB_MEMBER_FUNCT();
127
128
129
130
131
132
133
134
135
136
137
138
139
140
    // start data retrieval subsystems only in first call
    if (getNbHwAcquiredFrames() == 0) {
      // either we use eiger saving or the raw stream
      if(m_saving->isActive())
	m_saving->start();
      else
	m_stream->start();
    } else {
      TrigMode trig_mode;
      m_cam.getTrigMode(trig_mode);
      if (trig_mode != IntTrigMult)
	DEB_WARNING() << "Unexpected start";
    }

141
142
143
144
145
146
147
148
149
150
    m_cam.startAcq();
}

//-----------------------------------------------------
// @brief stop the camera acquisition
//-----------------------------------------------------
void Interface::stopAcq()
{
  DEB_MEMBER_FUNCT();
  m_cam.stopAcq();
151
  m_saving->stop();
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
152
  m_stream->stop();
153
154
155
156
157
158
159
160
161
}

//-----------------------------------------------------
// @brief return the status of detector/acquisition
//-----------------------------------------------------
void Interface::getStatus(StatusType& status)
{
    DEB_MEMBER_FUNCT();
    
162
163
    Camera::Status Eiger_status;
      
164
165
166
    Eiger_status = m_cam.getStatus();
    switch (Eiger_status)
    {
167
      case Camera::Ready:
168
	{
169
170
171
	  TrigMode trig_mode;
	  m_cam.getTrigMode(trig_mode);
	  if ((trig_mode == IntTrigMult) && !m_cam.allFramesAcquired())
172
173
	    status.set(HwInterface::StatusType::Ready);
	  else if (m_saving->isActive())
174
	    {
175
176
177
178
179
180
181
182
183
184
	      SavingCtrlObj::Status saving_status = m_saving->getStatus();
	      switch(saving_status)
		{
		case SavingCtrlObj::IDLE:
		  status.set(HwInterface::StatusType::Ready);break;
		case SavingCtrlObj::RUNNING:
		  status.set(HwInterface::StatusType::Readout);break;
		default:
		  status.set(HwInterface::StatusType::Fault);break;
		}
185
	    }
186
187
	  else if (m_stream->isRunning())
	    status.set(HwInterface::StatusType::Readout);
188
189
	  else
	    status.set(HwInterface::StatusType::Ready);
190
	}
191
192
193
194
195
196
        break;

      case Camera::Exposure:
        status.set(HwInterface::StatusType::Exposure);
        break;

197
198
      case Camera::Armed:
        status.set(HwInterface::StatusType::Ready);
199
200
201
202
203
204
        break;

      case Camera::Fault:
        status.set(HwInterface::StatusType::Fault);
        break;
        
205
      case Camera::Initializing:
206
207
	status.set(HwInterface::StatusType::Config);
	break;
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
    }
    
    DEB_RETURN() << DEB_VAR1(status);
}

//-----------------------------------------------------
// @brief return the hw number of acquired frames
//-----------------------------------------------------
int Interface::getNbHwAcquiredFrames()
{
     DEB_MEMBER_FUNCT();
     int acq_frames;
     m_cam.getNbHwAcquiredFrames(acq_frames);
     return acq_frames;
}

224
225
226
227
228
229
void Interface::getLastStreamInfo(StreamInfo& last_info)
{
     DEB_MEMBER_FUNCT();
     m_stream->getLastStreamInfo(last_info);
}