19 namespace ba = boost::asio;
20 namespace bs = boost::system;
62 Out() << endl <<
kBold <<
"First header received:" << endl;
65 Out() << Converter::GetHex<uint16_t>(fHeader, 16) << endl;
77 Out() << endl <<
kBold <<
"Header received:" << endl;
80 Out() << Converter::GetHex<uint16_t>(fHeader, 16) << endl;
88 Out() << endl <<
kBold <<
"FtuList received:" << endl;
91 Out() << Converter::GetHex<uint16_t>(fFtuList, 16) << endl;
99 Out() << endl <<
kBold <<
"Static data received:" << endl;
100 Out() << fStaticData;
102 Out() << Converter::GetHex<uint16_t>(fStaticData, 16) << endl;
110 Out() << endl <<
kBold <<
"Dynamic data received:" << endl;
111 Out() << fDynamicData;
113 Out() << Converter::GetHex<uint16_t>(fDynamicData, 16) << endl;
121 Out() << endl <<
kRed <<
"Error received:" << endl;
124 Out() << Converter::GetHex<uint16_t>(
fError, 16) << endl;
135 Out() <<
"Received: ";
158 const uint16_t ref = data[0].fPrescaling;
159 for (
int i=1;
i<40;
i++)
164 data[
i].fPrescaling = ref;
169 for (
int i=0;
i<4;
i++)
179 Warn(
"GeneralSettings not consistent with trigger sequence.");
181 Warn(
"Prescaling not consistent for all boards.");
183 Warn(
"Not all FTUs are enabled - enable all FTUs.");
185 return !warn1 && !warn2 && !warn3;
192 if (bytes_received==0 || err)
194 if (err==ba::error::eof)
195 Warn(
"Connection closed by remote host (FTM).");
199 if (err && err!=ba::error::eof &&
200 err!=ba::error::basic_errors::not_connected &&
201 err!=ba::error::basic_errors::operation_aborted)
204 str <<
"Reading from " << URL() <<
": " << err.message() <<
" (" << err <<
")";
207 PostClose(err!=ba::error::basic_errors::operation_aborted);
218 str <<
"Excepted " <<
sizeof(
FTM::Header) <<
" bytes (FTM::Header) but received " << bytes_received <<
".";
230 str <<
"Invalid header received: start delimiter wrong, received ";
247 switch (fHeader.
fType)
264 str <<
"Unknonw type " << fHeader.
fType <<
" in received header." << endl;
277 str <<
"Invalid data received: end delimiter wrong, received ";
292 fCounter[fHeader.
fType]++;
295 switch (fHeader.
fType)
307 if (!CheckConsistency(data))
309 CmdSendStatDat(data);
315 fStaticData = fBuffer;
318 if (!fBufStaticData.
valid())
319 fBufStaticData = fStaticData;
325 fDynamicData = fBuffer;
332 Out() << endl <<
kBold <<
"Register received: " << endl;
333 Out() <<
"Addr: " << ntohs(fBuffer[0]) << endl;
334 Out() <<
"Value: " << ntohs(fBuffer[1]) << endl;
345 str <<
"Unknonw type " << fHeader.
fType <<
" in header." << endl;
351 catch (
const logic_error &e)
354 str <<
"Exception converting buffer into data structure: " << e.what();
372 fBufStaticData.
clear();
391 if (error==ba::error::basic_errors::operation_aborted)
397 str <<
"Read timeout of " << URL() <<
": " << error.message() <<
" (" << error <<
")";
416 if (fInTimeout.expires_at() > ba::deadline_timer::traits_type::now())
419 Error(
"Timeout ("+to_simple_string(fInTimeout.expires_from_now())+
") reading data from "+URL());
425 void PostCmd(array<uint16_t, N> dat, uint16_t u1=0, uint16_t u2=0, uint16_t u3=0, uint16_t u4=0)
427 array<uint16_t, 5> cmd = {{
'@', u1, u2, u3, u4 }};
432 msg <<
"Sending command:" << hex;
433 msg <<
" 0x" << setw(4) << setfill(
'0') << cmd[0];
434 msg <<
" 0x" << setw(4) << setfill(
'0') << u1;
435 msg <<
" 0x" << setw(4) << setfill(
'0') << u2;
436 msg <<
" 0x" << setw(4) << setfill(
'0') << u3;
437 msg <<
" 0x" << setw(4) << setfill(
'0') << u4;
438 msg <<
" (+" << dec << dat.size() <<
" words)";
442 vector<uint16_t> out(cmd.size()+dat.size());
444 transform(cmd.begin(), cmd.end(), out.begin(), htons);
445 transform(dat.begin(), dat.end(), out.begin()+cmd.size(), htons);
450 void PostCmd(vector<uint16_t> dat, uint16_t u1=0, uint16_t u2=0, uint16_t u3=0, uint16_t u4=0)
452 array<uint16_t, 5> cmd = {{
'@', u1, u2, u3, u4 }};
457 msg <<
"Sending command:" << hex;
458 msg <<
" 0x" << setw(4) << setfill(
'0') << cmd[0];
459 msg <<
" 0x" << setw(4) << setfill(
'0') << u1;
460 msg <<
" 0x" << setw(4) << setfill(
'0') << u2;
461 msg <<
" 0x" << setw(4) << setfill(
'0') << u3;
462 msg <<
" 0x" << setw(4) << setfill(
'0') << u4;
463 msg <<
" (+" << dec << dat.size() <<
" words)";
467 vector<uint16_t> out(cmd.size()+dat.size());
469 transform(cmd.begin(), cmd.end(), out.begin(), htons);
470 copy(dat.begin(), dat.end(), out.begin()+cmd.size());
475 void PostCmd(uint16_t u1=0, uint16_t u2=0, uint16_t u3=0, uint16_t u4=0)
477 PostCmd(array<uint16_t, 0>(), u1, u2, u3, u4);
485 fIsVerbose(true), fIsDynamicOut(true), fIsHexOutput(true)
512 fBufStaticData =
data;
527 Info(
"Sending start trigger.");
535 Info(
"Sending stop trigger.");
540 const array<uint16_t, 2>
data = {{ uint16_t(n>>16), uint16_t(n&0xffff) }};
552 const array<uint16_t, 2>
data = {{ addr, val }};
555 reinterpret_cast<uint16_t*
>(&fBufStaticData)[addr] = val;
569 const array<uint16_t, 1>
data = {{ addr }};
581 Info(
"Sending crate reset for crate "+to_string(addr));
593 Info(
"Sending camera reset");
628 if (name.rfind(
".bin")!=name.length()-4)
642 if (fin.fail() || fin.eof())
648 CmdSendStatDat(data);
655 if (name.rfind(
".bin")!=name.length()-4)
662 fout.write(reinterpret_cast<const char*>(&fStaticData),
sizeof(
FTM::StaticData));
681 if (data[
i/4].
fDAC[
i%4] != value)
691 data[
i/4].
fDAC[
i%4] = value;
694 CmdSendStatDat(data);
705 const uint16_t addr = (uintptr_t(&fStaticData[patch/4].
fDAC[patch%4])-uintptr_t(&fStaticData))/2;
708 const array<uint16_t, 2>
data = {{ addr, uint16_t(value) }};
711 reinterpret_cast<uint16_t*
>(&fBufStaticData)[addr] = value;
732 if (th[
i]<0 || fBufStaticData[
i/4].
fDAC[
i%4]==th[
i])
736 const uint16_t addr = (uintptr_t(&fStaticData[i/4].
fDAC[i%4])-uintptr_t(&fStaticData))/2;
738 reinterpret_cast<uint16_t*
>(&fBufStaticData)[addr] = th[i];
741 const array<uint16_t, 2> arr = {{ addr, uint16_t(th[i]) }};
763 CmdSendStatDat(data);
782 if (data[
i].
fDAC[4] != value)
792 data[
i].
fDAC[4] = value;
795 CmdSendStatDat(data);
811 const uint16_t addr = (uintptr_t(&fStaticData[patch].
fDAC[4])-uintptr_t(&fStaticData))/2;
814 const array<uint16_t, 2>
data = {{ addr, uint16_t(value) }};
817 reinterpret_cast<uint16_t*
>(&fBufStaticData)[addr] = value;
836 for (
int i=0;
i<40;
i++)
849 CmdSendStatDat(data);
878 CmdSendStatDat(data);
893 CmdSendStatDat(data);
898 bool SetVal(uint16_t *dest, uint32_t val, uint32_t max)
908 dest =
reinterpret_cast<uint16_t*
>(&
data) + (dest - reinterpret_cast<uint16_t*>(&fStaticData));
912 CmdSendStatDat(data);
937 return SetVal(&fStaticData.
fDeadTime, val,
947 data.
Enable(type, enable);
948 CmdSendStatDat(data);
972 CmdSendStatDat(data);
989 CmdSendStatDat(data);
1006 CmdSendStatDat(data);
1023 CmdSendStatDat(data);
1040 CmdSendStatDat(data);
1049 for (
int i=0;
i<8;
i++)
1050 if (reg[
i]>0xffffffff)
1055 CmdSendStatDat(data);
1073 CmdSendStatDat(data);
1094 CmdSendStatDat(data);
1111 CmdSendStatDat(data);
1124 const uintptr_t base = uintptr_t(&data);
1125 const uint16_t *mem = data.
EnablePixel(idx, enable);
1128 const uint16_t addr = (uintptr_t(mem)-base)/2;
1131 const array<uint16_t, 2> cmd = {{ addr, *mem }};
1134 reinterpret_cast<uint16_t*
>(&fBufStaticData)[addr] = *mem;
1156 CmdSendStatDat(data);
1171 CmdSendStatDat(data);
1187 CmdSendStatDat(data);
1201 CmdSendStatDat(data);
1225 throw runtime_error(
"ConnectionFTM::GetState - Impossible code reached.");
1264 fDimPassport.
Update(data);
1284 fDimFtuList.
Update(data);
1293 fDimStaticData.
Update(data);
1302 fDimDynamicData.
Update(data);
1304 uint64_t odiff = fDynamicData.fOnTimeCounter;
1305 uint32_t cdiff = fHeader.fTriggerCounter;
1306 uint64_t tdiff = fHeader.fTimeStamp;
1319 const bool first = state!=fPrevState ||
1320 fHeader.fTimeStamp<fTimeStamp ||
1321 fHeader.fTriggerCounter<fTriggerCounter ||
1322 fDynamicData.fOnTimeCounter<fTimeStampOn;
1327 odiff -= fTimeStampOn;
1334 const float rate = tdiff==0 ? 0 : 1e6*cdiff/tdiff;
1336 fTimeStamp = fHeader.fTimeStamp;
1337 fTimeStampOn = fDynamicData.fOnTimeCounter;
1338 fTriggerCounter = fHeader.fTriggerCounter;
1342 rate, tdiff*1e-6, odiff*1e-6);
1345 fDimTriggerRates.
Update(rates);
1371 fDimCounter.
Update(counter);
1377 fDimPassport (
"FTM_CONTROL/PASSPORT",
"X:1;S:1",
1378 "Info about the FTM and FPGA version" 1379 "|BoardId[int]:BoardId, hexCode" 1380 "|DNA[int]:DNA of the FTM board"),
1381 fDimTriggerRates (
"FTM_CONTROL/TRIGGER_RATES",
"X:1;X:1;I:1;F:1;F:40;F:160;F:1;F:1",
1382 "Patch,Board,Camera trigger rates" 1383 "|FTMtimeStamp[us]:Time in microseconds, since trigger enabled or disabled" 1384 "|OnTimeCounter[us]:Effective on-time, ie. FTM triggers (eg. w/o busy)" 1385 "|TriggerCounter[int]:Counter of triggers since enabled or disabled" 1386 "|TriggerRate[Hz]:Trigger rate" 1387 "|BoardRate[Hz]:Trigger rate of individual FTUs" 1388 "|PatchRate[Hz]:Trigger rate of individual patches" 1389 "|ElapsedTime[s]:Time elapsed since previous report" 1390 "|OnTime[s]:OnTime elapsed since previous report"),
1391 fDimError (
"FTM_CONTROL/ERROR",
"X:1;S:1;S:28",
""),
1392 fDimFtuList (
"FTM_CONTROL/FTU_LIST",
"X:1;X:1;S:1;C:4;X:40;C:40;C:40",
1393 "Logs the changes of status of the FTUs" 1394 "|FTMtimeStamp[us]:Time in microseconds" 1395 "|ActiveFTU[bitpattern]:Description of enabled FTUs" 1396 "|NumBoards[int]:Total number of enabled FTUs" 1397 "|NumBoardsCrate[int]:Total number of enabled FTUs per crate" 1398 "|DNA[hexCode]:Hex code identifier of FTUs" 1399 "|Addr[bitpattern]:Crate address (hardware) of FTUs" 1400 "|Ping[int]:Number of pings until FTU response"),
1401 fDimStaticData (
"FTM_CONTROL/STATIC_DATA",
"X:1;S:1;S:1;X:1;S:1;S:3;C:4;S:1;S:1;S:1;S:1;S:1;S:1;I:1;I:8;S:90;S:160;S:40;S:40",
1402 "Configuration of FTM and FTUs" 1403 "|FTMtimeStamp[us]:Time in microseconds, since trigger enabled or disabled" 1404 "|GeneralSettings[bitpattern]:Status of the FTM settings (cf. FTM doc)" 1405 "|LEDStatus[bitpattern]:Not Used" 1406 "|ActiveFTU[bitpattern]:List of enabled FTUs" 1407 "|TriggerInterval[bitpattern]:Period of cal. and ped. events (cf. FTM doc)" 1408 "|TriggerSeq[int]:Sequence of calib. and pedestal events (LPint, LPext, Ped)" 1409 "|LPSettings[bitpattern]:Settings of LP, enabled int, ext, intensity int, ext" 1410 "|PhysTrigMult[int]:N for N out of 40 logic on FTM (Physics)" 1411 "|CalibTrigMult[int]: N for N out of 40 logic on FTM (Calib)" 1412 "|PhysTrigWindow[ns]:Coincidence window for N out of 40 (Physics)" 1413 "|CalibTrigWindow[ns]:Coincidence window for N out of 40 (Calib)" 1414 "|TrigDelay[ns]:Trigger delay applied on FTM" 1415 "|TMDelay[ns]:TM delay applied on FTM" 1416 "|DeadTime[ns]:Dead time applied after each event on the FTM" 1417 "|ClkCond[bitpattern]:Clock conditionner settings on the FTM (DRS sampling freq.)" 1418 "|PixEnabled[bitpattern]:Enabled pixels, pckd in 90 shorts (160*9bits=180bytes)" 1419 "|PatchThresh[DACcounts]:Threshold of the trigger patches" 1420 "|Multiplicity[DACcounts]:N out of 4 logic settings per FTU" 1421 "|Prescaling[500ms]:Update rate of the rate counter"),
1422 fDimDynamicData (
"FTM_CONTROL/DYNAMIC_DATA",
"X:1;X:1;F:4;I:160;I:40;S:40;S:40;S:40;S:1",
1423 "Regular reports sent by FTM" 1424 "|FTMtimeStamp[us]:Time in microseconds, since trigger enabled or disabled" 1425 "|OnTimeCounter[us]:Ontime, i.e. FTM processes triggers (e.g. No FAD busy)" 1426 "|Temperatures[Nan]:not yet defined nor used (wanna be FTM onboard temps)" 1427 "|TriggerPatchCounter[int]:counting since last update (prescaling)" 1428 "|BoardsCounter[int]:FTU board counting after N out of 4 and since last update" 1429 "|RateOverflow[bitpattern]:bits 0-4=patches overflow, 5=board overflow, 1 per board" 1430 "|Prescaling[500ms]:Update rate of the rate counter" 1431 "|CrcError[int]:Number of checksum error in RS485 communication" 1432 "|State[int]:State value of the FTM firmware (cf. FTM doc)"),
1433 fDimCounter (
"FTM_CONTROL/COUNTER",
"I:1;I:1;I:1;I:1;I:1;I:1",
1434 "Communication statistics to or from FTM control and FTM" 1435 "|NumHeaders[int]:Num. of headers (any header) received by ftm control" 1436 "|NumStaticData[int]:Num. of static data blocks (ftm and ftu settings)" 1437 "|NumDynamicData[int]:Num. of dynamic data blocks (e.g. rates)" 1438 "|NumFtuList[int]:Num. of FTU list (FTU identifiers, answer from ping)" 1439 "|NumErrors[int]:Num. of error messages" 1440 "|NumRegister[int]:Num. of answers from a single register accesess"),
1441 fTimeStamp(0), fTimeStampOn(0), fTriggerCounter(0), fPrevState(0)
1450 template <
class T,
class S>
1456 return T::GetCurrentState();
1459 function<int(const EventImp &)>
Wrapper(
function<
void()> func)
1473 msg << name <<
" - Received event has " << has <<
" bytes, but expected " << size <<
".";
1480 if (!CheckEventSize(evt.
GetSize(),
"SetRegister", 8))
1481 return T::kSM_FatalError;
1483 const uint32_t *dat = evt.
Ptr<uint32_t>();
1485 if (dat[1]>uint16_t(-1))
1488 msg << hex <<
"Value " << dat[1] <<
" out of range.";
1490 return T::GetCurrentState();
1494 if (dat[0]>uint16_t(-1) || !fFTM.CmdSetRegister(dat[0], dat[1]))
1497 msg << hex <<
"Address " << dat[0] <<
" out of range.";
1501 return T::GetCurrentState();
1506 if (!CheckEventSize(evt.
GetSize(),
"GetRegister", 4))
1507 return T::kSM_FatalError;
1509 const unsigned int addr = evt.
GetInt();
1510 if (addr>uint16_t(-1) || !fFTM.CmdGetRegister(addr))
1513 msg << hex <<
"Address " << addr <<
" out of range.";
1517 return T::GetCurrentState();
1535 return T::GetCurrentState();
1543 if (!CheckEventSize(evt.
GetSize(),
"TakeNevents", 4))
1544 return T::kSM_FatalError;
1546 const unsigned int dat = evt.
GetUInt();
1557 fFTM.CmdTakeNevents(dat);
1559 return T::GetCurrentState();
1564 if (!CheckEventSize(evt.
GetSize(),
"DisableReports", 1))
1565 return T::kSM_FatalError;
1567 fFTM.CmdDisableReports(evt.
GetBool());
1569 return T::GetCurrentState();
1574 if (!CheckEventSize(evt.
GetSize(),
"SetVerbosity", 1))
1575 return T::kSM_FatalError;
1577 fFTM.SetVerbose(evt.
GetBool());
1579 return T::GetCurrentState();
1584 if (!CheckEventSize(evt.
GetSize(),
"SetHexOutput", 1))
1585 return T::kSM_FatalError;
1587 fFTM.SetHexOutput(evt.
GetBool());
1589 return T::GetCurrentState();
1594 if (!CheckEventSize(evt.
GetSize(),
"SetDynamicOut", 1))
1595 return T::kSM_FatalError;
1597 fFTM.SetDynamicOut(evt.
GetBool());
1599 return T::GetCurrentState();
1604 if (fFTM.LoadStaticData(evt.
GetString()))
1605 return T::GetCurrentState();
1608 msg <<
"Loading static data from file '" << evt.
GetString() <<
"' failed ";
1611 msg <<
"(" << strerror(errno) <<
")";
1613 msg <<
"(wrong size, expected " <<
sizeof(
FTM::StaticData) <<
" bytes)";
1617 return T::GetCurrentState();
1622 if (fFTM.SaveStaticData(evt.
GetString()))
1623 return T::GetCurrentState();
1626 msg <<
"Writing static data to file '" << evt.
GetString() <<
"' failed ";
1627 msg <<
"(" << strerror(errno) <<
")";
1631 return T::GetCurrentState();
1636 if (!CheckEventSize(evt.
GetSize(),
"SetThreshold", 8))
1637 return T::kSM_FatalError;
1639 const int32_t *
data = evt.
Ptr<int32_t>();
1641 if (!fFTM.SetThreshold(data[0], data[1]))
1644 msg <<
"SetThreshold - Maximum allowed patch number 159, valid value range 0-0xffff (got: " << data[0] <<
" " << data[1] <<
")";
1648 return T::GetCurrentState();
1653 if (!CheckEventSize(evt.
GetSize(),
"SetSelectedThresholds", 160*4))
1654 return T::kSM_FatalError;
1656 const int32_t *
data = evt.
Ptr<int32_t>();
1657 if (!fFTM.SetSelectedThresholds(data))
1660 msg <<
"SetSelectedThresholds - Value out of range, maximum 0xffff.";
1664 return T::GetCurrentState();
1669 if (!CheckEventSize(evt.
GetSize(),
"SetAllThresholds", 160*4))
1670 return T::kSM_FatalError;
1672 const int32_t *
data = evt.
Ptr<int32_t>();
1673 if (!fFTM.SetAllThresholds(data))
1676 msg <<
"SetAllThresholds - Value out of range [0; 0xffff]";
1680 return T::GetCurrentState();
1685 if (!CheckEventSize(evt.
GetSize(),
"SetNoutof4", 8))
1686 return T::kSM_FatalError;
1688 const int32_t *
data = evt.
Ptr<int32_t>();
1690 if (!fFTM.SetNoutof4(data[0], data[1]))
1691 T::Warn(
"SetNoutof4 - Maximum allowed board number 39, valid value range 0-0xffff");
1693 return T::GetCurrentState();
1698 if (!CheckEventSize(evt.
GetSize(),
"EnableFTU", 5))
1699 return T::kSM_FatalError;
1701 const int32_t &board = evt.
Get<int32_t>();
1702 const int8_t &enable = evt.
Get<int8_t>(4);
1704 if (!fFTM.EnableFTU(board, enable))
1705 T::Warn(
"EnableFTU - Board number must be <40.");
1707 return T::GetCurrentState();
1712 if (!CheckEventSize(evt.
GetSize(),
"ToggleFTU", 4))
1713 return T::kSM_FatalError;
1715 if (!fFTM.ToggleFTU(evt.
GetInt()))
1716 T::Warn(
"ToggleFTU - Allowed range of boards 0-39.");
1718 return T::GetCurrentState();
1723 if (!CheckEventSize(evt.
GetSize(),
"SetTriggerInterval", 4))
1724 return T::kSM_FatalError;
1726 if (!fFTM.SetTriggerInterval(evt.
GetInt()))
1727 T::Warn(
"SetTriggerInterval - Value out of range.");
1729 return T::GetCurrentState();
1734 if (!CheckEventSize(evt.
GetSize(),
"SetTriggerDelay", 4))
1735 return T::kSM_FatalError;
1737 if (!fFTM.SetTriggerDelay(evt.
GetInt()))
1738 T::Warn(
"SetTriggerDealy - Value out of range.");
1740 return T::GetCurrentState();
1745 if (!CheckEventSize(evt.
GetSize(),
"SetTimeMarkerDelay", 4))
1746 return T::kSM_FatalError;
1748 if (!fFTM.SetTimeMarkerDelay(evt.
GetInt()))
1749 T::Warn(
"SetTimeMarkerDelay - Value out of range.");
1751 return T::GetCurrentState();
1756 if (!CheckEventSize(evt.
GetSize(),
"SetPrescaling", 4))
1757 return T::kSM_FatalError;
1759 if (!fFTM.SetPrescaling(evt.
GetInt()-1))
1760 T::Warn(
"SetPrescaling - Value out of range.");
1762 return T::GetCurrentState();
1767 if (!CheckEventSize(evt.
GetSize(),
"SetTriggerSeq", 6))
1768 return T::kSM_FatalError;
1770 const uint16_t *
data = evt.
Ptr<uint16_t>();
1772 if (!fFTM.SetTriggerSeq(data))
1773 T::Warn(
"SetTriggerSeq - Value out of range.");
1775 return T::GetCurrentState();
1780 if (!CheckEventSize(evt.
GetSize(),
"SetDeadTime", 4))
1781 return T::kSM_FatalError;
1783 if (!fFTM.SetDeadTime(evt.
GetInt()))
1784 T::Warn(
"SetDeadTime - Value out of range.");
1786 return T::GetCurrentState();
1791 if (!CheckEventSize(evt.
GetSize(),
"SetTriggerMultiplicity", 2))
1792 return T::kSM_FatalError;
1794 if (!fFTM.SetTriggerMultiplicity(evt.
GetUShort()))
1795 T::Warn(
"SetTriggerMultiplicity - Value out of range.");
1797 return T::GetCurrentState();
1802 if (!CheckEventSize(evt.
GetSize(),
"SetCalibMultiplicity", 2))
1803 return T::kSM_FatalError;
1805 if (!fFTM.SetCalibMultiplicity(evt.
GetUShort()))
1806 T::Warn(
"SetCalibMultiplicity - Value out of range.");
1808 return T::GetCurrentState();
1813 if (!CheckEventSize(evt.
GetSize(),
"SetTriggerWindow", 2))
1814 return T::kSM_FatalError;
1816 if (!fFTM.SetTriggerWindow(evt.
GetUShort()))
1817 T::Warn(
"SetTriggerWindow - Value out of range.");
1819 return T::GetCurrentState();
1824 if (!CheckEventSize(evt.
GetSize(),
"SetCalibWindow", 2))
1825 return T::kSM_FatalError;
1827 if (!fFTM.SetCalibWindow(evt.
GetUShort()))
1828 T::Warn(
"SetCalibWindow - Value out of range.");
1830 return T::GetCurrentState();
1835 if (!CheckEventSize(evt.
GetSize(),
"SetClockRegister", 8*8))
1836 return T::kSM_FatalError;
1838 const uint64_t *reg = evt.
Ptr<uint64_t>();
1840 if (!fFTM.SetClockRegister(reg))
1841 T::Warn(
"SetClockRegister - Value out of range.");
1843 return T::GetCurrentState();
1848 if (!CheckEventSize(evt.
GetSize(),
"SetClockFrequency", 2))
1849 return T::kSM_FatalError;
1851 const map<uint16_t,array<uint64_t, 8>>::const_iterator it =
1854 if (it==fClockCondSetup.end())
1856 T::Warn(
"SetClockFrequency - Frequency not supported.");
1857 return T::GetCurrentState();
1860 if (!fFTM.SetClockRegister(it->second.data()))
1861 T::Warn(
"SetClockFrequency - Register values out of range.");
1863 return T::GetCurrentState();
1868 if (!CheckEventSize(evt.
GetSize(),
"EnableLP", 1))
1869 return T::kSM_FatalError;
1871 if (!fFTM.EnableLP(lp, group, evt.
GetBool()))
1872 T::Warn(
"EnableLP - Invalid light pulser id.");
1874 return T::GetCurrentState();
1879 if (!CheckEventSize(evt.
GetSize(),
"SetIntensity", 2))
1880 return T::kSM_FatalError;
1882 if (!fFTM.SetIntensity(lp, evt.
GetShort()))
1883 T::Warn(
"SetIntensity - Value out of range.");
1885 return T::GetCurrentState();
1890 if (!CheckEventSize(evt.
GetSize(),
"Enable", 1))
1891 return T::kSM_FatalError;
1893 fFTM.Enable(type, evt.
GetBool());
1895 return T::GetCurrentState();
1900 if (!CheckEventSize(evt.
GetSize(),
"EnablePixel", 2))
1901 return T::kSM_FatalError;
1903 if (!fFTM.EnablePixel(evt.
GetUShort(), b))
1904 T::Warn(
"EnablePixel - Value out of range.");
1906 return T::GetCurrentState();
1911 if (!CheckEventSize(evt.
GetSize(),
"DisableAllPixelsExcept", 2))
1912 return T::kSM_FatalError;
1914 if (!fFTM.DisableAllPixelsExcept(evt.
GetUShort()))
1915 T::Warn(
"DisableAllPixelsExcept - Value out of range.");
1917 return T::GetCurrentState();
1922 if (!CheckEventSize(evt.
GetSize(),
"DisableAllPatchesExcept", 2))
1923 return T::kSM_FatalError;
1925 if (!fFTM.DisableAllPatchesExcept(evt.
GetUShort()))
1926 T::Warn(
"DisableAllPatchesExcept - Value out of range.");
1928 return T::GetCurrentState();
1933 if (!CheckEventSize(evt.
GetSize(),
"EnablePatch", 2))
1934 return T::kSM_FatalError;
1936 if (!fFTM.EnablePatch(evt.
GetUShort(), enable))
1937 T::Warn(
"EnablePatch - Value out of range.");
1939 return T::GetCurrentState();
1944 if (!CheckEventSize(evt.
GetSize(),
"TogglePixel", 2))
1945 return T::kSM_FatalError;
1948 T::Warn(
"TogglePixel - Value out of range.");
1950 return T::GetCurrentState();
1955 if (!CheckEventSize(evt.
GetSize(),
"ResetCrate", 2))
1956 return T::kSM_FatalError;
1960 return T::GetCurrentState();
1966 fFTM.PostClose(
false);
1974 return T::GetCurrentState();
1980 fFTM.PostClose(
false);
1984 ba::io_service::poll();
1990 fFTM.PostClose(
true);
1992 return T::GetCurrentState();
2016 const string name = evt.
GetText();
2018 fTargetConfig = fConfigs.find(name);
2019 if (fTargetConfig==fConfigs.end())
2021 T::Error(
"ConfigureFTM - Run-type '"+name+
"' not found.");
2022 return T::GetCurrentState();
2025 T::Message(
"Starting configuration for '"+name+
"' ["+to_string(fFTM.IsTxQueueEmpty())+
"]");
2035 return fFTM.GetState();
2042 switch (fFTM.GetState())
2052 switch (T::GetCurrentState())
2068 fFTM.CmdSendStatDat(fTargetConfig->second);
2070 T::Message(
"Trigger successfully disabled... sending new configuration.");
2093 T::Message(
"Sending new configuration was successfull.");
2095 T::Message(
"Configuration successfully updated.");
2118 fFTM.CmdStartRun(
false);
2132 switch (fFTM.GetState())
2138 throw runtime_error(
"StateMachineFTM - Execute() - Inavlid state.");
2142 return T::GetCurrentState();
2151 "FTM board not connected via ethernet.");
2154 "Ethernet connection to FTM established (no state received yet).");
2157 "Ethernet connection to FTM established, FTM in idle state.");
2160 "FTM in idle state and the last sent and received static data block are bitwise identical.");
2163 "Command to disable run sent... waiting for response.");
2165 "New configuration sent... waiting for response.");
2167 "Received answer identical with target configuration.");
2169 "Waiting for acknowledge of trigger enable.");
2172 "Ethernet connection to FTM established, FTM trigger output to FADs enabled.");
2189 (
"request transmission of dynamic data block");
2193 (
"request transmission of static data from FTM to memory");
2197 (
"read register from address addr" 2198 "|addr[short]:Address of register");
2202 (
"set register to value" 2203 "|addr[short]:Address of register" 2204 "|val[short]:Value to be set");
2208 (
"start a run (start distributing triggers)");
2212 (
"stop a run (stop distributing triggers)");
2216 (
"take n events (distribute n triggers)|number[int]:Number of events to be taken");
2220 (
"disable sending rate reports" 2221 "|status[bool]:disable or enable that the FTM sends rate reports (yes/no)");
2225 (
"Set the comparator threshold" 2226 "|Patch[idx]:Index of the patch (0-159), -1 for all" 2227 "|Threshold[counts]:Threshold to be set in binary counts");
2231 (
"Set the comparator thresholds. Only thresholds which are different and >=0 are sent." 2232 "|Thresholds[counts]:Threshold to be set in binary counts");
2236 (
"Set the comparator thresholds" 2237 "|Thresholds[counts]:Threshold to be set in binary counts");
2241 (
"Set the comparator threshold" 2242 "|Board[idx]:Index of the board (0-39), -1 for all" 2243 "|Threshold[counts]:Threshold to be set in binary counts");
2247 (
"Sets the FTU readout time intervals" 2248 "|time[0.5s]:The interval is given in units of 0.5s, i.e. 1 means 0.5s, 2 means 1s, ...");
2252 (
"Enable or disable FTU" 2253 "|Board[idx]:Index of the board (0-39), -1 for all" 2254 "|Enable[bool]:Whether FTU should be enabled or disabled (yes/no)");
2286 (
"Toggle status of FTU (this is mainly meant to be used in the GUI)" 2287 "|Board[idx]:Index of the board (0-39)");
2291 (
"Sets the trigger interval which is the distance between two consecutive artificial triggers." 2292 "|interval[ms]:The applied trigger interval in millisecond (min 1ms / 10bit)");
2297 "|delay[int]:The applied trigger delay is: delay*4ns+8ns");
2302 "|delay[int]:The applied time marker delay is: delay*4ns+8ns");
2307 "|dead_time[int]:The applied dead time is: dead_time*4ns+8ns");
2311 (
"Switch on the physics trigger" 2312 "|Enable[bool]:Enable physics trigger (yes/no)");
2317 (
"Switch on the triggers through the first external line" 2318 "|Enable[bool]:Enable ext1 trigger (yes/no)");
2323 (
"Switch on the triggers through the second external line" 2324 "|Enable[bool]:Enable ext2 trigger (yes/no)");
2329 "|Enable[bool]:Enable veto (yes/no)");
2333 (
"Enable clock conidtioner output in favor of time marker output" 2334 "|Enable[bool]:Enable clock conditioner (yes/no)");
2358 (
"Setup the sequence of artificial triggers produced by the FTM" 2359 "|Ped[short]:number of pedestal triggers in a row" 2360 "|LPext[short]:number of triggers of the external light pulser" 2361 "|LPint[short]:number of triggers of the internal light pulser");
2365 (
"Setup the Multiplicity condition for physcis triggers" 2366 "|N[int]:Number of requirered coincident triggers from sum-patches (1-40)");
2374 (
"Setup the Multiplicity condition for artificial (calibration) triggers" 2375 "|N[int]:Number of requirered coincident triggers from sum-patches (1-40)");
2397 (
"Reset states during a configuration or in case of configuration error");
2403 (
"Reset one of the crates 0-3" 2404 "|crate[short]:Crate number to be reseted (0-3)");
2408 (
"Reset all crates. The commands are sent in the order 0,1,2,3");
2414 (
"Saves the static data (FTM configuration) from memory to a file" 2415 "|filename[string]:Filename (can include a path), .bin is automatically added");
2419 (
"Loads the static data (FTM configuration) from a file into memory and sends it to the FTM" 2420 "|filename[string]:Filename (can include a path), .bin is automatically added");
2425 T::AddEvent(
"SET_VERBOSE",
"B")
2427 (
"set verbosity state" 2428 "|verbosity[bool]:disable or enable verbosity for received data (yes/no), except dynamic data");
2430 T::AddEvent(
"SET_HEX_OUTPUT",
"B")
2432 (
"enable or disable hex output for received data" 2433 "|hexout[bool]:disable or enable hex output for received data (yes/no)");
2435 T::AddEvent(
"SET_DYNAMIC_OUTPUT",
"B")
2437 (
"enable or disable output for received dynamic data (data is still broadcasted via Dim)" 2438 "|dynout[bool]:disable or enable output for dynamic data (yes/no)");
2444 (
"disconnect from ethernet");
2448 (
"(Re)connect ethernet connection to FTM, a new address can be given" 2449 "|[host][string]:new ethernet address in the form <host:port>");
2451 fFTM.StartConnect();
2456 fFTM.SetEndpoint(url);
2464 if (!conf.
HasDef(name, sub))
2466 T::Error(
"Neither "+name+
"default nor "+name+sub+
" found.");
2470 const V val = conf.
GetDef<V>(name, sub);
2476 str << name << sub <<
"=" << val <<
" exceeds allowed maximum of " << max <<
"!";
2485 fFTM.SetVerbose(!conf.
Get<
bool>(
"quiet"));
2486 fFTM.SetHexOutput(conf.
Get<
bool>(
"hex-out"));
2487 fFTM.SetDynamicOut(conf.
Get<
bool>(
"dynamic-out"));
2490 const vector<uint16_t>
freq = conf.
Vec<uint16_t>(
"clock-conditioner.frequency");
2492 T::Warn(
"No frequencies for the clock-conditioner defined.");
2494 T::Message(
"Defining clock conditioner frequencies");
2495 for (vector<uint16_t>::const_iterator it=freq.begin();
2496 it!=freq.end(); it++)
2498 if (fClockCondSetup.count(*it)>0)
2500 T::Error(
"clock-conditioner frequency defined twice.");
2504 if (!conf.
HasDef(
"clock-conditioner.R0.", *it) ||
2505 !conf.
HasDef(
"clock-conditioner.R1.", *it) ||
2506 !conf.
HasDef(
"clock-conditioner.R8.", *it) ||
2507 !conf.
HasDef(
"clock-conditioner.R9.", *it) ||
2508 !conf.
HasDef(
"clock-conditioner.R11.", *it) ||
2509 !conf.
HasDef(
"clock-conditioner.R13.", *it) ||
2510 !conf.
HasDef(
"clock-conditioner.R14.", *it) ||
2511 !conf.
HasDef(
"clock-conditioner.R15.", *it))
2513 T::Error(
"clock-conditioner values incomplete.");
2517 array<uint64_t, 8> &arr = fClockCondSetup[*it];
2529 out <<
" -> " << setw(4) << *it <<
"MHz:" << hex << setfill(
'0');
2530 for (
int i=0;
i<8;
i++)
2531 out <<
" " << setw(8) << arr[
i];
2532 T::Message(out.str());
2536 const vector<string> types = conf.
Vec<
string>(
"run-type");
2538 T::Warn(
"No run-types defined.");
2540 T::Message(
"Defining run-types");
2541 for (vector<string>::const_iterator it=types.begin();
2542 it!=types.end(); it++)
2544 T::Message(
" -> "+ *it);
2546 if (fConfigs.count(*it)>0)
2548 T::Error(
"Run-type "+*it+
" defined twice.");
2552 if (!conf.
HasDef(
"sampling-frequency.", *it))
2554 T::Error(
"Neither sampling-frequency."+*it+
" nor sampling-frequency.default found.");
2558 const uint16_t frq = conf.
GetDef<uint16_t>(
"sampling-frequency.", *it);
2561 data.SetClockRegister(fClockCondSetup[frq].
data());
2565 if (!CheckConfigVal<bool> (conf,
true,
"trigger.enable-trigger.", *it) ||
2566 !CheckConfigVal<bool> (conf,
true,
"trigger.enable-external-1.", *it) ||
2567 !CheckConfigVal<bool> (conf,
true,
"trigger.enable-external-2.", *it) ||
2568 !CheckConfigVal<bool> (conf,
true,
"trigger.enable-veto.", *it) ||
2569 !CheckConfigVal<bool> (conf,
true,
"trigger.enable-clock-conditioner.", *it) ||
2570 !CheckConfigVal<bool> (conf,
true,
"light-pulser.external.enable-group1.", *it) ||
2571 !CheckConfigVal<bool> (conf,
true,
"light-pulser.external.enable-group2.", *it) ||
2572 !CheckConfigVal<bool> (conf,
true,
"light-pulser.internal.enable-group1.", *it) ||
2573 !CheckConfigVal<bool> (conf,
true,
"light-pulser.internal.enable-group2.", *it) ||
2574 !CheckConfigVal<uint16_t>(conf, data.kMaxSequence,
"trigger.sequence.pedestal.", *it) ||
2575 !CheckConfigVal<uint16_t>(conf, data.kMaxSequence,
"trigger.sequence.lp-ext.", *it) ||
2576 !CheckConfigVal<uint16_t>(conf, data.kMaxSequence,
"trigger.sequence.lp-int.", *it) ||
2577 !CheckConfigVal<uint16_t>(conf, data.kMaxTriggerInterval,
"trigger.sequence.interval.", *it) ||
2578 !CheckConfigVal<uint16_t>(conf, data.kMaxMultiplicity,
"trigger.multiplicity-physics.", *it) ||
2579 !CheckConfigVal<uint16_t>(conf, data.kMaxMultiplicity,
"trigger.multiplicity-calib.", *it) ||
2580 !CheckConfigVal<uint16_t>(conf, data.kMaxWindow,
"trigger.coincidence-window-physics.", *it) ||
2581 !CheckConfigVal<uint16_t>(conf, data.kMaxWindow,
"trigger.coincidence-window-calib.", *it) ||
2582 !CheckConfigVal<uint16_t>(conf, data.kMaxDeadTime,
"trigger.dead-time.", *it) ||
2583 !CheckConfigVal<uint16_t>(conf, data.kMaxDelayTrigger,
"trigger.delay.", *it) ||
2584 !CheckConfigVal<uint16_t>(conf, data.kMaxDelayTimeMarker,
"trigger.time-marker-delay.", *it) ||
2585 !CheckConfigVal<uint16_t>(conf, 0xffff,
"ftu-report-interval.", *it) ||
2586 !CheckConfigVal<uint16_t>(conf, data.kMaxIntensity,
"light-pulser.external.intensity.", *it) ||
2587 !CheckConfigVal<uint16_t>(conf, data.kMaxIntensity,
"light-pulser.internal.intensity.", *it) ||
2588 !CheckConfigVal<uint16_t>(conf, data.kMaxDAC,
"trigger.threshold.patch.", *it) ||
2589 !CheckConfigVal<uint16_t>(conf, data.kMaxDAC,
"trigger.threshold.logic.", *it) ||
2593 data.Enable(data.kTrigger, conf.
GetDef<
bool>(
"trigger.enable-trigger.", *it));
2594 data.Enable(data.kExt1, conf.
GetDef<
bool>(
"trigger.enable-external-1.", *it));
2595 data.Enable(data.kExt2, conf.
GetDef<
bool>(
"trigger.enable-external-2.", *it));
2596 data.Enable(data.kVeto, conf.
GetDef<
bool>(
"trigger.enable-veto.", *it));
2597 data.Enable(data.kClockConditioner, conf.
GetDef<
bool>(
"trigger.enable-clock-conditioner.", *it));
2599 data.EnableLPint(data.kGroup1, conf.
GetDef<
bool>(
"light-pulser.internal.enable-group1.", *it));
2600 data.EnableLPint(data.kGroup2, conf.
GetDef<
bool>(
"light-pulser.internal.enable-group2.", *it));
2601 data.EnableLPext(data.kGroup1, conf.
GetDef<
bool>(
"light-pulser.external.enable-group1.", *it));
2602 data.EnableLPext(data.kGroup2, conf.
GetDef<
bool>(
"light-pulser.external.enable-group2.", *it));
2605 data.fIntensityLPint = conf.
GetDef<uint16_t>(
"light-pulser.internal.intensity.", *it);
2606 data.fIntensityLPext = conf.
GetDef<uint16_t>(
"light-pulser.external.intensity.", *it);
2607 data.fTriggerInterval = conf.
GetDef<uint16_t>(
"trigger.sequence.interval.", *it);
2608 data.fMultiplicityPhysics = conf.
GetDef<uint16_t>(
"trigger.multiplicity-physics.", *it);
2609 data.fMultiplicityCalib = conf.
GetDef<uint16_t>(
"trigger.multiplicity-calib.", *it);
2610 data.fWindowPhysics = conf.
GetDef<uint16_t>(
"trigger.coincidence-window-physics.", *it);
2611 data.fWindowCalib = conf.
GetDef<uint16_t>(
"trigger.coincidence-window-calib.", *it);
2612 data.fDelayTrigger = conf.
GetDef<uint16_t>(
"trigger.delay.", *it);
2613 data.fDelayTimeMarker = conf.
GetDef<uint16_t>(
"trigger.time-marker-delay.", *it);
2614 data.fDeadTime = conf.
GetDef<uint16_t>(
"trigger.dead-time.", *it);
2616 data.SetPrescaling(conf.
GetDef<uint16_t>(
"ftu-report-interval.", *it));
2618 const uint16_t seqped = conf.
GetDef<uint16_t>(
"trigger.sequence.pedestal.", *it);
2619 const uint16_t seqint = conf.
GetDef<uint16_t>(
"trigger.sequence.lp-int.", *it);
2620 const uint16_t seqext = conf.
GetDef<uint16_t>(
"trigger.sequence.lp-ext.", *it);
2622 data.SetSequence(seqped, seqint, seqext);
2624 data.EnableAllFTU();
2625 data.EnableAllPixel();
2627 const vector<uint16_t> pat1 = conf.
Vec<uint16_t>(
"trigger.disable-patch.default");
2628 const vector<uint16_t> pat2 = conf.
Vec<uint16_t>(
"trigger.disable-patch."+*it);
2630 const vector<uint16_t> pix1 = conf.
Vec<uint16_t>(
"trigger.disable-pixel.default");
2631 const vector<uint16_t> pix2 = conf.
Vec<uint16_t>(
"trigger.disable-pixel."+*it);
2633 const vector<uint16_t> ftu1 = conf.
Vec<uint16_t>(
"disable-ftu.default");
2634 const vector<uint16_t> ftu2 = conf.
Vec<uint16_t>(
"disable-ftu."+*it);
2636 vector<uint16_t> ftu, pat, pix;
2637 ftu.insert(ftu.end(), ftu1.begin(), ftu1.end());
2638 ftu.insert(ftu.end(), ftu2.begin(), ftu2.end());
2639 pat.insert(pat.end(), pat1.begin(), pat1.end());
2640 pat.insert(pat.end(), pat2.begin(), pat2.end());
2641 pix.insert(pix.end(), pix1.begin(), pix1.end());
2642 pix.insert(pix.end(), pix2.begin(), pix2.end());
2644 for (vector<uint16_t>::const_iterator ip=ftu.begin(); ip!=ftu.end(); ip++)
2653 data.DisableFTU(*ip);
2655 for (vector<uint16_t>::const_iterator ip=pat.begin(); ip!=pat.end(); ip++)
2664 data.EnablePatch(*ip,
false);
2666 for (vector<uint16_t>::const_iterator ip=pix.begin(); ip!=pix.end(); ip++)
2675 data.EnablePixel(*ip,
false);
2678 const uint16_t th0 = conf.
GetDef<uint16_t>(
"trigger.threshold.patch.", *it);
2679 const uint16_t th1 = conf.
GetDef<uint16_t>(
"trigger.threshold.logic.", *it);
2681 for (
int i=0;
i<40;
i++)
2683 data[
i].fDAC[0] = th0;
2684 data[
i].fDAC[1] = th0;
2685 data[
i].fDAC[2] = th0;
2686 data[
i].fDAC[3] = th0;
2687 data[
i].fDAC[4] = th1;
2690 fConfigs[*it] =
data;
2713 SetEndpoint(conf.
Get<
string>(
"addr"));
2723 template<
class T,
class S,
class R>
2726 return Main::execute<T, StateMachineFTM<S, R>>(conf);
2731 po::options_description control(
"Control options");
2732 control.add_options()
2733 (
"no-dim",
po_bool(),
"Disable dim services")
2734 (
"addr,a", var<string>(
"localhost:5000"),
"Network address of FTM")
2735 (
"quiet,q",
po_bool(
true),
"Disable printing contents of all received messages (except dynamic data) in clear text.")
2736 (
"hex-out",
po_bool(),
"Enable printing contents of all printed messages also as hex data.")
2737 (
"dynamic-out",
po_bool(),
"Enable printing received dynamic data.")
2741 po::options_description
freq(
"Sampling frequency setup");
2743 (
"clock-conditioner.frequency", vars<uint16_t>(),
"Frequencies for which to setup the clock-conditioner (replace the * in the following options by this definition)")
2744 (
"clock-conditioner.R0.*", var<Hex<uint32_t>>(),
"Clock-conditioner R0")
2745 (
"clock-conditioner.R1.*", var<Hex<uint32_t>>(),
"Clock-conditioner R1")
2746 (
"clock-conditioner.R8.*", var<Hex<uint32_t>>(),
"Clock-conditioner R8")
2747 (
"clock-conditioner.R9.*", var<Hex<uint32_t>>(),
"Clock-conditioner R9")
2748 (
"clock-conditioner.R11.*", var<Hex<uint32_t>>(),
"Clock-conditioner R11")
2749 (
"clock-conditioner.R13.*", var<Hex<uint32_t>>(),
"Clock-conditioner R13")
2750 (
"clock-conditioner.R14.*", var<Hex<uint32_t>>(),
"Clock-conditioner R14")
2751 (
"clock-conditioner.R15.*", var<Hex<uint32_t>>(),
"Clock-conditioner R15");
2753 po::options_description runtype(
"Run type configuration");
2754 runtype.add_options()
2755 (
"run-type", vars<string>(),
"Name of run-types (replace the * in the following configuration by the case-sensitive names defined here)")
2756 (
"sampling-frequency.*", var<uint16_t>(),
"Sampling frequency as defined in the clock-conditioner.frequency")
2757 (
"trigger.enable-trigger.*", var<bool>(),
"Enable trigger output of physics trigger")
2758 (
"trigger.enable-external-1.*", var<bool>(),
"Enable external trigger line 1")
2759 (
"trigger.enable-external-2.*", var<bool>(),
"Enable external trigger line 2")
2760 (
"trigger.enable-veto.*", var<bool>(),
"Enable veto line")
2761 (
"trigger.enable-clock-conditioner.*", var<bool>(),
"")
2762 (
"trigger.sequence.interval.*", var<uint16_t>(),
"Interval between two artifical triggers in units of ms")
2763 (
"trigger.sequence.pedestal.*", var<uint16_t>(),
"Number of pedestal events in the sequence of artificial triggers")
2764 (
"trigger.sequence.lp-int.*", var<uint16_t>(),
"Number of LPint events in the sequence of artificial triggers")
2765 (
"trigger.sequence.lp-ext.*", var<uint16_t>(),
"Number of LPext events in the sequence of artificial triggers")
2766 (
"trigger.multiplicity-physics.*", var<uint16_t>(),
"Multiplicity for physics events (n out of 40)")
2767 (
"trigger.multiplicity-calib.*", var<uint16_t>(),
"Multiplicity for LPext events (n out of 40)")
2768 (
"trigger.coincidence-window-physics.*", var<uint16_t>(),
"Coincidence window for physics triggers in units of n*4ns+8ns")
2769 (
"trigger.coincidence-window-calib.*", var<uint16_t>(),
"Coincidence window for LPext triggers in units of n*4ns+8ns")
2770 (
"trigger.dead-time.*", var<uint16_t>(),
"Dead time after trigger in units of n*4ns+8ns")
2771 (
"trigger.delay.*", var<uint16_t>(),
"Delay of the trigger send to the FAD boards after a trigger in units of n*4ns+8ns")
2772 (
"trigger.time-marker-delay.*", var<uint16_t>(),
"Delay of the time-marker after a trigger in units of n*4ns+8ns")
2773 (
"trigger.disable-pixel.*", vars<uint16_t>(),
"")
2774 (
"trigger.disable-patch.*", vars<uint16_t>(),
"")
2775 (
"trigger.threshold.patch.*", var<uint16_t>(),
"")
2776 (
"trigger.threshold.logic.*", var<uint16_t>(),
"")
2777 (
"ftu-report-interval.*", var<uint16_t>(),
"")
2778 (
"disable-ftu.*", vars<uint16_t>(),
"")
2779 (
"light-pulser.external.enable-group1.*", var<bool>(),
"Enable LED group 1 of external light pulser")
2780 (
"light-pulser.external.enable-group2.*", var<bool>(),
"Enable LED group 2 of external light pulser")
2781 (
"light-pulser.internal.enable-group1.*", var<bool>(),
"Enable LED group 1 of internal light pulser")
2782 (
"light-pulser.internal.enable-group2.*", var<bool>(),
"Enable LED group 2 of internal light pulser")
2783 (
"light-pulser.external.intensity.*", var<uint16_t>(),
"Intensity of external light pulser")
2784 (
"light-pulser.internal.intensity.*", var<uint16_t>(),
"Intensity of internal light pulser")
2804 "The ftmctrl controls the FTM (FACT Trigger Master) board.\n" 2806 "The default is that the program is started without user intercation. " 2807 "All actions are supposed to arrive as DimCommands. Using the -c " 2808 "option, a local shell can be initialized. With h or help a short " 2809 "help message about the usuage can be brought to the screen.\n" 2811 "Usage: ftmctrl [-c type] [OPTIONS]\n" 2812 " or: ftmctrl [OPTIONS]\n";
2818 Main::PrintHelp<StateMachineFTM<StateMachine, ConnectionFTM>>();
2838 int main(
int argc,
const char* argv[])
2851 if (!conf.
Has(
"console"))
2853 if (conf.
Get<
bool>(
"no-dim"))
2854 return RunShell<LocalStream, StateMachine, ConnectionFTM>(conf);
2856 return RunShell<LocalStream, StateMachineDim, ConnectionDimFTM>(conf);
2859 if (conf.
Get<
bool>(
"no-dim"))
2861 if (conf.
Get<
int>(
"console")==0)
2862 return RunShell<LocalShell, StateMachine, ConnectionFTM>(conf);
2864 return RunShell<LocalConsole, StateMachine, ConnectionFTM>(conf);
2868 if (conf.
Get<
int>(
"console")==0)
2869 return RunShell<LocalShell, StateMachineDim, ConnectionDimFTM>(conf);
2871 return RunShell<LocalConsole, StateMachineDim, ConnectionDimFTM>(conf);
DimDescribedService fDimPassport
int SetClockRegister(const EventImp &evt)
uint8_t GetSequencePed() const
bool CmdDisableReports(bool b)
bool ToggleFTU(uint32_t board)
Enable the trigger output.
int LoadStaticData(const EventImp &evt)
vector< uint16_t > fBuffer
Reboot (no power cycle) all FTUs and FADs of one crate.
int DisableAllPatchesExcept(const EventImp &evt)
int SetHexOutput(const EventImp &evt)
void SetHexOutput(bool b)
bool SetTriggerDelay(uint32_t val)
int SetIntensity(const EventImp &evt, FTM::StaticData::GeneralSettings lp)
FTM::DynamicData fDynamicData
uint16_t * EnablePixel(int idx, bool enable)
int DisableReports(const EventImp &evt)
function< int(const EventImp &)> Wrapper(function< void()> func)
int SetNoutof4(const EventImp &evt)
uint16_t fWindowCalib
(4ns * x + 8ns) At least N (multiplicity) rising edges (trigger signal) within this window ...
int SetVerbosity(const EventImp &evt)
std::vector< uint16_t > HtoN() const
A general base-class describing events issues in a state machine.
const char * GetText() const
bool CheckEventSize(size_t has, const char *name, size_t size)
uint8_t GetSequenceLPint() const
uint16_t fTriggerInterval
only 8 bit used
int SetClockFrequency(const EventImp &evt)
int EnableFTU(const EventImp &evt)
int SetDynamicOut(const EventImp &evt)
External trigger signal 2.
bool SetAllThresholds(const int32_t *th)
bool SetTriggerInterval(uint32_t val)
int GetRegister(const EventImp &evt)
map< string, FTM::StaticData > Configs
int SetDeadTime(const EventImp &evt)
void SetupConfiguration(Configuration &conf)
int EnableLP(const EventImp &evt, FTM::StaticData::GeneralSettings lp, FTM::StaticData::LightPulserEnable group)
void PostCmd(vector< uint16_t > dat, uint16_t u1=0, uint16_t u2=0, uint16_t u3=0, uint16_t u4=0)
bool SetTimeMarkerDelay(uint32_t val)
void setQuality(int quality)
DimDescribedService fDimTriggerRates
The base implementation of a distributed messaging system.
uint16_t fMultiplicityPhysics
void SetPrintUsage(const std::function< void(void)> &func)
T Get(const std::string &var)
FTM::StaticData fBufStaticData
DimDescribedService fDimDynamicData
int SetSelectedThresholds(const EventImp &evt)
void CmdTakeNevents(uint32_t n)
...fixed number of events
void EnableLPint(LightPulserEnable group, bool enable)
ConnectionFTM(ba::io_service &ioservice, MessageImp &imp)
void SetEndpoint(const string &url)
Types
Types sent in the header of the following data.
bool TogglePixel(uint16_t idx)
bool SetSelectedThresholds(const int32_t *th)
bool SetIntensity(FTM::StaticData::GeneralSettings lp, uint16_t intensity)
Select clock conditioner frequency (1) / time marker (0) as output.
int SetTriggerSeq(const EventImp &evt)
Static (configuration) data.
std::vector< T > Vec(const std::string &var)
uint16_t fDeadTime
(4ns * x + 8ns) FTM internal programmable delay between trigger descision and time marker output ...
std::string GetString() const
int EnablePatch(const EventImp &evt, bool enable)
int64_t first
Size of this column in the tile.
void PostCmd(uint16_t u1=0, uint16_t u2=0, uint16_t u3=0, uint16_t u4=0)
Configs::const_iterator fTargetConfig
void PostCmd(array< uint16_t, N > dat, uint16_t u1=0, uint16_t u2=0, uint16_t u3=0, uint16_t u4=0)
FTM and FTUs are being reconfigured.
int SetCalibWindow(const EventImp &evt)
bool SetNoutof4(int32_t patch, int32_t value)
bool SetCalibMultiplicity(uint16_t n)
bool CmdResetCrate(uint16_t addr)
bool CheckConsistency(FTM::StaticData &data)
int SaveStaticData(const EventImp &evt)
bool DisableAllPatchesExcept(int16_t idx)
Specifies that dynamic data is read/written.
int SetCalibMultiplicity(const EventImp &evt)
void SetSequence(uint8_t ped, uint8_t lpint, uint8_t lpext)
void SetupConfiguration(Configuration &conf)
virtual void UpdateFirstHeader()
int SetTriggerInterval(const EventImp &evt)
Specifies that a register is read/written.
StateMachineFTM(ostream &out=cout)
uint16_t GetUShort() const
virtual void UpdateCounter()
int Enable(const EventImp &evt, FTM::StaticData::GeneralSettings type)
void SetPrescaling(uint16_t val)
int SetRegister(const EventImp &evt)
Specifies that static (configuration) data is read/written.
virtual void UpdateFtuList()
bool SetPrescaling(uint32_t value)
Minimum required trigger multiplicity.
FTM::StaticData fStaticData
External trigger signal 1.
bool Has(const std::string &var)
T GetDef(const std::string &var, const S &val)
int Reconnect(const EventImp &evt)
bool SaveStaticData(string name) const
int DisableAllPixelsExcept(const EventImp &evt)
bool EnableLP(FTM::StaticData::GeneralSettings lp, FTM::StaticData::LightPulserEnable group, bool enable)
uint8_t fIntensityLPint
Enable for LED group 1/2 (LightPulserEnable)
void ConnectionEstablished()
uint8_t GetSequenceLPext() const
void CmdStartRun(bool log=true)
void EnableLPext(LightPulserEnable group, bool enable)
void AddOptions(const po::options_description &opt, bool visible=true)
bool CmdGetRegister(uint16_t addr)
int SetTimeMarkerDelay(const EventImp &evt)
const FTM::StaticData & GetStaticData() const
int SetTriggerMultiplicity(const EventImp &evt)
First user defined mode (to be used in derived classes' enums)
bool EnablePixel(int16_t idx, bool enable)
bool SetTriggerWindow(uint16_t win)
void HandleReceivedData(const bs::error_code &err, size_t bytes_received, int)
bool Enabled(uint16_t idx) const
DimDescribedService fDimError
int SetPrescaling(const EventImp &evt)
Disable the trigger output.
bool DisableAllPixelsExcept(uint16_t idx)
DimDescribedService fDimCounter
Enable trigger decision after light pulse (CalibrationTrigger, LP1)
int SetAllThresholds(const EventImp &evt)
int Wrap(function< void()> f)
Commandline parsing, resource file parsing and database access.
Disable transmission of rate-reports (dynamic data)
Enable artificial trigger after light pulse (LP2)
virtual void UpdateError()
int TogglePixel(const EventImp &evt)
Pedestal trigger (artifical)
bool LoadStaticData(string name)
map< uint16_t, uint32_t > fCounter
Local extension to identify a header in fCounter.
int EvalOptions(Configuration &conf)
FTU list (answer of ping)
bool SetTriggerSeq(const uint16_t d[3])
void HandleReadTimeout(const bs::error_code &error)
Start delimiter send before each header.
void Enable(FTM::StaticData::GeneralSettings type, bool enable)
void Enable(GeneralSettings type, bool enable)
uint32_t GetCounter(FTM::Types type)
uint16_t fWindowPhysics
R0, R1, R8, R9, R11, R13, R14, R15.
int ResetCrate(const EventImp &evt)
bool EnableFTU(int32_t board, bool enable)
uint16_t fMultiplicityCalib
Required trigger multiplicity for physcis triggers (0-40)
int ToggleFTU(const EventImp &evt)
bool EnablePatch(int16_t idx, bool enable)
virtual void HandleReadTimeout(const boost::system::error_code &)
DimDescribedService fDimStaticData
bool IsEnabled(GeneralSettings type) const
A requested register value.
int ConfigureFTM(const EventImp &evt)
virtual void UpdateHeader()
Veto trigger decision / artifical triggers.
bool SetDeadTime(uint32_t val)
virtual void UpdateStaticData()
(4ns * x + 8ns) At least N (multiplicity) rising edges (trigger signal) within this window ...
int RunShell(Configuration &conf)
int TakeNevents(const EventImp &evt)
Trigger output disabled, configuration possible.
uint16_t fDelayTimeMarker
(4ns * x + 8ns) FTM internal programmable delay between trigger decision and output ...
int main(int argc, const char *argv[])
int SetTriggerWindow(const EventImp &evt)
po::typed_value< bool > * po_bool(bool def=false)
End delimiter send after each data block.
Configure single FTU board.
void SetClockRegister(const uint64_t reg[])
uint16_t fDelayTrigger
Required trigger multiplicity calibration (LPext) triggers (0-40)
void CmdSendStatDat(const FTM::StaticData &data)
bool SetClockRegister(const uint64_t reg[])
void SetDynamicOut(bool b)
int SetTriggerDelay(const EventImp &evt)
T Get(size_t offset=0) const
virtual void UpdateDynamicData()
uint8_t fIntensityLPext
Ratio between trigger types send as artificial trigger (in this order) 3x5bit.
bool HasDef(const std::string &var, const T &val)
bool DoParse(int argc, const char **argv, const std::function< void()> &func=std::function< void()>())
bool SetCalibWindow(uint16_t win)
bool CheckConfigVal(Configuration &conf, V max, const string &name, const string &sub)
bool SetThreshold(int32_t patch, int32_t value)
Ping all FTUs (get FTU list)
Physics trigger decision (PhysicTrigger)
Trigger output enabled, configuration ignored.
bool SetTriggerMultiplicity(uint16_t n)
map< uint16_t, array< uint64_t, 8 > > fClockCondSetup
bool SetVal(uint16_t *dest, uint32_t val, uint32_t max)
const T * Ptr(size_t offset=0) const
ConnectionDimFTM(ba::io_service &ioservice, MessageImp &imp)
DimDescribedService fDimFtuList
bool CmdSetRegister(uint16_t addr, uint16_t val)
int SetThreshold(const EventImp &evt)
int EnablePixel(const EventImp &evt, bool b)
Error list (error when FTU communication failed)
virtual size_t GetSize() const