daqview.cc
Go to the documentation of this file.00001
00006 #include "Reader.hh"
00007 #include "ConfigHandler.hh"
00008 #include "CommandSwitchFunctions.hh"
00009 #include "V172X_Params.hh"
00010 #include "ProcessedPlotter.hh"
00011 #include "SumChannels.hh"
00012 #include "V172X_Event.hh"
00013 #include "EventHandler.hh"
00014 #include "Message.hh"
00015 #include "RootGraphix.hh"
00016 #include "TFile.h"
00017 #include "TCanvas.h"
00018 #include <fstream>
00019 #include <string>
00020 #include <exception>
00021 #include <stdlib.h>
00022
00023 using namespace std;
00025 void SaveCanvas(const TCanvas* c, const char* name)
00026 {
00027 TFile fout("daqview.root","UPDATE");
00028 if(!fout.IsOpen() || fout.IsZombie()){
00029 Message(ERROR)<<"Unable to open file daqview.root to save canvas!\n";
00030 }
00031 if(c)
00032 c->Write(name);
00033 }
00034
00035 int main(int argc, char** argv)
00036 {
00037 ConfigHandler* config = ConfigHandler::GetInstance();
00038 config->SetProgramUsageString("daqview [options] <filename> [<event>]");
00039 EventHandler* modules = EventHandler::GetInstance();
00040 modules->AddCommonModules();
00041
00042 RootGraphix* rootgraphix = new RootGraphix;
00043 modules->AddModule(rootgraphix, false, true);
00044 ProcessedPlotter* plotter = new ProcessedPlotter;
00045 modules->AddModule(plotter);
00046 modules->AddModule(rootgraphix, true, false);
00047
00048
00049 string list_filename="";
00050 config->AddCommandSwitch('l',"event-list",
00051 "Read the events to display from <file>",
00052 CommandSwitch::DefaultRead<string>(list_filename),
00053 "file");
00054 int printlevel;
00055 config->RegisterParameter("printlevel",printlevel = 1,
00056 "Event print verbosity (0=NONE to 3=All info)");
00057 config->AddCommandSwitch(' ',"printlevel",
00058 "Event print verbosity (0=NONE to 3=All info)",
00059 CommandSwitch::DefaultRead<int>(printlevel),
00060 "level");
00061
00062
00063 config->SetDefaultCfgFile("daqview.cfg");
00064 if(config->ProcessCommandLine(argc,argv))
00065 return -1;
00066 if(argc != 3 && argc != 2){
00067 Message(ERROR)<<"Incorrect number of arguments: "<<argc<<std::endl;
00068 config->PrintSwitches(true);
00069 }
00070 ifstream eventlist;
00071 bool use_elist = false;
00072 if(list_filename != ""){
00073 eventlist.open(list_filename.c_str());
00074 if(!eventlist.is_open()){
00075 Message(ERROR)<<"Unable to open event-list file "<<list_filename<<endl;
00076 return -1;
00077 }
00078 use_elist = true;
00079 }
00080
00081
00082 std::string fname(argv[1]);
00083 Reader reader(fname.c_str());
00084 if(!reader.IsOk())
00085 return 1;
00086 int next_evt = 0;
00087 if (argc == 3 ) next_evt = atoi(argv[2]);
00088 else if(use_elist) eventlist>>next_evt;
00089 if(modules->Initialize()){
00090 Message(ERROR)<<"Unable to initialize all modules.\n";
00091 return 1;
00092 }
00093 while(reader.IsOk() && !reader.eof()){
00094 RawEventPtr raw = reader.GetEventWithID(next_evt);
00095 if(!raw){
00096 if(!reader.eof())
00097 Message(ERROR)<<"Problem encountered reading event "<<next_evt<<"\n";
00098 else
00099 Message(INFO)<<"Reached end of file series.\n";
00100 break;
00101 }
00102 else{
00103 Message(DEBUG)<<"Processing event...\n";
00104 modules->Process(raw);
00105 if( plotter->GetLastProcessReturn()){
00106
00107 next_evt++;
00108 continue;
00109 }
00110 Message(DEBUG)<<"Done!\n";
00111 Message(DEBUG)<<"Current event has file index "<<reader.GetCurrentIndex()
00112 <<" and ID "<<raw->GetID()<<"\n";
00113 modules->GetCurrentEvent()->GetEventData()->Print(printlevel);
00114
00115 }
00116 int this_evt = next_evt;
00117 if(use_elist){
00118 if( !(eventlist>>next_evt)){
00119 Message(INFO)<<"Reached end event-list file.\n";
00120 next_evt = this_evt+1;
00121 }
00122 }
00123 else
00124 next_evt = this_evt+1;
00126 Message(INFO)<<"Enter the next event to view; <enter> for "<<next_evt
00127 <<", s to save this canvas, q or -1 to quit\n";
00128 std::string line;
00129 getline(std::cin, line);
00130 if( line == "" )
00131 {}
00132 else if(line == "q" || line == "Q" || line == "-1"){
00133 Message(DEBUG)<<"Quitting\n";
00134 break;
00135 }
00136 else if(line == "s" || line == "S"){
00137 Message(INFO)<<"Saving canvas to file daqview.root.\n";
00138 char name[30];
00139 sprintf(name, "Event%d_1",next_evt);
00140 SaveCanvas(plotter->GetCanvas(0),name);
00141 sprintf(name, "Event%d_2",next_evt);
00142 SaveCanvas(plotter->GetCanvas(1),name);
00143 }
00144 else{
00145 next_evt = atoi(line.c_str());
00146 }
00147 }
00148 modules->Finalize();
00149 return 0;
00150 }