14 #define TRG_SHORT_NAMES
15 #define TRGCDC_SHORT_NAMES
20 #include "trg/trg/BitStream.h"
21 #include "trg/cdc/Wire.h"
23 #include "framework/gearbox/Gearbox.h"
24 #include "trg/cdc/DisplayRphi.h"
25 #include "trg/cdc/DisplayHough.h"
26 namespace Belle2_TRGCDC {
27 Belle2::TRGCDCDisplayRphi* D = 0;
34 using namespace Belle2_TRGCDC;
38 #define PROGRAM_NAME "TRGCDCTSStreamReader"
39 #define PROGRAM_VERSION "version 0.03"
40 #define ENV_PATH "BELLE2_LOCAL_DIR"
41 #define CONFIG "TRGCDCWireConfig_0_20101110_0836.dat"
44 main(
int argc,
char* argv[])
47 cout << PROGRAM_NAME <<
" ... " << PROGRAM_VERSION << endl;
48 const string tab =
" ";
52 cout << PROGRAM_NAME <<
" !!! one argument necessary" << endl
53 << tab <<
" 1 : Track Segment Stream data file" << endl;
58 const string inname = argv[1];
59 cout << tab <<
"Track Segment Stream : " << inname << endl;
62 ifstream infile(inname.c_str(), ios::in | ios::binary);
64 cout << PROGRAM_NAME <<
" !!! can not open file" << endl
65 <<
" " << inname << endl;
71 const string path = getenv(ENV_PATH);
72 std::vector<std::string> m_backends;
73 std::string m_filename = path +
"/data/geometry/Belle2.xml";
74 m_backends.push_back(
"file:");
75 Gearbox& gearbox = Gearbox::getInstance();
76 gearbox.setBackends(m_backends);
77 gearbox.open(m_filename);
80 const string cname = path +
"/data/trg/" + CONFIG;
82 TRGCDC* cdc = TRGCDC::getTRGCDC(cname);
83 const TRGClock& clock = cdc->systemClock();
86 unsigned LID[9] = {2, 10, 16, 22, 28, 34, 40, 46, 52};
95 vector<TRGBitStream*> bits[9];
96 vector<const TCWire*> wires;
99 while (! infile.eof()) {
103 infile.read((
char*) & rec, 4);
105 infile.read((
char*) & siz, 4);
107 cout <<
"... " << hex << rec <<
"," << dec << siz << endl;
112 case TRGBSRecord_Comment: {
113 unsigned csiz = siz / 8;
115 char* buf =
new char[csiz + 1];
116 infile.read(buf, csiz);
119 cout <<
"siz,csiz=" << siz <<
"," << csiz << endl;
122 cout <<
"Comment : " << buf << endl;
126 case TRGBSRecord_BeginRun:
128 cout <<
"BeginRun : " << siz << endl;
131 case TRGBSRecord_EndRun:
133 cout <<
"EndRun : " << siz << endl;
136 case TRGBSRecord_BeginEvent:
137 #ifdef TRGCDC_DISPLAY
139 D->beginningOfEvent();
141 for (
unsigned i = 0; i < 9; i++) {
142 for (
unsigned j = 0; j < bits[i].size(); j++)
146 for (
unsigned i = 0; i < clks.size(); i++)
151 cout <<
"BeginEvent : " << siz << endl;
154 case TRGBSRecord_EndEvent:
155 #ifdef TRGCDC_DISPLAY
156 for (
unsigned i = 0; i < 9; i++) {
157 vector<TRGSignal> t = TRGBitStream::TRGBitStream2TRGSignal(
161 for (
unsigned j = 0; j < t.size(); j++) {
163 wires.push_back(cdc->wire(LID[i], j));
166 D->area().append(wires);
172 cout <<
"EndEvent : " << siz << endl;
175 case TRGBSRecord_Clock: {
177 infile.read((
char*) & clk, 4);
178 clks.push_back(
new int(clk));
180 cout <<
"Clock : " << clk << endl;
184 case TRGBSRecord_SegmentSL0:
185 case TRGBSRecord_SegmentSL1:
186 case TRGBSRecord_SegmentSL2:
187 case TRGBSRecord_SegmentSL3:
188 case TRGBSRecord_SegmentSL4:
189 case TRGBSRecord_SegmentSL5:
190 case TRGBSRecord_SegmentSL6:
191 case TRGBSRecord_SegmentSL7:
192 case TRGBSRecord_SegmentSL8: {
193 unsigned superLayer = rec - TRGBSRecord_SegmentSL0;
194 unsigned csiz = siz / 8;
196 char* buf =
new char[csiz];
197 infile.read(buf, csiz);
199 bits[superLayer].push_back(bs);
206 cout << PROGRAM_NAME <<
" !!! unknown record found : "
207 <<
"record type = " << hex << rec << endl;
214 cout << PROGRAM_NAME <<
" ... terminated" << endl;