CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/EventFilter/ResourceBroker/src/BUProxy.cc

Go to the documentation of this file.
00001 
00002 //
00003 // BUProxy
00004 // -------
00005 //
00007 
00008 
00009 #include "EventFilter/ResourceBroker/interface/BUProxy.h"
00010 
00011 #include "toolbox/mem/Reference.h"
00012 #include "toolbox/mem/MemoryPoolFactory.h"
00013 #include "toolbox/mem/exception/Exception.h"
00014 
00015 #include "i2o/Method.h"
00016 #include "i2o/utils/AddressMap.h"
00017 
00018 #include "xcept/tools.h"
00019 
00020 #include "interface/evb/i2oEVBMsgs.h" 
00021 #include "interface/shared/i2oXFunctionCodes.h"
00022 
00023 #include <iostream>
00024 
00025 using namespace std;
00026 using namespace evf;
00027 
00029 // construction/destruction
00031 
00032 //______________________________________________________________________________
00033 BUProxy::BUProxy(xdaq::ApplicationDescriptor *fuAppDesc,
00034                 xdaq::ApplicationDescriptor *buAppDesc,
00035                 xdaq::ApplicationContext *fuAppContext, toolbox::mem::Pool *i2oPool) :
00036         fuAppDesc_(fuAppDesc), buAppDesc_(buAppDesc), fuAppContext_(fuAppContext),
00037                         i2oPool_(i2oPool) {
00038 
00039 }
00040 
00041 //______________________________________________________________________________
00042 BUProxy::~BUProxy() {
00043 
00044 }
00045 
00047 // implementation of member functions
00049 
00050 //______________________________________________________________________________
00051 void BUProxy::sendAllocate(const UIntVec_t& fuResourceIds)
00052                 throw (evf::Exception) {
00053         Logger log = fuAppContext_->getLogger();
00054 
00055         try {
00056                 size_t msgSize = sizeof(I2O_BU_ALLOCATE_MESSAGE_FRAME)
00057                                 + sizeof(BU_ALLOCATE) * (fuResourceIds.size() - 1);
00058 
00059                 toolbox::mem::Reference *bufRef =
00060                                 toolbox::mem::getMemoryPoolFactory()->getFrame(i2oPool_,
00061                                                 msgSize);
00062 
00063                 I2O_MESSAGE_FRAME *stdMsg;
00064                 I2O_PRIVATE_MESSAGE_FRAME *pvtMsg;
00065                 I2O_BU_ALLOCATE_MESSAGE_FRAME *msg;
00066 
00067                 stdMsg = (I2O_MESSAGE_FRAME*) bufRef->getDataLocation();
00068                 pvtMsg = (I2O_PRIVATE_MESSAGE_FRAME*) stdMsg;
00069                 msg = (I2O_BU_ALLOCATE_MESSAGE_FRAME*) stdMsg;
00070 
00071                 stdMsg->MessageSize = msgSize >> 2;
00072                 stdMsg->InitiatorAddress = i2o::utils::getAddressMap()->getTid(
00073                                 fuAppDesc_);
00074                 stdMsg->TargetAddress = i2o::utils::getAddressMap()->getTid(buAppDesc_);
00075                 stdMsg->Function = I2O_PRIVATE_MESSAGE;
00076                 stdMsg->VersionOffset = 0;
00077                 stdMsg->MsgFlags = 0; // Point-to-point
00078 
00079                 pvtMsg->XFunctionCode = I2O_BU_ALLOCATE;
00080                 pvtMsg->OrganizationID = XDAQ_ORGANIZATION_ID;
00081 
00082                 msg->n = fuResourceIds.size();
00083 
00084                 for (UInt_t i = 0; i < fuResourceIds.size(); i++) {
00085                         msg->allocate[i].fuTransactionId = fuResourceIds[i];
00086                         msg->allocate[i].fset = 1; // IGNORED!!!
00087                 }
00088 
00089                 bufRef->setDataSize(msgSize);
00090 
00091                 fuAppContext_->postFrame(bufRef, fuAppDesc_, buAppDesc_);
00092         } catch (toolbox::mem::exception::Exception& e) {
00093                 string errmsg = "Failed to allocate buffer reference.";
00094                 LOG4CPLUS_ERROR(log, errmsg);
00095                 XCEPT_RETHROW(evf::Exception, errmsg, e);
00096         } catch (xdaq::exception::ApplicationDescriptorNotFound& e) {
00097                 string errmsg = "Failed to get tid.";
00098                 LOG4CPLUS_ERROR(log, errmsg);
00099                 XCEPT_RETHROW(evf::Exception, errmsg, e);
00100         } catch (xdaq::exception::Exception& e) {
00101                 string errmsg = "Failed to post 'Allocate' message.";
00102                 LOG4CPLUS_ERROR(log, errmsg);
00103                 XCEPT_RETHROW(evf::Exception, errmsg, e);
00104         }
00105 }
00106 
00107 //______________________________________________________________________________
00108 void BUProxy::sendDiscard(UInt_t buResourceId) throw (evf::Exception) {
00109         Logger log = fuAppContext_->getLogger();
00110 
00111         try {
00112                 size_t msgSize = sizeof(I2O_BU_DISCARD_MESSAGE_FRAME);
00113 
00114                 toolbox::mem::Reference *bufRef =
00115                                 toolbox::mem::getMemoryPoolFactory()->getFrame(i2oPool_,
00116                                                 msgSize);
00117 
00118                 I2O_MESSAGE_FRAME *stdMsg =
00119                                 (I2O_MESSAGE_FRAME*) bufRef->getDataLocation();
00120                 I2O_PRIVATE_MESSAGE_FRAME *pvtMsg = (I2O_PRIVATE_MESSAGE_FRAME*) stdMsg;
00121                 I2O_BU_DISCARD_MESSAGE_FRAME *msg =
00122                                 (I2O_BU_DISCARD_MESSAGE_FRAME*) stdMsg;
00123 
00124                 stdMsg->MessageSize = msgSize >> 2;
00125                 stdMsg->InitiatorAddress = i2o::utils::getAddressMap()->getTid(
00126                                 fuAppDesc_);
00127                 stdMsg->TargetAddress = i2o::utils::getAddressMap()->getTid(buAppDesc_);
00128                 stdMsg->Function = I2O_PRIVATE_MESSAGE;
00129                 stdMsg->VersionOffset = 0;
00130                 stdMsg->MsgFlags = 0; // Point-to-point
00131 
00132                 pvtMsg->XFunctionCode = I2O_BU_DISCARD;
00133                 pvtMsg->OrganizationID = XDAQ_ORGANIZATION_ID;
00134 
00135                 msg->n = 1;
00136                 msg->buResourceId[0] = buResourceId;
00137 
00138                 bufRef->setDataSize(msgSize);
00139 
00140                 fuAppContext_->postFrame(bufRef, fuAppDesc_, buAppDesc_);
00141         } catch (toolbox::mem::exception::Exception& e) {
00142                 string errmsg = "Failed to allocate buffer reference.";
00143                 LOG4CPLUS_ERROR(log, errmsg);
00144                 XCEPT_RETHROW(evf::Exception, errmsg, e);
00145         } catch (xdaq::exception::ApplicationDescriptorNotFound& e) {
00146                 string errmsg = "Failed to get tid.";
00147                 LOG4CPLUS_ERROR(log, errmsg);
00148                 XCEPT_RETHROW(evf::Exception, errmsg, e);
00149         } catch (xdaq::exception::Exception &e) {
00150                 string errmsg = "Failed to post 'Discard' message.";
00151                 LOG4CPLUS_ERROR(log, errmsg);
00152                 XCEPT_RETHROW(evf::Exception, errmsg, e);
00153         }
00154 
00155 }