CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/EventFilter/Processor/src/FWEPWrapper.cc

Go to the documentation of this file.
00001 #include "FWEPWrapper.h"
00002 
00003 #include "EventFilter/Utilities/interface/ParameterSetRetriever.h"
00004 #include "EventFilter/Utilities/interface/ModuleWebRegistry.h"
00005 #include "EventFilter/Utilities/interface/ServiceWebRegistry.h"
00006 #include "EventFilter/Utilities/interface/ServiceWeb.h"
00007 #include "EventFilter/Utilities/interface/MicroStateService.h"
00008 #include "EventFilter/Utilities/interface/TimeProfilerService.h"
00009 #include "EventFilter/Modules/interface/ShmOutputModuleRegistry.h"
00010 
00011 #include "EventFilter/Modules/src/FUShmOutputModule.h"
00012 
00013 #include "toolbox/task/WorkLoopFactory.h"
00014 #include "xdaq/ApplicationDescriptorImpl.h"
00015 #include "xdaq/ContextDescriptor.h"
00016 #include "xdaq/ApplicationContext.h"
00017 #include "xdata/Boolean.h"
00018 #include "xdata/TableIterator.h"
00019 #include "xdata/exdr/Serializer.h"
00020 #include "xdata/exdr/AutoSizeOutputStreamBuffer.h"
00021 
00022 #include "FWCore/PythonParameterSet/interface/MakeParameterSets.h"
00023 #undef HAVE_STAT
00024 #include "FWCore/PythonParameterSet/interface/PythonProcessDesc.h"
00025 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00026 #include "FWCore/ParameterSet/interface/ProcessDesc.h"
00027 #include "FWCore/ServiceRegistry/interface/Service.h"
00028 #include "FWCore/PrescaleService/interface/PrescaleService.h"
00029 #include "FWCore/Framework/interface/TriggerReport.h"
00030 
00031 #include "DQMServices/Core/interface/DQMStore.h"
00032 
00033 #include "xoap/MessageFactory.h"
00034 #include "xoap/SOAPEnvelope.h"
00035 #include "xoap/SOAPBody.h"
00036 #include "xoap/domutils.h"
00037 #include "xoap/Method.h"
00038 #include "xmas/xmas.h"
00039 
00040 #include "cgicc/CgiDefs.h"
00041 #include "cgicc/Cgicc.h"
00042 #include "cgicc/FormEntry.h"
00043 
00044 #include "utils.icc"
00045 
00046 #include <vector>
00047 
00048 namespace evf{
00049 
00050   const std::string FWEPWrapper::unknown = "unknown";
00051   FWEPWrapper::FWEPWrapper(log4cplus::Logger &log, unsigned int instance) 
00052     : evtProcessor_(0)
00053     , serviceToken_()
00054     , servicesDone_(false)
00055     , epInitialized_(false)
00056     , prescaleSvc_(0)
00057     , log_(log)
00058     , isPython_(true)
00059     , hasPrescaleService_(false)
00060     , hasModuleWebRegistry_(false)
00061     , hasServiceWebRegistry_(false)
00062     , monitorInfoSpace_(0) 
00063     , monitorInfoSpaceLegend_(0) 
00064     , timeoutOnStop_(3)
00065     , monSleepSec_(1)
00066     , nbProcessed_(0)
00067     , nbAccepted_(0)
00068     , wlMonitoring_(0)
00069     , asMonitoring_(0)
00070     , wlMonitoringActive_(false)
00071     , watching_(false)
00072     , allPastLumiProcessed_(0)
00073     , lsid_(0)
00074     , psid_(0)
00075     , lsTimeOut_(100000000)
00076     , lumiSectionIndex_(1)
00077     , prescaleSetIndex_(0)
00078     , lastLumiPrescaleIndex_(0)
00079     , lastLumiUsingEol_(0)
00080     , lsTimedOut_(false)
00081     , lsToBeRecovered_(true)
00082     , scalersUpdateAttempted_(0)
00083     , scalersUpdateCounter_(0)
00084     , lumiSectionsCtr_(lsRollSize_+1)
00085     , lumiSectionsTo_(lsRollSize_)
00086     , rollingLsIndex_(lsRollSize_-1)
00087     , rollingLsWrap_(false)
00088     , rcms_(0)
00089     , instance_(instance)
00090     , waitingForLs_(false)
00091     , mwrRef_(nullptr)
00092     , sorRef_(nullptr)
00093     , countDatasets_(false)
00094   {
00095     //list of variables for scalers flashlist
00096     names_.push_back("lumiSectionIndex");
00097     names_.push_back("prescaleSetIndex");
00098     names_.push_back("scalersTable");
00099     namesStatusLegenda_.push_back("macroStateLegenda");
00100     namesStatusLegenda_.push_back("microStateLegenda");
00101     namesScalersLegenda_.push_back("scalersLegenda");
00102     //some initialization of state data
00103     epMAltState_ = -1;
00104     epmAltState_ = -1;
00105     pthread_mutex_init(&ep_guard_lock_,0);
00106   }
00107 
00108   FWEPWrapper::~FWEPWrapper() {if (0!=evtProcessor_) delete evtProcessor_; evtProcessor_=0;}
00109 
00110   void FWEPWrapper::publishConfigAndMonitorItems(bool multi)
00111   {
00112 
00113     applicationInfoSpace_->fireItemAvailable("monSleepSec",             &monSleepSec_);
00114     applicationInfoSpace_->fireItemAvailable("timeoutOnStop",           &timeoutOnStop_);
00115     applicationInfoSpace_->fireItemAvailable("lsTimeOut",               &lsTimeOut_);
00116 
00117     applicationInfoSpace_->fireItemAvailable("lumiSectionIndex",        &lumiSectionIndex_);
00118     applicationInfoSpace_->fireItemAvailable("prescaleSetIndex",        &prescaleSetIndex_);
00119     applicationInfoSpace_->fireItemAvailable("lastLumiPrescaleIndex",   &lastLumiPrescaleIndex_);
00120     applicationInfoSpace_->fireItemAvailable("lastLumiUsingEol",        &lastLumiUsingEol_);
00121     applicationInfoSpace_->fireItemAvailable("lsTimedOut",              &lsTimedOut_);
00122     applicationInfoSpace_->fireItemAvailable("lsToBeRecovered",         &lsToBeRecovered_);
00123 
00124     monitorLegendaInfoSpace_->fireItemAvailable("macroStateLegenda",           &macro_state_legend_);
00125     monitorLegendaInfoSpace_->fireItemAvailable("microStateLegenda",           &micro_state_legend_);
00126 
00127     monitorInfoSpace_->fireItemAvailable("epMacroState",                &epMState_);
00128     monitorInfoSpace_->fireItemAvailable("epMicroState",                &epmState_);
00129 
00130     xdata::Table &stbl = trh_.getTable(); 
00131     scalersInfoSpace_->fireItemAvailable("scalersTable", &stbl);
00132     scalersInfoSpace_->fireItemAvailable("lumiSectionIndex",      &lumiSectionIndex_);
00133     scalersInfoSpace_->fireItemAvailable("prescaleSetIndex",      &prescaleSetIndex_);
00134     scalersInfoSpace_->fireItemAvailable("lastLumiPrescaleIndex", &lastLumiPrescaleIndex_);
00135     scalersInfoSpace_->fireItemAvailable("lastLumiUsingEol",      &lastLumiUsingEol_);
00136     scalersLegendaInfoSpace_->fireItemAvailable("scalersLegenda", trh_.getPathLegenda());    
00137 
00138     scalersComplete_.addColumn("instance", "unsigned int 32");
00139     scalersComplete_.addColumn("lsid", "unsigned int 32");
00140     scalersComplete_.addColumn("psid", "unsigned int 32");
00141     scalersComplete_.addColumn("proc", "unsigned int 32");
00142     scalersComplete_.addColumn("acc",  "unsigned int 32");
00143     scalersComplete_.addColumn("exprep",  "unsigned int 32");
00144     scalersComplete_.addColumn("effrep",  "unsigned int 32");
00145     scalersComplete_.addColumn("triggerReport", "table");  
00146 
00147     xdata::Table::iterator it = scalersComplete_.begin();
00148     if( it == scalersComplete_.end())
00149       {
00150         it = scalersComplete_.append();
00151         it->setField("instance",instance_);
00152       }
00153 
00154 
00155     //fill initial macrostate legenda information
00156     unsigned int i = 0;
00157     std::stringstream oss;
00158     for(i = (unsigned int)edm::event_processor::sInit; i < (unsigned int)edm::event_processor::sInvalid; i++)
00159       {
00160         oss << i << "=" << evtProcessor_->stateName((edm::event_processor::State) i) << " ";
00161         statmod_.push_back(evtProcessor_->stateName((edm::event_processor::State) i));
00162       }
00163     oss << i << "=" << "NotStarted ";
00164     statmod_.push_back("NotStarted");
00165     notstarted_state_code_ = i;
00166     std::stringstream oss2;
00167     oss2 << 0 << "=Invalid ";
00168     modmap_["Invalid"]=0;
00169     mapmod_.resize(1); 
00170     mapmod_[0]="Invalid";
00171 
00172     monitorInfoSpace_->lock();
00173     macro_state_legend_ = oss.str();
00174     micro_state_legend_ = oss2.str();
00175     monitorInfoSpace_->unlock();
00176 
00177     if(!multi) publishConfigAndMonitorItemsSP();
00178 
00179   }
00180 
00181   void FWEPWrapper::publishConfigAndMonitorItemsSP()
00182   {
00183     monitorInfoSpace_->fireItemAvailable("epSPMacroStateInt",             &epMAltState_);
00184     monitorInfoSpace_->fireItemAvailable("epSPMicroStateInt",             &epmAltState_);
00185 
00186     monitorInfoSpace_->fireItemAvailable("nbProcessed",                 &nbProcessed_);
00187     monitorInfoSpace_->fireItemAvailable("nbAccepted",                  &nbAccepted_);
00188   }
00189 
00190 
00191   void FWEPWrapper::init(unsigned short serviceMap, std::string &configString)
00192   {
00193     hasPrescaleService_ = serviceMap & 0x1;
00194     hasModuleWebRegistry_ = serviceMap & 0x2;
00195     hasServiceWebRegistry_ = serviceMap & 0x4;
00196     bool instanceZero = serviceMap & 0x8;
00197     hasSubProcesses = serviceMap & 0x10;
00198     countDatasets_ = (serviceMap&0x20)>0;
00199     configString_ = configString;
00200     trh_.resetFormat(); //reset the report table even if HLT didn't change
00201     scalersUpdateCounter_ = 0;
00202     if (epInitialized_) {
00203       LOG4CPLUS_INFO(log_,"CMSSW EventProcessor already initialized: skip!");
00204       return;
00205     }
00206       
00207     LOG4CPLUS_INFO(log_,"Initialize CMSSW EventProcessor.");
00208     LOG4CPLUS_INFO(log_,"CMSSW_BASE:"<<getenv("CMSSW_BASE"));
00209  
00210     //end job of previous EP instance
00211     if (0!=evtProcessor_) {
00212         edm::event_processor::State st = evtProcessor_->getState();
00213         if(st == edm::event_processor::sJobReady || st == edm::event_processor::sDone) {
00214           evtProcessor_->endJob();
00215         }
00216         delete evtProcessor_;
00217         evtProcessor_=0;
00218     }
00219 
00220     // job configuration string
00221     ParameterSetRetriever pr(configString_);
00222     configuration_ = pr.getAsString();
00223     pathTable_     = pr.getPathTableAsString();
00224     
00225     if (configString_.size() > 3 && configString_.substr(configString_.size()-3) == ".py") isPython_ = true;
00226     boost::shared_ptr<edm::ParameterSet> params; // change this name!
00227     boost::shared_ptr<std::vector<edm::ParameterSet> > pServiceSets;
00228     boost::shared_ptr<edm::ProcessDesc> pdesc;
00229     if(isPython_)
00230       {
00231         PythonProcessDesc ppdesc = PythonProcessDesc(configuration_);
00232         pdesc = ppdesc.processDesc();
00233       }
00234     else
00235       pdesc = boost::shared_ptr<edm::ProcessDesc>(new edm::ProcessDesc(configuration_));
00236     pServiceSets = pdesc->getServicesPSets();
00237 
00238     // add default set of services
00239     if(!servicesDone_) {
00240       //DQMStore should not be created in the Master (MP case) since this poses problems in the slave
00241       if(!hasSubProcesses){
00242         internal::addServiceMaybe(*pServiceSets,"DQMStore");
00243         internal::addServiceMaybe(*pServiceSets,"DQM");
00244       }
00245       else{
00246         internal::removeServiceMaybe(*pServiceSets,"DQMStore");
00247         internal::removeServiceMaybe(*pServiceSets,"DQM");
00248       }
00249       internal::addServiceMaybe(*pServiceSets,"MLlog4cplus");
00250       internal::addServiceMaybe(*pServiceSets,"MicroStateService");
00251       internal::addServiceMaybe(*pServiceSets,"ShmOutputModuleRegistry");
00252       if(hasPrescaleService_) internal::addServiceMaybe(*pServiceSets,"PrescaleService");
00253       if(hasModuleWebRegistry_) internal::addServiceMaybe(*pServiceSets,"ModuleWebRegistry");
00254       if(hasServiceWebRegistry_) internal::addServiceMaybe(*pServiceSets,"ServiceWebRegistry");
00255     
00256       try{
00257         serviceToken_ = edm::ServiceRegistry::createSet(*pServiceSets);
00258         internal::addServiceMaybe(*pServiceSets,"DQMStore");
00259         internal::addServiceMaybe(*pServiceSets,"DQM");
00260         //      slaveServiceToken_ = edm::ServiceRegistry::createSet(*pServiceSets);
00261       }
00262       catch(cms::Exception &e) {
00263         LOG4CPLUS_ERROR(log_,e.explainSelf());
00264       }    
00265       catch(std::exception &e) {
00266         LOG4CPLUS_ERROR(log_,e.what());
00267       }
00268       catch(...) {
00269         LOG4CPLUS_ERROR(log_,"Unknown Exception");
00270       }
00271       servicesDone_ = true;
00272     }
00273   
00274     edm::ServiceRegistry::Operate operate(serviceToken_);
00275 
00276 
00277     //test rerouting of fwk logging to log4cplus
00278     edm::LogInfo("FWEPWrapper")<<"started MessageLogger Service.";
00279     edm::LogInfo("FWEPWrapper")<<"Using config \n"<<configuration_;
00280 
00281     DQMStore *dqm = 0;
00282     try{
00283       if(edm::Service<DQMStore>().isAvailable())
00284         dqm = edm::Service<DQMStore>().operator->();
00285     }
00286     catch(...) { 
00287       LOG4CPLUS_INFO(log_,
00288                      "exception when trying to get service DQMStore");
00289     }
00290     if(dqm!=0) dqm->rmdir("");
00291   
00292 
00293     ModuleWebRegistry *mwr = 0;
00294     try{
00295       if(edm::Service<ModuleWebRegistry>().isAvailable())
00296         mwr = edm::Service<ModuleWebRegistry>().operator->();
00297     }
00298     catch(...) { 
00299       LOG4CPLUS_INFO(log_,
00300                      "exception when trying to get service ModuleWebRegistry");
00301     }
00302     mwrRef_=mwr;
00303 
00304     if(mwr) mwr->clear(); // in case we are coming from stop we need to clear the mwr
00305 
00306     ServiceWebRegistry *swr = 0;
00307     try{
00308       if(edm::Service<ServiceWebRegistry>().isAvailable())
00309         swr = edm::Service<ServiceWebRegistry>().operator->();
00310     }
00311     catch(...) { 
00312       LOG4CPLUS_INFO(log_,
00313                      "exception when trying to get service ModuleWebRegistry");
00314     }
00315     ShmOutputModuleRegistry *sor = 0;
00316     try{
00317       if(edm::Service<ShmOutputModuleRegistry>().isAvailable())
00318         sor = edm::Service<ShmOutputModuleRegistry>().operator->();
00319     }
00320     catch(...) { 
00321       LOG4CPLUS_INFO(log_,
00322                      "exception when trying to get service ShmOutputModuleRegistry");
00323     }
00324     if(sor) sor->clear();
00325     sorRef_=sor;
00326     //  if(swr) swr->clear(); // in case we are coming from stop we need to clear the swr
00327 
00328     //get and copy streams and datasets PSet from the framework configuration
00329     edm::ParameterSet streamsPSet;
00330     edm::ParameterSet datasetsPSet;
00331     if (countDatasets_)
00332       try {
00333         streamsPSet =  pdesc->getProcessPSet()->getParameter<edm::ParameterSet>("streams");
00334         datasetsPSet =  pdesc->getProcessPSet()->getParameter<edm::ParameterSet>("datasets");
00335       }
00336       catch (...) {
00337         streamsPSet = edm::ParameterSet();
00338         datasetsPSet = edm::ParameterSet();
00339       }
00340 
00341     // instantiate the event processor - fatal exceptions are caught in the main application
00342 
00343     std::vector<std::string> defaultServices;
00344     std::vector<std::string> forcedServices;
00345     defaultServices.push_back("MessageLogger");
00346     defaultServices.push_back("InitRootHandlers");
00347     defaultServices.push_back("JobReportService");
00348     pdesc->addServices(defaultServices, forcedServices);
00349     pthread_mutex_lock(&ep_guard_lock_);
00350     
00351     evtProcessor_ = new edm::EventProcessor(pdesc,
00352                                             serviceToken_,
00353                                             edm::serviceregistry::kTokenOverrides);
00354     pthread_mutex_unlock(&ep_guard_lock_);
00355     //    evtProcessor_->setRunNumber(runNumber_.value_);
00356     /* removed     
00357     if(!outPut_)
00358       evtProcessor_->enableEndPaths(outPut_);    
00359     outprev_=outPut_;
00360     */
00361     // publish all module names to XDAQ infospace
00362     
00363     if(mwr) 
00364       {
00365         mwr->publish(applicationInfoSpace_);
00366         mwr->publishToXmas(scalersInfoSpace_);
00367       }
00368     if(swr) 
00369       {
00370         swr->publish(applicationInfoSpace_);
00371       }
00372     if (sor && countDatasets_)
00373       {
00374         sor->insertStreamAndDatasetInfo(streamsPSet,datasetsPSet);
00375         sor->updateDatasetInfo();
00376       }
00377     // get the prescale service
00378     LOG4CPLUS_INFO(log_,
00379                    "Checking for edm::service::PrescaleService!");
00380     try {
00381       if(edm::Service<edm::service::PrescaleService>().isAvailable())
00382         {
00383           LOG4CPLUS_INFO(log_,
00384                          "edm::service::PrescaleService is available!");
00385           prescaleSvc_ = edm::Service<edm::service::PrescaleService>().operator->();
00386           LOG4CPLUS_INFO(log_,
00387                          "Obtained pointer to PrescaleService");
00388         }
00389     }
00390     catch(...) {
00391       LOG4CPLUS_INFO(log_,
00392                      "exception when trying to get service "
00393                      <<"edm::service::PrescaleService");
00394     }
00395     const edm::ParameterSet *prescaleSvcConfig = internal::findService(*pServiceSets,"PrescaleService");
00396     if(prescaleSvc_ != 0 && prescaleSvcConfig !=0) prescaleSvc_->reconfigure(*prescaleSvcConfig);
00397   
00398     monitorLegendaInfoSpace_->lock();
00399     //fill microstate legenda information
00400     descs_ = evtProcessor_->getAllModuleDescriptions();
00401 
00402     std::stringstream oss2;
00403     unsigned int outcount = 0;
00404     oss2 << 0 << "=Invalid ";
00405     oss2 << 1 << "=FwkOvh ";
00406     oss2 << 2 << "=Input ";
00407     modmap_["Invalid"]=0;
00408     modmap_["FWKOVH"]=1;
00409     modmap_["INPUT"]=2;
00410     mapmod_.resize(descs_.size()+4); // all modules including output plus one input plus DQM plus the invalid state 0
00411     mapmod_[0]="Invalid";
00412     mapmod_[1]="FWKOVH";
00413     mapmod_[2]="INPUT";
00414     outcount+=2;
00415     for(unsigned int j = 0; j < descs_.size(); j++)
00416       {
00417         if(descs_[j]->moduleName() == "ShmStreamConsumer") // find something better than hardcoding name
00418           { 
00419             outcount++;
00420             oss2 << outcount << "=" << descs_[j]->moduleLabel() << " ";
00421             modmap_[descs_[j]->moduleLabel()]=outcount;
00422             mapmod_[outcount] = descs_[j]->moduleLabel();
00423           }
00424       }
00425     modmap_["DQM"]=outcount+1;
00426     mapmod_[outcount+1]="DQM";
00427     oss2 << outcount+1 << "=DQMHistograms ";
00428     unsigned int modcount = 1;
00429     for(unsigned int i = 0; i < descs_.size(); i++)
00430       {
00431         if(descs_[i]->moduleName() != "ShmStreamConsumer")
00432           {
00433             modcount++;
00434             oss2 << outcount+modcount << "=" << descs_[i]->moduleLabel() << " ";
00435             modmap_[descs_[i]->moduleLabel()]=outcount+modcount;
00436             mapmod_[outcount+modcount] = descs_[i]->moduleLabel();
00437           }
00438       }
00439 //     std::cout << "*******************************microstate legend**************************" << std::endl;
00440 //     std::cout << oss2.str() << std::endl;
00441 //     std::cout << "*******************************microstate legend**************************" << std::endl;
00442 
00443     if(instanceZero){
00444       micro_state_legend_ = oss2.str().c_str();
00445     }
00446     monitorLegendaInfoSpace_->unlock();
00447     try{
00448       monitorLegendaInfoSpace_->fireItemGroupChanged(namesStatusLegenda_,0);
00449       scalersLegendaInfoSpace_->fireItemGroupChanged(namesScalersLegenda_,0);
00450       ::usleep(10);
00451     }
00452     catch(xdata::exception::Exception &e)
00453       {
00454         LOG4CPLUS_ERROR(log_, "Exception from fireItemGroupChanged: " << e.what());
00455       }
00456     LOG4CPLUS_INFO(log_," edm::EventProcessor configuration finished.");
00457     edm::TriggerReport tr;
00458     evtProcessor_->getTriggerReport(tr);
00459     trh_.formatReportTable(tr,descs_,pathTable_,instanceZero);
00460     epInitialized_ = true;
00461     return;
00462   }
00463 
00464   void FWEPWrapper::makeServicesOnly()
00465   {
00466     edm::ServiceRegistry::Operate operate(serviceToken_);
00467   }
00468  
00469   ModuleWebRegistry * FWEPWrapper::getModuleWebRegistry() {
00470     return mwrRef_;
00471   }
00472 
00473   ShmOutputModuleRegistry * FWEPWrapper::getShmOutputModuleRegistry() {
00474     return sorRef_;
00475   }
00476 
00477   //______________________________________________________________________________
00478   edm::EventProcessor::StatusCode FWEPWrapper::stop()
00479   {
00480     edm::event_processor::State st = evtProcessor_->getState();
00481     
00482     LOG4CPLUS_WARN(log_,"FUEventProcessor::stopEventProcessor.1 state "
00483                    << evtProcessor_->stateName(st));
00484     edm::EventProcessor::StatusCode rc = edm::EventProcessor::epSuccess;
00485 
00486     //total stopping time allowed before epTimeout/epOther
00487     unsigned int stopTimeLeft = (timeoutOnStop_.value_+1)*1000000;
00488     if (timeoutOnStop_.value_==0) stopTimeLeft=1500000;
00489  
00490     while (!(st==edm::event_processor::sStopping || st==edm::event_processor::sJobReady
00491                                      || st==edm::event_processor::sDone)) {
00492       usleep(100000);
00493       st = evtProcessor_->getState();
00494       if (stopTimeLeft<500000) {
00495         break;
00496       }
00497       stopTimeLeft-=100000;
00498     }
00499     //if already in stopped state
00500     if (st==edm::event_processor::sJobReady || st==edm::event_processor::sDone) 
00501       return edm::EventProcessor::epSuccess;
00502 
00503     //if not even in stopping state
00504     if(st!=edm::event_processor::sStopping) {
00505       LOG4CPLUS_WARN(log_,
00506           "FUEventProcessor::stopEventProcessor.2 After 1s - state: "
00507           << evtProcessor_->stateName(st)); 
00508       return edm::EventProcessor::epOther;
00509     }
00510     LOG4CPLUS_WARN(log_,"FUEventProcessor::stopEventProcessor.3 state "
00511         << evtProcessor_->stateName(st));
00512 
00513     //use remaining time left for the framework timeout
00514     if (stopTimeLeft<1000000) stopTimeLeft=1000000;
00515     stopTimeLeft/=1000000;
00516     if (timeoutOnStop_.value_==0) stopTimeLeft=0;
00517 
00518     try  {
00519       rc = evtProcessor_->waitTillDoneAsync(stopTimeLeft);
00520       watching_ = false;
00521     }
00522     catch(cms::Exception &e) {
00523       XCEPT_RAISE(evf::Exception,e.explainSelf());
00524     }    
00525     catch(std::exception &e) {
00526       XCEPT_RAISE(evf::Exception,e.what());
00527     }
00528     catch(...) {
00529       XCEPT_RAISE(evf::Exception,"Unknown Exception");
00530     }
00531     allPastLumiProcessed_ = 0;
00532     return rc;
00533     
00534   }
00535 
00536   void FWEPWrapper::stopAndHalt()
00537   {
00538     edm::ServiceRegistry::Operate operate(serviceToken_);
00539     ModuleWebRegistry *mwr = 0;
00540     try{
00541       if(edm::Service<ModuleWebRegistry>().isAvailable())
00542         mwr = edm::Service<ModuleWebRegistry>().operator->();
00543     }
00544     catch(...) { 
00545       LOG4CPLUS_INFO(log_,
00546                      "exception when trying to get service ModuleWebRegistry");
00547     }
00548     
00549     if(mwr) 
00550       {
00551         mwr->clear();
00552       }
00553     
00554     ServiceWebRegistry *swr = 0;
00555     try{
00556       if(edm::Service<ServiceWebRegistry>().isAvailable())
00557         swr = edm::Service<ServiceWebRegistry>().operator->();
00558     }
00559     catch(...) { 
00560       LOG4CPLUS_INFO(log_,
00561                      "exception when trying to get service ModuleWebRegistry");
00562     }
00563     
00564     if(swr) 
00565       {
00566         swr->clear();
00567       }
00568 
00569     edm::event_processor::State st = evtProcessor_->getState();
00570     edm::EventProcessor::StatusCode rc = stop();
00571     watching_ = false;
00572     if(rc != edm::EventProcessor::epTimedOut)
00573       {
00574         if(st == edm::event_processor::sJobReady || st == edm::event_processor::sDone)
00575           evtProcessor_->endJob();
00576         pthread_mutex_lock(&ep_guard_lock_);
00577         delete evtProcessor_;
00578         evtProcessor_ = 0;
00579         pthread_mutex_unlock(&ep_guard_lock_);
00580         epInitialized_ = false;
00581       }
00582     else
00583       {
00584         XCEPT_RAISE(evf::Exception,"EventProcessor stop timed out");
00585       }
00586     allPastLumiProcessed_ = 0;    
00587   }
00588     
00589   void FWEPWrapper::startMonitoringWorkLoop() throw (evf::Exception)
00590   {
00591     pid_t pid = getpid();
00592     nbProcessed_.value_ = 0;
00593     nbAccepted_.value_ = 0;
00594     struct timezone timezone;
00595     gettimeofday(&monStartTime_,&timezone);
00596 
00597     std::ostringstream ost;
00598     ost << "Monitoring" << pid;
00599     try {
00600       wlMonitoring_=
00601         toolbox::task::getWorkLoopFactory()->getWorkLoop(ost.str().c_str(),
00602                                                          "waiting");
00603 
00604       if (!wlMonitoring_->isActive()) wlMonitoring_->activate();
00605       asMonitoring_ = toolbox::task::bind(this,&FWEPWrapper::monitoring,
00606                                           ost.str().c_str());
00607 
00608       wlMonitoring_->submit(asMonitoring_);
00609       wlMonitoringActive_ = true;
00610 
00611     }
00612     catch (xcept::Exception& e) {
00613       std::string msg = "Failed to start workloop 'Monitoring'.";
00614 
00615       XCEPT_RETHROW(evf::Exception,msg,e);
00616     }
00617   }
00618 
00619 
00620 
00621   //______________________________________________________________________________
00622   bool FWEPWrapper::monitoring(toolbox::task::WorkLoop* wl)
00623   {
00624   
00625     struct timeval  monEndTime;
00626     struct timezone timezone;
00627     gettimeofday(&monEndTime,&timezone);
00628     edm::ServiceRegistry::Operate operate(serviceToken_);
00629     MicroStateService *mss = 0;
00630     if(!hasSubProcesses) monitorInfoSpace_->lock();
00631     if(evtProcessor_)
00632       {
00633         epMState_ = evtProcessor_->currentStateName();
00634         epMAltState_ = (int) evtProcessor_->getState();
00635       }
00636     else
00637       {
00638         epMState_ = "Off";
00639         epMAltState_ = -1;
00640       }
00641     if(0 != evtProcessor_ && evtProcessor_->getState() != edm::event_processor::sInit)
00642       {
00643         try{
00644           mss = edm::Service<MicroStateService>().operator->();
00645         }
00646         catch(...) { 
00647           LOG4CPLUS_INFO(log_,
00648                          "exception when trying to get service MicroStateService");
00649         }
00650         lsid_ = lumiSectionIndex_.value_;
00651         psid_ = prescaleSetIndex_.value_;
00652       }
00653     if(mss) 
00654       {
00655         epmState_  = mss->getMicroState2();
00656         epmAltState_ = modmap_[mss->getMicroState2()];
00657       }
00658     if(evtProcessor_)
00659       {
00660         nbProcessed_ = evtProcessor_->totalEvents();
00661         nbAccepted_  = evtProcessor_->totalEventsPassed(); 
00662       }
00663     if(!hasSubProcesses) monitorInfoSpace_->unlock();  
00664 
00665     ::sleep(monSleepSec_.value_);
00666     return true;
00667   }
00668 
00669   bool FWEPWrapper::getTriggerReport(bool useLock)
00670   {
00671     edm::ServiceRegistry::Operate operate(serviceToken_);
00672     // Calling this method results in calling 
00673     // evtProcessor_->getTriggerReport, the value returned is encoded as
00674     // a xdata::Table.
00675 
00676     LOG4CPLUS_DEBUG(log_,"getTriggerReport action invoked");
00677 
00678     //Get the trigger report.
00679     ModuleWebRegistry *mwr = 0;
00680     try{
00681       if(edm::Service<ModuleWebRegistry>().isAvailable())
00682         mwr = edm::Service<ModuleWebRegistry>().operator->();
00683     }
00684     catch(...) { 
00685       LOG4CPLUS_INFO(log_,
00686                      "exception when trying to get service ModuleWebRegistry");
00687       return false;
00688     }
00689     edm::TriggerReport tr; 
00690     if(mwr==0) return false;
00691 
00692     unsigned int ls = 0;
00693     unsigned int ps = 0;
00694     timeval tv;
00695     if(useLock) {
00696       gettimeofday(&tv,0);
00697       //      std::cout << getpid() << " calling openBackdoor " << std::endl;
00698       //waitingForLs_ = true;//moving this behind mutex lock
00699       mwr->openBackDoor("DaqSource",lsTimeOut_,&waitingForLs_);
00700       //      std::cout << getpid() << " opened Backdoor " << std::endl;
00701     }
00702 
00703     xdata::Table::iterator it = scalersComplete_.begin();
00704     ps = lastLumiPrescaleIndex_.value_;
00705     //  if(prescaleSvc_ != 0) prescaleSvc_->setIndex(ps);
00706     it->setField("psid",lastLumiPrescaleIndex_);
00707     psid_ = prescaleSetIndex_.value_;
00708     if(prescaleSvc_ != 0) prescaleSvc_->setIndex(psid_);
00709     ls = lumiSectionIndex_.value_;
00710     localLsIncludingTimeOuts_.value_ = ls;
00711     it->setField("lsid", localLsIncludingTimeOuts_);
00712 
00713     lsTriplet lst;
00714     lst.ls = localLsIncludingTimeOuts_.value_;
00715     lst.proc = evtProcessor_->totalEvents()-allPastLumiProcessed_;
00716     lst.acc = evtProcessor_->totalEventsPassed()-
00717       (rollingLsWrap_ ? lumiSectionsCtr_[0].acc : lumiSectionsCtr_[rollingLsIndex_+1].acc);
00718        lumiSectionsCtr_[rollingLsIndex_] = lst;
00719     allPastLumiProcessed_ = evtProcessor_->totalEvents();
00720 
00721 
00722     evtProcessor_->getTriggerReport(tr);
00723 
00724     if(useLock){
00725       //      std::cout << getpid() << " calling closeBackdoor " << std::endl;
00726       mwr->closeBackDoor("DaqSource");
00727       //      std::cout << getpid() << " closed Backdoor " << std::endl;
00728     }  
00729 
00730     trh_.formatReportTable(tr,descs_,pathTable_,false);
00731 
00732 
00733     trh_.triggerReportUpdate(tr,ls,ps,trh_.checkLumiSection(ls));
00734     ShmOutputModuleRegistry *sor = 0;
00735     try{
00736       if(edm::Service<ShmOutputModuleRegistry>().isAvailable())
00737         sor = edm::Service<ShmOutputModuleRegistry>().operator->();
00738     }
00739     catch(...) { 
00740       LOG4CPLUS_INFO(log_,
00741                      "exception when trying to get service ShmOutputModuleRegistry");
00742       return false;
00743     }
00744 
00745 
00746     trh_.packTriggerReport(tr,sor,countDatasets_);
00747     it->setField("triggerReport",trh_.getTableWithNames());
00748     //    std::cout << getpid() << " returning normally from gettriggerreport " << std::endl;
00749     return true;
00750   }
00751 
00752   bool FWEPWrapper::fireScalersUpdate()
00753   {
00754     //    trh_.printReportTable();
00755     scalersUpdateAttempted_++;
00756     //@@EM commented out on
00757     // @@EM 21.06.2011 - this flashlist is too big to be handled by LAS 
00758     /*
00759     try{
00760       //      scalersInfoSpace_->unlock();
00761       // scalersInfoSpace_->fireItemGroupChanged(names_,0); 
00762       ::usleep(10);
00763       //      scalersInfoSpace_->lock();
00764     }
00765     catch(xdata::exception::Exception &e)
00766       {
00767         LOG4CPLUS_ERROR(log_, "Exception from fireItemGroupChanged: " << e.what());
00768         //      localLog(e.what());
00769         return false;
00770       }
00771     */
00772     //@@EM added on 21.06.2011 
00773     // refresh the microstate legenda every 10 lumisections
00774     if(scalersUpdateAttempted_%10 == 0)
00775       monitorLegendaInfoSpace_->fireItemGroupChanged(namesStatusLegenda_,0);
00776     
00777     //if there is no state listener then do not attempt to send to monitorreceiver
00778     if(rcms_==0) return false;
00779     try{
00780       if(trh_.getProcThisLumi()!=0U)
00781         createAndSendScalersMessage();
00782       scalersUpdateCounter_++;
00783     }
00784     catch(...){return false;}
00785     return true;
00786   }
00787 
00788 
00789   //______________________________________________________________________________
00790   void FWEPWrapper::summaryWebPage(xgi::Input *in, xgi::Output *out,const std::string &urn)
00791   {
00792     //    std::string urn = xappDesc_->getURN();
00793 
00794     *out << "<table>"                                                  << std::endl;
00795     
00796     *out << "<tr valign=\"top\">"                                      << std::endl;
00797     *out << "<td>" << std::endl;
00798     
00799     TriggerReportStatic *tr = (TriggerReportStatic *)(trh_.getPackedTriggerReport()->mtext);
00800     // trigger summary table
00801     *out << "<table border=1 bgcolor=\"#CFCFCF\">" << std::endl;
00802     *out << "  <tr>"                                                    << std::endl;
00803     *out << "    <th colspan=7>"                                                << std::endl;
00804     *out << "      " << "Trigger Summary up to LS "
00805          << trh_.getLumiSectionReferenceIndex()-1 << std::endl;
00806     *out << "    </th>"                                                 << std::endl;
00807     *out << "  </tr>"                                                   << std::endl;
00808     
00809     *out << "  <tr >"                                                   << std::endl;
00810     *out << "    <th >Path</th>"                                                << std::endl;
00811     *out << "    <th >Exec</th>"                                                << std::endl;
00812     *out << "    <th >Pass</th>"                                                << std::endl;
00813     *out << "    <th >Fail</th>"                                                << std::endl;
00814     *out << "    <th >Except</th>"                                      << std::endl;
00815     *out << "  </tr>"                                                   << std::endl;
00816     
00817     
00818     for(int i=0; i<tr->trigPathsInMenu; i++) {
00819       *out << "  <tr>" << std::endl;
00820       *out << "    <td>"<< i << "</td>"         << std::endl;
00821       *out << "    <td>" << trh_.getl1pre(i) << "</td>"         << std::endl;
00822       *out << "    <td>" << trh_.getaccept(i) << "</td>"        << std::endl;
00823       *out << "    <td >" << trh_.getfailed(i) << "</td>"       << std::endl;
00824       *out << "    <td ";
00825       if(trh_.getexcept(i) !=0)
00826         *out << "bgcolor=\"red\""                                                       << std::endl;
00827       *out << ">" << trh_.getexcept(i) << "</td>"               << std::endl;
00828       *out << "  </tr >"                                                                << std::endl;
00829       
00830       }
00831     *out << "  <tr><th colspan=7>EndPaths</th></tr>"            << std::endl;
00832 
00833     for(int i=tr->trigPathsInMenu; i<tr->endPathsInMenu + tr->trigPathsInMenu; i++) {
00834       *out << "  <tr>" << std::endl;
00835       *out << "    <td>"<< i << "</td>"         << std::endl;
00836       *out << "    <td>" << trh_.getl1pre(i) << "</td>"         << std::endl;
00837       *out << "    <td>" << trh_.getaccept(i) << "</td>"        << std::endl;
00838       *out << "    <td >" << trh_.getfailed(i) << "</td>"       << std::endl;
00839       *out << "    <td ";
00840       if(trh_.getexcept(i) !=0)
00841         *out << "bgcolor=\"red\""                                                       << std::endl;
00842       *out << ">" << trh_.getexcept(i) << "</td>"               << std::endl;
00843       *out << "  </tr >"                                                                << std::endl;
00844       
00845       }
00846 
00847 
00848     *out << "</table>" << std::endl;
00849     *out << "</td>" << std::endl;
00850     *out << "</tr>" << std::endl;
00851     *out << "</table>" << std::endl;
00852   }
00853 
00854 
00855   //______________________________________________________________________________
00856   void FWEPWrapper::taskWebPage(xgi::Input *in, xgi::Output *out,const std::string &urn)
00857   {
00858     //    std::string urn = xappDesc_->getURN();
00859     ModuleWebRegistry *mwr = 0;
00860     edm::ServiceRegistry::Operate operate(evtProcessor_->getToken());
00861     try{
00862       if(edm::Service<ModuleWebRegistry>().isAvailable())
00863         mwr = edm::Service<ModuleWebRegistry>().operator->();
00864     }
00865     catch(...) {
00866       LOG4CPLUS_WARN(log_,
00867                      "Exception when trying to get service ModuleWebRegistry");
00868     }
00869     TimeProfilerService *tpr = 0;
00870     try{
00871       if(edm::Service<TimeProfilerService>().isAvailable())
00872         tpr = edm::Service<TimeProfilerService>().operator->();
00873     }
00874     catch(...) { 
00875     }
00876 
00877     *out << "<table>"                                                  << std::endl;
00878     
00879     *out << "<tr valign=\"top\">"                                      << std::endl;
00880     *out << "<td>" << std::endl;
00881     
00882     
00883     edm::TriggerReport tr; 
00884     evtProcessor_->getTriggerReport(tr);
00885     
00886     // trigger summary table
00887     *out << "<table border=1 bgcolor=\"#CFCFCF\">" << std::endl;
00888     *out << "  <tr>"                                                    << std::endl;
00889     *out << "    <th colspan=7>"                                                << std::endl;
00890     *out << "      " << "Trigger Summary"                                       << std::endl;
00891     *out << "    </th>"                                                 << std::endl;
00892     *out << "  </tr>"                                                   << std::endl;
00893         
00894     *out << "  <tr >"                                                   << std::endl;
00895     *out << "    <th >Path</th>"                                                << std::endl;
00896     *out << "    <th >Exec</th>"                                                << std::endl;
00897     *out << "    <th >Pass</th>"                                                << std::endl;
00898     *out << "    <th >Fail</th>"                                                << std::endl;
00899     *out << "    <th >Except</th>"                                      << std::endl;
00900     *out << "    <th >TargetPF</th>"                                    << std::endl;
00901     *out << "  </tr>"                                                   << std::endl;
00902     xdata::Serializable *psid = 0;
00903     try{
00904       psid = applicationInfoSpace_->find("prescaleSetIndex");
00905     }
00906     catch(xdata::exception::Exception e){
00907     }
00908     ShmOutputModuleRegistry *sor = 0;
00909     try{
00910       if(edm::Service<ShmOutputModuleRegistry>().isAvailable())
00911         sor = edm::Service<ShmOutputModuleRegistry>().operator->();
00912     }
00913     catch(...) { 
00914       LOG4CPLUS_INFO(log_,
00915                      "exception when trying to get service ShmOutputModuleRegistry");
00916     }
00917 
00918     
00919     for(unsigned int i=0; i<tr.trigPathSummaries.size(); i++) {
00920       *out << "  <tr>" << std::endl;
00921       *out << "    <td>"<< tr.trigPathSummaries[i].name << "</td>"              << std::endl;
00922       *out << "    <td>" << tr.trigPathSummaries[i].timesRun << "</td>"         << std::endl;
00923 
00924       *out << "    <td>" << tr.trigPathSummaries[i].timesPassed << "</td>"      << std::endl;
00925       *out << "    <td >" << tr.trigPathSummaries[i].timesFailed << "</td>"     << std::endl;
00926 
00927       *out << "    <td ";
00928       if(tr.trigPathSummaries[i].timesExcept !=0)
00929         *out << "bgcolor=\"red\""                                                       << std::endl;
00930       *out << ">" << tr.trigPathSummaries[i].timesExcept << "</td>"             << std::endl;
00931       if(psid != 0)
00932         {
00933           *out << "    <td>"
00934                << prescaleSvc_->getPrescale(tr.trigPathSummaries[i].name) 
00935                << "</td>"               << std::endl;
00936         }
00937       else      *out << "    <td>N/A</td>"                                      << std::endl;
00938       *out << "  </tr >"                                                                << std::endl;
00939       
00940     }
00941 
00942 
00943 
00944     for(unsigned int i=0; i<tr.endPathSummaries.size(); i++) {
00945       std::string olab = trh_.findLabelOfModuleTypeInEndPath(tr,descs_,
00946                                                              i,"ShmStreamConsumer");
00947       evf::OutputModule *o = sor->get(olab);
00948       *out << "  <tr>" << std::endl;
00949       *out << "    <td>"<< tr.endPathSummaries[i].name << "</td>"               << std::endl;
00950       *out << "    <td>" << tr.endPathSummaries[i].timesRun << "</td>"          << std::endl;
00951       *out << "    <td>" << (o ? o->getCounts() : -1) << "</td>"        << std::endl;
00952       *out << "    <td >" << (o ? (tr.endPathSummaries[i].timesRun - o->getCounts()) : -1) << "</td>"   << std::endl;
00953       *out << "    <td ";
00954       if(tr.endPathSummaries[i].timesExcept !=0)
00955         *out << "bgcolor=\"red\""                                                       << std::endl;
00956       *out << ">" << tr.endPathSummaries[i].timesExcept << "</td>"              << std::endl;
00957       *out << "    <td>N/A</td>"                                        << std::endl;
00958       *out << "  </tr >"                                                                << std::endl;
00959       
00960     }
00961   
00962     *out << "</table>" << std::endl;
00963     
00964     *out << "</td>" << std::endl;
00965     
00966 
00967     
00968     *out << "<td>" << std::endl;
00969     //Process details table
00970     *out << "<table frame=\"void\" rules=\"rows\" class=\"modules\">"   << std::endl;
00971     *out << "  <tr>"                                                    << std::endl;
00972     *out << "    <th colspan=3>"                                                << std::endl;
00973     *out << "      " << "HLT"                                           << std::endl;
00974     if(descs_.size()>0)
00975       *out << " (Process " << descs_[0]->processName() << ")"           << std::endl;
00976     *out << "    </th>"                                                 << std::endl;
00977     *out << "  </tr>"                                                   << std::endl;
00978 
00979     *out << "  <tr >"                                                   << std::endl;
00980     *out << "    <th >"                                                 << std::endl;
00981     *out << "       Module"                                             << std::endl;
00982     *out << "    </th>"                                                 << std::endl;
00983     *out << "    <th >"                                                 << std::endl;
00984     *out << "       Label"                                              << std::endl;
00985     *out << "    </th>"                                                 << std::endl;
00986     *out << "    <th >"                                                 << std::endl;
00987     *out << "       Version"                                            << std::endl;
00988     *out << "    </th>"                                                 << std::endl;
00989     if(tpr)
00990       {
00991         *out << "    <th >"                                                       << std::endl;
00992         *out << "       first"                                            << std::endl;
00993         *out << "    </th>"                                                       << std::endl;
00994         *out << "    <th >"                                                       << std::endl;
00995         *out << "       ave"                                              << std::endl;
00996         *out << "    </th>"                                                       << std::endl;
00997         *out << "    <th >"                                                       << std::endl;
00998         *out << "       max"                                              << std::endl;
00999         *out << "    </th>"                                                       << std::endl;
01000       }
01001     *out << "  </tr>"                                                   << std::endl;
01002     if(mwr && mwr->checkWeb("DaqSource"))
01003       *out << "    <tr><td ><a href=\"/" << urn 
01004            << "module=DaqSource\">DaqSource</a> </td></tr>";
01005     
01006     for(unsigned int idesc = 0; idesc < descs_.size(); idesc++)
01007       {
01008         *out << "  <tr>"                                                        << std::endl;
01009         *out << "    <td >";
01010         if(mwr && mwr->checkWeb(descs_[idesc]->moduleName()))
01011           *out << "<a href=\"/" << urn 
01012                << "module=" 
01013                << descs_[idesc]->moduleName() << "\">" 
01014                << descs_[idesc]->moduleName() << "</a>";
01015         else
01016           *out << descs_[idesc]->moduleName();
01017         *out << "</td>"                                                 << std::endl;
01018         *out << "    <td >";
01019         *out << descs_[idesc]->moduleLabel();
01020         *out << "</td>"                                                 << std::endl;
01021         *out << "    <td >";
01022         *out << descs_[idesc]->releaseVersion();
01023         *out << "</td>"                                                 << std::endl;
01024         if(tpr)
01025           {
01026             *out << "    <td align=\"right\">";
01027             *out << tpr->getFirst(descs_[idesc]->moduleLabel());
01028             *out << "</td>"                                                       << std::endl;
01029             *out << "    <td align=\"right\"";
01030             *out << (tpr->getAve(descs_[idesc]->moduleLabel())>1. ? "bgcolor=\"red\"" : "") 
01031                  << ">";
01032             *out << tpr->getAve(descs_[idesc]->moduleLabel());
01033             *out << "</td>"                                                       << std::endl;
01034             *out << "    <td align=\"right\">";
01035             *out << tpr->getMax(descs_[idesc]->moduleLabel());
01036             *out << "</td>"                                                       << std::endl;
01037           }
01038         *out << "  </tr>" << std::endl;
01039       }
01040     *out << "</table>" << std::endl;
01041     *out << "</td>" << std::endl;
01042   }
01043 
01044   //______________________________________________________________________________
01045   void FWEPWrapper::moduleWeb(xgi::Input  *in, xgi::Output *out)
01046   {
01047     using namespace cgicc;
01048     Cgicc cgi(in);
01049     std::vector<FormEntry> el1;
01050     cgi.getElement("module",el1);
01051     if(evtProcessor_)  {
01052       if(el1.size()!=0) {
01053         std::string mod = el1[0].getValue();
01054         edm::ServiceRegistry::Operate operate(evtProcessor_->getToken());
01055         ModuleWebRegistry *mwr = 0;
01056         try{
01057           if(edm::Service<ModuleWebRegistry>().isAvailable())
01058             mwr = edm::Service<ModuleWebRegistry>().operator->();
01059         }
01060         catch(...) { 
01061           LOG4CPLUS_WARN(log_,
01062                          "Exception when trying to get service ModuleWebRegistry");
01063         }
01064         mwr->invoke(in,out,mod);
01065       }
01066     }
01067     else {
01068       *out<<"EventProcessor just disappeared "<<std::endl;
01069     }
01070   }
01071   
01072 
01073   //______________________________________________________________________________
01074   void FWEPWrapper::serviceWeb(xgi::Input  *in, xgi::Output *out)
01075   {
01076     using namespace cgicc;
01077     Cgicc cgi(in);
01078     std::vector<FormEntry> el1;
01079     cgi.getElement("service",el1);
01080     if(evtProcessor_)  {
01081       if(el1.size()!=0) {
01082         std::string ser = el1[0].getValue();
01083         edm::ServiceRegistry::Operate operate(evtProcessor_->getToken());
01084         ServiceWebRegistry *swr = 0;
01085         try{
01086           if(edm::Service<ServiceWebRegistry>().isAvailable())
01087             swr = edm::Service<ServiceWebRegistry>().operator->();
01088         }
01089         catch(...) { 
01090           LOG4CPLUS_WARN(log_,
01091                          "Exception when trying to get service ModuleWebRegistry");
01092         }
01093         swr->invoke(in,out,ser);
01094       }
01095     }
01096     else {
01097       *out<<"EventProcessor just disappeared "<<std::endl;
01098     }
01099   }
01100 
01101 //______________________________________________________________________________
01102   void FWEPWrapper::microState(xgi::Input  *in, xgi::Output *out)
01103   {
01104     edm::ServiceRegistry::Operate operate(serviceToken_);
01105     MicroStateService *mss = 0;
01106     std::string micro1 = "unavailable";
01107     if(epInitialized_)
01108       micro1 = "initialized";
01109     std::string micro2 = "unavailable";
01110     if(evtProcessor_!=0 && evtProcessor_->getState() != edm::event_processor::sInit)
01111       {
01112         try{
01113         mss = edm::Service<MicroStateService>().operator->();
01114         }
01115         catch(...) { 
01116           LOG4CPLUS_INFO(log_,
01117                          "exception when trying to get service MicroStateService");
01118         }
01119         pthread_mutex_lock(&ep_guard_lock_);
01120         if(evtProcessor_!=0) micro1 = evtProcessor_->currentStateName();
01121         pthread_mutex_unlock(&ep_guard_lock_);
01122       }
01123 
01124     if(mss) {
01125       micro2 = mss->getMicroState2();
01126     }
01127 
01128     //    *out << fsm_.stateName()->toString() << std::endl;   
01129     *out << "<td>" << micro1 << "</td>";
01130     *out << "<td>" << micro2 << "</td>";
01131     *out << "<td>" << nbAccepted_.value_ << "/" << nbProcessed_.value_  
01132          << " (" << float(nbAccepted_.value_)/float(nbProcessed_.value_)*100. <<"%)" << "</td>";
01133     *out << "<td>" << lsid_ << "/" << lsidTimedOutAsString_ << "</td>";
01134     *out << "<td>" << psid_ << "</td>";
01135     
01136 
01137   }
01138   
01139   void FWEPWrapper::lumiSumTable(xgi::Output *out)
01140   {
01141     // lumisection summary table
01142     *out << "   <table border=1 bgcolor=\"#CFCFCF\">" << std::endl;
01143     *out << "     <tr>"                                                 << std::endl;
01144     *out << "       <td> LS </td>";
01145     if(rollingLsWrap_)
01146       {
01147         for(unsigned int i = rollingLsIndex_; i < lumiSectionsCtr_.size(); i++)
01148           *out << "<td " << (lumiSectionsTo_[i] ? "bgcolor=\"red\"" : "")
01149                << ">" << lumiSectionsCtr_[i].ls << "</td>" << std::endl;
01150         for(unsigned int i = 0; i < rollingLsIndex_; i++)
01151           *out << "<td " << (lumiSectionsTo_[i] ? "bgcolor=\"red\"" : "")
01152                << ">" << lumiSectionsCtr_[i].ls << "</td>" << std::endl;
01153       }
01154     else
01155       for(unsigned int i = rollingLsIndex_; i < lumiSectionsCtr_.size(); i++)
01156         *out << "<td  " << (lumiSectionsTo_[i] ? "bgcolor=\"red\"" : "")
01157              << ">" << lumiSectionsCtr_[i].ls << "</td>" << std::endl;
01158     
01159     *out << "     </tr>"                                                        << std::endl;    
01160     *out << "     <tr>"                                                 << std::endl;
01161     *out << "       <td> Ev </td>";
01162     if(rollingLsWrap_)
01163       {
01164         for(unsigned int i = rollingLsIndex_; i < lumiSectionsCtr_.size(); i++)
01165           *out << "<td>" << lumiSectionsCtr_[i].proc << "</td>" << std::endl;
01166         for(unsigned int i = 0; i < rollingLsIndex_; i++)
01167           *out << "<td>" << lumiSectionsCtr_[i].proc << "</td>" << std::endl;
01168       }
01169     else
01170       for(unsigned int i = rollingLsIndex_; i < lumiSectionsCtr_.size(); i++)
01171         *out << "<td>" << lumiSectionsCtr_[i].proc << "</td>" << std::endl;
01172     *out << "     </tr>"                                                        << std::endl;    
01173     *out << "     <tr>"                                                 << std::endl;
01174     *out << "       <td> Acc </td>";
01175     if(rollingLsWrap_)
01176       {
01177         for(unsigned int i = rollingLsIndex_; i < lumiSectionsCtr_.size(); i++)
01178           *out << "<td>" << lumiSectionsCtr_[i].acc << "</td>" << std::endl;
01179         for(unsigned int i = 0; i < rollingLsIndex_; i++)
01180           *out << "<td>" << lumiSectionsCtr_[i].acc << "</td>" << std::endl;
01181       }
01182     else
01183       for(unsigned int i = rollingLsIndex_; i < lumiSectionsCtr_.size(); i++)
01184         *out << "<td>" << lumiSectionsCtr_[i].acc << "</td>" << std::endl;
01185     *out << "     </tr>"                                                        << std::endl;    
01186     *out << "</table>" << std::endl;
01187   }
01188 
01189 
01190   void FWEPWrapper::sumAndPackTriggerReport(MsgBuf &buf)
01191   {
01192     trh_.sumAndPackTriggerReport(buf);
01193   }
01194   void FWEPWrapper::updateRollingReport()
01195   {
01196     trh_.packedTriggerReportToTable();
01197     if(rollingLsIndex_==0){rollingLsIndex_=lsRollSize_; rollingLsWrap_ = true;}
01198     rollingLsIndex_--;
01199     xdata::UnsignedInteger32* lsp = 0;
01200     xdata::UnsignedInteger32* psp = 0;
01201     TriggerReportStatic *tr = trh_.getPackedTriggerReportAsStruct();
01202     lsTriplet lst;
01203     lst.ls = tr->lumiSection;
01204     lsid_ = tr->lumiSection;
01205     lst.proc = tr->eventSummary.totalEvents;
01206     lst.acc = tr->eventSummary.totalEventsPassed;
01207     xdata::Serializable *psid = 0;
01208     xdata::Serializable *lsid = 0;
01209     xdata::Serializable *nbs = 0;
01210     xdata::Serializable *nbsr = 0;
01211     try{
01212       lsid =applicationInfoSpace_->find("lumiSectionIndex");
01213       if(lsid!=0){
01214         lsp = ((xdata::UnsignedInteger32*)lsid); 
01215         lsp->value_= tr->lumiSection;
01216       }
01217       psid = applicationInfoSpace_->find("lastLumiPrescaleIndex");
01218       if(psid!=0) {
01219         psp = ((xdata::UnsignedInteger32*)psid);
01220         if(tr->eventSummary.totalEvents != 0)
01221           psp->value_ = tr->prescaleIndex;
01222       }
01223       nbs  = applicationInfoSpace_->find("nbSubProcesses");
01224       nbsr = applicationInfoSpace_->find("nbSubProcessesReporting");
01225     }
01226     catch(xdata::exception::Exception e){
01227     }
01228 
01229     xdata::Table::iterator it = scalersComplete_.begin();
01230     if(lsp)
01231       it->setField("lsid", *lsp);
01232     if(psp)
01233       it->setField("psid", *psp);
01234     if(nbs)
01235       it->setField("exprep", *nbs);
01236     else
01237       std::cout << "nbSubProcesses item not found !!!" << std::endl;
01238     if(nbsr)
01239       it->setField("effrep", *nbsr);
01240     else
01241       std::cout << "nbSubProcessesReporting item not found !!!" << std::endl;
01242 
01243     it->setField("proc",trh_.getProcThisLumi());
01244     it->setField("acc",trh_.getAccThisLumi());
01245     it->setField("triggerReport",trh_.getTableWithNames());
01246     lumiSectionsCtr_[rollingLsIndex_] = lst;
01247 
01248   }
01249 
01250 
01251   void FWEPWrapper::createAndSendScalersMessage()
01252   {
01253     toolbox::net::URL url(rcms_->getContextDescriptor()->getURL());
01254     toolbox::net::URL at(xappDesc_->getContextDescriptor()->getURL() + "/" + xappDesc_->getURN());
01255     toolbox::net::URL properurl(url.getProtocol(),url.getHost(),url.getPort(),"");
01256     xdaq::ContextDescriptor *ctxdsc = new xdaq::ContextDescriptor(properurl.toString());
01257     xdaq::ApplicationDescriptor *appdesc = new xdaq::ApplicationDescriptorImpl(ctxdsc,rcms_->getClassName(),rcms_->getLocalId(), "pippo");
01258     
01259     appdesc->setAttribute("path","/rcms/servlet/monitorreceiver");
01260 
01261     xoap::MessageReference msg = xoap::createMessage();
01262     xoap::SOAPEnvelope envelope = msg->getSOAPPart().getEnvelope();
01263     xoap::SOAPName responseName = envelope.createName( "report", xmas::NamespacePrefix, xmas::NamespaceUri);
01264     (void) envelope.getBody().addBodyElement ( responseName );          
01265     xoap::SOAPName reportName ("report", xmas::NamespacePrefix, xmas::NamespaceUri);
01266     xoap::SOAPElement reportElement = envelope.getBody().getChildElements(reportName)[0];
01267     reportElement.addNamespaceDeclaration (xmas::sensor::NamespacePrefix, xmas::sensor::NamespaceUri);
01268     xoap::SOAPName sampleName = envelope.createName( "sample", xmas::NamespacePrefix, xmas::NamespaceUri);
01269     xoap::SOAPElement sampleElement = reportElement.addChildElement(sampleName);
01270     xoap::SOAPName flashListName = envelope.createName( "flashlist", "", "");
01271     sampleElement.addAttribute(flashListName,"urn:xdaq-flashlist:scalers");
01272     xoap::SOAPName tagName = envelope.createName( "tag", "", "");
01273     sampleElement.addAttribute(tagName,"tag");
01274     xoap::MimeHeaders* headers = msg->getMimeHeaders();
01275     headers->removeHeader("x-xdaq-tags");
01276     headers->addHeader("x-xdaq-tags", "tag");
01277     tagName = envelope.createName( "originator", "", "");
01278     sampleElement.addAttribute(tagName,at.toString());
01279 
01280     xdata::exdr::AutoSizeOutputStreamBuffer outBuffer;
01281     xdata::exdr::Serializer serializer;
01282     try
01283       {
01284         serializer.exportAll( &scalersComplete_, &outBuffer );
01285       }
01286     catch(xdata::exception::Exception & e)
01287       {
01288         LOG4CPLUS_WARN(log_,
01289                        "Exception in serialization of scalers table");      
01290         //      localLog("-W- Exception in serialization of scalers table");      
01291         throw;
01292       }
01293   
01294     xoap::AttachmentPart * attachment = msg->createAttachmentPart(outBuffer.getBuffer(), outBuffer.tellp(), "application/x-xdata+exdr");
01295     attachment->setContentEncoding("binary");
01296     tagName = envelope.createName( "tag", "", "");
01297     sampleElement.addAttribute(tagName,"tag");
01298     std::stringstream contentId;
01299 
01300     contentId << "<" <<  "urn:xdaq-flashlist:scalers" << "@" << at.getHost() << ">";
01301     attachment->setContentId(contentId.str());
01302     std::stringstream contentLocation;
01303     contentId << at.toString();
01304     attachment->setContentLocation(contentLocation.str());
01305   
01306     std::stringstream disposition;
01307     disposition << "attachment; filename=" << "urn:xdaq-flashlist:scalers" << ".exdr; creation-date=" << "\"" << "dummy" << "\"";
01308     attachment->addMimeHeader("Content-Disposition",disposition.str());
01309     msg->addAttachmentPart(attachment);
01310 
01311     try{
01312       xappCtxt_->postSOAP(msg,*(xappDesc_),*appdesc);
01313     }
01314     catch(xdaq::exception::Exception &ex)
01315       {
01316         std::string message = "exception when posting SOAP message to MonitorReceiver";
01317         message += ex.what();
01318         LOG4CPLUS_WARN(log_,message.c_str());
01319         std::string lmessage = "-W- "+message;
01320         delete appdesc; 
01321         delete ctxdsc;
01322         throw;
01323         //      localLog(lmessage);
01324       }
01325     delete appdesc; 
01326     delete ctxdsc;
01327   }
01328 }