From 848c033b2800b5293e003b0474516021e22b6acf Mon Sep 17 00:00:00 2001 From: Adrien Laviron <adrien.laviron@csnsm.in2p3.fr> Date: Wed, 11 Nov 2020 01:35:45 +0100 Subject: [PATCH] DecodeD seem to be accessing root-type data now --- .../ComptonTelescope/online/src/DecodeD.cpp | 114 +++++++++++++++++- .../ComptonTelescope/online/src/DecodeD.h | 56 +++++++++ .../ComptonTelescope/online/src/online.cpp | 15 ++- 3 files changed, 182 insertions(+), 3 deletions(-) diff --git a/Projects/ComptonTelescope/online/src/DecodeD.cpp b/Projects/ComptonTelescope/online/src/DecodeD.cpp index 2235c1981..9f351966b 100644 --- a/Projects/ComptonTelescope/online/src/DecodeD.cpp +++ b/Projects/ComptonTelescope/online/src/DecodeD.cpp @@ -3,9 +3,119 @@ DecodeD::DecodeD(bool v) { verbose = v; + cursor = 0; + datatype = D_NONE; + t1 = 0; + length = 0; } DecodeD::~DecodeD() -{ } +{ + switch (datatype) { + case D_ROOT: + delete t1; + break; + case D_MFM: + break;//TBR + } +} + +void DecodeD::setTree(const char* filename) +{ + datatype = D_ROOT; + cursor = 0; + TFile* f = new TFile(filename); + t1 = (TTree*)f->Get("Events"); + length = t1 -> GetEntries(); + if (verbose) { cout << "Length of loaded tree: " << length << endl; } + t1->SetBranchAddress("chip_data", &event.chip_data); + t1->SetBranchAddress("analog_trigger", &event.analog_trigger); + t1->SetBranchAddress("seu", &event.seu); + t1->SetBranchAddress("ch_status", &event.ch_status); + t1->SetBranchAddress("ref_channel", &event.ref_channel); + t1->SetBranchAddress("sample", &event.sample); + t1->SetBranchAddress("cm_data", &event.cm_data); + t1->SetBranchAddress("timestamp", &event.timestamp); +} + +void DecodeD::setRaw() +{ + datatype = D_MFM; +} + +long int DecodeD::getCursor() +{ + return cursor; +} + +long int DecodeD::getLength() +{ + return length; +} + +newframe_t* DecodeD::getEvent() +{ + return &event; +} + +void DecodeD::decodeEvent() +{ + switch (datatype) { + case D_ROOT: + if (cursor < length) { + t1->GetEntry(cursor); +// for (int i = 0; i < 3; i++) { + // for (int j = 0; i < 8; j++) { +/* int i = 0; int j = 0; + event.chip_data[i][j] = chip_data[i][j]; + event.analog_trigger[i][j] = analog_trigger[i][j]; + event.seu[i][j] = seu[i][j]; + event.ch_status[i][j] = ch_status[i][j]; + event.ref_channel[i][j] = ref_channel[i][j]; + event.cm_data[i][j] = cm_data[i][j]; + for (int k = 0; k<32; k++) { + event.sample[i][j][k] = sample[i][j][k]; + } +// } + // } + event.timestamp = *timestamp;*/ + cursor++; + } + break; + case D_MFM: + break; + case D_NONE: + cout << "No data has been set to decode" << endl; + } +} + +void DecodeD::Dump() +{ + cout << "Datatype: " << datatype << " means "; + switch (datatype) { + case D_ROOT: + cout << "ROOT" << endl; + break; + case D_MFM: + cout << "MFM" << endl; + break; + case D_NONE: + cout << "no data has been set" << endl; + return; + } + cout << "Timestamp: " << event.timestamp << endl; + cout << "Chip data\tanalog trigger\tseu\tchannel status\tref channel\tcm data" << endl; + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 8; j++) { + cout << (int)event.chip_data[i][j] << "\t" << (int)event.analog_trigger[i][j] << "\t" << (int)event.seu[i][j] << "\t" << (int)event.ch_status[i][j] << "\t" << (int)event.ref_channel[i][j] << "\t" << (int)event.cm_data[i][j] << endl; + cout << "Samples: "; + for (int k = 0; k<32; k++) { + cout << event.sample[i][j][k] << " "; + } + cout << endl; + } + } +} + + -//DecodeD:: diff --git a/Projects/ComptonTelescope/online/src/DecodeD.h b/Projects/ComptonTelescope/online/src/DecodeD.h index 1f7e76763..2f2014e4c 100644 --- a/Projects/ComptonTelescope/online/src/DecodeD.h +++ b/Projects/ComptonTelescope/online/src/DecodeD.h @@ -11,15 +11,71 @@ using namespace std; #include "TFile.h" #include "TTree.h" +enum Datatype {D_NONE = 0, D_ROOT, D_MFM}; + +typedef struct { + uint8_t chain; // Chain Number (0 or 1) + uint8_t nb_asic; // ASIC Number + uint8_t chip_data; // 0=Empty Frame; + uint8_t analog_trigger; + uint8_t seu; + uint32_t ch_status; + uint16_t ref_channel; + uint16_t sample[32]; + uint16_t cm_data; + uint32_t timestamp; +} frame_t; + +typedef struct +{ + uint8_t chip_data[3][8]; + uint8_t analog_trigger[3][8]; + uint8_t seu[3][8]; + uint32_t ch_status[3][8]; + uint16_t ref_channel[3][8]; + uint16_t sample[3][8][32]; + uint16_t cm_data[3][8]; + uint32_t timestamp; +} newframe_t; class DecodeD { private: bool verbose; + Datatype datatype; + long int cursor; + newframe_t event; + + // For root data + TTree* t1; + long int length; + uint8_t** chip_data; + uint8_t** analog_trigger; + uint8_t** seu; + uint32_t** ch_status; + uint16_t** ref_channel; + uint16_t*** sample; + uint16_t** cm_data; + uint32_t* timestamp; + + // For online data public: DecodeD(bool v); ~DecodeD(); + + void setTree(const char* filename); + void setRaw(); + + long int getCursor(); + long int getLength(); + newframe_t* getEvent(); + // One may add a few getters here and deprecate getEvent to avoid requiring the class user to know the newframe_t struct + + void decodeEvent(); + + void Dump(); }; #endif + diff --git a/Projects/ComptonTelescope/online/src/online.cpp b/Projects/ComptonTelescope/online/src/online.cpp index 33248e241..29a1dac79 100644 --- a/Projects/ComptonTelescope/online/src/online.cpp +++ b/Projects/ComptonTelescope/online/src/online.cpp @@ -79,7 +79,20 @@ int main() is.close(); i++; - // Read from file(s) + // Read from file + DD -> setTree("20200128_10h44_bi207_conv.root"); +// DD -> decodeEvent(); +// DD -> Dump(); + int dlength = DD -> getLength(); + newframe_t* event; + while (DD -> getCursor() < dlength) + { + DD -> decodeEvent(); + event = DD -> getEvent(); + //Fill TComptonTelescopeData here (if possible) + } + + // Read from file D -> setRaw(buffer); D -> decodeRawMFM(); // get rid of the first two (empty) events -- GitLab