diff --git a/config/offline_monitor.conf b/config/offline_monitor.conf index 09f3d14f92f584c957556826d248971658e84852..a04be81e09e225167fc50d9c0981ae6f4cc024db 100644 --- a/config/offline_monitor.conf +++ b/config/offline_monitor.conf @@ -1,8 +1,8 @@ # configuration for online monitoring -host = clrlpc.jlab.org +host = chpc11.jlab.org port = 11111 -etfile = /tmp/et_test +etfile = /tmp/et_tcd modules = ${THIS_DIR}/esb_module.conf output = ${THIS_DIR}/../processed_data/offline.root diff --git a/include/utils.h b/include/utils.h index db158a6b4ca81095306a0a1d137a8991f7ed8104..fc6777e7e6795de717a5e99973bbe6964f5b9442 100644 --- a/include/utils.h +++ b/include/utils.h @@ -17,6 +17,10 @@ struct BranchData float integral[MAX_NPEAKS], peak[MAX_NPEAKS], time[MAX_NPEAKS]; int raw[MAX_RAW]; float ped_mean, ped_err; + + + BranchData() : npul(0), nraw(0), ped_mean(0.), ped_err(0.) {} + void Reset() { npul = 0; nraw = 0; ped_mean = 0.; ped_err = 0.; } }; enum ModuleType diff --git a/online/monitor.cxx b/online/monitor.cxx index a2e3dbb29fd6a705d40b6ded81f40d96d9bf467d..f72a2e2c989a6247872e6fcad7eae9668a4d979c 100644 --- a/online/monitor.cxx +++ b/online/monitor.cxx @@ -38,61 +38,6 @@ uint32_t swap_endian32(uint32_t num) return b0 | b1 | b2 | b3; } -uint32_t parseBlock(const uint32_t *buf) -{ - auto header = (ETChannel::CodaEvHeader*) buf; - const uint32_t buf_size = header->length + 1; - std::cout << "ROC header: " << std::dec << buf_size << "\n" - << (int) header->etype << ", " << (int) header->dtype << ", " << (int) header->num - << std::endl; - std::cout << std::hex; - for (uint32_t i = 0; i < buf_size; ++i) { - std::cout << "0x" << std::setw(8) << std::setfill('0') << buf[i] << "\n"; - } - return buf_size; -} - -// parse an evio event -bool parseEvent(const uint32_t *buf, bool verbose = false) -{ - auto header = (ETChannel::CodaEvHeader*)buf; - const uint32_t buf_size = header->length + 1; - if (verbose) { - std::cout << "Event header: " << std::dec << buf_size << "\n" - << (int) header->etype << ", " << (int) header->dtype << ", " << (int) header->num - << std::endl; - std::cout << std::hex; - for (uint32_t i = 0; i < 2; ++i) { - std::cout << "0x" << std::setw(8) << std::setfill('0') << buf[i] << "\n"; - } - } - - switch(header->etype) { - case ETChannel::CODA_PHY1: - case ETChannel::CODA_PHY2: - break; - case ETChannel::CODA_PRST: - case ETChannel::CODA_GO: - case ETChannel::CODA_END: - default: - return false; - } - - simpleScan((volatile uint32_t*)buf, buf_size); - return true; - - /* - // parse ROC data - uint32_t index = 2; - while(index < buf_size) { - // skip header size and data size 2 + (length - 1) - index += parseBlock(&buf[index]); - } - - // return parsed event type - return buf_size; - */ -} #define BUF_SIZE 1000 static double buffer[BUF_SIZE], wfbuf[BUF_SIZE], bkbuf[BUF_SIZE]; @@ -232,13 +177,11 @@ void fill_tree(TTree *tree, std::unordered_map<std::string, BranchData> &brdata, tree->Branch((n + "_Pint").c_str(), &brdata[n].integral[0], (n + "_Pint[" + n + "_N]/F").c_str()); tree->Branch((n + "_Ptime").c_str(), &brdata[n].time[0], (n + "_Ptime[" + n + "_N]/F").c_str()); // raw waveform provides more information - if (mode == 1) { - tree->Branch((n + "_Ppeak").c_str(), &brdata[n].peak[0], (n + "_Ppeak[" + n + "_N]/F").c_str()); - tree->Branch((n + "_Nraw").c_str(), &brdata[n].nraw, (n + "_Nraw/I").c_str()); - tree->Branch((n + "_raw").c_str(), &brdata[n].raw[0], (n + "_raw[" + n + "_Nraw]/I").c_str()); - tree->Branch((n + "_ped_mean").c_str(), &brdata[n].ped_mean, (n + "_ped_mean/F").c_str()); - tree->Branch((n + "_ped_err").c_str(), &brdata[n].ped_err, (n + "_ped_err/F").c_str()); - } + tree->Branch((n + "_Ppeak").c_str(), &brdata[n].peak[0], (n + "_Ppeak[" + n + "_N]/F").c_str()); + tree->Branch((n + "_Nraw").c_str(), &brdata[n].nraw, (n + "_Nraw/I").c_str()); + tree->Branch((n + "_raw").c_str(), &brdata[n].raw[0], (n + "_raw[" + n + "_Nraw]/I").c_str()); + tree->Branch((n + "_ped_mean").c_str(), &brdata[n].ped_mean, (n + "_ped_mean/F").c_str()); + tree->Branch((n + "_ped_err").c_str(), &brdata[n].ped_err, (n + "_ped_err/F").c_str()); } init = true; std::cout << "Initialized root file for mode " << mode << " data." << std::endl; @@ -251,7 +194,37 @@ void fill_tree(TTree *tree, std::unordered_map<std::string, BranchData> &brdata, void processEvent(const uint32_t *buf, int &count, TTree *tree, bool &init_tree, int &data_mode, const std::vector<Module> &modules, std::unordered_map<std::string, BranchData> &brdata) { - if (!parseEvent(buf, false)) { + auto header = (ETChannel::CodaEvHeader*) buf; + const uint32_t buf_size = header->length + 1; + + /* + std::cout << "Event header: " << std::dec << buf_size << "\n" + << (int) header->etype << ", " << (int) header->dtype << ", " << (int) header->num + << std::endl; + std::cout << std::hex; + for (uint32_t i = 0; i < 2; ++i) { + std::cout << "0x" << std::setw(8) << std::setfill('0') << buf[i] << "\n"; + } + */ + + switch(header->etype) { + case ETChannel::CODA_PHY1: + case ETChannel::CODA_PHY2: + simpleScan((volatile uint32_t*)buf, buf_size); + break; + case ETChannel::CODA_GO: + // reset for new run + tree->Reset(); + data_mode = -1; + for (auto &br : brdata) { + br.second.Reset(); + } + count = 0; + std::cout << "New run started, clear all previous events." << std::endl; + return; + case ETChannel::CODA_PRST: + case ETChannel::CODA_END: + default: return; } @@ -262,8 +235,7 @@ void processEvent(const uint32_t *buf, int &count, TTree *tree, bool &init_tree, for (int ii = 0; ii < blvl; ++ii) { // clear data buffer for (auto &br : brdata) { - br.second.npul = 0; - br.second.nraw = 0; + br.second.Reset(); } // parse module data @@ -374,7 +346,7 @@ void monitor(const std::string &cpath = "config/online_monitor.conf") switch (status) { case ETChannel::READ_ERROR: case ETChannel::READ_EOF: - term = 1; + // term = 1; break; case ETChannel::READ_EMPTY: std::cout << "ET station is empty, wait 2 secs..." << std::endl; diff --git a/src/esb_analyze.cpp b/src/esb_analyze.cpp index a988b8e7b2c8eec1cba9a885adbffd84134876c4..f82a05a2e8e233fa2a4da26f3930c81127bd2b77 100644 --- a/src/esb_analyze.cpp +++ b/src/esb_analyze.cpp @@ -155,16 +155,6 @@ int main(int argc, char* argv[]) } -#define MAX_NPEAKS 20 -#define MAX_RAW 300 -struct BranchData -{ - int npul, nraw; - float integral[MAX_NPEAKS], peak[MAX_NPEAKS], time[MAX_NPEAKS]; - int raw[MAX_RAW]; - float ped_mean, ped_err; -}; - #define BUF_SIZE 1000 static double buffer[BUF_SIZE], wfbuf[BUF_SIZE], bkbuf[BUF_SIZE]; void refine_pedestal(const std::vector<uint32_t> &raw, float &ped_mean, float &ped_err) @@ -363,8 +353,7 @@ void write_raw_data(const std::string &dpath, const std::string &opath, int nev, for (int ii = 0; ii < blvl; ++ii) { // clear data buffer for (auto &br : brdata) { - br.second.npul = 0; - br.second.nraw = 0; + br.second.Reset(); } // parse module data