Belle II Software  release-06-01-15
svdDumpModule.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 <svd/modules/svdDump/svdDumpModule.h>
10 
11 #include <framework/logging/Logger.h>
12 
13 using namespace Belle2;
14 using namespace std;
15 
16 //-----------------------------------------------------------------
17 // Register the Module
18 //-----------------------------------------------------------------
19 REG_MODULE(svdDump)
20 
21 //-----------------------------------------------------------------
22 // Implementation
23 //-----------------------------------------------------------------
24 
25 // Implementations
27 {
28  // Module description
29  setDescription("Module to create SVD data file");
30  setPropertyFlags(Module::c_HistogramManager);
31 
32  // Parameters
33  addParam("outputFileName", m_outputFileName, "Name of output file.", string("svdDumpModule.dat"));
34 
35  addParam("svdRawName", m_svdRawName, "Name of the SVD Raw", string(""));
36 
37  addParam("nFtbHeader", m_nFtbHeader, "# of FTB header", int(2));
38  addParam("nFtbTrailer", m_nFtbTrailer, "# of FTB header", int(1));
39 
40 }
41 
42 svdDumpModule::~svdDumpModule()
43 {
44 }
45 
47 {
48  B2INFO("svdDumpModule: initialize() is called.");
49 
50  m_rawSVD.isRequired(m_svdRawName);
51 
52  m_event = 0;
53 
54  m_outputFile = new ofstream(m_outputFileName.c_str(), ios::trunc);
55  if (!(*m_outputFile)) {
56  B2FATAL("Output file: " << m_outputFileName.c_str() << " cannot be opened.");
57  }
58 
59  return;
60 }
61 
63 {
64  B2INFO("svdDumpModule: terminate() is called.");
65 
66  m_outputFile->close();
67  delete m_outputFile; m_outputFile = nullptr;
68 
69  return;
70 }
71 
72 
74 {
75  B2INFO("svdDumpModule: beginRun() is called.");
76 }
77 
79 {
80  B2INFO("svdDumpModule: endRun() is called.");
81 }
82 
84 {
85  StoreArray<RawSVD> rawSVD(m_svdRawName);
86 
87  unsigned int total_nWords = 0;
88  for (int i = 0; i < rawSVD.getEntries(); i++) {
89  for (int j = 0; j < rawSVD[ i ]->GetNumEntries(); j++) {
90  unsigned int nWords = rawSVD[i]->Get1stDetectorNwords(j);
91  if (((int)nWords - m_nFtbHeader - m_nFtbTrailer) < 0) {
92  B2FATAL("Remaining data size is negative: " << ((int)nWords - m_nFtbHeader - m_nFtbTrailer));
93  }
94  unsigned int remaining_nWords = (nWords - m_nFtbHeader - m_nFtbTrailer);
95  total_nWords += remaining_nWords;
96  }
97  }
98  uint32_t header = (0xf << 28);
99  header |= ((total_nWords & 0xffff) << 12) + (m_event & 0xfff);
100  m_outputFile->write((char*)(&header), sizeof(uint32_t));
101 
102  for (int i = 0; i < rawSVD.getEntries(); i++) {
103  for (int j = 0; j < rawSVD[ i ]->GetNumEntries(); j++) {
104 
105  unsigned int nWords = rawSVD[i]->Get1stDetectorNwords(j);
106  unsigned int remaining_nWords = (nWords - m_nFtbHeader - m_nFtbTrailer);
107 
108  uint32_t* data32 = (uint32_t*)rawSVD[i]->Get1stDetectorBuffer(j);
109 
110  m_outputFile->write((char*)(data32 + m_nFtbHeader), sizeof(uint32_t)*remaining_nWords);
111 
112  }
113  }
114 
115  m_event++;
116 
117  return;
118 }
Base class for Modules.
Definition: Module.h:72
@ c_HistogramManager
This module is used to manage histograms accumulated by other modules.
Definition: Module.h:81
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
Class definition of svdClsHistoManager module.
Definition: svdDumpModule.h:28
virtual void initialize() override
module functions
virtual void event() override
This method is the core of the module.
virtual void endRun() override
This method is called if the current run ends.
virtual void terminate() override
This method is called at the end of the event processing.
virtual void beginRun() override
Called when entering a new run.
#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.