CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BUProxy.cc
Go to the documentation of this file.
1 //
3 // BUProxy
4 // -------
5 //
7 
8 
10 
11 #include "toolbox/mem/Reference.h"
12 #include "toolbox/mem/MemoryPoolFactory.h"
13 #include "toolbox/mem/exception/Exception.h"
14 
15 #include "i2o/Method.h"
16 #include "i2o/utils/AddressMap.h"
17 
18 #include "xcept/tools.h"
19 
20 #include "interface/evb/i2oEVBMsgs.h"
21 #include "interface/shared/i2oXFunctionCodes.h"
22 
23 #include <iostream>
24 
25 using namespace std;
26 using namespace evf;
27 
29 // construction/destruction
31 
32 //______________________________________________________________________________
33 BUProxy::BUProxy(xdaq::ApplicationDescriptor *fuAppDesc,
34  xdaq::ApplicationDescriptor *buAppDesc,
35  xdaq::ApplicationContext *fuAppContext, toolbox::mem::Pool *i2oPool) :
36  fuAppDesc_(fuAppDesc), buAppDesc_(buAppDesc), fuAppContext_(fuAppContext),
37  i2oPool_(i2oPool) {
38 
39 }
40 
41 //______________________________________________________________________________
43 
44 }
45 
47 // implementation of member functions
49 
50 //______________________________________________________________________________
51 void BUProxy::sendAllocate(const UIntVec_t& fuResourceIds)
52  throw (evf::Exception) {
53  Logger log = fuAppContext_->getLogger();
54 
55  try {
56  size_t msgSize = sizeof(I2O_BU_ALLOCATE_MESSAGE_FRAME)
57  + sizeof(BU_ALLOCATE) * (fuResourceIds.size() - 1);
58 
59  toolbox::mem::Reference *bufRef =
60  toolbox::mem::getMemoryPoolFactory()->getFrame(i2oPool_,
61  msgSize);
62 
63  I2O_MESSAGE_FRAME *stdMsg;
64  I2O_PRIVATE_MESSAGE_FRAME *pvtMsg;
65  I2O_BU_ALLOCATE_MESSAGE_FRAME *msg;
66 
67  stdMsg = (I2O_MESSAGE_FRAME*) bufRef->getDataLocation();
68  pvtMsg = (I2O_PRIVATE_MESSAGE_FRAME*) stdMsg;
69  msg = (I2O_BU_ALLOCATE_MESSAGE_FRAME*) stdMsg;
70 
71  stdMsg->MessageSize = msgSize >> 2;
72  stdMsg->InitiatorAddress = i2o::utils::getAddressMap()->getTid(
73  fuAppDesc_);
74  stdMsg->TargetAddress = i2o::utils::getAddressMap()->getTid(buAppDesc_);
75  stdMsg->Function = I2O_PRIVATE_MESSAGE;
76  stdMsg->VersionOffset = 0;
77  stdMsg->MsgFlags = 0; // Point-to-point
78 
79  pvtMsg->XFunctionCode = I2O_BU_ALLOCATE;
80  pvtMsg->OrganizationID = XDAQ_ORGANIZATION_ID;
81 
82  msg->n = fuResourceIds.size();
83 
84  for (UInt_t i = 0; i < fuResourceIds.size(); i++) {
85  msg->allocate[i].fuTransactionId = fuResourceIds[i];
86  msg->allocate[i].fset = 1; // IGNORED!!!
87  }
88 
89  bufRef->setDataSize(msgSize);
90 
91  fuAppContext_->postFrame(bufRef, fuAppDesc_, buAppDesc_);
93  string errmsg = "Failed to allocate buffer reference.";
94  LOG4CPLUS_ERROR(log, errmsg);
95  XCEPT_RETHROW(evf::Exception, errmsg, e);
96  } catch (xdaq::exception::ApplicationDescriptorNotFound& e) {
97  string errmsg = "Failed to get tid.";
98  LOG4CPLUS_ERROR(log, errmsg);
99  XCEPT_RETHROW(evf::Exception, errmsg, e);
100  } catch (xdaq::exception::Exception& e) {
101  string errmsg = "Failed to post 'Allocate' message.";
102  LOG4CPLUS_ERROR(log, errmsg);
103  XCEPT_RETHROW(evf::Exception, errmsg, e);
104  }
105 }
106 
107 //______________________________________________________________________________
108 void BUProxy::sendDiscard(UInt_t buResourceId) throw (evf::Exception) {
109  Logger log = fuAppContext_->getLogger();
110 
111  try {
112  size_t msgSize = sizeof(I2O_BU_DISCARD_MESSAGE_FRAME);
113 
114  toolbox::mem::Reference *bufRef =
115  toolbox::mem::getMemoryPoolFactory()->getFrame(i2oPool_,
116  msgSize);
117 
118  I2O_MESSAGE_FRAME *stdMsg =
119  (I2O_MESSAGE_FRAME*) bufRef->getDataLocation();
120  I2O_PRIVATE_MESSAGE_FRAME *pvtMsg = (I2O_PRIVATE_MESSAGE_FRAME*) stdMsg;
121  I2O_BU_DISCARD_MESSAGE_FRAME *msg =
122  (I2O_BU_DISCARD_MESSAGE_FRAME*) stdMsg;
123 
124  stdMsg->MessageSize = msgSize >> 2;
125  stdMsg->InitiatorAddress = i2o::utils::getAddressMap()->getTid(
126  fuAppDesc_);
127  stdMsg->TargetAddress = i2o::utils::getAddressMap()->getTid(buAppDesc_);
128  stdMsg->Function = I2O_PRIVATE_MESSAGE;
129  stdMsg->VersionOffset = 0;
130  stdMsg->MsgFlags = 0; // Point-to-point
131 
132  pvtMsg->XFunctionCode = I2O_BU_DISCARD;
133  pvtMsg->OrganizationID = XDAQ_ORGANIZATION_ID;
134 
135  msg->n = 1;
136  msg->buResourceId[0] = buResourceId;
137 
138  bufRef->setDataSize(msgSize);
139 
140  fuAppContext_->postFrame(bufRef, fuAppDesc_, buAppDesc_);
142  string errmsg = "Failed to allocate buffer reference.";
143  LOG4CPLUS_ERROR(log, errmsg);
144  XCEPT_RETHROW(evf::Exception, errmsg, e);
145  } catch (xdaq::exception::ApplicationDescriptorNotFound& e) {
146  string errmsg = "Failed to get tid.";
147  LOG4CPLUS_ERROR(log, errmsg);
148  XCEPT_RETHROW(evf::Exception, errmsg, e);
149  } catch (xdaq::exception::Exception &e) {
150  string errmsg = "Failed to post 'Discard' message.";
151  LOG4CPLUS_ERROR(log, errmsg);
152  XCEPT_RETHROW(evf::Exception, errmsg, e);
153  }
154 
155 }
virtual ~BUProxy()
Definition: BUProxy.cc:42
int i
Definition: DBlmapReader.cc:9
void sendDiscard(UInt_t buResourceId)
Definition: BUProxy.cc:108
void sendAllocate(const UIntVec_t &fuResourceIds)
Definition: BUProxy.cc:51
unsigned int UInt_t
Definition: FUTypes.h:12
std::vector< UInt_t > UIntVec_t
Definition: FUTypes.h:15