Commit c00fa28b authored by minime's avatar minime
Browse files

Fixed bug in decoding 0xFFFF bx_counter / added ResetMask / added ResetTDAC /...

Fixed bug in decoding 0xFFFF bx_counter / added ResetMask / added ResetTDAC / packed commands per hybrid
parent ae8a615d
......@@ -781,55 +781,57 @@ void RD53FWInterface::ReadNEvents(BeBoard* pBoard, uint32_t pNEvents, std::vecto
// ##########################################
// # Use of OpenMP (compiler flag -fopenmp) #
// ##########################################
uint16_t RD53FWInterface::DecodeEventsMultiThreads (const std::vector<uint32_t>& data,
std::vector<RD53FWInterface::Event>& events)
uint16_t RD53FWInterface::DecodeEventsMultiThreads(const std::vector<uint32_t>& data, std::vector<RD53FWInterface::Event>& events)
{
// ######################
// # Consistency checks #
// ######################
if (data.size() == 0) return RD53FWEvtEncoder::EMPTY;
uint16_t evtStatus = RD53FWEvtEncoder::GOOD;
// ######################
// # Consistency checks #
// ######################
if(data.size() == 0) return RD53FWEvtEncoder::EMPTY;
std::vector<size_t> eventStart;
for (auto i = 0u; i < data.size(); i++)
if (data[i] >> RD53FWEvtEncoder::NBIT_BLOCKSIZE == RD53FWEvtEncoder::EVT_HEADER) eventStart.push_back(i);
if (eventStart.size() == 0) return RD53FWEvtEncoder::NOHEADER;
const auto nEvents = ceil(static_cast<double>(eventStart.size()) / omp_get_max_threads());
eventStart.push_back(data.size());
uint16_t evtStatus = RD53FWEvtEncoder::GOOD;
std::vector<size_t> eventStart;
size_t i = 0u;
while(i < data.size())
if(data[i] >> RD53FWEvtEncoder::NBIT_BLOCKSIZE == RD53FWEvtEncoder::EVT_HEADER)
{
eventStart.push_back(i);
i += RD53FWEvtEncoder::EVT_HEADER_SIZE;
}
else
i++;
if(eventStart.size() == 0) return RD53FWEvtEncoder::NOHEADER;
const auto nEvents = ceil(static_cast<double>(eventStart.size()) / omp_get_max_threads());
eventStart.push_back(data.size());
// ######################
// # Unpack data vector #
// ######################
#pragma omp parallel
// ######################
// # Unpack data vector #
// ######################
#pragma omp parallel
{
std::vector<RD53FWInterface::Event> vecEvents;
std::vector<size_t> vecEventStart;
std::vector<RD53FWInterface::Event> vecEvents;
std::vector<size_t> vecEventStart;
if (eventStart.begin() + nEvents * omp_get_thread_num() < eventStart.end())
if(eventStart.begin() + nEvents * omp_get_thread_num() < eventStart.end())
{
auto firstEvent = eventStart.begin() + nEvents * omp_get_thread_num();
auto lastEvent = firstEvent + nEvents + 1 < eventStart.end() ? firstEvent + nEvents + 1 : eventStart.end();
std::move(firstEvent, lastEvent, std::back_inserter(vecEventStart));
uint16_t status = RD53FWInterface::DecodeEvents(data, vecEvents, vecEventStart);
auto firstEvent = eventStart.begin() + nEvents * omp_get_thread_num();
auto lastEvent = firstEvent + nEvents + 1 < eventStart.end() ? firstEvent + nEvents + 1 : eventStart.end();
std::move(firstEvent, lastEvent, std::back_inserter(vecEventStart));
#pragma omp atomic
evtStatus |= status;
uint16_t status = RD53FWInterface::DecodeEvents(data, vecEvents, vecEventStart);
#pragma omp atomic
evtStatus |= status;
// #####################
// # Pack event vector #
// #####################
#pragma omp critical
std::move(vecEvents.begin(), vecEvents.end(), std::back_inserter(events));
// #####################
// # Pack event vector #
// #####################
#pragma omp critical
std::move(vecEvents.begin(), vecEvents.end(), std::back_inserter(events));
}
}
return evtStatus;
return evtStatus;
}
*/
uint16_t RD53FWInterface::DecodeEventsMultiThreads(const std::vector<uint32_t>& data, std::vector<RD53FWInterface::Event>& events)
......@@ -847,8 +849,15 @@ uint16_t RD53FWInterface::DecodeEventsMultiThreads(const std::vector<uint32_t>&
std::vector<std::vector<size_t>> vecEventStart(RD53Shared::NTHREADS);
std::vector<size_t> eventStart;
for(auto i = 0u; i < data.size(); i++)
if(data[i] >> RD53FWEvtEncoder::NBIT_BLOCKSIZE == RD53FWEvtEncoder::EVT_HEADER) eventStart.push_back(i);
size_t i = 0u;
while(i < data.size())
if(data[i] >> RD53FWEvtEncoder::NBIT_BLOCKSIZE == RD53FWEvtEncoder::EVT_HEADER)
{
eventStart.push_back(i);
i += RD53FWEvtEncoder::EVT_HEADER_SIZE;
}
else
i++;
if(eventStart.size() == 0) return RD53FWEvtEncoder::NOHEADER;
const auto nEvents = ceil(static_cast<double>(eventStart.size()) / RD53Shared::NTHREADS);
eventStart.push_back(data.size());
......@@ -856,8 +865,7 @@ uint16_t RD53FWInterface::DecodeEventsMultiThreads(const std::vector<uint32_t>&
// ######################
// # Unpack data vector #
// ######################
auto i = 0u;
for(; i < RD53Shared::NTHREADS - 1; i++)
for(i = 0u; i < RD53Shared::NTHREADS - 1; i++)
{
auto firstEvent = eventStart.begin() + nEvents * i;
if(firstEvent + nEvents + 1 > eventStart.end() - 1) break;
......@@ -894,9 +902,9 @@ void RD53FWInterface::DecodeEventsWrapper(const std::vector<uint32_t>& data, std
uint16_t RD53FWInterface::DecodeEvents(const std::vector<uint32_t>& data, std::vector<RD53FWInterface::Event>& events, const std::vector<size_t>& eventStartExt)
{
uint16_t evtStatus = RD53FWEvtEncoder::GOOD;
std::vector<size_t> eventStartLocal;
std::vector<size_t>& refEventStart = const_cast<std::vector<size_t>&>(eventStartExt);
uint16_t evtStatus = RD53FWEvtEncoder::GOOD;
const size_t maxL1Counter = RD53Shared::setBits(RD53EvtEncoder::NBIT_TRIGID) + 1;
// ######################
......@@ -906,8 +914,15 @@ uint16_t RD53FWInterface::DecodeEvents(const std::vector<uint32_t>& data, std::v
if(eventStartExt.size() == 0)
{
for(auto i = 0u; i < data.size(); i++)
if(data[i] >> RD53FWEvtEncoder::NBIT_BLOCKSIZE == RD53FWEvtEncoder::EVT_HEADER) eventStartLocal.push_back(i);
size_t i = 0u;
while(i < data.size())
if(data[i] >> RD53FWEvtEncoder::NBIT_BLOCKSIZE == RD53FWEvtEncoder::EVT_HEADER)
{
eventStartLocal.push_back(i);
i += RD53FWEvtEncoder::EVT_HEADER_SIZE;
}
else
i++;
if(eventStartLocal.size() == 0) return RD53FWEvtEncoder::NOHEADER;
eventStartLocal.push_back(data.size());
refEventStart = eventStartLocal;
......@@ -1011,7 +1026,7 @@ RD53FWInterface::Event::Event(const uint32_t* data, size_t n)
// ######################
// # Consistency checks #
// ######################
if(n < 4)
if(n < RD53FWEvtEncoder::EVT_HEADER_SIZE)
{
evtStatus = RD53FWEvtEncoder::INCOMPLETE;
return;
......@@ -1142,7 +1157,7 @@ void RD53FWInterface::ConfigureFastCommands(const FastCommandsConfig* cfg)
RD53FWInterface::SendBoardCommand("user.ctrl_regs.fast_cmd_reg_1.load_config");
}
void RD53FWInterface::SetAndConfigureFastCommands(const BeBoard* pBoard, size_t nTRIGxEvent, size_t injType, uint32_t nClkDelays, bool enableAutozero)
void RD53FWInterface::SetAndConfigureFastCommands(const BeBoard* pBoard, uint32_t nTRIGxEvent, size_t injType, uint32_t nClkDelays, bool enableAutozero)
// ############################
// # injType == 0 --> None #
// # injType == 1 --> Analog #
......@@ -1176,9 +1191,9 @@ void RD53FWInterface::SetAndConfigureFastCommands(const BeBoard* pBoard, size_t
// #######################################
// # Configuration for digital injection #
// #######################################
RD53::CalCmd calcmd_first(1, 0, 2, 0, 0);
RD53::CalCmd calcmd_first(1, 2, 8, 0, 0);
RD53FWInterface::localCfgFastCmd.fast_cmd_fsm.first_cal_data = calcmd_first.getCalCmd(chipId);
RD53::CalCmd calcmd_second(0, 0, 2, 0, 0);
RD53::CalCmd calcmd_second(0, 0, 0, 0, 0);
RD53FWInterface::localCfgFastCmd.fast_cmd_fsm.second_cal_data = calcmd_second.getCalCmd(chipId);
RD53FWInterface::localCfgFastCmd.fast_cmd_fsm.delay_after_first_prime = (nClkDelays == 0 ? (uint32_t)INJdelay::Loop : nClkDelays);
......@@ -1197,7 +1212,7 @@ void RD53FWInterface::SetAndConfigureFastCommands(const BeBoard* pBoard, size_t
// ######################################
// # Configuration for analog injection #
// ######################################
RD53::CalCmd calcmd_first(1, 0, 2, 0, 0);
RD53::CalCmd calcmd_first(1, 0, 0, 0, 0);
RD53FWInterface::localCfgFastCmd.fast_cmd_fsm.first_cal_data = calcmd_first.getCalCmd(chipId);
RD53::CalCmd calcmd_second(0, 0, 2, 0, 0);
RD53FWInterface::localCfgFastCmd.fast_cmd_fsm.second_cal_data = calcmd_second.getCalCmd(chipId);
......
......@@ -41,15 +41,16 @@ namespace RD53FWEvtEncoder
// ################
// # Event header #
// ################
const uint16_t EVT_HEADER = 0xFFFF;
const uint8_t NBIT_EVTHEAD = 16; // Number of bits for the Error Code
const uint8_t NBIT_BLOCKSIZE = 16; // Number of bits for the Block Size
const uint8_t NBIT_TRIGID = 16; // Number of bits for the TLU Trigger ID
const uint8_t NBIT_FMTVER = 8; // Number of bits for the Format Version
const uint8_t NBIT_DUMMY = 8; // Number of bits for the Dummy Size
const uint8_t NBIT_TDC = 8; // Number of bits for the TDC
const uint8_t NBIT_L1ACNT = 24; // Number of bits for the L1A Counter (Event number)
const uint8_t NBIT_BXCNT = 32; // Number of bits for the BX Counter
const uint16_t EVT_HEADER = 0xFFFF;
const uint16_t EVT_HEADER_SIZE = 4; // Number of words in event header
const uint8_t NBIT_EVTHEAD = 16; // Number of bits for the Error Code
const uint8_t NBIT_BLOCKSIZE = 16; // Number of bits for the Block Size
const uint8_t NBIT_TRIGID = 16; // Number of bits for the TLU Trigger ID
const uint8_t NBIT_FMTVER = 8; // Number of bits for the Format Version
const uint8_t NBIT_DUMMY = 8; // Number of bits for the Dummy Size
const uint8_t NBIT_TDC = 8; // Number of bits for the TDC
const uint8_t NBIT_L1ACNT = 24; // Number of bits for the L1A Counter (Event number)
const uint8_t NBIT_BXCNT = 32; // Number of bits for the BX Counter
// ###############
// # Chip header #
......@@ -183,7 +184,7 @@ class RD53FWInterface : public BeBoardFWInterface
uint32_t delay_after_ecr = 0;
uint32_t delay_after_autozero = 0; // @TMP@
uint32_t delay_after_inject = 0;
uint16_t delay_after_trigger = 0;
uint32_t delay_after_trigger = 0;
uint32_t delay_after_prime = 0;
};
......@@ -205,7 +206,7 @@ class RD53FWInterface : public BeBoardFWInterface
};
void ConfigureFromXML(const Ph2_HwDescription::BeBoard* pBoard);
void SetAndConfigureFastCommands(const Ph2_HwDescription::BeBoard* pBoard, size_t nTRIGxEvent, size_t injType, uint32_t nClkDelays = 0, bool enableAutozero = false);
void SetAndConfigureFastCommands(const Ph2_HwDescription::BeBoard* pBoard, uint32_t nTRIGxEvent, size_t injType, uint32_t nClkDelays = 0, bool enableAutozero = false);
struct DIO5Config
{
......
......@@ -286,6 +286,8 @@ void SystemController::ConfigureHw(bool bIgnoreI2c)
size_t injType = SystemController::findValueInSettings("INJtype");
size_t nClkDelays = SystemController::findValueInSettings("nClkDelays");
size_t colStart = SystemController::findValueInSettings("COLstart");
bool resetMask = SystemController::findValueInSettings("ResetMask");
bool resetTDAC = SystemController::findValueInSettings("ResetTDAC");
static_cast<RD53FWInterface*>(this->fBeBoardFWMap[cBoard->getId()])->SetAndConfigureFastCommands(cBoard, nTRIGxEvent, injType, nClkDelays, colStart < RD53::LIN.colStart);
LOG(INFO) << GREEN << "Configured FSM fast command block" << RESET;
......@@ -319,12 +321,15 @@ void SystemController::ConfigureHw(bool bIgnoreI2c)
for(auto cHybrid: *cOpticalGroup)
{
LOG(INFO) << GREEN << "Initializing communication to Hybrid: " << RESET << BOLDYELLOW << +cHybrid->getId() << RESET;
for(const auto cRD53: *cHybrid)
for(const auto cChip: *cHybrid)
{
LOG(INFO) << GREEN << "Configuring RD53: " << RESET << BOLDYELLOW << +cRD53->getId() << RESET;
static_cast<RD53Interface*>(fReadoutChipInterface)->ConfigureChip(static_cast<RD53*>(cRD53));
LOG(INFO) << GREEN << "Number of masked pixels: " << RESET << BOLDYELLOW << static_cast<RD53*>(cRD53)->getNbMaskedPixels() << RESET;
// @TMP@ static_cast<RD53Interface*>(fReadoutChipInterface)->CheckChipID(static_cast<RD53*>(cRD53), 0);
LOG(INFO) << GREEN << "Configuring RD53: " << RESET << BOLDYELLOW << +cChip->getId() << RESET;
if(resetMask == true) static_cast<RD53*>(cChip)->enableAllPixels();
if(resetTDAC == true) static_cast<RD53*>(cChip)->resetTDAC();
static_cast<RD53*>(cChip)->copyMaskToDefault();
static_cast<RD53Interface*>(fReadoutChipInterface)->ConfigureChip(static_cast<RD53*>(cChip));
LOG(INFO) << GREEN << "Number of masked pixels: " << RESET << BOLDYELLOW << static_cast<RD53*>(cChip)->getNbMaskedPixels() << RESET;
// @TMP@ static_cast<RD53Interface*>(fReadoutChipInterface)->CheckChipID(static_cast<RD53*>(cChip), 0);
}
}
}
......
......@@ -137,11 +137,9 @@
<Register name="ext_clk_en"> 0 </Register>
</Register>
<!--
<Register name="fast_cmd_reg_3">
<Register name="triggers_to_accept"> 10 </Register>
</Register>
-->
</Register>
</Register>
......@@ -151,15 +149,17 @@
<Settings>
<!--
=== Calibration parameters ===
INJtype = 0: no injection; INJtype = 1: analog; INJtype = 2: digital
DoFast = 0: run on all pixels in the selected region; DoFast = 1: run on a subset
DisplayHisto = 0: don't display; DisplayHisto = 1: display
UpdateChipCfg = 0: don't update; UpdateChipCfg = 1: update
TargetCharge: average charge (electrons) corresponding to ToT point = max value - 1
TargetOcc: average fraction of acceptable hits per pixel
UnstuckPixels = 0: do not try to unstuck pixels; UnstuckPixels = 1: set TDAC to 0 to unstuck pixels
ThrEquResetTDAC = 0: do not reset TDAC; ThrEquResetTDAC = 1: reset TDAC
INJtype = 0: no injection; INJtype = 1: analog; INJtype = 2: digital
ResetMask = 0: do not reenable masked pixels; ResetMask = 1: enable all pixels
ResetTDAC = 0: do not reset TDAC; ResetTDAC = 1: reset TDAC to range midpoint
DoFast = 0: run on all pixels in the selected region; DoFast = 1: run on a subset
DisplayHisto = 0: don't display; DisplayHisto = 1: display
UpdateChipCfg = 0: don't update; UpdateChipCfg = 1: update
TargetCharge (thradj): average charge (electrons) corresponding to ToT point = max value - 1
TargetOcc (thrmin): average pixel occupancy
TargetOcc (pixelalive/noise): per pixel occupancy threhold below/above which pixels are masked
UnstuckPixels (pixelalive) = 0: do not try to unstuck pixels; UnstuckPixels = 1: set TDAC to 0 to unstuck pixels
-->
<Setting name="nEvents"> 100 </Setting>
<Setting name="nEvtsBurst"> 100 </Setting>
......@@ -170,6 +170,8 @@
<Setting name="nTRIGxEvent"> 10 </Setting>
<Setting name="INJtype"> 1 </Setting>
<Setting name="ResetMask"> 0 </Setting>
<Setting name="ResetTDAC"> 0 </Setting>
<Setting name="ROWstart"> 0 </Setting>
<Setting name="ROWstop"> 191 </Setting>
......@@ -192,9 +194,7 @@
<Setting name="ThrStop"> 440 </Setting>
<Setting name="TargetThr"> 2000 </Setting>
<Setting name="TargetOcc"> 1e-6 </Setting>
<Setting name="UnstuckPixels"> 1 </Setting>
<Setting name="ThrEquResetTDAC"> 0 </Setting>
<Setting name="UnstuckPixels"> 0 </Setting>
<Setting name="DoFast"> 0 </Setting>
<Setting name="DisplayHisto"> 0 </Setting>
......
......@@ -19,8 +19,8 @@
#include "Tool.h"
#ifdef __USE_ROOT__
#include "../DQMUtils/RD53GainHistograms.h"
#include "TApplication.h"
#include "../DQMUtils/RD53GainHistograms.h"
#endif
// ###################
......
......@@ -19,8 +19,8 @@
#include "Tool.h"
#ifdef __USE_ROOT__
#include "../DQMUtils/RD53PhysicsHistograms.h"
#include "TApplication.h"
#include "../DQMUtils/RD53PhysicsHistograms.h"
#endif
// #######################
......
......@@ -256,8 +256,13 @@ std::shared_ptr<DetectorDataContainer> PixelAlive::analyze()
if(enable == false) nMaskedPixelsPerCalib++;
}
LOG(INFO) << BOLDBLUE << "\t--> Number of potentially masked pixels in this iteration: " << BOLDYELLOW << nMaskedPixelsPerCalib << RESET;
LOG(INFO) << BOLDBLUE << "\t--> Total number of potentially masked pixels: " << BOLDYELLOW << static_cast<RD53*>(cChip)->getNbMaskedPixels() << RESET;
if(unstuckPixels == false)
{
LOG(INFO) << BOLDBLUE << "\t--> Number of potentially " << BOLDYELLOW << "masked" << BOLDBLUE << " pixels in this iteration: " << BOLDYELLOW << nMaskedPixelsPerCalib << RESET;
LOG(INFO) << BOLDBLUE << "\t--> Total number of potentially masked pixels: " << BOLDYELLOW << static_cast<RD53*>(cChip)->getNbMaskedPixels() << RESET;
}
else
LOG(INFO) << BOLDBLUE << "\t--> Number of potentially " << BOLDYELLOW << "unstuck" << BOLDBLUE << " pixels in this iteration: " << BOLDYELLOW << nMaskedPixelsPerCalib << RESET;
// ######################################
// # Copy register values for streaming #
......
......@@ -18,8 +18,8 @@
#include "Tool.h"
#ifdef __USE_ROOT__
#include "../DQMUtils/RD53PixelAliveHistograms.h"
#include "TApplication.h"
#include "../DQMUtils/RD53PixelAliveHistograms.h"
#endif
// #########################
......
......@@ -19,8 +19,8 @@
#include "Tool.h"
#ifdef __USE_ROOT__
#include "../DQMUtils/RD53SCurveHistograms.h"
#include "TApplication.h"
#include "../DQMUtils/RD53SCurveHistograms.h"
#endif
// #####################
......
......@@ -33,7 +33,6 @@ void ThrEqualization::ConfigureCalibration()
nEvtsBurst = this->findValueInSettings("nEvtsBurst");
startValue = this->findValueInSettings("VCalHstart");
stopValue = this->findValueInSettings("VCalHstop");
resetTDAC = this->findValueInSettings("ThrEquResetTDAC");
nHITxCol = this->findValueInSettings("nHITxCol");
doFast = this->findValueInSettings("DoFast");
doDisplay = this->findValueInSettings("DisplayHisto");
......@@ -307,22 +306,6 @@ void ThrEqualization::bitWiseScanGlobal(const std::string& regName, uint32_t nEv
bestContainer.at(cBoard->getIndex())->at(cOpticalGroup->getIndex())->at(cHybrid->getIndex())->at(cChip->getIndex())->getSummary<OccupancyAndPh>().fOccupancy = 0;
}
// ##############
// # Reset TDAC #
// ##############
if(resetTDAC == true)
for(const auto cBoard: *fDetectorContainer)
for(const auto cOpticalGroup: *cBoard)
for(const auto cHybrid: *cOpticalGroup)
for(const auto cChip: *cHybrid)
{
static_cast<RD53*>(cChip)->resetTDAC();
this->fReadoutChipInterface->ReadChipAllLocalReg(
static_cast<RD53*>(cChip), regName, *theTDACcontainer.at(cBoard->getIndex())->at(cOpticalGroup->getIndex())->at(cHybrid->getIndex())->at(cChip->getIndex()));
this->fReadoutChipInterface->WriteChipAllLocalReg(
static_cast<RD53*>(cChip), regName, *theTDACcontainer.at(cBoard->getIndex())->at(cOpticalGroup->getIndex())->at(cHybrid->getIndex())->at(cChip->getIndex()));
}
for(auto i = 0u; i <= numberOfBits; i++)
{
// ###########################
......
......@@ -62,7 +62,6 @@ class ThrEqualization : public PixelAlive
size_t nEvtsBurst;
size_t startValue;
size_t stopValue;
bool resetTDAC;
size_t nHITxCol;
bool doFast;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment