CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 #ifndef EVENTFILTER_PROCESSOR_FWEPWRAPPER_H
00002 #define EVENTFILTER_PROCESSOR_FWEPWRAPPER_H
00003 
00004 #include "FWCore/Framework/interface/EventProcessor.h"
00005 
00006 #include "FWCore/PrescaleService/interface/PrescaleService.h"
00007 #include "HLTrigger/Timer/interface/FastTimerService.h"
00008 
00009 #include "EventFilter/Utilities/interface/Exception.h"
00010 #include "TriggerReportHelpers.h"
00011 
00012 #include "toolbox/lang/Class.h"
00013 #include "toolbox/task/WorkLoop.h"
00014 #include "toolbox/net/URL.h"
00015 
00016 
00017 #include "xgi/Input.h"
00018 #include "xgi/Output.h"
00019 #include "xgi/exception/Exception.h"
00020 
00021 #include "xoap/MessageReference.h"
00022 
00023 #include "xdata/InfoSpace.h"
00024 #include "xdata/Integer.h"
00025 #include "xdata/UnsignedInteger32.h"
00026 #include "xdata/Boolean.h"
00027 #include "log4cplus/logger.h"
00028 
00029 #include <string>
00030 #include "EventFilter/Utilities/interface/MsgBuf.h"
00031 #include "EventFilter/Utilities/interface/ModuleWeb.h"
00032 #include "EventFilter/Utilities/interface/ModuleWebRegistry.h"
00033 
00034 namespace xdaq{
00035   class ApplicationDescriptor;
00036   class ApplicationContext;
00037 }
00038 
00039 namespace evf{
00040 
00041   struct lsTriplet{
00042     lsTriplet(): ls(0), proc(0), acc(0){}
00043     unsigned int ls;
00044     unsigned int proc;
00045     unsigned int acc;
00046   };
00047   class FWEPWrapper : public toolbox::lang::Class{
00048 
00049   public:
00050 
00051     FWEPWrapper(log4cplus::Logger &, unsigned int instance);
00052     virtual ~FWEPWrapper();
00053 
00054 
00055 
00056     void taskWebPage(xgi::Input *,xgi::Output *,const std::string &);
00057     void summaryWebPage(xgi::Input *,xgi::Output *,const std::string &);
00058     void moduleWeb(xgi::Input *in,xgi::Output *out);
00059     void serviceWeb(xgi::Input *in,xgi::Output *out);
00060     void microState(xgi::Input *in,xgi::Output *out);
00061 
00062     edm::EventProcessor *operator->(){return evtProcessor_;}
00063     operator bool(){return epInitialized_;}
00064 
00065     // initialize the cmssw event processor
00066     void init(unsigned short, std::string &);
00067     void makeServicesOnly();
00068     void forceInitEventProcessorMaybe(){epInitialized_ = false;}
00069 
00070     // stop the cmssw event processor
00071     edm::EventProcessor::StatusCode stop();
00072 
00073     // stop and halt (check if stop done)
00074     void stopAndHalt();
00075 
00076     // infospace pointers transfer
00077     void setScalersInfoSpace(xdata::InfoSpace *sis, xdata::InfoSpace *slis)
00078     {
00079       scalersInfoSpace_ = sis;
00080       scalersLegendaInfoSpace_ = slis;
00081     }
00082     void setApplicationInfoSpace(xdata::InfoSpace *is){applicationInfoSpace_ = is;}
00083     void setMonitorInfoSpace(xdata::InfoSpace *mis, xdata::InfoSpace *mlis)
00084     {
00085       monitorInfoSpace_ = mis;
00086       monitorLegendaInfoSpace_ = mlis;
00087     }
00088     void setMonitorInfoSpaceLegend(xdata::InfoSpace *is){monitorInfoSpaceLegend_ = is;}
00089     void setRcms(xdaq::ApplicationDescriptor* rcms){rcms_ = rcms;}
00090     void setAppDesc(xdaq::ApplicationDescriptor *ad){xappDesc_ = ad;}
00091     void setAppCtxt(xdaq::ApplicationContext *ctx){xappCtxt_ = ctx;}
00092 
00093 
00094     void publishConfigAndMonitorItems(bool);
00095     void publishConfigAndMonitorItemsSP();
00096     void setupFastTimerService(unsigned int nProcesses);
00097 
00098     std::string wlMonitoring(){
00099       if(wlMonitoring_!=0 && wlMonitoring_->isActive()) return (wlMonitoringActive_ ? "active" : "inactive");
00100       else return "not initialized"; 
00101     }
00102     std::string const &configuration() const {return configuration_;}
00103     // calculate monitoring information in separate thread
00104     void startMonitoringWorkLoop() throw (evf::Exception);
00105     bool monitoring(toolbox::task::WorkLoop* wl);
00106     // trigger report callback
00107     bool getTriggerReport(bool useLock);
00108     void updateRollingReport();
00109 
00110     void sumAndPackTriggerReport(MsgBuf &buf);
00111     void resetPackedTriggerReport(){trh_.resetPackedTriggerReport();}
00112     void adjustLsIndexForRestart(){trh_.adjustLsIndexForRestart();}
00113     void resetTriggerReport(){trh_.resetTriggerReport();}
00114     MsgBuf &getPackedTriggerReport(){return trh_.getPackedTriggerReport();}
00115     TriggerReportStatic *getPackedTriggerReportAsStruct(){return trh_.getPackedTriggerReportAsStruct();}
00116     bool fireScalersUpdate(); 
00117     void createAndSendScalersMessage();
00118 
00119     void lumiSumTable(xgi::Output *out);
00120 
00121     // some accessors for FUEventProcessor
00122     std::string const &moduleNameFromIndex(unsigned int i) const
00123       {
00124         if(i<mapmod_.size()) return mapmod_[i];
00125         else return unknown;
00126       }
00127     std::string const &stateNameFromIndex(unsigned int i) const
00128       {
00129         if(i<statmod_.size()) return statmod_[i];
00130         else return unknown;
00131       }
00132     int notstarted_state_code() const { return notstarted_state_code_;}
00133     lsTriplet &lastLumi(){return lumiSectionsCtr_[rollingLsIndex_];}
00134     void resetWaiting(){waitingForLs_ = false;}
00135     bool isWaitingForLs(){return waitingForLs_;}
00136     unsigned int getScalersUpdates(){return scalersUpdateCounter_;}
00137     void resetLumiSectionReferenceIndex(){trh_.resetLumiSectionReferenceIndex();}
00138     void withdrawLumiSectionIncrement(){trh_.withdrawLumiSectionIncrement();}
00139     unsigned int getLumiSectionReferenceIndex(){return trh_.getLumiSectionReferenceIndex();}
00140     unsigned int getNumberOfMicrostates(){return mapmod_.size();}
00141     std::vector<std::string> const &getmicromap() const { return mapmod_;}
00142 
00143     ModuleWebRegistry * getModuleWebRegistry();
00144     ShmOutputModuleRegistry * getShmOutputModuleRegistry();
00145   private:
00146     static const std::string        unknown;
00147     edm::EventProcessor             *evtProcessor_;
00148 
00149     edm::ServiceToken                serviceToken_;    
00150     bool                             servicesDone_;
00151     bool                             epInitialized_;
00152     std::string                      configString_;
00153 
00154     // prescale (cmssw framework-) service
00155     edm::service::PrescaleService*  prescaleSvc_;
00156 
00157     fuep::TriggerReportHelpers       trh_;
00158     log4cplus::Logger                log_;
00159     bool                             isPython_;
00160     bool                             hasPrescaleService_;
00161     bool                             hasModuleWebRegistry_;
00162     bool                             hasServiceWebRegistry_;
00163                                                  
00164     // infospace variables, general
00165     xdata::InfoSpace                *applicationInfoSpace_;
00166 
00167     // infospace variables, monitor
00168     xdata::InfoSpace                *monitorInfoSpace_;
00169     xdata::InfoSpace                *monitorLegendaInfoSpace_;
00170     xdata::InfoSpace                *monitorInfoSpaceLegend_;
00171 
00172     xdata::UnsignedInteger32         timeoutOnStop_; // in seconds
00173 
00174     std::vector<edm::ModuleDescription const*> descs_; //module description array
00175     std::map<std::string,int>        modmap_;
00176     std::vector<std::string>         mapmod_;
00177     std::vector<std::string>         statmod_;
00178 
00179     // monitoring workloop params
00180     xdata::UnsignedInteger32         monSleepSec_;
00181     struct timeval                   monStartTime_;
00182 
00183     // flahslist variables
00184     xdata::String                    epMState_;
00185     xdata::String                    epmState_;
00186     xdata::UnsignedInteger32         nbProcessed_;
00187     xdata::UnsignedInteger32         nbAccepted_;
00188 
00189     // workloop / action signature for monitoring
00190     toolbox::task::WorkLoop         *wlMonitoring_;      
00191     toolbox::task::ActionSignature  *asMonitoring_;
00192     bool                             wlMonitoringActive_;
00193     bool                             watching_;
00194 
00195     // flahslist variables, alt
00196     xdata::Integer                   epMAltState_;
00197     xdata::Integer                   epmAltState_;
00198 
00199 
00200     // flahslist variables, legend
00201     xdata::String                    macro_state_legend_;
00202     xdata::String                    micro_state_legend_;
00203 
00204     // LS stuff
00205     unsigned int                     allPastLumiProcessed_;
00206     std::list<std::string>           names_;
00207     std::list<std::string>           namesStatusLegenda_;
00208     std::list<std::string>           namesScalersLegenda_;
00209     std::string                      lsidTimedOutAsString_;
00210     unsigned int                     lsid_;
00211     unsigned int                     psid_;
00212 
00213     xdata::InfoSpace                *scalersInfoSpace_;
00214     xdata::InfoSpace                *scalersLegendaInfoSpace_;
00215     xdata::UnsignedInteger32         localLsIncludingTimeOuts_;
00216     xdata::UnsignedInteger32         lsTimeOut_;
00217     xdata::Table                     scalersComplete_;
00218 
00219     xdata::UnsignedInteger32         lumiSectionIndex_;
00220     xdata::UnsignedInteger32         prescaleSetIndex_;
00221     xdata::UnsignedInteger32         lastLumiPrescaleIndex_;
00222     xdata::UnsignedInteger32         lastLumiUsingEol_;
00223     xdata::Boolean                   lsTimedOut_;
00224     xdata::Boolean                   lsToBeRecovered_;
00225 
00226     unsigned int                     scalersUpdateAttempted_;    
00227     unsigned int                     scalersUpdateCounter_;
00228     std::vector<lsTriplet>           lumiSectionsCtr_;
00229     std::vector<bool>                lumiSectionsTo_;
00230     unsigned int                     rollingLsIndex_;
00231     bool                             rollingLsWrap_;
00232     static const unsigned int        lsRollSize_ = 20;
00233     xdaq::ApplicationDescriptor*     rcms_;
00234     xdaq::ApplicationDescriptor*     xappDesc_;
00235     xdaq::ApplicationContext*        xappCtxt_;
00236     std::string                      configuration_;
00237     std::string                      pathTable_;
00238     xdata::UnsignedInteger32         instance_;
00239     bool                             hasSubProcesses;
00240     bool                             waitingForLs_;
00241     pthread_mutex_t                  ep_guard_lock_;
00242     int                              notstarted_state_code_;
00243     ModuleWebRegistry                *mwrRef_;
00244     ShmOutputModuleRegistry          *sorRef_;
00245     FastTimerService                 *ftsRef_;
00246     bool                              countDatasets_;
00247     friend class FUEventProcessor;
00248 
00249   };
00250 }
00251 #endif