CMS 3D CMS Logo

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