Belle II Software  release-05-02-19
ECLCompressBGOverlayModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2018 - Belle II Collaboration *
4  * *
5  * Author: Alexei Sibidanov *
6  * *
7  * This software is provided "as is" without any warranty. *
8  **************************************************************************/
9 
10 //This module
11 #include <ecl/modules/eclCompressBGOverlay/ECLCompressBGOverlayModule.h>
12 
13 //ECL
14 #include <ecl/dataobjects/ECLDsp.h>
15 #include <ecl/dataobjects/ECLWaveforms.h>
16 #include <ecl/digitization/EclConfiguration.h>
17 
18 using namespace Belle2;
19 using namespace ECL;
20 
21 //-----------------------------------------------------------------
22 // Register the Module
23 //-----------------------------------------------------------------
24 REG_MODULE(ECLCompressBGOverlay)
25 
26 //-----------------------------------------------------------------
27 // Implementation
28 //-----------------------------------------------------------------
30 {
31  //Set module properties
32  setDescription("Compress recorded waveforms for beam backround overlay in simulation.");
33  setPropertyFlags(c_ParallelProcessingCertified);
34  addParam("CompressionAlgorithm", m_compAlgo, "Waveform compression algorithm", 0u);
35  addParam("eclWaveformsName", m_eclWaveformsName, "Name of the collection with compressed waveforms", std::string(""));
36 }
37 
39 {
40 }
41 
43 {
44  m_eclDsps.registerInDataStore();
45  m_eclWaveforms.registerInDataStore(m_eclWaveformsName);
46  m_comp = selectAlgo(m_compAlgo & 0xff);
47  if (m_comp == NULL)
48  B2FATAL("Unknown compression algorithm: " << m_compAlgo);
49 }
50 
52 {
53  setReturnValue(0);
55 
56  // check the number of waveforms
57  if (m_eclDsps.getEntries() != ec.m_nch) return;
58 
59  // sort by cell id
60  unsigned short indx[ec.m_nch], count = 0;
61  memset(indx, 0xff, sizeof(indx));
62  for (const auto& t : m_eclDsps) indx[t.getCellId() - 1] = count++;
63 
64  // check that all crystals are here
65  for (auto t : indx) if (t >= ec.m_nch) return;
66 
67  int FitA[ec.m_nsmp]; // buffer for a waveform
68 
69  // compress waveforms
70  BitStream out(ec.m_nch * ec.m_nsmp);
71  out.putNBits(m_compAlgo & 0xff, 8);
72  for (int j = 0; j < ec.m_nch; j++) {
73  m_eclDsps[indx[j]]->getDspA(FitA);
74  m_comp->compress(out, FitA);
75  }
76  out.resize();
77 
78  ECLWaveforms* wf = new ECLWaveforms;
79  m_eclWaveforms.assign(wf);
80 
81  std::swap(out.getStore(), wf->getStore());
82  setReturnValue(1);
83 }
84 
86 {
87  if (m_comp) delete m_comp;
88 }
Belle2::ECLCompressBGOverlayModule::~ECLCompressBGOverlayModule
~ECLCompressBGOverlayModule()
Destructor
Definition: ECLCompressBGOverlayModule.cc:38
Belle2::ECL::EclConfiguration::m_nch
static constexpr int m_nch
total number of electronic channels (crystals) in calorimeter
Definition: EclConfiguration.h:44
Belle2::ECLCompressBGOverlayModule
The ECLCompressBGOverlay module compresses recorded waveforms triggered by the random trigger and to ...
Definition: ECLCompressBGOverlayModule.h:38
Belle2::ECL::EclConfiguration::m_nsmp
static constexpr int m_nsmp
number of ADC measurements for signal fitting
Definition: EclConfiguration.h:51
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::ECL::BitStream
Bit stream struct.
Definition: ECLCompress.h:39
Belle2::ECLCompressBGOverlayModule::event
void event() override
Compression happens here.
Definition: ECLCompressBGOverlayModule.cc:51
Belle2::ECLWaveforms::getStore
std::vector< unsigned int > & getStore()
get data
Definition: ECLWaveforms.h:38
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::ECL::EclConfiguration
singleton class to hold the ECL configuration
Definition: EclConfiguration.h:31
Belle2::ECL::EclConfiguration::get
static EclConfiguration & get()
return this instance
Definition: EclConfiguration.h:34
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ECLCompressBGOverlayModule::terminate
void terminate() override
Cleanup variables
Definition: ECLCompressBGOverlayModule.cc:85
Belle2::ECLCompressBGOverlayModule::initialize
void initialize() override
Initialize variables
Definition: ECLCompressBGOverlayModule.cc:42
Belle2::ECLWaveforms
Class to store ECL waveforms for entire calorimeter.
Definition: ECLWaveforms.h:32