#include #include #include #include "hdview2.h" #include "MyProcessor.h" int GO = 0; // 1=continuously display events 0=wait for user bool PRINT_FACTORY_LIST = false; TCanvas *maincanvas=NULL; extern JApplication *japp; JEventLoop *eventloop =NULL; MyProcessor *myproc = NULL; void PrintFactoryList(JApplication *japp); void ParseCommandLineArguments(int &narg, char *argv[], JApplication *japp); void Usage(JApplication *japp); //------------------- // main //------------------- int main(int narg, char *argv[]) { // Parse the command line arguments ParseCommandLineArguments(narg, argv, japp); // Instantiate a DApplication object. This has to be done BEFORE // creating the TApplication object since that modifies the argument list. japp = new DApplication(narg, argv); // Create a ROOT TApplication object TApplication app("HDView", &narg, argv); // This is done AFTER creating the TApplication object so when the // init routine is called, the window will be mapped and it can // draw the detectors. myproc = new MyProcessor(); japp->AddProcessor(myproc); // Call the JApplication's Init() routine to attach any plugins japp->Init(); // Create the JEventLoop object explicitly. eventloop = new JEventLoop(japp); eventloop->SetAutoFree(0); // prevent auto-freeing of event after OneEvent is called // We need to re-call myproc->init here (it was already called from the japp->Init() // call above). This is because the previous call was done before the JEventLoop // object existed and so the hdv_mainframe object wasn't created etc... We have // to call japp->Init() before instantiated the JEventLoop so that the plugins // are attached and the JEventLoop can capture the full list of factories and // processors. myproc->init(); // If the PRINT_FACTORY_LIST flag was set, then print the factory list if(PRINT_FACTORY_LIST)PrintFactoryList(japp); // Process the first event eventloop->OneEvent(); // Hand control to the ROOT "event" loop japp->GetJParameterManager()->PrintParameters(); app.SetReturnFromRun(true); app.Run(); // Clean-up the app (call erun and fini methods, delete sources) //japp->Fini(); // This now actually done in hdv_mainframe::DoQuit() if(japp)delete japp; return 0; } //----------- // PrintFactoryList //----------- void PrintFactoryList(JApplication *japp) { // When we get here, the Run() method hasn't been // called so the JEventLoop objects haven't // been created yet and cansequently the factory objects // don't yet exist. Since we want the "list factories" // option to work even without an input file, we need // to first make the factories before we can list them. // To do this we only need to instantiate a JEventLoop object // passing it our "app" pointer. The JEventLoop will automatically // register itself with the DApplication and the factories // will be made, even ones from plugins passed on the command // line. vector loops = japp->GetJEventLoops(); if(loops.size()<1){ _DBG_<<"No JEventLoops in japp!"< factories = loop->GetFactories(); vector::iterator iter = factories.begin(); for(; iter!=factories.end(); iter++){ cout<<" "<<(*iter)->GetDataClassName(); if(strlen((*iter)->Tag()) !=0){ cout<<" : "<<(*iter)->Tag(); } cout<Usage(); cout<