Belle II Software development
ROIPayloadAssemblerModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <tracking/modules/roiFinding/pxd/ROIPayloadAssemblerModule.h>
10#include <framework/dataobjects/EventMetaData.h>
11#include <tracking/dataobjects/ROIid.h>
12#include <tracking/dataobjects/ROIpayload.h>
13#include <vxd/dataobjects/VxdID.h>
14#include <hlt/softwaretrigger/core/FinalTriggerDecisionCalculator.h>
15#include <mdst/dataobjects/SoftwareTriggerResult.h>
16#include <vxd/geometry/GeoCache.h>
17#include <vxd/geometry/SensorInfoBase.h>
18
19#include <set>
20
21using namespace Belle2;
22
23//-----------------------------------------------------------------
24// Register the Module
25//-----------------------------------------------------------------
26
27REG_MODULE(ROIPayloadAssembler);
28
29//-----------------------------------------------------------------
30// Implementation
31//-----------------------------------------------------------------
32
34{
35 //Set module properties
36 setDescription("This module assembles payload for the ROI in the correct format to be sent to the ONSEN");
38
39 addParam("ROIListName", m_ROIListName, "name of the list of ROIs", std::string(""));
40 addParam("ROIpayloadName", m_ROIpayloadName, "name of the payload of ROIs", std::string(""));
41 addParam("SendAllDownscaler", mSendAllDS,
42 "Send all Data (no selection) downscaler; Workaround for missing ONSEN functionality, 0 never set, 1 always set, 2 set in every second...",
43 9u);
44 addParam("SendROIsDownscaler", mSendROIsDS,
45 "Send ROIs downscaler; Workaround for missing ONSEN functionality, 0 never set, 1 always set, 2 set in every second...", 3u);
46 addParam("CutNrROIs", mCutNrROIs,
47 "If Nr of ROIs per DHHID reach this, send out only one full sensor ROI", 32u);
48 addParam("AcceptAll", mAcceptAll, "Accept all, Ignore HLT decision", false);
49 addParam("NoRejectFlag", mNoRejectFlag, "Never reject, just send no ROI", true);
50}
51
53{
54 m_eventMetaData.isRequired();
55 m_ROIList.isOptional(m_ROIListName);
56
57 m_roiPayloads.registerInDataStore(
58 m_ROIpayloadName); // DataStore::EStoreFlags::c_ErrorIfAlreadyRegistered will not work with two modules in separate path branches
59
60 // in case we don't accept all events, we have to look
61 // up the trigger decision
62 if (!mAcceptAll) {
64 result.isRequired();
65 }
66}
67
68
70{
71 const VXD::GeoCache& aGeometry = VXD::GeoCache::getInstance();
72 unsigned int evtNr = m_eventMetaData->getEvent();
73 unsigned int countROIs = 0;
74 bool accepted = true;
75
76 if (!mAcceptAll) {
78 if (!result.isValid()) {
80 B2INFO("SoftwareTriggerResult object not available but needed to generate the ROI payload.");
81 accepted = false;
82 } else {
84 }
85 }
86
87 std::map<VxdID, std::set<ROIrawID, ROIrawID>> mapOrderedROIraw;
88
89 if (accepted) {
90 // skip the preprocessing if the event is not accepted to save CPU time
91
92 B2DEBUG(1, " number of ROIs in the list = " << m_ROIList.getEntries());
93
94 for (auto& iROI : m_ROIList) {
95 ROIrawID roiraw;
97 int layer = (iROI.getSensorID()).getLayerNumber() - 1;
98 int ladder = (iROI.getSensorID()).getLadderNumber();
99 int sensor = (iROI.getSensorID()).getSensorNumber() - 1;
100
101 roiraw.setSystemFlag(0);// System 0 is HLT, 1 would be DATCON
102 roiraw.setDHHID(((layer) << 5) | ((ladder) << 1) | (sensor));
103
104 roiraw.setMinVid(iROI.getMinVid());
105 roiraw.setMaxVid(iROI.getMaxVid());
106 roiraw.setMinUid(iROI.getMinUid());
107 roiraw.setMaxUid(iROI.getMaxUid());
108
109 // order set will drop identical ROIs automatically
110 mapOrderedROIraw[iROI.getSensorID()].insert(roiraw);
111 }
112
113 B2DEBUG(1, " number of original ROIs = " << m_ROIList.getEntries());
114
115 // The payload is created with a buffer long enough to contains all
116 // the ROIs but the actual payload could be smaller, if the ROIs per
117 // sensor exceed the (ONSEN) limit, we can save bandwidth by just
118 // sending only one full size ROI for that sensor
119 for (auto& it : mapOrderedROIraw) {
120 if (it.second.size() < mCutNrROIs) countROIs += it.second.size();
121 else countROIs++;
122 }
123 }
124
125 if (m_roiPayloads.isValid()) {
126 B2FATAL("ROIpayload already in datastore, this must not be the case when calling the ROIPayloadAssemblerModule.");
127 }
128
129 ROIpayload* payload = new ROIpayload(countROIs);// let the ROIpayload compute the size itself
130
131 m_roiPayloads.assign(payload);
132
133 // set all the Header flags and event number
134 payload->setHeader(accepted || mNoRejectFlag,
135 mSendAllDS ? (evtNr % mSendAllDS) == 0 : 0, mSendROIsDS ? (evtNr % mSendROIsDS) == 0 : 0);
136 payload->setTriggerNumber(evtNr);
137
138 // Set run subrun exp number
139 payload->setRunSubrunExpNumber(m_eventMetaData->getRun(), m_eventMetaData->getSubrun(), m_eventMetaData->getExperiment());
140
141 unsigned int addROI = 0;
142
143 if (accepted) {
144 // skip this if the event is not accepted (actually mapOrderedROIraw should be empty anyway)
145 // iterate over map
146 for (auto& it : mapOrderedROIraw) {
147 // check size of set
148 if (it.second.size() > 0) {
149 if (it.second.size() < mCutNrROIs) {
150 for (auto& itSet : it.second) {
151 payload->addROIraw(itSet.getBigEndian());
152 addROI++;
153 }
154 } else {
155 ROIrawID roiraw;
156 B2INFO("Nr ROI on DHHID " << it.second.begin()->getDHHID() << std::endl <<
157 " exceeds limit CutNrROIs, thus full sensor ROI is created.");
158 const VXD::SensorInfoBase& aSensorInfo = aGeometry.getSensorInfo(it.first);
159 const int nPixelsU = aSensorInfo.getUCells();
160 const int nPixelsV = aSensorInfo.getVCells();
161
162 roiraw.setSystemFlag(0);
163 roiraw.setDHHID(it.second.begin()->getDHHID());
164
165 roiraw.setMinVid(0);
166 roiraw.setMaxVid(nPixelsV - 1);
167 roiraw.setMinUid(0);
168 roiraw.setMaxUid(nPixelsU - 1);
169
170 payload->addROIraw(roiraw.getBigEndian());
171 }
172 }
173 }
174 }
175
176 payload->setPayloadLength();
177 payload->setCRC();
178
179 B2DEBUG(1, " number of ROIs in payload = " << addROI);
180}
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
unsigned int mSendROIsDS
Send ROIs downscaler; Workaround for missing ONSEN functionality.
void initialize() override final
Initializes the Module.
bool mNoRejectFlag
Never reject, just send no ROI.
std::string m_ROIListName
name of the ROI list
StoreObjPtr< ROIpayload > m_roiPayloads
pointer to the ROIpayload dataobject
std::string m_ROIpayloadName
name of the payload to be sent to ONSEN
StoreObjPtr< EventMetaData > m_eventMetaData
pointer to the dataobject with event number etc
unsigned int mCutNrROIs
If Nr of ROIs per DHHID reach this, send out only one full sensor ROI.
void event() override final
This method is the core of the module.
bool mAcceptAll
Accept all event, dont use HLT decision.
ROIPayloadAssemblerModule()
Constructor of the module.
unsigned int mSendAllDS
Send all Data (no selection) downscaler; Workaround for missing ONSEN functionality.
StoreArray< ROIid > m_ROIList
the ROIids dataobjects collection
ROIpayload TODO: Better explanation, Is there a reason to inherit from TObject and not Relationsobjec...
Definition: ROIpayload.h:35
ROIrawID.
Definition: ROIrawID.h:24
void setMinVid(baseType MinV)
set minimum V
Definition: ROIrawID.h:79
void setSystemFlag(baseType SystemFlag)
set system flag
Definition: ROIrawID.h:77
void setMinUid(baseType MinU)
set minimum U
Definition: ROIrawID.h:80
void setMaxUid(baseType MaxU)
set maximum U
Definition: ROIrawID.h:82
void setDHHID(baseType DHHID)
set DHH ID
Definition: ROIrawID.h:78
void setMaxVid(baseType MaxV)
set maximum V
Definition: ROIrawID.h:81
baseType getBigEndian() const
get bigEndian
Definition: ROIrawID.cc:13
static bool getFinalTriggerDecision(const SoftwareTriggerResult &result, bool forgetTotalResult=false)
Calculate the final cut decision using all "total_results" of all sub triggers in the software trigge...
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
Class to faciliate easy access to sensor information of the VXD like coordinate transformations or pi...
Definition: GeoCache.h:39
const SensorInfoBase & getSensorInfo(Belle2::VxdID id) const
Return a referecne to the SensorInfo of a given SensorID.
Definition: GeoCache.cc:67
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:214
Base class to provide Sensor Information for PXD and SVD.
int getVCells() const
Return number of pixel/strips in v direction.
int getUCells() const
Return number of pixel/strips in u direction.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.