Commit 76f7b782 authored by Sarah Seif El Nasr's avatar Sarah Seif El Nasr
Browse files

Added LpGBT monitor and few improvements

parent c6b45b56
Pipeline #3014322 failed with stages
in 16 minutes and 3 seconds
......@@ -143,6 +143,10 @@
#define MAX_NUMBER_OF_STUB_CLUSTERS_PS 5
#define MAX_NUMBER_OF_STUB_CLUSTERS_2S 3
// LpGBT convertion factors
#define VREF_LPGBT 1.0
#define CONVERSION_FACTOR (VREF_LPGBT / 1024.)
enum class BoardType
{
D19C,
......
......@@ -756,6 +756,7 @@ bool CbcInterface::WriteChipMultReg(Chip* pCbc, const std::vector<std::pair<std:
}
bool CbcInterface::WriteChipAllLocalReg(ReadoutChip* pCbc, const std::string& dacName, ChipContainer& localRegValues, bool pVerifLoop)
{
std::lock_guard<std::mutex> theGuard(fMutex);
setBoard(pCbc->getBeBoardId());
assert(localRegValues.size() == pCbc->getNumberOfChannels());
std::string dacTemplate;
......
......@@ -449,7 +449,7 @@ bool D19cFWInterface::ResetLink(uint8_t pLinkId)
}
bool D19cFWInterface::LinkLock(const BeBoard* pBoard)
{
std::lock_guard<std::mutex> theGuard(fMutex);
std::lock_guard<std::recursive_mutex> theGuard(fMutex);
// reset lpGBT core
this->WriteReg("fc7_daq_ctrl.optical_block.general", 0x1);
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
......@@ -512,7 +512,7 @@ bool D19cFWInterface::LinkLock(const BeBoard* pBoard)
bool D19cFWInterface::GBTLock(const BeBoard* pBoard)
{
std::lock_guard<std::mutex> theGuard(fMutex);
std::lock_guard<std::recursive_mutex> theGuard(fMutex);
// get link Ids
std::vector<uint8_t> cLinkIds;
for(auto cOpticalReadout: *pBoard)
......@@ -3833,7 +3833,7 @@ bool D19cFWInterface::ReadI2C(uint32_t pNReplies, std::vector<uint32_t>& pReplie
bool D19cFWInterface::WriteI2C(std::vector<uint32_t>& pVecSend, std::vector<uint32_t>& pReplies, bool pReadback, bool pBroadcast)
{
std::lock_guard<std::mutex> theGuard(fMutex);
std::lock_guard<std::recursive_mutex> theGuard(fMutex);
bool cFailed(false);
if(fOptical)
{
......@@ -3998,7 +3998,7 @@ bool D19cFWInterface::WriteChipBlockReg(std::vector<uint32_t>& pVecReg, uint8_t&
bool D19cFWInterface::BCWriteChipBlockReg(std::vector<uint32_t>& pVecReg, bool pReadback)
{
std::lock_guard<std::mutex> theGuard(fMutex);
std::lock_guard<std::recursive_mutex> theGuard(fMutex);
std::vector<uint32_t> cReplies;
bool cSuccess = !WriteI2C(pVecReg, cReplies, false, true);
......@@ -4038,6 +4038,7 @@ bool D19cFWInterface::BCWriteChipBlockReg(std::vector<uint32_t>& pVecReg, bool p
void D19cFWInterface::ReadChipBlockReg(std::vector<uint32_t>& pVecReg)
{
std::lock_guard<std::recursive_mutex> theGuard(fMutex);
std::vector<uint32_t> cReplies;
// it sounds weird, but ReadI2C is called inside writeI2c, therefore here I have to write and disable the readback.
// The actual read command is in the words of the vector, no broadcast, maybe I can get rid of it
......@@ -4046,9 +4047,15 @@ void D19cFWInterface::ReadChipBlockReg(std::vector<uint32_t>& pVecReg)
pVecReg = cReplies;
}
void D19cFWInterface::ChipI2CRefresh() { WriteReg("fc7_daq_ctrl.fast_command_block.control.fast_i2c_refresh", 0x1); }
void D19cFWInterface::ChipI2CRefresh()
{
std::lock_guard<std::recursive_mutex> theGuard(fMutex);
WriteReg("fc7_daq_ctrl.fast_command_block.control.fast_i2c_refresh", 0x1);
}
void D19cFWInterface::ReadoutChipReset()
{
std::lock_guard<std::recursive_mutex> theGuard(fMutex);
// for CBCs
// LOG (DEBUG) << BOLDBLUE << "Sending hard reset to all read-out chips..." << RESET;
if(fOptical)
......@@ -4071,6 +4078,7 @@ void D19cFWInterface::ReadoutChipReset()
}
void D19cFWInterface::ChipReset()
{
std::lock_guard<std::recursive_mutex> theGuard(fMutex);
// for CBCs
ReadoutChipReset();
// for CICs
......@@ -4099,6 +4107,7 @@ void D19cFWInterface::ChipReset()
}
void D19cFWInterface::Compose_fast_command(uint32_t duration, uint32_t resync_en, uint32_t l1a_en, uint32_t cal_pulse_en, uint32_t bc0_en)
{
std::lock_guard<std::recursive_mutex> theGuard(fMutex);
uint32_t encode_resync = resync_en << 16;
uint32_t encode_cal_pulse = cal_pulse_en << 17;
uint32_t encode_l1a = l1a_en << 18;
......@@ -4110,6 +4119,7 @@ void D19cFWInterface::Compose_fast_command(uint32_t duration, uint32_t resync_en
}
void D19cFWInterface::ChipReSync()
{
std::lock_guard<std::recursive_mutex> theGuard(fMutex);
uint8_t cReSync = 1;
uint8_t cCalPulse = 0;
uint8_t cL1A = 0;
......@@ -4120,6 +4130,7 @@ void D19cFWInterface::ChipReSync()
}
void D19cFWInterface::ChipTestPulse()
{
std::lock_guard<std::recursive_mutex> theGuard(fMutex);
uint8_t cReSync = 0;
uint8_t cCalPulse = 1;
uint8_t cL1A = 0;
......@@ -4138,6 +4149,7 @@ void D19cFWInterface::Trigger(uint8_t pDuration)
}
bool D19cFWInterface::Bx0Alignment()
{
std::lock_guard<std::recursive_mutex> theGuard(fMutex);
// auto cStubPackageDelay = this->ReadReg("fc7_daq_cnfg.physical_interface_block.cic.stub_package_delay");
bool cSuccess = false;
uint32_t cStubDebug = this->ReadReg("fc7_daq_cnfg.ddr3_debug.stub_enable");
......@@ -5498,6 +5510,7 @@ void D19cFWInterface::ResetOptoLink() { this->WriteStackReg({{"fc7_daq_ctrl.opti
bool D19cFWInterface::WriteOptoLpGBTRegister(const uint32_t linkNumber, const uint32_t pAddress, const uint32_t pData, const bool pVerifLoop)
{
std::lock_guard<std::recursive_mutex> theGuard(fMutex);
LOG(INFO) << BOLDMAGENTA << "D19cFWInterface::WriteOptoLpGBTRegister" << RESET;
// Reset
ResetOptoLink();
......@@ -5530,6 +5543,7 @@ bool D19cFWInterface::WriteOptoLpGBTRegister(const uint32_t linkNumber, const ui
uint32_t D19cFWInterface::ReadOptoLpGBTRegister(const uint32_t linkNumber, const uint32_t pAddress)
{
std::lock_guard<std::recursive_mutex> theGuard(fMutex);
// Reset
ResetOptoLink();
selectLink(linkNumber);
......@@ -5597,6 +5611,7 @@ std::vector<uint32_t> D19cFWInterface::ReadReplyCPB(uint8_t pNWords)
bool D19cFWInterface::WriteLpGBTRegister(uint8_t pLinkId, uint16_t pRegisterAddress, uint8_t pRegisterValue, bool pVerifLoop)
{
std::lock_guard<std::recursive_mutex> theGuard(fMutex);
if(fCPBConfig.fVerbose) LOG(INFO) << BOLDMAGENTA << "D19cFWInterface::WriteLpGBTRegister" << RESET;
size_t cExpectedReplySize = 10 * 1;
this->WriteReg("fc7_daq_cnfg.command_processor_block.link_select", pLinkId);
......@@ -5650,6 +5665,7 @@ bool D19cFWInterface::WriteLpGBTRegister(uint8_t pLinkId, uint16_t pRegisterAddr
uint8_t D19cFWInterface::ReadLpGBTRegister(uint8_t pLinkId, uint16_t pRegisterAddress)
{
std::lock_guard<std::recursive_mutex> theGuard(fMutex);
size_t cExpectedReplySize = 10 * 1;
this->WriteReg("fc7_daq_cnfg.command_processor_block.link_select", pLinkId);
ResetCPB();
......@@ -5824,6 +5840,7 @@ uint8_t D19cFWInterface::I2CRead(uint8_t pLinkId, uint8_t pMasterId, uint8_t pSl
bool D19cFWInterface::WriteFERegister(Ph2_HwDescription::Chip* pChip, uint16_t pRegisterAddress, uint8_t pRegisterValue, bool pVerify)
{
std::lock_guard<std::recursive_mutex> theGuard(fMutex);
auto cLinkId = pChip->getOpticalId();
uint8_t cMasterId = ((pChip->getHybridId() % 2) == 0) ? 2 : 0;
if(cLpGBTI2CHack && cMasterId == 0) cMasterId = 1;
......@@ -5874,6 +5891,7 @@ bool D19cFWInterface::WriteFERegister(Ph2_HwDescription::Chip* pChip, uint16_t p
uint8_t D19cFWInterface::ReadFERegister(Ph2_HwDescription::Chip* pChip, uint16_t pRegisterAddress)
{
std::lock_guard<std::recursive_mutex> theGuard(fMutex);
auto cLinkId = pChip->getOpticalId();
uint8_t cMasterId = ((pChip->getHybridId() % 2) == 0) ? 2 : 0;
if(cLpGBTI2CHack && cMasterId == 0) cMasterId = 1;
......
......@@ -98,7 +98,7 @@ class D19clpGBTInterface;
class D19cFWInterface : public BeBoardFWInterface
{
private:
std::mutex fMutex;
std::recursive_mutex fMutex;
D19cFWEvtEncoder::D19cFWEvt fD19cFWEvts;
std::vector<std::vector<uint32_t>> fSlaveMap;
std::map<uint8_t, std::vector<uint32_t>> fI2CSlaveMap;
......
......@@ -31,7 +31,7 @@ bool D19clpGBTInterface::ConfigureChip(Ph2_HwDescription::Chip* pChip, bool pVer
CPBconfig cCPBconfig;
cCPBconfig.fEnable = fUseCPB;
cCPBconfig.fI2CFrequency = 3;
cCPBconfig.fWait_us = 50; // TO-DO - make configurable from xml
cCPBconfig.fWait_us = 500; // TO-DO - make configurable from xml
cCPBconfig.fReTry = 1; // TO-DO - make configurable from xml
cCPBconfig.fVerbose = 0; // TO-DO - make configurable from xml
cCPBconfig.fMaxAttempts = 1000; // TO-DO - make configurable from xml
......@@ -64,10 +64,7 @@ bool D19clpGBTInterface::ConfigureChip(Ph2_HwDescription::Chip* pChip, bool pVer
cReady = IsPUSMDone(pChip);
cIter++;
}
if(cReady){
LOG(INFO) << BOLDGREEN << "lpGBT Configured [READY]" << RESET;
ResetI2C(pChip, {0, 1, 2});
}
if(cReady) LOG(INFO) << BOLDGREEN << "lpGBT Configured [READY]" << RESET;
if(!cReady) throw std::runtime_error(std::string("lpGBT Power-Up State Machine NOT DONE"));
// PrintChipMode(pChip);
return cReady;
......
......@@ -15,6 +15,7 @@
#include "TCanvas.h"
#include "TFile.h"
#include "TGraph.h"
#include "TAxis.h"
//========================================================================================================================
MonitorDQMPlotCBC::MonitorDQMPlotCBC() {}
......@@ -32,23 +33,63 @@ void MonitorDQMPlotCBC::book(TFile* theOutputFile, const DetectorContainer& theD
ContainerFactory::copyStructure(theDetectorStructure, fDetectorData);
// SoC utilities only - END
fDoMonitorThreshold = detectorMonitorConfig.isElementToMonitor("CBCThreshold");
// creating the histograms fo all the chips:
fDoMonitorThreshold = detectorMonitorConfig.isElementToMonitor("CBCThreshold");
fDoMonitorLpGBT_ADC1 = detectorMonitorConfig.isElementToMonitor("LpGBT_ADC1" );
fDoMonitorLpGBT_VDD = detectorMonitorConfig.isElementToMonitor("LpGBT_VDD" );
fDoMonitorLpGBT_VDDA = detectorMonitorConfig.isElementToMonitor("LpGBT_VDDA" );
fDoMonitorLpGBT_TEMP = detectorMonitorConfig.isElementToMonitor("LpGBT_TEMP" );
if(fDoMonitorThreshold ) bookCBCPlots (theOutputFile, theDetectorStructure, "VCth");
if(fDoMonitorLpGBT_ADC1) bookLpGBTPlots(theOutputFile, theDetectorStructure, "ADC1");
if(fDoMonitorLpGBT_VDD ) bookLpGBTPlots(theOutputFile, theDetectorStructure, "VDD" );
if(fDoMonitorLpGBT_VDDA) bookLpGBTPlots(theOutputFile, theDetectorStructure, "VDDA");
if(fDoMonitorLpGBT_TEMP) bookLpGBTPlots(theOutputFile, theDetectorStructure, "TEMP");
}
//========================================================================================================================
void MonitorDQMPlotCBC::bookCBCPlots(TFile* theOutputFile, const DetectorContainer& theDetectorStructure, std::string registerName)
{
// creating the histograms for all the chips:
// create the GraphContainer<TGraph> as you would create a TGraph (it implements some feature needed to avoid memory
// leaks in copying histograms like the move constructor)
if(fDoMonitorThreshold)
{
GraphContainer<TGraph> theTGraphPedestalContainer(0);
theTGraphPedestalContainer.setNameTitle("ChipDQM", "ChipDQM");
// create Histograms for all the chips, they will be automatically accosiated to the output file, no need to save
// them, change the name for every chip or set their directory
RootContainerFactory::bookChipHistograms<GraphContainer<TGraph>>(theOutputFile, theDetectorStructure, fDetectorMonitorPlots, theTGraphPedestalContainer);
}
GraphContainer<TGraph> theTGraphPedestalContainer(0);
theTGraphPedestalContainer.setNameTitle("CBC_DQM_" + registerName, "CBC_DQM_" + registerName);
theTGraphPedestalContainer.fTheGraph->GetXaxis()->SetTimeDisplay(1);
theTGraphPedestalContainer.fTheGraph->GetXaxis()->SetNdivisions(503);
theTGraphPedestalContainer.fTheGraph->GetXaxis()->SetTimeFormat("%Y-%m-%d %H:%M");
theTGraphPedestalContainer.fTheGraph->GetXaxis()->SetTimeOffset(0,"gmt");
// create Histograms for all the chips, they will be automatically accosiated to the output file, no need to save
// them, change the name for every chip or set their directory
RootContainerFactory::bookChipHistograms<GraphContainer<TGraph>>(theOutputFile, theDetectorStructure, fCBCRegisterMonitorPlotMap[registerName], theTGraphPedestalContainer);
}
//========================================================================================================================
void MonitorDQMPlotCBC::fillDQMThresholdPlots(DetectorDataContainer& theThresholdContainer, time_t rawTime)
void MonitorDQMPlotCBC::bookLpGBTPlots(TFile* theOutputFile, const DetectorContainer& theDetectorStructure, std::string registerName)
{
// creating the histograms for all the chips:
// create the GraphContainer<TGraph> as you would create a TGraph (it implements some feature needed to avoid memory
// leaks in copying histograms like the move constructor)
GraphContainer<TGraph> theTGraphPedestalContainer(0);
theTGraphPedestalContainer.setNameTitle("LpGBT_DQM_" + registerName, "LpGBT_DQM_" + registerName);
theTGraphPedestalContainer.fTheGraph->GetXaxis()->SetTimeDisplay(1);
theTGraphPedestalContainer.fTheGraph->GetXaxis()->SetNdivisions(503);
theTGraphPedestalContainer.fTheGraph->GetXaxis()->SetTimeFormat("%Y-%m-%d %H:%M");
theTGraphPedestalContainer.fTheGraph->GetXaxis()->SetTimeOffset(0,"gmt");
// create Histograms for all the chips, they will be automatically accosiated to the output file, no need to save
// them, change the name for every chip or set their directory
RootContainerFactory::bookOpticalGroupHistograms<GraphContainer<TGraph>>(theOutputFile, theDetectorStructure, fLpGBTRegisterMonitorPlotMap[registerName], theTGraphPedestalContainer);
}
//========================================================================================================================
void MonitorDQMPlotCBC::fillCBCRegisterPlots(DetectorDataContainer& theThresholdContainer, std::string registerName, time_t rawTime)
{
if(!fCBCRegisterMonitorPlotMap.count(registerName))
{
LOG(ERROR) << BOLDRED << "No plots for CBC register " << registerName << RESET;
LOG(ERROR) << BOLDRED << "Check that DQM and Monitor register names matches" << RESET;
abort();
}
uint32_t timeStampForRoot = getTimeStampForRoot(rawTime);
for(auto board: theThresholdContainer) // for on boards - begin
......@@ -64,11 +105,11 @@ void MonitorDQMPlotCBC::fillDQMThresholdPlots(DetectorDataContainer& theThreshol
{
size_t chipIndex = chip->getIndex();
// Retreive the corresponging chip histogram:
TGraph* chipDQMPlot = fDetectorMonitorPlots.at(boardIndex)->at(opticalGroupIndex)->at(hybridIndex)->at(chipIndex)->getSummary<GraphContainer<TGraph>>().fTheGraph;
TGraph* chipDQMPlot = fCBCRegisterMonitorPlotMap[registerName].at(boardIndex)->at(opticalGroupIndex)->at(hybridIndex)->at(chipIndex)->getSummary<GraphContainer<TGraph>>().fTheGraph;
// Check if the chip data are there (it is needed in the case of the SoC when data may be sent chip
// by chip and not in one shot)
if(chip == nullptr) continue;
if(!chip->hasSummary()) continue;
// // Get channel data and fill the histogram
// for(auto channel: *chip->getChannelContainer<uint32_t>()) // for on channel - begin
chipDQMPlot->SetPoint(chipDQMPlot->GetN(), timeStampForRoot, chip->getSummary<uint16_t>()); // for on channel - end
......@@ -78,6 +119,32 @@ void MonitorDQMPlotCBC::fillDQMThresholdPlots(DetectorDataContainer& theThreshol
} // for on boards - end
}
//========================================================================================================================
void MonitorDQMPlotCBC::fillLpGBTRegisterPlots(DetectorDataContainer& theThresholdContainer, std::string registerName, time_t rawTime)
{
if(!fLpGBTRegisterMonitorPlotMap.count(registerName))
{
LOG(FATAL) << BOLDRED << "No plots for LpGBT register " << registerName << RESET;
LOG(FATAL) << BOLDRED << "Check that DQM and Monitor register names matches" << RESET;
abort();
}
uint32_t timeStampForRoot = getTimeStampForRoot(rawTime);
for(auto board: theThresholdContainer) // for on boards - begin
{
size_t boardIndex = board->getIndex();
for(auto opticalGroup: *board) // for on opticalGroup - begin
{
if(!opticalGroup->hasSummary()) continue;
size_t opticalGroupIndex = opticalGroup->getIndex();
TGraph* LpGBTDQMPlot = fLpGBTRegisterMonitorPlotMap[registerName].at(boardIndex)->at(opticalGroupIndex)->getSummary<GraphContainer<TGraph>>().fTheGraph;
LpGBTDQMPlot->SetPoint(LpGBTDQMPlot->GetN(), timeStampForRoot, opticalGroup->getSummary<uint16_t>() * CONVERSION_FACTOR);
} // for on opticalGroup - end
} // for on boards - end
}
//========================================================================================================================
void MonitorDQMPlotCBC::process() {}
......@@ -95,7 +162,7 @@ bool MonitorDQMPlotCBC::fill(std::vector<char>& dataBuffer)
// IF YOU DO NOT WANT TO GO INTO THE SOC WITH YOUR DQM YOU DO NOT NEED THE FOLLOWING COMMENTED LINES
// I'm expecting to receive a data stream from an uint16_t contained from DQM "DQMExample"
ChipContainerStream<uint16_t, EmptyContainer, time_t> theDQMStreamer("CBCMonitor");
ChipContainerStream<uint16_t, EmptyContainer, std::array<char, 50>, time_t> theDQMStreamer("CBCMonitor");
// Try to see if the char buffer matched what I'm expection (container of uint16_t from DQMExample
// procedure)
......@@ -106,7 +173,8 @@ bool MonitorDQMPlotCBC::fill(std::vector<char>& dataBuffer)
// It matched! Decoding chip data
theDQMStreamer.decodeChipData(fDetectorData);
// Filling the histograms
fillDQMThresholdPlots(fDetectorData, theDQMStreamer.getHeaderElement());
std::string registerName = "Not working!!!";
fillCBCRegisterPlots(fDetectorData, registerName, theDQMStreamer.getHeaderElement<1>());
// Cleaning the data container to be ready for the next TCP string
fDetectorData.cleanDataStored();
return true;
......
......@@ -57,15 +57,25 @@ class MonitorDQMPlotCBC : public MonitorDQMPlotBase
void reset(void) override;
/*!
* \brief fillDQMThresholdPlots
* \param theThresholdContainer : Container with the hits you want to plot
* \brief fillCBCRegisterPlots
* \param theCBCRegisterContainer : Container with the hits you want to plot
* \param timeStamp : timeStamp
*/
void fillDQMThresholdPlots(DetectorDataContainer& theThresholdContainer, time_t timeStamp);
void fillCBCRegisterPlots (DetectorDataContainer& theCBCRegisterContainer, std::string registerName, time_t timeStamp);
void fillLpGBTRegisterPlots(DetectorDataContainer& theCBCRegisterContainer, std::string registerName, time_t timeStamp);
private:
bool fDoMonitorThreshold{false};
DetectorDataContainer fDetectorMonitorPlots;
bool fDoMonitorThreshold {false};
bool fDoMonitorLpGBT_ADC1 {false};
bool fDoMonitorLpGBT_VDD {false};
bool fDoMonitorLpGBT_VDDA {false};
bool fDoMonitorLpGBT_TEMP {false};
std::map<std::string, DetectorDataContainer> fCBCRegisterMonitorPlotMap ;
std::map<std::string, DetectorDataContainer> fLpGBTRegisterMonitorPlotMap;
DetectorDataContainer fDetectorData;
void bookCBCPlots (TFile* theOutputFile, const DetectorContainer& theDetectorStructure, std::string registerName);
void bookLpGBTPlots(TFile* theOutputFile, const DetectorContainer& theDetectorStructure, std::string registerName);
};
#endif
#include "CBCMonitor.h"
#include "../HWDescription/OuterTrackerHybrid.h"
#include "../Utils/ContainerFactory.h"
#include "../HWDescription/Definition.h"
#include "../HWInterface/D19clpGBTInterface.h"
#ifdef __USE_ROOT__
#include "TFile.h"
#endif
using namespace Ph2_HwInterface;
CBCMonitor::CBCMonitor(const Ph2_System::SystemController* theSystemController, DetectorMonitorConfig theDetectorMonitorConfig) : DetectorMonitor(theSystemController, theDetectorMonitorConfig)
{
fDoMonitorThreshold = fDetectorMonitorConfig.isElementToMonitor("CBCThreshold");
fDoMonitorThreshold = fDetectorMonitorConfig.isElementToMonitor("CBCThreshold");
fDoMonitorLpGBT_ADC1 = fDetectorMonitorConfig.isElementToMonitor("LpGBT_ADC1" );
fDoMonitorLpGBT_VDD = fDetectorMonitorConfig.isElementToMonitor("LpGBT_VDD" );
fDoMonitorLpGBT_VDDA = fDetectorMonitorConfig.isElementToMonitor("LpGBT_VDDA" );
fDoMonitorLpGBT_TEMP = fDetectorMonitorConfig.isElementToMonitor("LpGBT_TEMP" );
#ifdef __USE_ROOT__
fMonitorPlotDQM.book(fOutputFile, *fTheSystemController->fDetectorContainer, fDetectorMonitorConfig);
fMonitorPlotDQM = new MonitorDQMPlotCBC();
fMonitorDQMPlotCBC = static_cast<MonitorDQMPlotCBC*>(fMonitorPlotDQM);
fMonitorDQMPlotCBC->book(fOutputFile, *fTheSystemController->fDetectorContainer, fDetectorMonitorConfig);
#endif
}
void CBCMonitor::runMonitor()
{
if(fDoMonitorThreshold) runThresholdMonitor();
if(fDoMonitorThreshold) runCBCRegisterMonitor ("VCth");
if(fDoMonitorLpGBT_ADC1) runLpGBTRegisterMonitor("ADC1");
if(fDoMonitorLpGBT_VDD ) runLpGBTRegisterMonitor("VDD" );
if(fDoMonitorLpGBT_VDDA) runLpGBTRegisterMonitor("VDDA");
if(fDoMonitorLpGBT_TEMP) runLpGBTRegisterMonitor("TEMP");
}
void CBCMonitor::runThresholdMonitor()
void CBCMonitor::runCBCRegisterMonitor(std::string registerName)
{
DetectorDataContainer theThresholdContainer;
ContainerFactory::copyAndInitChip<uint16_t>(*fTheSystemController->fDetectorContainer, theThresholdContainer);
DetectorDataContainer theCBCRegisterContainer;
ContainerFactory::copyAndInitChip<uint16_t>(*fTheSystemController->fDetectorContainer, theCBCRegisterContainer);
for(const auto& board: *fTheSystemController->fDetectorContainer)
{
......@@ -32,22 +46,50 @@ void CBCMonitor::runThresholdMonitor()
{
for(const auto& chip: *hybrid)
{
uint16_t VCth = fTheSystemController->fReadoutChipInterface->ReadChipReg(chip, "VCth"); // just to read something
LOG(INFO) << BOLDMAGENTA << "CBC " << hybrid->getId() << " - Threshold = " << VCth << RESET;
theThresholdContainer.at(board->getIndex())->at(opticalGroup->getIndex())->at(hybrid->getIndex())->at(chip->getIndex())->getSummary<uint16_t>() = VCth;
uint16_t registerValue = fTheSystemController->fReadoutChipInterface->ReadChipReg(chip, registerName); // just to read something
LOG(INFO) << BOLDMAGENTA << "CBC " << hybrid->getId() << " - " << registerName << " = " << registerValue << RESET;
theCBCRegisterContainer.at(board->getIndex())->at(opticalGroup->getIndex())->at(hybrid->getIndex())->at(chip->getIndex())->getSummary<uint16_t>() = registerValue;
}
}
}
}
#ifdef __USE_ROOT__
fMonitorPlotDQM.fillDQMThresholdPlots(theThresholdContainer, getTimeStamp());
fMonitorDQMPlotCBC->fillCBCRegisterPlots(theCBCRegisterContainer, registerName, getTimeStamp());
#else
// auto theCBCThresholdStreamer = prepareHybridContainerStreamer<EmptyContainer, uint16_t, EmptyContainer, time_t>("CBCThreshold");
// theCBCThresholdStreamer.setHeaderElement(getTimeStamp());
// auto theCBCRegisterStreamer = prepareHybridContainerStreamer<EmptyContainer, uint16_t, EmptyContainer, time_t>("CBCRegister");
// theCBCRegisterStreamer.setHeaderElement(getTimeStamp());
// if(fStreamerEnabled)
// {
// for(auto board: theThresholdContainer) { theCBCThresholdStreamer.streamAndSendBoard(board, fNetworkStreamer); }
// for(auto board: theCBCRegisterContainer) { theCBCRegisterStreamer.streamAndSendBoard(board, fNetworkStreamer); }
// }
#endif
}
void CBCMonitor::runLpGBTRegisterMonitor(std::string registerName)
{
DetectorDataContainer theLpGBTRegisterContainer;
ContainerFactory::copyAndInitOpticalGroup<uint16_t>(*fTheSystemController->fDetectorContainer, theLpGBTRegisterContainer);
for(const auto& board: *fTheSystemController->fDetectorContainer)
{
for(const auto& opticalGroup: *board)
{
uint16_t registerValue = static_cast<D19clpGBTInterface*>(fTheSystemController->flpGBTInterface)->ReadADC(opticalGroup->flpGBT, registerName);
LOG(INFO) << BOLDMAGENTA << "LpGBT " << opticalGroup->getId() << " - " << registerName << " = " << registerValue << RESET;
theLpGBTRegisterContainer.at(board->getIndex())->at(opticalGroup->getIndex())->getSummary<uint16_t>() = registerValue;
}
}
#ifdef __USE_ROOT__
fMonitorDQMPlotCBC->fillLpGBTRegisterPlots(theLpGBTRegisterContainer, registerName, getTimeStamp());
#else
// auto theLpGBTRegisterStreamer = prepareHybridContainerStreamer<EmptyContainer, uint16_t, EmptyContainer, time_t>("LpGBTRegister");
// theLpGBTRegisterStreamer.setHeaderElement(getTimeStamp());
// if(fStreamerEnabled)
// {
// for(auto board: theLpGBTRegisterContainer) { theLpGBTRegisterStreamer.streamAndSendBoard(board, fNetworkStreamer); }
// }
#endif
}
\ No newline at end of file
......@@ -16,10 +16,17 @@ class CBCMonitor : public DetectorMonitor
void runMonitor() override;
private:
void runThresholdMonitor();
bool fDoMonitorThreshold{false};
void runCBCRegisterMonitor (std::string registerName);
void runLpGBTRegisterMonitor(std::string registerName);
bool fDoMonitorThreshold {false};
bool fDoMonitorLpGBT_ADC1 {false};
bool fDoMonitorLpGBT_VDD {false};
bool fDoMonitorLpGBT_VDDA {false};
bool fDoMonitorLpGBT_TEMP {false};
#ifdef __USE_ROOT__
MonitorDQMPlotCBC fMonitorPlotDQM;
MonitorDQMPlotCBC *fMonitorDQMPlotCBC;
#endif
};
......
#include "DetectorMonitor.h"
#include "Utilities.h"
#ifdef __USE_ROOT__
#include <TFile.h>
#endif
DetectorMonitor::DetectorMonitor(const Ph2_System::SystemController* theSystemController, DetectorMonitorConfig theDetectorMonitorConfig)
: fDetectorMonitorConfig(theDetectorMonitorConfig)
{
#ifdef __USE_ROOT__
, fOutputFile(new TFile("TmpMonitor.root", "RECREATE"))
std::string monitorOutputDir = "MonitorResults";
std::string cCommand = "mkdir -p " + monitorOutputDir;
try
{
system(cCommand.c_str());
}
catch(std::exception& e)
{
LOG(ERROR) << "Exceptin when trying to create MonitorResults Directory: " << e.what();
}
std::string monitorOutputFileName = monitorOutputDir + "/" + "MonitorDQM" + currentDateTime() + ".root";
fOutputFile = new TFile(monitorOutputFileName.c_str(), "RECREATE");
#endif
{
fTheSystemController = theSystemController;
fKeepRunning = true;
startMonitor = false;
......@@ -26,6 +41,7 @@ DetectorMonitor::~DetectorMonitor()
fOutputFile->Write();
fOutputFile->Close();
delete fOutputFile;
delete fMonitorPlotDQM;
#endif
}
......
......@@ -10,6 +10,7 @@
#ifdef __USE_ROOT__
class TFile;
#include "MonitorDQM/MonitorDQMPlotBase.h"
#endif
class DetectorMonitor
......@@ -29,6 +30,7 @@ class DetectorMonitor
DetectorMonitorConfig fDetectorMonitorConfig;
#ifdef __USE_ROOT__
TFile* fOutputFile;
MonitorDQMPlotBase *fMonitorPlotDQM;
#endif
time_t getTimeStamp();
std::string getMonitorName();
......
......@@ -133,7 +133,7 @@ void copyAndInitHybrid(const DetectorContainer& original, DetectorDataContainer&
template <typename T>
void copyAndInitOpticalGroup(const DetectorContainer& original, DetectorDataContainer& copy)
{
copyAndInitStructure<EmptyContainer, EmptyContainer, EmptyContainer, EmptyContainer, T, EmptyContainer, EmptyContainer>(original, copy);
copyAndInitStructure<EmptyContainer, EmptyContainer, EmptyContainer, T, EmptyContainer, EmptyContainer>(original, copy);
}
template <typename T>
......
......@@ -261,7 +261,7 @@
<MonitoringSettings>
<Monitoring type="2S" enable="1">
<MonitoringSleepTime> 500 </MonitoringSleepTime>
<MonitoringSleepTime> 100 </MonitoringSleepTime>
<MonitoringElements
CBCThreshold = "1"
LpGBT_ADC1 = "1"
......
......@@ -40,9 +40,6 @@
#include "Antenna.h"
#endif
// reference volage for lpgBT
float VREF_LPGBT = 1.0;
float cConversionFactor = VREF_LPGBT / 1024.;
using namespace Ph2_HwDescription;
using namespace Ph2_HwInterface;
......@@ -355,7 +352,7 @@ int main(int argc, char* argv[])
static_cast<D19clpGBTInterface*>(cTool.flpGBTInterface)->ConfigureVref(clpGBT, cEnableVref, cRef);
// wait until Vref is stable
std::this_thread::sleep_for(std::chrono::milliseconds(10));
for(size_t cM = 0; cM < cVals.size(); cM++) { cVals[cM] = static_cast<D19clpGBTInterface*>(cTool.flpGBTInterface)->ReadADC(clpGBT, cADCsel) * cConversionFactor; }
for(size_t cM = 0; cM < cVals.size(); cM++) { cVals[cM] = static_cast<D19clpGBTInterface*>(cTool.flpGBTInterface)->ReadADC(clpGBT, cADCsel) * CONVERSION_FACTOR; }