00001
00002
00003
00004
00005
00006
00007
00009
00010 #include "EventFilter/ResourceBroker/interface/FUResourceBroker.h"
00011 #include "EventFilter/ResourceBroker/interface/SMEventScheduler.h"
00012
00013 #include "EventFilter/ResourceBroker/interface/FUResource.h"
00014 #include "EventFilter/ResourceBroker/interface/BUProxy.h"
00015 #include "EventFilter/ResourceBroker/interface/SMProxy.h"
00016 #include "EventFilter/ResourceBroker/interface/SoapUtils.h"
00017
00018 #include "i2o/Method.h"
00019 #include "interface/shared/i2oXFunctionCodes.h"
00020 #include "interface/evb/i2oEVBMsgs.h"
00021 #include "xcept/tools.h"
00022
00023 #include "toolbox/mem/HeapAllocator.h"
00024 #include "toolbox/mem/Reference.h"
00025 #include "toolbox/mem/MemoryPoolFactory.h"
00026 #include "toolbox/mem/exception/Exception.h"
00027
00028 #include "xoap/MessageReference.h"
00029 #include "xoap/MessageFactory.h"
00030 #include "xoap/SOAPEnvelope.h"
00031 #include "xoap/SOAPBody.h"
00032 #include "xoap/domutils.h"
00033 #include "xoap/Method.h"
00034
00035 #include "cgicc/CgiDefs.h"
00036 #include "cgicc/Cgicc.h"
00037 #include "cgicc/FormEntry.h"
00038 #include "cgicc/HTMLClasses.h"
00039
00040 #include <signal.h>
00041 #include <iostream>
00042 #include <sstream>
00043
00044 using std::string;
00045 using std::cout;
00046 using std::endl;
00047 using std::stringstream;
00048 using std::vector;
00049 using namespace evf;
00050 using namespace evf::rb_statemachine;
00051
00053
00055
00056
00057 FUResourceBroker::FUResourceBroker(xdaq::ApplicationStub *s) :
00058 xdaq::Application(s),
00059 res_(new SharedResources(getApplicationLogger())) {
00060
00061 bindStateMachineCallbacks();
00062
00063 res_->gui_ = new IndependentWebGUI(this);
00064 res_->gui_->setVersionString("Changeset: *** 05.07.2012 - V1.22 ***");
00065
00066
00067 fsm_.reset(new RBStateMachine(this, res_));
00068
00069
00070 fsm_->initiate();
00071
00072
00073 eventScheduler_ = new SMEventScheduler(fsm_, res_->commands_);
00074
00075
00076 url_ = getApplicationDescriptor()->getContextDescriptor()->getURL() + "/"
00077 + getApplicationDescriptor()->getURN();
00078 class_ = getApplicationDescriptor()->getClassName();
00079 instance_ = getApplicationDescriptor()->getInstance();
00080 res_->sourceId_ = class_.toString() + "_" + instance_.toString();
00081
00082
00083 i2o::bind(this, &FUResourceBroker::I2O_FU_TAKE_Callback, I2O_FU_TAKE,
00084 XDAQ_ORGANIZATION_ID);
00085 i2o::bind(this, &FUResourceBroker::I2O_FU_DATA_DISCARD_Callback,
00086 I2O_FU_DATA_DISCARD, XDAQ_ORGANIZATION_ID);
00087 i2o::bind(this, &FUResourceBroker::I2O_FU_DQM_DISCARD_Callback,
00088 I2O_FU_DQM_DISCARD, XDAQ_ORGANIZATION_ID);
00089 i2o::bind(this, &FUResourceBroker::I2O_EVM_LUMISECTION_Callback,
00090 I2O_EVM_LUMISECTION, XDAQ_ORGANIZATION_ID);
00091
00092
00093 xgi::bind(this, &evf::FUResourceBroker::webPageRequest, "Default");
00094
00095 vector<toolbox::lang::Method*> methods = res_->gui_->getMethods();
00096 vector<toolbox::lang::Method*>::iterator it;
00097 for (it = methods.begin(); it != methods.end(); ++it) {
00098 if ((*it)->type() == "cgi") {
00099 string name = static_cast<xgi::MethodSignature*> (*it)->name();
00100 xgi::bind(this, &evf::FUResourceBroker::webPageRequest, name);
00101 }
00102 }
00103 xgi::bind(this, &evf::FUResourceBroker::customWebPage, "customWebPage");
00104
00105
00106 string i2oPoolName = res_->sourceId_ + "_i2oPool";
00107 try {
00108 toolbox::mem::HeapAllocator *allocator =
00109 new toolbox::mem::HeapAllocator();
00110 toolbox::net::URN urn("toolbox-mem-pool", i2oPoolName);
00111 toolbox::mem::MemoryPoolFactory* poolFactory =
00112 toolbox::mem::getMemoryPoolFactory();
00113 res_->i2oPool_ = poolFactory->createPool(urn, allocator);
00114 } catch (toolbox::mem::exception::Exception& e) {
00115 string s = "Failed to create pool: " + i2oPoolName;
00116 LOG4CPLUS_FATAL(res_->log_, s);
00117 XCEPT_RETHROW(xcept::Exception, s, e);
00118 }
00119
00120
00121 exportParameters();
00122
00123
00124 fsm_->findRcmsStateListener(this);
00125
00126
00127 getApplicationDescriptor()->setAttribute("icon", "/evf/images/rbicon.jpg");
00128
00129
00130 }
00131
00132
00133 FUResourceBroker::~FUResourceBroker() {
00134 delete eventScheduler_;
00135 }
00136
00138
00140
00141
00142 void FUResourceBroker::bindStateMachineCallbacks() {
00143 xoap::bind(this, &FUResourceBroker::handleFSMSoapMessage, "Configure",
00144 XDAQ_NS_URI);
00145 xoap::bind(this, &FUResourceBroker::handleFSMSoapMessage, "Enable",
00146 XDAQ_NS_URI);
00147 xoap::bind(this, &FUResourceBroker::handleFSMSoapMessage, "Stop",
00148 XDAQ_NS_URI);
00149 xoap::bind(this, &FUResourceBroker::handleFSMSoapMessage, "Halt",
00150 XDAQ_NS_URI);
00151 }
00152
00153
00154 bool FUResourceBroker::waitForStateChange(string initialState,
00155 int timeoutMicroSec) {
00156 timeval start;
00157 timeval now;
00158
00159 gettimeofday(&start, 0);
00160
00161 while (fsm_->getExternallyVisibleState().compare(initialState) == 0) {
00162 gettimeofday(&now, 0);
00163 if (now.tv_usec <= start.tv_usec + timeoutMicroSec)
00164 ::usleep(50000);
00165 else
00166 return false;
00167 }
00168 return true;
00169 }
00170
00172
00174
00175 xoap::MessageReference FUResourceBroker::handleFSMSoapMessage(
00176 xoap::MessageReference msg) throw (xoap::exception::Exception) {
00177
00178 string errorMsg;
00179 xoap::MessageReference returnMsg;
00180
00181
00182 string initialState = fsm_->getExternallyVisibleState();
00183
00184 try {
00185 errorMsg
00186 = "Failed to extract FSM event and parameters from SOAP message: ";
00187 string command = soaputils::extractParameters(msg, this);
00188
00189 errorMsg = "Failed to put a '" + command
00190 + "' state machine event into command queue: ";
00191
00192 if (command == "Configure") {
00193
00194 EventPtr stMachEvent(new Configure());
00195 res_->commands_.enqEvent(stMachEvent);
00196
00197 } else if (command == "Enable") {
00198
00199 EventPtr stMachEvent(new Enable());
00200 res_->commands_.enqEvent(stMachEvent);
00201
00202 } else if (command == "Stop") {
00203
00204 EventPtr stMachEvent(new Stop());
00205 res_->commands_.enqEvent(stMachEvent);
00206
00207 } else if (command == "Halt") {
00208
00209 EventPtr stMachEvent(new Halt());
00210 res_->commands_.enqEvent(stMachEvent);
00211 }
00212
00213 else {
00214 XCEPT_RAISE(
00215 xcept::Exception,
00216 "Received an unknown state machine event '" + command
00217 + "'.");
00218
00219 EventPtr stMachEvent(new Fail());
00220 res_->commands_.enqEvent(stMachEvent);
00221 }
00222
00223 errorMsg = "Failed to create FSM SOAP reply message: ";
00224
00225
00226
00227 if (waitForStateChange(initialState, 2000000)) {
00228 returnMsg = soaputils::createFsmSoapResponseMsg(command,
00229 fsm_->getExternallyVisibleState());
00230 } else {
00231 XCEPT_RAISE(xcept::Exception,
00232 "FAILED TO REACH TARGET STATE FROM SOAP COMMAND WITHIN TIMEOUT!");
00233
00234 EventPtr stMachEvent(new Fail());
00235 res_->commands_.enqEvent(stMachEvent);
00236 }
00237
00238 } catch (xcept::Exception& e) {
00239 string s = "Exception on FSM Callback!";
00240 LOG4CPLUS_FATAL(res_->log_, s);
00241 XCEPT_RETHROW(xcept::Exception, s, e);
00242 }
00243
00244 return returnMsg;
00245 }
00246
00247
00248 void FUResourceBroker::I2O_FU_TAKE_Callback(toolbox::mem::Reference* bufRef) {
00249
00250 int currentStateID = -1;
00251 fsm_->transitionReadLock();
00252 currentStateID = fsm_->getCurrentState().stateID();
00253 fsm_->transitionUnlock();
00254
00255 if (currentStateID==rb_statemachine::RUNNING) {
00256 try {
00257 bool eventComplete = res_->resourceStructure_->buildResource(bufRef);
00258 if (eventComplete && res_->doDropEvents_)
00259 {
00260 cout << "dropping event" << endl;
00261 res_->resourceStructure_->dropEvent();
00262 }
00263 }
00264 catch (evf::Exception& e) {
00265 fsm_->getCurrentState().moveToFailedState(e);
00266 }
00267 }
00268 else {
00269
00270 stringstream details;
00271 details << " More details -> allocated events: "
00272 << res_->nbAllocatedEvents_ << ", pending requests to BU: "
00273 << res_->nbPendingRequests_ << ", received events: "
00274 << res_->nbReceivedEvents_;
00275 LOG4CPLUS_ERROR(
00276 res_->log_,
00277 "TAKE i2o frame received in state "
00278 << fsm_->getExternallyVisibleState()
00279 << " is being lost! THIS MEANS LOST EVENT DATA!"
00280 << details.str());
00281
00282 bufRef->release();
00283 }
00284 res_->nbTakeReceived_.value_++;
00285 }
00286
00287
00288 void FUResourceBroker::I2O_EVM_LUMISECTION_Callback(
00289 toolbox::mem::Reference* bufRef) {
00290
00291 int currentStateID = -1;
00292 fsm_->transitionReadLock();
00293 currentStateID = fsm_->getCurrentState().stateID();
00294 fsm_->transitionUnlock();
00295
00296 bool success = true;
00297 if (currentStateID==rb_statemachine::RUNNING) {
00298
00299 I2O_EVM_END_OF_LUMISECTION_MESSAGE_FRAME *msg =
00300 (I2O_EVM_END_OF_LUMISECTION_MESSAGE_FRAME *) bufRef->getDataLocation();
00301 if (msg->lumiSection == 0) {
00302 LOG4CPLUS_ERROR(res_->log_, "EOL message received for ls=0!!! ");
00303 EventPtr fail(new Fail());
00304 res_->commands_.enqEvent(fail);
00305 success=false;
00306 }
00307 if (success) {
00308 res_->nbReceivedEol_++;
00309 if (res_->highestEolReceived_.value_ + 100 < msg->lumiSection) {
00310 LOG4CPLUS_ERROR( res_->log_, "EOL message not in sequence, expected "
00311 << res_->highestEolReceived_.value_ + 1 << " received "
00312 << msg->lumiSection);
00313
00314 EventPtr fail(new Fail());
00315 res_->commands_.enqEvent(fail);
00316 success=false;
00317 }
00318 }
00319 if (success) {
00320 if (res_->highestEolReceived_.value_ + 1 != msg->lumiSection)
00321 LOG4CPLUS_WARN( res_->log_, "EOL message not in sequence, expected "
00322 << res_->highestEolReceived_.value_ + 1 << " received "
00323 << msg->lumiSection);
00324
00325 if (res_->highestEolReceived_.value_ < msg->lumiSection)
00326 res_->highestEolReceived_.value_ = msg->lumiSection;
00327
00328 try {
00329 res_->resourceStructure_->postEndOfLumiSection(bufRef);
00330 } catch (evf::Exception& e) {
00331 fsm_->getCurrentState().moveToFailedState(e);
00332 }
00333 }
00334 }
00335 else success=false;
00336
00337 if (!success) LOG4CPLUS_ERROR(res_->log_,"EOL i2o frame received in state "
00338 << fsm_->getExternallyVisibleState() << " is being lost");
00339 bufRef->release();
00340 }
00341
00342
00343 void FUResourceBroker::I2O_FU_DATA_DISCARD_Callback(
00344 toolbox::mem::Reference* bufRef) {
00345
00346
00347 res_->lockRSAccess();
00348
00349 fsm_->transitionReadLock();
00350 const BaseState& currentState = fsm_->getCurrentState();
00351
00352 if (res_->allowI2ODiscards_)
00353
00354 currentState.discardDataEvent(bufRef);
00355 else {
00356 LOG4CPLUS_WARN(
00357 res_->log_,
00358 "Data Discard I2O message received from SM is being ignored! ShmBuffer was reinitialized!");
00359 bufRef->release();
00360 }
00361 fsm_->transitionUnlock();
00362 res_->unlockRSAccess();
00363
00364 res_->nbDataDiscardReceived_.value_++;
00365 }
00366
00367
00368 void FUResourceBroker::I2O_FU_DQM_DISCARD_Callback(
00369 toolbox::mem::Reference* bufRef) {
00370
00371
00372 res_->lockRSAccess();
00373
00374 fsm_->transitionReadLock();
00375 const BaseState& currentState = fsm_->getCurrentState();
00376
00377 if (res_->allowI2ODiscards_)
00378
00379 currentState.discardDqmEvent(bufRef);
00380 else {
00381 LOG4CPLUS_WARN(
00382 res_->log_,
00383 "DQM Discard I2O message received from SM is being ignored! ShmBuffer was reinitialized!");
00384 bufRef->release();
00385 }
00386 fsm_->transitionUnlock();
00387 res_->unlockRSAccess();
00388
00389 res_->nbDqmDiscardReceived_.value_++;
00390 }
00391
00392
00393 void FUResourceBroker::webPageRequest(xgi::Input *in, xgi::Output *out)
00394 throw (xgi::exception::Exception) {
00395 string name = in->getenv("PATH_INFO");
00396 if (name.empty())
00397 name = "defaultWebPage";
00398 static_cast<xgi::MethodSignature*> (res_->gui_->getMethod(name))->invoke(
00399 in, out);
00400 }
00401
00402
00403 void FUResourceBroker::actionPerformed(xdata::Event& e) {
00404 res_->lock();
00405
00406 if (0 != res_->resourceStructure_) {
00407
00408
00409
00410 if (e.type() == "urn:xdata-event:ItemGroupRetrieveEvent") {
00411 res_->nbClients_ = res_->resourceStructure_->nbClients();
00412 res_->clientPrcIds_
00413 = res_->resourceStructure_->clientPrcIdsAsString();
00414 res_->nbAllocatedEvents_ = res_->resourceStructure_->nbAllocated();
00415 res_->nbPendingRequests_ = res_->resourceStructure_->nbPending();
00416 res_->nbReceivedEvents_ = res_->resourceStructure_->nbCompleted();
00417 res_->nbSentEvents_ = res_->resourceStructure_->nbSent();
00418 res_->nbSentDqmEvents_ = res_->resourceStructure_->nbSentDqm();
00419 res_->nbSentErrorEvents_ = res_->resourceStructure_->nbSentError();
00420
00421 int nbPSMD = res_->resourceStructure_->nbPendingSMDiscards();
00422 if (nbPSMD>=0) res_->nbPendingSMDiscards_=(unsigned int)nbPSMD;
00423 else res_->nbPendingSMDiscards_=0;
00424
00425 res_->nbPendingSMDqmDiscards_
00426 = res_->resourceStructure_->nbPendingSMDqmDiscards();
00427 res_->nbDiscardedEvents_ = res_->resourceStructure_->nbDiscarded();
00428 res_->nbLostEvents_ = res_->resourceStructure_->nbLost();
00429
00430 res_->nbEolPosted_ = res_->resourceStructure_->nbEolPosted();
00431 res_->nbEolDiscarded_ = res_->resourceStructure_->nbEolDiscarded();
00432 res_->nbDataErrors_ = res_->resourceStructure_->nbErrors();
00433 res_->nbCrcErrors_ = res_->resourceStructure_->nbCrcErrors();
00434 res_->nbAllocateSent_ = res_->resourceStructure_->nbAllocSent();
00435 res_->dataErrorFlag_.value_ = (res_->nbCrcErrors_.value_ != 0u
00436 + ((res_->nbDataErrors_.value_ != 0u) << 1)
00437 + ((res_->nbLostEvents_.value_ != 0u) << 2)
00438 + ((res_->nbTimeoutsWithEvent_.value_ != 0u) << 3)
00439 + ((res_->nbTimeoutsWithoutEvent_.value_ != 0u) << 4)
00440 + ((res_->nbSentErrorEvents_.value_ != 0u) << 5));
00441
00442 } else if (e.type() == "ItemChangedEvent") {
00443
00444 string item = dynamic_cast<xdata::ItemChangedEvent&> (e).itemName();
00445
00446 if (item == "doFedIdCheck")
00447 FUResource::doFedIdCheck(res_->doFedIdCheck_);
00448 if (item == "useEvmBoard")
00449 FUResource::useEvmBoard(res_->useEvmBoard_);
00450 if (item == "doCrcCheck")
00451 res_->resourceStructure_->setDoCrcCheck(res_->doCrcCheck_);
00452 if (item == "doDumpEvents")
00453 res_->resourceStructure_->setDoDumpEvents(res_->doDumpEvents_);
00454 }
00455
00456
00457 } else {
00458 res_->nbClients_ = 0;
00459 res_->clientPrcIds_ = "";
00460 res_->nbAllocatedEvents_ = 0;
00461 res_->nbPendingRequests_ = 0;
00462 res_->nbReceivedEvents_ = 0;
00463 res_->nbSentEvents_ = 0;
00464 res_->nbSentDqmEvents_ = 0;
00465 res_->nbSentErrorEvents_ = 0;
00466 res_->nbPendingSMDiscards_ = 0;
00467 res_->nbPendingSMDqmDiscards_ = 0;
00468 res_->nbDiscardedEvents_ = 0;
00469 res_->nbLostEvents_ = 0;
00470 res_->nbDataErrors_ = 0;
00471 res_->nbCrcErrors_ = 0;
00472 res_->nbAllocateSent_ = 0;
00473 }
00474 res_->unlock();
00475 }
00476
00477
00478 void FUResourceBroker::exportParameters() {
00479 assert(0 != res_->gui_);
00480
00481 res_->gui_->addMonitorParam("url", &url_);
00482 res_->gui_->addMonitorParam("class", &class_);
00483 res_->gui_->addMonitorParam("instance", &instance_);
00484 res_->gui_->addMonitorParam("runNumber", &res_->runNumber_);
00485 res_->gui_->addMonitorParam("stateName",
00486 fsm_->getExternallyVisibleStatePtr());
00487
00488 res_->gui_->addMonitorParam("deltaT", &res_->deltaT_);
00489 res_->gui_->addMonitorParam("deltaN", &res_->deltaN_);
00490 res_->gui_->addMonitorParam("deltaSumOfSquares", &res_->deltaSumOfSquares_);
00491 res_->gui_->addMonitorParam("deltaSumOfSizes", &res_->deltaSumOfSizes_);
00492
00493 res_->gui_->addMonitorParam("throughput", &res_->throughput_);
00494 res_->gui_->addMonitorParam("rate", &res_->rate_);
00495 res_->gui_->addMonitorParam("average", &res_->average_);
00496 res_->gui_->addMonitorParam("rms", &res_->rms_);
00497 res_->gui_->addMonitorParam("dataErrorFlag", &res_->dataErrorFlag_);
00498
00499 res_->gui_->addMonitorCounter("nbAllocatedEvents",
00500 &res_->nbAllocatedEvents_);
00501 res_->gui_->addMonitorCounter("nbPendingRequests",
00502 &res_->nbPendingRequests_);
00503 res_->gui_->addMonitorCounter("nbReceivedEvents", &res_->nbReceivedEvents_);
00504 res_->gui_->addMonitorCounter("nbSentEvents", &res_->nbSentEvents_);
00505 res_->gui_->addMonitorCounter("nbSentErrorEvents",
00506 &res_->nbSentErrorEvents_);
00507 res_->gui_->addMonitorCounter("nbDiscardedEvents",
00508 &res_->nbDiscardedEvents_);
00509
00510 res_->gui_->addMonitorCounter("nbReceivedEol", &res_->nbReceivedEol_);
00511 res_->gui_->addMonitorCounter("highestEolReceived",
00512 &res_->highestEolReceived_);
00513 res_->gui_->addMonitorCounter("nbEolPosted", &res_->nbEolPosted_);
00514 res_->gui_->addMonitorCounter("nbEolDiscarded", &res_->nbEolDiscarded_);
00515
00516 res_->gui_->addMonitorCounter("nbPendingSMDiscards",
00517 &res_->nbPendingSMDiscards_);
00518
00519 res_->gui_->addMonitorCounter("nbSentDqmEvents", &res_->nbSentDqmEvents_);
00520 res_->gui_->addMonitorCounter("nbDqmDiscardReceived",
00521 &res_->nbDqmDiscardReceived_);
00522 res_->gui_->addMonitorCounter("nbPendingSMDqmDiscards",
00523 &res_->nbPendingSMDqmDiscards_);
00524
00525 res_->gui_->addMonitorCounter("nbLostEvents", &res_->nbLostEvents_);
00526 res_->gui_->addMonitorCounter("nbDataErrors", &res_->nbDataErrors_);
00527 res_->gui_->addMonitorCounter("nbCrcErrors", &res_->nbCrcErrors_);
00528 res_->gui_->addMonitorCounter("nbTimeoutsWithEvent",
00529 &res_->nbTimeoutsWithEvent_);
00530 res_->gui_->addMonitorCounter("nbTimeoutsWithoutEvent",
00531 &res_->nbTimeoutsWithoutEvent_);
00532
00533 res_->gui_->addStandardParam("segmentationMode", &res_->segmentationMode_);
00534 res_->gui_->addStandardParam("useMessageQueueIPC",
00535 &res_->useMessageQueueIPC_);
00536 res_->gui_->addStandardParam("nbClients", &res_->nbClients_);
00537 res_->gui_->addStandardParam("clientPrcIds", &res_->clientPrcIds_);
00538 res_->gui_->addStandardParam("nbRawCells", &res_->nbRawCells_);
00539 res_->gui_->addStandardParam("nbRecoCells", &res_->nbRecoCells_);
00540 res_->gui_->addStandardParam("nbDqmCells", &res_->nbDqmCells_);
00541 res_->gui_->addStandardParam("rawCellSize", &res_->rawCellSize_);
00542 res_->gui_->addStandardParam("recoCellSize", &res_->recoCellSize_);
00543 res_->gui_->addStandardParam("dqmCellSize", &res_->dqmCellSize_);
00544 res_->gui_->addStandardParam("nbFreeResRequiredForAllocate",
00545 &res_->freeResRequiredForAllocate_);
00546
00547 res_->gui_->addStandardParam("doDropEvents", &res_->doDropEvents_);
00548 res_->gui_->addStandardParam("doFedIdCheck", &res_->doFedIdCheck_);
00549 res_->gui_->addStandardParam("doCrcCheck", &res_->doCrcCheck_);
00550 res_->gui_->addStandardParam("doDumpEvents", &res_->doDumpEvents_);
00551 res_->gui_->addStandardParam("buClassName", &res_->buClassName_);
00552 res_->gui_->addStandardParam("buInstance", &res_->buInstance_);
00553 res_->gui_->addStandardParam("smClassName", &res_->smClassName_);
00554 res_->gui_->addStandardParam("smInstance", &res_->smInstance_);
00555 res_->gui_->addStandardParam("resourceStructureTimeout_",
00556 &res_->resourceStructureTimeout_);
00557 res_->gui_->addStandardParam("monSleepSec", &res_->monSleepSec_);
00558 res_->gui_->addStandardParam("watchSleepSec", &res_->watchSleepSec_);
00559 res_->gui_->addStandardParam("timeOutSec", &res_->timeOutSec_);
00560 res_->gui_->addStandardParam("processKillerEnabled",
00561 &res_->processKillerEnabled_);
00562 res_->gui_->addStandardParam("useEvmBoard", &res_->useEvmBoard_);
00563 res_->gui_->addStandardParam("rcmsStateListener", fsm_->rcmsStateListener());
00564
00565 res_->gui_->addStandardParam("foundRcmsStateListener",
00566 fsm_->foundRcmsStateListener());
00567
00568 res_->gui_->addStandardParam("reasonForFailed", &res_->reasonForFailed_);
00569
00570 res_->gui_->addDebugCounter("nbAllocateSent", &res_->nbAllocateSent_);
00571 res_->gui_->addDebugCounter("nbTakeReceived", &res_->nbTakeReceived_);
00572 res_->gui_->addDebugCounter("nbDataDiscardReceived",
00573 &res_->nbDataDiscardReceived_);
00574
00575 res_->gui_->exportParameters();
00576
00577 res_->gui_->addItemChangedListener("doFedIdCheck", this);
00578 res_->gui_->addItemChangedListener("useEvmBoard", this);
00579 res_->gui_->addItemChangedListener("doCrcCheck", this);
00580 res_->gui_->addItemChangedListener("doDumpEvents", this);
00581
00582 }
00583
00584
00585 void FUResourceBroker::customWebPage(xgi::Input*in, xgi::Output*out)
00586 throw (xgi::exception::Exception) {
00587 using namespace cgicc;
00588 Cgicc cgi(in);
00589 std::vector < FormEntry > els = cgi.getElements();
00590 for (std::vector<FormEntry>::iterator it = els.begin(); it != els.end(); it++)
00591 cout << "form entry " << (*it).getValue() << endl;
00592
00593 std::vector < FormEntry > el1;
00594 cgi.getElement("crcError", el1);
00595 *out << "<html>" << endl;
00596 res_->gui_->htmlHead(in, out, res_->sourceId_);
00597 *out << "<body>" << endl;
00598 res_->gui_->htmlHeadline(in, out);
00599
00600 res_->lock();
00601
00602 if (0 != res_->resourceStructure_) {
00603 if (el1.size() != 0) {
00604 res_->resourceStructure_->injectCRCError();
00605 }
00606 *out << "<form method=\"GET\" action=\"customWebPage\" >";
00607 *out
00608 << "<button name=\"crcError\" type=\"submit\" value=\"injCRC\">Inject CRC</button>"
00609 << endl;
00610 *out << "</form>" << endl;
00611 *out << "<hr/>" << endl;
00612 vector < pid_t > client_prc_ids
00613 = res_->resourceStructure_->clientPrcIds();
00614 *out << table().set("frame", "void").set("rules", "rows") .set("class",
00615 "modules").set("width", "250") << endl << tr() << th(
00616 "Client Processes").set("colspan", "3") << tr() << endl << tr()
00617 << th("client").set("align", "left") << th("process id").set(
00618 "align", "center") << th("status").set("align", "center")
00619 << tr() << endl;
00620 for (UInt_t i = 0; i < client_prc_ids.size(); i++) {
00621
00622 pid_t pid = client_prc_ids[i];
00623 int status = kill(pid, 0);
00624
00625 stringstream ssi;
00626 ssi << i + 1;
00627 stringstream sspid;
00628 sspid << pid;
00629 stringstream ssstatus;
00630 ssstatus << status;
00631
00632 string bg_status = (status == 0) ? "#00ff00" : "ff0000";
00633 *out << tr() << td(ssi.str()).set("align", "left") << td(
00634 sspid.str()).set("align", "center")
00635 << td(ssstatus.str()).set("align", "center").set("bgcolor",
00636 bg_status) << tr() << endl;
00637 }
00638 *out << table() << endl;
00639 *out << "<br><br>" << endl;
00640
00641 vector < string > states = res_->resourceStructure_->cellStates();
00642 vector < UInt_t > evt_numbers
00643 = res_->resourceStructure_->cellEvtNumbers();
00644 vector < pid_t > prc_ids = res_->resourceStructure_->cellPrcIds();
00645 vector < time_t > time_stamps
00646 = res_->resourceStructure_->cellTimeStamps();
00647
00648 *out << table().set("frame", "void").set("rules", "rows") .set("class",
00649 "modules").set("width", "500") << endl << tr() << th(
00650 "Shared Memory Cells").set("colspan", "6") << tr() << endl
00651 << tr() << th("cell").set("align", "left") << th("state").set(
00652 "align", "center") << th("event").set("align", "center") << th(
00653 "process id").set("align", "center") << th("timestamp").set(
00654 "align", "center") << th("time").set("align", "center") << tr()
00655 << endl;
00656 for (UInt_t i = 0; i < states.size(); i++) {
00657 string state = states[i];
00658 UInt_t evt = evt_numbers[i];
00659 pid_t pid = prc_ids[i];
00660 time_t tstamp = time_stamps[i];
00661 double tdiff = difftime(time(0), tstamp);
00662
00663 stringstream ssi;
00664 ssi << i;
00665 stringstream ssevt;
00666 if (evt != 0xffffffff)
00667 ssevt << evt;
00668 else
00669 ssevt << " - ";
00670 stringstream sspid;
00671 if (pid != 0)
00672 sspid << pid;
00673 else
00674 sspid << " - ";
00675 stringstream sststamp;
00676 if (tstamp != 0)
00677 sststamp << tstamp;
00678 else
00679 sststamp << " - ";
00680 stringstream sstdiff;
00681 if (tstamp != 0)
00682 sstdiff << tdiff;
00683 else
00684 sstdiff << " - ";
00685
00686 string bg_state = "#ffffff";
00687 if (state == "RAWWRITING" || state == "RAWWRITTEN" || state
00688 == "RAWREADING" || state == "RAWREAD")
00689 bg_state = "#99CCff";
00690 else if (state == "PROCESSING")
00691 bg_state = "#ff0000";
00692 else if (state == "PROCESSED" || state == "RECOWRITING" || state
00693 == "RECOWRITTEN")
00694 bg_state = "#CCff99";
00695 else if (state == "SENDING")
00696 bg_state = "#00FF33";
00697 else if (state == "SENT")
00698 bg_state = "#006633";
00699 else if (state == "DISCARDING")
00700 bg_state = "#FFFF00";
00701 else if (state == "LUMISECTION")
00702 bg_state = "#0000FF";
00703
00704 *out << tr() << td(ssi.str()).set("align", "left")
00705 << td(state).set("align", "center").set("bgcolor", bg_state)
00706 << td(ssevt.str()).set("align", "center")
00707 << td(sspid.str()).set("align", "center") << td(
00708 sststamp.str()).set("align", "center")
00709 << td(sstdiff.str()).set("align", "center") << tr() << endl;
00710 }
00711 *out << table() << endl;
00712 *out << "<br><br>" << endl;
00713
00714 vector < string > dqmstates = res_->resourceStructure_->dqmCellStates();
00715
00716 *out << table().set("frame", "void").set("rules", "rows") .set("class",
00717 "modules").set("width", "500") << endl << tr() << th(
00718 "Shared Memory DQM Cells").set("colspan", "6") << tr() << endl
00719 << tr() << th("cell").set("align", "left") << th("state").set(
00720 "align", "center") << tr() << endl;
00721 for (UInt_t i = 0; i < dqmstates.size(); i++) {
00722 string state = dqmstates[i];
00723
00724 string bg_state = "#ffffff";
00725 if (state == "WRITING" || state == "WRITTEN")
00726 bg_state = "#99CCff";
00727 else if (state == "SENDING")
00728 bg_state = "#00FF33";
00729 else if (state == "SENT")
00730 bg_state = "#006633";
00731 else if (state == "DISCARDING")
00732 bg_state = "#FFFF00";
00733
00734 *out << tr() << "<td>" << i << "</td>" << td(state).set("align",
00735 "center").set("bgcolor", bg_state) << tr() << endl;
00736 }
00737 *out << table() << endl;
00738
00739 }
00740 *out << "</body>" << endl << "</html>" << endl;
00741
00742 res_->unlock();
00743 }
00744
00746
00748
00749 XDAQ_INSTANTIATOR_IMPL(FUResourceBroker)