Skip to content

Commit ff0c600

Browse files
first cleanup pass, re-organizing (#359)
* use std::shared_ptr instead of refs, rename files, collect common init blocks * more tidying, isolate fiberless stuff, share read_event * share sw emulation headers across all opto-link readout code in hardware limits on number of ROCs and ECONs * document parameters to init * ability to disable ROCs on an EcalSMM * Apply clang-format --style=Google --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent aa4217f commit ff0c600

23 files changed

Lines changed: 829 additions & 950 deletions

CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,25 +114,25 @@ set(pflib_src
114114
src/pflib/GPIO.cxx
115115
src/pflib/Elinks.cxx
116116
src/pflib/Parameters.cxx
117+
src/pflib/DAQ.cxx
117118
src/pflib/lpGBT.cxx
118119
src/pflib/lpgbt/lpGBT_ConfigTransport_I2C.cxx
119120
src/pflib/lpgbt/lpGBT_Registers.cxx
120121
src/pflib/lpgbt/lpGBT_Utility.cxx
121122
src/pflib/lpgbt/lpGBT_standard_configs.cxx
122123
src/pflib/lpgbt/I2C.cxx
123124
src/pflib/lpgbt/GPIO.cxx
124-
src/pflib/TargetFiberless.cxx
125125
src/pflib/GPIO_HcalHGCROCZCU.cxx
126126
src/pflib/FastControlCMS_MMap.cxx
127127
src/pflib/ECOND_Formatter.cxx
128128
src/pflib/zcu/UIO.cxx
129-
src/pflib/zcu/Elinks_zcu.cxx
130129
src/pflib/zcu/lpGBT_ICEC_ZCU_Simple.cxx
131130
src/pflib/zcu/zcu_elinks.cxx
132-
src/pflib/zcu/zcu_DAQ.cxx
131+
src/pflib/zcu/zcu_daq.cxx
133132
src/pflib/zcu/zcu_optolink.cxx
134-
src/pflib/zcu/HcalBackplaneZCU.cxx
135-
src/pflib/zcu/EcalSMMTarget.cxx
133+
src/pflib/zcu/HcalBackplane.cxx
134+
src/pflib/zcu/EcalSMM.cxx
135+
src/pflib/zcu/HGCROCBoardFiberless.cxx
136136
src/pflib/Ecal.cxx
137137
src/pflib/Bias.cxx
138138
)
@@ -144,8 +144,8 @@ if (${Rogue_FOUND})
144144
src/pflib/bittware/bittware_elinks.cxx
145145
src/pflib/bittware/bittware_daq.cxx
146146
src/pflib/bittware/bittware_FastControl.cxx
147-
src/pflib/bittware/HcalBackplaneBittware.cxx
148-
src/pflib/bittware/EcalSMMTarget.cxx
147+
src/pflib/bittware/HcalBackplane.cxx
148+
src/pflib/bittware/EcalSMM.cxx
149149
)
150150
endif()
151151

app/tool/main.cxx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,15 @@ int main(int argc, char* argv[]) {
352352
if (ilink < 0 or ilink > 1) {
353353
PFEXCEPTION_RAISE("BadLink", "ZCU EcalSMM ilink can only be 0 or 1");
354354
}
355-
tgt.reset(pflib::makeTargetEcalSMMZCU(ilink));
355+
auto rocmask = target.get<int>("rocmask", 0x3f);
356+
tgt.reset(pflib::makeTargetEcalSMMZCU(ilink, rocmask));
356357
readout_cfg = pftool::State::CFG_ECALOPTO_ZCU;
357358
pftool::root()->hide(ONLY_FIBERLESS | ONLY_HCAL);
358359
} else if (target_type == "HcalBackplaneBittware") {
359360
#ifdef USE_ROGUE
360361
// need ilink to be in configuration
361362
auto ilink = target.get<int>("ilink");
362-
auto boardmask = target.get<int>("boardmask", 0xff);
363+
auto boardmask = target.get<int>("boardmask", 0xf);
363364
auto dev = target.get<std::string>("dev", "/dev/datadev_0");
364365
tgt.reset(pflib::makeTargetHcalBackplaneBittware(ilink, boardmask,
365366
dev.c_str()));
@@ -374,7 +375,8 @@ int main(int argc, char* argv[]) {
374375
// need ilink to be in configuration
375376
auto ilink = target.get<int>("ilink");
376377
auto dev = target.get<std::string>("dev", "/dev/datadev_0");
377-
tgt.reset(pflib::makeTargetEcalSMMBittware(ilink, dev.c_str()));
378+
auto rocmask = target.get<int>("rocmask", 0x3f);
379+
tgt.reset(pflib::makeTargetEcalSMMBittware(ilink, rocmask, dev.c_str()));
378380
readout_cfg = pftool::State::CFG_ECALOPTO_BW;
379381
pftool::root()->hide(ONLY_FIBERLESS | ONLY_HCAL);
380382
#else

include/pflib/DAQ.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,20 @@ class DAQ {
6161
/// Advance link read pointer
6262
virtual void advanceLinkReadPtr() {}
6363

64-
// get any useful debugging data
64+
/// get any useful debugging data
6565
virtual std::map<std::string, uint32_t> get_debug(uint32_t ask) {
6666
return std::map<std::string, uint32_t>();
6767
}
6868

69+
/**
70+
* readout an event including emulation of the headers the firmware inserts
71+
*
72+
* The Bittware firmware includes headers when copying the data into the axi
73+
* stream and we include those here so that the non-axis readout can have
74+
* data that is in the same format as axis data.
75+
*/
76+
std::vector<uint32_t> read_event_sw_headers();
77+
6978
private:
7079
/// number of links
7180
int n_links;
@@ -75,8 +84,6 @@ class DAQ {
7584
int samples_, soi_;
7685
};
7786

78-
DAQ* get_DAQ_zcu();
79-
8087
} // namespace pflib
8188

8289
#endif // PFLIB_DAQ_H_INCLUDED

include/pflib/ECON.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ namespace pflib {
1717
*/
1818
class ECON {
1919
public:
20-
ECON(I2C& i2c, uint8_t econ_base_addr, const std::string& type_version);
20+
ECON(std::shared_ptr<I2C> i2c, uint8_t econ_base_addr,
21+
const std::string& type_version);
2122

2223
const std::string& type() const { return type_; }
2324
void setRunMode(bool active = true, int edgesel = -1, int fcmd_invert = -1);
@@ -77,7 +78,7 @@ class ECON {
7778
TestParameters::Builder testParameters();
7879

7980
private:
80-
I2C& i2c_;
81+
std::shared_ptr<I2C> i2c_;
8182
uint8_t econ_base_;
8283
Compiler compiler_;
8384
std::string type_;
@@ -87,4 +88,4 @@ class ECON {
8788

8889
} // namespace pflib
8990

90-
#endif // PFLIB_ECON_H_INCLUDED
91+
#endif // PFLIB_ECON_H_INCLUDED

include/pflib/Ecal.h

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22

3-
#include <map>
43
#include <memory>
54
#include <vector>
65

@@ -18,21 +17,31 @@ namespace pflib {
1817
*/
1918
class EcalModule {
2019
public:
21-
EcalModule(lpGBT& lpgbt, int i2cbus, int modulenumber);
20+
/**
21+
* Construct access to an EcalModule given the DAQ lpGBT
22+
* it talks through
23+
*
24+
* @param[in] lpgbt accessor to the lpgbt
25+
* @param[in] i2cbus bus on which the EcalModule is
26+
* @param[in] modulenumber module ID number
27+
* @param[in] roc_mask bit-mask saying if a board is activate/enabled (1)
28+
* or inactive/disabled (0) - position i represents ROC i
29+
*/
30+
EcalModule(lpGBT& lpgbt, int i2cbus, int modulenumber, uint8_t roc_mask);
2231

2332
/** number of hgcrocs */
24-
int nrocs() const { return 6; }
25-
/// number of econds
26-
int necons() const { return 2; }
33+
int nrocs() const;
34+
/// number of econs
35+
int necons() const;
2736

2837
/** do we have a roc with this id? */
29-
bool have_roc(int iroc) const { return iroc >= 0 && iroc <= nrocs(); }
38+
bool have_roc(int iroc) const;
3039

3140
static constexpr const int ECON_D = 0;
3241
static constexpr const int ECON_T = 1;
3342

3443
/** do we have an econ with this id? */
35-
bool have_econ(int iecon) const { return iecon == ECON_D || iecon == ECON_T; }
44+
bool have_econ(int iecon) const;
3645

3746
/** get a list of the IDs we have set up */
3847
std::vector<int> roc_ids() const;
@@ -65,12 +74,18 @@ class EcalModule {
6574
lpGBT& lpGBT_;
6675
int i2cbus_;
6776
int imodule_;
68-
std::unique_ptr<I2C> i2c_;
69-
/// representation of Ecal HexaModule
70-
std::vector<ROC> rocs_;
71-
std::vector<ECON> econs_;
72-
// Mapping ROC channel → ERX channel
77+
std::shared_ptr<I2C> i2c_;
78+
/// number of ROCs that are enabled
79+
int n_rocs_;
80+
/// up to 6 ROCs some of which could be disabled
81+
std::array<std::unique_ptr<ROC>, 6> rocs_;
82+
/// number of ECONs that are enabled
83+
int n_econs_;
84+
/// two ECONs
85+
std::array<std::unique_ptr<ECON>, 2> econs_;
86+
7387
private:
88+
/// mapping of ROC halves to ECON-D eRx channels
7489
static const std::vector<std::pair<int, int>> roc_to_erx_map_;
7590
};
7691

@@ -83,7 +98,7 @@ class EcalMotherboard {
8398
EcalModule& module(int imodule);
8499

85100
private:
86-
std::vector<std::shared_ptr<EcalModule*>> modules_;
101+
std::vector<std::shared_ptr<EcalModule>> modules_;
87102
};
88103

89104
} // namespace pflib

include/pflib/HcalBackplane.h

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,22 @@ namespace pflib {
1414
*/
1515
class HcalBackplane : public Target {
1616
public:
17+
/// virtual destructor since we'll be holding this as a Target
1718
virtual ~HcalBackplane() = default;
19+
1820
HcalBackplane();
1921

22+
/**
23+
* Common initialization for slow control given lpGBT
24+
* objects and a mask for which HGCROC boards are connected
25+
*
26+
* @param[in] daq_lpgbt accessor to DAQ lpGBT
27+
* @param[in] trig_lpgbt accessor to TRIG lpGBT
28+
* @param[in] hgcroc_boards bit-mask saying if a board is active/enabled (1)
29+
* or inactive/disabled (0) - the bit in position i represents board i
30+
*/
31+
void init(lpGBT& daq_lpgbt, lpGBT& trig_lpgbt, int hgcroc_boards);
32+
2033
/** number of boards */
2134
virtual int nrocs() override { return nhgcroc_; }
2235

@@ -57,16 +70,6 @@ class HcalBackplane : public Target {
5770
const std::vector<std::pair<int, int>>& getRocErxMapping() override;
5871

5972
protected:
60-
/** Add a ROC to the set of ROCs */
61-
void add_roc(int iroc, uint8_t roc_baseaddr,
62-
const std::string& roc_type_version,
63-
std::shared_ptr<I2C> roc_i2c, std::shared_ptr<I2C> bias_i2c,
64-
std::shared_ptr<I2C> board_i2c);
65-
66-
/** Add a ECON to the set of ECONs */
67-
void add_econ(int iecon, uint8_t econ_baseaddr, const std::string& econ_type,
68-
std::shared_ptr<I2C> econ_i2c);
69-
7073
/** Number of HGCROC boards in this system */
7174
int nhgcroc_;
7275

@@ -76,22 +79,21 @@ class HcalBackplane : public Target {
7679
/** The GPIO interface */
7780
std::unique_ptr<GPIO> gpio_;
7881

79-
/** The I2C interfaces and objects for a HGCROC board */
80-
struct ROCConnection {
81-
pflib::ROC roc_;
82-
std::shared_ptr<I2C> roc_i2c_;
83-
pflib::Bias bias_;
84-
std::shared_ptr<I2C> bias_i2c_;
85-
std::shared_ptr<I2C> board_i2c_;
82+
/**
83+
* an HGCROC board contains one ROC, one Bias board
84+
* and some other utilities that are accessible
85+
* via the Bias C++ object
86+
*/
87+
struct HGCROCBoard {
88+
ROC roc;
89+
Bias bias;
8690
};
87-
std::map<int, ROCConnection> roc_connections_;
8891

89-
/** The I2C interface and object for a ECON board */
90-
struct ECONConnection {
91-
pflib::ECON econ_;
92-
std::shared_ptr<I2C> i2c_;
93-
};
94-
std::map<int, ECONConnection> econ_connections_;
92+
/// the backplane can hold up to 4 HGCROC boards
93+
std::array<std::unique_ptr<HGCROCBoard>, 4> rocs_;
94+
95+
/// the ECONs on the ECON Mezzanine on this backplane
96+
std::array<std::unique_ptr<ECON>, 3> econs_;
9597
};
9698

9799
} // namespace pflib

include/pflib/ROC.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class ROC {
1919
static const int N_REGISTERS_PER_PAGE = 32;
2020

2121
public:
22-
ROC(I2C& i2c, uint8_t roc_base_addr, const std::string& type_version);
22+
ROC(std::shared_ptr<I2C> i2c, uint8_t roc_base_addr,
23+
const std::string& type_version);
2324

2425
void setRunMode(bool active = true);
2526
bool isRunMode();
@@ -182,7 +183,7 @@ class ROC {
182183
TestParameters::Builder testParameters();
183184

184185
private:
185-
I2C& i2c_;
186+
std::shared_ptr<I2C> i2c_;
186187
uint8_t roc_base_;
187188
std::string type_version_;
188189
Compiler compiler_;

include/pflib/Target.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ Target* makeTargetFiberless();
123123
Target* makeTargetHcalBackplaneZCU(int ilink, uint8_t board_mask);
124124
Target* makeTargetHcalBackplaneBittware(int ilink, uint8_t board_mask,
125125
const char* dev);
126-
Target* makeTargetEcalSMMZCU(int ilink);
127-
Target* makeTargetEcalSMMBittware(int ilink, const char* dev);
126+
Target* makeTargetEcalSMMZCU(int ilink, uint8_t roc_mask);
127+
Target* makeTargetEcalSMMBittware(int ilink, uint8_t rocmask, const char* dev);
128128

129129
} // namespace pflib
130130

include/pflib/zcu/zcu_daq.h

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,32 @@
44
namespace pflib {
55
namespace zcu {
66

7+
/**
8+
* Data capture on ZCU when connected with an optical fiber
9+
*/
710
class ZCU_Capture : public DAQ {
811
public:
12+
virtual ~ZCU_Capture() = default;
913
ZCU_Capture();
10-
virtual void reset();
11-
virtual int getEventOccupancy();
12-
virtual void setupLink(int ilink, int l1a_delay, int l1a_capture_width) {
14+
virtual void reset() final;
15+
virtual int getEventOccupancy() final;
16+
virtual void setupLink(int ilink, int l1a_delay,
17+
int l1a_capture_width) final {
1318
// none of these parameters are relevant for the econd capture, which is
1419
// data-pattern based
1520
}
16-
virtual void getLinkSetup(int ilink, int& l1a_delay, int& l1a_capture_width) {
21+
virtual void getLinkSetup(int ilink, int& l1a_delay,
22+
int& l1a_capture_width) final {
1723
l1a_delay = -1;
1824
l1a_capture_width = -1;
1925
}
20-
virtual void bufferStatus(int ilink, bool& empty, bool& full);
21-
virtual void setup(int econid, int samples_per_ror, int soi);
22-
virtual void enable(bool doenable);
23-
virtual bool enabled();
24-
virtual std::vector<uint32_t> getLinkData(int ilink);
25-
virtual void advanceLinkReadPtr();
26-
virtual std::map<std::string, uint32_t> get_debug(uint32_t ask);
26+
virtual void bufferStatus(int ilink, bool& empty, bool& full) final;
27+
virtual void setup(int econid, int samples_per_ror, int soi) final;
28+
virtual void enable(bool doenable) final;
29+
virtual bool enabled() final;
30+
virtual std::vector<uint32_t> getLinkData(int ilink) final;
31+
virtual void advanceLinkReadPtr() final;
32+
virtual std::map<std::string, uint32_t> get_debug(uint32_t ask) final;
2733

2834
private:
2935
UIO capture_;

0 commit comments

Comments
 (0)