diff --git a/src/Acquisition.cpp b/src/Acquisition.cpp index 0d7cdab3b8228ec967d6370d9e8554e806952c3a..e4a2221b0dd1a46ca92f4b343d2e16ee50788db8 100644 --- a/src/Acquisition.cpp +++ b/src/Acquisition.cpp @@ -83,22 +83,22 @@ Tango::DevState Acquisition::get_state() switch(m_helper->get_state()) { - case State::INITIALIZATION_SUCCESSFUL: + case INITIALIZATION_SUCCESSFUL: ///DEBUG_STREAM<<"------- INITIALIZATION_SUCCESSFUL"<<endl; if(m_state!=Tango::ALARM) set_state(Tango::STANDBY); break; - case State::INITIALIZATION_UNKNOWN: + case INITIALIZATION_UNKNOWN: DEBUG_STREAM<<"------- INITIALIZATION_UNKNOWN"<<endl; set_state(Tango::FAULT); return m_state; break; - case State::INITIALIZATION_FAILED: + case INITIALIZATION_FAILED: DEBUG_STREAM<<"------- INITIALIZATION_FAILED"<<endl; set_state(Tango::FAULT); return m_state; break; - case State::INITIALIZATION_PROGRESS: + case INITIALIZATION_PROGRESS: DEBUG_STREAM<<"------- INITIALIZATION_PROGRESS"<<endl; set_state(Tango::INIT); return m_state; diff --git a/src/AcquisitionMapping.cpp b/src/AcquisitionMapping.cpp index 8f7d2ad551d789207db0745c8a6ed6edc4188b5e..8671e4910551e602cbee916b82178cde7d00c893 100644 --- a/src/AcquisitionMapping.cpp +++ b/src/AcquisitionMapping.cpp @@ -249,8 +249,7 @@ void AcquisitionMapping::readout_buffer(int module) m_module_info_array[module].m_is_pixel_readout = true; DataBufferContainer* map_buffer = new DataBufferContainer(module, m_module_info_array[module].m_buffer_length); - // readout acquisition buffer from installed modules - INFO_STREAM << " " << std::endl; + // readout acquisition buffer from installed modules INFO_STREAM << "\t- readout buffer from board - " << module << std::endl; m_helper->get_buffer(module, m_module_info_array[module].m_current_buffer, map_buffer->base()); @@ -262,7 +261,14 @@ void AcquisitionMapping::readout_buffer(int module) int nb_pixels = (int) map_buffer->base()[8]; // send MappingDataBufferContainer over to MappingDataProcessingTask - INFO_STREAM << "\t- send Data Buffer of pixels [" << starting_pixel << " : " << starting_pixel + nb_pixels - 1 << "] to Data Store." << std::endl; + INFO_STREAM << "\t- send Data Buffer of pixels [" + << starting_pixel + << " : " + << starting_pixel + nb_pixels - 1 + << "] to Data Store. (nbPixels = " + << nb_pixels + <<")" + << std::endl; //process the buffer m_store->process_data(map_buffer); diff --git a/src/DataParser.cpp b/src/DataParser.cpp new file mode 100755 index 0000000000000000000000000000000000000000..5025e920bf662d1a80556d346d228adca19dfefe --- /dev/null +++ b/src/DataParser.cpp @@ -0,0 +1,51 @@ +//============================================================================= +// +// file : DataParser.cpp +// +// description : +// +// project : XiaDxp Project +// +// $Author: noureddine $ +// +// copyleft : Synchrotron SOLEIL +// L'Orme des merisiers - Saint Aubin +// BP48 - 91192 Gif sur Yvette +// FRANCE +//============================================================================= + +#include <tango.h> +#include "Controller.h" +#include "DataStore.h" +#include "DataParser.h" + + +namespace XiaDxp_ns +{ +//---------------------------------------------------------------------------------------------------------------------- +//- ctor +//---------------------------------------------------------------------------------------------------------------------- +DataParser::DataParser(Tango::DeviceImpl *dev, DataStore* store) +: Tango::LogAdapter(dev), +m_device(dev), +m_store(store), +m_mode("") + +{ + INFO_STREAM << "DataParser::DataParser() - [BEGIN]" << endl; + INFO_STREAM << "DataParser::DataParser() - [END]" << endl; +} + +//---------------------------------------------------------------------------------------------------------------------- +//- dtor +//---------------------------------------------------------------------------------------------------------------------- +DataParser::~DataParser() +{ + INFO_STREAM << "DataParser::~DataParser() - [BEGIN]" << endl; + INFO_STREAM << "DataParser::~DataParser() - [END]" << endl; +} +//---------------------------------------------------------------------------------------------------------------------- +//- +//---------------------------------------------------------------------------------------------------------------------- + +} // namespace diff --git a/src/DataParser.h b/src/DataParser.h new file mode 100755 index 0000000000000000000000000000000000000000..3d343dbffca08098b626e3c823129f1f2f330ecc --- /dev/null +++ b/src/DataParser.h @@ -0,0 +1,41 @@ +/************************************************************************* +/*! + * \file DataStore.h + * \brief class DataStore + * \author Arafat Noureddine + */ +/*************************************************************************/ + +#ifndef DATA_PARSER_H +#define DATA_PARSER_H + +//TANGO +#include <tango.h> +#include "DataStore.h" + + +namespace XiaDxp_ns +{ +//------------------------------------------------------------------ +// class: DataParser +//------------------------------------------------------------------ +class DataParser: public Tango::LogAdapter +{ +public: + ///ctor + DataParser(Tango::DeviceImpl *dev, DataStore* store); + ///dtor + virtual ~DataParser(); + ///parse datas for acquired mapping buffer + virtual void parse_buffer(DataBufferContainer& map_buffer) = 0; +protected: + + /// Owner Device server object + Tango::DeviceImpl* m_device; + DataStore* m_store; + std::string m_mode; +}; + +} + +#endif //DATA_PARSER_H diff --git a/src/DataParserMapping.cpp b/src/DataParserMapping.cpp new file mode 100755 index 0000000000000000000000000000000000000000..53922f3f665cc481165eecd091e7355a61bc3523 --- /dev/null +++ b/src/DataParserMapping.cpp @@ -0,0 +1,289 @@ +//============================================================================= +// +// file : DataParserMapping.cpp +// +// description : +// +// project : XiaDxp Project +// +// $Author: noureddine $ +// +// copyleft : Synchrotron SOLEIL +// L'Orme des merisiers - Saint Aubin +// BP48 - 91192 Gif sur Yvette +// FRANCE +//============================================================================= + +#include <tango.h> +#include "Controller.h" +#include "DataStore.h" +#include "DataParser.h" +#include "DataParserMapping.h" + + +namespace XiaDxp_ns +{ +//---------------------------------------------------------------------------------------------------------------------- +//- ctor +//---------------------------------------------------------------------------------------------------------------------- +DataParserMapping::DataParserMapping(Tango::DeviceImpl *dev, DataStore* store) +: DataParser(dev, store) +{ + INFO_STREAM << "DataParserMapping::DataParserMapping() - [BEGIN]" << endl; + m_mode = store->get_acquisition_mode(); + INFO_STREAM << "DataParserMapping::DataParserMapping() - [END]" << endl; +} + +//---------------------------------------------------------------------------------------------------------------------- +//- dtor +//---------------------------------------------------------------------------------------------------------------------- +DataParserMapping::~DataParserMapping() +{ + INFO_STREAM << "DataParserMapping::~DataParserMapping() - [BEGIN]" << endl; + INFO_STREAM << "DataParserMapping::~DataParserMapping() - [END]" << endl; +} +//---------------------------------------------------------------------------------------------------------------------- +//- Parse entire buffer acquisition +//---------------------------------------------------------------------------------------------------------------------- +void DataParserMapping::parse_buffer(DataBufferContainer& map_buffer) +{ + DEBUG_STREAM << "DataParserMapping::parse_buffer() - [BEGIN]" << endl; + INFO_STREAM<<"\t- parse the mapping buffer"<<endl; + try + { + if ((map_buffer.base()[0] != TAG_HEAD0) || (map_buffer.base()[1] != TAG_HEAD1)) + { + std::stringstream ss_msg; + ss_msg << "Missing TAG_HEAD0/TAG_HEAD1 in the mapping buffer !" << std::endl; + ERROR_STREAM << "DataParserMapping::parse_buffer() - " << ss_msg.str() << std::endl; + //stop_acquisition();//@@TODO + //on_alarm(ss_msg.str()); + m_store->set_state(Tango::FAULT); + Tango::Except::throw_exception("XIA_ERROR", + (ss_msg.str()).c_str(), + "DataParserMapping::parse_buffer()"); + } + + if (map_buffer.base()[31] != 0x0000) + { + std::stringstream ss_msg; + ss_msg << "Expected 0 in WORD 31 of mapping buffer !" << std::endl; + ERROR_STREAM << "DataParserMapping::parse_buffer() - " << ss_msg.str() << std::endl; + //stop_acquisition();//@@TODO + //on_alarm(ss_msg.str()); + m_store->set_state(Tango::FAULT); + Tango::Except::throw_exception("XIA_ERROR", + (ss_msg.str()).c_str(), + "DataParserMapping::parse_buffer()"); + } + + // parse pixels + int startingPixel = WORD_TO_LONG((int) map_buffer.base()[9], (int) map_buffer.base()[10]); + int nbPixels = (int) map_buffer.base()[8]; + //INFO_STREAM << "\t- pixels to process : " << nbPixels <<std::endl; + + for (int pixel = 0; pixel < nbPixels; ++pixel) + { + //DEBUG_STREAM<<"------------------------------------"<<std::endl; + //DEBUG_STREAM<<"---------- pixel = "<<pixel<<std::endl; + //DEBUG_STREAM<<"------------------------------------"<<std::endl; + if(m_store->get_acquisition_mode()== "MAPPING" || m_store->get_acquisition_mode()== "MAPPING_FULL") + parse_pixel_full(map_buffer.module(), pixel, map_buffer.base()); + else + parse_pixel_sca(map_buffer.module(), pixel, map_buffer.base()); + } + + //INFO_STREAM << "\t- processed pixels : " << startingPixel << " to " << startingPixel + nbPixels - 1 << " (" <<nbPixels<<")"<<std::endl; + } + catch(const std::exception& ex) + { + ERROR_STREAM << "DataParserMapping::parse_buffer() - " << ex.what() << endl; + //stop_acquisition();//@@TODO + //on_alarm(ex.what()); + m_store->set_state(Tango::FAULT); + Tango::Except::throw_exception("XIA_ERROR", + ex.what(), + "DataParserMapping::parse_buffer()"); + } + DEBUG_STREAM << "DataParserMapping::parse_buffer() - [END]" << endl; +} + +//---------------------------------------------------------------------------------------------------------------------- +//- Parse one pixel (in mode full) contained in the buffer acquisition +//---------------------------------------------------------------------------------------------------------------------- +void DataParserMapping::parse_pixel_full(int module, int pixel, DataType* map_buffer) +{ + //DEBUG_STREAM<<"DataParserMapping::parse_pixel_full() - [BEGIN]"<<std::endl; + + DataType* pixel_data = map_buffer + BUFFER_HEADER_SIZE; + + // go to current pixel + for (int i = 0; i < pixel; ++i) + { + unsigned long pixelBlockSize = WORD_TO_LONG(pixel_data[6], pixel_data[7]); + pixel_data += pixelBlockSize; + } + + // check pixel buffer + if ((pixel_data[0] != TAG_DATA0) && (pixel_data[1] != TAG_DATA1)) + { + std::stringstream ss_msg; + ss_msg << "Missing TAG_DATA0/TAG_DATA1 in the pixel ["<<pixel<<"] of the mapping buffer !" << std::endl; + ERROR_STREAM << "DataStore::parse_data() - " << ss_msg.str() << endl; + //stop_acquisition();//@@TODO + //on_alarm(ss_msg.str()); + m_store->set_state(Tango::FAULT); + Tango::Except::throw_exception("XIA_ERROR", + (ss_msg.str()).c_str(), + "DataStore::parse_data()"); + } + + unsigned long the_pixel = WORD_TO_LONG(pixel_data[4], pixel_data[5]); + //DEBUG_STREAM<<"\t- the_pixel = "<<the_pixel<<std::endl; + unsigned long length_of_pixData = WORD_TO_LONG(pixel_data[6], pixel_data[7]); + + // Get spectrum sizes + // WORD 8/9/10/11 (XMAP_USER_MANUAL.pdf - 5.3.3.3 Mapping Mode 1 - page 70) + // number of channels = ALWAYS 4 for XMAP board ! @@TODO what is the spec for Falcon ? + DataType size[4]; + for (int channel = 0; channel < 4; channel++) + { + size[channel] = pixel_data[8 + channel]; + //DEBUG_STREAM<<"\t- size channel["<<channel<<"] = "<<size[channel]<<std::endl; + } + + //DEBUG_STREAM <<"\t- parse data - module = " <<module <<" - pixel = " <<the_pixel <<" - length = " <<length_of_pixData <<std::endl; + + // statistics for current pixel + //DEBUG_STREAM << "\t- push statistics for the pixel ["<<the_pixel<<"] into DataStore" <<std::endl; + + for (int channel = 0; channel < 4; channel++) + { + //each channels statistics contains 8 WORD, that is why channel*8 + unsigned long realtime = WORD_TO_LONG(pixel_data[32 + channel * 8], pixel_data[33 + channel * 8]); + unsigned long livetime = WORD_TO_LONG(pixel_data[34 + channel * 8], pixel_data[35 + channel * 8]); + unsigned long triggers = WORD_TO_LONG(pixel_data[36 + channel * 8], pixel_data[37 + channel * 8]); + unsigned long outputs = WORD_TO_LONG(pixel_data[38 + channel * 8], pixel_data[39 + channel * 8]); + + PixelData pix_data; + pix_data.triggers = triggers; + pix_data.outputs = outputs; + pix_data.realtime = static_cast<double> (realtime); + pix_data.livetime = static_cast<double> (livetime); + + //push statistics into DataStore + m_store->store_statistics(module, //nb module + channel, //numero of channel + the_pixel, //numero of pixel + pix_data); + } + + //datas for current pixel + //DEBUG_STREAM << "\t- push buffer data for the pixel ["<<the_pixel<<"] into DataStore "<<endl; + DataType* spectrum_data = pixel_data + PIXEL_HEADER_SIZE; + for (int channel = 0; channel < 4; ++channel) + { + m_store->store_data(module, //nb module + channel, //numero of channel + the_pixel, //numero of pixel + (DataType*) spectrum_data, + size[channel] + ); + spectrum_data += size[channel]; + } + + //DEBUG_STREAM << "\t- The pixel ["<<m_current_pixel<<"] is parsed & stored." <<std::endl; + //DEBUG_STREAM<<"DataParserMapping::parse_pixel_full() - [END]"<<std::endl; +} + +//---------------------------------------------------------------------------------------------------------------------- +//- Parse one pixel (in mode sca) contained in the buffer acquisition +//---------------------------------------------------------------------------------------------------------------------- +void DataParserMapping::parse_pixel_sca(int module, int pixel, DataType* map_buffer) +{ + //DEBUG_STREAM<<"DataParserMapping::parse_pixel_sca() - [BEGIN]"<<std::endl; + + DataType* pixel_data = map_buffer + BUFFER_HEADER_SIZE; + + // go to current pixel + for (int i = 0; i < pixel; ++i) + { + unsigned long pixelBlockSize = WORD_TO_LONG(pixel_data[6], pixel_data[7]); + //INFO_STREAM<<"\t\t- pixelBlockSize = "<<pixelBlockSize<<endl; + pixel_data += pixelBlockSize; + } + + // check pixel buffer + if ((pixel_data[0] != TAG_DATA0) && (pixel_data[1] != TAG_DATA1)) + { + std::stringstream ss_msg; + ss_msg << "Missing TAG_DATA0/TAG_DATA1 in the pixel ["<<pixel<<"] of the mapping buffer !" << std::endl; + ERROR_STREAM << "DataParserMapping::parse_pixel_sca() - " << ss_msg.str() << endl; + //stop_acquisition();//@@TODO + //on_alarm(ss_msg.str()); + m_store->set_state(Tango::FAULT); + Tango::Except::throw_exception("XIA_ERROR", + (ss_msg.str()).c_str(), + "DataParserMapping::parse_pixel_sca()"); + } + + unsigned long the_pixel = WORD_TO_LONG(pixel_data[4], pixel_data[5]); + //INFO_STREAM<<"\t\t- the_pixel = "<<the_pixel<<std::endl; + unsigned long length_of_pixData = WORD_TO_LONG(pixel_data[6], pixel_data[7]); + + // Get spectrum sizes + // WORD 8/9/10/11 (XMAP_USER_MANUAL.pdf - 5.3.3.3 Mapping Mode 1 - page 70) + // number of channels = ALWAYS 4 for XMAP board ! @@TODO what is the spec for Falcon ? + DataType nb_rois[4]; + for (int channel = 0; channel < 4; channel++) + { + nb_rois[channel] = pixel_data[8 + channel]; + //INFO_STREAM<<"\t\t- nb_rois["<<channel<<"] = "<<nb_rois[channel]<<std::endl; + } + + //INFO_STREAM <<"\t\t- parse data - module = " <<module <<" - pixel = " <<the_pixel <<" - length = " <<length_of_pixData <<std::endl; + + // statistics for current pixel + //INFO_STREAM << "\t\t- push statistics for the pixel ["<<the_pixel<<"] into DataStore" <<std::endl; + + for (int channel = 0; channel < 4; channel++) + { + //each channels statistics contains 8 WORD, that is why channel*8 + unsigned long realtime = WORD_TO_LONG(pixel_data[32 + channel * 8], pixel_data[33 + channel * 8]); + unsigned long livetime = WORD_TO_LONG(pixel_data[34 + channel * 8], pixel_data[35 + channel * 8]); + unsigned long triggers = WORD_TO_LONG(pixel_data[36 + channel * 8], pixel_data[37 + channel * 8]); + unsigned long outputs = WORD_TO_LONG(pixel_data[38 + channel * 8], pixel_data[39 + channel * 8]); + + PixelData pix_data; + pix_data.triggers = triggers; + pix_data.outputs = outputs; + pix_data.realtime = static_cast<double> (realtime); + pix_data.livetime = static_cast<double> (livetime); + + //push statistics into DataStore + m_store->store_statistics(module, //nb module + channel, //numero of channel + the_pixel, //numero of pixel + pix_data); + } + + //datas for current pixel + //INFO_STREAM << "\t\t- push buffer data for the pixel ["<<the_pixel<<"] into DataStore "<<endl; + DataType* sca_rois = pixel_data + NB_SCA_MAX;//PIXEL_HEADER_SIZE in case of sca mode = 64 + for (int channel = 0; channel < 4; ++channel) + { + m_store->store_data(module, //nb module + channel, //numero of channel + the_pixel, //numero of pixel + (DataType*) sca_rois, + nb_rois[channel] + ); + sca_rois += nb_rois[channel]; + //INFO_STREAM<<"nb_rois[channel] = "<<nb_rois[channel]<<endl; + } + + //DEBUG_STREAM << "\t- The pixel ["<<the_pixel<<"] is parsed & stored." <<std::endl; + //DEBUG_STREAM<<"DataParserMapping::parse_pixel_sca() - [END]"<<std::endl; +} + +} // namespace diff --git a/src/DataParserMapping.h b/src/DataParserMapping.h new file mode 100755 index 0000000000000000000000000000000000000000..56227702f7cd4565a00647972c3a997b80f71e68 --- /dev/null +++ b/src/DataParserMapping.h @@ -0,0 +1,40 @@ +/************************************************************************* +/*! + * \file DataParserMapping.h + * \brief class DataStore + * \author Arafat Noureddine + */ +/*************************************************************************/ + +#ifndef DATA_PARSER_MAPPING_H +#define DATA_PARSER_MAPPING_H + +//TANGO +#include <tango.h> +#include "DataStore.h" + + +namespace XiaDxp_ns +{ +//------------------------------------------------------------------ +// class: DataParserMapping +//------------------------------------------------------------------ +class DataParserMapping: public DataParser +{ +public: + ///ctor + DataParserMapping(Tango::DeviceImpl *dev, DataStore* store); + ///dtor + virtual ~DataParserMapping(); + ///parse datas for acquired mapping buffer + virtual void parse_buffer(DataBufferContainer& map_buffer); +protected: + ///parse datas for each acquired mapping pixel + virtual void parse_pixel_full(int module, int pixel, DataType* map_buffer); + ///parse datas for each acquired mapping pixel + virtual void parse_pixel_sca(int module, int pixel, DataType* map_buffer); +}; + +} + +#endif //DATA_PARSER_MAPPING_H diff --git a/src/DataParserMca.cpp b/src/DataParserMca.cpp new file mode 100755 index 0000000000000000000000000000000000000000..73052afd50c03d3eddcd23664dde0df834624ec8 --- /dev/null +++ b/src/DataParserMca.cpp @@ -0,0 +1,55 @@ +//============================================================================= +// +// file : DataParserMca.cpp +// +// description : +// +// project : XiaDxp Project +// +// $Author: noureddine $ +// +// copyleft : Synchrotron SOLEIL +// L'Orme des merisiers - Saint Aubin +// BP48 - 91192 Gif sur Yvette +// FRANCE +//============================================================================= + +#include <tango.h> +#include "Controller.h" +#include "DataStore.h" +#include "DataParser.h" +#include "DataParserMca.h" + + +namespace XiaDxp_ns +{ +//---------------------------------------------------------------------------------------------------------------------- +//- ctor +//---------------------------------------------------------------------------------------------------------------------- +DataParserMca::DataParserMca(Tango::DeviceImpl *dev,DataStore* store) +: DataParser(dev, store) +{ + INFO_STREAM << "DataParserMca::DataParserMca() - [BEGIN]" << endl; + INFO_STREAM << "DataParserMca::DataParserMca() - [END]" << endl; +} + +//---------------------------------------------------------------------------------------------------------------------- +//- dtor +//---------------------------------------------------------------------------------------------------------------------- +DataParserMca::~DataParserMca() +{ + INFO_STREAM << "DataParserMca::~DataParserMca() - [BEGIN]" << endl; + INFO_STREAM << "DataParserMca::~DataParserMca() - [END]" << endl; +} + +//---------------------------------------------------------------------------------------------------------------------- +//- Parse entire buffer acquisition +//---------------------------------------------------------------------------------------------------------------------- +void DataParserMca::parse_buffer(DataBufferContainer& map_buffer) +{ + INFO_STREAM<<"DataParserMca::parse_buffer() - [BEGIN]"<<std::endl; + //Nothing to do + INFO_STREAM<<"DataParserMca::parse_buffer() - [END]"<<std::endl; +} + +} // namespace diff --git a/src/DataParserMca.h b/src/DataParserMca.h new file mode 100755 index 0000000000000000000000000000000000000000..f69ea04c819981ef9488f8051f5b160bded7d8c1 --- /dev/null +++ b/src/DataParserMca.h @@ -0,0 +1,37 @@ +/************************************************************************* +/*! + * \file DataParserMca.h + * \brief class DataParserMca + * \author Arafat Noureddine + */ +/*************************************************************************/ + +#ifndef DATA_PARSER_MCA_H +#define DATA_PARSER_MCA_H + +//TANGO +#include <tango.h> +#include "DataStore.h" + + +namespace XiaDxp_ns +{ +//------------------------------------------------------------------ +// class: DataParserMca +//------------------------------------------------------------------ +class DataParserMca: public DataParser +{ +public: + ///ctor + DataParserMca(Tango::DeviceImpl *dev, DataStore* store); + ///dtor + virtual ~DataParserMca(); + ///parse datas for acquired mapping buffer + virtual void parse_buffer(DataBufferContainer& map_buffer); +protected: + +}; + +} + +#endif //DATA_PARSER_MCA_H diff --git a/src/DataStore.cpp b/src/DataStore.cpp index f8556c8167159c4b6f481bf483542b9904ca0a97..d6e764f9f211fa026f77edf6737de7062c6f3b8c 100644 --- a/src/DataStore.cpp +++ b/src/DataStore.cpp @@ -17,6 +17,10 @@ #include <tango.h> #include "Controller.h" #include "DataStore.h" +#include "DataParser.h" +#include "DataParserMapping.h" +#include "DataParserMca.h" + namespace XiaDxp_ns @@ -25,7 +29,8 @@ namespace XiaDxp_ns //- ctor //---------------------------------------------------------------------------------------------------------------------- DataStore::DataStore(Tango::DeviceImpl *dev) -: yat4tango::DeviceTask(dev) +: yat4tango::DeviceTask(dev), + m_device(dev) { INFO_STREAM << "DataStore::DataStore() - [BEGIN]" << endl; enable_timeout_msg(false); @@ -67,6 +72,9 @@ void DataStore::init(int nb_modules, int nb_channels, int nb_pixels, int nb_bins m_acquisition_mode = acquisition_mode; m_data.module_data.clear(); + //build the data parser + m_parser.reset(build_parser(m_acquisition_mode)); + // setup mapping data structure m_data.module_data.resize(nb_modules); for (int imod = 0; imod < nb_modules; imod++) @@ -139,6 +147,56 @@ void DataStore::reinit() INFO_STREAM << "DataStore::reinit() - [END]" << endl; } +// ============================================================================ +// DataStore::build_parser() +// ============================================================================ +DataParser* DataStore::build_parser(const std::string& acq_mode) +{ + INFO_STREAM << "DataStore::build_parser() - [BEGIN]" << endl; + DataParser* parser; + try + { + std::string mode = acq_mode; + std::transform(mode.begin(), mode.end(), mode.begin(), ::toupper); + + //create the stream + if(mode == "MAPPING"||mode == "MAPPING_FULL"||mode == "MAPPING_SCA") + { + parser = new DataParserMapping(m_device, this); + } + else if(mode == "MCA") + { + parser = new DataParserMca(m_device, this); + } + else + { + std::ostringstream ossMsgErr; + ossMsgErr << "Wrong Acquisition mode:\n" + "Possibles values are:\n" + "MAPPING\n" + "MAPPING_FULL\n" + "MAPPING_SCA\n" + "MCA" + <<std::endl; + Tango::Except::throw_exception("LOGIC_ERROR", + ossMsgErr.str().c_str(), + "DataStore::build_parser()"); + } + } + catch (Tango::DevFailed& df) + { + ERROR_STREAM << df << endl; + std::stringstream ss; + ss << "Initialization Failed.\n" << endl; + ss << "Origin\t: " << df.errors[0].origin << endl; + ss << "Desc\t: " << df.errors[0].desc << endl; + on_abort(ss.str()); + + } + INFO_STREAM << "DataStore::build_parser() - [END]" << endl; + return parser; +} + //---------------------------------------------------------------------------------------------------------------------- //- DataStore::store_statistics //---------------------------------------------------------------------------------------------------------------------- @@ -666,320 +724,17 @@ void DataStore::on_process_data(DataBufferContainer& map_buffer) { DEBUG_STREAM << "DataStore::on_process_data() - [BEGIN]" << std::endl; set_state(Tango::RUNNING); - if(m_acquisition_mode == "MAPPING" ||m_acquisition_mode == "MAPPING_FULL") //keep key MAPPING for retro-compatibility with already configured system on beamline! - { - parse_mapping_full(map_buffer); - } - else if (m_acquisition_mode == "MAPPING_SCA") - { - parse_mapping_sca(map_buffer); - } - else - { - //MCA : NOP - } - - //DEBUG_STREAM << "DataStore::process_data() - [END]" << std::endl; -} - -//---------------------------------------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------------------------------------- -void DataStore::parse_mapping_full(DataBufferContainer& map_buffer) -{ try { - if ((map_buffer.base()[0] != TAG_HEAD0) || (map_buffer.base()[1] != TAG_HEAD1)) - { - std::stringstream ss_msg; - ss_msg << "Missing TAG HEAD in buffer !" << std::endl; - ERROR_STREAM << "DataStore::parse_mapping_full_buffer() - " << ss_msg.str() << std::endl; - //stop_acquisition();//@@TODO - //on_alarm(ss_msg.str()); - set_state(Tango::FAULT); - Tango::Except::throw_exception("XIA_ERROR", - "Missing TAG HEAD in buffer !", - "DataStore::parse_mapping_full_buffer()"); - } - - if (map_buffer.base()[31] != 0x0000) - { - std::stringstream ss_msg; - ss_msg << "Expected 0 in word 31 of mapping buffer !" << std::endl; - ERROR_STREAM << "DataStore::parse_mapping_full_buffer() - " << ss_msg.str() << std::endl; - //stop_acquisition();//@@TODO - //on_alarm(ss_msg.str()); - set_state(Tango::FAULT); - Tango::Except::throw_exception("XIA_ERROR", - (ss_msg.str()).c_str(), - "DataStore::parse_mapping_full_buffer()"); - } - - // parse pixels - const int startingPixel = WORD_TO_LONG((int) map_buffer.base()[9], (int) map_buffer.base()[10]); - const int nbPixels = (int) map_buffer.base()[8]; - //INFO_STREAM << "\t- pixels to process : " << nbPixels <<std::endl; - - for (int pixel = 0; pixel < nbPixels; ++pixel) - { - //DEBUG_STREAM<<"------------------------------------"<<std::endl; - //DEBUG_STREAM<<"---------- pixel = "<<pixel<<std::endl; - //DEBUG_STREAM<<"------------------------------------"<<std::endl; - parse_mapping_full_pixel(map_buffer.module(), pixel, map_buffer.base()); - } - - //INFO_STREAM << "\t- processed pixels : " << startingPixel << " to " << startingPixel + nbPixels - 1 << " (" <<nbPixels<<")"<<std::endl; + m_parser->parse_buffer(map_buffer); } - catch(const std::exception& ex) + catch (Tango::DevFailed &df) { - ERROR_STREAM << "DataStore::parse_mapping_full_buffer() - " << ex.what() << endl; - //stop_acquisition();//@@TODO - //on_alarm(ex.what()); + ERROR_STREAM << df << endl; set_state(Tango::FAULT); - Tango::Except::throw_exception("XIA_ERROR", - ex.what(), - "DataStore::parse_mapping_full_buffer()"); } -} - -//---------------------------------------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------------------------------------- -void DataStore::parse_mapping_full_pixel(int module, int pixel, DataType* map_buffer) -{ - //DEBUG_STREAM<<"DataStore::parse_data() - [BEGIN]"<<std::endl; - - unsigned long* pixel_data = map_buffer + BUFFER_HEADER_SIZE; - - // go to current pixel - for (int i = 0; i < pixel; ++i) - { - const unsigned long pixelBlockSize = WORD_TO_LONG(pixel_data[6], pixel_data[7]); - pixel_data += pixelBlockSize; - } - - // check pixel buffer - if ((pixel_data[0] != TAG_DATA0) && (pixel_data[1] != TAG_DATA1)) - { - std::stringstream ss_msg; - ss_msg << "Missing TAG DATA in buffer for pixel : " << pixel << std::endl; - ERROR_STREAM << "DataStore::parse_data() - " << ss_msg.str() << endl; - //stop_acquisition();//@@TODO - //on_alarm(ss_msg.str()); - set_state(Tango::FAULT); - Tango::Except::throw_exception("XIA_ERROR", - (ss_msg.str()).c_str(), - "DataStore::parse_data()"); - } - - const unsigned long the_pixel = WORD_TO_LONG(pixel_data[4], pixel_data[5]); - //DEBUG_STREAM<<"\t- the_pixel = "<<the_pixel<<std::endl; - const std::size_t length_of_pixData = WORD_TO_LONG(pixel_data[6], pixel_data[7]); - - // Get spectrum sizes - // WORD 8/9/10/11 (XMAP_USER_MANUAL.pdf - 5.3.3.3 Mapping Mode 1 - page 70) - // number of channels = ALWAYS 4 for XMAP board ! @@TODO what is the spec for Falcon ? - unsigned long size[4]; - for (int channel = 0; channel < 4; channel++) - { - size[channel] = pixel_data[8 + channel]; - //DEBUG_STREAM<<"\t- size channel["<<channel<<"] = "<<size[channel]<<std::endl; - } - - //DEBUG_STREAM <<"\t- parse data - module = " <<module <<" - pixel = " <<the_pixel <<" - length = " <<length_of_pixData <<std::endl; - - // statistics for current pixel - //DEBUG_STREAM << "\t- push statistics for the pixel ["<<the_pixel<<"] into DataStore" <<std::endl; - - for (int channel = 0; channel < 4; channel++) - { - //each channels statistics contains 8 WORD, that is why channel*8 - unsigned long realtime = WORD_TO_LONG(pixel_data[32 + channel * 8], pixel_data[33 + channel * 8]); - unsigned long livetime = WORD_TO_LONG(pixel_data[34 + channel * 8], pixel_data[35 + channel * 8]); - unsigned long triggers = WORD_TO_LONG(pixel_data[36 + channel * 8], pixel_data[37 + channel * 8]); - unsigned long outputs = WORD_TO_LONG(pixel_data[38 + channel * 8], pixel_data[39 + channel * 8]); - - PixelData pix_data; - pix_data.triggers = triggers; - pix_data.outputs = outputs; - pix_data.realtime = static_cast<double> (realtime); - pix_data.livetime = static_cast<double> (livetime); - - //push statistics into DataStore - store_statistics(module, //nb module - channel, //numero of channel - the_pixel, //numero of pixel - pix_data); - } - - //datas for current pixel - //DEBUG_STREAM << "\t- push buffer data for the pixel ["<<the_pixel<<"] into DataStore "<<endl; - unsigned long* spectrum_data = pixel_data + PIXEL_HEADER_SIZE; - for (int channel = 0; channel < 4; ++channel) - { - store_data(module, //nb module - channel, //numero of channel - the_pixel, //numero of pixel - (DataType*) spectrum_data, - size[channel] - ); - spectrum_data += size[channel]; - } - - //m_current_pixel = the_pixel; - //DEBUG_STREAM << "\t- The pixel ["<<m_current_pixel<<"] is parsed & stored." <<std::endl; - //DEBUG_STREAM<<"DataStore::parse_data() - [END]"<<std::endl; -} - -//---------------------------------------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------------------------------------- -void DataStore::parse_mapping_sca(DataBufferContainer& map_buffer) -{ - //DEBUG_STREAM<<"DataStore::parse_mapping_sca() - [BEGIN]"<<std::endl; - try - { - if ((map_buffer.base()[0] != TAG_HEAD0) || (map_buffer.base()[1] != TAG_HEAD1)) - { - std::stringstream ss_msg; - ss_msg << "Missing TAG HEAD in buffer !" << std::endl; - ERROR_STREAM << "DataStore::parse_mapping_sca() - " << ss_msg.str() << std::endl; - //stop_acquisition();//@@TODO - //on_alarm(ss_msg.str()); - set_state(Tango::FAULT); - Tango::Except::throw_exception("XIA_ERROR", - "Missing TAG HEAD in buffer !", - "DataStore::parse_mapping_sca()"); - } - - if (map_buffer.base()[31] != 0x0000) - { - std::stringstream ss_msg; - ss_msg << "Expected 0 in word 31 of mapping buffer !" << std::endl; - ERROR_STREAM << "DataStore::parse_mapping_sca() - " << ss_msg.str() << std::endl; - //stop_acquisition();//@@TODO - //on_alarm(ss_msg.str()); - set_state(Tango::FAULT); - Tango::Except::throw_exception("XIA_ERROR", - (ss_msg.str()).c_str(), - "DataStore::parse_mapping_sca()"); - } - - // parse pixels - const int startingPixel = WORD_TO_LONG((int) map_buffer.base()[9], (int) map_buffer.base()[10]); - const int nbPixels = (int) map_buffer.base()[8]; - //INFO_STREAM << "\t- pixels to process : " << nbPixels <<std::endl; - //INFO_STREAM << "\t- startingPixel : " << startingPixel <<std::endl; - - for (int pixel = 0; pixel < nbPixels; ++pixel) - { - //DEBUG_STREAM<<"------------------------------------"<<std::endl; - //DEBUG_STREAM<<"---------- pixel = "<<pixel<<std::endl; - //DEBUG_STREAM<<"------------------------------------"<<std::endl; - parse_mapping_sca_pixel(map_buffer.module(), pixel, map_buffer.base()); - } - - //INFO_STREAM << "\t- processed pixels : " << startingPixel << " to " << startingPixel + nbPixels - 1 << " - [" <<nbPixels<<"] pixels"<<std::endl; - } - catch(const std::exception& ex) - { - ERROR_STREAM << "DataStore::parse_mapping_sca() - " << ex.what() << endl; - //stop_acquisition();//@@TODO - //on_alarm(ex.what()); - set_state(Tango::FAULT); - Tango::Except::throw_exception("XIA_ERROR", - ex.what(), - "DataStore::parse_mapping_sca()"); - } - //DEBUG_STREAM<<"DataStore::parse_mapping_sca() - [END]"<<std::endl; -} - -//---------------------------------------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------------------------------------- -void DataStore::parse_mapping_sca_pixel(int module, int pixel, DataType* map_buffer) -{ - //DEBUG_STREAM<<"DataStore::parse_mapping_sca_pixel() - [BEGIN]"<<std::endl; - - unsigned long* pixel_data = map_buffer + BUFFER_HEADER_SIZE; - - // go to current pixel - for (int i = 0; i < pixel; ++i) - { - const unsigned long pixelBlockSize = WORD_TO_LONG(pixel_data[6], pixel_data[7]); - //INFO_STREAM<<"\t\t- pixelBlockSize = "<<pixelBlockSize<<endl; - pixel_data += pixelBlockSize; - } - - // check pixel buffer - if ((pixel_data[0] != TAG_DATA0) && (pixel_data[1] != TAG_DATA1)) - { - std::stringstream ss_msg; - ss_msg << "Missing TAG DATA in buffer for pixel : " << pixel << std::endl; - ERROR_STREAM << "DataStore::parse_mapping_sca_pixel() - " << ss_msg.str() << endl; - //stop_acquisition();//@@TODO - //on_alarm(ss_msg.str()); - set_state(Tango::FAULT); - Tango::Except::throw_exception("XIA_ERROR", - (ss_msg.str()).c_str(), - "DataStore::parse_mapping_sca_pixel()"); - } - - const unsigned long the_pixel = WORD_TO_LONG(pixel_data[4], pixel_data[5]); - //INFO_STREAM<<"\t\t- the_pixel = "<<the_pixel<<std::endl; - const std::size_t length_of_pixData = WORD_TO_LONG(pixel_data[6], pixel_data[7]); - - // Get spectrum sizes - // WORD 8/9/10/11 (XMAP_USER_MANUAL.pdf - 5.3.3.3 Mapping Mode 1 - page 70) - // number of channels = ALWAYS 4 for XMAP board ! @@TODO what is the spec for Falcon ? - unsigned long nb_rois[4]; - for (int channel = 0; channel < 4; channel++) - { - nb_rois[channel] = pixel_data[8 + channel]; - //INFO_STREAM<<"\t\t- nb_rois["<<channel<<"] = "<<nb_rois[channel]<<std::endl; - } - - //INFO_STREAM <<"\t\t- parse data - module = " <<module <<" - pixel = " <<the_pixel <<" - length = " <<length_of_pixData <<std::endl; - - // statistics for current pixel - //INFO_STREAM << "\t\t- push statistics for the pixel ["<<the_pixel<<"] into DataStore" <<std::endl; - - for (int channel = 0; channel < 4; channel++) - { - //each channels statistics contains 8 WORD, that is why channel*8 - unsigned long realtime = WORD_TO_LONG(pixel_data[32 + channel * 8], pixel_data[33 + channel * 8]); - unsigned long livetime = WORD_TO_LONG(pixel_data[34 + channel * 8], pixel_data[35 + channel * 8]); - unsigned long triggers = WORD_TO_LONG(pixel_data[36 + channel * 8], pixel_data[37 + channel * 8]); - unsigned long outputs = WORD_TO_LONG(pixel_data[38 + channel * 8], pixel_data[39 + channel * 8]); - - PixelData pix_data; - pix_data.triggers = triggers; - pix_data.outputs = outputs; - pix_data.realtime = static_cast<double> (realtime); - pix_data.livetime = static_cast<double> (livetime); - - //push statistics into DataStore - store_statistics(module, //nb module - channel, //numero of channel - the_pixel, //numero of pixel - pix_data); - } - - //datas for current pixel - //INFO_STREAM << "\t\t- push buffer data for the pixel ["<<the_pixel<<"] into DataStore "<<endl; - unsigned long* sca_rois = pixel_data + 64;//PIXEL_HEADER_SIZE i case of sca mode = 64 - for (int channel = 0; channel < 4; ++channel) - { - store_data(module, //nb module - channel, //numero of channel - the_pixel, //numero of pixel - (DataType*) sca_rois, - nb_rois[channel] - ); - sca_rois += nb_rois[channel]; - //INFO_STREAM<<"nb_rois[channel] = "<<nb_rois[channel]<<endl; - } - - //m_current_pixel = the_pixel; - //DEBUG_STREAM << "\t- The pixel ["<<the_pixel<<"] is parsed & stored." <<std::endl; - //DEBUG_STREAM<<"DataStore::parse_mapping_sca_pixel() - [END]"<<std::endl; + //DEBUG_STREAM << "DataStore::process_data() - [END]" << std::endl; } //---------------------------------------------------------------------------------------------------------------------- diff --git a/src/DataStore.h b/src/DataStore.h index 804a32431ec6728f685c239a680ff25073e915c9..4a7ba026f2e48c606e3757d49ed895add69e974d 100644 --- a/src/DataStore.h +++ b/src/DataStore.h @@ -125,6 +125,9 @@ private: //------------------------------------------------------------------ class DataStore : public yat4tango::DeviceTask { + friend class DataParser; + friend class DataParserMapping; + friend class DataParserMca; public: ///ctor DataStore(Tango::DeviceImpl *dev); @@ -179,14 +182,8 @@ private: void on_abort(std::string status); ///process the data's buffer in order to get statistics & datas from the acquired buffer void on_process_data(DataBufferContainer& map_buffer); - ///parse datas for acquired mapping full buffer - void parse_mapping_full(DataBufferContainer& map_buffer); - ///parse datas for each acquired mapping full pixel - void parse_mapping_full_pixel(int module, int pixel, DataType* map_buffer); - ///parse datas for acquired mapping sca buffer - void parse_mapping_sca(DataBufferContainer& map_buffer); - ///parse datas for each acquired mapping sca pixel - void parse_mapping_sca_pixel(int module, int pixel, DataType* map_buffer); + //build the data buffer parser + DataParser* build_parser(const std::string& acq_mode); ///compute statistics double compute_realtime(double realtime); double compute_livetime(double livetime); @@ -212,6 +209,10 @@ private: double m_timebase; class Controller* m_controller; bool m_is_exception_stream_occured; + /// Parser object + yat::UniquePtr<DataParser> m_parser; + /// Owner Device server object + Tango::DeviceImpl* m_device; }; } diff --git a/src/SimulatorHelper.h b/src/SimulatorHelper.h index 2d5795d98e9ae8c48e2bb25629365e50af6c7473..e1a2604e37f30ff88548a84adb9db7d1068f25b2 100644 --- a/src/SimulatorHelper.h +++ b/src/SimulatorHelper.h @@ -44,10 +44,10 @@ const int NUMERIC_LOAD_CONIGURATION_DELAY_MS = 5000;//in ms //fix other parameters const int NUMERIC_NB_BINS = 2048; -const int NUMERIC_NB_SCA_ROIS = 64; +const int NUMERIC_NB_SCA_MAX = 64; const int NUMERIC_MCA_LENGTH = NUMERIC_NB_BINS; const int NUMERIC_BUFFER_LENGTH = BUFFER_HEADER_SIZE + PIXEL_HEADER_SIZE + 4 * NUMERIC_NB_BINS; -const int NUMERIC_BUFFER_LENGTH_SCA = BUFFER_HEADER_SIZE + PIXEL_HEADER_SIZE_SCA + 4 * NUMERIC_NB_SCA_ROIS; +const int NUMERIC_BUFFER_LENGTH_SCA = BUFFER_HEADER_SIZE + PIXEL_HEADER_SIZE_SCA + 4 * NUMERIC_NB_SCA_MAX; const double NUMERIC_DYNAMIC_RANGE = 3.0; const double NUMERIC_PEAKING_TIME = 2.0; const double NUMERIC_PRESET_VALUE = 4.0; //in s