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