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 
26 using namespace std;
27 using namespace evf;
28 
29 
31 // construction/destruction
33 
34 //______________________________________________________________________________
35 BUProxy::BUProxy(xdaq::ApplicationDescriptor *fuAppDesc,
36  xdaq::ApplicationDescriptor *buAppDesc,
37  xdaq::ApplicationContext *fuAppContext,
38  toolbox::mem::Pool *i2oPool)
39  : fuAppDesc_(fuAppDesc)
40  , buAppDesc_(buAppDesc)
41  , fuAppContext_(fuAppContext)
42  , i2oPool_(i2oPool)
43 {
44 
45 }
46 
47 
48 //______________________________________________________________________________
50 {
51 
52 }
53 
54 
56 // implementation of member functions
58 
59 //______________________________________________________________________________
60 void BUProxy::sendAllocate(const UIntVec_t& fuResourceIds)
61  throw (evf::Exception)
62 {
63  Logger log=fuAppContext_->getLogger();
64 
65  try {
66  size_t msgSize=
67  sizeof(I2O_BU_ALLOCATE_MESSAGE_FRAME)+
68  sizeof(BU_ALLOCATE)*(fuResourceIds.size()-1);
69 
70  toolbox::mem::Reference *bufRef=
71  toolbox::mem::getMemoryPoolFactory()->getFrame(i2oPool_,msgSize);
72 
73  I2O_MESSAGE_FRAME *stdMsg;
74  I2O_PRIVATE_MESSAGE_FRAME *pvtMsg;
75  I2O_BU_ALLOCATE_MESSAGE_FRAME *msg;
76 
77  stdMsg=(I2O_MESSAGE_FRAME*)bufRef->getDataLocation();
78  pvtMsg=(I2O_PRIVATE_MESSAGE_FRAME*)stdMsg;
79  msg =(I2O_BU_ALLOCATE_MESSAGE_FRAME*)stdMsg;
80 
81  stdMsg->MessageSize =msgSize >> 2;
82  stdMsg->InitiatorAddress=i2o::utils::getAddressMap()->getTid(fuAppDesc_);
83  stdMsg->TargetAddress =i2o::utils::getAddressMap()->getTid(buAppDesc_);
84  stdMsg->Function =I2O_PRIVATE_MESSAGE;
85  stdMsg->VersionOffset =0;
86  stdMsg->MsgFlags =0; // Point-to-point
87 
88  pvtMsg->XFunctionCode =I2O_BU_ALLOCATE;
89  pvtMsg->OrganizationID =XDAQ_ORGANIZATION_ID;
90 
91  msg->n =fuResourceIds.size();
92 
93  for(UInt_t i=0;i<fuResourceIds.size();i++) {
94  msg->allocate[i].fuTransactionId=fuResourceIds[i];
95  msg->allocate[i].fset =1; // IGNORED!!!
96  }
97 
98  bufRef->setDataSize(msgSize);
99 
100  fuAppContext_->postFrame(bufRef,fuAppDesc_,buAppDesc_);
101  }
103  string errmsg="Failed to allocate buffer reference.";
104  LOG4CPLUS_ERROR(log,errmsg);
105  XCEPT_RETHROW(evf::Exception,errmsg,e);
106  }
107  catch(xdaq::exception::ApplicationDescriptorNotFound& e) {
108  string errmsg="Failed to get tid.";
109  LOG4CPLUS_ERROR(log,errmsg);
110  XCEPT_RETHROW(evf::Exception,errmsg,e);
111  }
112  catch(xdaq::exception::Exception& e) {
113  string errmsg="Failed to post 'Allocate' message.";
114  LOG4CPLUS_ERROR(log,errmsg);
115  XCEPT_RETHROW(evf::Exception,errmsg,e);
116  }
117 }
118 
119 
120 //______________________________________________________________________________
121 void BUProxy::sendDiscard(UInt_t buResourceId)
122  throw (evf::Exception)
123 {
124  Logger log=fuAppContext_->getLogger();
125 
126  try {
127  size_t msgSize=sizeof(I2O_BU_DISCARD_MESSAGE_FRAME);
128 
129  toolbox::mem::Reference *bufRef=
130  toolbox::mem::getMemoryPoolFactory()->getFrame(i2oPool_,msgSize);
131 
132  I2O_MESSAGE_FRAME *stdMsg=(I2O_MESSAGE_FRAME*)bufRef->getDataLocation();
133  I2O_PRIVATE_MESSAGE_FRAME *pvtMsg=(I2O_PRIVATE_MESSAGE_FRAME*)stdMsg;
134  I2O_BU_DISCARD_MESSAGE_FRAME *msg=(I2O_BU_DISCARD_MESSAGE_FRAME*)stdMsg;
135 
136  stdMsg->MessageSize =msgSize >> 2;
137  stdMsg->InitiatorAddress=i2o::utils::getAddressMap()->getTid(fuAppDesc_);
138  stdMsg->TargetAddress =i2o::utils::getAddressMap()->getTid(buAppDesc_);
139  stdMsg->Function =I2O_PRIVATE_MESSAGE;
140  stdMsg->VersionOffset =0;
141  stdMsg->MsgFlags =0; // Point-to-point
142 
143  pvtMsg->XFunctionCode =I2O_BU_DISCARD;
144  pvtMsg->OrganizationID =XDAQ_ORGANIZATION_ID;
145 
146  msg->n =1;
147  msg->buResourceId[0] =buResourceId;
148 
149  bufRef->setDataSize(msgSize);
150 
151  fuAppContext_->postFrame(bufRef,fuAppDesc_,buAppDesc_);
152  }
154  string errmsg="Failed to allocate buffer reference.";
155  LOG4CPLUS_ERROR(log,errmsg);
156  XCEPT_RETHROW(evf::Exception,errmsg,e);
157  }
158  catch (xdaq::exception::ApplicationDescriptorNotFound& e) {
159  string errmsg="Failed to get tid.";
160  LOG4CPLUS_ERROR(log,errmsg);
161  XCEPT_RETHROW(evf::Exception,errmsg,e);
162  }
163  catch (xdaq::exception::Exception &e) {
164  string errmsg="Failed to post 'Discard' message.";
165  LOG4CPLUS_ERROR(log,errmsg);
166  XCEPT_RETHROW(evf::Exception,errmsg,e);
167  }
168 
169 }
170 
virtual ~BUProxy()
Definition: BUProxy.cc:49
int i
Definition: DBlmapReader.cc:9
std::vector< UInt_t > UIntVec_t
Definition: FUTypes.h:15
void sendDiscard(UInt_t buResourceId)
Definition: BUProxy.cc:121
void sendAllocate(const UIntVec_t &fuResourceIds)
Definition: BUProxy.cc:60
unsigned int UInt_t
Definition: FUTypes.h:12
Log< T >::type log(const T &t)
Definition: Log.h:22