CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/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 
00026 using namespace std;
00027 using namespace evf;
00028 
00029 
00031 // construction/destruction
00033 
00034 //______________________________________________________________________________
00035 BUProxy::BUProxy(xdaq::ApplicationDescriptor *fuAppDesc,
00036                  xdaq::ApplicationDescriptor *buAppDesc,
00037                  xdaq::ApplicationContext    *fuAppContext,
00038                  toolbox::mem::Pool          *i2oPool)
00039   : fuAppDesc_(fuAppDesc)
00040   , buAppDesc_(buAppDesc)
00041   , fuAppContext_(fuAppContext)
00042   , i2oPool_(i2oPool)
00043 {
00044   
00045 }
00046 
00047 
00048 //______________________________________________________________________________
00049 BUProxy::~BUProxy()
00050 {
00051 
00052 }
00053 
00054 
00056 // implementation of member functions
00058 
00059 //______________________________________________________________________________
00060 void BUProxy::sendAllocate(const UIntVec_t& fuResourceIds)
00061   throw (evf::Exception)
00062 {
00063   Logger log=fuAppContext_->getLogger();
00064 
00065   try {
00066     size_t msgSize=
00067       sizeof(I2O_BU_ALLOCATE_MESSAGE_FRAME)+
00068       sizeof(BU_ALLOCATE)*(fuResourceIds.size()-1);
00069     
00070     toolbox::mem::Reference *bufRef=
00071       toolbox::mem::getMemoryPoolFactory()->getFrame(i2oPool_,msgSize);
00072   
00073     I2O_MESSAGE_FRAME             *stdMsg;
00074     I2O_PRIVATE_MESSAGE_FRAME     *pvtMsg;
00075     I2O_BU_ALLOCATE_MESSAGE_FRAME *msg;
00076     
00077     stdMsg=(I2O_MESSAGE_FRAME*)bufRef->getDataLocation();
00078     pvtMsg=(I2O_PRIVATE_MESSAGE_FRAME*)stdMsg;
00079     msg   =(I2O_BU_ALLOCATE_MESSAGE_FRAME*)stdMsg; 
00080     
00081     stdMsg->MessageSize     =msgSize >> 2;
00082     stdMsg->InitiatorAddress=i2o::utils::getAddressMap()->getTid(fuAppDesc_);
00083     stdMsg->TargetAddress   =i2o::utils::getAddressMap()->getTid(buAppDesc_);
00084     stdMsg->Function        =I2O_PRIVATE_MESSAGE;
00085     stdMsg->VersionOffset   =0;
00086     stdMsg->MsgFlags        =0;  // Point-to-point
00087     
00088     pvtMsg->XFunctionCode   =I2O_BU_ALLOCATE;
00089     pvtMsg->OrganizationID  =XDAQ_ORGANIZATION_ID;
00090     
00091     msg->n                  =fuResourceIds.size();
00092     
00093     for(UInt_t i=0;i<fuResourceIds.size();i++) {
00094       msg->allocate[i].fuTransactionId=fuResourceIds[i];
00095       msg->allocate[i].fset           =1; // IGNORED!!!
00096     }
00097 
00098     bufRef->setDataSize(msgSize);
00099 
00100     fuAppContext_->postFrame(bufRef,fuAppDesc_,buAppDesc_);
00101   }
00102   catch(toolbox::mem::exception::Exception& e)  {
00103     string errmsg="Failed to allocate buffer reference.";
00104     LOG4CPLUS_ERROR(log,errmsg);
00105     XCEPT_RETHROW(evf::Exception,errmsg,e);
00106   }
00107   catch(xdaq::exception::ApplicationDescriptorNotFound& e) {
00108     string errmsg="Failed to get tid.";
00109     LOG4CPLUS_ERROR(log,errmsg);
00110     XCEPT_RETHROW(evf::Exception,errmsg,e);
00111   }
00112   catch(xdaq::exception::Exception& e) {
00113     string errmsg="Failed to post 'Allocate' message.";
00114     LOG4CPLUS_ERROR(log,errmsg);
00115     XCEPT_RETHROW(evf::Exception,errmsg,e);
00116   }
00117 }
00118 
00119 
00120 //______________________________________________________________________________
00121 void BUProxy::sendDiscard(UInt_t buResourceId)
00122   throw (evf::Exception)
00123 {
00124   Logger log=fuAppContext_->getLogger();
00125   
00126   try {
00127     size_t msgSize=sizeof(I2O_BU_DISCARD_MESSAGE_FRAME);
00128     
00129     toolbox::mem::Reference *bufRef=
00130       toolbox::mem::getMemoryPoolFactory()->getFrame(i2oPool_,msgSize);
00131     
00132     I2O_MESSAGE_FRAME         *stdMsg=(I2O_MESSAGE_FRAME*)bufRef->getDataLocation();
00133     I2O_PRIVATE_MESSAGE_FRAME *pvtMsg=(I2O_PRIVATE_MESSAGE_FRAME*)stdMsg;
00134     I2O_BU_DISCARD_MESSAGE_FRAME *msg=(I2O_BU_DISCARD_MESSAGE_FRAME*)stdMsg;
00135     
00136     stdMsg->MessageSize     =msgSize >> 2;
00137     stdMsg->InitiatorAddress=i2o::utils::getAddressMap()->getTid(fuAppDesc_);
00138     stdMsg->TargetAddress   =i2o::utils::getAddressMap()->getTid(buAppDesc_);
00139     stdMsg->Function        =I2O_PRIVATE_MESSAGE;
00140     stdMsg->VersionOffset   =0;
00141     stdMsg->MsgFlags        =0;  // Point-to-point
00142     
00143     pvtMsg->XFunctionCode   =I2O_BU_DISCARD;
00144     pvtMsg->OrganizationID  =XDAQ_ORGANIZATION_ID;
00145     
00146     msg->n                  =1;
00147     msg->buResourceId[0]    =buResourceId;
00148     
00149     bufRef->setDataSize(msgSize);
00150 
00151     fuAppContext_->postFrame(bufRef,fuAppDesc_,buAppDesc_);
00152   }
00153   catch (toolbox::mem::exception::Exception& e) {
00154     string errmsg="Failed to allocate buffer reference.";
00155     LOG4CPLUS_ERROR(log,errmsg);
00156     XCEPT_RETHROW(evf::Exception,errmsg,e);
00157   }
00158   catch (xdaq::exception::ApplicationDescriptorNotFound& e) {
00159     string errmsg="Failed to get tid.";
00160     LOG4CPLUS_ERROR(log,errmsg);
00161     XCEPT_RETHROW(evf::Exception,errmsg,e);
00162   }
00163   catch (xdaq::exception::Exception &e) {
00164     string errmsg="Failed to post 'Discard' message.";
00165     LOG4CPLUS_ERROR(log,errmsg);
00166     XCEPT_RETHROW(evf::Exception,errmsg,e);
00167   }
00168   
00169 }
00170