10 #include "dictionaries.h"
14 #include "constants.h"
21 _daq_buffersize(DTB_SOURCE_BUFFER_SIZE),
22 _daq_startstop_warning(false)
25 LOG(logQUIET) <<
"Instanciating API for " << PACKAGE_STRING;
28 Log::ReportingLevel() = Log::FromString(logLevel);
29 LOG(logINFO) <<
"Log level: " << logLevel;
32 _hal =
new hal(usbId);
46 std::vector<std::pair<std::string,double> > power_settings,
47 std::vector<std::pair<std::string,uint8_t> > pg_setup) {
50 if(!_hal->compatible())
return false;
55 checkTestboardPower(power_settings);
58 checkTestboardDelays(sig_delays);
61 verifyPatternGenerator(pg_setup);
70 LOG(logERROR) <<
"Signal delays not updated!";
73 checkTestboardDelays(sig_delays);
74 _hal->setTestboardDelays(
_dut->sig_delays);
75 LOG(logDEBUGAPI) <<
"Testboard signal delays updated.";
80 LOG(logERROR) <<
"Pattern generator not updated!";
83 verifyPatternGenerator(pg_setup);
84 _hal->SetupPatternGenerator(
_dut->pg_setup,
_dut->pg_sum);
85 LOG(logDEBUGAPI) <<
"Pattern generator verified and updated.";
90 LOG(logERROR) <<
"Voltages/current limits not upated!";
93 checkTestboardPower(power_settings);
95 LOG(logDEBUGAPI) <<
"Voltages/current limits updated.";
100 std::vector<std::vector<std::pair<std::string,uint8_t> > > tbmDACs,
102 std::vector<std::vector<std::pair<std::string,uint8_t> > > rocDACs,
103 std::vector<std::vector<pixelConfig> > rocPixels) {
104 std::vector<uint8_t> rocI2Cs;
105 return initDUT(hubid, tbmtype, tbmDACs, roctype, rocDACs, rocPixels, rocI2Cs);
110 std::vector<std::vector<std::pair<std::string,uint8_t> > > tbmDACs,
112 std::vector<std::vector<std::pair<std::string,uint8_t> > > rocDACs,
113 std::vector<std::vector<pixelConfig> > rocPixels,
114 std::vector<uint8_t> rocI2Cs) {
117 if(!_hal->status())
return false;
122 if(!rocI2Cs.empty()) {
123 if(rocI2Cs.size() != rocDACs.size()) {
124 LOG(logCRITICAL) <<
"Hm, we have " << rocI2Cs.size() <<
" I2C addresses but " << rocDACs.size() <<
" DAC configs.";
125 LOG(logCRITICAL) <<
"This cannot end well...";
126 throw InvalidConfig(
"Mismatch between number of I2C addresses and DAC configurations");
128 LOG(logDEBUGAPI) <<
"I2C addresses for all ROCs are provided as user input.";
130 else { LOG(logDEBUGAPI) <<
"I2C addresses will be automatically generated."; }
133 if(rocDACs.size() != rocPixels.size()) {
134 LOG(logCRITICAL) <<
"Hm, we have " << rocDACs.size() <<
" DAC configs but " << rocPixels.size() <<
" pixel configs.";
135 LOG(logCRITICAL) <<
"This cannot end well...";
136 throw InvalidConfig(
"Mismatch between number of DAC and pixel configurations");
139 if (rocDACs.size() == 0 || rocPixels.size() == 0){
140 LOG(logCRITICAL) <<
"No DAC/pixel configurations for any ROC supplied!";
141 throw InvalidConfig(
"No DAC/pixel configurations for any ROC supplied");
144 for(std::vector<std::vector<pixelConfig> >::iterator rocit = rocPixels.begin();rocit != rocPixels.end(); rocit++){
146 if ((*rocit).size() == 0){
147 LOG(logWARNING) <<
"No pixel configured for ROC "<<
static_cast<int>(rocit - rocPixels.begin()) <<
"!";
149 if ((*rocit).size() > 4160){
150 LOG(logCRITICAL) <<
"Too many pixels (N_pixel="<< rocit->size() <<
" > 4160) configured for ROC "<<
static_cast<int>(rocit - rocPixels.begin()) <<
"!";
155 for(std::vector<pixelConfig>::iterator pixit = rocit->begin(); pixit != rocit->end(); pixit++){
156 if (std::count_if(rocit->begin(),rocit->end(),
findPixelXY(pixit->column(),pixit->row())) > 1){
157 LOG(logCRITICAL) <<
"Config for pixel in column " <<
static_cast<int>(pixit->column()) <<
" and row "<< static_cast<int>(pixit->row()) <<
" present multiple times in ROC " << static_cast<int>(rocit-rocPixels.begin()) <<
"!";
162 throw InvalidConfig(
"Duplicate pixel configurations present");
166 if (std::count_if((*rocit).begin(),(*rocit).end(),
findPixelBeyondXY(51,79)) > 0) {
167 LOG(logCRITICAL) <<
"Found pixels with values for column and row outside of valid address range on ROC "<<
static_cast<int>(rocit - rocPixels.begin()) <<
"!";
168 throw InvalidConfig(
"Found pixels with values for column and row outside of valid address range");
172 LOG(logDEBUGAPI) <<
"We have " << rocDACs.size() <<
" DAC configs and " << rocPixels.size() <<
" pixel configs, with " << rocDACs.at(0).size() <<
" and " << rocPixels.at(0).size() <<
" entries for the first ROC, respectively.";
180 LOG(logDEBUGAPI) <<
"Received settings for " << tbmDACs.size() <<
" TBM cores.";
182 for(std::vector<std::vector<std::pair<std::string,uint8_t> > >::iterator tbmIt = tbmDACs.begin(); tbmIt != tbmDACs.end(); ++tbmIt) {
184 LOG(logDEBUGAPI) <<
"Processing TBM Core " <<
static_cast<int>(tbmIt - tbmDACs.begin());
189 newtbm.type = stringToDeviceCode(tbmtype);
190 if(newtbm.type == 0x0)
return false;
193 for(std::vector<std::pair<std::string,uint8_t> >::iterator dacIt = (*tbmIt).begin(); dacIt != (*tbmIt).end(); ++dacIt) {
196 uint8_t tbmregister, value = dacIt->second;
197 if(!verifyRegister(dacIt->first, tbmregister, value, TBM_REG))
continue;
200 if((tbmIt - tbmDACs.begin())%2 == 0) { tbmregister = 0xE0 | tbmregister; }
201 else { tbmregister = 0xF0 | tbmregister; }
203 std::pair<std::map<uint8_t,uint8_t>::iterator,
bool> ret;
204 ret = newtbm.dacs.insert( std::make_pair(tbmregister,value) );
205 if(ret.second ==
false) {
206 LOG(logWARNING) <<
"Overwriting existing DAC \"" << dacIt->first
207 <<
"\" value " <<
static_cast<int>(ret.first->second)
208 <<
" with " << static_cast<int>(value);
209 newtbm.dacs[tbmregister] = value;
214 _dut->tbm.push_back(newtbm);
218 if(
_dut->tbm.size() == 1) {
219 LOG(logDEBUGAPI) <<
"Only register settings for one TBM core supplied. Duplicating to second core.";
222 newtbm.type =
_dut->tbm.at(0).type;
224 for(std::map<uint8_t,uint8_t>::iterator reg =
_dut->tbm.at(0).dacs.begin(); reg !=
_dut->tbm.at(0).dacs.end(); ++reg) {
225 uint8_t tbmregister = reg->first;
227 tbmregister ^= (1u << 4);
228 newtbm.dacs.insert(std::make_pair(tbmregister,reg->second));
230 _dut->tbm.push_back(newtbm);
234 if(!
_dut->tbm.empty()) {
237 LOG(logDEBUGAPI) <<
"RDA/Tout DTB input termination set to LCDS.";
242 LOG(logDEBUGAPI) <<
"RDA/Tout DTB input termination set to LVDS.";
246 for(std::vector<std::vector<std::pair<std::string,uint8_t> > >::iterator rocIt = rocDACs.begin(); rocIt != rocDACs.end(); ++rocIt){
251 newroc.type = stringToDeviceCode(roctype);
252 if(newroc.type == 0x0)
return false;
255 if(rocI2Cs.empty()) { newroc.i2c_address =
static_cast<uint8_t
>(rocIt - rocDACs.begin()); }
257 else { newroc.i2c_address =
static_cast<uint8_t
>(rocI2Cs.at(rocIt - rocDACs.begin())); }
258 LOG(logDEBUGAPI) <<
"I2C address for the next ROC is: " <<
static_cast<int>(newroc.i2c_address);
261 for(std::vector<std::pair<std::string,uint8_t> >::iterator dacIt = (*rocIt).begin(); dacIt != (*rocIt).end(); ++dacIt){
263 uint8_t dacRegister, dacValue = dacIt->second;
264 if(!verifyRegister(dacIt->first, dacRegister, dacValue, ROC_REG))
continue;
266 std::pair<std::map<uint8_t,uint8_t>::iterator,
bool> ret;
267 ret = newroc.dacs.insert( std::make_pair(dacRegister,dacValue) );
268 if(ret.second ==
false) {
269 LOG(logWARNING) <<
"Overwriting existing DAC \"" << dacIt->first
270 <<
"\" value " <<
static_cast<int>(ret.first->second)
271 <<
" with " << static_cast<int>(dacValue);
272 newroc.dacs[dacRegister] = dacValue;
277 for(std::vector<pixelConfig>::iterator pixIt = rocPixels.at(rocIt - rocDACs.begin()).begin(); pixIt != rocPixels.at(rocIt - rocDACs.begin()).end(); ++pixIt) {
279 if((*pixIt).trim() > 15) {
280 LOG(logWARNING) <<
"Pixel "
281 <<
static_cast<int>((*pixIt).column()) <<
", "
282 << static_cast<int>((*pixIt).row())<<
" trim value "
283 << static_cast<int>((*pixIt).trim()) <<
" exceeds limit. Set to 15.";
284 (*pixIt).setTrim(15);
287 newroc.pixels.push_back(*pixIt);
291 _dut->roc.push_back(newroc);
295 _dut->_initialized =
true;
301 if(!
_dut->_initialized) {
302 LOG(logERROR) <<
"DUT not initialized, unable to program it.";
310 _hal->setHubId(
_dut->hubId);
313 if(!enabledTbms.empty()) {LOG(logDEBUGAPI) <<
"Programming TBMs...";}
314 for (std::vector<tbmConfig>::iterator tbmit = enabledTbms.begin(); tbmit != enabledTbms.end(); ++tbmit){
315 _hal->initTBMCore((*tbmit).type,(*tbmit).dacs);
319 if(!enabledRocs.empty()) {LOG(logDEBUGAPI) <<
"Programming ROCs...";}
320 for (std::vector<rocConfig>::iterator rocit = enabledRocs.begin(); rocit != enabledRocs.end(); ++rocit){
321 _hal->initROC(rocit->i2c_address,(*rocit).type, (*rocit).dacs);
326 for (std::vector<rocConfig>::iterator rocit =
_dut->roc.begin(); rocit !=
_dut->roc.end(); ++rocit) {
327 _hal->AllColumnsSetEnable(rocit->i2c_address,
true);
333 _dut->_programmed =
true;
340 if(_hal->status() &&
_dut->
status())
return true;
345 bool pxarCore::verifyRegister(std::string name, uint8_t &
id, uint8_t &value, uint8_t type) {
348 std::transform(name.begin(), name.end(), name.begin(), ::tolower);
354 id = _dict->getRegister(name,type);
358 LOG(logERROR) <<
"Invalid register name \"" << name <<
"\".";
363 uint8_t regLimit = _dict->getSize(
id, type);
364 if(value > regLimit) {
365 LOG(logWARNING) <<
"Register range overflow, set register \""
366 << name <<
"\" (" <<
static_cast<int>(id) <<
") to "
367 << static_cast<int>(regLimit) <<
" (was: " <<
static_cast<int>(value) <<
")";
368 value =
static_cast<uint8_t
>(regLimit);
377 uint8_t pxarCore::stringToDeviceCode(std::string name) {
380 std::transform(name.begin(), name.end(), name.begin(), ::tolower);
381 LOG(logDEBUGAPI) <<
"Looking up device type for \"" << name <<
"\"";
387 uint8_t _code = _devices->getDevCode(name);
388 LOG(logDEBUGAPI) <<
"Device type return: " <<
static_cast<int>(_code);
390 if(_code == 0x0) {LOG(logERROR) <<
"Unknown device \"" <<
static_cast<int>(_code) <<
"\"!";}
400 LOG(logERROR) <<
"The testboard should only be flashed without initialization"
401 <<
" and with all attached DUTs powered down.";
402 LOG(logERROR) <<
"Please power cycle the testboard and flash directly after startup!";
407 std::ifstream flashFile;
409 LOG(logINFO) <<
"Trying to open " << filename;
410 flashFile.open(filename.c_str(), std::ifstream::in);
411 if(!flashFile.is_open()) {
412 LOG(logERROR) <<
"Could not open specified DTB flash file \"" << filename<<
"\"!";
418 status = _hal->flashTestboard(flashFile);
425 if(!_hal->status()) {
return 0;}
426 return _hal->getTBia();
430 if(!_hal->status()) {
return 0;}
431 return _hal->getTBva();
435 if(!_hal->status()) {
return 0;}
436 return _hal->getTBid();
440 if(!_hal->status()) {
return 0;}
441 return _hal->getTBvd();
456 _dut->_programmed =
false;
467 if(!_hal->status()) {
return false;}
473 std::transform(probe.begin(), probe.end(), probe.begin(), ::tolower);
476 std::transform(name.begin(), name.end(), name.begin(), ::tolower);
479 if(probe.compare(0,1,
"d") == 0) {
482 uint8_t signal = _dict->getSignal(name,PROBE_DIGITAL);
483 LOG(logDEBUGAPI) <<
"Digital probe signal lookup for \"" << name
484 <<
"\" returned signal: " <<
static_cast<int>(signal);
487 if(probe.compare(
"d1") == 0) {
488 _hal->SignalProbeD1(signal);
491 else if(probe.compare(
"d2") == 0) {
492 _hal->SignalProbeD2(signal);
497 else if(probe.compare(0,1,
"a") == 0) {
500 uint8_t signal = _dict->getSignal(name, PROBE_ANALOG);
501 LOG(logDEBUGAPI) <<
"Analog probe signal lookup for \"" << name
502 <<
"\" returned signal: " <<
static_cast<int>(signal);
505 if(probe.compare(
"a1") == 0) {
506 _hal->SignalProbeA1(signal);
509 else if(probe.compare(
"a2") == 0) {
510 _hal->SignalProbeA2(signal);
513 else if (probe.compare(
"adc") == 0) {
514 _hal->SignalProbeADC(signal, 0);
519 LOG(logERROR) <<
"Invalid probe name \"" << probe <<
"\" selected!";
525 std::vector<uint16_t> pxarCore::daqADC(std::string signalName, uint8_t gain, uint16_t nSample, uint8_t source, uint8_t start){
527 vector<uint16_t> data;
528 if(!_hal->status()) {
return data;}
531 std::transform(signalName.begin(), signalName.end(), signalName.begin(), ::tolower);
532 uint8_t signal = _dict->getSignal(signalName, PROBE_ANALOG);
534 data = _hal->daqADC(signal, gain, nSample, source, start);
540 return _hal->daqStatistics();
548 if(!
status()) {
return false;}
552 if(!verifyRegister(dacName, dacRegister, dacValue, ROC_REG))
return false;
554 std::pair<std::map<uint8_t,uint8_t>::iterator,
bool> ret;
555 std::vector<rocConfig>::iterator rocit;
556 for (rocit =
_dut->roc.begin(); rocit !=
_dut->roc.end(); ++rocit) {
562 if(static_cast<int>(rocit -
_dut->roc.begin()) == rocID) {
565 ret = rocit->dacs.insert(std::make_pair(dacRegister,dacValue));
566 if(ret.second ==
true) {
567 LOG(logWARNING) <<
"DAC \"" << dacName <<
"\" was not initialized. Created with value " <<
static_cast<int>(dacValue);
570 rocit->dacs[dacRegister] = dacValue;
571 LOG(logDEBUGAPI) <<
"DAC \"" << dacName <<
"\" updated with value " <<
static_cast<int>(dacValue);
574 _hal->rocSetDAC(rocit->i2c_address,dacRegister,dacValue);
580 if(rocit ==
_dut->roc.end()) {
581 LOG(logERROR) <<
"ROC@I2C " <<
static_cast<int>(rocID) <<
" does not exist in the DUT!";
590 if(!
status()) {
return false;}
594 if(!verifyRegister(dacName, dacRegister, dacValue, ROC_REG))
return false;
596 std::pair<std::map<uint8_t,uint8_t>::iterator,
bool> ret;
598 for (std::vector<rocConfig>::iterator rocit =
_dut->roc.begin(); rocit !=
_dut->roc.end(); ++rocit) {
601 if(!rocit->enable()) {
continue; }
604 ret = rocit->dacs.insert(std::make_pair(dacRegister,dacValue));
605 if(ret.second ==
true) {
606 LOG(logWARNING) <<
"DAC \"" << dacName <<
"\" was not initialized. Created with value " <<
static_cast<int>(dacValue);
609 rocit->dacs[dacRegister] = dacValue;
610 LOG(logDEBUGAPI) <<
"DAC \"" << dacName <<
"\" updated with value " <<
static_cast<int>(dacValue);
613 _hal->rocSetDAC(rocit->i2c_address,dacRegister,dacValue);
624 if(!verifyRegister(dacName, dacRegister, val, ROC_REG))
return 0;
630 return _dict->getSize(dacRegister, ROC_REG);
639 if(!verifyRegister(regName, _register, regValue, TBM_REG))
return false;
641 std::pair<std::map<uint8_t,uint8_t>::iterator,
bool> ret;
642 if(
_dut->tbm.size() >
static_cast<size_t>(tbmid)) {
646 _register |=
_dut->tbm.at(tbmid).dacs.begin()->first&0xF0;
649 ret =
_dut->tbm.at(tbmid).dacs.insert(std::make_pair(_register,regValue));
650 if(ret.second ==
true) {
651 LOG(logWARNING) <<
"Register \"" << regName <<
"\" (" << std::hex << static_cast<int>(_register) << std::dec <<
") was not initialized. Created with value " << static_cast<int>(regValue);
654 _dut->tbm.at(tbmid).dacs[_register] = regValue;
655 LOG(logDEBUGAPI) <<
"Register \"" << regName <<
"\" (" << std::hex << static_cast<int>(_register) << std::dec <<
") updated with value " << static_cast<int>(regValue);
658 _hal->tbmSetReg(_register,regValue);
661 LOG(logERROR) <<
"TBM " << tbmid <<
" is not existing in the DUT!";
669 for(
size_t tbms = 0; tbms <
_dut->tbm.size(); ++tbms) {
670 if(!
setTbmReg(regName, regValue, tbms))
return false;
675 std::vector< std::pair<uint8_t, std::vector<pixel> > >
pxarCore::getPulseheightVsDAC(std::string dacName, uint8_t dacMin, uint8_t dacMax, uint16_t flags, uint16_t nTriggers) {
681 std::vector< std::pair<uint8_t, std::vector<pixel> > >
pxarCore::getPulseheightVsDAC(std::string dacName, uint8_t dacStep, uint8_t dacMin, uint8_t dacMax, uint16_t flags, uint16_t nTriggers) {
683 if(!
status()) {
return std::vector< std::pair<uint8_t, std::vector<pixel> > >();}
686 if(dacMin > dacMax) {
688 LOG(logWARNING) <<
"Swapping upper and lower bound.";
689 uint8_t temp = dacMin;
696 if(!verifyRegister(dacName, dacRegister, dacMax, ROC_REG)) {
697 return std::vector< std::pair<uint8_t, std::vector<pixel> > >();
701 HalMemFnPixelSerial pixelfn = &hal::SingleRocOnePixelDacScan;
702 HalMemFnPixelParallel multipixelfn = &hal::MultiRocOnePixelDacScan;
703 HalMemFnRocSerial rocfn = &hal::SingleRocAllPixelsDacScan;
709 std::vector<int32_t> param;
710 param.push_back(static_cast<int32_t>(dacRegister));
711 param.push_back(static_cast<int32_t>(dacMin));
712 param.push_back(static_cast<int32_t>(dacMax));
713 param.push_back(static_cast<int32_t>(flags));
714 param.push_back(static_cast<int32_t>(nTriggers));
715 param.push_back(static_cast<int32_t>(dacStep));
718 std::vector<Event*> data = expandLoop(pixelfn, multipixelfn, rocfn, multirocfn, param, flags);
720 std::vector< std::pair<uint8_t, std::vector<pixel> > > result = repackDacScanData(data,dacStep,dacMin,dacMax,nTriggers,flags,
false);
724 for (std::vector<rocConfig>::iterator rocit = enabledRocs.begin(); rocit != enabledRocs.end(); ++rocit){
725 uint8_t oldDacValue =
_dut->
getDAC(static_cast<size_t>(rocit - enabledRocs.begin()),dacName);
726 LOG(logDEBUGAPI) <<
"Reset DAC \"" << dacName <<
"\" to original value " <<
static_cast<int>(oldDacValue);
727 _hal->rocSetDAC(static_cast<uint8_t>(rocit - enabledRocs.begin()),dacRegister,oldDacValue);
733 std::vector< std::pair<uint8_t, std::vector<pixel> > >
pxarCore::getEfficiencyVsDAC(std::string dacName, uint8_t dacMin, uint8_t dacMax, uint16_t flags, uint16_t nTriggers) {
739 std::vector< std::pair<uint8_t, std::vector<pixel> > >
pxarCore::getEfficiencyVsDAC(std::string dacName, uint8_t dacStep, uint8_t dacMin, uint8_t dacMax, uint16_t flags, uint16_t nTriggers) {
741 if(!
status()) {
return std::vector< std::pair<uint8_t, std::vector<pixel> > >();}
744 if(dacMin > dacMax) {
746 LOG(logWARNING) <<
"Swapping upper and lower bound.";
747 uint8_t temp = dacMin;
754 if(!verifyRegister(dacName, dacRegister, dacMax, ROC_REG)) {
755 return std::vector< std::pair<uint8_t, std::vector<pixel> > >();
759 HalMemFnPixelSerial pixelfn = &hal::SingleRocOnePixelDacScan;
760 HalMemFnPixelParallel multipixelfn = &hal::MultiRocOnePixelDacScan;
761 HalMemFnRocSerial rocfn = &hal::SingleRocAllPixelsDacScan;
765 std::vector<int32_t> param;
766 param.push_back(static_cast<int32_t>(dacRegister));
767 param.push_back(static_cast<int32_t>(dacMin));
768 param.push_back(static_cast<int32_t>(dacMax));
769 param.push_back(static_cast<int32_t>(flags));
770 param.push_back(static_cast<int32_t>(nTriggers));
771 param.push_back(static_cast<int32_t>(dacStep));
774 std::vector<Event*> data = expandLoop(pixelfn, multipixelfn, rocfn, multirocfn, param, flags);
776 std::vector< std::pair<uint8_t, std::vector<pixel> > > result = repackDacScanData(data,dacStep,dacMin,dacMax,nTriggers,flags,
true);
780 for (std::vector<rocConfig>::iterator rocit = enabledRocs.begin(); rocit != enabledRocs.end(); ++rocit){
781 uint8_t oldDacValue =
_dut->
getDAC(static_cast<size_t>(rocit - enabledRocs.begin()),dacName);
782 LOG(logDEBUGAPI) <<
"Reset DAC \"" << dacName <<
"\" to original value " <<
static_cast<int>(oldDacValue);
783 _hal->rocSetDAC(static_cast<uint8_t>(rocit - enabledRocs.begin()),dacRegister,oldDacValue);
789 std::vector< std::pair<uint8_t, std::vector<pixel> > >
pxarCore::getThresholdVsDAC(std::string dacName, std::string dac2name, uint8_t dac2min, uint8_t dac2max, uint16_t flags, uint16_t nTriggers) {
794 return getThresholdVsDAC(dacName, dacStep, dac1min, dac1max, dac2name, dacStep, dac2min, dac2max, flags, nTriggers);
797 std::vector< std::pair<uint8_t, std::vector<pixel> > >
pxarCore::getThresholdVsDAC(std::string dac1name, uint8_t dac1step, uint8_t dac1min, uint8_t dac1max, std::string dac2name, uint8_t dac2step, uint8_t dac2min, uint8_t dac2max, uint16_t flags, uint16_t nTriggers) {
799 uint8_t threshold = 50;
800 return getThresholdVsDAC(dac1name, dac1step, dac1min, dac1max, dac2name, dac2step, dac2min, dac2max, threshold, flags, nTriggers);
803 std::vector< std::pair<uint8_t, std::vector<pixel> > >
pxarCore::getThresholdVsDAC(std::string dac1name, uint8_t dac1step, uint8_t dac1min, uint8_t dac1max, std::string dac2name, uint8_t dac2step, uint8_t dac2min, uint8_t dac2max, uint8_t threshold, uint16_t flags, uint16_t nTriggers) {
805 if(!
status()) {
return std::vector< std::pair<uint8_t, std::vector<pixel> > >();}
808 if(dac1min > dac1max) {
810 LOG(logWARNING) <<
"Swapping upper and lower bound.";
811 uint8_t temp = dac1min;
815 if(dac2min > dac2max) {
817 LOG(logWARNING) <<
"Swapping upper and lower bound.";
818 uint8_t temp = dac2min;
824 uint8_t dac1register, dac2register;
825 if(!verifyRegister(dac1name, dac1register, dac1max, ROC_REG)) {
826 return std::vector< std::pair<uint8_t, std::vector<pixel> > >();
828 if(!verifyRegister(dac2name, dac2register, dac2max, ROC_REG)) {
829 return std::vector< std::pair<uint8_t, std::vector<pixel> > >();
833 if(threshold == 0 || threshold > 100) {
834 LOG(logCRITICAL) <<
"Threshold level of " <<
static_cast<int>(threshold) <<
"% is not possible!";
835 return std::vector< std::pair<uint8_t, std::vector<pixel> > >();
839 HalMemFnPixelSerial pixelfn = &hal::SingleRocOnePixelDacDacScan;
840 HalMemFnPixelParallel multipixelfn = &hal::MultiRocOnePixelDacDacScan;
842 HalMemFnRocSerial rocfn = NULL;
846 std::vector<int32_t> param;
847 param.push_back(static_cast<int32_t>(dac1register));
848 param.push_back(static_cast<int32_t>(dac1min));
849 param.push_back(static_cast<int32_t>(dac1max));
850 param.push_back(static_cast<int32_t>(dac2register));
851 param.push_back(static_cast<int32_t>(dac2min));
852 param.push_back(static_cast<int32_t>(dac2max));
853 param.push_back(static_cast<int32_t>(flags));
854 param.push_back(static_cast<int32_t>(nTriggers));
855 param.push_back(static_cast<int32_t>(dac1step));
856 param.push_back(static_cast<int32_t>(dac2step));
859 std::vector<Event*> data = expandLoop(pixelfn, multipixelfn, rocfn, multirocfn, param, flags);
861 std::vector< std::pair<uint8_t, std::vector<pixel> > > result = repackThresholdDacScanData(data,dac1step,dac1min,dac1max,dac2step,dac2min,dac2max,threshold,nTriggers,flags);
865 for (std::vector<rocConfig>::iterator rocit = enabledRocs.begin(); rocit != enabledRocs.end(); ++rocit){
866 uint8_t oldDac1Value =
_dut->
getDAC(static_cast<size_t>(rocit - enabledRocs.begin()),dac1name);
867 uint8_t oldDac2Value =
_dut->
getDAC(static_cast<size_t>(rocit - enabledRocs.begin()),dac2name);
868 LOG(logDEBUGAPI) <<
"Reset DAC \"" << dac1name <<
"\" to original value " <<
static_cast<int>(oldDac1Value);
869 LOG(logDEBUGAPI) <<
"Reset DAC \"" << dac2name <<
"\" to original value " <<
static_cast<int>(oldDac2Value);
870 _hal->rocSetDAC(static_cast<uint8_t>(rocit - enabledRocs.begin()),dac1register,oldDac1Value);
871 _hal->rocSetDAC(static_cast<uint8_t>(rocit - enabledRocs.begin()),dac2register,oldDac2Value);
878 std::vector< std::pair<uint8_t, std::pair<uint8_t, std::vector<pixel> > > >
pxarCore::getPulseheightVsDACDAC(std::string dac1name, uint8_t dac1min, uint8_t dac1max, std::string dac2name, uint8_t dac2min, uint8_t dac2max, uint16_t flags, uint16_t nTriggers) {
881 return getPulseheightVsDACDAC(dac1name, 1, dac1min, dac1max, dac2name, 1, dac2min, dac2max, flags, nTriggers);
884 std::vector< std::pair<uint8_t, std::pair<uint8_t, std::vector<pixel> > > >
pxarCore::getPulseheightVsDACDAC(std::string dac1name, uint8_t dac1step, uint8_t dac1min, uint8_t dac1max, std::string dac2name, uint8_t dac2step, uint8_t dac2min, uint8_t dac2max, uint16_t flags, uint16_t nTriggers) {
886 if(!
status()) {
return std::vector< std::pair<uint8_t, std::pair<uint8_t, std::vector<pixel> > > >();}
889 if(dac1min > dac1max) {
891 LOG(logWARNING) <<
"Swapping upper and lower bound.";
892 uint8_t temp = dac1min;
896 if(dac2min > dac2max) {
898 LOG(logWARNING) <<
"Swapping upper and lower bound.";
899 uint8_t temp = dac2min;
905 uint8_t dac1register, dac2register;
906 if(!verifyRegister(dac1name, dac1register, dac1max, ROC_REG)) {
907 return std::vector< std::pair<uint8_t, std::pair<uint8_t, std::vector<pixel> > > >();
909 if(!verifyRegister(dac2name, dac2register, dac2max, ROC_REG)) {
910 return std::vector< std::pair<uint8_t, std::pair<uint8_t, std::vector<pixel> > > >();
914 HalMemFnPixelSerial pixelfn = &hal::SingleRocOnePixelDacDacScan;
915 HalMemFnPixelParallel multipixelfn = &hal::MultiRocOnePixelDacDacScan;
916 HalMemFnRocSerial rocfn = &hal::SingleRocAllPixelsDacDacScan;
920 std::vector<int32_t> param;
921 param.push_back(static_cast<int32_t>(dac1register));
922 param.push_back(static_cast<int32_t>(dac1min));
923 param.push_back(static_cast<int32_t>(dac1max));
924 param.push_back(static_cast<int32_t>(dac2register));
925 param.push_back(static_cast<int32_t>(dac2min));
926 param.push_back(static_cast<int32_t>(dac2max));
927 param.push_back(static_cast<int32_t>(flags));
928 param.push_back(static_cast<int32_t>(nTriggers));
929 param.push_back(static_cast<int32_t>(dac1step));
930 param.push_back(static_cast<int32_t>(dac2step));
933 std::vector<Event*> data = expandLoop(pixelfn, multipixelfn, rocfn, multirocfn, param, flags);
935 std::vector< std::pair<uint8_t, std::pair<uint8_t, std::vector<pixel> > > > result = repackDacDacScanData(data,dac1step,dac1min,dac1max,dac2step,dac2min,dac2max,nTriggers,flags,
false);
939 for (std::vector<rocConfig>::iterator rocit = enabledRocs.begin(); rocit != enabledRocs.end(); ++rocit){
940 uint8_t oldDac1Value =
_dut->
getDAC(static_cast<size_t>(rocit - enabledRocs.begin()),dac1name);
941 uint8_t oldDac2Value =
_dut->
getDAC(static_cast<size_t>(rocit - enabledRocs.begin()),dac2name);
942 LOG(logDEBUGAPI) <<
"Reset DAC \"" << dac1name <<
"\" to original value " <<
static_cast<int>(oldDac1Value);
943 LOG(logDEBUGAPI) <<
"Reset DAC \"" << dac2name <<
"\" to original value " <<
static_cast<int>(oldDac2Value);
944 _hal->rocSetDAC(static_cast<uint8_t>(rocit - enabledRocs.begin()),dac1register,oldDac1Value);
945 _hal->rocSetDAC(static_cast<uint8_t>(rocit - enabledRocs.begin()),dac2register,oldDac2Value);
951 std::vector< std::pair<uint8_t, std::pair<uint8_t, std::vector<pixel> > > >
pxarCore::getEfficiencyVsDACDAC(std::string dac1name, uint8_t dac1min, uint8_t dac1max, std::string dac2name, uint8_t dac2min, uint8_t dac2max, uint16_t flags, uint16_t nTriggers) {
954 return getEfficiencyVsDACDAC(dac1name, 1, dac1min, dac1max, dac2name, 1, dac2min, dac2max, flags, nTriggers);
957 std::vector< std::pair<uint8_t, std::pair<uint8_t, std::vector<pixel> > > >
pxarCore::getEfficiencyVsDACDAC(std::string dac1name, uint8_t dac1step, uint8_t dac1min, uint8_t dac1max, std::string dac2name, uint8_t dac2step, uint8_t dac2min, uint8_t dac2max, uint16_t flags, uint16_t nTriggers) {
959 if(!
status()) {
return std::vector< std::pair<uint8_t, std::pair<uint8_t, std::vector<pixel> > > >();}
962 if(dac1min > dac1max) {
964 LOG(logWARNING) <<
"Swapping upper and lower bound.";
965 uint8_t temp = dac1min;
969 if(dac2min > dac2max) {
971 LOG(logWARNING) <<
"Swapping upper and lower bound.";
972 uint8_t temp = dac2min;
978 uint8_t dac1register, dac2register;
979 if(!verifyRegister(dac1name, dac1register, dac1max, ROC_REG)) {
980 return std::vector< std::pair<uint8_t, std::pair<uint8_t, std::vector<pixel> > > >();
982 if(!verifyRegister(dac2name, dac2register, dac2max, ROC_REG)) {
983 return std::vector< std::pair<uint8_t, std::pair<uint8_t, std::vector<pixel> > > >();
987 HalMemFnPixelSerial pixelfn = &hal::SingleRocOnePixelDacDacScan;
988 HalMemFnPixelParallel multipixelfn = &hal::MultiRocOnePixelDacDacScan;
989 HalMemFnRocSerial rocfn = &hal::SingleRocAllPixelsDacDacScan;
993 std::vector<int32_t> param;
994 param.push_back(static_cast<int32_t>(dac1register));
995 param.push_back(static_cast<int32_t>(dac1min));
996 param.push_back(static_cast<int32_t>(dac1max));
997 param.push_back(static_cast<int32_t>(dac2register));
998 param.push_back(static_cast<int32_t>(dac2min));
999 param.push_back(static_cast<int32_t>(dac2max));
1000 param.push_back(static_cast<int32_t>(flags));
1001 param.push_back(static_cast<int32_t>(nTriggers));
1002 param.push_back(static_cast<int32_t>(dac1step));
1003 param.push_back(static_cast<int32_t>(dac2step));
1006 std::vector<Event*> data = expandLoop(pixelfn, multipixelfn, rocfn, multirocfn, param, flags);
1008 std::vector< std::pair<uint8_t, std::pair<uint8_t, std::vector<pixel> > > > result = repackDacDacScanData(data,dac1step,dac1min,dac1max,dac2step,dac2min,dac2max,nTriggers,flags,
true);
1012 for (std::vector<rocConfig>::iterator rocit = enabledRocs.begin(); rocit != enabledRocs.end(); ++rocit){
1013 uint8_t oldDac1Value =
_dut->
getDAC(static_cast<size_t>(rocit - enabledRocs.begin()),dac1name);
1014 uint8_t oldDac2Value =
_dut->
getDAC(static_cast<size_t>(rocit - enabledRocs.begin()),dac2name);
1015 LOG(logDEBUGAPI) <<
"Reset DAC \"" << dac1name <<
"\" to original value " <<
static_cast<int>(oldDac1Value);
1016 LOG(logDEBUGAPI) <<
"Reset DAC \"" << dac2name <<
"\" to original value " <<
static_cast<int>(oldDac2Value);
1017 _hal->rocSetDAC(static_cast<uint8_t>(rocit - enabledRocs.begin()),dac1register,oldDac1Value);
1018 _hal->rocSetDAC(static_cast<uint8_t>(rocit - enabledRocs.begin()),dac2register,oldDac2Value);
1026 if(!
status()) {
return std::vector<pixel>();}
1029 HalMemFnPixelSerial pixelfn = &hal::SingleRocOnePixelCalibrate;
1030 HalMemFnPixelParallel multipixelfn = &hal::MultiRocOnePixelCalibrate;
1031 HalMemFnRocSerial rocfn = &hal::SingleRocAllPixelsCalibrate;
1035 std::vector<int32_t> param;
1036 param.push_back(static_cast<int32_t>(flags));
1037 param.push_back(static_cast<int32_t>(nTriggers));
1040 std::vector<Event*> data = expandLoop(pixelfn, multipixelfn, rocfn, multirocfn, param, flags);
1043 std::vector<pixel> result = repackMapData(data, nTriggers, flags,
false);
1050 if(!
status()) {
return std::vector<pixel>();}
1053 HalMemFnPixelSerial pixelfn = &hal::SingleRocOnePixelCalibrate;
1054 HalMemFnPixelParallel multipixelfn = &hal::MultiRocOnePixelCalibrate;
1055 HalMemFnRocSerial rocfn = &hal::SingleRocAllPixelsCalibrate;
1059 std::vector<int32_t> param;
1060 param.push_back(static_cast<int32_t>(flags));
1061 param.push_back(static_cast<int32_t>(nTriggers));
1064 std::vector<Event*> data = expandLoop(pixelfn, multipixelfn, rocfn, multirocfn, param, flags);
1067 std::vector<pixel> result = repackMapData(data, nTriggers, flags,
true);
1076 uint8_t dacStep = 1;
1077 return getThresholdMap(dacName, dacStep, dacMin, dacMax, flags, nTriggers);
1080 std::vector<pixel>
pxarCore::getThresholdMap(std::string dacName, uint8_t dacStep, uint8_t dacMin, uint8_t dacMax, uint16_t flags, uint16_t nTriggers) {
1082 uint8_t threshold = 50;
1083 return getThresholdMap(dacName, dacStep, dacMin, dacMax, threshold, flags, nTriggers);
1086 std::vector<pixel>
pxarCore::getThresholdMap(std::string dacName, uint8_t dacStep, uint8_t dacMin, uint8_t dacMax, uint8_t threshold, uint16_t flags, uint16_t nTriggers) {
1088 if(!
status()) {
return std::vector<pixel>();}
1091 uint8_t dacRegister;
1092 if(!verifyRegister(dacName, dacRegister, dacMax, ROC_REG)) {
1093 return std::vector<pixel>();
1097 if(threshold == 0 || threshold > 100) {
1098 LOG(logCRITICAL) <<
"Threshold level of " <<
static_cast<int>(threshold) <<
"% is not possible!";
1099 return std::vector<pixel>();
1103 HalMemFnPixelSerial pixelfn = &hal::SingleRocOnePixelDacScan;
1104 HalMemFnPixelParallel multipixelfn = &hal::MultiRocOnePixelDacScan;
1105 HalMemFnRocSerial rocfn = &hal::SingleRocAllPixelsDacScan;
1109 std::vector<int32_t> param;
1110 param.push_back(static_cast<int32_t>(dacRegister));
1111 param.push_back(static_cast<int32_t>(dacMin));
1112 param.push_back(static_cast<int32_t>(dacMax));
1113 param.push_back(static_cast<int32_t>(flags));
1114 param.push_back(static_cast<int32_t>(nTriggers));
1115 param.push_back(static_cast<int32_t>(dacStep));
1118 std::vector<Event*> data = expandLoop(pixelfn, multipixelfn, rocfn, multirocfn, param, flags);
1121 std::vector<pixel> result = repackThresholdMapData(data, dacStep, dacMin, dacMax, threshold, nTriggers, flags);
1128 std::vector<std::vector<uint16_t> > values;
1129 if(!
status()) {
return values; }
1131 values = _hal->daqReadback();
1132 LOG(logDEBUGAPI) <<
"Decoders provided readback values for " << values.size() <<
" ROCs.";
1140 return daqStart(_daq_buffersize,
true);
1145 if(!
status()) {
return false;}
1152 if(buffersize > DTB_SOURCE_BUFFER_SIZE) {
1153 LOG(logWARNING) <<
"Requested buffer size too large, setting to max. " \
1154 << DTB_SOURCE_BUFFER_SIZE;
1155 _daq_buffersize = DTB_SOURCE_BUFFER_SIZE;
1157 else { _daq_buffersize = buffersize; }
1160 LOG(logDEBUGAPI) <<
"Starting new DAQ session...";
1171 for (std::vector<rocConfig>::iterator rocit =
_dut->roc.begin(); rocit !=
_dut->roc.end(); ++rocit) {
1172 _hal->AllColumnsSetEnable(rocit->i2c_address,
true);
1175 else if(!_daq_startstop_warning){
1176 LOG(logWARNING) <<
"Not unmasking DUT, not setting Calibrate bits!";
1177 _daq_startstop_warning =
true;
1182 if(!
_dut->tbm.empty()) { type =
_dut->tbm.at(0).type; }
1185 _hal->daqStart(
_dut->sig_delays[SIG_DESER160PHASE],type,buffersize);
1187 _daq_running =
true;
1204 LOG(logDEBUGAPI) <<
"DAQ not running!";
1210 uint32_t filled_buffer = _hal->daqBufferStatus();
1211 perFull =
static_cast<uint8_t
>(
static_cast<float>(filled_buffer)/_daq_buffersize*100.0);
1212 if(filled_buffer > 0.9*_daq_buffersize) {
1213 LOG(logWARNING) <<
"DAQ buffer about to overflow!";
1217 LOG(logDEBUGAPI) <<
"Everything alright, buffer size " << filled_buffer
1218 <<
"/" << _daq_buffersize;
1227 if(period < _dut->pg_sum) {
1228 period =
_dut->pg_sum;
1229 LOG(logWARNING) <<
"Loop period setting too small for configured "
1230 <<
"Pattern generator. "
1231 <<
"Forcing loop delay to " << period <<
" clk";
1232 LOG(logWARNING) <<
"To suppress this warning supply a larger delay setting";
1235 _hal->daqTrigger(nTrig,period);
1245 if(period < _dut->pg_sum) {
1246 period =
_dut->pg_sum;
1247 LOG(logWARNING) <<
"Loop period setting too small for configured "
1248 <<
"Pattern generator. "
1249 <<
"Forcing loop delay to " << period <<
" clk";
1250 LOG(logWARNING) <<
"To suppress this warning supply a larger delay setting";
1252 _hal->daqTriggerLoop(period);
1253 LOG(logDEBUGAPI) <<
"Loop period set to " << period <<
" clk";
1260 _hal->daqTriggerLoopHalt();
1266 std::vector<uint16_t> buffer = _hal->daqBuffer();
1274 std::vector<rawEvent> data = std::vector<rawEvent>();
1275 std::vector<rawEvent*> buffer = _hal->daqAllRawEvents();
1278 for(std::vector<rawEvent*>::iterator it = buffer.begin(); it != buffer.end(); ++it) {
1279 data.push_back(**it);
1289 std::vector<Event> data = std::vector<Event>();
1290 std::vector<Event*> buffer = _hal->daqAllEvents();
1293 for(std::vector<Event*>::iterator it = buffer.begin(); it != buffer.end(); ++it) {
1294 data.push_back(**it);
1306 Event * evt = _hal->daqEvent();
1318 rawEvent * evt = _hal->daqRawEvent();
1330 if(!
status()) {
return false;}
1332 LOG(logINFO) <<
"No DAQ running, not executing daqStop command.";
1336 _daq_running =
false;
1350 for (std::vector<rocConfig>::iterator rocit =
_dut->roc.begin(); rocit !=
_dut->roc.end(); ++rocit) {
1351 _hal->AllColumnsSetEnable(rocit->i2c_address,
false);
1354 else if(!_daq_startstop_warning){
1355 LOG(logWARNING) <<
"Not unmasking DUT, not setting Calibrate bits!";
1356 _daq_startstop_warning =
true;
1363 std::vector<Event*> pxarCore::expandLoop(HalMemFnPixelSerial pixelfn, HalMemFnPixelParallel multipixelfn, HalMemFnRocSerial rocfn,
HalMemFnRocParallel multirocfn, std::vector<int32_t> param, uint16_t flags) {
1366 std::vector<Event*> data = std::vector<Event*>();
1373 for(std::vector<uint8_t>::iterator rc = enabledRocs.begin(); rc != enabledRocs.end(); ++rc) {
1376 flags |= FLAG_FORCE_SERIAL;
1377 LOG(logDEBUGAPI) <<
"Not all ROCs have their pixels configured the same way. "
1378 <<
"Running in FLAG_FORCE_SERIAL mode.";
1385 if((flags & FLAG_FORCE_UNMASKED) == 0) {
1390 else if((flags & FLAG_FORCE_SERIAL) != 0) { MaskAndTrim(
false); }
1392 else { MaskAndTrim(
true); }
1403 LOG(logDEBUGAPI) <<
"\"The Loop\" contains one call to \'multirocfn\'";
1406 data = CALL_MEMBER_FN(*_hal,multirocfn)(rocs_i2c, param);
1409 else if (multipixelfn != NULL) {
1413 std::vector<Event*> rocdata = std::vector<Event*>();
1416 LOG(logDEBUGAPI) <<
"\"The Loop\" contains "
1417 << enabledPixels.size() <<
" calls to \'multipixelfn\'";
1419 for (std::vector<pixelConfig>::iterator px = enabledPixels.begin(); px != enabledPixels.end(); ++px) {
1421 std::vector<Event*> buffer = CALL_MEMBER_FN(*_hal,multipixelfn)(rocs_i2c, px->column(), px->row(), param);
1424 if (rocdata.empty()){
1428 rocdata.reserve(rocdata.size() + buffer.size());
1429 rocdata.insert(rocdata.end(), buffer.begin(), buffer.end());
1433 if (data.empty()) data = rocdata;
1435 data.reserve(data.size() + rocdata.size());
1436 data.insert(data.end(), rocdata.begin(), rocdata.end());
1452 LOG(logDEBUGAPI) <<
"\"The Loop\" contains " << enabledRocs.size() <<
" calls to \'rocfn\'";
1454 for (std::vector<rocConfig>::iterator rocit = enabledRocs.begin(); rocit != enabledRocs.end(); ++rocit) {
1457 if(((flags & FLAG_FORCE_SERIAL) != 0) && ((flags & FLAG_FORCE_UNMASKED) != 0)) { MaskAndTrim(
true,rocit); }
1460 std::vector<Event*> rocdata = CALL_MEMBER_FN(*_hal,rocfn)(rocit->i2c_address, param);
1462 if (data.empty()) data = rocdata;
1464 data.reserve(data.size() + rocdata.size());
1465 data.insert(data.end(), rocdata.begin(), rocdata.end());
1469 else if (pixelfn != NULL) {
1475 LOG(logDEBUGAPI) <<
"\"The Loop\" contains " << enabledRocs.size() <<
" enabled ROCs.";
1477 for (std::vector<rocConfig>::iterator rocit = enabledRocs.begin(); rocit != enabledRocs.end(); ++rocit){
1478 std::vector<Event*> rocdata = std::vector<Event*>();
1479 std::vector<pixelConfig> enabledPixels =
_dut->
getEnabledPixels(static_cast<uint8_t>(rocit - enabledRocs.begin()));
1482 LOG(logDEBUGAPI) <<
"\"The Loop\" for the current ROC contains " \
1483 << enabledPixels.size() <<
" calls to \'pixelfn\'";
1485 for (std::vector<pixelConfig>::iterator pixit = enabledPixels.begin(); pixit != enabledPixels.end(); ++pixit) {
1487 std::vector<Event*> buffer = CALL_MEMBER_FN(*_hal,pixelfn)(rocit->i2c_address, pixit->column(), pixit->row(), param);
1489 if (rocdata.empty()){
1493 rocdata.reserve(rocdata.size() + buffer.size());
1494 rocdata.insert(rocdata.end(), buffer.begin(), buffer.end());
1498 if (data.empty()) data = rocdata;
1500 data.reserve(data.size() + rocdata.size());
1501 data.insert(data.end(), rocdata.begin(), rocdata.end());
1506 LOG(logCRITICAL) <<
"LOOP EXPANSION FAILED -- NO MATCHING FUNCTION TO CALL?!";
1519 LOG(logCRITICAL) <<
"NO DATA FROM TEST FUNCTION -- are any TBMs/ROCs/PIXs enabled?!";
1531 LOG(logINFO) <<
"Test took " << t <<
"ms.";
1537 std::vector<Event*> pxarCore::condenseTriggers(std::vector<Event*> data, uint16_t nTriggers,
bool efficiency) {
1539 std::vector<Event*> packed;
1541 if(data.size()%nTriggers != 0) {
1542 LOG(logCRITICAL) <<
"Data size does not correspond to " << nTriggers <<
" triggers! Aborting data processing!";
1546 for(std::vector<Event*>::iterator Eventit = data.begin(); Eventit!= data.end(); Eventit += nTriggers) {
1549 std::map<pixel,uint16_t> pxcount = std::map<pixel,uint16_t>();
1550 std::map<pixel,double> pxmean = std::map<pixel,double>();
1551 std::map<pixel,double> pxm2 = std::map<pixel,double>();
1553 for(std::vector<Event*>::iterator it = Eventit; it != Eventit+nTriggers; ++it) {
1556 for(std::vector<pixel>::iterator pixit = (*it)->pixels.begin(); pixit != (*it)->pixels.end(); ++pixit) {
1559 std::vector<pixel>::iterator px = std::find_if(evt->pixels.begin(),
1561 findPixelXY(pixit->column(), pixit->row(), pixit->roc()));
1563 if(px != evt->pixels.end()) {
1564 if(efficiency) { px->setValue(px->value()+1); }
1567 double delta = pixit->value() - pxmean[*px];
1568 pxmean[*px] += delta/pxcount[*px];
1569 pxm2[*px] += delta*(pixit->value() - pxmean[*px]);
1575 if(efficiency) { pixit->setValue(1); }
1578 pxcount.insert(std::make_pair(*pixit,1));
1579 pxmean.insert(std::make_pair(*pixit,pixit->value()));
1580 pxm2.insert(std::make_pair(*pixit,0));
1582 evt->pixels.push_back(*pixit);
1593 for(std::vector<pixel>::iterator px = evt->pixels.begin(); px != evt->pixels.end(); ++px) {
1594 px->setValue(pxmean[*px]);
1595 px->setVariance(pxm2[*px]/(pxcount[*px] - 1));
1598 packed.push_back(evt);
1604 std::vector<pixel> pxarCore::repackMapData (std::vector<Event*> data, uint16_t nTriggers, uint16_t flags,
bool efficiency) {
1607 uint8_t expected_column = 0, expected_row = 0;
1609 std::vector<pixel> result;
1610 LOG(logDEBUGAPI) <<
"Simple Map Repack of " << data.size() <<
" data blocks, returning " << (efficiency ?
"efficiency" :
"averaged pulse height") <<
".";
1616 std::vector<Event*> packed = condenseTriggers(data, nTriggers, efficiency);
1619 for(std::vector<Event*>::iterator Eventit = packed.begin(); Eventit!= packed.end(); ++Eventit) {
1622 for(std::vector<pixel>::iterator pixit = (*Eventit)->pixels.begin(); pixit != (*Eventit)->pixels.end(); ++pixit) {
1624 if((flags&FLAG_CHECK_ORDER) != 0) {
1625 if(pixit->column() != expected_column || pixit->row() != expected_row) {
1628 if((flags&FLAG_FORCE_UNMASKED) != 0) { LOG(logDEBUGPIPES) <<
"This is a background hit: " << (*pixit); }
1631 LOG(logERROR) <<
"This pixel doesn't belong here: " << (*pixit) <<
". Expected [" <<
static_cast<int>(expected_column) <<
"," << static_cast<int>(expected_row) <<
",x]";
1635 pixit->setValue(-1*pixit->value());
1638 result.push_back(*pixit);
1641 if((flags&FLAG_CHECK_ORDER) != 0) {
1643 if(expected_row >= ROC_NUMROWS) { expected_row = 0; expected_column++; }
1644 if(expected_column >= ROC_NUMCOLS) { expected_row = 0; expected_column = 0; }
1649 if((flags&FLAG_NOSORT) == 0) { std::sort(result.begin(),result.end()); }
1652 for(std::vector<Event*>::iterator it = packed.begin(); it != packed.end(); ++it) {
delete *it; }
1654 LOG(logDEBUGAPI) <<
"Correctly repacked Map data for delivery.";
1655 LOG(logDEBUGAPI) <<
"Repacking took " << t <<
"ms.";
1659 std::vector< std::pair<uint8_t, std::vector<pixel> > > pxarCore::repackDacScanData (std::vector<Event*> data, uint8_t dacStep, uint8_t dacMin, uint8_t dacMax, uint16_t nTriggers, uint16_t ,
bool efficiency){
1661 std::vector< std::pair<uint8_t, std::vector<pixel> > > result;
1667 std::vector<Event*> packed = condenseTriggers(data, nTriggers, efficiency);
1669 if(packed.size() %
static_cast<size_t>((dacMax-dacMin)/dacStep+1) != 0) {
1670 LOG(logCRITICAL) <<
"Data size not as expected! " << packed.size() <<
" data blocks do not fit to " <<
static_cast<int>((dacMax-dacMin)/dacStep+1) <<
" DAC values!";
1674 LOG(logDEBUGAPI) <<
"Packing DAC range " <<
static_cast<int>(dacMin) <<
" - " << static_cast<int>(dacMax) <<
" (step size " <<
static_cast<int>(dacStep) <<
"), data has " << packed.size() <<
" entries.";
1677 for(
size_t dac = dacMin; dac <= dacMax; dac += dacStep) { result.push_back(std::make_pair(dac,std::vector<pixel>())); }
1679 size_t currentDAC = dacMin;
1681 for(std::vector<Event*>::iterator Eventit = packed.begin(); Eventit!= packed.end(); ++Eventit) {
1682 if(currentDAC > dacMax) { currentDAC = dacMin; }
1683 result.at((currentDAC-dacMin)/dacStep).second.insert(result.at((currentDAC-dacMin)/dacStep).second.end(),
1684 (*Eventit)->pixels.begin(),
1685 (*Eventit)->pixels.end());
1686 currentDAC += dacStep;
1690 for(std::vector<Event*>::iterator it = packed.begin(); it != packed.end(); ++it) {
delete *it; }
1692 LOG(logDEBUGAPI) <<
"Correctly repacked DacScan data for delivery.";
1693 LOG(logDEBUGAPI) <<
"Repacking took " << t <<
"ms.";
1697 std::vector<pixel> pxarCore::repackThresholdMapData (std::vector<Event*> data, uint8_t dacStep, uint8_t dacMin, uint8_t dacMax, uint8_t thresholdlevel, uint16_t nTriggers, uint16_t flags) {
1699 std::vector<pixel> result;
1701 std::vector<pixel> found;
1705 uint16_t threshold =
static_cast<uint16_t
>(ceil(static_cast<float>(nTriggers)*thresholdlevel/100));
1706 LOG(logDEBUGAPI) <<
"Scanning for threshold level " << threshold <<
", "
1707 << ((flags&FLAG_RISING_EDGE) == 0 ?
"falling":
"rising") <<
" edge";
1713 std::vector<std::pair<uint8_t,std::vector<pixel> > > packed_dac = repackDacScanData(data, dacStep, dacMin, dacMax, nTriggers, flags,
true);
1716 std::map<pixel,uint8_t> oldvalue;
1720 std::vector<std::pair<uint8_t,std::vector<pixel> > >::iterator it_start;
1721 std::vector<std::pair<uint8_t,std::vector<pixel> > >::iterator it_end;
1723 if((flags&FLAG_RISING_EDGE) != 0) { it_start = packed_dac.begin(); it_end = packed_dac.end(); increase_op = 1; }
1724 else { it_start = packed_dac.end()-1; it_end = packed_dac.begin()-1; increase_op = -1; }
1726 for(std::vector<std::pair<uint8_t,std::vector<pixel> > >::iterator it = it_start; it != it_end; it += increase_op) {
1728 for(std::vector<pixel>::iterator pixit = it->second.begin(); pixit != it->second.end(); ++pixit) {
1730 std::vector<pixel>::iterator px_found = std::find_if(found.begin(),
1732 findPixelXY(pixit->column(), pixit->row(), pixit->roc()));
1733 if(px_found != found.end())
continue;
1736 std::vector<pixel>::iterator px = std::find_if(result.begin(),
1738 findPixelXY(pixit->column(), pixit->row(), pixit->roc()));
1741 if(px != result.end()) {
1743 uint8_t delta_old = abs(oldvalue[*px] - threshold);
1744 uint8_t delta_new = abs(static_cast<uint8_t>(pixit->value()) - threshold);
1745 bool positive_slope = (
static_cast<uint8_t
>(pixit->value()) - oldvalue[*px] > 0 ?
true :
false);
1751 if(positive_slope && !(delta_new < delta_old)) {
1752 found.push_back(*pixit);
1757 px->setValue(it->first);
1759 oldvalue[*px] =
static_cast<uint8_t
>(pixit->value());
1765 if(pixit->value() >= threshold) { found.push_back(*pixit); }
1768 oldvalue.insert(std::make_pair(*pixit,pixit->value()));
1771 pixit->setValue(it->first);
1772 result.push_back(*pixit);
1778 for(std::vector<pixel>::iterator px = result.begin(); px != result.end(); ++px) {
1779 std::vector<pixel>::iterator px_found = std::find_if(found.begin(),
1783 if(px_found != found.end())
continue;
1787 if((flags&FLAG_RISING_EDGE) != 0) { px->setValue(dacMax); }
1788 else { px->setValue(dacMin); }
1789 LOG(logWARNING) <<
"No threshold found for " << (*px);
1793 if((flags&FLAG_NOSORT) == 0) { std::sort(result.begin(),result.end()); }
1795 LOG(logDEBUGAPI) <<
"Correctly repacked&analyzed ThresholdMap data for delivery.";
1796 LOG(logDEBUGAPI) <<
"Repacking took " << t <<
"ms.";
1800 std::vector<std::pair<uint8_t,std::vector<pixel> > > pxarCore::repackThresholdDacScanData (std::vector<Event*> data, uint8_t dac1step, uint8_t dac1min, uint8_t dac1max, uint8_t dac2step, uint8_t dac2min, uint8_t dac2max, uint8_t thresholdlevel, uint16_t nTriggers, uint16_t flags) {
1802 std::vector<std::pair<uint8_t,std::vector<pixel> > > result;
1804 std::map<uint8_t,std::vector<pixel> > found;
1808 uint16_t threshold =
static_cast<uint16_t
>(ceil(static_cast<float>(nTriggers)*thresholdlevel/100));
1809 LOG(logDEBUGAPI) <<
"Scanning for threshold level " << threshold <<
", "
1810 << ((flags&FLAG_RISING_EDGE) == 0 ?
"falling":
"rising") <<
" edge";
1816 std::vector<std::pair<uint8_t,std::pair<uint8_t,std::vector<pixel> > > > packed_dacdac = repackDacDacScanData(data,dac1step,dac1min,dac1max,dac2step,dac2min,dac2max,nTriggers,flags,
true);
1819 std::map<uint8_t,std::map<pixel,uint8_t> > oldvalue;
1823 std::vector<std::pair<uint8_t,std::pair<uint8_t,std::vector<pixel> > > >::iterator it_start;
1824 std::vector<std::pair<uint8_t,std::pair<uint8_t,std::vector<pixel> > > >::iterator it_end;
1826 if((flags&FLAG_RISING_EDGE) != 0) { it_start = packed_dacdac.begin(); it_end = packed_dacdac.end(); increase_op = 1; }
1827 else { it_start = packed_dacdac.end()-1; it_end = packed_dacdac.begin()-1; increase_op = -1; }
1829 for(std::vector<std::pair<uint8_t,std::pair<uint8_t,std::vector<pixel> > > >::iterator it = it_start; it != it_end; it += increase_op) {
1832 for(std::vector<pixel>::iterator pixit = it->second.second.begin(); pixit != it->second.second.end(); ++pixit) {
1835 std::vector<std::pair<uint8_t, std::vector<pixel> > >::iterator dac;
1836 for(dac = result.begin(); dac != result.end(); ++dac) {
if(it->second.first == dac->first)
break; }
1839 if(dac == result.end()) {
1840 result.push_back(std::make_pair(it->second.first,std::vector<pixel>()));
1841 dac = result.end() - 1;
1843 found.insert(std::make_pair(it->second.first,std::vector<pixel>()));
1844 oldvalue.insert(std::make_pair(it->second.first,std::map<pixel,uint8_t>()));
1848 std::vector<pixel>::iterator px_found = std::find_if(found[dac->first].begin(),
1849 found[dac->first].end(),
1850 findPixelXY(pixit->column(), pixit->row(), pixit->roc()));
1851 if(px_found != found[dac->first].end())
continue;
1854 std::vector<pixel>::iterator px = std::find_if(dac->second.begin(),
1856 findPixelXY(pixit->column(), pixit->row(), pixit->roc()));
1859 if(px != dac->second.end()) {
1861 uint8_t delta_old = abs(oldvalue[dac->first][*px] - threshold);
1862 uint8_t delta_new = abs(static_cast<uint8_t>(pixit->value()) - threshold);
1863 bool positive_slope = (
static_cast<uint8_t
>(pixit->value()) - oldvalue[dac->first][*px] > 0 ?
true :
false);
1869 if(positive_slope && !(delta_new < delta_old)) {
1870 found[dac->first].push_back(*pixit);
1875 px->setValue(it->first);
1877 oldvalue[dac->first][*px] =
static_cast<uint8_t
>(pixit->value());
1883 if(pixit->value() >= threshold) { found[dac->first].push_back(*pixit); }
1886 oldvalue[dac->first].insert(std::make_pair(*pixit,pixit->value()));
1888 pixit->setValue(it->first);
1889 dac->second.push_back(*pixit);
1895 for(std::vector<std::pair<uint8_t,std::vector<pixel> > >::iterator dac = result.begin(); dac != result.end(); ++dac) {
1897 for(std::vector<pixel>::iterator px = dac->second.begin(); px != dac->second.end(); px++) {
1898 std::vector<pixel>::iterator px_found = std::find_if(found[dac->first].begin(),
1899 found[dac->first].end(),
1902 if(px_found != found[dac->first].end())
continue;
1906 if((flags&FLAG_RISING_EDGE) != 0) { px->setValue(dac2max); }
1907 else { px->setValue(dac2min); }
1908 LOG(logWARNING) <<
"No threshold found for " << (*px) <<
" at DAC value " <<
static_cast<int>(dac->first);
1913 if((flags&FLAG_NOSORT) == 0) { std::sort(result.begin(),result.end()); }
1915 LOG(logDEBUGAPI) <<
"Correctly repacked&analyzed ThresholdDacScan data for delivery.";
1916 LOG(logDEBUGAPI) <<
"Repacking took " << t <<
"ms.";
1920 std::vector< std::pair<uint8_t, std::pair<uint8_t, std::vector<pixel> > > > pxarCore::repackDacDacScanData (std::vector<Event*> data, uint8_t dac1step, uint8_t dac1min, uint8_t dac1max, uint8_t dac2step, uint8_t dac2min, uint8_t dac2max, uint16_t nTriggers, uint16_t ,
bool efficiency) {
1921 std::vector< std::pair<uint8_t, std::pair<uint8_t, std::vector<pixel> > > > result;
1927 std::vector<Event*> packed = condenseTriggers(data, nTriggers, efficiency);
1929 if(packed.size() %
static_cast<size_t>(((dac1max-dac1min)/dac1step+1)*((dac2max-dac2min)/dac2step+1)) != 0) {
1930 LOG(logCRITICAL) <<
"Data size not as expected! " << packed.size() <<
" data blocks do not fit to " <<
static_cast<int>(((dac1max-dac1min)/dac1step+1)*((dac2max-dac2min)/dac2step+1)) <<
" DAC values!";
1934 LOG(logDEBUGAPI) <<
"Packing DAC range [" <<
static_cast<int>(dac1min) <<
" - " << static_cast<int>(dac1max)
1935 <<
", step size " <<
static_cast<int>(dac1step) <<
"]x["
1936 << static_cast<int>(dac2min) <<
" - " <<
static_cast<int>(dac2max)
1937 <<
", step size " << static_cast<int>(dac2step)
1938 <<
"], data has " << packed.size() <<
" entries.";
1941 for(
size_t dac1 = dac1min; dac1 <= dac1max; dac1 += dac1step) {
1942 std::pair<uint8_t,std::vector<pixel> > dacpair;
1943 for(
size_t dac2 = dac2min; dac2 <= dac2max; dac2 += dac2step) {
1944 dacpair = std::make_pair(dac2,std::vector<pixel>());
1945 result.push_back(std::make_pair(dac1,dacpair));
1949 size_t current1dac = dac1min;
1950 size_t current2dac = dac2min;
1954 for(std::vector<Event*>::iterator Eventit = packed.begin(); Eventit!= packed.end(); ++Eventit) {
1955 if(current2dac > dac2max) {
1956 current2dac = dac2min;
1957 current1dac += dac1step;
1959 if(current1dac > dac1max) { current1dac = dac1min; }
1961 result.at((current1dac-dac1min)/dac1step*((dac2max-dac2min)/dac2step+1) + (current2dac-dac2min)/dac2step).second.second.insert(result.at((current1dac-dac1min)/dac1step*((dac2max-dac2min)/dac2step+1) + (current2dac-dac2min)/dac2step).second.second.end(),
1962 (*Eventit)->pixels.begin(),
1963 (*Eventit)->pixels.end());
1965 current2dac += dac2step;
1969 for(std::vector<Event*>::iterator it = packed.begin(); it != packed.end(); ++it) {
delete *it; }
1971 LOG(logDEBUGAPI) <<
"Correctly repacked DacDacScan data for delivery.";
1972 LOG(logDEBUGAPI) <<
"Repacking took " << t <<
"ms.";
1977 void pxarCore::MaskAndTrimNIOS() {
1983 for (std::vector<rocConfig>::iterator rocit =
_dut->roc.begin(); rocit !=
_dut->roc.end(); ++rocit) {
1984 _hal->SetupTrimValues(rocit->i2c_address,rocit->pixels);
1989 void pxarCore::MaskAndTrim(
bool trim) {
1991 for (std::vector<rocConfig>::iterator rocit =
_dut->roc.begin(); rocit !=
_dut->roc.end(); ++rocit) {
1992 MaskAndTrim(trim,rocit);
1997 void pxarCore::MaskAndTrim(
bool trim, std::vector<rocConfig>::iterator rocit) {
2001 LOG(logDEBUGAPI) <<
"ROC@I2C " <<
static_cast<int>(rocit->i2c_address) <<
" features "
2002 << static_cast<int>(std::count_if(rocit->pixels.begin(),rocit->pixels.end(),
configMaskSet(
true)))
2003 <<
" masked pixels.";
2004 LOG(logDEBUGAPI) <<
"Unmasking and trimming ROC@I2C " <<
static_cast<int>(rocit->i2c_address) <<
" in one go.";
2005 _hal->RocSetMask(rocit->i2c_address,
false,rocit->pixels);
2009 LOG(logDEBUGAPI) <<
"Masking ROC@I2C " <<
static_cast<int>(rocit->i2c_address) <<
" in one go.";
2010 _hal->RocSetMask(rocit->i2c_address,
true);
2019 for (std::vector<rocConfig>::iterator rocit =
_dut->roc.begin(); rocit !=
_dut->roc.end(); ++rocit) {
2021 LOG(logDEBUGAPI) <<
"Configuring calibrate bits in all enabled PUCs of ROC@I2C " <<
static_cast<int>(rocit->i2c_address);
2025 for(std::vector<pixelConfig>::iterator pxit = rocit->pixels.begin(); pxit != rocit->pixels.end(); ++pxit) {
2026 if(pxit->enable() ==
true) { _hal->PixelSetCalibrate(rocit->i2c_address,pxit->column(),pxit->row(),0); }
2031 else {_hal->RocClearCalibrate(rocit->i2c_address);}
2035 void pxarCore::checkTestboardDelays(std::vector<std::pair<std::string,uint8_t> > sig_delays) {
2038 std::map<uint8_t,uint8_t> delays;
2039 for(std::vector<std::pair<std::string,uint8_t> >::iterator sigIt = sig_delays.begin(); sigIt != sig_delays.end(); ++sigIt) {
2042 uint8_t sigRegister, sigValue = sigIt->second;
2043 if(!verifyRegister(sigIt->first,sigRegister,sigValue,DTB_REG))
continue;
2045 std::pair<std::map<uint8_t,uint8_t>::iterator,
bool> ret;
2046 ret = delays.insert( std::make_pair(sigRegister,sigValue) );
2047 if(ret.second ==
false) {
2048 LOG(logWARNING) <<
"Overwriting existing DTB delay setting \"" << sigIt->first
2049 <<
"\" value " <<
static_cast<int>(ret.first->second)
2050 <<
" with " << static_cast<int>(sigValue);
2051 delays[sigRegister] = sigValue;
2055 _dut->sig_delays = delays;
2058 void pxarCore::checkTestboardPower(std::vector<std::pair<std::string,double> > power_settings) {
2061 double va = 2.5, vd = 3.0, ia = 3.0,
id = 3.0;
2062 for(std::vector<std::pair<std::string,double> >::iterator it = power_settings.begin(); it != power_settings.end(); ++it) {
2063 std::transform((*it).first.begin(), (*it).first.end(), (*it).first.begin(), ::tolower);
2065 if((*it).second < 0) {
2066 LOG(logERROR) <<
"Negative value for power setting \"" << (*it).first <<
"\". Using default limit.";
2070 if((*it).first.compare(
"va") == 0) {
2071 if((*it).second > va) { LOG(logWARNING) <<
"Limiting \"" << (*it).first <<
"\" to " << va; }
2072 else { va = (*it).second; }
2075 else if((*it).first.compare(
"vd") == 0) {
2076 if((*it).second > vd) { LOG(logWARNING) <<
"Limiting \"" << (*it).first <<
"\" to " << vd; }
2077 else {vd = (*it).second; }
2080 else if((*it).first.compare(
"ia") == 0) {
2081 if((*it).second > ia) { LOG(logWARNING) <<
"Limiting \"" << (*it).first <<
"\" to " << ia; }
2082 else { ia = (*it).second; }
2085 else if((*it).first.compare(
"id") == 0) {
2086 if((*it).second >
id) { LOG(logWARNING) <<
"Limiting \"" << (*it).first <<
"\" to " << id; }
2087 else {
id = (*it).second; }
2090 else { LOG(logERROR) <<
"Unknown power setting " << (*it).first <<
"! Skipping.";}
2093 if(va < 0.01 || vd < 0.01 || ia < 0.01 ||
id < 0.01) {
2094 LOG(logCRITICAL) <<
"Power settings are not sufficient. Please check and re-configure!";
2095 throw InvalidConfig(
"Power settings are not sufficient. Please check and re-configure.");
2099 void pxarCore::verifyPatternGenerator(std::vector<std::pair<std::string,uint8_t> > &pg_setup) {
2101 std::vector<std::pair<uint16_t,uint8_t> > patterns;
2107 if(pg_setup.size() > 256) {
2108 LOG(logCRITICAL) <<
"Pattern too long (" << pg_setup.size() <<
" entries) for pattern generator. "
2109 <<
"Only 256 entries allowed!";
2110 throw InvalidConfig(
"Pattern too long for pattern generator. Please check and re-configure.");
2112 else { LOG(logDEBUGAPI) <<
"Pattern generator setup with " << pg_setup.size() <<
" entries provided."; }
2115 bool have_trigger =
false;
2116 bool have_tbmreset =
false;
2119 for(std::vector<std::pair<std::string,uint8_t> >::iterator it = pg_setup.begin(); it != pg_setup.end(); ++it) {
2122 if(it->second == 0 && it != pg_setup.end() -1 ) {
2123 LOG(logCRITICAL) <<
"Found delay = 0 on early entry! This stops the pattern generator at position "
2124 <<
static_cast<int>(it - pg_setup.begin()) <<
".";
2125 throw InvalidConfig(
"Found delay = 0 on early entry! This stops the pattern generator.");
2129 if(it == pg_setup.end() - 1 && it->second != 0) {
2130 LOG(logWARNING) <<
"No delay = 0 found on last entry. Setting last delay to 0 to stop the pattern generator.";
2135 std::transform(it->first.begin(), it->first.end(), it->first.begin(), ::tolower);
2137 std::istringstream signals(it->first);
2139 uint16_t signal = 0;
2141 while (std::getline(signals, s,
';')) {
2143 uint16_t sig = _dict->getSignal(s);
2144 if(sig != PG_ERR) signal += sig;
2146 LOG(logCRITICAL) <<
"Could not find pattern generator signal \"" << s <<
"\" in the dictionary!";
2147 throw InvalidConfig(
"Wrong pattern generator signal provided.");
2151 if(sig == PG_TRG) have_trigger =
true;
2152 if(sig == PG_REST) have_tbmreset =
true;
2154 LOG(logDEBUGAPI) <<
"Found PG signal " << s <<
" (" << std::hex << sig << std::dec <<
")";
2156 patterns.push_back(std::make_pair(signal,it->second));
2161 LOG(logWARNING) <<
"Pattern generator does not contain a trigger signal. "
2162 <<
"No data is expected from the DUT!";
2167 LOG(logWARNING) <<
"Pattern generator contains TBM Reset signal. "
2168 <<
"No event number cross checks possible.";
2172 _dut->pg_setup = patterns;
2174 _dut->pg_sum = getPatternGeneratorDelaySum(
_dut->pg_setup);
2177 uint32_t pxarCore::getPatternGeneratorDelaySum(std::vector<std::pair<uint16_t,uint8_t> > &pg_setup) {
2179 uint32_t delay_sum = 0;
2181 for(std::vector<std::pair<uint16_t,uint8_t> >::iterator it = pg_setup.begin(); it != pg_setup.end(); ++it) { delay_sum += (*it).second + 1; }
2184 LOG(logDEBUGAPI) <<
"Sum of Pattern generator delays: " << delay_sum <<
" clk";
2190 LOG(logDEBUGAPI) <<
"Setting clock to " << (enable ?
"external" :
"internal") <<
" source.";
2193 if(_hal->IsClockPresent()) { _hal->SetClockSource(CLK_SRC_EXT);
return true; }
2194 else LOG(logCRITICAL) <<
"DTB reports that no external clock is present!";
2199 _hal->SetClockSource(CLK_SRC_INT);
2206 uint8_t sigRegister, value = 0;
2207 if(!verifyRegister(signal, sigRegister, value, DTB_REG))
return;
2209 LOG(logDEBUGAPI) <<
"Setting signal " << signal <<
" ("
2210 <<
static_cast<int>(sigRegister) <<
") to mode "
2211 << static_cast<int>(mode) <<
".";
2212 _hal->SigSetMode(sigRegister, mode);
2217 LOG(logDEBUGAPI) <<
"Set Clock Stretch " <<
static_cast<int>(src) <<
" " << static_cast<int>(delay) <<
" " <<
static_cast<int>(width);
2218 _hal->SetClockStretch(src,width,delay);
2224 if( !
status() ) {
return 0; }
2226 return _hal->GetADC( rpc_par1 );
std::vector< pixel > getPulseheightMap(uint16_t flags, uint16_t nTriggers)
bool setExternalClock(bool enable)
void setPatternGenerator(std::vector< std::pair< std::string, uint8_t > > pg_setup)
void daqTriggerLoopHalt()
std::vector< std::pair< uint8_t, std::vector< pixel > > > getPulseheightVsDAC(std::string dacName, uint8_t dacMin, uint8_t dacMax, uint16_t flags, uint16_t nTriggers)
bool setDAC(std::string dacName, uint8_t dacValue, uint8_t rocI2C)
statistics getStatistics()
std::vector< std::pair< uint8_t, std::vector< pixel > > > getThresholdVsDAC(std::string dacName, std::string dac2name, uint8_t dac2min, uint8_t dac2max, uint16_t flags, uint16_t nTriggers)
uint8_t getDACRange(std::string dacName)
std::vector< uint8_t > getEnabledRocI2Caddr()
bool comparePixelConfiguration(const std::vector< pixelConfig > pxA, const std::vector< pixelConfig > pxB)
bool SignalProbe(std::string probe, std::string name)
std::vector< std::vector< uint16_t > > daqGetReadback()
pxarCore(std::string usbId="*", std::string logLevel="WARNING")
std::vector< rocConfig > getEnabledRocs()
void setSignalMode(std::string signal, uint8_t mode)
void setTestboardDelays(std::vector< std::pair< std::string, uint8_t > > sig_delays)
uint16_t daqTriggerLoop(uint16_t period=1000)
std::vector< std::pair< uint8_t, std::vector< pixel > > > getEfficiencyVsDAC(std::string dacName, uint8_t dacMin, uint8_t dacMax, uint16_t flags, uint16_t nTriggers)
std::vector< pixel > getThresholdMap(std::string dacName, uint8_t dacStep, uint8_t dacMin, uint8_t dacMax, uint16_t flags, uint16_t nTriggers)
void setTestboardPower(std::vector< std::pair< std::string, double > > power_settings)
std::vector< std::pair< uint8_t, std::pair< uint8_t, std::vector< pixel > > > > getPulseheightVsDACDAC(std::string dac1name, uint8_t dac1min, uint8_t dac1max, std::string dac2name, uint8_t dac2min, uint8_t dac2max, uint16_t flags, uint16_t nTriggers)
std::vector< uint8_t > getEnabledRocIDs()
void SetCalibrateBits(bool enable)
bool flashTB(std::string filename)
uint16_t GetADC(uint8_t rpc_par1)
bool setTbmReg(std::string regName, uint8_t regValue, uint8_t tbmid)
std::vector< uint16_t > daqGetBuffer()
std::vector< std::pair< uint8_t, std::pair< uint8_t, std::vector< pixel > > > > getEfficiencyVsDACDAC(std::string dac1name, uint8_t dac1min, uint8_t dac1max, std::string dac2name, uint8_t dac2min, uint8_t dac2max, uint16_t flags, uint16_t nTriggers)
std::vector< pixel > getEfficiencyMap(uint16_t flags, uint16_t nTriggers)
std::vector< pixelConfig > getEnabledPixels(size_t rocid)
std::vector< uint8_t > getRocI2Caddr()
bool initDUT(uint8_t hubId, std::string tbmtype, std::vector< std::vector< std::pair< std::string, uint8_t > > > tbmDACs, std::string roctype, std::vector< std::vector< std::pair< std::string, uint8_t > > > rocDACs, std::vector< std::vector< pixelConfig > > rocPixels, std::vector< uint8_t > rocI2Cs)
uint8_t getDAC(size_t rocId, std::string dacName)
void setClockStretch(uint8_t src, uint16_t delay, uint16_t width)
std::vector< Event > daqGetEventBuffer()
uint16_t daqTrigger(uint32_t nTrig=1, uint16_t period=0)
rawEvent daqGetRawEvent()
std::vector< tbmConfig > getEnabledTbms()
std::vector< Event * >(hal::* HalMemFnRocParallel)(std::vector< uint8_t > rocids, std::vector< int32_t > parameter)
bool initTestboard(std::vector< std::pair< std::string, uint8_t > > sig_delays, std::vector< std::pair< std::string, double > > power_settings, std::vector< std::pair< std::string, uint8_t > > pg_setup)
std::vector< rawEvent > daqGetRawEventBuffer()