Belle II Software  release-05-02-19
KLMPackerModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Petr Katrenko, Anselm Vossen, Giacomo De Pietro *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 /* Own header. */
12 #include <klm/modules/KLMPacker/KLMPackerModule.h>
13 
14 /* Belle 2 headers. */
15 #include <framework/logging/Logger.h>
16 
17 using namespace Belle2;
18 
19 REG_MODULE(KLMPacker)
20 
22  Module(),
23  m_ElementNumbers(&(KLMElementNumbers::Instance()))
24 {
25  setDescription("KLM raw data packer (creates RawKLM from KLMDigits).");
26  setPropertyFlags(c_ParallelProcessingCertified);
27 }
28 
30 {
31 }
32 
34 {
35  m_Digits.isRequired();
36  m_EventMetaData.isRequired();
37  m_RawKLMs.registerInDataStore();
38 }
39 
41 {
42  if (!m_ElectronicsMap.isValid())
43  B2FATAL("KLM electronics map is not available.");
44 }
45 
47 {
48  /* Indices: copper, data concentrator.
49  * Coppers from 0 to 3 are BKLM;
50  * coppers from 4 to 7 are EKLM.
51  */
52  std::vector<uint32_t> dataWords[8][4];
53 
54  /* Pack KLM digits. */
55  for (const KLMDigit& digit : m_Digits) {
56  uint32_t buf[2] = {0};
57  uint16_t bword1 = 0;
58  uint16_t bword2 = 0;
59  uint16_t bword3 = 0;
60  uint16_t bword4 = 0;
61  int channel =
63  digit.getSubdetector(), digit.getSection(), digit.getSector(),
64  digit.getLayer(), digit.getPlane(), digit.getStrip());
65  const KLMElectronicsChannel* electronicsChannel =
66  m_ElectronicsMap->getElectronicsChannel(channel);
67  if (electronicsChannel == nullptr)
68  B2FATAL("Incomplete KLM electronics map.");
69  int flag;
70  if (digit.inRPC())
71  flag = 2; // RPC
72  else
73  flag = 4; // Scintillator
74  int lane = electronicsChannel->getLane();
75  int plane = electronicsChannel->getAxis();
76  int strip = electronicsChannel->getChannel();
77  formatData(flag, lane, plane, strip,
78  digit.getCharge(), digit.getCTime(), digit.getTDC(),
79  bword1, bword2, bword3, bword4);
80  buf[0] |= bword2;
81  buf[0] |= ((bword1 << 16));
82  buf[1] |= bword4;
83  buf[1] |= ((bword3 << 16));
84  if (digit.getSubdetector() == KLMElementNumbers::c_BKLM) {
85  int copper = electronicsChannel->getCopper() - BKLM_ID - 1;
86  int dataConcentrator = electronicsChannel->getSlot() - 1;
87  dataWords[copper][dataConcentrator].push_back(buf[0]);
88  dataWords[copper][dataConcentrator].push_back(buf[1]);
89  } else {
90  int copper = electronicsChannel->getCopper() - EKLM_ID - 1;
91  int dataConcentrator = electronicsChannel->getSlot() - 1;
92  dataWords[copper + 4][dataConcentrator].push_back(buf[0]);
93  dataWords[copper + 4][dataConcentrator].push_back(buf[1]);
94  }
95  }
96 
97  /* Create RawKLM objects. */
98  RawCOPPERPackerInfo packerInfo;
99  packerInfo.exp_num = m_EventMetaData->getExperiment();
100  packerInfo.run_subrun_num = (m_EventMetaData->getRun() << 8) +
101  (m_EventMetaData->getSubrun() & 0xFF);
102  packerInfo.eve_num = m_EventMetaData->getEvent();
103  packerInfo.tt_ctime = 0;
104  packerInfo.tt_utime = 0;
105  packerInfo.b2l_ctime = 0;
106  int* detectorBuf[4];
107  int nWords[4];
108  for (int i = 0; i < 8; i++) {
109  if (i < 4) // BKLM
110  packerInfo.node_id = BKLM_ID + 1 + i;
111  else // EKLM
112  packerInfo.node_id = EKLM_ID + 1 + i - 4;
113  RawKLM* rawKlm = m_RawKLMs.appendNew();
114  for (int j = 0; j < 4; j++) {
115  nWords[j] = dataWords[i][j].size();
116  detectorBuf[j] = new int[nWords[j] + 1];
117  for (int k = 0; k < nWords[j]; k++)
118  detectorBuf[j][k] = dataWords[i][j][k];
119  detectorBuf[j][nWords[j]] = 0;
120  }
121  rawKlm->PackDetectorBuf(detectorBuf[0], nWords[0] + 1,
122  detectorBuf[1], nWords[1] + 1,
123  detectorBuf[2], nWords[2] + 1,
124  detectorBuf[3], nWords[3] + 1,
125  packerInfo);
126  for (int j = 0; j < 4; j++)
127  delete[] detectorBuf[j];
128  }
129 }
130 
131 /*
132  * Data format:
133  * Word 1: Bit 0-6 -> strip number.
134  * Bit 7 -> plane number.
135  * Bit 8-12 -> lane in the data concentrator.
136  * Bit 13-15 -> data type: RPC=0x010; scintillator=0x100.
137  * Word 2: 15 bits of ctime.
138  * Word 3: 10 bits of TDC.
139  * Word 4: 12 bits of charge.
140  */
141 void KLMPackerModule::formatData(int flag, int lane, int plane, int strip, int charge, uint16_t ctime, uint16_t tdc,
142  uint16_t& bword1, uint16_t& bword2, uint16_t& bword3, uint16_t& bword4)
143 {
144  bword1 = 0;
145  bword2 = 0;
146  bword3 = 0;
147  bword4 = 0;
148  bword1 |= (strip & 0x7F);
149  bword1 |= ((plane & 1) << 7);
150  bword1 |= ((lane & 0x1F) << 8);
151  bword1 |= (flag << 13);
152  bword2 |= (ctime & 0xFFFF);
153  bword3 |= (tdc & 0x3FF);
154  bword4 |= (charge & 0xFFF);
155 }
156 
158 {
159 }
160 
162 {
163 }
164 
Belle2::RawCOPPERPackerInfo::tt_utime
unsigned int tt_utime
27bit clock ticks at trigger timing distributed by FTSW. For details, see Nakao-san's belle2link user...
Definition: RawCOPPERPackerInfo.h:28
Belle2::RawCOPPERPackerInfo
struct to contain header information used by RawCOPPERFormat::Packer()
Definition: RawCOPPERPackerInfo.h:12
Belle2::KLMPackerModule::endRun
virtual void endRun() override
This method is called if the current run ends.
Definition: KLMPackerModule.cc:157
Belle2::RawCOPPERPackerInfo::exp_num
unsigned int exp_num
Experiment number (10bit)
Definition: RawCOPPERPackerInfo.h:16
Belle2::KLMElectronicsChannel::getChannel
int getChannel() const
Get channel.
Definition: KLMElectronicsChannel.h:145
Belle2::RawCOPPERPackerInfo::node_id
unsigned int node_id
Event Number (32bit)
Definition: RawCOPPERPackerInfo.h:22
Belle2::KLMPackerModule::beginRun
virtual void beginRun() override
Called when entering a new run.
Definition: KLMPackerModule.cc:40
Belle2::RawCOPPERPackerInfo::b2l_ctime
unsigned int b2l_ctime
32bit unitx time at trigger timing distributed by FTSW. For details, see Nakao-san's belle2link user ...
Definition: RawCOPPERPackerInfo.h:31
Belle2::KLMPackerModule::m_ElementNumbers
const KLMElementNumbers * m_ElementNumbers
Element numbers.
Definition: KLMPackerModule.h:119
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::KLMPackerModule
KLM raw packer.
Definition: KLMPackerModule.h:49
Belle2::KLMPackerModule::m_RawKLMs
StoreArray< RawKLM > m_RawKLMs
Raw data.
Definition: KLMPackerModule.h:110
Belle2::KLMElectronicsChannel::getSlot
int getSlot() const
Get slot.
Definition: KLMElectronicsChannel.h:94
Belle2::KLMPackerModule::m_EventMetaData
StoreObjPtr< EventMetaData > m_EventMetaData
Event meta data.
Definition: KLMPackerModule.h:113
Belle2::KLMElementNumbers::channelNumber
uint16_t channelNumber(int subdetector, int section, int sector, int layer, int plane, int strip) const
Get channel number.
Definition: KLMElementNumbers.cc:37
Belle2::RawCOPPERPackerInfo::eve_num
unsigned int eve_num
Run # and subrun # ( 22bit )
Definition: RawCOPPERPackerInfo.h:20
Belle2::KLMDigit
KLM digit (class representing a digitized hit in RPCs or scintillators).
Definition: KLMDigit.h:40
Belle2::KLMElectronicsChannel::getAxis
int getAxis() const
Get axis.
Definition: KLMElectronicsChannel.h:128
Belle2::RawCOPPERPackerInfo::tt_ctime
unsigned int tt_ctime
Node ID (32bit)
Definition: RawCOPPERPackerInfo.h:25
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::KLMPackerModule::event
virtual void event() override
This method is called for each event.
Definition: KLMPackerModule.cc:46
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::RawCOPPERPackerInfo::run_subrun_num
unsigned int run_subrun_num
Experiment number (10bit)
Definition: RawCOPPERPackerInfo.h:18
Belle2::RawKLM
The Raw KLM class Class for RawCOPPER class data taken by KLM.
Definition: RawKLM.h:27
Belle2::KLMPackerModule::terminate
virtual void terminate() override
This method is called at the end of the event processing.
Definition: KLMPackerModule.cc:161
Belle2::KLMPackerModule::formatData
void formatData(int flag, int lane, int plane, int strip, int charge, uint16_t ctime, uint16_t tdc, uint16_t &bword1, uint16_t &bword2, uint16_t &bword3, uint16_t &bword4)
Creation of raw data.
Definition: KLMPackerModule.cc:141
Belle2::KLMElementNumbers::c_BKLM
@ c_BKLM
BKLM.
Definition: KLMElementNumbers.h:47
Belle2::KLMElectronicsChannel::getCopper
int getCopper() const
Get copper.
Definition: KLMElectronicsChannel.h:77
Belle2::KLMElectronicsChannel
BKLM electronics channel.
Definition: KLMElectronicsChannel.h:33
Belle2::RawCOPPER::PackDetectorBuf
void PackDetectorBuf(int *detector_buf_1st, int nwords_1st, int *detector_buf_2nd, int nwords_2nd, int *detector_buf_3rd, int nwords_3rd, int *detector_buf_4th, int nwords_4th, RawCOPPERPackerInfo rawcprpacker_info)
Packer for RawCOPPER class Pack data (format ver.
Definition: RawCOPPER.cc:183
Belle2::KLMElementNumbers
KLM element numbers.
Definition: KLMElementNumbers.h:37
Belle2::KLMElectronicsChannel::getLane
int getLane() const
Get lane.
Definition: KLMElectronicsChannel.h:111
Belle2::KLMPackerModule::m_ElectronicsMap
DBObjPtr< KLMElectronicsMap > m_ElectronicsMap
Electronics map.
Definition: KLMPackerModule.h:116
Belle2::KLMPackerModule::m_Digits
StoreArray< KLMDigit > m_Digits
KLM digits.
Definition: KLMPackerModule.h:122
Belle2::KLMPackerModule::initialize
virtual void initialize() override
Initializer.
Definition: KLMPackerModule.cc:33
Belle2::KLMPackerModule::~KLMPackerModule
virtual ~KLMPackerModule()
Destructor.
Definition: KLMPackerModule.cc:29