Commit 20ac8cf7 authored by yannick legoc's avatar yannick legoc
Browse files

Implemented LISTMODE_S data block without the need to specify the list of board controllers.

Corrected remote DPP controllers to read live data from the lst file.
parent 0eb96c72
......@@ -17,6 +17,9 @@
*/
#include "DPPAcquisitionController.h"
#include "ListModeBlock.h"
#include "controllers/common/datafile/AsciiDataFileManager.h"
#include "controllers/common/datafile/AsciiDataFile.h"
#include "controllers/common/family/Families.h"
#include <lstdpp128/lstdpp.h>
......@@ -32,6 +35,8 @@ const string DPPAcquisitionController::NO_LIVE_PROCESS = "none";
const string DPPAcquisitionController::HISTOGRAM_PROCESS = "histogram";
const string DPPAcquisitionController::COINCIDENCE_PROCESS = "coincidence";
DataBlock* decodeListModeBlock(AsciiDataFileManager* dataFileManager, AsciiDataFile* dataFile, string blockType, typename boost::tokenizer<boost::char_separator<char> >::iterator iter, typename boost::tokenizer<boost::char_separator<char> >::iterator end);
/*
* Constructor
*/
......@@ -62,6 +67,8 @@ DPPAcquisitionController::DPPAcquisitionController(const string& name) :
m_coincidenceController.init(this, "coincidence_controller");
registerRefresher(nbAdcControllers, &DPPAcquisitionController::refreshNbAdcControllersProperty, this);
dynamic_cast<AsciiDataFileManager *>(DataFileManager::getAsciiInstance())->addDataBlockFunction("LISTMODE_S", &decodeListModeBlock);
}
/*
......@@ -104,6 +111,45 @@ void DPPAcquisitionController::postConfiguration() {
setCrateNumber();
registerRefresher(liveProcessType, &DPPAcquisitionController::refreshLiveProcessTypeProperty, this);
// DPP Context.
// Warning: we suppose that the list mode block is ordered like the ADC controllers
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();
}
}
cout << "DPP context" << endl;
cout << listModeContext << endl;
}
/*
......@@ -498,4 +544,57 @@ void DPPAcquisitionController::setContext() {
// cout << listModeContext << endl;
}
DataBlock* decodeListModeBlock(AsciiDataFileManager* dataFileManager, AsciiDataFile* dataFile, string blockType, typename boost::tokenizer<boost::char_separator<char> >::iterator iter, typename boost::tokenizer<boost::char_separator<char> >::iterator end) {
cout << "decodeListModeBlock" << endl;
// Change
// - tok1.end() into end
// - getAbstractController into dataFileManager->getAbstractController
// - m_DataFile into dataFile
// - creation of the block to copy and return the block
// - goto error into return NULL
// Get number of GEGE
if (++iter == end) {
return NULL;
}
uint32 nbgeges = (uint32) strtol((*iter).c_str(), NULL, 10);
vector<AbstractController*> gegecontrollers;
for(uint32 i=0;i<nbgeges;++i) {
AbstractController* controller = NULL;
if (++iter == end) {
return NULL;
}
if ((*iter).empty() == false) {
controller = dataFileManager->getAbstractController(*iter);
}
gegecontrollers.push_back(controller);
}
// Get number of detector controller
if (++iter == end) {
return NULL;
}
uint32 nbdetectors = (uint32) strtol((*iter).c_str(), NULL, 10);
vector<AbstractController*> detectorcontrollers;
for(uint32 i=0;i<nbdetectors;++i) {
if (++iter == end) {
return NULL;
}
AbstractController* detector = NULL;
if ((*iter).empty() == false) {
detector = dataFileManager->getAbstractController(*iter);
}
detectorcontrollers.push_back(detector);
}
npp::ListModeBlock * newBlock = new npp::ListModeBlock(nbgeges, gegecontrollers, nbdetectors, detectorcontrollers);
dataFile->addDataBlock(newBlock);
return newBlock;
}
}
/*
* 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 "ListModeBlock.h"
#include "InstrumentAbstraction/AbstractController.h"
#include <common/base/ServerProperties.h>
#include <lstdpp128/lstdpp.h>
#include <boost/format.hpp>
using namespace boost;
using namespace lstdpp128;
namespace npp {
ListModeBlock::ListModeBlock(uint32 nbgeges, const vector<AbstractController*>& gegeControllers, uint32 nbdetectors,
const vector<AbstractController*>& detectorControllers) :
DataBlock(true), m_NbGeges(nbgeges), m_GegeControllers(gegeControllers), m_NbDetectors(nbdetectors), m_DetectorControllers(
detectorControllers), m_Oldlistmodedatasize(0) {
// Empty
}
ListModeBlock::~ListModeBlock() {
// Empty
}
void ListModeBlock::writeBlock(std::ofstream & file) {
cout << "ListModeBlock write" << endl;
int32 *listmodedata = 0;
uint32 listmodedatasize = 0;
uint32 totallistmodedatasize = 0;
ostringstream filename;
filename << common::ServerProperties::getInstance()->getNomadDataPath() << boost::format("%06i") % m_RecordNumber << ".lst";
ofstream dataFile;
// Open data file
dataFile.open(filename.str().c_str(), std::ios::app | std::ios::binary);
if (dataFile) {
// Verify if first write
if (dataFile.tellp() == 0) {
// cout << "DPP context (ListModeBlock)" << endl;
// cout << listModeContext << endl;
// Write header
// uint32 buffer[4 + m_NbGeges];
// buffer[0] = 1;
// buffer[1] = 9;
// buffer[2] = 0;
// buffer[3] = m_NbGeges;
// for (uint32 i = 0; i < m_NbGeges; ++i) {
// if (m_GegeControllers[i] != NULL) {
// int32 evtype = 0; //any_cast<int32>(m_GegeControllers[i]->getValue("display_channel"));
// int32 card = any_cast<int32>(m_GegeControllers[i]->getValue("crate_number"));
// int32 channels = any_cast<int32>(m_GegeControllers[i]->getValue("nb_channels"));
// int32 type = any_cast<int32>(m_GegeControllers[i]->getValue("card_type"));
// buffer[4 + i] = type & 0x3F;
// buffer[4 + i] |= (channels & 0x3F) << 6;
// buffer[4 + i] |= (card & 0xF) << 12;
// buffer[4 + i] |= (evtype & 0xFFFF) << 16;
// }
// }
// dataFile.write((const char *) buffer, (4 + m_NbGeges) * sizeof(uint32));
string buffer = writeListModeContextToBinary(listModeContext);
dataFile.write(buffer.c_str(), buffer.size());
m_Oldlistmodedatasize = 0;
}
for (uint32 i = 0; i < m_NbDetectors; ++i) {
// Write list mode
if (m_DetectorControllers[i] != NULL) {
listmodedata = any_cast<int32*>(m_DetectorControllers[i]->getValue("list_mode_data"));
listmodedatasize = any_cast<int32>(m_DetectorControllers[i]->getValue("list_mode_data_size"));
if ((listmodedatasize != 0) && (listmodedata != NULL)) {
totallistmodedatasize += listmodedatasize / 4;
dataFile.write((const char *) listmodedata, listmodedatasize * sizeof(int32));
m_DetectorControllers[i]->setValue("list_mode_data_size", (int32) 0);
}
}
}
dataFile.close();
}
fstream dataFile1;
dataFile1.open(filename.str().c_str(), ios_base::in | ios_base::out | std::ios::binary);
if (dataFile1) {
dataFile1.seekp(2 * sizeof(uint32), ios_base::beg);
totallistmodedatasize += m_Oldlistmodedatasize;
dataFile1.write((const char *) &totallistmodedatasize, sizeof(uint32));
m_Oldlistmodedatasize = totallistmodedatasize;
dataFile1.close();
}
}
}
/*
* 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.
*/
#ifndef NPP_LISTMODEBLOCK_H
#define NPP_LISTMODEBLOCK_H
#include <iostream>
#include <vector>
#include <string>
#include "controllers/common/datafile/DataBlock.h"
class AbstractController;
namespace npp {
class ListModeBlock: public DataBlock {
public:
ListModeBlock(uint32 nbgeges, const vector<AbstractController*>& gegeControllers, uint32 nbdetectors,
const vector<AbstractController*>& detectorControllers);
virtual ~ListModeBlock();
void writeBlock(std::ofstream & file);
private:
uint32 m_NbGeges;
std::vector<AbstractController*> m_GegeControllers;
uint32 m_NbDetectors;
std::vector<AbstractController*> m_DetectorControllers;
uint32 m_Oldlistmodedatasize;
};
}
#endif
......@@ -105,6 +105,10 @@ void RemoteDPPCoincidence::setDetectorControllers(const std::vector<ControllerPt
void RemoteDPPCoincidence::start() {
// Need a mutex to avoid having two start at the same time.
{
boost::mutex::scoped_lock lock(m_mutex);
initFileReading();
resetData();
......@@ -211,24 +215,10 @@ void RemoteDPPCoincidence::start() {
// Wait for the termination of the application
application::State state = m_coincidenceApplication->waitFor();
cout << "coincidence application terminated with state " << state << endl;
// Join the test thread
finishFileReading(thread);
}
void RemoteDPPCoincidence::stop() {
// Test the coincidence application and the publisher
if (m_coincidenceApplication.get() != 0 && m_publisher.get() != 0) {
if (fileReadingMode()) {
m_reader->stop();
}
cout << *m_publisher << " end of stream" << endl;
m_publisher->sendEnd();
// we do not stop the application because the termination of the publisher will do it.
cout << "coincidence application terminated with state " << state << endl;
}
}
......
......@@ -40,7 +40,6 @@ public:
virtual void setDetectorControllers(const std::vector<ControllerPtr<acquisition::DetectorController> > & detectorControllers);
virtual void start();
virtual void stop();
virtual void raz();
void refreshNumberOfDetectorChannels(int32 value);
......
......@@ -37,42 +37,42 @@ RemoteDPPContext::~RemoteDPPContext() {
void RemoteDPPContext::postConfiguration() {
// Warning: we suppose that the list mode block is ordered like the ADC controllers
releaseListModeContext(listModeContext);
int32 nbCrates = 0;
for (int32 adc = 0; adc < acquisitionController->nbAdcControllers(); ++adc) {
int32 crate = acquisitionController->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 < acquisitionController->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 < acquisitionController->nbAdcControllers(); ++board) {
listModeContext.crateBoard.crates[0].boards[board].boardType = (BoardType)acquisitionController->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 = acquisitionController->adcController[board]->nbChannels();
}
}
cout << "DPP context" << endl;
cout << listModeContext << endl;
// releaseListModeContext(listModeContext);
//
// int32 nbCrates = 0;
//
// for (int32 adc = 0; adc < acquisitionController->nbAdcControllers(); ++adc) {
// int32 crate = acquisitionController->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 < acquisitionController->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 < acquisitionController->nbAdcControllers(); ++board) {
// listModeContext.crateBoard.crates[0].boards[board].boardType = (BoardType)acquisitionController->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 = acquisitionController->adcController[board]->nbChannels();
// }
// }
// cout << "DPP context" << endl;
// cout << listModeContext << endl;
}
}
......
......@@ -89,6 +89,10 @@ void RemoteDPPHistogram::setDetectorControllers(const std::vector<ControllerPtr<
void RemoteDPPHistogram::start() {
// Need a mutex to avoid having two start at the same time.
{
boost::mutex::scoped_lock lock(m_mutex);
initFileReading();
resetData();
......@@ -160,12 +164,12 @@ void RemoteDPPHistogram::start() {
vector<double> channelRates;
while (subscriber->receive(channelRates)) {
cout << "received rates " << channelRates.size() << endl;
//cout << "received rates " << channelRates.size() << endl;
// Copying the rates
for (int32 i = 0; i < totalNumberOfChannels(); i++) {
channelRate.set(i, channelRates[i]);
cout << "rate " << i << " = " << channelRate(i) << endl;
//cout << "rate " << i << " = " << channelRate(i) << endl;
}
vector<int32_t> histograms;
......@@ -206,24 +210,10 @@ void RemoteDPPHistogram::start() {
// Wait for the termination of the application
application::State state = m_histoApplication->waitFor();
cout << "histogram application terminated with state " << application::toString(state) << endl;
// Join the test thread
finishFileReading(thread);
}
void RemoteDPPHistogram::stop() {
// Test the histogram application and the publisher
if (m_histoApplication.get() != 0 && m_publisher.get() != 0) {
if (fileReadingMode()) {
m_reader->stop();
}
cout << *m_publisher << " end of stream" << endl;
m_publisher->sendEnd();
// We do not stop the application because the termination of the publisher will do it.
cout << "histogram application terminated with state " << application::toString(state) << endl;
}
}
......
......@@ -40,7 +40,6 @@ public:
virtual void setDetectorControllers(const std::vector<ControllerPtr<acquisition::DetectorController> > & detectorControllers);
virtual void start();
virtual void stop();
virtual void raz();
void updateListModeData(int index);
......
......@@ -59,7 +59,14 @@ void RemoteDPPLiveProcess::postConfiguration() {
}
bool RemoteDPPLiveProcess::fileReadingMode() {
return (mode() == TEST_MODE || mode() == FILE_MODE);
if (mode() == TEST_MODE || mode() == FILE_MODE) {
return true;
}
// The direct mode is not supported now.
return false;
}
std::string RemoteDPPLiveProcess::getFileNameToRead() {
......@@ -68,7 +75,15 @@ std::string RemoteDPPLiveProcess::getFileNameToRead() {
return testFileName();
}
else {
return ServerProperties::getInstance()->getNomadDataPath() + "/" + fileName();
// Set the numor name.
string numorName = fileName();
size_t size = numorName.size();
if (size < 6) {
string prefix(6 - size, '0');
numorName = prefix + numorName;
}
return ServerProperties::getInstance()->getNomadDataPath() + "/" + numorName + ".lst";
}
return "";
......@@ -77,7 +92,6 @@ std::string RemoteDPPLiveProcess::getFileNameToRead() {
void RemoteDPPLiveProcess::initFileReading() {
if (fileReadingMode()) {
m_reader.reset(new lstdpp128::LiveReader(blockSize()));
m_reader->open(getFileNameToRead());
}
......@@ -86,8 +100,12 @@ void RemoteDPPLiveProcess::initFileReading() {
void RemoteDPPLiveProcess::fileReadingLoop() {
if (fileReadingMode()) {
cout << "reading file " << getFileNameToRead() << endl;
// Loop over events
while (!m_publisher->hasEnded()) {
while (!isStopped()) {
// Reading next block
int32_t blockSize = m_reader->read();
......@@ -109,6 +127,10 @@ void RemoteDPPLiveProcess::fileReadingLoop() {
usleep(10000);
}
cout << "controller has stopped" << endl;
m_publisher->sendEnd();
cout << "finished reading file" << endl;
}
}
......@@ -129,6 +151,14 @@ void RemoteDPPLiveProcess::finishFileReading(std::auto_ptr<boost::thread> thread
}
}
void RemoteDPPLiveProcess::stop() {
// Stop the reader which should be blocked in fileReadingLoop.
if (m_reader.get() != 0) {
m_reader->stop();
}
}
}
......@@ -37,6 +37,8 @@ public:
virtual void postConfiguration();
virtual void stop();
protected:
void initFileReading();
void fileReadingLoop();
......@@ -54,6 +56,8 @@ protected:
std::auto_ptr<cameo::application::Publisher> m_publisher;
std::auto_ptr<lstdpp128::LiveReader> m_reader;
boost::mutex m_mutex;
static const std::string TEST_MODE;
static const std::string FILE_MODE;
static const std::string DIRECT_MODE;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment