Belle II Software  release-08-01-10
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/pxdDataReduction/ROIPayloadAssemblerModule.h>
10 #include <vxd/dataobjects/VxdID.h>
11 #include <set>
12 #include <hlt/softwaretrigger/core/FinalTriggerDecisionCalculator.h>
13 #include <mdst/dataobjects/SoftwareTriggerResult.h>
14 #include <vxd/geometry/GeoCache.h>
15 #include <vxd/geometry/SensorInfoBase.h>
16 
17 using namespace Belle2;
18 
19 //-----------------------------------------------------------------
20 // Register the Module
21 //-----------------------------------------------------------------
22 
23 REG_MODULE(ROIPayloadAssembler);
24 
25 //-----------------------------------------------------------------
26 // Implementation
27 //-----------------------------------------------------------------
28 
30 {
31  //Set module properties
32  setDescription("This module assembles payload for the ROI in the correct format to be sent to the ONSEN");
34 
35  addParam("ROIListName", m_ROIListName, "name of the list of ROIs", std::string(""));
36  addParam("ROIpayloadName", m_ROIpayloadName, "name of the payload of ROIs", std::string(""));
37  addParam("SendAllDownscaler", mSendAllDS,
38  "Send all Data (no selection) downscaler; Workaround for missing ONSEN functionality, 0 never set, 1 alway set, 2 set in every second...",
39  9u);
40  addParam("SendROIsDownscaler", mSendROIsDS,
41  "Send ROIs downscaler; Workaround for missing ONSEN functionality, 0 never set, 1 alway set, 2 set in every second...", 3u);
42  addParam("CutNrROIs", mCutNrROIs,
43  "If Nr of ROIs per DHHID reach this, send out only one full sensor ROI", 32u);
44  addParam("AcceptAll", mAcceptAll, "Accept all, Ignore HLT decision", false);
45  addParam("NoRejectFlag", mNoRejectFlag, "Never reject, just send no ROI", true);
46 }
47 
49 {
50  m_eventMetaData.isRequired();
51  m_ROIList.isOptional(m_ROIListName);
52 
53  m_roiPayloads.registerInDataStore(
54  m_ROIpayloadName); // DataStore::EStoreFlags::c_ErrorIfAlreadyRegistered will not work with two modules in seperate path branches
55 
56  // in case we don't accept all events, we have to look
57  // up the trigger decision
58  if (!mAcceptAll) {
60  result.isRequired();
61  }
62 }
63 
64 
66 {
67  const VXD::GeoCache& aGeometry = VXD::GeoCache::getInstance();
68  unsigned int evtNr = m_eventMetaData->getEvent();
69  unsigned int countROIs = 0;
70  bool accepted = true;
71 
72  if (!mAcceptAll) {
74  if (!result.isValid()) {
76  B2INFO("SoftwareTriggerResult object not available but needed to generate the ROI payload.");
77  accepted = false;
78  } else {
80  }
81  }
82 
83  std::map<VxdID, std::set<ROIrawID, ROIrawID>> mapOrderedROIraw;
84 
85  if (accepted) {
86  // skip the preprocessing if the event is not accepted to save CPU time
87 
88  B2DEBUG(1, " number of ROIs in the list = " << m_ROIList.getEntries());
89 
90  for (auto& iROI : m_ROIList) {
91  ROIrawID roiraw;
93  int layer = (iROI.getSensorID()).getLayerNumber() - 1;
94  int ladder = (iROI.getSensorID()).getLadderNumber();
95  int sensor = (iROI.getSensorID()).getSensorNumber() - 1;
96 
97  roiraw.setSystemFlag(0);// System 0 is HLT, 1 would be DATCON
98  roiraw.setDHHID(((layer) << 5) | ((ladder) << 1) | (sensor));
99 
100  roiraw.setMinVid(iROI.getMinVid());
101  roiraw.setMaxVid(iROI.getMaxVid());
102  roiraw.setMinUid(iROI.getMinUid());
103  roiraw.setMaxUid(iROI.getMaxUid());
104 
105  // order set will drop identical ROIs automatically
106  mapOrderedROIraw[iROI.getSensorID()].insert(roiraw);
107  }
108 
109  B2DEBUG(1, " number of original ROIs = " << m_ROIList.getEntries());
110 
111  // The payload is created with a buffer long enough to contains all
112  // the ROIs but the actual payload could be smaller, if the ROIs per
113  // sensor exceed the (ONSEN) limit, we can save bandwidth by just
114  // sending only one full size ROI for that sensor
115  for (auto& it : mapOrderedROIraw) {
116  if (it.second.size() < mCutNrROIs) countROIs += it.second.size();
117  else countROIs++;
118  }
119  }
120 
121  if (m_roiPayloads.isValid()) {
122  B2FATAL("ROIpayload already in datastore, this must not be the case when calling the ROIPayloadAssemblerModule.");
123  }
124 
125  ROIpayload* payload = new ROIpayload(countROIs);// let the ROIpayload compute the size itself
126 
127  m_roiPayloads.assign(payload);
128 
129  // set all the Header flags and event number
130  payload->setHeader(accepted || mNoRejectFlag,
131  mSendAllDS ? (evtNr % mSendAllDS) == 0 : 0, mSendROIsDS ? (evtNr % mSendROIsDS) == 0 : 0);
132  payload->setTriggerNumber(evtNr);
133 
134  // Set run subrun exp number
135  payload->setRunSubrunExpNumber(m_eventMetaData->getRun(), m_eventMetaData->getSubrun(), m_eventMetaData->getExperiment());
136 
137  unsigned int addROI = 0;
138 
139  if (accepted) {
140  // skip this if the event is not accepted (actually mapOrderedROIraw should be empty anyway)
141  // iterate over map
142  for (auto& it : mapOrderedROIraw) {
143  // check size of set
144  if (it.second.size() > 0) {
145  if (it.second.size() < mCutNrROIs) {
146  for (auto& itSet : it.second) {
147  payload->addROIraw(itSet.getBigEndian());
148  addROI++;
149  }
150  } else {
151  ROIrawID roiraw;
152  B2INFO("Nr ROI on DHHID " << it.second.begin()->getDHHID() << std::endl <<
153  " exceeds limit CutNrROIs, thus full sensor ROI is created.");
154  const VXD::SensorInfoBase& aSensorInfo = aGeometry.getSensorInfo(it.first);
155  const int nPixelsU = aSensorInfo.getUCells();
156  const int nPixelsV = aSensorInfo.getVCells();
157 
158  roiraw.setSystemFlag(0);
159  roiraw.setDHHID(it.second.begin()->getDHHID());
160 
161  roiraw.setMinVid(0);
162  roiraw.setMaxVid(nPixelsV - 1);
163  roiraw.setMinUid(0);
164  roiraw.setMaxUid(nPixelsU - 1);
165 
166  payload->addROIraw(roiraw.getBigEndian());
167  }
168  }
169  }
170  }
171 
172  payload->setPayloadLength();
173  payload->setCRC();
174 
175  B2DEBUG(1, " number of ROIs in payload = " << addROI);
176 }
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.
REG_MODULE(arichBtest)
Register the Module.
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
Abstract base class for different kinds of events.