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