Belle II Software development
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
13using namespace Belle2;
14using namespace std;
15
16//-----------------------------------------------------------------
17// Register the Module
18//-----------------------------------------------------------------
19REG_MODULE(svdDump);
20
21//-----------------------------------------------------------------
22// Implementation
23//-----------------------------------------------------------------
24
25// Implementations
27{
28 // Module description
29 setDescription("Module to create SVD data file");
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
43{
44 B2INFO("svdDumpModule: initialize() is called.");
45
46 m_rawSVD.isRequired(m_svdRawName);
47
48 m_event = 0;
49
50 m_outputFile = new ofstream(m_outputFileName.c_str(), ios::trunc);
51 if (!(*m_outputFile)) {
52 B2FATAL("Output file: " << m_outputFileName.c_str() << " cannot be opened.");
53 }
54
55 return;
56}
57
59{
60 B2INFO("svdDumpModule: terminate() is called.");
61
62 m_outputFile->close();
63 delete m_outputFile; m_outputFile = nullptr;
64
65 return;
66}
67
68
70{
71 B2INFO("svdDumpModule: beginRun() is called.");
72}
73
75{
76 B2INFO("svdDumpModule: endRun() is called.");
77}
78
80{
82
83 unsigned int total_nWords = 0;
84 for (int i = 0; i < rawSVD.getEntries(); i++) {
85 for (int j = 0; j < rawSVD[ i ]->GetNumEntries(); j++) {
86 unsigned int nWords = rawSVD[i]->Get1stDetectorNwords(j);
87 if (((int)nWords - m_nFtbHeader - m_nFtbTrailer) < 0) {
88 B2FATAL("Remaining data size is negative: " << ((int)nWords - m_nFtbHeader - m_nFtbTrailer));
89 }
90 unsigned int remaining_nWords = (nWords - m_nFtbHeader - m_nFtbTrailer);
91 total_nWords += remaining_nWords;
92 }
93 }
94 uint32_t header = 0xf;
95 header <<= 28;
96 header |= ((total_nWords & 0xffff) << 12) + (m_event & 0xfff);
97 m_outputFile->write((char*)(&header), sizeof(uint32_t));
98
99 for (int i = 0; i < rawSVD.getEntries(); i++) {
100 for (int j = 0; j < rawSVD[ i ]->GetNumEntries(); j++) {
101
102 unsigned int nWords = rawSVD[i]->Get1stDetectorNwords(j);
103 unsigned int remaining_nWords = (nWords - m_nFtbHeader - m_nFtbTrailer);
104
105 uint32_t* data32 = (uint32_t*)rawSVD[i]->Get1stDetectorBuffer(j);
106
107 m_outputFile->write((char*)(data32 + m_nFtbHeader), sizeof(uint32_t)*remaining_nWords);
108
109 }
110 }
111
112 m_event++;
113
114 return;
115}
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_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
std::string m_svdRawName
raw name
Definition: svdDumpModule.h:49
StoreArray< RawSVD > m_rawSVD
Array for RawSVD.
Definition: svdDumpModule.h:39
virtual void initialize() override
module functions
virtual void event() override
dump RawSVDs
int m_nFtbTrailer
FTB trailer.
Definition: svdDumpModule.h:44
virtual void endRun() override
print end run
virtual void terminate() override
write output file
std::ofstream * m_outputFile
output file.
Definition: svdDumpModule.h:47
virtual void beginRun() override
print begin run
int m_nFtbHeader
FTB header.
Definition: svdDumpModule.h:43
svdDumpModule()
Constructor and Destructor.
unsigned long m_event
event number
Definition: svdDumpModule.h:41
std::string m_outputFileName
Name of output file.
Definition: svdDumpModule.h:46
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
#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.
STL namespace.