MiniballSort
Loading...
Searching...
No Matches
MiniballGUI.cc
Go to the documentation of this file.
1// Very basic ROOT GUI to perform sorting of Miniball data
2//
3// Liam Gaffney (liam.gaffney@liverpool.ac.uk) - 21/01/2022
4
5#include "MiniballGUI.hh"
6
9
11
12 //-------------------//
13 // Create main frame //
14 //-------------------//
15 main_frame = new TGMainFrame( gClient->GetRoot(), 1000, 300, kMainFrame | kHorizontalFrame );
16
17 // terminate ROOT session when window is closed
18 main_frame->Connect( "CloseWindow()", "TApplication", gApplication, "Terminate()" );
19 main_frame->DontCallClose();
20
21
22 //----------------------------------//
23 // Create sub frames and separators //
24 //----------------------------------//
25
26 // Left frame - for file list
27 left_frame = new TGVerticalFrame( main_frame, 150, 300 );
28 left_frame->SetName( "left_frame" );
29 main_frame->AddFrame( left_frame, new TGLayoutHints( kLHintsLeft ) );
30
31 // File button box
32 fbut_frame = new TGHorizontalFrame( left_frame, 150, 20 );
33 fbut_frame->SetName( "fbut_frame" );
34 left_frame->AddFrame( fbut_frame, new TGLayoutHints( kLHintsBottom | kLHintsExpandX ) );
35
36 // Vertical separator
37 fVertical_0 = new TGVertical3DLine( main_frame, 8, 300 );
38 fVertical_0->SetName( "fVertical_0" );
39 main_frame->AddFrame( fVertical_0, new TGLayoutHints( kLHintsLeft | kLHintsTop, 2, 2, 2, 2 ) );
40
41 // Centre frame - Files, directories, buttons, etc
42 centre_frame = new TGVerticalFrame( main_frame, 600, 300 );
43 centre_frame->SetName( "centre_frame" );
44 main_frame->AddFrame( centre_frame, new TGLayoutHints( kLHintsCenterX ) );
45
46 centre_files = new TGHorizontalFrame( centre_frame, 600, 300 );
47 centre_files->SetName( "centre_files" );
48 centre_frame->AddFrame( centre_files, new TGLayoutHints( kLHintsCenterX ) );
49
50 centre_progress = new TGVerticalFrame( centre_frame, 600, 300 );
51 centre_progress->SetName( "centre_progress" );
52 centre_frame->AddFrame( centre_progress, new TGLayoutHints( kLHintsCenterX ) );
53
54 fHorizontal_0 = new TGHorizontal3DLine( centre_frame, 600, 8 );
55 fHorizontal_0->SetName( "fHorizontal_0" );
56 centre_frame->AddFrame( fHorizontal_0, new TGLayoutHints( kLHintsLeft | kLHintsTop, 2, 2, 2, 2 ) );
57
58 centre_progress = new TGVerticalFrame( centre_frame, 600, 300 );
59 centre_progress->SetName( "centre_progress" );
60 centre_frame->AddFrame( centre_progress, new TGLayoutHints( kLHintsCenterX ) );
61
62 centre_go = new TGHorizontalFrame( centre_frame, 600, 300 );
63 centre_go->SetName( "centre_go" );
64 centre_frame->AddFrame( centre_go, new TGLayoutHints( kLHintsCenterX ) );
65
66 centre_label = new TGVerticalFrame( centre_files, 180, 300 );
67 centre_label->SetName( "centre_label" );
68 centre_files->AddFrame( centre_label, new TGLayoutHints( kLHintsCenterX ) );
69
70 centre_text = new TGVerticalFrame( centre_files, 500, 300 );
71 centre_text->SetName( "centre_text" );
72 centre_files->AddFrame( centre_text, new TGLayoutHints( kLHintsCenterX ) );
73
74 centre_button = new TGVerticalFrame( centre_files, 10, 300 );
75 centre_button->SetName( "centre_button" );
76 centre_files->AddFrame( centre_button, new TGLayoutHints( kLHintsCenterX ) );
77
78
79 //-------------------------//
80 // Open/Save config button //
81 //-------------------------//
82
83 // Setup file open
84 but_open = new TGTextButton( left_frame, "Open setup", -1, TGTextButton::GetDefaultGC()(),
85 TGTextButton::GetDefaultFontStruct(), kRaisedFrame );
86 but_open->SetTextJustify( 36 );
87 but_open->SetMargins( 0, 0, 0, 0 );
88 but_open->SetWrapLength( -1 );
89 but_open->Resize( 25, 30 );
90 left_frame->AddFrame( but_open, new TGLayoutHints( kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2 ) );
91
92 // Setup file save
93 but_save = new TGTextButton( left_frame, "Save setup", -1, TGTextButton::GetDefaultGC()(),
94 TGTextButton::GetDefaultFontStruct(), kRaisedFrame );
95 but_save->SetTextJustify( 36 );
96 but_save->SetMargins( 0, 0, 0, 0 );
97 but_save->SetWrapLength( -1 );
98 but_save->Resize( 25, 30 );
99 left_frame->AddFrame( but_save, new TGLayoutHints( kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2 ) );
100
101
102 //---------------//
103 // Create labels //
104 //---------------//
105
106 // Run files
107 lab_run_files = new TGLabel( left_frame, "List of file names" );
108 lab_run_files->SetTextJustify( 36 );
109 lab_run_files->SetMargins( 0, 0, 0, 0 );
110 lab_run_files->SetWrapLength( -1 );
111 lab_run_files->Resize( 80, lab_run_files->GetDefaultHeight() );
112 main_frame->AddFrame( lab_run_files,
113 new TGLayoutHints( kLHintsCenterX | kLHintsTop, 2, 2, 2, 2 ) );
114
115 // Settings file
116 lab_set_file = new TGLabel( centre_label, "Settings file" );
117 lab_set_file->SetTextJustify( 36 );
118 lab_set_file->SetMargins( 0, 0, 0, 0 );
119 lab_set_file->SetWrapLength( -1 );
120 lab_set_file->Resize( 80, lab_set_file->GetDefaultHeight() );
121 centre_label->AddFrame( lab_set_file,
122 new TGLayoutHints( kLHintsCenterX | kLHintsTop, 2, 2, 5, 5 ) );
123
124 // Calibration file
125 lab_cal_file = new TGLabel( centre_label, "Calibration file" );
126 lab_cal_file->SetTextJustify( 36 );
127 lab_cal_file->SetMargins( 0, 0, 0, 0 );
128 lab_cal_file->SetWrapLength( -1 );
129 lab_cal_file->Resize( 80, lab_cal_file->GetDefaultHeight() );
130 centre_label->AddFrame( lab_cal_file,
131 new TGLayoutHints( kLHintsCenterX | kLHintsTop, 2, 2, 5, 5 ) );
132
133 // Reaction file
134 lab_rea_file = new TGLabel( centre_label, "Reaction file" );
135 lab_rea_file->SetTextJustify( 36 );
136 lab_rea_file->SetMargins( 0, 0, 0, 0 );
137 lab_rea_file->SetWrapLength( -1 );
138 lab_rea_file->Resize( 80, lab_rea_file->GetDefaultHeight() );
139 centre_label->AddFrame( lab_rea_file,
140 new TGLayoutHints( kLHintsCenterX | kLHintsTop, 2, 2, 5, 5 ) );
141
142 // Output directory
143 lab_out_dir = new TGLabel( centre_label, "Output directory" );
144 lab_out_dir->SetTextJustify( 36 );
145 lab_out_dir->SetMargins( 0, 0, 0, 0 );
146 lab_out_dir->SetWrapLength( -1 );
147 lab_out_dir->Resize( 80, lab_out_dir->GetDefaultHeight() );
148 centre_label->AddFrame( lab_out_dir,
149 new TGLayoutHints( kLHintsCenterX | kLHintsTop, 2, 2, 5, 5 ) );
150
151 // Output file
152 lab_out_file = new TGLabel( centre_label, "Histogram file" );
153 lab_out_file->SetTextJustify( 36 );
154 lab_out_file->SetMargins( 0, 0, 0, 0 );
155 lab_out_file->SetWrapLength( -1 );
156 lab_out_file->Resize( 80, lab_out_file->GetDefaultHeight() );
157 centre_label->AddFrame( lab_out_file,
158 new TGLayoutHints( kLHintsCenterX | kLHintsTop, 2, 2, 5, 5 ) );
159
160
161 //-----------------//
162 // Create list box //
163 //-----------------//
164
165 // Run files
166 run_list_box = new TGListBox( left_frame, -1, kSunkenFrame );
167 run_list_box->SetName( "run_list_box" );
168 run_list_box->Resize( 300, 256 );
169 left_frame->AddFrame( run_list_box, new TGLayoutHints( kLHintsLeft | kLHintsTop | kLHintsExpandY, 2, 2, 2, 2 ) );
170
171 run_selected = new TList;
172 run_list_box->SetMultipleSelections( true );
173
174 //---------------------//
175 // Create text entries //
176 //---------------------//
177
178 // Add file
179 text_add_file = new TGTextEntry( left_frame );
180 text_add_file->SetMaxLength( 4096 );
181 text_add_file->SetAlignment( kTextLeft );
182 text_add_file->Resize( 300, text_add_file->GetDefaultHeight() );
183 left_frame->AddFrame( text_add_file, new TGLayoutHints( kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2 ) );
184
185 // Settings file
186 text_set_file = new TGTextEntry( centre_text );
187 text_set_file->SetMaxLength( 4096 );
188 text_set_file->SetAlignment( kTextLeft );
189 text_set_file->Resize( 400, text_set_file->GetDefaultHeight() );
190 centre_text->AddFrame( text_set_file, new TGLayoutHints( kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2 ) );
191
192 // Calibration file
193 text_cal_file = new TGTextEntry( centre_text );
194 text_cal_file->SetMaxLength( 4096 );
195 text_cal_file->SetAlignment( kTextLeft );
196 text_cal_file->Resize( 400, text_cal_file->GetDefaultHeight() );
197 centre_text->AddFrame( text_cal_file, new TGLayoutHints( kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2 ) );
198
199 // Reaction file
200 text_rea_file = new TGTextEntry( centre_text );
201 text_rea_file->SetMaxLength( 4096 );
202 text_rea_file->SetAlignment( kTextLeft );
203 text_rea_file->Resize( 400, text_rea_file->GetDefaultHeight() );
204 centre_text->AddFrame( text_rea_file, new TGLayoutHints( kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2 ) );
205
206 // Output directory
207 text_out_dir = new TGTextEntry( centre_text, "./sorted" );
208 text_out_dir->SetMaxLength( 4096 );
209 text_out_dir->SetAlignment( kTextLeft );
210 text_out_dir->Resize( 400, text_out_dir->GetDefaultHeight() );
211 centre_text->AddFrame( text_out_dir, new TGLayoutHints( kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2 ) );
212
213 // Output file
214 text_out_file = new TGTextEntry( centre_text );
215 text_out_file->SetMaxLength( 4096 );
216 text_out_file->SetAlignment( kTextLeft );
217 text_out_file->Resize( 400, text_out_file->GetDefaultHeight() );
218 centre_text->AddFrame( text_out_file, new TGLayoutHints( kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2 ) );
219
220 //----------------------//
221 // Create check buttons //
222 //----------------------//
223
224 check_mbs = new TGCheckButton( centre_go, "MBS data" );
225 centre_go->AddFrame( check_mbs, new TGLayoutHints( kLHintsLeft, 2, 2, 2, 2 ) );
226
227 check_source = new TGCheckButton( centre_go, "Source data" );
228 centre_go->AddFrame( check_source, new TGLayoutHints( kLHintsLeft, 2, 2, 2, 2 ) );
229
230 check_force = new TGCheckButton( centre_go, "Force convert" );
231 centre_go->AddFrame( check_force, new TGLayoutHints( kLHintsLeft, 2, 2, 2, 2 ) );
232
233 check_event = new TGCheckButton( centre_go, "Rebuild events" );
234 centre_go->AddFrame( check_event, new TGLayoutHints( kLHintsLeft, 2, 2, 2, 2 ) );
235
236 check_ebis = new TGCheckButton( centre_go, "EBIS only" );
237 centre_go->AddFrame( check_ebis, new TGLayoutHints( kLHintsLeft, 2, 2, 2, 2 ) );
238
239
240 //-----------------------//
241 // Create action buttons //
242 //-----------------------//
243
244 // Select files
245 but_sel = new TGTextButton( fbut_frame, "Select", -1, TGTextButton::GetDefaultGC()(),
246 TGTextButton::GetDefaultFontStruct(), kRaisedFrame );
247 but_sel->SetTextJustify( 36 );
248 but_sel->SetMargins( 0, 0, 0, 0 );
249 but_sel->SetWrapLength( -1 );
250 but_sel->Resize( 65, 46 );
251 fbut_frame->AddFrame( but_sel, new TGLayoutHints( kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2 ) );
252
253 // Add files
254 but_add = new TGTextButton( fbut_frame, "Add", -1, TGTextButton::GetDefaultGC()(),
255 TGTextButton::GetDefaultFontStruct(), kRaisedFrame );
256 but_add->SetTextJustify( 36 );
257 but_add->SetMargins( 0, 0, 0, 0 );
258 but_add->SetWrapLength( -1 );
259 but_add->Resize( 65, 46 );
260 fbut_frame->AddFrame( but_add, new TGLayoutHints( kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2 ) );
261
262 // Remove files
263 but_del = new TGTextButton( fbut_frame, "Remove", -1, TGTextButton::GetDefaultGC()(),
264 TGTextButton::GetDefaultFontStruct(), kRaisedFrame );
265 but_del->SetTextJustify( 36 );
266 but_del->SetMargins( 0, 0, 0, 0 );
267 but_del->SetWrapLength( -1 );
268 but_del->Resize( 65, 46 );
269 fbut_frame->AddFrame( but_del, new TGLayoutHints( kLHintsRight | kLHintsExpandX, 2, 2, 2, 2 ) );
270
271 // Settings file
272 but_set = new TGTextButton( centre_button, "Open", -1, TGTextButton::GetDefaultGC()(),
273 TGTextButton::GetDefaultFontStruct(), kRaisedFrame );
274 but_set->SetTextJustify( 36 );
275 but_set->SetMargins( 0, 0, 0, 0 );
276 but_set->SetWrapLength( -1 );
277 but_set->Resize( 65, 46 );
278 centre_button->AddFrame( but_set, new TGLayoutHints( kLHintsRight | kLHintsExpandX, 2, 2, 7, 2 ) );
279
280 // Calibration file
281 but_cal = new TGTextButton( centre_button, "Open", -1, TGTextButton::GetDefaultGC()(),
282 TGTextButton::GetDefaultFontStruct(), kRaisedFrame );
283 but_cal->SetTextJustify( 36 );
284 but_cal->SetMargins( 0, 0, 0, 0 );
285 but_cal->SetWrapLength( -1 );
286 but_cal->Resize( 65, 46 );
287 centre_button->AddFrame( but_cal, new TGLayoutHints( kLHintsRight | kLHintsExpandX, 2, 2, 2, 2 ) );
288
289 // Reaction file
290 but_rea = new TGTextButton( centre_button, "Open", -1, TGTextButton::GetDefaultGC()(),
291 TGTextButton::GetDefaultFontStruct(), kRaisedFrame );
292 but_rea->SetTextJustify( 36 );
293 but_rea->SetMargins( 0, 0, 0, 0 );
294 but_rea->SetWrapLength( -1 );
295 but_rea->Resize( 65, 46 );
296 centre_button->AddFrame( but_rea, new TGLayoutHints( kLHintsRight | kLHintsExpandX, 2, 2, 2, 2 ) );
297
298 // Output directory
299 but_dir = new TGTextButton( centre_button, "Select", -1, TGTextButton::GetDefaultGC()(),
300 TGTextButton::GetDefaultFontStruct(), kRaisedFrame );
301 but_dir->SetTextJustify( 36 );
302 but_dir->SetMargins( 0, 0, 0, 0 );
303 but_dir->SetWrapLength( -1 );
304 but_dir->Resize( 65, 46 );
305 centre_button->AddFrame( but_dir, new TGLayoutHints( kLHintsRight | kLHintsExpandX, 2, 2, 2, 2 ) );
306
307 // Output file
308 but_out = new TGTextButton( centre_button, "Open", -1, TGTextButton::GetDefaultGC()(),
309 TGTextButton::GetDefaultFontStruct(), kRaisedFrame );
310 but_out->SetTextJustify( 36 );
311 but_out->SetMargins( 0, 0, 0, 0 );
312 but_out->SetWrapLength( -1 );
313 but_out->Resize( 65, 46 );
314 centre_button->AddFrame( but_out, new TGLayoutHints( kLHintsRight | kLHintsExpandX, 2, 2, 2, 2 ) );
315
316 // Go sorting
317 but_sort = new TGTextButton( centre_go, "GO!", -1, TGTextButton::GetDefaultGC()(),
318 TGTextButton::GetDefaultFontStruct(), kDoubleBorder );
319 but_sort->SetTextJustify( 36 );
320 but_sort->SetMargins( 0, 0, 0, 0 );
321 but_sort->SetWrapLength( -1 );
322 but_sort->Resize( 65, 46 );
323 but_sort->SetTextColor( TColor::Number2Pixel( kWhite ) );
324 but_sort->SetBackgroundColor( TColor::Number2Pixel( kGreen+1 ) );
325 centre_go->AddFrame( but_sort, new TGLayoutHints( kLHintsRight | kLHintsExpandX ) );
326
327
328 //---------------//
329 // Progress bars //
330 //---------------//
331 prog_conv.reset( new TGHProgressBar( centre_progress, TGProgressBar::kFancy, 400 ) );
332 prog_sort.reset( new TGHProgressBar( centre_progress, TGProgressBar::kFancy, 400 ) );
333 prog_evnt.reset( new TGHProgressBar( centre_progress, TGProgressBar::kFancy, 400 ) );
334 prog_hist.reset( new TGHProgressBar( centre_progress, TGProgressBar::kFancy, 400 ) );
335 prog_conv->ShowPosition( true, false, "Converter" );
336 prog_sort->ShowPosition( true, false, "TimeSorter" );
337 prog_evnt->ShowPosition( true, false, "EventBuilder" );
338 prog_hist->ShowPosition( true, false, "Histogrammer" );
339 centre_progress->AddFrame( prog_conv.get(), new TGLayoutHints(kLHintsTop|kLHintsLeft|
340 kLHintsExpandX,5,5,5,10) );
341 centre_progress->AddFrame( prog_sort.get(), new TGLayoutHints(kLHintsTop|kLHintsLeft|
342 kLHintsExpandX,5,5,5,10) );
343 centre_progress->AddFrame( prog_evnt.get(), new TGLayoutHints(kLHintsTop|kLHintsLeft|
344 kLHintsExpandX,5,5,5,10) );
345 centre_progress->AddFrame( prog_hist.get(), new TGLayoutHints(kLHintsTop|kLHintsLeft|
346 kLHintsExpandX,5,5,5,10) );
347
348
349 //-----------------//
350 // Open the window //
351 //-----------------//
352
353 // Set a name to the main frame
354 main_frame->SetWindowName( "mb_sort" );
355
356 // Map all sub windows
357 main_frame->MapSubwindows();
358
359 // Initialize the layout algorithm via Resize()
360 main_frame->Resize( main_frame->GetDefaultSize() );
361
362 // Map windows
363 main_frame->MapWindow();
364 //main_frame->Print();
365
366
367 //----------//
368 // Defaults //
369 //----------//
370 text_add_file->SetText( "R1_0" );
371
372
373 //----------------//
374 // Button presses //
375 //----------------//
376 but_save->Connect( "Clicked()", "MiniballGUI", this, "on_save_clicked()" );
377 but_open->Connect( "Clicked()", "MiniballGUI", this, "on_open_clicked()" );
378 but_sel->Connect( "Clicked()", "MiniballGUI", this, "on_sel_clicked()" );
379 but_add->Connect( "Clicked()", "MiniballGUI", this, "on_add_clicked()" );
380 text_add_file->Connect( "ReturnPressed()", "MiniballGUI", this, "on_add_clicked()" );
381 but_del->Connect( "Clicked()", "MiniballGUI", this, "on_del_clicked()" );
382 but_sort->Connect( "Clicked()", "MiniballGUI", this, "on_sort_clicked()" );
383 but_set->Connect( "Clicked()", "MiniballGUI", this, "on_set_clicked()" );
384 but_cal->Connect( "Clicked()", "MiniballGUI", this, "on_cal_clicked()" );
385 but_rea->Connect( "Clicked()", "MiniballGUI", this, "on_rea_clicked()" );
386 but_dir->Connect( "Clicked()", "MiniballGUI", this, "on_dir_clicked()" );
387 but_out->Connect( "Clicked()", "MiniballGUI", this, "on_out_clicked()" );
388
389
390 //clean up
391 filelist.clear();
392 filestatus.clear();
393
394}
395
397
398 // Clean up main frame...
399 main_frame->Cleanup();
400 delete main_frame;
401
402}
403
405
406 // Configure file dialog
407 TGFileInfo fi;
408 fi.SetMultipleSelection( false );
409 TString dir(".");
410 fi.fIniDir = StrDup(dir);
411
412 // Open a file dialog
413 auto open_mode = kFDOpen;
414 new TGFileDialog( gClient->GetRoot(), main_frame, open_mode, &fi );
415
416 return fi.fFilename;
417
418}
419
421
422 // Configure file dialog
423 TGFileInfo fi;
424 fi.SetMultipleSelection( false );
425 TString dir(".");
426 fi.fIniDir = StrDup(dir);
427
428 // Open a file dialog
429 auto open_mode = kDOpen;
430#if ( ROOTVER == 5 || ( ROOTVER == 6 && ROOTSUBVER < 24 ) )
431 open_mode = kFDOpen;
432#endif
433 new TGFileDialog( gClient->GetRoot(), main_frame, open_mode, &fi );
434
435 return fi.fIniDir;
436
437}
438
440
441 // Slot to react to select file button
442 TString filename = get_filename();
443
444 text_add_file->SetText( filename );
446
447 return;
448
449}
450
452
453 // Slot to react to add file button
454 TGString filename = text_add_file->GetText();
455
456 run_list_box->AddEntrySort( filename, filelist.size() + 1 );
457 run_list_box->Layout();
458
459 filelist.push_back( filename.GetString() );
460 filestatus.push_back( true );
461
462}
463
465
466 // Cleanup the selected entries
467 run_selected->Clear();
468
469 // Slot to react to remove file button
470 if( run_list_box->GetSelected() < 0 ) {
471
472 std::cout << "\nNo runs selected" << std::endl;
473
474 }
475
476 else if( run_list_box->GetMultipleSelections() ) {
477
478 run_list_box->GetSelectedEntries( run_selected );
479 TIter next( run_selected );
480
481 while( TGLBEntry *ent = (TGLBEntry*)next() ) {
482
483 filestatus.at( ent->EntryId() - 1 ) = false;
484 run_list_box->RemoveEntry( ent->EntryId() );
485
486 }
487
488 }
489
490 else {
491
492 filestatus.at( run_list_box->GetSelected() - 1 ) = false;
493 run_list_box->RemoveEntry( -1 );
494
495 }
496
497 run_list_box->Layout();
498
499}
500
501void MiniballGUI::SaveSetup( TString setupfile ) {
502
503 TEnv *fSetup = new TEnv( setupfile );
504
505 TString list_of_files = "";
506
507 for( unsigned int i = 0; i < filelist.size(); i++ ) {
508
509 if( !filestatus.at( i ) ) continue;
510
511 list_of_files += filelist.at(i);
512 list_of_files += " ";
513
514 }
515
516 fSetup->SetValue( "filelist", list_of_files );
517 fSetup->SetValue( "force", check_force->IsOn() );
518 fSetup->SetValue( "events", check_event->IsOn() );
519 fSetup->SetValue( "ebis", check_ebis->IsOn() );
520 fSetup->SetValue( "mbs", check_mbs->IsOn() );
521
522 fSetup->WriteFile( setupfile );
523
524}
525
526void MiniballGUI::LoadSetup( TString setupfile ) {
527
528 TEnv *fSetup = new TEnv( setupfile );
529 fSetup->ReadFile( setupfile, kEnvLocal );
530
531 TString list_of_files = fSetup->GetValue( "filelist", "" );
532 std::vector <TString>().swap( filelist );
533 std::vector <bool>().swap( filestatus );
534 run_list_box->RemoveAll();
535
536 std::stringstream ss;
537 TString current_file;
538 ss << list_of_files;
539 ss >> current_file;
540
541 while( !ss.eof() ) {
542
543 filelist.push_back( current_file );
544 filestatus.push_back( true );
545
546 run_list_box->AddEntrySort( current_file, filelist.size() );
547
548 ss >> current_file;
549
550 }
551
552 run_list_box->Layout();
553
554 check_force->SetOn( fSetup->GetValue( "force", false ) );
555 check_event->SetOn( fSetup->GetValue( "event", false ) );
556 check_ebis->SetOn( fSetup->GetValue( "ebis", false ) );
557 check_mbs->SetOn( fSetup->GetValue( "mbs", false ) );
558
559}
560
562
563 //------------------------//
564 // Run conversion to ROOT //
565 //------------------------//
566 MiniballMidasConverter conv_midas( myset );
567 MiniballMbsConverter conv_mbs( myset );
568
569 if( flag_mbs ) conv_mbs.AddProgressBar( prog_conv );
570 else conv_midas.AddProgressBar( prog_conv );
571
572 std::cout << "\n +++ Miniball Analysis:: processing MiniballMidasConverter +++" << std::endl;
573
574 // Progress bar and filename
575 std::string prog_format;
576 TFile *rtest;
577 std::ifstream ftest;
578 TString name_input_file;
579 TString name_output_file;
580
581 // Check each file
582 for( unsigned int i = 0; i < filelist.size(); i++ ){
583
584 name_input_file = filelist.at(i);
585 name_input_file = name_input_file( name_input_file.Last('/')+1,
586 name_input_file.Length() - name_input_file.Last('/')-1 );
587 if( name_input_file.Contains('.') )
588 name_input_file = name_input_file( 0, name_input_file.Last('.') );
589
590 if( flag_source ) name_output_file = name_input_file + "_source.root";
591 else name_output_file = name_input_file + ".root";
592
593 name_output_file = datadir_name + "/" + name_output_file;
594 name_input_file = filelist.at(i);
595
596 force_convert.push_back( false );
597
598 // Skip the file if it's deleted
599 if( !filestatus.at(i) ) continue;
600
601 // If input doesn't exist, skip it
602 ftest.open( name_input_file.Data() );
603 if( !ftest.is_open() ) {
604
605 std::cerr << name_input_file << " does not exist" << std::endl;
606 continue;
607
608 }
609 else ftest.close();
610
611 // If input doesn't exist, skip it
612 ftest.open( name_input_file.Data() );
613 if( !ftest.is_open() ) {
614
615 std::cerr << name_input_file << " does not exist" << std::endl;
616 continue;
617
618 }
619 else ftest.close();
620
621 // If output doesn't exist, we have to convert it anyway
622 // The convert flag will force it to be converted
623 ftest.open( name_output_file );
624 if( !ftest.is_open() ) force_convert.at(i) = true;
625 else {
626
627 ftest.close();
628 rtest = new TFile( name_output_file );
629 if( rtest->IsZombie() ) force_convert.at(i) = true;
630 if( !flag_convert && !force_convert.at(i) )
631 std::cout << name_output_file << " already converted" << std::endl;
632 rtest->Close();
633
634 }
635
636 if( flag_convert || force_convert.at(i) ) {
637
638 std::cout << name_input_file << " --> ";
639 std::cout << name_output_file << std::endl;
640
641 prog_format = "Converting ";
642 prog_format += name_input_file( name_input_file.Last('/') + 1,
643 name_input_file.Length() - name_input_file.Last('/') ).Data();
644 prog_format += ": %.0f%%";
645 prog_conv->ShowPosition( true, false, prog_format.data() );
646
647 // Open file and covert data to ROOT
648 if( flag_mbs ) {
649
650 if( flag_source ) conv_mbs.SourceOnly();
651 if( flag_ebis ) conv_mbs.EBISOnly();
652 conv_mbs.SetOutput( name_output_file.Data() );
653 conv_mbs.AddCalibration( mycal );
654 conv_mbs.MakeTree();
655 conv_mbs.MakeHists();
656 conv_mbs.ConvertFile( name_input_file.Data() );
657
658 }
659 else {
660
661 if( flag_source ) conv_midas.SourceOnly();
662 if( flag_ebis ) conv_midas.EBISOnly();
663 conv_midas.SetOutput( name_output_file.Data() );
664 conv_midas.AddCalibration( mycal );
665 conv_midas.MakeTree();
666 conv_midas.MakeHists();
667 conv_midas.ConvertFile( name_input_file.Data() );
668
669 }
670
671 prog_format = "Converter complete";
672 prog_conv->ShowPosition( true, false, prog_format.data() );
673
674 // Time sorting
675 if( !flag_source ) {
676
677 prog_format = "Time ordering ";
678 prog_format += name_input_file( name_input_file.Last('/') + 1,
679 name_input_file.Length() - name_input_file.Last('/') ).Data();
680 prog_format += ": %.0f%%";
681 prog_sort->ShowPosition( true, false, prog_format.data() );
682
683 if( flag_mbs ) {
684 conv_mbs.AddProgressBar( prog_sort );
685 conv_mbs.BuildMbsIndex();
686 if( myset->GetMbsEventMode() )
687 conv_mbs.SortTree(false);
688 conv_mbs.SortTree();
689 }
690 else {
691 conv_midas.AddProgressBar( prog_sort );
692 conv_midas.SortTree();
693 }
694
695
696 prog_format = "Time ordering complete";
697 prog_conv->ShowPosition( true, false, prog_format.data() );
698
699 }
700
701 // Close file
702 if( flag_mbs ) conv_mbs.CloseOutput();
703 else conv_midas.CloseOutput();
704
705 }
706
707 // Update everything
708 gSystem->ProcessEvents();
709
710 }
711
712 return;
713
714}
715
717
718 //-----------------------//
719 // Physics event builder //
720 //-----------------------//
723 std::cout << "\n +++ Miniball Analysis:: processing MiniballEventBuilder +++" << std::endl;
724
725 // Update everything
726 gSystem->ProcessEvents();
727
728 // Progress bar and filename
729 std::string prog_format;
730 TFile *rtest;
731 std::ifstream ftest;
732 TString name_input_file;
733 TString name_output_file;
734
735 // Update calibration file if given
736 if( mycal->InputFile() != "dummy" )
737 eb.AddCalibration( mycal );
738
739 // Do event builder for each file individually
740 for( unsigned int i = 0; i < filelist.size(); i++ ){
741
742 name_input_file = filelist.at(i);
743 name_input_file = name_input_file( name_input_file.Last('/')+1,
744 name_input_file.Length() - name_input_file.Last('/')-1 );
745 if( name_input_file.Contains('.') )
746 name_input_file = name_input_file( 0, name_input_file.Last('.') );
747
748 name_output_file = datadir_name + "/" + name_input_file + "_events.root";
749 name_input_file = datadir_name + "/" + name_input_file + ".root";
750
751 // Skip the file if it's deleted
752 if( !filestatus.at(i) ) continue;
753
754 // If input doesn't exist, skip it
755 ftest.open( name_input_file.Data() );
756 if( !ftest.is_open() ) {
757
758 std::cerr << name_input_file << " does not exist" << std::endl;
759 continue;
760
761 }
762 else {
763
764 ftest.close();
765
766 }
767
768 // We need to do event builder if we just converted it
769 // specific request to do new event build with -e
770 // this is useful if you need to add a new calibration
771 if( flag_convert || force_convert.at(i) || flag_events )
772 force_events = true;
773
774 // If it doesn't exist, we have to sort it anyway
775 else {
776
777 ftest.open( name_output_file );
778 if( !ftest.is_open() ) force_events = true;
779 else {
780
781 ftest.close();
782 rtest = new TFile( name_output_file );
783 if( rtest->IsZombie() ) force_events = true;
784 if( !force_events )
785 std::cout << name_output_file << " already built" << std::endl;
786 rtest->Close();
787
788 }
789
790 }
791
792 if( force_events ) {
793
794 std::cout << name_input_file << " --> ";
795 std::cout << name_output_file << std::endl;
796
797 prog_format = "Building ";
798 prog_format += name_input_file( name_input_file.Last('/') + 1,
799 name_input_file.Length() - name_input_file.Last('/') ).Data();
800 prog_format += ": %.0f%%";
801 prog_evnt->ShowPosition( true, false, prog_format.data() );
802
803 eb.SetInputFile( name_input_file.Data() );
804 eb.SetOutput( name_output_file.Data() );
805 eb.BuildEvents();
806 eb.CloseOutput();
807
808 force_events = false;
809
810 }
811
812 prog_format = "EventBuilder complete";
813 prog_evnt->ShowPosition( true, false, prog_format.data() );
814
815 // Update everything
816 gSystem->ProcessEvents();
817
818 }
819
820 return;
821
822}
823
825
826 //------------------------------//
827 // Finally make some histograms //
828 //------------------------------//
831 std::cout << "\n +++ Miniball Analysis:: processing MiniballHistogrammer +++" << std::endl;
832
833 // Update everything
834 gSystem->ProcessEvents();
835
836 // Progress bar and filename
837 std::string prog_format;
838 std::ifstream ftest;
839 TString name_input_file;
840 TString name_output_file;
841
842 prog_format = "Histogramming: %.0f%%";
843 prog_hist->ShowPosition( true, false, prog_format.data() );
844
845 name_output_file = text_out_file->GetText();
846 if( name_output_file == "" ) name_output_file = "output.root";
847 hist.SetOutput( name_output_file.Data() );
848 std::vector<std::string> name_hist_files;
849
850 // We are going to chain all the event files now
851 for( unsigned int i = 0; i < filelist.size(); i++ ){
852
853 // Skip the file if it's deleted
854 if( !filestatus.at(i) ) continue;
855
856 name_input_file = filelist.at(i);
857 name_input_file = name_input_file( name_input_file.Last('/')+1,
858 name_input_file.Length() - name_input_file.Last('/')-1 );
859 if( name_input_file.Contains('.') )
860 name_input_file = name_input_file( 0, name_input_file.Last('.') );
861 name_input_file = datadir_name + "/" + name_input_file + "_events.root";
862
863 // Test if the input file exists
864 ftest.open( name_input_file.Data() );
865 if( !ftest.is_open() ) {
866
867 std::cerr << name_input_file << " does not exist" << std::endl;
868 continue;
869
870 }
871 else ftest.close();
872
873 name_hist_files.push_back( name_input_file.Data() );
874
875 }
876
877 hist.SetInputFile( name_hist_files );
878 hist.FillHists();
879 hist.CloseOutput();
880
881 prog_format = "Histogramming complete";
882 prog_hist->ShowPosition( true, false, prog_format.data() );
883
884
885 // Update everything
886 gSystem->ProcessEvents();
887 return;
888
889}
890
892
893 // Settings files, etc
894 std::string name_set_file = text_set_file->GetText();
895 std::string name_cal_file = text_cal_file->GetText();
896 std::string name_rea_file = text_rea_file->GetText();
897
898 if( name_set_file == "" ) name_set_file = "dummy";
899 if( name_cal_file == "" ) name_cal_file = "dummy";
900 if( name_rea_file == "" ) name_rea_file = "dummy";
901
902 myset = std::make_shared<MiniballSettings>( name_set_file );
903 mycal = std::make_shared<MiniballCalibration>( name_cal_file, myset );
904 if( flag_mbs ) mycal->SetDefaultQint();
905 mycal->ReadCalibration();
906 myrea = std::make_shared<MiniballReaction>( name_rea_file, myset );
907
908 // select what steps of the analysis to be forced
909 force_events = false;
910 flag_source = check_source->IsOn();
911 flag_convert = check_force->IsOn();
912 flag_events = check_event->IsOn();
913 flag_ebis = check_ebis->IsOn();
914 flag_mbs = check_mbs->IsOn();
915 datadir_name = text_out_dir->GetText();
916
917 //------------------//
918 // Run the analysis //
919 //------------------//
920 gui_convert();
921 gui_build();
922 gui_hist();
923 std::cout << "\n\nFinished!\n";
924
925}
926
927MyDialog::MyDialog( const TGWindow *p, const TGWindow *main, TString msg, bool &ans ) {
928
929 // Default answer is false
930 answer = false;
931
932 fDialog = new TGTransientFrame( p, main, 800, 100, kVerticalFrame );
933 frame_button = new TGHorizontalFrame( fDialog, 240, 60 );
934
935 dialog_msg = new TGLabel( fDialog, msg );
936 fDialog->AddFrame( dialog_msg, new TGLayoutHints( kLHintsTop | kLHintsExpandY, 5, 5, 5, 5) );
937
938 but_yes = new TGTextButton( frame_button, " &Yes ", 1 );
939 but_yes->Connect( "Clicked()", "MyDialog", this, "SayYes()" );
940 but_yes->Associate( fDialog );
941 frame_button->AddFrame( but_yes, new TGLayoutHints( kLHintsLeft | kLHintsExpandX, 4, 4, 4, 4 ) );
942
943 but_no = new TGTextButton( frame_button, " &No ", 1 );
944 but_no->Connect( "Clicked()", "MyDialog", this, "SayNo()" );
945 but_no->Associate( fDialog );
946 frame_button->AddFrame( but_no, new TGLayoutHints( kLHintsLeft | kLHintsExpandX, 4, 4, 4, 4 ) );
947
948 frame_button->Resize( 100, but_no->GetDefaultHeight() + 4 );
949 fDialog->AddFrame( frame_button, new TGLayoutHints( kLHintsBottom | kLHintsCenterX | kLHintsExpandY, 5, 5, 5, 5 ) );
950
951 fDialog->MapSubwindows();
952 fDialog->Resize( fDialog->GetDefaultSize() );
953
954 fDialog->MapWindow();
955
956 gClient->WaitFor( fDialog );
957
958 ans = answer;
959
960}
961
963
964 delete fDialog;
965 delete but_yes;
966 delete but_no;
967 delete dialog_msg;
968 delete frame_button;
969
970 delete fDialog;
971
972}
973
975
976 answer = true;
977 fDialog->SendCloseMessage();
978
979}
980
982
983 answer = false;
984 fDialog->SendCloseMessage();
985
986}
987
ClassImp(MiniballGUI) ClassImp(MyDialog) MiniballGUI
Definition MiniballGUI.cc:7
void AddCalibration(std::shared_ptr< MiniballCalibration > mycal)
Definition Converter.hh:79
void AddProgressBar(std::shared_ptr< TGProgressBar > myprog)
Definition Converter.hh:92
unsigned long long int SortTree(bool do_sort=true)
Definition Converter.cc:489
void SetOutput(std::string output_file_name)
Definition Converter.cc:111
void AddCalibration(std::shared_ptr< MiniballCalibration > mycal)
void SetInputFile(std::string input_file_name)
unsigned long BuildEvents()
void AddProgressBar(std::shared_ptr< TGProgressBar > myprog)
void SetOutput(std::string output_file_name, bool cWrite=false)
std::string datadir_name
std::shared_ptr< TGHProgressBar > prog_conv
TGVertical3DLine * fVertical_0
TGVerticalFrame * centre_text
TGTextEntry * text_out_file
TGListBox * run_list_box
TGCheckButton * check_ebis
TGTextEntry * text_cal_file
TGHorizontal3DLine * fHorizontal_0
void on_sort_clicked()
TGVerticalFrame * centre_button
TGTextButton * but_del
TGVerticalFrame * centre_progress
TGLabel * lab_cal_file
TGLabel * lab_rea_file
void LoadSetup(TString setupfile)
TGLabel * lab_out_file
std::shared_ptr< TGHProgressBar > prog_sort
TGHorizontalFrame * fbut_frame
std::vector< bool > force_convert
TGCheckButton * check_event
TGTextEntry * text_rea_file
TGTextEntry * text_out_dir
TList * run_selected
TGTextButton * but_add
TGTextButton * but_cal
TGTextButton * but_sort
void on_add_clicked()
TGLabel * lab_out_dir
TString get_filename()
void on_del_clicked()
void gui_hist()
TGVerticalFrame * left_frame
TGTextButton * but_rea
TGTextEntry * text_set_file
TGTextButton * but_open
TGLabel * lab_set_file
std::vector< bool > filestatus
TString get_directory()
std::vector< TString > filelist
TGTextEntry * text_add_file
TGHorizontalFrame * centre_go
TGTextButton * but_out
TGLabel * lab_run_files
TGVerticalFrame * centre_frame
TGCheckButton * check_mbs
std::shared_ptr< MiniballCalibration > mycal
TGTextButton * but_save
TGMainFrame * main_frame
void gui_build()
std::shared_ptr< MiniballSettings > myset
void gui_convert()
TGTextButton * but_set
virtual ~MiniballGUI()
TGCheckButton * check_source
TGTextButton * but_sel
std::shared_ptr< MiniballReaction > myrea
std::shared_ptr< TGHProgressBar > prog_hist
void SaveSetup(TString setupfile)
TGCheckButton * check_force
TGTextButton * but_dir
void on_sel_clicked()
std::shared_ptr< TGHProgressBar > prog_evnt
TGHorizontalFrame * centre_files
TGVerticalFrame * centre_label
void SetOutput(std::string output_file_name, bool cWrite=false)
unsigned long FillHists()
void SetInputFile(std::vector< std::string > input_file_names)
void AddProgressBar(std::shared_ptr< TGProgressBar > myprog)
int ConvertFile(std::string input_file_name, unsigned long start_block=0, long end_block=-1)
int ConvertFile(std::string input_file_name, unsigned long start_block=0, long end_block=-1)
TGTextButton * but_no
TGHorizontalFrame * frame_button
TGTextButton * but_yes
MyDialog(const TGWindow *p, const TGWindow *main, TString msg, bool &ans)
void SayYes()
TGLabel * dialog_msg
bool answer
void SayNo()
virtual ~MyDialog()
TGTransientFrame * fDialog
std::string name_set_file
Definition mb_sort.cc:76
int main(int argc, char *argv[])
Definition mb_sort.cc:939
std::string name_cal_file
Definition mb_sort.cc:77