/
Data.cpp
575 lines (498 loc) · 15.2 KB
/
Data.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
#include <QStringList>
#include <QFile>
#include <QTextStream>
#include <QDebug>
#include "Head9809.h"
#include "Data.h"
#include "ViewCtrl.h"
Data::Data( QWidget *p ) : QFrame( p )
{
setupUi( this );
u = new Units;
SettingL = 0;
SettingC = QColor( 0, 0, 0 );
FSDialog = new QFileDialog;
CSDialog = new QColorDialog;
QStringList filters;
filters << "*.dat" << "*.*" << "*";
FSDialog->setAcceptMode( QFileDialog::AcceptOpen );
FSDialog->setDirectory( QDir::currentPath() );
FSDialog->setNameFilters( filters );
theViewC = NULL;
theMCAView = NULL;
theTYView = NULL;
theXYView = NULL;
XYLine0 = XYLines = 0;
MCADataIsValid = false;
S2DI.valid = false;
DColors << DColor01 << DColor02 << DColor03 << DColor04 << DColor05
<< DColor06 << DColor07 << DColor08 << DColor09 << DColor10;
DColors << DColor11 << DColor12 << DColor13 << DColor14 << DColor15
<< DColor16 << DColor17 << DColor18 << DColor19 << DColor20;
DColors << DColor21 << DColor22 << DColor23 << DColor24 << DColor25
<< DColor26 << DColor27 << DColor28 << DColor29 << DColor30;
connect( FileSelect, SIGNAL( clicked() ), FSDialog, SLOT( show() ),
Qt::UniqueConnection );
connect( FSDialog, SIGNAL( fileSelected( const QString & ) ),
this, SLOT( ShowFName( const QString & ) ),
Qt::UniqueConnection );
connect( DataShow, SIGNAL( clicked() ), this, SLOT( StartToShowData() ),
Qt::UniqueConnection );
for ( int i = 0; i < DColors.count(); i++ ) {
connect( DColors.at(i), SIGNAL( clicked() ), this, SLOT( callCSDialog() ),
Qt::UniqueConnection );
}
connect( CSDialog, SIGNAL( colorSelected( const QColor & ) ),
this, SLOT( newColorSelected( const QColor & ) ),
Qt::UniqueConnection );
}
Data::~Data( void )
{
delete u;
delete FSDialog;
delete CSDialog;
}
void Data::setDataRoot( const QString &dataRoot )
{
FSDialog->setDirectory( dataRoot );
}
void Data::callCSDialog( void )
{
SettingL = 0;
for ( int i = 0; i < DColors.count(); i++ ) {
if ( DColors.at(i) == sender() ) {
SettingL = i;
break;
}
}
CSDialog->show();
}
void Data::newColorSelected( const QColor &c )
{
SettingC = c;
SetColor( SettingL, SettingC );
emit GiveMeCurrentView();
}
void Data::GotCurrentView( void *view )
{
if ( (XYView*)view == theXYView ) {
if ( SettingL < XYLines ) {
theXYView->SetColor( XYLine0 + SettingL, SettingC );
theXYView->update();
}
}
}
void Data::ShowFName( const QString &fname )
{
FName = fname;
QString dfname = fname;
SelectedFile->setText( dfname );
CheckFileType( fname );
emit AskToGetNewView( dataType, FSDialog->directory().absolutePath() );
}
void Data::StartToShowData( void )
{
emit AskToGetNewView( dataType, "" );
}
void Data::CheckFileType( const QString &fname )
{
QFile f( fname );
if ( !f.open( QIODevice::ReadOnly | QIODevice::Text ) ) {
DataType->setText( DataTypeNames[ dataType = NONDATA ] );
emit showMessage( tr( "Can not open the file %1." ).arg( fname ), 2000 );
return;
}
QTextStream in( &f );
if ( in.atEnd() ) {
f.close();
DataType->setText( DataTypeNames[ dataType = NONDATA ] );
emit showMessage( tr( "The file %1 is empty." ).arg( fname ), 2000 );
return;
}
QString aline = in.readLine();
f.close();
if ( aline.left( FileIDs[ MEASDATA ].length() ) == FileIDs[ MEASDATA ] ) {
DataType->setText( DataTypeNames[ dataType = MEASSHOW ] );
} else if ( aline.left( FileIDs[ SCANDATA ].length() ) == FileIDs[ SCANDATA ] ) {
DataType->setText( DataTypeNames[ dataType = SCANSHOW ] );
} else if ( aline.left( FileIDs[ MONDATA ].length() ) == FileIDs[ MONDATA ] ) {
DataType->setText( DataTypeNames[ dataType = MONSHOW ] );
} else if ( aline.left( FileIDs[ MCADATA ].length() ) == FileIDs[ MCADATA ] ) {
DataType->setText( DataTypeNames[ dataType = MCASHOW ] );
} else if ( aline.left( FileIDs[ S2DDATA ].length() ) == FileIDs[ S2DDATA ] ) {
DataType->setText( DataTypeNames[ dataType = S2DSHOW ] );
} else {
DataType->setText( DataTypeNames[ dataType = NONDATA ] );
emit showMessage( tr( "The file %1 is not avaliable to show." ).arg( fname ), 2000 );
}
}
void Data::GotNewView( ViewCTRL *viewC,
QVector<AMotor*> &AMotors, QVector<ASensor*> &ASensors )
{
QFile f( FName );
if ( !f.open( QIODevice::ReadOnly | QIODevice::Text ) ) {
DataType->setText( DataTypeNames[ dataType = NONDATA ] );
emit showMessage( tr( "Can not open the file %1." ).arg( FName ), 2000 );
return;
}
theViewC = viewC;
QTextStream in( &f );
switch( dataType ) {
#if 0
case MEASSHOW: showMeasData( in ); break;
#endif
case MONSHOW: showMonData( in, ASensors ); break;
case SCANSHOW: showScanData( in, AMotors, ASensors ); break;
case MCASHOW: showMCAData( in ); break;
case S2DSHOW: showS2DData( in, AMotors, ASensors ); break;
default: break;
}
f.close();
}
void Data::SetColor( int i, const QColor &c )
{
DColors.at(i)->setStyleSheet( "background-color: " + c.name() );
}
#if 0
void Data::showMeasData( QTextStream &in )
{
QString HeaderEnd = " Offset";
QString line;
QStringList vals;
theXYView = (XYView*)(theViewC->getView());
// なんか怪しげ showMeasData を復活させるなら要再検討
if ( theViewC->getDType() == NONDATA ) {
theViewC->setNowDType( MEASSHOW );
theViewC->setNowVType( XYVIEW );
theXYView->SetWindow0( 1e300, 0, -1e300, 0 );
theXYView->SetLeftName( "mu(E)" );
theXYView->SetRightName( "I0" );
}
int L0 = theXYView->GetLines(); // ここで描画をはじめる前にすでに描画されている線の数
Head9809 head;
if ( ! head.readFromStream( in ) ) {
qDebug() << "Incomplete file as 9809 format";
return;
}
// int TrMode = head.getMode();
// 混在測定を許すのでファイル全体モードは
// あまり意味がない。
// 最初の x(to go), x(enc), dwell は抜いたデータのモードだけ返って来る。
QStringList ChModes0 = head.getChModes();
int cols = ChModes0.count();
bool aFluo = false;
QVector<int> ChModes; // 返ってきたモードを数字に直しておく
for ( int i = 0; i < ChModes0.count(); i++ ) {
ChModes << ChModes0[i].toInt();
}
int I0col = -1, I1col = -1;
for ( int i = 0; i < cols; i++ ) {
if ( ChModes[i] == I0 ) { // 先に I0 を探さないと計算できない
I0col = i + 3;
}
if ( ChModes[i] == TRANS ) { // 一時期のバグで I0の mode 番号として 1 でなく、
// 2 (本来は I1) を書いてしまってるファイルがあるので
// I0 が見つからなくて I1 があるときは I1 を I0 と
// みなす。
I1col = i + 3;
}
if ( ChModes[i] == FLUO ) { // 蛍光モードが少なくとも一チャンネルある
aFluo = true;
}
}
if ( I0col == -1 ) { // I0 が見つからなければ表示できない
if ( I1col == -1 ) {
qDebug() << "No I0 data is found.";
return;
} else {
I0col = I1col;
}
}
bool dispf;
double x, y, I00, I, totalf;
while ( ! in.atEnd() ) {
totalf = 0;
line = in.readLine().simplified();
vals = line.split( QRegExp( "\\s" ) );
x = u->deg2keV( vals[0].toDouble() );
I00 = vals.at( I0col ).toDouble();
for ( int i = 0; i < cols; i++ ) {
dispf = true;
I = vals.at( i + 3 ).toDouble();
switch( ChModes[i] ) {
case I0: y = I; break;
case TRANS: y = ( I != 0 ) ? log( fabs( I00 / I ) ) : 1; break;
case FLUO: y = ( I00 != 0 ) ? I / I00 : 1; totalf += y; break;
default: dispf = false; break;
}
if ( dispf ) {
theXYView->NewPoint( L0+i, x, y );
}
}
if ( aFluo ) {
theXYView->NewPoint( L0+cols, x, totalf );
}
}
int L = theXYView->GetLines(); // ここで描画した線もいれた線の数
for ( int i = L0; i < L; i++ ) {
SetColor( i - L0, theXYView->GetColor( i ) );
theXYView->SetLR( i, LEFT_AX ); // 一旦全部は左軸
theXYView->SetScaleType( i, FULLSCALE );
}
theXYView->SetLR( L0, RIGHT_AX ); // 最初の一本だけ右軸 (I0)
theXYView->SetScaleType( L0, I0TYPE );
theXYView->SetLLine( L0+1 ); // デフォルトで情報表示される左軸の線はデータの1番め
theXYView->SetRLine( L0 ); // デフォルトで情報表示される右軸の線はデータの0番め (I0)
XYLine0 = L0; // このクラスで管理する線の番号の最初と、
XYLines = L - L0 + 1; // その本数
theXYView->update();
}
#endif
void Data::showScanData( QTextStream &in,
QVector<AMotor*> &AMotors, QVector<ASensor*> &ASensors )
{
QStringList heads, vals;
QString line;
theXYView = (XYView*)theViewC->getView();
theXYView->SetWindow0( 1e300, 0, -1e300, 0 );
theXYView->SetAutoScale( true );
int L0 = theXYView->GetLines();
ScanInfo si = theXYView->getSInfo();
si.load( in, AMotors, ASensors );
si.show();
theXYView->SetLineName( L0, si.asName );
theXYView->SetLR( L0, RIGHT_AX ); theXYView->SetScaleType( 0, FULLSCALE );
theXYView->SetLineName( L0+1, si.as0Name );
theXYView->SetLR( L0+1, LEFT_AX ); theXYView->SetScaleType( 1, FULLSCALE );
theXYView->SetXName( si.amName );
theXYView->SetXUnitName( si.unitName );
theXYView->SetUpp( si.upp );
theXYView->SetCenter( si.origin );
int lines = 2 + si.mi.Sensors.count();
while ( ! in.atEnd() ) {
line = in.readLine();
line = line.simplified();
if ( line.count() < 2 ) continue;
if ( line[0] == '#' ) continue;
vals = line.split( QRegExp( "\\s" ) );
for ( int i = 0; i < lines; i++ ) {
if ( vals.count() > i + 1 ) {
theXYView->NewPoint( i, vals[0].toDouble(), vals[i+1].toDouble() );
}
}
}
int L = theXYView->GetLines();
for ( int i = L0; i < L; i++ ) {
SetColor( i - L0, theXYView->GetColor( i ) );
}
theXYView->SetLLine( L0+1 ); // デフォルトで情報表示される左軸の線はデータの1番め
theXYView->SetRLine( L0 ); // デフォルトで情報表示される右軸の線はデータの0番め (I0)
XYLine0 = L0;
XYLines = 2;
theXYView->makeValid( true );
theXYView->update();
}
void Data::showMonData( QTextStream &in, QVector<ASensor*> &ASensors )
{
QStringList heads, vals;
QString line;
double Values[ MaxMon ];
theTYView = (TYView*)theViewC->getView();
#if 0
if ( theViewC->getNowDType() == NONDATA ) {
theViewC->setNowDType( MONSHOW );
theViewC->setNowVType( TYVIEW );
}
#endif
theTYView->SetMonScale( 0 );
theTYView->makeValid( true );
MonInfo monInfo;
monInfo.load( in, ASensors );
monInfo.show();
#if 0
if ( ! in.atEnd() ) line = in.readLine();
if ( ! in.atEnd() ) line = in.readLine(); // 2行空読
if ( ! in.atEnd() ) line = in.readLine();
heads = line.split( '\t' );
for ( int i = 2; i < heads.count(); i++ ) {
theTYView->SetLName( i-2, heads.at( i ) );
}
#endif
int Lines = monInfo.SensorNames.count();
for ( int i = 0; i < Lines; i++ ) {
theTYView->SetLName( i, monInfo.SensorNames[i] );
}
// theTYView->SetXName( heads.at( 1 ) );
theTYView->ClearDataR();
theTYView->SetLines( Lines );
for ( int i = 0; i < MaxMon; i++ )
Values[i] = 0;
while ( ! in.atEnd() ) {
line = in.readLine();
line = line.simplified();
vals = line.split( QRegExp( "\\s" ) );
int Vals = vals.count();
int i;
for ( i = 0; i < Vals; i++ ) {
if ( vals[i][0] == QChar( '#' ) ) break;
}
if ( i < Vals )
Vals = i;
for ( int i = 1; i < Vals; i++ ) {
Values[i-1] = vals.at( i ).toDouble();
}
theTYView->NewPointR( vals.at(0).toDouble()*1000, Values, Vals - 1 );
}
int L = theTYView->GetLines();
for ( int i = 0; i < L; i++ ) {
SetColor( i, theTYView->getColor( i ) );
}
theTYView->update();
}
void Data::showMCAData( QTextStream &in )
{
// MCALength = 2048;
QStringList vals;
theMCAView = (MCAView*)theViewC->getView();
KeV2Pix *k2p = theMCAView->keV2Pix();
cMCACh = 0;
#if 0
if ( theViewC->getNowDType() == NONDATA ) {
theViewC->setNowDType( MCASHOW );
theViewC->setNowVType( MCAVIEW );
}
#endif
theMCAView->makeValid( true );
MCADataIsValid = false;
// getNewMCAs( MCALength );
// aMCA.setSize( MCALength, MaxSSDs );
aMCA.load( in, "" );
cMCA = theMCAView->setMCAdataPointer( aMCA.length() );
#if 0
while ( ! in.atEnd() ) {
vals = in.readLine().simplified().split( QRegExp( "\\s" ) );
if ( vals[0][0] != '#' ) {
int i = vals[0].toInt();
for ( int ch = 0; ch < MaxSSDs; ch++ ) {
double E = vals[ ch * 2 + 1 ].toDouble();
int count = vals[ ch * 2 + 2 ].toInt();
MCAEs[ch][i] = E; // これは測定時にそのピクセルに対応していたエネルギー
MCAs0[ch][i] = count;
}
}
}
#endif
if ( ! aMCA.isValid() )
return;
aMCA.correctE( k2p );
#if 0
// 測定時のエネルギーとピクセルの関係は、
// 今のエネルギーとピクセルの関係とは違っている可能性があるので
// 今のピクセルに対応するエネルギーでのカウント数を線形補完で求めておく
for ( int i = 0; i < MCALength; i++ ) {
for ( int ch = 0; ch < MaxSSDs; ch++ ) {
double nowE = k2p->p2E( ch, i );
int j;
for ( j = 1; j < MCALength - 1; j++ ) {
if ( nowE < MCAEs[ch][j] ) {
break;
}
}
MCAs[ch][i] = (int)(( nowE - MCAEs[ch][j-1] ) / ( MCAEs[ch][j] - MCAEs[ch][j-1] )
* ( (int)MCAs0[ch][j] - (int)MCAs0[ch][j-1] )
+ MCAs0[ch][j-1] );
}
}
#endif
aMCA.copyCnt( cMCACh, cMCA );
#if 0
for ( int i = 0; i < MCALength; i++ ) {
cMCA[i] = MCAs[cMCACh][i];
}
#endif
emit setMCACh( cMCACh );
theMCAView->SetMCACh( cMCACh );
MCADataIsValid = true;
theMCAView->update();
}
#if 0
void Data::getNewMCAs( int MCALength )
{
while( MCAs.count() > 0 ) {
delete [] MCAs[0];
MCAs.remove( 0 );
}
for ( int i = 0; i < MaxSSDs; i++ ) {
quint32 *amca = new quint32 [ MCALength ];
MCAs << amca;
}
while( MCAs0.count() > 0 ) {
delete [] MCAs0[0];
MCAs0.remove( 0 );
}
for ( int i = 0; i < MaxSSDs; i++ ) {
quint32 *amca = new quint32 [ MCALength ];
MCAs0 << amca;
}
while( MCAEs.count() > 0 ) {
delete [] MCAEs[0];
MCAEs.remove( 0 );
}
for ( int i = 0; i < MaxSSDs; i++ ) {
double *amcaE = new double [ MCALength ];
MCAEs << amcaE;
}
}
#endif
void Data::SelectedNewMCACh( int ch )
{
if ( ! MCADataIsValid ) return;
cMCACh = ch;
aMCA.copyCnt( cMCACh, cMCA );
#if 0
for ( int i = 0; i < MCALength; i++ ) {
cMCA[i] = MCAs[ cMCACh ][i];
}
#endif
theMCAView->SetMCACh( cMCACh );
theMCAView->update();
}
void Data::showS2DData( QTextStream &in,
QVector<AMotor*> &AMotors, QVector<ASensor*> & /* ASensors */ )
{
QStringList HeadLine1, HeadLine2, vals;
QString line;
theS2DB = (S2DB*)(theViewC->getView());
theS2DB = (S2DB*)(theViewC->getView());
theS2DB->setLoadBHidden( false );
theS2DView = (S2DView*)(theS2DB->getView());
#if 0
if ( theViewC->getNowDType() == NONDATA ) {
theViewC->setNowDType( S2DSHOW );
theViewC->setNowVType( S2DVIEW );
// theS2DView->SetWindow0( 1e300, 0, -1e300, 0 );
}
#endif
theS2DView->setRatioType( AS_SCREEN );
S2DInfo s2di;
s2di.load( in, AMotors );
theS2DB->setS2DI( s2di );
theS2DView->setRange( s2di.sx[0], s2di.sx[1] - s2di.dx[1] / 2,
s2di.dx[0], s2di.dx[1],
s2di.ps[0], s2di.ps[1] + 1 );
int ix = 0, iy = 0;
while ( ! in.atEnd() ) {
vals = in.readLine().simplified().split( QRegExp( "\\s+" ) );
if ( vals.count() > 0 ) {
if ( vals[0][0] != '#' ) {
if ( vals.count() >= 3 ) {
theS2DView->setData( ix, iy, vals[2].toDouble() );
ix++;
} else {
ix = 0;
iy++;
}
}
}
}
}