// // Prototype of a Level-3 trigger program with full DANA // reconstuction capaibility that is also a RunObject // and so can communicate directly with the DAQ system. // July 27, 2009 DL // // This works by launching a thread to handle the RunObject // callbacks and having JANA launch its own threads for // event processing. #include #include using std::exception; // avoid compiler error about "ambiguous" defintion #include #include "RunObject_L3.h" #include "DEventProcessor_L3.h" using namespace std; using namespace codaObject; using namespace jana; RunObject_L3 *RUNOBJECT=NULL; pthread_mutex_t L3MUTEX; //----------------- // RunObjectThread //----------------- void* RunObjectThread(void *arg) { DApplication *dapp = (DApplication*)arg; string myName = "runTest"; string myUDL = "cMsg://localhost/cMsg"; string myDescr = "run object test"; try { RunObject_L3 rt(myUDL,myName,myDescr, dapp); RUNOBJECT = &rt; // start processing, wait until done, stop processing rt.startProcessing(); while(rt.isRunning()) {sleep(1);} rt.stopProcessing(); } catch (CodaException e) { cerr << e.toString() << endl; //std::exit(EXIT_FAILURE); } catch (...) { cerr << "?unknown exception" << endl; //std::exit(EXIT_FAILURE); } // Set the RUNOBJECT pointer to NULL so that // main() won't try calling exit pthread_mutex_lock(&L3MUTEX); RUNOBJECT=NULL; pthread_mutex_unlock(&L3MUTEX); cout<< " ---- Run Object thread done ----" << endl << endl; pthread_exit(NULL); } //----------------- // main //----------------- int main(int narg, char *argv[]) { // Create a mutex to serialize access to resources // common to both the CODAObjects and JANA systems pthread_mutex_init(&L3MUTEX, NULL); // Create DApplication for event processing DApplication *dapp = new DApplication(narg, argv); // Launch thread to handle communication with DAQ system pthread_t runobject_thread; pthread_create(&runobject_thread, NULL, RunObjectThread, dapp); // Process events until told to quit dapp->monitor_heartbeat = false; dapp->Run(new DEventProcessor_L3()); // Done with event processing. Tell runobject to quit // if he's still around. pthread_mutex_lock(&L3MUTEX); if(RUNOBJECT)RUNOBJECT->exit("Finished"); pthread_mutex_unlock(&L3MUTEX); return 0; } //------------------------------------------------------------------------------- //-------------------------------------------------------------------------------