EventHandler.hh

Go to the documentation of this file.
00001 
00007 #ifndef EVENTHANDLER_h
00008 #define EVENTHANDLER_h
00009 
00010 #include "ParameterList.hh"
00011 #include "Event.hh"
00012 #include "runinfo.hh"
00013 #include <string>
00014 #include <vector>
00015 
00016 class BaseModule;
00017 class AsyncEventHandler;
00018 
00023 class EventHandler : public ParameterList{
00024 private:
00026   EventHandler();
00028   EventHandler(const EventHandler& right);
00030   EventHandler& operator=(const EventHandler& right);
00031 
00032 public:
00034   static EventHandler* GetInstance();
00036   ~EventHandler();
00037   
00039   int AddModule(BaseModule* mod, 
00040                 bool processme = true,
00041                 bool registerme = true);
00043   BaseModule* GetModule(const std::string& modname);
00044   
00047   template<class Module> 
00048   Module* AddModule(const std::string& name=Module::GetDefaultName(),
00049                     bool processme = true,
00050                     bool registerme = true);
00052   template<class Module>
00053   Module* GetModule(const std::string& name=Module::GetDefaultName());
00054   
00056   int AddCommonModules(); 
00057   
00059   void  AddAsyncReceiver(AsyncEventHandler* handler)
00060   { if(handler) _async_receivers.push_back(handler); }
00062   void ClearAsyncReceivers(){ _async_receivers.clear(); }
00063   
00064   //public interface functions
00065   //return 0 if no errors
00067   int Initialize();
00069   int Process(RawEventPtr raw);
00071   int Process(EventPtr evt);
00073   int Finalize();
00074   
00076   EventPtr GetCurrentEvent(){ return _current_event; }
00078   const std::vector<BaseModule*>* GetListOfModules() const{ return &_modules; }
00080   std::vector<BaseModule*>* GetListOfModules(){ return &_modules;}
00082   const std::vector<BaseModule*>* GetProcessingModules() const 
00083   { return &_processing_modules; }
00085   std::vector<BaseModule*>* GetProcessingModules() 
00086   { return &_processing_modules;}
00087   
00089   void SetRunID(int id){ run_id = id; }
00091   int SetRunIDFromFilename(const std::string& filename);
00093   int GetRunID(){ return run_id; }
00095   runinfo* GetRunInfo(){ return &_runinfo; }
00097   void AllowDatabaseAccess(bool setval){ _access_database=setval; }
00099   bool GetFailOnBadCal() const { return _fail_on_bad_cal;}
00100 private:
00101   std::vector<BaseModule*> _modules;
00102   std::vector<BaseModule*> _processing_modules;
00103   std::vector<AsyncEventHandler*> _async_receivers;
00104   EventPtr _current_event;
00105   bool _is_initialized;  
00106   int run_id;
00107   runinfo _runinfo; 
00108   bool _access_database; 
00109   bool _fail_on_bad_cal; 
00110   
00111   bool _run_parallel;   
00112   std::vector<AsyncEventHandler*> _para_handlers;
00113 };
00114 
00115 #include "BaseModule.hh"
00116 
00117 template<class Module> inline 
00118 Module* EventHandler::AddModule(const std::string& name,
00119                                 bool processme,
00120                                 bool registerme)
00121 {
00122   for(std::vector<BaseModule*>::iterator it = _modules.begin(); 
00123       it != _modules.end(); it++){
00124     if( (*it)->GetName() == name && dynamic_cast<Module*>(*it) )
00125       return dynamic_cast<Module*>( *it );
00126   }
00127   //if we get here, this module doesn't exist yet, so add it
00128   BaseModule* newmod = new Module;
00129   newmod->SetName(name);
00130   AddModule(newmod, processme, registerme);
00131   return dynamic_cast<Module*>( newmod );
00132 }
00133 
00134 template<class Module> inline 
00135 Module* EventHandler::GetModule(const std::string& name)
00136 {
00137   for(std::vector<BaseModule*>::iterator it = _modules.begin(); 
00138       it != _modules.end(); it++){
00139     if( (*it)->GetName() == name && dynamic_cast<Module*>(*it) )
00140       return dynamic_cast<Module*>( *it );
00141   }
00142   //if we get here, this module doesn't exist yet
00143   return 0;
00144 }
00145 
00146 
00147 #endif
00148   
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on 20 Jun 2014 for daqman by  doxygen 1.6.1