> Date: Sat, 28 Apr 2001 15:10:15 -0400 > From: Vitaliy Ziskin <vziskin@mitlns.mit.edu> > Subject: [ROOT] Running more than one ttimer > > Is there a way to run more thatn one timer at the same time in the same > function. I seem to have difficultiy doing that. Would anyone have a > comprehensive example in which they utilize more than one ttimer. > > Thanks, Vitaliy I've attached a program that uses multiple TTimers. The code won't run as-is, since you'd need some libraries and input files that I haven't included. Just search for the text "Timer" and you'll see how I chose to do it. -- Bill Seligman | mailto://seligman@nevis.columbia.edu Nevis Labs | http://www.nevis.columbia.edu/~seligman/ PO Box 137 | Irvington NY 10533 | Phone: (914) 591-2823 // Simple analysis code for I/O timing studies. // Note the #ifdef's that depend on __CINT__. They are used because // this code is meant to be either compiled ("make analysis"), or be // interpreted ("root analysis.C", or type ".x analysis.C" within // ROOT). #ifndef __CINT__ #include "LArRootEvent.hh" #include "LArRootHit.hh" #include "RootInputInterface.h" #include "RootInputNull.h" #include "RootInputTree.h" #include "RootInputObject.h" #include "RootInputTDS.h" #include "RootInputTDSTree.h" #include "TROOT.h" #include "TObjectTable.h" #include "TFile.h" #include "TH1.h" #include "TStopwatch.h" #include <iostream> // Create the ROOT environment. TROOT rootBase("analysis","ROOT analysis environment"); int main(int argc, char* argv[]) { #else { gROOT->Reset(); // Test if we have to load shared libraries. For some reason, the // physics libraries are not normally loaded with the ROOT // interactive application. if (!TClassTable::GetDict("TVector3")) { cout << "Loading physics library..." << endl; gSystem->Load("libPhysics.so"); } else { cout << "Physics library already loaded" << endl; } if (!TClassTable::GetDict("TDataSet")) { cout << "Loading STAR library..." << endl; gSystem->Load("libStar.so"); } else { cout << "STAR library already loaded" << endl; } if (!TClassTable::GetDict("LArRootEvent")) { cout << "Loading LAr library..." << endl; gSystem->Load("lib/LArDictionary.so"); } else { cout << "LAr library already loaded" << endl; } #endif // Setup timers. When you create a TStopwatch, it automatically // starts. TStopwatch* programTimer = new TStopwatch(); TStopwatch* readTimer = new TStopwatch(); readTimer->Stop(); TStopwatch* convertTimer = new TStopwatch(); convertTimer->Stop(); TStopwatch* histTimer = new TStopwatch(); histTimer->Stop(); // If we're executing this via batch, accept command-line arguments. // If we're executing interactively, use hard-coded values. #ifdef __CINT__ Int_t argc = 3; Char_t* argv[3]; argv[0] = "analysis"; // name of program argv[1] = "tabletree"; // I/O method argv[2] = "/home/seligman/data/IOstudy/table-tree.root"; // input file #endif // Select the input method and filename. TString fileName = "IOStudy.root"; if (argc >= 3) { fileName = argv[2]; } TString ioMethod = "null"; if (argc >= 2) { ioMethod = argv[1]; } RootInputInterface* input = 0; if (ioMethod == "tree") { input = new RootInputTree(); } else if (ioMethod == "object") { input = new RootInputObject(); } else if (ioMethod == "table") { input = new RootInputTDS(); } else if (ioMethod == "tabletree") { input = new RootInputTDSTree(); } // If no method was selected, use "null". if (input == 0) { Int_t numberDummyEvents = 8000; Int_t numberDummyHits = 8602; input = new RootInputNull(numberDummyEvents,numberDummyHits); } // Open the input file. input->Open(fileName); // Create an output file for histograms. TString outputName = "/a/home/kolya/seligman/data/IOstudy/analysis-" + TString(ioMethod) + ".hist"; TFile* output = new TFile(outputName,"RECREATE","Analysis histograms"); // Make a histogram. Float_t maxLArEnergy = 0; TH1D* LArHist = new TH1D("LArEnergy", "Energy deposited in LAr barrel calorimeter",20,6.,12.); LArHist->SetDirectory(output); LArHist->SetYTitle("# events"); LArHist->SetXTitle("Energy [GeV]"); // For each event in the file (start the timer, read, then stop the timer)... Int_t eventCount = -1; readTimer->Start(kFALSE); while (input->Read()) { readTimer->Stop(); eventCount++; // Convert the event return a pointer ot it. convertTimer->Start(kFALSE); const LArRootEvent* event = input->ConvertEvent(); convertTimer->Stop(); histTimer->Start(kFALSE); Int_t numHits = event->GetNumberHits(); Double_t LArEnergy = 0; // Accumulate values for each hit in the event. for (Int_t j = 0; j < numHits; j++) { LArRootHit* hit = event->GetHit(j); Double_t energy = hit->GetEnergy(); LArEnergy += energy; } if (LArEnergy > maxLArEnergy) maxLArEnergy = LArEnergy; LArHist->Fill(LArEnergy); // Look for memory leaks. #ifdef __CINT__ if (eventCount%100 == 0) gObjectTable->Print(); #endif histTimer->Stop(); readTimer->Start(kFALSE); } readTimer->Stop(); cout << "maxLArEnergy=" << maxLArEnergy << endl; // Clean up the files and close them. output->Write(); output->Close(); input->Close(); delete input; delete output; // Display timers. cout << "Read timer: "; readTimer->Print(); cout << "Convert timer: "; convertTimer->Print(); cout << "Histogram timer: "; histTimer->Print(); cout << "Program timer: "; programTimer->Print(); delete readTimer; delete convertTimer; delete histTimer; delete programTimer; return (0); }
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:44 MET