9#include <trg/top/modules/trgtopTRD2TTSConverter/trgtopTRD2TTSConverterModule.h>
11#include <trg/top/dataobjects/TRGTOPTimeStampsSlot.h>
12#include <trg/top/dataobjects/TRGTOPTimeStamp.h>
13#include <top/dataobjects/TOPDigit.h>
14#include <top/dataobjects/TOPRawDigit.h>
35 return std::string(
"1.00");
48 std::string desc =
"TRGTOPTRD2TTSConverterModule(" +
version() +
")" +
"converts TOPRawDigits to TOP TRG timestamps";
52 B2DEBUG(20,
"TRGTOPTRD2TTSConverter: Constructor done.");
58 "name of TOPRawDigit store array", std::string(
""));
61 "name of TOPDigit store array", std::string(
""));
65 "name of TRGTOPTimeStampsSlot store array", std::string(
""));
68 "name of TRGTOPTimeStamp store array", std::string(
""));
75 addParam(
"minNumberOfTimeStamps", m_minNumberOfTimeStamps,
"minimum number of timestamps in a slot (when required, default:5)",
76 MIN_NUMBER_OF_TIMESTAMPS);
80TRGTOPTRD2TTSConverterModule::~TRGTOPTRD2TTSConverterModule()
92 m_TRGTOPTimeStampsSlots.registerRelationTo(m_TRGTOPTimeStamps);
93 m_TRGTOPTimeStamps.registerRelationTo(m_TRGTOPTimeStampsSlots);
111 for (
int slot = 0; slot < NUMBER_OF_TOP_SLOTS; slot++) m_interimTimeStamps[slot].clear();
118 int slot = convertedDigit.getModuleID() - 1;
120 auto relRawDigits = convertedDigit.getRelationsTo<
TOPRawDigit>();
122 if (relRawDigits.size()) {
124 int revo9Counter = relRawDigits[0]->getRevo9Counter();
127 int deltaRevo9 = revo9Counter -
latencyL1;
130 int revo9CounterEvent = deltaRevo9 >= 0 ? deltaRevo9 :
revo9CounterMax + deltaRevo9 ;
134 for (
int i = 1; i < 9; i++) {
135 if (revo9CounterEvent < timeOfWindows[i])
break;
139 auto window = relRawDigits[0]->getASICWindow();
140 auto sample = relRawDigits[0]->getSampleRise();
142 if (phase >= 0 && phase <= 8) {
147 double timeStamp_ns_d = ((numberOfWindows[phase] + window) * 64 + sample) * 0.375 + 0.5 +
timeCorrection;
148 int timeStamp_ns = timeStamp_ns_d;
151 thisTimeStamp.slot = slot + 1;
153 thisTimeStamp.value = timeStamp_ns / 2;
154 thisTimeStamp.refDigit = &convertedDigit;
156 m_interimTimeStamps[slot].push_back(thisTimeStamp);
162 for (
int slot = 0; slot < NUMBER_OF_TOP_SLOTS; slot++) {
164 int numberOfTimeStamps = m_interimTimeStamps[slot].size();
167 && numberOfTimeStamps)) {
171 auto* timeStampsSlotStore = m_TRGTOPTimeStampsSlots.appendNew(slot + 1, numberOfTimeStamps);
182 sort(m_interimTimeStamps[slot].begin(), m_interimTimeStamps[slot].end(),
timeOrder());
184 for (std::vector<interimTimeStamp>::const_iterator it = m_interimTimeStamps[slot].begin(); it != m_interimTimeStamps[slot].end();
189 int value = thisInterimTimeStamp.value;
193 auto* timeStampStore = m_TRGTOPTimeStamps.appendNew(timeStamp);
195 timeStampsSlotStore->addRelationTo(timeStampStore);
196 timeStampStore->addRelationTo(timeStampsSlotStore);
199 timeStampStore->addRelationTo(thisInterimTimeStamp.refDigit);
200 thisInterimTimeStamp.refDigit->
addRelationTo(timeStampStore);
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
Class to store unpacked raw data (hits in feature-extraction format) It provides also calculation of ...
static constexpr int latencyL1
L1 latency in FTSW clock cycles.
StoreArray< TOPRawDigit > m_rawDigits
collection of raw digits
std::string m_outputTimeStampsSlotName
name of TOPTRGTimeStampsSlot store array
bool m_requireMinNumberOfTimeStamps
switch ON/OFF min number of timestamps requirement for individual slots
virtual void initialize() override
Initialize the Module.
std::string m_outputTimeStampName
name of TOPTRGTimeStamp store array
virtual void event() override
This method is the core of the module.
static constexpr int revo9CounterMax
max number of FTSW clocks in revo9 cycle
virtual void endRun() override
This method is called if the current run ends.
virtual void terminate() override
This method is called at the end of the event processing.
TRGTOPTRD2TTSConverterModule()
Constructor: Sets the description, the properties and the parameters of the module.
std::string m_inputRawDigitsName
name of TOPRawDigit store array
int m_eventNumber
Event number (according to L1/global)
virtual void beginRun() override
Called when entering a new run.
static constexpr int timeCorrection
time correction in ns (estimated by comparing trigger readout with main readout
StoreArray< TOPDigit > m_convertedDigits
collection of raw digits
bool m_addRelations
switch ON/OFF relations to TOPRawDigits
std::string m_inputConvertedDigitsName
name of TOPRawDigit store array
std::string version() const
returns version of TRGTOPTRD2TTSConverterModule.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.