DPPAcquisitionController.cpp 14.7 KB
Newer Older
Paolo Mutti's avatar
Paolo Mutti committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
 * Nomad Instrument Control Software
 *
 * Copyright 2011 Institut Laue-Langevin
 *
 * Licensed under the EUPL, Version 1.1 only (the "License");
 * You may not use this work except in compliance with the Licence.
 * You may obtain a copy of the Licence at:
 *
 * http://joinup.ec.europa.eu/software/page/eupl
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the Licence is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Licence for the specific language governing permissions and
 * limitations under the Licence.
 */

#include "DPPAcquisitionController.h"
Paolo Mutti's avatar
Paolo Mutti committed
20
#include "controllers/common/family/Families.h"
21
#include <lstdpp128/lstdpp.h>
Paolo Mutti's avatar
Paolo Mutti committed
22
23
24

using namespace std;
using namespace acquisition;
25
using namespace lstdpp128;
Paolo Mutti's avatar
Paolo Mutti committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

namespace npp {

const string DPPAcquisitionController::TYPE = "dppacquisition_setup";

const string DPPAcquisitionController::NO_LIVE_PROCESS = "none";
const string DPPAcquisitionController::HISTOGRAM_PROCESS = "histogram";
const string DPPAcquisitionController::COINCIDENCE_PROCESS = "coincidence";

/*
 * Constructor
 */
DPPAcquisitionController::DPPAcquisitionController(const string& name) :
		TimeAcquisitionController(name) {

Paolo Mutti's avatar
Paolo Mutti committed
41
42
	setFamily(family::ACQUISITION, family::SETTING);

Paolo Mutti's avatar
Paolo Mutti committed
43
44
45
46
	nbAdcControllers.init(this, SAVE, "nb_adc_controllers");
	nbBits.init(this, SAVE, "nb_bits");
	gateWidth.init(this, SAVE, "gate_width");
	scopeChannel.init(this, NOSAVE, "scope_channel");
Paolo Mutti's avatar
Paolo Mutti committed
47
	useWaveForm.init(this, NOSAVE, "waveform_mode");
Paolo Mutti's avatar
Paolo Mutti committed
48
	useScope.init(this, NOSAVE, "scope_mode");
Paolo Mutti's avatar
Paolo Mutti committed
49
	totalChannels.init(this, NOSAVE, "total_channels");
Paolo Mutti's avatar
Paolo Mutti committed
50
51
52
53
54
55
56
57
58
59
60
	useScopeStr.init(this, NOSAVE, "scope_mode_str");
	usePn1Coincidence.init(this, SAVE, "pn1_coincidence");
	liveProcessType.init(this, SAVE, "live_process_type");

	boardIndex.init(this, NOSAVE, "board_index");
	channelsPerBoard.init(this, NOSAVE, "channels_per_board");

	m_AcquisitionMode = AcquisitionCommon::PULSE_PROCESSING_MODE;

	registerFunction(TYPE);

61
62
	m_histogramController.init(this, "histogram_controller");
	m_coincidenceController.init(this, "coincidence_controller");
Paolo Mutti's avatar
Paolo Mutti committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

	registerRefresher(nbAdcControllers, &DPPAcquisitionController::refreshNbAdcControllersProperty, this);
}

/*
 * Destructor
 */
DPPAcquisitionController::~DPPAcquisitionController() {

}

/*
 * postConfiguration
 */
void DPPAcquisitionController::postConfiguration() {

	TimeAcquisitionController::postConfiguration();

	// Copy local ptr for setting the write type cast
82
	dppDriver.resize(m_nRegisteredDrivers);
Paolo Mutti's avatar
Paolo Mutti committed
83
	for (int32 i = 0; i < m_nRegisteredDrivers; ++i) {
84
85
86
87
88
89
		dppDriver[i].copy(m_Drivers[i]);
		registerUpdater(dppDriver[i]->curve0, &DPPAcquisitionController::updateCurve0ArrayProperty, this, i);
		registerUpdater(dppDriver[i]->curve1, &DPPAcquisitionController::updateCurve1ArrayProperty, this, i);
		registerUpdater(dppDriver[i]->curve2, &DPPAcquisitionController::updateCurve2ArrayProperty, this, i);
		registerUpdater(dppDriver[i]->curve3, &DPPAcquisitionController::updateCurve3ArrayProperty, this, i);
		registerUpdater(dppDriver[i]->curve4, &DPPAcquisitionController::updateCurve4ArrayProperty, this, i);
Paolo Mutti's avatar
Paolo Mutti committed
90
91
92
93
94
95
	}

	registerRefresher(usePn1Coincidence, &DPPAcquisitionController::refreshUsePn1CoincidenceModeProperty, this);
	registerRefresher(nbBits, &DPPAcquisitionController::refreshNbBitsProperty, this);

	for (int32 i = 0; i < nbAdcControllers(); ++i) {
Paolo Mutti's avatar
Paolo Mutti committed
96
97
		registerUpdater(adcController[i]->dppAcqMode, &DPPAcquisitionController::updateAcqModeProperty, this, i);
		registerUpdater(adcController[i]->displayChannel, &DPPAcquisitionController::updateAcqModeProperty, this, i);
98
99
		registerUpdater(adcController[i]->channels, &DPPAcquisitionController::setChannelsPerBoard, this);
		registerUpdater(adcController[i]->recordLength, &DPPAcquisitionController::updateRecordLengthProperty, this, i);
Paolo Mutti's avatar
Paolo Mutti committed
100
101
102
103
	}

	setChannelsPerBoard();
	setScopeMode();
104
	setCrateNumber();
105
106

	registerRefresher(liveProcessType, &DPPAcquisitionController::refreshLiveProcessTypeProperty, this);
Paolo Mutti's avatar
Paolo Mutti committed
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
}

/*
 * refreshNDriversProperty
 */
void DPPAcquisitionController::refreshNDriversProperty(int32 aValue) throw (CannotSetValue) {

	boardIndex.resize(aValue);
	channelsPerBoard.resize(aValue);

	TimeAcquisitionController::refreshNDriversProperty(aValue);
}

/*
 * refreshNbAdcControllersProperty
 */
void DPPAcquisitionController::refreshNbAdcControllersProperty(int32 aValue) throw (CannotSetValue) {

	if (aValue == nbAdcControllers()) {
		return;
	}
128
	adcController.resize(aValue);
Paolo Mutti's avatar
Paolo Mutti committed
129
130
131

	for (int32 i = 0; i < aValue; ++i) {
		string controllerName = "adc_controller" + lexical_cast<string>(i + 1);
132
		adcController[i].init(this, controllerName);
Paolo Mutti's avatar
Paolo Mutti committed
133
134
135
136
137
	}

}

/*
138
139
140
 * updateRecordLengthProperty
 */
void DPPAcquisitionController::updateRecordLengthProperty(int32 index) {
141
	int32 rencordlength = adcController[index]->recordLength();
142
	for (int32 i = 0; i < m_nRegisteredDrivers; ++i) {
143
		dppDriver[i]->recordLength = rencordlength;
144
145
146
147
148
	}
}

/*
 * updateCurve0ArrayProperty
Paolo Mutti's avatar
Paolo Mutti committed
149
 */
150
void DPPAcquisitionController::updateCurve0ArrayProperty(int32 index) {
Paolo Mutti's avatar
Paolo Mutti committed
151
152

	for (int32 adc = 0; adc < nbAdcControllers(); ++adc) {
153
154
155
		adcController[adc]->curve0.update(dppDriver[index]->curve0());
		adcController[adc]->curve0.setSize(dppDriver[index]->curve0.getSize());
		adcController[adc]->curve0.sendEvent();
156
157
158
159
160
161
162
163
164
	}
}

/*
 * updateCurve1ArrayProperty
 */
void DPPAcquisitionController::updateCurve1ArrayProperty(int32 index) {

	for (int32 adc = 0; adc < nbAdcControllers(); ++adc) {
165
166
167
		adcController[adc]->curve1.update(dppDriver[index]->curve1());
		adcController[adc]->curve1.setSize(dppDriver[index]->curve1.getSize());
		adcController[adc]->curve1.sendEvent();
168
169
170
171
172
173
174
175
176
	}
}

/*
 * updateCurve2ArrayProperty
 */
void DPPAcquisitionController::updateCurve2ArrayProperty(int32 index) {

	for (int32 adc = 0; adc < nbAdcControllers(); ++adc) {
177
178
179
		adcController[adc]->curve2.update(dppDriver[index]->curve2());
		adcController[adc]->curve2.setSize(dppDriver[index]->curve2.getSize());
		adcController[adc]->curve2.sendEvent();
180
181
182
183
184
185
186
187
188
	}
}

/*
 * updateCurve3ArrayProperty
 */
void DPPAcquisitionController::updateCurve3ArrayProperty(int32 index) {

	for (int32 adc = 0; adc < nbAdcControllers(); ++adc) {
189
190
191
		adcController[adc]->curve3.update(dppDriver[index]->curve3());
		adcController[adc]->curve3.setSize(dppDriver[index]->curve3.getSize());
		adcController[adc]->curve3.sendEvent();
192
193
194
195
196
197
198
199
200
	}
}

/*
 * updateCurve4ArrayProperty
 */
void DPPAcquisitionController::updateCurve4ArrayProperty(int32 index) {

	for (int32 adc = 0; adc < nbAdcControllers(); ++adc) {
201
202
203
		adcController[adc]->curve4.update(dppDriver[index]->curve4());
		adcController[adc]->curve4.setSize(dppDriver[index]->curve4.getSize());
		adcController[adc]->curve4.sendEvent();
Paolo Mutti's avatar
Paolo Mutti committed
204
205
206
207
	}
}

/*
Paolo Mutti's avatar
Paolo Mutti committed
208
 * updateUseScopeProperty
Paolo Mutti's avatar
Paolo Mutti committed
209
 */
Paolo Mutti's avatar
Paolo Mutti committed
210
void DPPAcquisitionController::updateAcqModeProperty(int32 index) {
Paolo Mutti's avatar
Paolo Mutti committed
211
212

	int32 boardChannel = 0;
213
	int32 aValue = adcController[index]->dppAcqMode();
Paolo Mutti's avatar
Paolo Mutti committed
214

215
	if (aValue == acquisition::DPPAcquisitionCommon::SCOPE_MODE) {
Paolo Mutti's avatar
Paolo Mutti committed
216
217
		for (int32 i=0; i<nbAdcControllers(); ++i) {
			if (i != index) {
218
				adcController[i]->dppAcqMode = acquisition::DPPAcquisitionCommon::LISTMODE_MODE;
Paolo Mutti's avatar
Paolo Mutti committed
219
220
			}
		}
Paolo Mutti's avatar
Paolo Mutti committed
221
		adcController[index]->dppAcqMode = acquisition::DPPAcquisitionCommon::SCOPE_MODE;
Paolo Mutti's avatar
Paolo Mutti committed
222
223
224
		useScope = 1;
		useScopeStr = "Active";
		for (int32 i=0; i<index; ++i) {
225
			boardChannel += adcController[i]->channels();
Paolo Mutti's avatar
Paolo Mutti committed
226
		}
227
		boardChannel += adcController[index]->displayChannel();
Paolo Mutti's avatar
Paolo Mutti committed
228
229
		useListMode = 0;
		usePn1Coincidence = 0;
Paolo Mutti's avatar
Paolo Mutti committed
230
	} else if (aValue == acquisition::DPPAcquisitionCommon::LISTMODE_MODE) {
Paolo Mutti's avatar
Paolo Mutti committed
231
232
233
234
		useScope = 0;
		useScopeStr = "Inactive";
	}

Paolo Mutti's avatar
Paolo Mutti committed
235
	scopeChannel = boardChannel;
236
237
238
239
240
	int32 board = adcController[index]->acqBoardIndex();
	dppDriver[board]->useScope = useScope();
	dppDriver[board]->scopeChannel = boardChannel;
	dppDriver[board]->scopeCardActivated = adcController[index]->modelName();
	dppDriver[board]->recordLength =  adcController[index]->recordLength();
Paolo Mutti's avatar
Paolo Mutti committed
241
	dppDriver[board]->useListMode = (useListMode() == true ? 1 : 0);
242
	dppDriver[board]->usePn1Coincidence = usePn1Coincidence();
Paolo Mutti's avatar
Paolo Mutti committed
243
244
245
246
247
}

/*
 * refreshUseListModeProperty
 */
Paolo Mutti's avatar
Paolo Mutti committed
248
void DPPAcquisitionController::refreshUseListModeProperty(bool aValue) throw (CannotSetValue) {
Paolo Mutti's avatar
Paolo Mutti committed
249
250

	for (int32 board=0; board<nDrivers(); ++board) {
Paolo Mutti's avatar
Paolo Mutti committed
251
		dppDriver[board]->useListMode = (aValue == true ? 1 : 0);
Paolo Mutti's avatar
Paolo Mutti committed
252
253
	}

Paolo Mutti's avatar
Paolo Mutti committed
254
	if (aValue == true) {
Paolo Mutti's avatar
Paolo Mutti committed
255
		for (int32 adc = 0; adc < nbAdcControllers(); ++adc) {
256
			adcController[adc]->dppAcqMode = acquisition::DPPAcquisitionCommon::LISTMODE_MODE;
Paolo Mutti's avatar
Paolo Mutti committed
257
258
259
260
261
262
263
264
265
266
		}
	}
}

/*
 * refreshUseListModeProperty
 */
void DPPAcquisitionController::refreshUsePn1CoincidenceModeProperty(int32 aValue) throw (CannotSetValue) {

	for (int32 board=0; board<nDrivers(); ++board) {
267
268
		dppDriver[board]->usePn1Coincidence = aValue;
		dppDriver[board]->gateWidth = gateWidth();
Paolo Mutti's avatar
Paolo Mutti committed
269
270
	}

Paolo Mutti's avatar
Paolo Mutti committed
271
	adcController[0]->enableCoincidence = aValue;
Paolo Mutti's avatar
Paolo Mutti committed
272
	if (aValue == 1) {
Paolo Mutti's avatar
Paolo Mutti committed
273
274
		adcController[0]->coincidenceWindow = gateWidth();
		adcController[0]->coincidenceMask = 0x103;
Paolo Mutti's avatar
Paolo Mutti committed
275
		for (int32 adc = 0; adc < nbAdcControllers(); ++adc) {
276
			adcController[adc]->dppAcqMode = acquisition::DPPAcquisitionCommon::LISTMODE_MODE;
Paolo Mutti's avatar
Paolo Mutti committed
277
278
279
280
281
282
283
284
285
286
		}
	}
}

/*
 * refreshNbBitsProperty
 */
void DPPAcquisitionController::refreshNbBitsProperty(int32 aValue) throw (CannotSetValue) {

	for (int32 i = 0; i < m_nRegisteredDrivers; ++i) {
287
		dppDriver[i]->nbBits = aValue;
Paolo Mutti's avatar
Paolo Mutti committed
288
289
290
291
292
293
294
295
	}
}

/*
 * refreshLiveProcessTypeProperty
 */
void DPPAcquisitionController::refreshLiveProcessTypeProperty(const std::string& aValue) throw (CannotSetValue) {

296
297
	m_histogramController->raz();
	m_coincidenceController->raz();
Paolo Mutti's avatar
Paolo Mutti committed
298

299
300
301
302
303
304
	if (aValue == HISTOGRAM_PROCESS) {
		m_liveProcessController = m_histogramController;
	} else if (aValue == COINCIDENCE_PROCESS) {
		m_liveProcessController = m_coincidenceController;
	} else {
		m_liveProcessController.assign(0);
Paolo Mutti's avatar
Paolo Mutti committed
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
	}
}

/*
 * resize
 */
void DPPAcquisitionController::resize() throw (CannotOpenFile, SlicesFileError, TooManySlices, SliceTooBig) {

	int32 resolution = (int32) pow(2.0, nbBits());
	m_Detector->setDataSize(resolution, 1);
}

/*
 * writeParams
 */
void DPPAcquisitionController::writeParams() {

	int32 totalAdc = 0;
	for (int32 i = 0; i < nDrivers(); ++i) {
		totalAdc += channelsPerBoard.get(i);
	}
Paolo Mutti's avatar
Paolo Mutti committed
326
	totalChannels = totalAdc;
Paolo Mutti's avatar
Paolo Mutti committed
327
328

	log(Level::s_Debug) << name << cursor << "Sending DPP parameters to acquisition card : listmode " << useListMode()
Paolo Mutti's avatar
Paolo Mutti committed
329
			<< " , wanted adc " << totalChannels() << " , wanted resolution " << nbBits() << endlog;
Paolo Mutti's avatar
Paolo Mutti committed
330
331
332

	Parallel::begin();
	for (int32 adc = 0; adc < nbAdcControllers(); ++adc) {
333
		adcController[adc]->clearDataParallel();
Paolo Mutti's avatar
Paolo Mutti committed
334
335
336
337
338
339
340
	}
	Parallel::end();

	if (isModeChanged() == true) {

		Parallel::begin();
		for (int32 i = 0; i < nDrivers(); ++i) {
341
342
343
344
345
346
			dppDriver[i]->wantedMode = m_AcquisitionMode;
			dppDriver[i]->nbBits = nbBits();
			dppDriver[i]->nbChannels = channelsPerBoard.get(i);
			dppDriver[i]->scopeChannel = scopeChannel();
			dppDriver[i]->gateWidth = gateWidth();
			dppDriver[i]->usePn1Coincidence = usePn1Coincidence();
Paolo Mutti's avatar
Paolo Mutti committed
347
			dppDriver[i]->useListMode = (useListMode() == true ? 1 : 0);
348
			dppDriver[i]->useScope = useScope();
Paolo Mutti's avatar
Paolo Mutti committed
349
350
351
352

			/*
			 * Execute the write param command
			 */
353
			dppDriver[i].executeParallel(AcquisitionCommon::WRITE_PARAMETERS_COMMAND);
Paolo Mutti's avatar
Paolo Mutti committed
354
355
356
357
358
359
360
		}
		Parallel::end();

		/*
		 * Execute the write param command
		 */
		for (int32 i = 0; i < nDrivers(); ++i) {
361
			dppDriver[i].execute(AcquisitionCommon::LIST_MODE_COMMAND, false, true);
Paolo Mutti's avatar
Paolo Mutti committed
362
363
		}

364
365
		// starting DPPCoincidence
		if (useListMode() && m_liveProcessController.isAssigned()) {
Paolo Mutti's avatar
Paolo Mutti committed
366

367
368
369
			// set the lst context
			setContext();

370
371
			// start the process in parallel to avoid blocking
			m_liveProcessController->startParallel();
Paolo Mutti's avatar
Paolo Mutti committed
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388

			if (checkStatus() == true) {
				log(Level::s_Debug) << name << emptycursor << "DPP parameters accepted by acquisition card(s): " << totalAdc
						<< " x " << nbBits() << endlog;
			}
		}
	}
}

/*
 * stop
 */
void DPPAcquisitionController::stop() {

	TimeAcquisitionController::stop();

	// stopping DPPCoincidence
389
390
	if (m_liveProcessController.isAssigned()) {
		m_liveProcessController->stopCommand();
Paolo Mutti's avatar
Paolo Mutti committed
391
392
393
394
395
396
397
398
399
400
401
402
403
	}
}

/*
 * useEnergy
 */
bool DPPAcquisitionController::useEnergy() const {
	return true;
}

void DPPAcquisitionController::setScopeMode() {

	int32 scope = 0;
Paolo Mutti's avatar
Paolo Mutti committed
404
405
	int32 boardChannel = 0;
	int32 index = 0;
Paolo Mutti's avatar
Paolo Mutti committed
406
407
	for (int32 board=0; board<nDrivers(); ++board) {
		for (int32 adc = 0; adc < nbAdcControllers(); ++adc) {
408
			if (adcController[adc]->dppAcqMode() == acquisition::DPPAcquisitionCommon::SCOPE_MODE) {
Paolo Mutti's avatar
Paolo Mutti committed
409
				index = adc;
Paolo Mutti's avatar
Paolo Mutti committed
410
411
412
413
414
415
				scope = 1;
				useScopeStr = "Active";
			} else {
				useScopeStr = "Inactive";
			}
		}
Paolo Mutti's avatar
Paolo Mutti committed
416
417
		if (scope == 1) {
			for (int32 i=0; i<index; ++i) {
418
				boardChannel += adcController[i]->channels();
Paolo Mutti's avatar
Paolo Mutti committed
419
			}
420
			boardChannel += adcController[index]->displayChannel();
Paolo Mutti's avatar
Paolo Mutti committed
421
422
			scopeChannel = boardChannel;
		}
423
424
425
426
427
428
		dppDriver[board]->useScope = scope;
		dppDriver[board]->scopeChannel = boardChannel;
		dppDriver[board]->scopeCardActivated = adcController[index]->modelName();
		dppDriver[board]->recordLength =  adcController[index]->recordLength();
		dppDriver[board]->useListMode = useListMode();
		dppDriver[board]->usePn1Coincidence = usePn1Coincidence();
Paolo Mutti's avatar
Paolo Mutti committed
429
430
431
432
433
434
435
436
437
	}
	useScope = scope;
}

void DPPAcquisitionController::setChannelsPerBoard() {

	for (int32 board=0; board<nDrivers(); ++board) {
		int32 totalChannels = 0;
		for (int32 adc = 0; adc < nbAdcControllers(); ++adc) {
438
439
			if (adcController[adc]->acqBoardIndex() == board) {
				totalChannels += adcController[adc]->channels();
Paolo Mutti's avatar
Paolo Mutti committed
440
441
442
443
			}
		}
		boardIndex.set(board, board);
		channelsPerBoard.set(board, totalChannels);
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
		dppDriver[board]->nbChannels = totalChannels;
	}
}

void DPPAcquisitionController::setCrateNumber() {
	for (int32 board=0; board<nDrivers(); ++board) {
		for (int32 adc = 0; adc < nbAdcControllers(); ++adc) {
			if (adcController[adc]->acqBoardIndex() == board) {
				adcController[adc]->crateNumber = dppDriver[board]->crateNumber();
			}
		}
	}
}

/**
 * Warning: we suppose that the list mode block is ordered like the ADC controllers
 */
void DPPAcquisitionController::setContext() {

	releaseListModeContext(listModeContext);

	int32 nbCrates = 0;

	for (int32 adc = 0; adc < nbAdcControllers(); ++adc) {
		int32 crate = adcController[adc]->crateNumber();
		if (crate >= nbCrates) {
			nbCrates = crate + 1;
		}
	}

	listModeContext.crateBoard.nbCrates = nbCrates;
	listModeContext.crateBoard.crates = new Crate[nbCrates];

	for (int32 crate = 0; crate < nbCrates; ++crate) {
		int32 nbBoards = 0;

		for (int32 board = 0; board < nbAdcControllers(); ++board) {
			if (board >= nbBoards) {
				nbBoards = board + 1;
			}
		}

		listModeContext.crateBoard.crates[crate].nbBoards = nbBoards;
		listModeContext.crateBoard.crates[crate].boards = new Board[nbBoards];

		for (int32 board = 0; board < nbAdcControllers(); ++board) {
			listModeContext.crateBoard.crates[0].boards[board].boardType = (BoardType)adcController[board]->cardType();
			listModeContext.crateBoard.crates[0].boards[board].crate = crate;
			listModeContext.crateBoard.crates[0].boards[board].eventType = 0;
			listModeContext.crateBoard.crates[0].boards[board].nbChannels = adcController[board]->nbChannels();
		}
Paolo Mutti's avatar
Paolo Mutti committed
495
	}
496

Paolo Mutti's avatar
Paolo Mutti committed
497
498
//	cout << "context before live process" << endl;
//	cout << listModeContext << endl;
Paolo Mutti's avatar
Paolo Mutti committed
499
500
501
}

}