Skip to content

Commit

Permalink
filter, eudaq writer and doc
Browse files Browse the repository at this point in the history
  • Loading branch information
frankscu committed Aug 23, 2018
2 parents 25538d9 + 24fd186 commit e1615dd
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 83 deletions.
18 changes: 18 additions & 0 deletions doc/eudaq_run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# EUDAQ with JadePix Run

## ENV setting

```
export EUDAQ_MODULE_DIR="/home/cepcdaq/JadePix/kc705/lib"
export PATH="/home/cepcdaq/JadePix/eudaq/bin:${PATH}"
export PATH="/home/cepcdaq/JadePix/kc705/bin:${PATH}"
``
## Running process
```
euCliProducer -n JadeProducer -t jade
euCliProducer -n TluProducer -t tlu
euCliCollector -n TriggerIDSyncDataCollector -t tgid
StdEventMonitor -r tcp://localhost:44000 -t my_mon
```
39 changes: 39 additions & 0 deletions software/conf/eudaq_conf/Ex0.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# example config file: Ex0.conf
[RunControl]
EX0_STOP_RUN_AFTER_N_SECONDS=60
EUDAQ_CTRL_PRODUCER_LAST_START=tlu

[DataCollector.tgid]
EUDAQ_MN=my_mon
EUDAQ_FW=native
EUDAQ_FW_PATTERN=/home/cepcdaq/data/run$3R_$12D$X
EX0_DISABLE_PRINT=1
DISABLE_PRINT=1

[Monitor.my_mon]
EX0_ENABLE_PRINT=0
EX0_ENABLE_STD_PRINT=0
EX0_ENABLE_STD_CONVERTER=1

[Producer.jade]
EUDAQ_DC=tgid

[Producer.tlu]
EUDAQ_DC=tgid
# Auto trigger with interval in units of ms
TriggerInterval = 1
# Activate DUT Channel 0 -> only telescope
DutMask = 1
# Don't power PMTs: Set Control Voltage to 0 mV
PMTVcntl1 = 0
PMTVcntl2 = 0
PMTVcntl3 = 0
PMTVcntl4 = 0

[Producer.MimosaNI]
EUDAQ_DC=tgid
# Set here the local IP of the NI crate on which MimosaDAQ (Anemone LV) is running
NiIPaddr = 192.168.22.2
#TriggerType = 1
Det = MIMOSA26
Mode = ZS2
4 changes: 4 additions & 0 deletions software/conf/eudaq_conf/Ex0.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# example init file: Ex0.ini
[Producer.jade]
JSON_PATH=/home/cepcdaq/JadePix/kc705/software/conf/sample_summer_tlu.json

2 changes: 1 addition & 1 deletion software/conf/sample_summer_tlu.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
},
"JadeWriter":{
"type":"CdsWriter",
"type":"EudaqWriter",
"parameter":{
"PATH":"/home/cepcdaq/data/test_producer",
"DISABLE_FILE_WRITE":false
Expand Down
6 changes: 3 additions & 3 deletions software/lib/core/include/JadeDataFrame.hh
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ class DLLEXPORT JadeDataFrame {
uint32_t GetMatrixHighY() const;
uint32_t GetMatrixSizeX() const; //x row, y column
uint32_t GetMatrixSizeY() const;
uint32_t GetTriggerSerialOrder() const;
uint32_t GetTriggerExtension() const;
uint32_t GetTriggerN() const;
uint32_t GetExtension() const;
void Print(std::ostream& os, size_t ws = 0) const;

private:
private:
bool m_is_decoded;
std::string m_data_raw;
std::string m_description;
Expand Down
27 changes: 12 additions & 15 deletions software/lib/core/src/CdsFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,24 @@ CdsFilter::CdsFilter(const JadeOption& opt)
{
}

JadeDataFrameSP CdsFilter::Filter(JadeDataFrameSP df)
{
//std::cout<<"filtering"<<std::endl;
//if (!m_df_last) {
// m_df_last = df;
// std::cout << "first data arrives" << std::endl;
// return nullptr;
//}

//if(m_df_last->GetFrameCount() +1 != df->GetFrameCount()){
auto trigger_serial_order = df->GetTriggerSerialOrder();
if (trigger_serial_order == 0) {
JadeDataFrameSP CdsFilter::Filter(JadeDataFrameSP df){
if(!m_df_last){
m_df_last = df;
return nullptr;
}

if(df->GetTriggerN() != m_df_last->GetTriggerN()){
if(df->GetExtension()!= 0){
std::cerr<<"CdsFilter: in the first dataframe of new triiger number, the extension word is not zero\n";
throw;
}
m_df_last = df;
//std::cout << "FrameCount mismatch, skipped" << std::endl;
return nullptr;
}

//TODO, reuse the memory of m_df_last, since it will be delelted soon
JadeDataFrameSP df_cds = JadeDataFrame::CdsAndReturnNewObject(*m_df_last, *df);
m_df_last = df;
return df_cds;
return df_cds;
}

void CdsFilter::Reset()
Expand Down
1 change: 1 addition & 0 deletions software/lib/core/src/CdsWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void CdsWriter::Write(JadeDataFrameSP df){
std::cerr<<"JadeWrite: File is not opened/created before writing\n";
throw;
}

auto& data = df->Data();
if(data.size()){
std::fwrite(reinterpret_cast<char*>(&(data[0])), 2, data.size(), m_fd);
Expand Down
26 changes: 11 additions & 15 deletions software/lib/core/src/JadeDataFrame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@ JadeDataFrame::JadeDataFrame(std::string& data)
{
}

// JadeDataFrame::JadeDataFrame(size_t nraw)
// : m_is_decoded(false)
// , m_is_cds(false)
// , m_n_x(0)
// , m_n_y(0)
// {
// m_data_raw.resize(nraw);
// }

JadeDataFrame::~JadeDataFrame()
{
Expand Down Expand Up @@ -115,12 +107,12 @@ uint32_t JadeDataFrame::GetMatrixSizeY() const
return m_n_y;
}

uint32_t JadeDataFrame::GetTriggerSerialOrder() const
uint32_t JadeDataFrame::GetTriggerN() const
{
return m_trigger_n;
}

uint32_t JadeDataFrame::GetTriggerExtension() const
uint32_t JadeDataFrame::GetExtension() const
{
return m_extension;
}
Expand All @@ -135,7 +127,7 @@ void JadeDataFrame::Decode()
const char* p_raw = m_data_raw.data();
size_t p_offset = 0;
uint32_t len_raw = LE32TOH(*reinterpret_cast<const uint32_t*>(p_raw + p_offset));
// Matrix A: size=1936
// Matrix A: size=1936
// Matrix B: size=3856
if(len_raw == 1936){
m_n_x = 16;
Expand All @@ -147,7 +139,7 @@ void JadeDataFrame::Decode()
std::cerr << "JadeDataFrame: raw data length does not match\n";
throw;
}
p_offset += 4;
p_offset +=4;

m_data.clear();
m_data.resize(m_n_x * m_n_y, 0);
Expand All @@ -158,10 +150,10 @@ void JadeDataFrame::Decode()
throw;
}
p_offset += 4;
m_trigger_n = LE16TOH(*reinterpret_cast<const uint16_t*>(p_raw + p_offset));
p_offset += 2;
m_extension = LE16TOH(*reinterpret_cast<const uint16_t*>(p_raw + p_offset));
p_offset += 2;
m_trigger_n = LE16TOH(*reinterpret_cast<const uint16_t*>(p_raw + p_offset));
p_offset += 2;

int16_t* p_data = m_data.data();
bool is_first_row = true;
Expand Down Expand Up @@ -263,6 +255,7 @@ void JadeDataFrame::Print(std::ostream& os, size_t ws) const
JadeDataFrameSP JadeDataFrame::CdsAndReturnNewObject(const JadeDataFrame& earlier,
const JadeDataFrame& later)
{

JadeDataFrameSP dfsp(new JadeDataFrame(""));
auto& df = *dfsp;
auto& data_cds_result = df.Data();
Expand All @@ -272,9 +265,12 @@ JadeDataFrameSP JadeDataFrame::CdsAndReturnNewObject(const JadeDataFrame& earlie
std::transform(data_later.begin(), data_later.end(), data_earlier.begin(),
data_cds_result.begin(),
std::minus<int16_t>());
df.m_is_decoded = later.m_is_decoded;
df.m_is_decoded = true;
df.m_description = later.m_description + "+CDS";
df.m_ts = later.m_ts;
df.m_trigger_n = later.m_trigger_n;
df.m_extension = later.m_extension;
df.m_ts = later.m_ts;
df.m_frame_n = later.m_frame_n;
df.m_n_x = later.m_n_x;
df.m_n_y = later.m_n_y;
Expand Down
3 changes: 3 additions & 0 deletions software/lib/core/src/TestManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,7 @@ std::string TestManager::SendCommand(const std::string& cmd, const std::string&
JadeUtils::FormatString("{\"PRINT_EVENT_N\":%u}", std::stoul(para)));
return "";
}

std::cout<<"TestManager:: no match command processing"<<std::endl;
return "";
}
48 changes: 33 additions & 15 deletions software/lib/eudaq/src/JadeProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ class EudaqWriter: public JadeWriter {
EudaqWriter(const JadeOption &opt);
~EudaqWriter() override;
void Write(JadeDataFrameSP df) override;
JadeOption Post(const std::string &url, const JadeOption &opt) override;
void Close() override;

JadeOption Post(const std::string &url, const JadeOption &opt) override;
void SetProducerCallback(eudaq::Producer *producer);
private:
eudaq::Producer *m_producer;
eudaq::EventUP m_evup_to_send;
};

//+++++++++++++++++++++++++++++++++++++++++
Expand Down Expand Up @@ -53,23 +55,37 @@ JadeOption EudaqWriter::Post(const std::string &url, const JadeOption &opt){
return JadePost::Post(url, opt);
}

void EudaqWriter::Close(){
m_evup_to_send.reset();
}

void EudaqWriter::Write(JadeDataFrameSP df){
if(m_producer){
auto ev = eudaq::Event::MakeUnique("JadeRaw");
ev->SetTriggerN(df->GetFrameCount());

std::vector<uint16_t> v_info;
v_info.push_back(df->GetMatrixSizeX());
v_info.push_back(df->GetMatrixSizeY());
v_info.push_back(df->GetTriggerExtension());
v_info.push_back(df->GetTriggerSerialOrder());
ev->AddBlock<uint16_t>((uint32_t)0, v_info);

ev->AddBlock<int16_t>((uint32_t)1, df->Data());
if(m_producer)
m_producer->SendEvent(std::move(ev));
if(!m_producer){
std::cerr<<"EudaqWriter: ERROR, eudaq producer is not avalible";
throw;
}

if(m_evup_to_send){ //1st CDS frame exists in evup
if(m_evup_to_send->GetTriggerN() == df->GetTriggerN()){
m_evup_to_send->AddBlock<int16_t>((uint32_t)2, df->Data());
m_producer->SendEvent(std::move(m_evup_to_send));
return;
}
else{
std::cout<<"EudaqWriter: WARNING, current CDS has different trigger number to the existing CDS"<<std::endl;
// m_producer->SendEvent(std::move(m_evup_to_send));
throw;
}
}

m_evup_to_send = eudaq::Event::MakeUnique("JadeRaw");
m_evup_to_send->SetTriggerN(df->GetTriggerN());

std::vector<uint16_t> v_info;
v_info.push_back(df->GetMatrixSizeX());
v_info.push_back(df->GetMatrixSizeY());
m_evup_to_send->AddBlock<uint16_t>((uint32_t)0, v_info);
m_evup_to_send->AddBlock<int16_t>((uint32_t)1, df->Data());
}

class JadeProducer : public eudaq::Producer {
Expand Down Expand Up @@ -131,6 +147,8 @@ void JadeProducer::DoStartRun(){

void JadeProducer::DoStopRun(){
m_jade_man->StopDataTaking();

std::cout<< "xxxxxxxxxxxxxxxxxxxxxxxx" <<std::endl;
}

void JadeProducer::DoReset(){
Expand Down
48 changes: 27 additions & 21 deletions software/lib/eudaq/src/JadeRawEvent2LCEventConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include "IMPL/TrackerDataImpl.h"
#include "UTIL/CellIDEncoder.h"


#define PLANE_ID_OFFSET_LICO 200

class JadeRawEvent2LCEventConverter: public eudaq::LCEventConverter{
typedef std::vector<uint8_t>::const_iterator datait;
public:
Expand Down Expand Up @@ -32,12 +35,6 @@ bool JadeRawEvent2LCEventConverter::Converting(eudaq::EventSPC d1, eudaq::LCEven
uint16_t x_n_pixel = *data_info;
uint16_t y_n_pixel = *(data_info+1);
uint32_t n_pixel = x_n_pixel * y_n_pixel;

std::vector<uint8_t> block_decoded = ev->GetBlock(1);
uint16_t *data_decoded = reinterpret_cast<uint16_t*>( block_decoded.data());
if(block_decoded.size() || block_decoded.size() != n_pixel *2 ){
EUDAQ_THROW("Unknown data, pixel size mismatch");
}

lcio::LCCollectionVec *zsDataCollection = nullptr;
auto p_col_names = d2->getCollectionNames();
Expand All @@ -49,24 +46,33 @@ bool JadeRawEvent2LCEventConverter::Converting(eudaq::EventSPC d1, eudaq::LCEven
else{
zsDataCollection = new lcio::LCCollectionVec(lcio::LCIO::TRACKERDATA);
d2->addCollection(zsDataCollection, "zsdata_jade");
}
}

for(auto bn: block_n_list){
if(bn == 0){
//info block
continue;
}
std::vector<uint8_t> block_decoded = ev->GetBlock(bn);
uint16_t *data_decoded = reinterpret_cast<uint16_t*>( block_decoded.data());
if(block_decoded.size() || block_decoded.size() != n_pixel *2 ){
EUDAQ_THROW("Unknown data, pixel size mismatch");
}

lcio::CellIDEncoder<lcio::TrackerDataImpl> zsDataEncoder("sensorID:7,sparsePixelType:5",
lcio::CellIDEncoder<lcio::TrackerDataImpl> zsDataEncoder("sensorID:7,sparsePixelType:5",
zsDataCollection);
//NOTE: is "sensorID:7,sparsePixelType:5" going to be overwritten?
//the meaning sparsePixelType
zsDataEncoder["sensorID"] = 100;
zsDataEncoder["sparsePixelType"] = 2;
auto zsFrame = new lcio::TrackerDataImpl;
zsDataEncoder.setCellID(zsFrame);
zsDataEncoder["sensorID"] = PLANE_ID_OFFSET_LICO + bn;
zsDataEncoder["sparsePixelType"] = 2;
auto zsFrame = new lcio::TrackerDataImpl;
zsDataEncoder.setCellID(zsFrame);

for(uint32_t i = 0; i< n_pixel; i++){
zsFrame->chargeValues().push_back(i%x_n_pixel);//x
zsFrame->chargeValues().push_back(i/x_n_pixel);//y
zsFrame->chargeValues().push_back(*(data_decoded+i));//signal
zsFrame->chargeValues().push_back(0);//time
for(uint32_t i = 0; i< n_pixel; i++){
zsFrame->chargeValues().push_back(i%x_n_pixel);//x
zsFrame->chargeValues().push_back(i/x_n_pixel);//y
zsFrame->chargeValues().push_back(*(data_decoded+i));//signal
zsFrame->chargeValues().push_back(0);//time
}
zsDataCollection->push_back(zsFrame);
}

zsDataCollection->push_back(zsFrame);
return true;
}
Loading

0 comments on commit e1615dd

Please sign in to comment.