Belle II Software development
TRGCDCTSStreamReader.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//-----------------------------------------------------------------------------
10// Description : A program to read Track Segment (TS) stream data
11//-----------------------------------------------------------------------------
12
13#define TRG_SHORT_NAMES
14#define TRGCDC_SHORT_NAMES
15
16#include <iostream>
17#include <fstream>
18#include <string>
19#include "trg/trg/BitStream.h"
20#include "trg/cdc/Wire.h"
21#ifdef TRGCDC_DISPLAY
22#include "framework/gearbox/Gearbox.h"
23#include "trg/cdc/DisplayRphi.h"
24#include "trg/cdc/DisplayHough.h"
25namespace Belle2_TRGCDC {
26 Belle2::TRGCDCDisplayRphi* D = 0;
27}
28#endif
29
30using namespace std;
31using namespace Belle2;
32#ifdef TRGCDC_DISPLAY
33using namespace Belle2_TRGCDC;
34#endif
35
36#define DEBUG_LEVEL 1
37#define PROGRAM_NAME "TRGCDCTSStreamReader"
38#define PROGRAM_VERSION "version 0.03"
39#define ENV_PATH "BELLE2_LOCAL_DIR"
40#define CONFIG "TRGCDCWireConfig_0_20101110_0836.dat"
41
42int
43main(int argc, const char* argv[])
44{
45
46 cout << PROGRAM_NAME << " ... " << PROGRAM_VERSION << endl;
47 const string tab = " ";
48
49 //...Check arguments...
50 if (argc < 2) {
51 cout << PROGRAM_NAME << " !!! one argument necessary" << endl
52 << tab << " 1 : Track Segment Stream data file" << endl;
53 return -1;
54 }
55
56 //...1st argument...
57 const string inname = argv[1];
58 cout << tab << "Track Segment Stream : " << inname << endl;
59
60 //...Open configuration data...
61 ifstream infile(inname.c_str(), ios::in | ios::binary);
62 if (infile.fail()) {
63 cout << PROGRAM_NAME << " !!! can not open file" << endl
64 << " " << inname << endl;
65 return -2;
66 }
67
68#ifdef TRGCDC_DISPLAY
69 //...Gearbox...
70 const string path = getenv(ENV_PATH);
71 std::vector<std::string> m_backends;
72 std::string m_filename = path + "/data/geometry/Belle2.xml";
73 m_backends.push_back("file:");
74 Gearbox& gearbox = Gearbox::getInstance();
75 gearbox.setBackends(m_backends);
76 gearbox.open(m_filename);
77
78 //...TRGCDC...
79 const string cname = path + "/data/trg/" + CONFIG;
80// TRGCDC * cdc = TRGCDC::getTRGCDC(cname, false, 100, 100);
81 TRGCDC* cdc = TRGCDC::getTRGCDC(cname);
82 const TRGClock& clock = cdc->systemClock();
83
84 //...Wire layer ID for the central wires...
85 unsigned LID[9] = {2, 10, 16, 22, 28, 34, 40, 46, 52};
86
87 //...Display...
88 D->clear();
89 D->show();
90#endif
91
92 //...Prepare buffers...
93 vector<int*> clks;
94 vector<TRGBitStream*> bits[9];
95 vector<const TCWire*> wires;
96
97 //...Read stream...
98 while (! infile.eof()) {
99
100 //...Read record type...
101 unsigned rec = 0;
102 infile.read((char*) & rec, 4);
103 unsigned siz = 0;
104 infile.read((char*) & siz, 4);
105
106 cout << "... " << hex << rec << "," << dec << siz << endl;
107
108 //...Record manipulation...
109 switch (rec) {
110
111 case TRGBSRecord_Comment: {
112 unsigned csiz = siz / 8;
113 if (siz % 8) ++csiz;
114 char* buf = new char[csiz + 1];
115 infile.read(buf, csiz);
116 buf[csiz] = 0;
117
118 cout << "siz,csiz=" << siz << "," << csiz << endl;
119
120 if (DEBUG_LEVEL)
121 cout << "Comment : " << buf << endl;
122 break;
123 }
124
125 case TRGBSRecord_BeginRun:
126 if (DEBUG_LEVEL)
127 cout << "BeginRun : " << siz << endl;
128 break;
129
130 case TRGBSRecord_EndRun:
131 if (DEBUG_LEVEL)
132 cout << "EndRun : " << siz << endl;
133 break;
134
135 case TRGBSRecord_BeginEvent:
136#ifdef TRGCDC_DISPLAY
137 D->clear();
138 D->beginningOfEvent();
139#endif
140 for (unsigned i = 0; i < 9; i++) {
141 for (unsigned j = 0; j < bits[i].size(); j++)
142 delete bits[i][j];
143 bits[i].clear();
144 }
145 for (unsigned i = 0; i < clks.size(); i++)
146 delete clks[i];
147 clks.clear();
148 wires.clear();
149 if (DEBUG_LEVEL)
150 cout << "BeginEvent : " << siz << endl;
151 break;
152
153 case TRGBSRecord_EndEvent:
154#ifdef TRGCDC_DISPLAY
155 for (unsigned i = 0; i < 9; i++) {
156 vector<TRGSignal> t = TRGBitStream::TRGBitStream2TRGSignal(
157 clock,
158 0,
159 bits[i]);
160 for (unsigned j = 0; j < t.size(); j++) {
161 if (t[j].active())
162 wires.push_back(cdc->wire(LID[i], j));
163 }
164 }
165 D->area().append(wires);
166 D->endOfEvent();
167 D->run();
168
169#endif
170 if (DEBUG_LEVEL)
171 cout << "EndEvent : " << siz << endl;
172 break;
173
174 case TRGBSRecord_Clock: {
175 unsigned clk = 0;
176 infile.read((char*) & clk, 4);
177 clks.push_back(new int(clk));
178 if (DEBUG_LEVEL)
179 cout << "Clock : " << clk << endl;
180 break;
181 }
182
183 case TRGBSRecord_SegmentSL0:
184 case TRGBSRecord_SegmentSL1:
185 case TRGBSRecord_SegmentSL2:
186 case TRGBSRecord_SegmentSL3:
187 case TRGBSRecord_SegmentSL4:
188 case TRGBSRecord_SegmentSL5:
189 case TRGBSRecord_SegmentSL6:
190 case TRGBSRecord_SegmentSL7:
191 case TRGBSRecord_SegmentSL8: {
192 unsigned superLayer = rec - TRGBSRecord_SegmentSL0;
193 unsigned csiz = siz / 8;
194 if (siz % 8) ++csiz;
195 char* buf = new char[csiz];
196 infile.read(buf, csiz);
197 TRGBitStream* bs = new TRGBitStream(buf, siz);
198 bits[superLayer].push_back(bs);
199 if (DEBUG_LEVEL)
200 bs->dump();
201 break;
202 }
203
204 default:
205 cout << PROGRAM_NAME << " !!! unknown record found : "
206 << "record type = " << hex << rec << endl;
207 break;
208 }
209 }
210 infile.close();
211
212 //...Termination...
213 cout << PROGRAM_NAME << " ... terminated" << endl;
214}
Singleton class responsible for loading detector parameters from an XML file.
Definition: Gearbox.h:34
A class to represent a bit stream.
Definition: BitStream.h:45
The instance of TRGCDC is a singleton.
Definition: TRGCDC.h:69
A class to represent a digitized signal. Unit is nano second.
Definition: Clock.h:38
static Gearbox & getInstance()
Return reference to the Gearbox instance.
Definition: Gearbox.cc:81
static TRGCDC * getTRGCDC(void)
returns TRGCDC object.
Definition: TRGCDC.cc:192
static std::vector< TRGSignal > TRGBitStream2TRGSignal(const TRGClock &clock, int initialClockPosition, std::vector< TRGBitStream * > stream)
Make trigger signals from bit stream.
Definition: BitStream.cc:127
Abstract base class for different kinds of events.
STL namespace.