CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/EventFilter/Processor/src/FUEventProcessor.h

Go to the documentation of this file.
00001 #ifndef FUEVENTPROCESSOR_H
00002 #define FUEVENTPROCESSOR_H 1
00003 
00004 #include "EventFilter/Utilities/interface/StateMachine.h"
00005 #include "EventFilter/Utilities/interface/RunBase.h"
00006 #include "EventFilter/Utilities/interface/Css.h"
00007 #include "EventFilter/Utilities/interface/Exception.h"
00008 #include "EventFilter/Utilities/interface/SquidNet.h"
00009 #include "EventFilter/Utilities/interface/Vulture.h"
00010 
00011 #include "EventFilter/Utilities/interface/MasterQueue.h"
00012 #include "EventFilter/Utilities/interface/SlaveQueue.h"
00013 #include "EventFilter/Utilities/interface/ModuleWeb.h"
00014 #include "EventFilter/Utilities/interface/ModuleWebRegistry.h"
00015 #include "EventFilter/Modules/interface/ShmOutputModuleRegistry.h"
00016 #include "SubProcess.h"
00017 #include "FWEPWrapper.h"
00018 
00019 #include "DataFormats/Provenance/interface/ModuleDescription.h"
00020 #include "FWCore/PluginManager/interface/PresenceFactory.h"
00021 
00022 #include "xdaq/Application.h"
00023 #include "xdaq/NamespaceURI.h"
00024 
00025 #include "xdata/String.h"
00026 #include "xdata/Integer.h"
00027 #include "xdata/Boolean.h"
00028 #include "xdata/Vector.h"
00029 #include "xdata/UnsignedInteger32.h"
00030 #include "xdata/ActionListener.h"
00031 #include "xdata/InfoSpaceFactory.h"
00032 
00033 #include "xgi/Input.h"
00034 #include "xgi/Output.h"
00035 #include "xgi/exception/Exception.h"
00036 
00037 #include <sys/time.h>
00038 #include <pthread.h>
00039 #include <sys/resource.h>
00040 #include <signal.h>
00041 
00042 #include <list>
00043 #include <vector>
00044 #include <map>
00045 
00046 namespace evf
00047 {
00048 
00049   /* to be filled in with summary from paths */
00050   struct filter {
00051 
00052   };
00053   class CPUStat;
00054   class RateStat;
00055   namespace internal{
00056     
00057     class MyCgi : public xgi::Input{
00058     public:
00059       MyCgi() : xgi::Input("",0){}
00060       //      MyCgi(xgi::Input &b) : xgi::Input("",0) {environment_ = b.environment_;}
00061       std::map<std::string, std::string, std::less<std::string> > &getEnvironment(){return environment_;}
00062     };
00063   }
00064   class FUEventProcessor : public xdaq::Application,
00065                            public xdata::ActionListener
00066   {
00067   public:
00068     //
00069     // construction/destruction
00070     //
00071     XDAQ_INSTANTIATOR();
00072     FUEventProcessor(xdaq::ApplicationStub *s);
00073     virtual ~FUEventProcessor();
00074     
00075 
00076     //
00077     // member functions
00078     //
00079 
00080     // work loop functions to be executed during transitional states (async)
00081     bool configuring(toolbox::task::WorkLoop* wl);
00082     bool enabling(toolbox::task::WorkLoop* wl);
00083     bool stopping(toolbox::task::WorkLoop* wl);
00084     bool halting(toolbox::task::WorkLoop* wl);
00085 
00086     // fsm soap command callback
00087     xoap::MessageReference fsmCallback(xoap::MessageReference msg)
00088       throw (xoap::exception::Exception);
00089         
00090     // xdata:ActionListener interface
00091     void actionPerformed(xdata::Event& e);
00092     
00093     // trigger report related helper functions
00094     //    std::string triggerReportToString(const edm::TriggerReport& tr);
00095     //    void triggerReportToTable(const edm::TriggerReport& tr);
00096     //    void        printTriggerReport(const edm::TriggerReport& tr);
00097 
00098     // HyperDAQ related functions
00099     void defaultWebPage(xgi::Input *in,xgi::Output *out)
00100       throw(xgi::exception::Exception);
00101     void spotlightWebPage(xgi::Input *,xgi::Output *)
00102       throw(xgi::exception::Exception);
00103     void scalersWeb(xgi::Input *,xgi::Output *)
00104       throw(xgi::exception::Exception);
00105     void pathNames(xgi::Input *,xgi::Output *)
00106       throw(xgi::exception::Exception);
00107     void css(xgi::Input *in,xgi::Output *out) throw (xgi::exception::Exception)
00108     {
00109       css_.css(in,out);
00110     }
00111 
00112     void getSlavePids(xgi::Input  *in, xgi::Output *out) throw (xgi::exception::Exception);
00113     void subWeb(xgi::Input *in,xgi::Output *out) throw (xgi::exception::Exception);
00114     void moduleWeb(xgi::Input *in,xgi::Output *out) throw (xgi::exception::Exception) {evtProcessor_.moduleWeb(in,out);}
00115     void serviceWeb(xgi::Input *in,xgi::Output *out) throw (xgi::exception::Exception) {evtProcessor_.serviceWeb(in,out);}
00116     void microState(xgi::Input *in,xgi::Output *out) throw (xgi::exception::Exception);
00117     void updater(xgi::Input *in,xgi::Output *out) throw (xgi::exception::Exception);
00118     void procStat(xgi::Input *in,xgi::Output *out) throw (xgi::exception::Exception);
00119     void sendMessageOverMonitorQueue(MsgBuf &);
00120 
00121     static void forkProcessFromEDM_helper(void * addr);
00122     void handleSignalSlave(int sig, siginfo_t* info, void* c);
00123 
00124   private:
00125 
00126 
00127     void forkProcessesFromEDM();
00128 
00129     bool enableForkInEDM();
00130     bool restartForkInEDM(unsigned int slotId);
00131     bool doEndRunInEDM();
00132 
00133     void setAttachDqmToShm() throw (evf::Exception);
00134     void attachDqmToShm()    throw (evf::Exception);
00135     void detachDqmFromShm()  throw (evf::Exception);
00136 
00137     std::string logsAsString();
00138     void localLog(std::string);
00139 
00140     // MPEP functions
00141     void startSupervisorLoop();
00142     void startReceivingLoop();
00143     void startReceivingMonitorLoop();
00144     // calculate scalers information in separate thread
00145     void startScalersWorkLoop() throw (evf::Exception);
00146     bool scalers(toolbox::task::WorkLoop* wl);
00147     void startSummarizeWorkLoop() throw (evf::Exception);
00148     bool summarize(toolbox::task::WorkLoop* wl);
00149 
00150     bool receiving(toolbox::task::WorkLoop* wl);
00151     bool receivingAndMonitor(toolbox::task::WorkLoop* wl);
00152     bool supervisor(toolbox::task::WorkLoop* wl);
00153     void startSignalMonitorWorkLoop() throw (evf::Exception);
00154     bool sigmon(toolbox::task::WorkLoop* wl);
00155 
00156     bool enableCommon();
00157     bool enableClassic();
00158     //    void enableMPEPMaster();
00159     bool enableMPEPSlave();
00160     bool stopClassic();
00161     void stopSlavesAndAcknowledge();
00162     void makeStaticInfo();
00163 
00164     //
00165     // member data
00166     //
00167     
00168     // finite state machine
00169     evf::StateMachine                fsm_;
00170     
00171     // logger
00172     Logger                           log_;
00173 
00174     // edm event processor
00175     FWEPWrapper                      evtProcessor_;
00176     
00177     // parameters published to XDAQ info space(s)
00178     xdata::String                    url_;
00179     xdata::String                    class_;
00180     xdata::UnsignedInteger32         instance_;
00181     xdata::UnsignedInteger32         runNumber_;
00182     xdata::Boolean                   epInitialized_; 
00183     xdata::String                    configString_;
00184     std::string                      configuration_;
00185 
00186     xdata::Boolean                   outPut_;
00187 
00188     xdata::Boolean                   autoRestartSlaves_;
00189     xdata::UnsignedInteger32         slaveRestartDelaySecs_;
00190 
00191     xdata::Boolean                   hasShMem_;
00192     xdata::Boolean                   hasPrescaleService_;
00193     xdata::Boolean                   hasModuleWebRegistry_;
00194     xdata::Boolean                   hasServiceWebRegistry_;
00195     xdata::Boolean                   isRunNumberSetter_;
00196     xdata::Boolean                   iDieStatisticsGathering_;
00197     bool                             outprev_;
00198     
00199     // application identifier
00200     std::string                      sourceId_;
00201 
00202     // flashlist variables, squids
00203     xdata::Boolean                   squidPresent_; 
00204 
00205     // behavior on error - configurable
00206     
00207     xdata::Boolean                   exitOnError_; 
00208 
00209     // HyperDAQ related
00210     Css                              css_;
00211 
00212     // Misc
00213     std::string                      reasonForFailedState_;
00214 
00215     SquidNet                         squidnet_;
00216     std::vector<std::string>         logRing_;
00217     unsigned int                     logRingIndex_;
00218     static const unsigned int        logRingSize_ = 50;
00219     bool                             logWrap_;
00220 
00221     xdata::UnsignedInteger32         nbSubProcesses_;
00222     xdata::UnsignedInteger32         nbSubProcessesReporting_;
00223     xdata::UnsignedInteger32         forkInEDM_;
00224     std::vector<SubProcess>          subs_;
00225     unsigned int                     nblive_; 
00226     unsigned int                     nbdead_; 
00227 
00228     unsigned int                     nbTotalDQM_;
00229 
00230     // workloop / action signature for message passing
00231     toolbox::task::WorkLoop         *wlReceiving_;      
00232     toolbox::task::ActionSignature  *asReceiveMsgAndExecute_;
00233     bool                             receiving_;
00234     toolbox::task::WorkLoop         *wlReceivingMonitor_;      
00235     toolbox::task::ActionSignature  *asReceiveMsgAndRead_;
00236     bool                             receivingM_;
00237     SubProcess*                      myProcess_;
00238     toolbox::task::WorkLoop         *wlSupervising_;      
00239     toolbox::task::ActionSignature  *asSupervisor_;
00240     bool                             supervising_;
00241     toolbox::task::WorkLoop         *wlSignalMonitor_;      
00242     toolbox::task::ActionSignature  *asSignalMonitor_;
00243     bool                             signalMonitorActive_;
00244 
00245 
00246     xdata::InfoSpace*                monitorInfoSpace_;
00247     xdata::InfoSpace*                monitorLegendaInfoSpace_;
00248     xdata::InfoSpace*                applicationInfoSpace_;
00249     pthread_mutex_t                  stop_lock_;
00250     pthread_mutex_t                  start_lock_;
00251     pthread_mutex_t                  pickup_lock_;
00252     std::string                      updaterStatic_;
00253     xdata::Serializable             *nbProcessed;
00254     xdata::Serializable             *nbAccepted;
00255 
00256     // flahslist variables, scalers
00257     xdata::InfoSpace                *scalersInfoSpace_;
00258     xdata::InfoSpace                *scalersLegendaInfoSpace_;
00259 
00260     //scalers workloop
00261     toolbox::task::WorkLoop         *wlScalers_;      
00262     toolbox::task::ActionSignature  *asScalers_;
00263     bool                             wlScalersActive_;
00264     unsigned int                     scalersUpdates_;
00265 
00266     //summarize workloop
00267     toolbox::task::WorkLoop         *wlSummarize_;      
00268     toolbox::task::ActionSignature  *asSummarize_;
00269     bool                             wlSummarizeActive_;
00270     int                              anonymousPipe_[2];
00271     xdata::Vector<xdata::Integer>    spMStates_;
00272     xdata::Vector<xdata::Integer>    spmStates_;
00273     xdata::UnsignedInteger32         superSleepSec_; 
00274     std::list<std::string>           names_;
00275     xdata::String                    iDieUrl_;
00276     Vulture                         *vulture_;
00277     pid_t                            vp_;
00278     CPUStat                         *cpustat_;
00279     RateStat                        *ratestat_;
00280 
00281     ModuleWebRegistry                *mwrRef_;
00282     ShmOutputModuleRegistry          *sorRef_;
00283     MsgBuf                           master_message_prg_;
00284     MsgBuf                           master_message_prr_;
00285     MsgBuf                           slave_message_prr_;
00286     MsgBuf                           slave_message_monitoring_;
00287     MsgBuf                           master_message_trr_;
00288 
00289     moduleweb::ForkInfoObj           *forkInfoObj_;
00290     pthread_mutex_t                  forkObjLock_;
00291     bool                             restart_in_progress_;
00292     bool                             edm_init_done_;
00293 
00294     unsigned int                     crashesThisRun_;
00295     bool                             rlimit_coresize_changed_;
00296     rlimit                           rlimit_coresize_default_;
00297     xdata::UnsignedInteger32         crashesToDump_;
00298     sem_t                            *sigmon_sem_;
00299     timeval                          lastCrashTime_;
00300 
00301     unsigned long long               idleProcStats_;
00302     unsigned long long               allProcStats_;
00303     timeval                          lastProcReport_;
00304 
00305     std::auto_ptr<edm::Presence>     messageServicePresence_;
00306     xdata::Boolean                   datasetCounting_;
00307   };
00308 
00309   
00310 } // namespace evf
00311 
00312 
00313 #endif