// evloop.C // // ROOT macro that updates a job in a loop until it finishes. // The h2-h6 histograms are used to display the completed events. // // nloop = number of loops before checking with user // show_loop_count = flag to display # loops remaining each loop // show_job - flag to display job status each loop // show_hists - flag to list of histograms each loop // pause_time - time (in ms) to pause between loops void evloop(int nloop=25, bool show_loop_count=true, bool show_job=true, bool show_hists=false, int pause_time=4000) { int nrem = nloop; TCanvas mycan("My canvas"); while ( true ) { while ( nrem > 0 ) { cout << endl; if ( show_loop_count ) { cout << "********* Remaining loop count = " << nrem << endl; } // Fetch latest job from scheduler. dial::Job ljob = msch.job(jid); if ( ! ljob.is_valid() ) { cout << "Invalid job" << endl; break; } if ( show_job ) { cout << ljob << endl; } // Fetch and select histogram. const dset::Dataset& resdst = ljob.result(); if ( resdst.is_valid() ) { open_hbook(ljob.result(), show_hists); TH1* ph = dynamic_cast(gROOT->FindObject("h2")); if ( ph!=0 && ph->GetBinContent(ph->GetNbinsX()+1)==0 ) { ph->Draw(); } else { ph = dynamic_cast(gROOT->FindObject("h3")); if ( ph!=0 && ph->GetBinContent(ph->GetNbinsX()+1)==0 ) { ph->Draw(); } else { ph = dynamic_cast(gROOT->FindObject("h4")); if ( ph!=0 && ph->GetBinContent(ph->GetNbinsX()+1)==0 ) { ph->Draw(); } else { ph = dynamic_cast(gROOT->FindObject("h5")); if ( ph!=0 && ph->GetBinContent(ph->GetNbinsX()+1)==0 ) { ph->Draw(); } else { ph = dynamic_cast(gROOT->FindObject("h6")); if ( ph!=0 ) { ph->Draw(); } } } } } mycan.Update(); if ( ! ljob.is_active() ) break; } if ( --nrem == 0 ) cout << "# loops [1] or 'q' to quit> "; // Pause between loops. if ( nrem != 0 ) { gSystem->Sleep(pause_time); } } if ( ! ljob.is_running() ) { cout << endl; cout << "Job is finished ( to exit)" << endl; cout << endl; } char response = cin.get(); // If user enters a number then do that many loops before asking again. if ( isdigit(response) ) { cin.putback(response); cin >> nrem; } else if ( isalpha(response) && (response == 'q' || response == 'Q') ) { return; } else { while ( response != '\n' ) { response = cin.get(); } } if ( ! ljob.is_running() ) { return; } } }