Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

PlotMan.cxx

Go to the documentation of this file.
00001 #include <algorithm>
00002 
00003 #include "TApplication.h"
00004 #include "TCanvas.h"
00005 #include "TError.h"
00006 #include "TGButton.h"
00007 #include "TGClient.h"
00008 #include "TGFrame.h"
00009 #include "TGLabel.h"
00010 #include "TGProgressBar.h"
00011 #include "TGButton.h"
00012 #include "TGTextEntry.h"
00013 #include "TGNumberEntry.h"
00014 #include "TSystem.h"
00015 #include "TFile.h"
00016 #include "TROOT.h"
00017 
00018 #include "AtNuEvent/AtmosEvent.h"
00019 #include "HistMan/HistMan.h"
00020 #include "MessageService/MsgService.h"
00021 
00022 #include "AtNuUtils/UtilFile.h"
00023 
00024 #include "AtNuUtils/CamAna.h"
00025 #include "AtNuUtils/PlotMan.h"
00026 
00027 TChain *fChain = new TChain("ntp");
00028 
00029 typedef vector<string> VS;
00030 
00031 CVSID("$Id: PlotMan.cxx,v 1.4 2009/02/28 21:46:10 gmieg Exp $");
00032 
00033 PlotMan::PlotMan(bool interactive)
00034 {
00035   fSpinning = false;
00036   fStopSpinning = false;
00037   fDoFinish = true;
00038   fChain = new TChain("ntp");
00039   fRootFilesSuf = ".root";
00040   fChainBuilt = false;
00041   fChainCurrent = false;
00042 
00043   fEvent = -1;
00044   fEntries = 0;
00045   fReadNEntries = false;
00046   fUpdateInterval = 0;
00047   fUpdateFraction = 0;
00048   fUpdateSleep = 0;
00049 
00050   fProgress = 0;
00051   cgSleep = 0;
00052   cgMain = 0;
00053 
00054   if(interactive && gApplication) this->ControlWindow(0,1,1);
00055 }
00056 
00057 PlotMan::~PlotMan()
00058 {
00059 }
00060 
00061 void PlotMan::AddCamAna(CamAna *camana, bool dohist, bool docanv)
00062 {
00063   MSG("PlotMan", Msg::kSynopsis) << "Adding CamAna: " << camana->GetName()
00064                                  << endl;
00065   fCamAnas.push_back(camana);
00066   if(dohist) camana->MakeHistos();
00067   if(docanv) camana->MakeCanvases();
00068 
00069   fEventsRun.push_back(0);
00070   fEventsPassed.push_back(0);
00071   fFilterOn.push_back(false);
00072   fFilterRev.push_back(false);
00073 
00074   if (cgMain) {
00075     MSG("PlotMan",Msg::kSynopsis) << " CamAna filters" << endl;
00076     TGCompositeFrame *cgH1 = new TGHorizontalFrame(cgMain);
00077 
00078     TGLabel *cgLabel = new TGLabel(cgH1,
00079         Form("%d)%s",fCamAnas.size()-1,camana->GetName()));
00080     cgH1->AddFrame(cgLabel, new TGLayoutHints(kLHintsLeft));
00081 
00082     TGCheckButton *cgCheck = new TGCheckButton(cgH1, "Filt", 2);
00083     cgCheck->Connect("Pressed()", "PlotMan", this,
00084       Form("FilterOn(=true, %d)",fCamAnas.size()-1));
00085     cgCheck->Connect("Released()", "PlotMan", this,
00086       Form("FilterOn(=false, %d)",fCamAnas.size()-1));
00087     cgH1->AddFrame(cgCheck, new TGLayoutHints(kLHintsRight));
00088 
00089     MSG("PlotMan",Msg::kSynopsis) << " CamAna filters" << endl;
00090     cgCheck = new TGCheckButton(cgH1, "Rev", 2);
00091     cgCheck->Connect("Pressed()", "PlotMan", this,
00092       Form("FilterRev(=true, %d)",fCamAnas.size()-1));
00093     cgCheck->Connect("Released()", "PlotMan", this,
00094       Form("FilterRev(=false, %d)",fCamAnas.size()-1));
00095     cgH1->AddFrame(cgCheck, new TGLayoutHints(kLHintsRight));
00096 
00097     cgMain->AddFrame(cgH1, new TGLayoutHints(kLHintsExpandX));
00098 
00099     cgMain->Resize();
00100     cgMain->MapSubwindows();
00101     cgMain->Layout();
00102     cgMain->MapWindow();
00103   }
00104 }
00105 
00106 CamAna *PlotMan::GetCamAna(string caname) {
00107   for (unsigned int i=0;i<fCamAnas.size();i++) {
00108     if(caname == fCamAnas[i]->GetName()) return fCamAnas[i];
00109   }
00110   return 0;
00111 }
00112 
00113 CamAna *PlotMan::GetCamAna(unsigned int canum) {
00114   if(canum<fCamAnas.size()) return fCamAnas[canum];
00115   return 0;
00116 }
00117 
00118 void PlotMan::AllFiltersOn(bool filt) {
00119   for(unsigned int i=0;i<fFilterOn.size();i++) fFilterOn[i] = filt;
00120 }
00121 
00122 void PlotMan::FilterOn(bool filt, string caname) {
00123   for (unsigned int i=0;i<fCamAnas.size();i++) {
00124     if (caname == fCamAnas[i]->GetName()) {
00125       fFilterOn[i] = filt;
00126       MSG("PlotMan",Msg::kSynopsis) << "Turning the filter for " << caname;
00127       if(filt) MSG("PlotMan",Msg::kSynopsis) << " on" << endl;
00128       else MSG("PlotMan",Msg::kSynopsis) << " off" << endl;
00129     }
00130   }
00131 }
00132 
00133 void PlotMan::FilterOn(bool filt, unsigned int canum) {
00134   if (canum<fFilterOn.size()) {
00135     fFilterOn[canum] = filt;
00136     MSG("PlotMan",Msg::kSynopsis) << "Turning the filter for " << fCamAnas[canum]->GetName();
00137     if(filt) MSG("PlotMan",Msg::kSynopsis) << " on" << endl;
00138     else MSG("PlotMan",Msg::kSynopsis) << " off" << endl;
00139   }
00140 }
00141 
00142 void PlotMan::AllFiltersRev(bool filt) {
00143   for(unsigned int i=0;i<fFilterRev.size();i++) fFilterRev[i] = filt;
00144 }
00145 
00146 void PlotMan::FilterRev(bool filt, string caname) {
00147   for (unsigned int i=0;i<fCamAnas.size();i++) {
00148     if(caname == fCamAnas[i]->GetName()) {
00149       fFilterRev[i] = filt;
00150       MSG("PlotMan",Msg::kSynopsis) << "Reverse the filter for " << caname;
00151       if(filt) MSG("PlotMan",Msg::kSynopsis) << " on" << endl;
00152       else MSG("PlotMan",Msg::kSynopsis) << " off" << endl;
00153     }
00154   }
00155 }
00156 
00157 void PlotMan::FilterRev(bool filt, unsigned int canum) {
00158   if(canum<fFilterRev.size()) {
00159     fFilterRev[canum] = filt;
00160     MSG("PlotMan",Msg::kSynopsis) << "Turning the filter for "
00161                                   << fCamAnas[canum]->GetName();
00162     if(filt) MSG("PlotMan",Msg::kSynopsis) << " on" << endl;
00163     else MSG("PlotMan",Msg::kSynopsis) << " off" << endl;
00164   }
00165 }
00166 
00167 void PlotMan::AddFile(string fname) {
00168   if (! UtilFile::CheckFile(fname) ) {
00169     MSG("PlotMan",Msg::kWarning)<< "No such file " << fname << endl;
00170     return;
00171   }
00172   fRootFiles.push_back(fname);
00173   fChainCurrent = false;
00174   MSG("PlotMan",Msg::kSynopsis) << "Added file: " << fname << endl;
00175 }
00176 
00177 void PlotMan::AddFileChecked(std::string fname) {
00178   int nentries = 0;
00179   TFile *tf = TFile::Open(fname.c_str());
00180   if (!tf) {
00181     MSG("PlotMan",Msg::kError) << "zero TFile" << endl;
00182     return;
00183   }
00184   if (tf->IsZombie()) {
00185     MSG("PlotMan",Msg::kError) << "zombie TFile" << endl;
00186     return;
00187   }
00188   TObject *obj = tf->Get("ntp");
00189   if (!obj) {
00190     MSG("PlotMan",Msg::kError) << "zero TObject ntp" << endl;
00191     return;
00192   }
00193 
00194   //TChain in file
00195   if (obj->InheritsFrom("TChain")) {
00196     nentries = (dynamic_cast<TChain*>(obj))->GetEntries();
00197     fChain->Add(dynamic_cast<TChain*>(obj));
00198   }
00199   //TTree in file
00200   else if (obj->InheritsFrom("TTree")) {
00201     nentries = (dynamic_cast<TTree*>(obj))->GetEntries();
00202     //Include the 0 to read header from file and get nentries
00203     fChain->Add(fname.c_str(),0);
00204   }
00205   else {
00206     MSG("PlotMan",Msg::kError) << "TObject not a TChain or TTree" << endl;
00207     return;
00208   }
00209   MSG("PlotMan",Msg::kSynopsis) << "Added file " << fname << " with "
00210          << nentries << " entries" << endl;
00211   tf->Close();
00212   fEntries += nentries;
00213   if(fProgress) fProgress->SetRange(0,fEntries);
00214 }
00215 
00216 void PlotMan::AddList(string lname)
00217 {
00218   fRootFiles = UtilFile::FileFileList(lname, fRootFilesSuf,
00219                                       true, true, fRootFiles);
00220   fChainCurrent = false;
00221   MSG("PlotMan",Msg::kSynopsis) << "Added file list: " << lname << " nfiles = "
00222                                 << fRootFiles.size() << endl;
00223 }
00224 
00225 void PlotMan::AddDirectory(string dname)
00226 {
00227   fRootFiles =
00228     UtilFile::DirFileList(dname,fRootFilesSuf,true,true,fRootFiles);
00229   fChainCurrent = false;
00230   MSG("PlotMan",Msg::kSynopsis) << "Added file directory: " << dname << endl;
00231 }
00232 
00233 //Build the fChain from the fRootFiles vector
00234 void PlotMan::BuildChain(bool checked) {
00235   MSG("PlotMan",Msg::kSynopsis) << "Building chain for " << fRootFiles.size()
00236          << " files";
00237   if(checked) MSG("PlotMan",Msg::kSynopsis) << " with checking";
00238   MSG("PlotMan",Msg::kSynopsis) << endl;
00239 
00240   sort(fRootFiles.begin(),fRootFiles.end());
00241   VS::iterator nend = unique(fRootFiles.begin(),fRootFiles.end());
00242   if (nend != fRootFiles.end()) {
00243     MSG("PlotMan",Msg::kWarning) << "Redundant items in the list of root files:"
00244                                  << endl;
00245 
00246     //This doesn't exactly work, whatever
00247     for(VS::iterator i=nend;i!=fRootFiles.end();i++)
00248       MSG("PlotMan",Msg::kWarning)<< "  " << i->c_str() << endl;
00249   }
00250   for (VS::iterator i=fRootFiles.begin();i!=nend;i++) {
00251     if(checked) AddFileChecked(*i);
00252     else fChain->Add(i->c_str());
00253     MSG("PlotMan",Msg::kVerbose) << "Added file " << *i << endl;
00254   }
00255   if(fReadNEntries) SetEntries(fChain->GetEntries());
00256   fChainBuilt = true;
00257   MSG("PlotMan",Msg::kSynopsis) << "Built chain with " << fEntries << " entries"
00258                                 << endl;
00259 }
00260 
00261 //Build the fChain from the fRootFiles vector
00262 void PlotMan::ChainReport() {
00263   MSG("PlotMan",Msg::kSynopsis) << "Chain has NTrees =  " << fChain->GetNtrees() 
00264                                 << endl;
00265 }
00266 
00267 void PlotMan::SetBranchStatus(const char* branch, int status) {
00268   fChain->SetBranchStatus(branch, status);
00269 }
00270 
00271 void PlotMan::SpinChain(int nevents) {
00272   Emit("SpinChain()");
00273   if (fSpinning)  {
00274     MSG("PlotMan",Msg::kSynopsis) << "Already Spinning Chain" << endl;
00275     return;
00276   }
00277 
00278   if(!fChainBuilt) BuildChain();
00279 
00280   fSpinning = true;
00281   MSG("PlotMan",Msg::kSynopsis) << "Spinning Chain";
00282   if(fUpdateInterval>0)
00283     MSG("PlotMan",Msg::kSynopsis) << " (update interval=" << fUpdateInterval << ")";
00284   if(fUpdateFraction>0)
00285     MSG("PlotMan",Msg::kSynopsis) << " (update fraction=" << fUpdateFraction << ")";
00286   MSG("PlotMan",Msg::kSynopsis) << endl;
00287   const AtmosEvent* event = 0;
00288   fChain->SetBranchAddress("evt",&event);
00289 
00290   int ThisTreeNumber = -1;
00291   int irun = 0;
00292   int i = fEvent+1;//Start at fEvent+1 to not double count events
00293   MSG("PlotMan",Msg::kSynopsis) << "\r on entry " << i;
00294   if(fEntries>0) MSG("PlotMan",Msg::kSynopsis) << " of " << fEntries;
00295   MSG("PlotMan",Msg::kSynopsis) << flush;
00296   for (; fChain->GetEntry(i)>0; i++) {
00297     bool ThisRetStatus = this->FillCamEvent(event);
00298     if(fProgress) fProgress->Increment(1);
00299 
00300     if(fUpdateInterval>0) if (i%fUpdateInterval == 0) {
00301       MSG("PlotMan",Msg::kSynopsis) << "\r on entry " << i;
00302       if(fEntries>0) MSG("PlotMan",Msg::kSynopsis) << " of " << fEntries;
00303       MSG("PlotMan",Msg::kSynopsis) << flush;
00304       if (ThisRetStatus) {
00305         this->UpdateCanvases();
00306         if(fUpdateSleep>0) gSystem->Sleep(fUpdateSleep);
00307       }
00308 
00309       if(cgSnarl) cgSnarl->SetNumber(event->Snarl);
00310       if(cgRun) cgRun->SetNumber(event->Run);
00311       if(cgSubRun) cgSubRun->SetNumber(event->SubRun);
00312     }
00313 
00314     if (fUpdateFraction>0 && fEntries>0) {
00315       double upinter = (double)fEntries / (double)fUpdateFraction;
00316       int iinter = (int)(i/upinter);
00317       if (((double)i - iinter*upinter) < 1.) {
00318         MSG("PlotMan",Msg::kSynopsis) << "\r on entry " << i;
00319         if(fEntries>0) MSG("PlotMan",Msg::kSynopsis) << " of " << fEntries;
00320         MSG("PlotMan",Msg::kSynopsis) << flush;
00321         if (ThisRetStatus) {
00322           this->UpdateCanvases();
00323           if(fUpdateSleep>0) gSystem->Sleep(fUpdateSleep);
00324         }
00325       }
00326 
00327       if(cgSnarl) cgSnarl->SetNumber(event->Snarl);
00328       if(cgRun) cgRun->SetNumber(event->Run);
00329       if(cgSubRun) cgSubRun->SetNumber(event->SubRun);
00330     }
00331 
00332     if (fChain->GetTreeNumber() != ThisTreeNumber) {
00333       MSG("PlotMan",Msg::kSynopsis) << "\r on tree " << fChain->GetTreeNumber() + 1
00334              << " of " << fChain->GetNtrees() << flush;
00335       ThisTreeNumber = fChain->GetTreeNumber();
00336     }
00337 
00338     gSystem->ProcessEvents();
00339 
00340     irun++;
00341     if(nevents>0 && irun>=nevents) break;
00342 
00343     if(fStopSpinning) break;
00344   }
00345   MSG("PlotMan",Msg::kSynopsis) << endl;
00346   MSG("PlotMan",Msg::kSynopsis) << "Ran " << irun << " events in this spin" << endl;
00347   fEvent = i;
00348 
00349   for (unsigned int i=0;i<fCamAnas.size();i++) {
00350     MSG("PlotMan",Msg::kSynopsis) << "Ana " << fCamAnas[i]->GetName() << "\t\t"
00351            << "Passed " << fEventsPassed[i]
00352            << " of " << fEventsRun[i] << " Events" << endl;
00353   }
00354 
00355   fSpinning = false;
00356   fStopSpinning = false;
00357   if(fDoFinish) this->FinishSpin();
00358   MSG("PlotMan",Msg::kSynopsis) << "Done Spinning Chain" << endl;
00359 }
00360 
00361 void PlotMan::StepEvent(int nevents)
00362 {
00363   if (fSpinning)  {
00364     MSG("PlotMan",Msg::kWarning)<< "Can't step while spinning Chain" << endl;
00365     return;
00366   }
00367   if(!fChainBuilt) BuildChain();
00368 
00369   fSpinning = true;
00370   MSG("PlotMan",Msg::kSynopsis) << "Stepping chain by " << nevents << " events" << endl;
00371   const AtmosEvent* event = 0;
00372   fChain->SetBranchAddress("evt",&event);
00373 
00374   int i = fEvent+nevents;
00375 
00376   if(i<0) i = 0;
00377   if(i>=fEntries) i = fEntries-1;
00378 
00379   if (fChain->GetEntry(i)) {
00380     this->FillCamEvent(event);
00381     this->UpdateCanvases();
00382     if(fProgress) fProgress->Increment(nevents);
00383     if(cgSnarl) cgSnarl->SetNumber(event->Snarl);
00384     if(cgRun) cgRun->SetNumber(event->Run);
00385     if(cgSubRun) cgSubRun->SetNumber(event->SubRun);
00386   }
00387   else {
00388     MSG("PlotMan",Msg::kWarning)<< "Chain could not get entry " << i << endl;
00389   }
00390 
00391   fEvent = i;
00392   fSpinning = false;
00393   fStopSpinning = false;
00394   MSG("PlotMan",Msg::kInfo) << "Done stepping Chain" << endl;
00395 }
00396 
00397 void PlotMan::StepPassEvent(int nevents)
00398 {
00399   if (fSpinning)  {
00400     MSG("PlotMan",Msg::kInfo) << "Can't step while spinning Chain" << endl;
00401     return;
00402   }
00403   if(!fChainBuilt) BuildChain();
00404 
00405   fSpinning = true;
00406   MSG("PlotMan",Msg::kInfo) << "Stepping chain by " << nevents << " events"
00407                             << endl;
00408   const AtmosEvent* event = 0;
00409   fChain->SetBranchAddress("evt",&event);
00410 
00411   int i = fEvent+1;
00412   if(nevents<0) i = fEvent-1;
00413 
00414   if(i<0) i = 0;
00415   if(i>=fEntries) i = fEntries-1;
00416 
00417   if(fChain->GetEntry(i) == 0) return;
00418   int npassed = 0;
00419 
00420   while (nevents > 0 && npassed < nevents) {
00421     while (!this->FillCamEvent(event)) {
00422       i++;
00423       if(fChain->GetEntry(i) == 0) fStopSpinning = true;
00424       if(fProgress) fProgress->Increment(1);
00425       gSystem->ProcessEvents();
00426       if(fStopSpinning) break;
00427     }
00428     if(fStopSpinning) break;
00429     npassed++;
00430   }
00431 
00432   while (nevents < 0 && npassed < -nevents) {
00433     while (!this->FillCamEvent(event)) {
00434       i--;
00435       if(fChain->GetEntry(i) == 0) fStopSpinning = true;
00436       if(fProgress) fProgress->Increment(1);
00437       gSystem->ProcessEvents();
00438       if(fStopSpinning) break;
00439     }
00440     if(fStopSpinning) break;
00441     npassed++;
00442   }
00443 
00444   if(cgSnarl && event) cgSnarl->SetNumber(event->Snarl);
00445   if(cgRun && event) cgRun->SetNumber(event->Run);
00446   if(cgSubRun && event) cgSubRun->SetNumber(event->SubRun);
00447   this->UpdateCanvases();
00448 
00449   fEvent = i;
00450   fSpinning = false;
00451   fStopSpinning = false;
00452   MSG("PlotMan",Msg::kInfo) << "Done stepping Chain" << endl;
00453 }
00454 
00455 void PlotMan::JumpToEvent(int ievent) {
00456   if (fSpinning)  {
00457     MSG("PlotMan",Msg::kInfo) << "Can't step while spinning Chain" << endl;
00458     return;
00459   }
00460   if(!fChainBuilt) BuildChain();
00461 
00462   fSpinning = true;
00463   MSG("PlotMan",Msg::kInfo) << "Jumping to event " << ievent << endl;
00464   const AtmosEvent* event = 0;
00465   fChain->SetBranchAddress("evt", &event);
00466 
00467   int i = ievent;
00468 
00469   if(i<0) i = 0;
00470   if(i>=fEntries) i = fEntries - 1;
00471 
00472   if (fChain->GetEntry(i) != 0) {
00473     this->FillCamEvent(event);
00474     this->UpdateCanvases();
00475     if(fProgress) fProgress->SetPosition(i);
00476     if(cgSnarl) cgSnarl->SetNumber(event->Snarl);
00477     if(cgRun) cgRun->SetNumber(event->Run);
00478     if(cgSubRun) cgSubRun->SetNumber(event->SubRun);
00479   }
00480 
00481   fEvent = i;
00482   fSpinning = false;
00483   fStopSpinning = false;
00484   MSG("PlotMan",Msg::kInfo) << "Done stepping Chain" << endl;
00485 }
00486 
00487 void PlotMan::ManSnarlJump() {
00488   if(!cgSnarl) return;
00489   JumpToSnarl((int)cgSnarl->GetNumber());
00490 }
00491 
00492 void PlotMan::ManRunJump() {
00493   if(!cgRun || !cgSubRun) return;
00494   JumpToRun((int)cgRun->GetNumber()*100 + (int)cgSubRun->GetNumber());
00495 }
00496 
00497 void PlotMan::SetUpdateSleep(int sleep) {
00498   if(sleep < 0) return;
00499   fUpdateSleep = sleep;
00500   MSG("PlotMan",Msg::kSynopsis) << "Setting Update Sleep to " << fUpdateSleep
00501                                 << "ms" << endl;
00502   if(cgSleep) cgSleep->SetNumber(sleep);
00503 }
00504 
00505 void PlotMan::ManUpdateSleep() {
00506   if(!cgSleep) return;
00507   fUpdateSleep = (int)cgSleep->GetNumber();
00508   MSG("PlotMan",Msg::kSynopsis) << "Setting Update Sleep to " << fUpdateSleep
00509                                 << "ms" << endl;
00510 }
00511 
00512 void PlotMan::JumpToSnarl(int snarl) {
00513   if (fSpinning)  {
00514     MSG("PlotMan",Msg::kInfo) << "Can't jump while spinning Chain" << endl;
00515     return;
00516   }
00517   if(!fChainBuilt) BuildChain();
00518 
00519   int ToSnarl = snarl;
00520 
00521   MSG("PlotMan",Msg::kInfo) << "Jumping to snarl " << ToSnarl << endl;
00522   fSpinning = true;
00523   const AtmosEvent* event = 0;
00524   fChain->SetBranchAddress("evt", &event);
00525 
00526   int i = fEvent+1;
00527 
00528   if(i<0) i = 0;
00529   //if(i>=fEntries) i = fEntries-1;
00530 
00531   MSG("PlotMan",Msg::kSynopsis) << " Starting at i = " << i << endl;
00532   MSG("PlotMan",Msg::kSynopsis) << " Chain has nentries = "
00533                                 << fChain->GetEntries() << endl;
00534   for (; fChain->GetEntry(i)>0; i++) {
00535     if(event->Snarl >= ToSnarl) break;
00536     gSystem->ProcessEvents();
00537     if(fStopSpinning) break;
00538   }
00539   MSG("PlotMan",Msg::kSynopsis) << " Ending at i = " << i << endl;
00540 
00541   FillCamEvent(event);
00542   UpdateCanvases();
00543   if(fProgress) fProgress->SetPosition(i);
00544   if(cgSnarl) cgSnarl->SetNumber(event->Snarl);
00545 
00546   fEvent = i;
00547   fSpinning = false;
00548   fStopSpinning = false;
00549   MSG("PlotMan",Msg::kInfo) << "Done jumping through chain" << endl;
00550 }
00551 
00552 void PlotMan::JumpToRun(int run) {
00553   if (fSpinning)  {
00554     MSG("PlotMan",Msg::kInfo) << "Can't jump while spinning Chain" << endl;
00555     return;
00556   }
00557   if(!fChainBuilt) BuildChain();
00558 
00559   int ToRun = run;
00560 
00561   MSG("PlotMan",Msg::kInfo) << "Jumping to run " << ToRun << endl;
00562   fSpinning = true;
00563   const AtmosEvent* event = 0;
00564   fChain->SetBranchAddress("evt", &event);
00565 
00566   int i = fEvent+1;
00567 
00568   if(i<0) i = 0;
00569   //if(i>=fEntries) i = fEntries-1;
00570 
00571   MSG("PlotMan",Msg::kSynopsis) << " Starting at i = " << i << endl;
00572   MSG("PlotMan",Msg::kSynopsis) << " Chain has nentries = "
00573                                 << fChain->GetEntries() << endl;
00574   for (; fChain->GetEntry(i)>0; i++) {
00575     if(((event->Run*100)+event->SubRun) >= ToRun) break;
00576     gSystem->ProcessEvents();
00577     if(fStopSpinning) break;
00578   }
00579   MSG("PlotMan",Msg::kSynopsis) << " Ending at i = " << i << endl;
00580 
00581   FillCamEvent(event);
00582   UpdateCanvases();
00583   if(fProgress) fProgress->SetPosition(i);
00584   if(cgRun) cgRun->SetNumber(event->Run);
00585   if(cgSubRun) cgSubRun->SetNumber(event->SubRun);
00586 
00587   fEvent = i;
00588   fSpinning = false;
00589   fStopSpinning = false;
00590   MSG("PlotMan",Msg::kInfo) << "Done jumping through chain" << endl;
00591 }
00592 
00593 bool PlotMan::FillCamEvent(const AtmosEvent* event) {
00594   if (!event) {
00595     MSG("PlotMan",Msg::kWarning) << "FillCamEvent has empty AtmosEvent" << endl;
00596     return false;
00597   }
00598 
00599   bool RetStatus = true;
00600   bool FillStatus = true;
00601   for (unsigned int i=0;i<fCamAnas.size();i++) {
00602     RetStatus = false;
00603     fEventsRun[i]++;
00604     FillStatus = fCamAnas[i]->FillEvent(event);
00605     if(!(FillStatus^fFilterRev[i]) && fFilterOn[i]) break;
00606     fEventsPassed[i]++;
00607     RetStatus = true;
00608   }
00609   return RetStatus;
00610 }
00611 
00612 void PlotMan::FinishSpin()
00613 {
00614   for(unsigned int i=0;i<fCamAnas.size();i++) fCamAnas[i]->Finish();
00615 }
00616 
00617 void PlotMan::UpdateCanvases(TFolder *tfol)
00618 {
00619   if(gROOT->IsBatch()) return;
00620   //For empty parameter, start at the top
00621   TFolder *tf = tfol;
00622   if (!tf) {
00623     HistMan hm("");
00624     tf = &(hm.BaseFolder());
00625   }
00626 
00627   TCollection *flist = tf->GetListOfFolders();
00628   TIter itr(flist->MakeIterator());
00629   TObject *fobj = 0;
00630   while ( (fobj=itr()) ) {
00631     if (fobj->InheritsFrom("TFolder")) {
00632       this->UpdateCanvases(dynamic_cast<TFolder*>(fobj));
00633       continue;
00634     }
00635     if (fobj->InheritsFrom("TCanvas")) {
00636       TCanvas *tc = dynamic_cast<TCanvas*>(fobj);
00637       tc->Modified();
00638       TList *tl = tc->GetListOfPrimitives();
00639       for (int j=0;j<tl->GetSize();j++) {
00640         if(! tl->At(j)->InheritsFrom("TPad")) continue;
00641         TPad *tp = dynamic_cast<TPad*>(tl->At(j));
00642         tp->Modified();
00643       }
00644       tc->Update();
00645     }
00646   }
00647 
00648   /*
00649   for (unsigned int i=0;i<fCanvases.size();i++) {
00650     fCanvases[i]->Modified();
00651     TList *tl = fCanvases[i]->GetListOfPrimitives();
00652     for (int j=0;j<tl->GetSize();j++) {
00653       if(! tl->At(j)->InheritsFrom("TPad")) continue;
00654       TPad *thispad = dynamic_cast<TPad*>(tl->At(j));
00655       thispad->Modified();
00656     }
00657     fCanvases[i]->Update();
00658   }
00659   */
00660   return;
00661 }
00662 
00663 /*
00664 void PlotMan::PrintCanvases(string fn) {
00665   if (fCanvases.size() == 0) return;
00666   fCanvases[0]->Print((fn+"[").c_str());
00667   for (unsigned int i=0;i<fCanvases.size();i++) {
00668     fCanvases[i]->Print(fn.c_str());
00669   }
00670   fCanvases[0]->Print((fn+"]").c_str());
00671   return;
00672 }
00673 */
00674 
00675 void PlotMan::WriteOut(string fn)
00676 {
00677   HistMan hm("");
00678   hm.WriteOut(fn.c_str());
00679 }
00680 
00681 void PlotMan::SetEntries(int entries)
00682 {
00683   fEntries = entries;
00684   if(fProgress) fProgress->SetRange(0,fEntries);
00685 }
00686 
00687 void PlotMan::Reset()
00688 {
00689   if (fSpinning)  {
00690     MSG("PlotMan",Msg::kInfo) << "Can't reset while spinning Chain" << endl;
00691     return;
00692   }
00693 
00694   fChain->Reset();
00695   fEntries = 0;
00696 
00697   MSG("PlotMan",Msg::kInfo) << "Resetting PlotMan" << endl;
00698   fEvent=0;
00699   if(fProgress) fProgress->Reset();
00700   for(unsigned int i=0;i<fCamAnas.size();i++) fCamAnas[i]->Reset();
00701 }
00702 
00703 void PlotMan::SetLoud(int loud, string lstream)
00704 {
00705   if(loud<=0) gErrorIgnoreLevel = kFatal;
00706   MsgStream *s = MsgService::Instance()->GetStream(lstream.c_str());
00707 
00708   if(loud>= 4) s->SetLogLevel(Msg::kVerbose);
00709   if(loud== 3) s->SetLogLevel(Msg::kDebug);
00710   if(loud== 2) s->SetLogLevel(Msg::kSynopsis);
00711   if(loud== 1) s->SetLogLevel(Msg::kInfo);
00712   if(loud== 0) s->SetLogLevel(Msg::kWarning);
00713   if(loud==-1) s->SetLogLevel(Msg::kError);
00714   if(loud<=-2) s->SetLogLevel(Msg::kFatal);
00715 }
00716 
00717 int PlotMan::GetLoud(string lstream)
00718 {
00719   MsgStream *s = MsgService::Instance()->GetStream(lstream.c_str());
00720 
00721   Msg::LogLevel_t loglevel = s->GetLogLevel();
00722   if(loglevel==Msg::kVerbose) return 4;;
00723   if(loglevel==Msg::kDebug) return 3;
00724   if(loglevel==Msg::kSynopsis) return 2;
00725   if(loglevel==Msg::kInfo) return 1;
00726   if(loglevel==Msg::kWarning) return 0;
00727   if(loglevel==Msg::kError) return -1;
00728   if(loglevel==Msg::kFatal) return -2;
00729   return 0;
00730 }
00731 
00732 void PlotMan::ControlWindow(const TGWindow *p, UInt_t w, UInt_t h)
00733 {
00734   TGLayoutHints *cgLayout =
00735     new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);
00736 
00737   TGCompositeFrame *cgH1 = 0;
00738   TGLabel *cgLabel = 0;
00739 
00740   cgMain = new TGMainFrame(p, w, h);
00741   cgMain->SetCleanup(kDeepCleanup);
00742   cgMain->Connect("CloseWindow()","PlotMan",this,"CloseWindow()");
00743 
00744   TGTextButton *cgStart = new TGTextButton(cgMain, "Start", 1);
00745   cgStart->Connect("Clicked()","PlotMan",this,"SpinChain()");
00746   cgMain->AddFrame(cgStart, cgLayout);
00747 
00748   TGTextButton *cgStop = new TGTextButton(cgMain, "&Stop", 2);
00749   cgStop->Connect("Clicked()","PlotMan",this,"StopSpinning()");
00750   cgMain->AddFrame(cgStop, cgLayout);
00751 
00752   cgH1 = new TGHorizontalFrame(cgMain);
00753 
00754   cgLabel = new TGLabel(cgH1,"Sleep(ms):");
00755   cgH1->AddFrame(cgLabel, new TGLayoutHints(kLHintsLeft | kLHintsExpandY));
00756 
00757   cgSleep = new TGNumberEntry(cgH1, 0, 5, -1);
00758   cgSleep->Connect("ValueSet(Long_t)", "PlotMan", this, "ManUpdateSleep()");
00759   cgH1->AddFrame(cgSleep, cgLayout);
00760 
00761   cgMain->AddFrame(cgH1, cgLayout);
00762 
00763   TGTextButton *cgNextPass = new TGTextButton(cgMain, "&NextPass", 3);
00764   cgNextPass->Connect("Clicked()","PlotMan",this,"StepPassEvent(=1)");
00765   cgMain->AddFrame(cgNextPass, cgLayout);
00766 
00767   TGTextButton *cgPrevPass = new TGTextButton(cgMain, "&PrevPass", 3);
00768   cgPrevPass->Connect("Clicked()","PlotMan",this,"StepPassEvent(=-1)");
00769   cgMain->AddFrame(cgPrevPass, cgLayout);
00770 
00771   TGTextButton *cgNext = new TGTextButton(cgMain, "&Next", 3);
00772   cgNext->Connect("Clicked()","PlotMan",this,"Next()");
00773   cgMain->AddFrame(cgNext, cgLayout);
00774 
00775   TGTextButton *cgPrev = new TGTextButton(cgMain, "&Prev", 4);
00776   cgPrev->Connect("Clicked()","PlotMan",this,"Prev()");
00777   cgMain->AddFrame(cgPrev, cgLayout);
00778 
00779   //Run Number Entry
00780   cgH1 = new TGHorizontalFrame(cgMain);
00781   cgLabel = new TGLabel(cgH1, "Run:");
00782   cgH1->AddFrame(cgLabel, new TGLayoutHints(kLHintsLeft | kLHintsExpandY));
00783   cgRun = new TGNumberEntry(cgH1, 0, 5, -1);
00784   cgRun->Connect("ValueSet(Long_t)", "PlotMan", this, "ManRunJump()");
00785   cgH1->AddFrame(cgRun, cgLayout);
00786   cgMain->AddFrame(cgH1, cgLayout);
00787 
00788   //SubRun Number Entry
00789   cgH1 = new TGHorizontalFrame(cgMain);
00790   cgLabel = new TGLabel(cgH1, "SubRun:");
00791   cgH1->AddFrame(cgLabel, new TGLayoutHints(kLHintsLeft | kLHintsExpandY));
00792   cgSubRun = new TGNumberEntry(cgH1, 0, 5, -1);
00793   cgSubRun->Connect("ValueSet(Long_t)", "PlotMan", this, "ManRunJump()");
00794   cgH1->AddFrame(cgSubRun, cgLayout);
00795   cgMain->AddFrame(cgH1, cgLayout);
00796 
00797   //Snarl Number Entry
00798   cgH1 = new TGHorizontalFrame(cgMain);
00799   cgLabel = new TGLabel(cgH1, "Snarl:");
00800   cgH1->AddFrame(cgLabel, new TGLayoutHints(kLHintsLeft | kLHintsExpandY));
00801   cgSnarl = new TGNumberEntry(cgH1, 0, 5, -1);
00802   cgSnarl->Connect("ValueSet(Long_t)", "PlotMan", this, "ManSnarlJump()");
00803   cgH1->AddFrame(cgSnarl, cgLayout);
00804   cgMain->AddFrame(cgH1, cgLayout);
00805 
00806   TGTextButton *tgReDraw = new TGTextButton(cgMain, "&ReDraw", 4);
00807   tgReDraw->Connect("Clicked()","PlotMan",this,"ReDraw()");
00808   cgMain->AddFrame(tgReDraw, cgLayout);
00809 
00810   TGTextButton *cgReset = new TGTextButton(cgMain, "&Reset", 5);
00811   cgReset->Connect("Clicked()","PlotMan",this,"Reset()");
00812   cgMain->AddFrame(cgReset, cgLayout);
00813 
00814   TGTextButton *cgQuit = new TGTextButton(cgMain, "&Quit", 6);
00815   cgQuit->Connect("Clicked()","PlotMan",this,"CloseWindow()" );
00816   cgMain->AddFrame(cgQuit, cgLayout);
00817 
00818   fProgress = new TGHProgressBar(cgMain,100);
00819   fProgress->SetBarColor("lightgreen");
00820   fProgress->ShowPosition();
00821   cgMain->AddFrame(fProgress, cgLayout);
00822 
00823   cgMain->MapSubwindows();
00824   cgMain->Resize();
00825 
00826   cgMain->Layout();
00827 
00828   cgMain->SetWindowName("Ntp Control Window");
00829   cgMain->SetIconName("Ntp Control Window");
00830 
00831   cgMain->MapWindow();
00832 }
00833 
00834 void PlotMan::CloseWindow() {
00835   if (fSpinning)  {
00836     MSG("PlotMan",Msg::kInfo) << "Can't close window while spinning Chain" << endl;
00837     return;
00838   }
00839   if(gApplication) gApplication->Terminate();
00840 }

Generated on Mon Feb 15 11:07:24 2010 for loon by  doxygen 1.3.9.1