Skip to content

Commit b9f08d3

Browse files
mfasDadavidrohr
authored andcommitted
[EMCAL-610] Change handling of current bunch in bunch spitting
Changing find bunches method to push bunches to the output vector after they are closed instead of when they are opened. In this case buches with 0 length (ADCs suppressed by zero-suppression) can be filtered out. A minimum amount of samples (default: 3 - settable) is required to select the bunch when closing. In addition: Add documentation to header file.
1 parent 708b62d commit b9f08d3

2 files changed

Lines changed: 151 additions & 29 deletions

File tree

Detectors/EMCAL/simulation/include/EMCALSimulation/RawWriter.h

Lines changed: 114 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,33 @@ namespace emcal
3535
{
3636

3737
class Geometry;
38+
39+
/// \struct AltroBunch
40+
/// \brief ALTRO bunch information obtained from digits
3841
struct AltroBunch {
39-
int mStarttime;
40-
std::vector<int> mADCs;
42+
int mStarttime; ///< Start time of the bunch
43+
std::vector<int> mADCs; ///< ADCs belonging to the bunch
4144
};
4245

46+
/// \struct ChannelData
47+
/// \brief Structure for mapping digits to Channels within a SRU
4348
struct ChannelData {
44-
int mRow;
45-
int mCol;
46-
std::vector<o2::emcal::Digit*> mDigits;
49+
int mRow; ///< Row of the channel
50+
int mCol; ///< Column of the channel
51+
std::vector<o2::emcal::Digit*> mDigits; ///< Digits for the channel within the current event
4752
};
4853

54+
/// \struct SRUDigitContainer
55+
/// \brief Structure for organizing digits within the SRU
4956
struct SRUDigitContainer {
50-
int mSRUid;
51-
std::map<int, ChannelData> mChannels;
57+
int mSRUid; ///< DDL of the SRU
58+
std::map<int, ChannelData> mChannels; ///< Containers for channels within the SRU
5259
};
5360

61+
/// \union ChannelHeader
62+
/// \brief Bitfield encoding channel headers
5463
union ChannelHeader {
55-
uint32_t mDataWord;
64+
uint32_t mDataWord; ///< Full data word representation
5665
struct {
5766
uint32_t mHardwareAddress : 16; ///< Bits 0 - 15: Hardware address
5867
uint32_t mPayloadSize : 10; ///< Bits 16 - 25: Payload size
@@ -62,8 +71,10 @@ union ChannelHeader {
6271
};
6372
};
6473

74+
/// \union CaloBunchWord
75+
/// \brief Encoding of ALTRO words (32 bit consisting of 3 10-bit words)
6576
union CaloBunchWord {
66-
uint32_t mDataWord;
77+
uint32_t mDataWord; ///< Full data word representation
6778
struct {
6879
uint32_t mWord2 : 10; ///< Bits 0 - 9 : Word 2
6980
uint32_t mWord1 : 10; ///< Bits 10 - 19 : Word 1
@@ -72,45 +83,135 @@ union CaloBunchWord {
7283
};
7384
};
7485

86+
/// \class RawWriter
87+
/// \brief Raw data creator for EMCAL raw data based on EMCAL digits
88+
/// \ingroup EMCALsimulation
89+
/// \author Markus Fasel <markus.fasel@cern.ch>, Oak Ridge National Laboratory
90+
/// \author Hadi Hassan, Oak Ridge National Laboratory
91+
/// \since Jan 24, 2020
7592
class RawWriter
7693
{
7794
public:
95+
/// \enum FileFor_t
96+
/// \brief Definition of the granularity of the raw files
7897
enum class FileFor_t {
79-
kFullDet,
80-
kSubDet,
81-
kLink
98+
kFullDet, ///< Full detector (EMCAL + DCAL)
99+
kSubDet, ///< Subdetector (EMCAL/DCAL separate)
100+
kLink ///< Per link
82101
};
102+
103+
/// \brief Dummy constructor
83104
RawWriter() = default;
105+
106+
/// \brief Constructor, defining output location
107+
/// \param outputdir Output directiory
108+
///
109+
/// Initializing the output directory. The output files
110+
/// can be found in the output directory with the granularity
111+
/// defined via setFileFor
84112
RawWriter(const char* outputdir) { setOutputLocation(outputdir); }
113+
114+
/// \brief Destructor
85115
~RawWriter() = default;
86116

117+
/// \brief Get access to underlying RawFileWriter
118+
/// \return RawFileWriter
87119
o2::raw::RawFileWriter& getWriter() const { return *mRawWriter; }
88120

89121
void setOutputLocation(const char* outputdir) { mOutputLocation = outputdir; }
90122
void setDigits(gsl::span<o2::emcal::Digit> digits) { mDigits = digits; }
123+
124+
/// \brief Set the granularity of the output file
125+
/// \param filefor Output granularity
126+
///
127+
/// Output files can be created for
128+
/// - Whole EMCAL
129+
/// - Subdetector (EMCAL or DCAL)
130+
/// - Link
91131
void setFileFor(FileFor_t filefor) { mFileFor = filefor; }
132+
133+
/// \brief Set the number of ADC samples in the readout window
134+
/// \param nsapmles Number of time samples
92135
void setNumberOfADCSamples(int nsamples) { mNADCSamples = nsamples; }
136+
137+
/// \brief Set min. ADC samples expected in a calo bunch
138+
/// \param nsamples Minimum number of ADC samples
139+
void setMinADCSamplesBunch(int nsamples) { mMinADCBunch = nsamples; }
140+
141+
/// \brief Set pedestal threshold used to accept ADC values when creating the bunches
142+
/// \param pedestal Pedestal value
93143
void setPedestal(int pedestal) { mPedestal = pedestal; }
144+
145+
/// \brief Set the geometry parameters
146+
/// \param geo EMCAL geometry
94147
void setGeometry(o2::emcal::Geometry* geo) { mGeometry = geo; }
95148

96149
void init();
150+
151+
/// \brief Converting digits from a full timeframe to raw pages
152+
/// \param digits Vector of digits belonging to the same timeframe
153+
/// \param triggers trigger records with ranges in digits container of data for the various events in the timeframe
154+
///
155+
/// Processing all events from within a timeframe. See processTrigger for more information
156+
/// about the digit to raw converion of a single event.
97157
void digitsToRaw(gsl::span<o2::emcal::Digit> digits, gsl::span<o2::emcal::TriggerRecord> triggers);
158+
159+
/// \brief Processing digits to raw conversion for the digits from the current event
160+
/// \param trg Trigger record providing collision information and data range for the current event
161+
///
162+
/// Digits are first sorted according to SRUs and within their channels and time samples.
163+
/// For each SRU and channel within the SRU calo bunches are created. In case at least one
164+
/// valid calo bunch is found channels are created, and they data words are organized in a
165+
/// raw stream, which is closed by the RCU trailer of the given stream. The content of the
166+
/// stream is then passed to the RawFileWriter for page splitting and output streaming.
98167
bool processTrigger(const o2::emcal::TriggerRecord& trg);
99168

100169
int carryOverMethod(const header::RDHAny* rdh, const gsl::span<char> data,
101170
const char* ptr, int maxSize, int splitID,
102171
std::vector<char>& trailer, std::vector<char>& header) const;
103172

104173
protected:
174+
/// \brief Parse digits vector in channel and create ALTRO bunches
175+
/// \param channelDigits Vector with digits in the channel for the current event
176+
///
177+
/// Channels are parsed in a time-reversed order. Bunches are selected for ranges of
178+
/// digits where the ADC value is consecutively above the pedestal. Only bunches having
179+
/// a min. amount of ADC samples are selected.
105180
std::vector<AltroBunch> findBunches(const std::vector<o2::emcal::Digit*>& channelDigits);
106181

182+
/// \brief Create channel header
183+
/// \param hardwareAddress Hardware address
184+
/// \param payloadSize Size of the payload of the channel in 10-bit ALTRO words
185+
/// \param isBadChannel If true the channel is a bad channel at hardware level
107186
ChannelHeader createChannelHeader(int hardwareAddress, int payloadSize, bool isBadChannel);
187+
188+
/// \brief Creating RCU trailer
189+
/// \param payloadsize Size of the payload as 32bit word
190+
/// \param timesampe Length of the time sample (for L1 phase calculation)
191+
/// \param triggertime Time of the trigger (for L1 phase calculation)
192+
/// \param feeID Link ID
193+
///
194+
/// Creating RCU trailer. Also setting the values of the ALTRO Config registers based
195+
/// on the settings in the raw writer. The RCU trailer is then encoded and converted to
196+
/// 8-bit words.
108197
std::vector<char> createRCUTrailer(int payloadsize, double timesample, uint64_t triggertime, int feeID);
198+
199+
/// \brief Encoding words of the ALTRO bunch into 32-bit words
200+
/// \param data ALTRO bunch information
201+
/// \return Encoded ALTRO words
202+
///
203+
/// Converting ALTRO bunch into ALTRO words. For the ALTRO bunch the following structure is
204+
/// expected:
205+
/// - bunch size including bunch header size (2)
206+
/// - start time
207+
/// - ADC samples
208+
/// The input data is converted to 10 but ALTRO words and put on the stream.
109209
std::vector<int> encodeBunchData(const std::vector<int>& data);
110210

111211
private:
112212
int mNADCSamples = 15; ///< Number of time samples
113-
int mPedestal = 0; ///< Pedestal
213+
int mPedestal = 1; ///< Pedestal
214+
int mMinADCBunch = 3; ///< Min. number of ADC samples in ALTRO bunch
114215
FileFor_t mFileFor = FileFor_t::kFullDet; ///< Granularity of the output files
115216
o2::emcal::Geometry* mGeometry = nullptr; ///< EMCAL geometry
116217
std::string mOutputLocation; ///< Rawfile name

Detectors/EMCAL/simulation/src/RawWriter.cxx

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ bool RawWriter::processTrigger(const o2::emcal::TriggerRecord& trg)
132132

133133
std::vector<int> rawbunches;
134134
for (auto& bunch : findBunches(channel.mDigits)) {
135+
if (!bunch.mADCs.size()) {
136+
LOG(ERROR) << "Found bunch with without ADC entries - skipping ...";
137+
continue;
138+
}
135139
rawbunches.push_back(bunch.mADCs.size() + 2); // add 2 words for header information
136140
rawbunches.push_back(bunch.mStarttime);
137141
for (auto adc : bunch.mADCs) {
@@ -188,37 +192,54 @@ bool RawWriter::processTrigger(const o2::emcal::TriggerRecord& trg)
188192
std::vector<AltroBunch> RawWriter::findBunches(const std::vector<o2::emcal::Digit*>& channelDigits)
189193
{
190194
std::vector<AltroBunch> result;
191-
AltroBunch* currentBunch = nullptr;
195+
AltroBunch currentBunch;
196+
bool bunchStarted = false;
192197
// Digits in ALTRO bunch in time-reversed order
193198
int itime;
194199
for (itime = channelDigits.size() - 1; itime >= 0; itime--) {
195200
auto dig = channelDigits[itime];
196201
if (!dig) {
197-
if (currentBunch) {
198-
currentBunch->mStarttime = itime + 1;
199-
currentBunch = nullptr;
202+
if (bunchStarted) {
203+
// we have a bunch which is started and needs to be closed
204+
// check if the ALTRO bunch has a minimum amount of ADCs
205+
if (currentBunch.mADCs.size() >= mMinADCBunch) {
206+
// Bunch selected, set start time and push to bunches
207+
currentBunch.mStarttime = itime + 1;
208+
result.push_back(currentBunch);
209+
currentBunch = AltroBunch();
210+
bunchStarted = false;
211+
}
200212
}
201213
continue;
202214
}
203215
int adc = dig->getAmplitudeADC();
204216
if (adc < mPedestal) {
205-
// Stop bunch
217+
// ADC value below threshold
218+
// in case we have an open bunch it needs to be stopped bunch
206219
// Set the start time to the time sample of previous (passing) digit
207-
currentBunch->mStarttime = itime + 1;
208-
currentBunch = nullptr;
209-
continue;
220+
if (bunchStarted) {
221+
// check if the ALTRO bunch has a minimum amount of ADCs
222+
if (currentBunch.mADCs.size() >= mMinADCBunch) {
223+
// Bunch selected, set start time and push to bunches
224+
currentBunch.mStarttime = itime + 1;
225+
result.push_back(currentBunch);
226+
currentBunch = AltroBunch();
227+
bunchStarted = false;
228+
}
229+
}
210230
}
211-
if (!currentBunch) {
212-
// start new bunch
213-
AltroBunch bunch;
214-
result.push_back(bunch);
215-
currentBunch = &(result.back());
231+
// Valid ADC value, if the bunch is closed we start a new bunch
232+
if (!bunchStarted) {
233+
bunchStarted = true;
216234
}
217-
currentBunch->mADCs.emplace_back(adc);
235+
currentBunch.mADCs.emplace_back(adc);
218236
}
219237
// if we have a last bunch set time start time to the time bin of teh previous digit
220-
if (currentBunch) {
221-
currentBunch->mStarttime = itime + 1;
238+
if (bunchStarted) {
239+
if (currentBunch.mADCs.size() >= mMinADCBunch) {
240+
currentBunch.mStarttime = itime + 1;
241+
result.push_back(currentBunch);
242+
}
222243
}
223244
return result;
224245
}

0 commit comments

Comments
 (0)