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