LDMX Software
Public Member Functions | Private Attributes | List of all members
ecal::EcalRawEncoder Class Reference

Public Member Functions

 EcalRawEncoder (const std::string &name, framework::Process &process)
 Constructor.
 
virtual ~EcalRawEncoder ()
 Destructor.
 
virtual void configure (framework::config::Parameters &)
 Callback for the EventProcessor to configure itself from the given set of parameters.
 
virtual void produce (framework::Event &event)
 Process the event and put new data products into it.
 
- Public Member Functions inherited from framework::Producer
 Producer (const std::string &name, Process &process)
 Class constructor.
 
virtual void beforeNewRun (ldmx::RunHeader &header)
 Handle allowing producers to modify run headers before the run begins.
 
- Public Member Functions inherited from framework::EventProcessor
 EventProcessor (const std::string &name, Process &process)
 Class constructor.
 
virtual ~EventProcessor ()
 Class destructor.
 
virtual void onNewRun (const ldmx::RunHeader &runHeader)
 Callback for the EventProcessor to take any necessary action when the run being processed changes.
 
virtual void onFileOpen (EventFile &eventFile)
 Callback for the EventProcessor to take any necessary action when a new event input ROOT file is opened.
 
virtual void onFileClose (EventFile &eventFile)
 Callback for the EventProcessor to take any necessary action when a event input ROOT file is closed.
 
virtual void onProcessStart ()
 Callback for the EventProcessor to take any necessary action when the processing of events starts, such as creating histograms.
 
virtual void onProcessEnd ()
 Callback for the EventProcessor to take any necessary action when the processing of events finishes, such as calculating job-summary quantities.
 
template<class T >
const T & getCondition (const std::string &condition_name)
 Access a conditions object for the current event.
 
TDirectory * getHistoDirectory ()
 Access/create a directory in the histogram file for this event processor to create histograms and analysis tuples.
 
void setStorageHint (framework::StorageControl::Hint hint)
 Mark the current event as having the given storage control hint from this module.
 
void setStorageHint (framework::StorageControl::Hint hint, const std::string &purposeString)
 Mark the current event as having the given storage control hint from this module and the given purpose string.
 
int getLogFrequency () const
 Get the current logging frequency from the process.
 
int getRunNumber () const
 Get the run number from the process.
 
std::string getName () const
 Get the processor name.
 
void createHistograms (const std::vector< framework::config::Parameters > &histos)
 Internal function which is used to create histograms passed from the python configuration @parma histos vector of Parameters that configure histograms to create.
 

Private Attributes

std::string input_name_
 input object of encoded data
 
std::string input_pass_
 input pass of creating encoded data
 
std::string output_name_
 output object to put onto event bus
 
int roc_version_
 version of HGC ROC we are decoding
 

Additional Inherited Members

- Static Public Member Functions inherited from framework::EventProcessor
static void declare (const std::string &classname, int classtype, EventProcessorMaker *)
 Internal function which is part of the PluginFactory machinery.
 
- Static Public Attributes inherited from framework::Producer
static const int CLASSTYPE {1}
 Constant used to track EventProcessor types by the PluginFactory.
 
- Protected Member Functions inherited from framework::EventProcessor
void abortEvent ()
 Abort the event immediately.
 
- Protected Attributes inherited from framework::EventProcessor
HistogramHelper histograms_
 Interface class for making and filling histograms.
 
NtupleManagerntuple_ {NtupleManager::getInstance()}
 Manager for any ntuples.
 
logging::logger theLog_
 The logger for this EventProcessor.
 

Detailed Description

Definition at line 14 of file EcalRawEncoder.h.

Constructor & Destructor Documentation

◆ EcalRawEncoder()

ecal::EcalRawEncoder::EcalRawEncoder ( const std::string &  name,
framework::Process process 
)

Constructor.

Definition at line 15 of file EcalRawEncoder.cxx.

17 : Producer(name, process) {}
Producer(const std::string &name, Process &process)
Class constructor.

◆ ~EcalRawEncoder()

ecal::EcalRawEncoder::~EcalRawEncoder ( )
virtual

Destructor.

Definition at line 19 of file EcalRawEncoder.cxx.

19{}

Member Function Documentation

◆ configure()

void ecal::EcalRawEncoder::configure ( framework::config::Parameters parameters)
virtual

Callback for the EventProcessor to configure itself from the given set of parameters.

The parameters a processor has access to are the member variables of the python class in the sequence that has className equal to the EventProcessor class name.

For an example, look at MyProcessor.

Parameters
parametersParameters for configuration.

Reimplemented from framework::EventProcessor.

Definition at line 21 of file EcalRawEncoder.cxx.

21 {
22 input_name_ = ps.getParameter<std::string>("input_name");
23 input_pass_ = ps.getParameter<std::string>("input_pass");
24 output_name_ = ps.getParameter<std::string>("output_name");
25 roc_version_ = ps.getParameter<int>("roc_version");
26}
std::string output_name_
output object to put onto event bus
std::string input_pass_
input pass of creating encoded data
int roc_version_
version of HGC ROC we are decoding
std::string input_name_
input object of encoded data

References framework::config::Parameters::getParameter(), input_name_, input_pass_, output_name_, and roc_version_.

◆ produce()

void ecal::EcalRawEncoder::produce ( framework::Event event)
virtual

Process the event and put new data products into it.

Parameters
eventThe Event to process.

Static parameters depending on ROC version

Translation

Now the HgcrocDigiCollection::Sample class handles the unpacking of individual samples; however, we still need to translate detector IDs into electronics ID and resort the data into grouped by bunch.

Encoding

Now that the samples are sorted into per-bunch groupings, we can start writing this data into the encoded data format documented in the ECal DAQ specifications. Since the class HgcrocDigiCollection::Sample handles the encoding and decoding of specific sample words, we "only" need to actually encode the header information the calculate the CRC checksums.

TODO calculate bunch ID, read request, and orbit from sample ID, event number, and run number placeholder: bunch ID = event number read request = sample ID orbit = run number

Calculate lengths of link sub-packets

Table 4 of ECal DAQ Specifications.

Each ROC link has 3 header words, a common mode channel, and a trailing CRC checksum word. The 3 header words contain a readout map of which channels are included in the DAQ packet, so we end up with.

len of link = 3 + 1 + channels.size() + 1;

The total FPGA packet includes at least 2 header words, a trailing checksum word, and a single word for each four links.

This means we add up the subpacket lengths into subpacket_total and then

n_linkwords = (nlinks/4+(nlinks%4!=0)) total_length = 2 + n_linkwords + subpacket_total + 1;

Encode Bunch Header We have a few words of header material before the actual data. This header material is assumed to be encoded as in Table 3 of the DAQ specs.

<name> (bits)

VERSION (4) | FPGA_ID (8) | NLINKS (6) | 0 | LEN (12) BX ID (12) | RREQ (10) | OR (10) RID ok (1) | CDC ok (1) | LEN3 (6) | RID ok (1) | CDC ok (1) | LEN2 (6) | RID ok (1) | CDC ok (1) | LEN1 (6) | RID ok (1) | CDC ok (1) | LEN0 (6) ... other listing of links ...

Encode lengths of link subpackets

Prepare RO Map bitset

Encode Each Link in Sequence Now we should be decoding each link serially where each link was encoded as in Table 4 of the DAQ specs

ROC_ID (16) | CRC ok (1) | 00000 | RO Map (8) RO Map (32)

TODO: Common-Mode Channel Somewhere in here is where the common-mode channel would be inserted. I'm not sure if we should expect that the common mode channel also has a sample or it will be reserved and never should have a sample

Implements framework::Producer.

Definition at line 28 of file EcalRawEncoder.cxx.

28 {
32 // static const unsigned int common_mode_channel = roc_version_ == 2 ? 19 : 1;
33
34 auto digis{
36 std::vector<std::map<
37 uint16_t, std::map<uint16_t, std::map<uint32_t, uint32_t> // channel to
38 // sample
39 > // links
40 > // fpgas
41 > // bunches
42 sorted_samples(digis.getNumSamplesPerDigi());
43
52 auto detmap{
53 getCondition<EcalDetectorMap>(EcalDetectorMap::CONDITIONS_OBJECT_NAME)};
54 for (auto digi : digis) {
55 ldmx::EcalID detid{digi.id()};
56 ldmx::EcalElectronicsID eid{detmap.get(detid)};
57
58 for (std::size_t i_bx{0}; i_bx < digis.getNumSamplesPerDigi(); i_bx++) {
59 sorted_samples[i_bx][eid.fiber()][eid.elink()][eid.channel()] =
60 digi.at(i_bx).raw();
61 }
62 }
63
74 std::vector<uint32_t> buffer;
75 // word to use for constructing buffer
76 static uint32_t word;
77 uint32_t i_bx{0};
78 for (auto const& bunch : sorted_samples) {
83 uint32_t bunch_id = event.getEventNumber();
84 uint32_t rreq = i_bx;
85 uint32_t orbit = event.getEventHeader().getRun();
86
87 // bunch lists the fpgs, links, and channels with their corresponding sample
88 for (auto const& [fpga_id, links] : bunch) {
100 std::vector<uint32_t> link_lengths;
101 for (auto const& [link_id, channels] : links) {
102 link_lengths.push_back(3 + 1 + channels.size() + 1);
103 }
104
115 uint32_t n_linkwords =
116 link_lengths.size() / 4 + (link_lengths.size() % 4 != 0);
117 uint32_t total_length{2 + n_linkwords + 1};
118 for (uint32_t const& link_len : link_lengths) {
119 total_length += link_len;
120 }
121
122 packing::utility::CRC fpga_crc;
138 word = 0;
139
140 word |= (1 << (12 + 1 + 6 + 8)); // version
141 word |= (fpga_id & packing::utility::mask<8>) << (12 + 1 + 6); // FPGA
142 word |= (links.size() & packing::utility::mask<6>) << (12 + 1); // NLINKS
143 word |= (total_length & packing::utility::mask<12>); // LEN TODO
144 buffer.push_back(word);
145 fpga_crc << word;
146
147 word = 0;
148 word |= (bunch_id & packing::utility::mask<12>) << 20; // BX ID
149 word |= (rreq & packing::utility::mask<10>) << 10; // RREQ
150 word |= (orbit & packing::utility::mask<10>); // OR
151 buffer.push_back(word);
152 fpga_crc << word;
153
157 for (uint32_t i_linkword{0}; i_linkword < n_linkwords; i_linkword++) {
158 word = 0;
159 for (uint32_t i_linklen{0}; i_linklen < 4; i_linklen++) {
160 uint32_t i_link = 4 * i_linkword + i_linklen;
161 if (i_link <= link_lengths.size()) {
162 // we have a link
163 word |= (((0b11 << 6) +
164 (link_lengths.at(i_link) & packing::utility::mask<6>))
165 << 8 * i_linklen);
166 } // do we have a link for this linklen subword?
167 } // loop through subwords in this word
168 buffer.push_back(word);
169 fpga_crc << word;
170 } // loop through words
171
172 // fpga lists the links and channels with their corresponding sample
173 for (auto const& [link_id, channels] : links) {
177 std::bitset<40> ro_map; // starts as all 0s
178 ro_map.set(0); // special "header" word from ROC
179 ro_map.set(39); // trailing checksum from ROC
180 // each link maps the channels that were readout to their sample
181 for (auto const& [channel, sample] : channels) {
182 ro_map.set(channel);
183 }
184
185 packing::utility::CRC link_crc;
195 word = 0;
196 word |= (link_id & packing::utility::mask<16>) << 16;
197 word |= 1 << 15;
198 // put first 8bits of RO Map in first header word
199 word |= (ro_map >> 32).to_ulong();
200
201 buffer.push_back(word);
202 fpga_crc << word;
203 link_crc << word;
204
205 // next header word is end of RO map
206 word = (ro_map.to_ulong() & 0xFFFFFFFF);
207 buffer.push_back(word);
208 fpga_crc << word;
209 link_crc << word;
210
211 // special "header" word from ROC
212 word = 0;
213 word |= 0b0101 << 28;
214 word |= (bunch_id & packing::utility::mask<12>) << 16;
215 word |= (rreq & packing::utility::mask<6>) << 10;
216 word |= (orbit & packing::utility::mask<3>) << 7;
217 // skipping hamming error bits because we will set them all to false
218 // here
219 word |= 0b0101;
220 buffer.push_back(word);
221 fpga_crc << word;
222 link_crc << word;
223
232 // put samples into buffer
233 for (auto const& [channel, sample] : channels) {
234 buffer.push_back(sample);
235 fpga_crc << sample;
236 link_crc << sample;
237 }
238 buffer.push_back(link_crc.get());
239 fpga_crc << link_crc.get();
240 }
241 }
242 i_bx++;
243 }
244
245 event.add(output_name_, buffer);
246
247 return;
248} // produce
static constexpr const char * CONDITIONS_OBJECT_NAME
The name of the EID <-> DetID map for the ECal.
RawValue raw() const
Definition DetectorID.h:68
Identifies a location in the Ecal readout chain.
Extension of DetectorID providing access to ECal layers and cell numbers in a hex grid.
Definition EcalID.h:20
Represents a collection of the digi hits readout by an HGCROC.
The HGC ROC and FPGA use a CRC checksum to double check that the data transfer has been done correctl...
Definition CRC.h:50
uint32_t get()
Get the calculate checksum from the calculator.
Definition CRC.h:110

References ecal::EcalDetectorMap::CONDITIONS_OBJECT_NAME, packing::utility::CRC::get(), input_name_, input_pass_, output_name_, and ldmx::DetectorID::raw().

Member Data Documentation

◆ input_name_

std::string ecal::EcalRawEncoder::input_name_
private

input object of encoded data

Definition at line 36 of file EcalRawEncoder.h.

Referenced by configure(), and produce().

◆ input_pass_

std::string ecal::EcalRawEncoder::input_pass_
private

input pass of creating encoded data

Definition at line 38 of file EcalRawEncoder.h.

Referenced by configure(), and produce().

◆ output_name_

std::string ecal::EcalRawEncoder::output_name_
private

output object to put onto event bus

Definition at line 40 of file EcalRawEncoder.h.

Referenced by configure(), and produce().

◆ roc_version_

int ecal::EcalRawEncoder::roc_version_
private

version of HGC ROC we are decoding

Definition at line 42 of file EcalRawEncoder.h.

Referenced by configure().


The documentation for this class was generated from the following files: