Skip to content
Snippets Groups Projects
Commit 143171ac authored by Chao Peng's avatar Chao Peng
Browse files

adjust the decoding structure for multi-blocks data

parent 1206b192
No related branches found
No related tags found
No related merge requests found
#ifndef FADC250_DECODE_H #ifndef FADC250_DECODER_H
#define FADC250_DECODE_H #define FADC250_DECODER_H
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
...@@ -90,7 +90,7 @@ struct Fadc250Data ...@@ -90,7 +90,7 @@ struct Fadc250Data
}; };
void fadc250_decode_helper(uint32_t *buf, uint32_t &id, Fadc250Data &fadc, uint32_t type = FillerWord); void fadc250_decoder_helper(uint32_t *buf, uint32_t &id, Fadc250Data &fadc, uint32_t type = FillerWord);
void print_word(uint32_t word) void print_word(uint32_t word)
{ {
std::cout << "0x" << std::hex << std::setw(8) << std::setfill('0') << word << std::dec << "\n"; std::cout << "0x" << std::hex << std::setw(8) << std::setfill('0') << word << std::dec << "\n";
...@@ -117,7 +117,7 @@ inline uint32_t fill_in_words(uint32_t *buf, uint32_t beg, Container &raw_data, ...@@ -117,7 +117,7 @@ inline uint32_t fill_in_words(uint32_t *buf, uint32_t beg, Container &raw_data,
return nwords; return nwords;
} }
Fadc250Data fadc250_decode(uint32_t header, uint32_t *buf, uint32_t /* len */) Fadc250Data fadc250_decoder(uint32_t header, uint32_t *buf, uint32_t /* len */)
{ {
Fadc250Data res; Fadc250Data res;
...@@ -130,12 +130,12 @@ Fadc250Data fadc250_decode(uint32_t header, uint32_t *buf, uint32_t /* len */) ...@@ -130,12 +130,12 @@ Fadc250Data fadc250_decode(uint32_t header, uint32_t *buf, uint32_t /* len */)
res.blk_num = (header >> 8) & 0x3FF; res.blk_num = (header >> 8) & 0x3FF;
res.blk_nev = (header & 0xFF); res.blk_nev = (header & 0xFF);
uint32_t index = 0; uint32_t index = 0;
fadc250_decode_helper(buf, index, res); fadc250_decoder_helper(buf, index, res);
return res; return res;
} }
void fadc250_decode_helper(uint32_t *buf, uint32_t &id, Fadc250Data &fadc, uint32_t type) void fadc250_decoder_helper(uint32_t *buf, uint32_t &id, Fadc250Data &fadc, uint32_t type)
{ {
uint32_t data = buf[id]; uint32_t data = buf[id];
...@@ -227,7 +227,7 @@ void fadc250_decode_helper(uint32_t *buf, uint32_t &id, Fadc250Data &fadc, uint3 ...@@ -227,7 +227,7 @@ void fadc250_decode_helper(uint32_t *buf, uint32_t &id, Fadc250Data &fadc, uint3
} }
id++; id++;
fadc250_decode_helper(buf, id, fadc, type); fadc250_decoder_helper(buf, id, fadc, type);
} }
#endif // FADC250_DECODE_H #endif // FADC250_DECODER_H
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "TFile.h" #include "TFile.h"
#include "TH1.h" #include "TH1.h"
#include "simpleLib.h" #include "simpleLib.h"
#include "Fadc250Decode.h" #include "Fadc250Decoder.h"
#define FADC_BANK 3 #define FADC_BANK 3
...@@ -432,7 +432,7 @@ void write_raw_data(const std::string &dpath, const std::string &opath, int nev, ...@@ -432,7 +432,7 @@ void write_raw_data(const std::string &dpath, const std::string &opath, int nev,
evdata->LoadEvent(datafile.getEvBuffer()); evdata->LoadEvent(datafile.getEvBuffer());
evtype = evdata->GetEvType(); evtype = evdata->GetEvType();
if((++count % PROGRESS_COUNT) == 0) { if((count % PROGRESS_COUNT) == 0) {
std::cout << "Processed events - " << count << "\r" << std::flush; std::cout << "Processed events - " << count << "\r" << std::flush;
} }
...@@ -440,26 +440,28 @@ void write_raw_data(const std::string &dpath, const std::string &opath, int nev, ...@@ -440,26 +440,28 @@ void write_raw_data(const std::string &dpath, const std::string &opath, int nev,
continue; continue;
} }
// get block level
int blvl = 1;
simpleGetRocBlockLevel(modules.front().crate, FADC_BANK, &blvl);
int data_mode = -1;
for (int ii = 0; ii < blvl; ++ii) {
// clear data buffer // clear data buffer
for (auto &br : brdata) { for (auto &br : brdata) {
br.second.npul = 0; br.second.npul = 0;
br.second.nraw = 0; br.second.nraw = 0;
} }
// read data into event buffer // parse module data
int data_mode = -1;
for (auto &mod : modules) { for (auto &mod : modules) {
int blvl = 1;
simpleGetRocBlockLevel(mod.crate, FADC_BANK, &blvl);
uint32_t header = 0; uint32_t header = 0;
auto status = simpleGetSlotBlockHeader(mod.crate, FADC_BANK, mod.slot, &header); auto status = simpleGetSlotBlockHeader(mod.crate, FADC_BANK, mod.slot, &header);
if (status <= 0) { if (status <= 0) {
std::cout << "Error getting header for crate = " << mod.crate << ", slot = " << mod.slot << std::endl; std::cout << "Error getting header for crate = "
<< mod.crate << ", slot = " << mod.slot << std::endl;
continue; continue;
} }
for (int ii = 0; ii < blvl; ++ii) {
uint32_t *dbuf; uint32_t *dbuf;
auto len = simpleGetSlotEventData(mod.crate, FADC_BANK, mod.slot, ii, &dbuf); auto len = simpleGetSlotEventData(mod.crate, FADC_BANK, mod.slot, ii, &dbuf);
if (len <= 0) { if (len <= 0) {
...@@ -467,20 +469,21 @@ void write_raw_data(const std::string &dpath, const std::string &opath, int nev, ...@@ -467,20 +469,21 @@ void write_raw_data(const std::string &dpath, const std::string &opath, int nev,
<< ", block_level = " << ii << std::endl; << ", block_level = " << ii << std::endl;
continue; continue;
} }
auto slot_data = fadc250_decode(header, dbuf, len); auto slot_data = fadc250_decoder(header, dbuf, len);
// check data mode // check data mode
if (slot_data.GetMode() > 0 && data_mode < 0) { if (slot_data.GetMode() > 0 && data_mode < 0) {
data_mode = slot_data.GetMode(); data_mode = slot_data.GetMode();
} }
// fill branch data // fill branch data
fill_branch(slot_data, mod, brdata); fill_branch(slot_data, mod, brdata);
} }
}
// fill event
fill_tree(tree, brdata, init_tree, data_mode); fill_tree(tree, brdata, init_tree, data_mode);
count ++;
// output csv file
if (wpath.empty()) { continue; } if (wpath.empty()) { continue; }
output << count; output << count;
for (auto &mod : modules) { for (auto &mod : modules) {
...@@ -495,6 +498,8 @@ void write_raw_data(const std::string &dpath, const std::string &opath, int nev, ...@@ -495,6 +498,8 @@ void write_raw_data(const std::string &dpath, const std::string &opath, int nev,
} }
output << std::endl; output << std::endl;
} }
}
std::cout << "Processed events - " << count << std::endl; std::cout << "Processed events - " << count << std::endl;
hfile->Write(); hfile->Write();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment