CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BUFUInterface.cc
Go to the documentation of this file.
1 /*
2  * BUFUInterface.cc
3  *
4  * Created on: Aug 16, 2011
5  * Author: aspataru
6  */
7 
9 
10 #define BUFU_VERBOSE
11 //#define BUFU_DEBUG
12 
13 using namespace evf;
14 
15 // initialize instance_ to 0
17 
18 //______________________________________________________________________________
20  // delete instance_;
21  instance_ = 0;
22 }
23 
24 //______________________________________________________________________________
26  if (instance_ == 0) {
27  instance_ = new BUFUInterface();
28  }
29  return instance_;
30 
31 }
32 
33 //______________________________________________________________________________
35  return new BUFUInterface();
36 }
37 
38 //______________________________________________________________________________
40  bool succeeded = false;
41  if (bu != 0) {
42  bu_ = bu;
43  buLogger_ = log;
44  buConn_ = true;
45  succeeded = true;
46 
47 #ifdef BUFU_VERBOSE
48  LOG4CPLUS_INFO(buLogger_, "BU registered to BUFU interface!");
49  if (directConnection()) {
50  LOG4CPLUS_INFO(buLogger_, "BU and FU : DIRECTLY CONNECTED!");
51  }
52 #endif
53 
54  }
55  return succeeded;
56 }
57 
58 //______________________________________________________________________________
60  bool succeeded = false;
61  if (fu != 0) {
62  fu_ = fu;
63  fuLogger_ = log;
64  fuConn_ = true;
65  succeeded = true;
66 
67 #ifdef BUFU_VERBOSE
68  LOG4CPLUS_INFO(fuLogger_, "FU registered to BUFU interface!");
69  if (directConnection()) {
70  LOG4CPLUS_INFO(buLogger_, "BU and FU : DIRECTLY CONNECTED!");
71  }
72 #endif
73 
74  }
75  return succeeded;
76 }
77 
78 //______________________________________________________________________________
79 void BUFUInterface::allocate(const UIntVec_t& fuResourceIds,
80  xdaq::ApplicationDescriptor* fuAppDesc) {
81 
82  // direct connection -> method call
83  if (directConnection()) {
84 
85  bu_->DIRECT_BU_ALLOCATE(fuResourceIds, fuAppDesc);
86 
87 #ifdef BUFU_DEBUG
88  std::cout << "ALLOCATE FU->BU message sent directly!" << std::endl;
89 #endif
90  }
91 
92  // no connection -> line protocol
93  else {
94  // call FU to build I2O allocate message and send it
95  fu_->buildAndSendAllocate(fuResourceIds);
96 
97 #ifdef BUFU_DEBUG
98  std::cout << "ALLOCATE FU->BU message sent through I2O!" << std::endl;
99 #endif
100  }
101 
102 }
103 
104 //______________________________________________________________________________
105 void BUFUInterface::discard(UInt_t buResourceId) {
106 
107  // direct connection -> method call
108  if (directConnection()) {
109 
110  bu_->DIRECT_BU_DISCARD(buResourceId);
111 
112 #ifdef BUFU_DEBUG
113  std::cout << "DISCARD FU->BU message sent directly!" << std::endl;
114 #endif
115  }
116 
117  // no connection -> line protocol
118  else {
119  // call FU to build I2O discard and send it
120  fu_->buildAndSendDiscard(buResourceId);
121 
122 #ifdef BUFU_DEBUG
123  std::cout << "DISCARD FU->BU message sent through I2O!" << std::endl;
124 #endif
125  }
126 
127 }
128 
129 //______________________________________________________________________________
130 void BUFUInterface::take(xdaq::ApplicationDescriptor* fuAppDesc,
131  toolbox::mem::Reference* bufRef) {
132 
133  // direct connection -> method call
134  if (directConnection()) {
135 
136  fu_->I2O_FU_TAKE_Callback(bufRef);
137 
138 #ifdef BUFU_DEBUG
139  std::cout << "TAKE BU->FU message sent directly!" << std::endl;
140 #endif
141  }
142 
143  // no connection -> line protocol
144  else {
145  bu_->postI2OFrame(fuAppDesc, bufRef);
146 
147 #ifdef BUFU_DEBUG
148  std::cout << "TAKE BU->FU message sent through I2O!" << std::endl;
149 #endif
150  }
151 
152 }
153 
154 //______________________________________________________________________________
156  bu_(0), fu_(0), /*buLogger_(0), fuLogger_(0),*/ buConn_(false), fuConn_(false) {
157 
158 }
virtual void postI2OFrame(xdaq::ApplicationDescriptor *fuAppDesc, toolbox::mem::Reference *bufRef)=0
bool registerFU(BaseFU *fu, Logger log)
register the FU to the interface
BUFUInterface()
private constructor
virtual void DIRECT_BU_DISCARD(UInt_t buResourceId)=0
DISCARD called by the BUFU Interface when BU and FU are in the same process.
bool buConn_
flags for BU, FU connection
Definition: BUFUInterface.h:72
virtual void I2O_FU_TAKE_Callback(toolbox::mem::Reference *bufRef)=0
function to be performed upon receiving a TAKE from the BU
virtual void buildAndSendAllocate(const UIntVec_t &fuResourceIds)=0
called by the BUFU Interface to trigger an I2O ALLOCATE message being built and sent ...
BaseFU * fu_
pointer to connected ResourceBroker(FU), using BaseFU interface
Definition: BUFUInterface.h:68
bool registerBU(BaseBU *bu, Logger log)
register the BU to the interface
virtual void buildAndSendDiscard(UInt_t buResourceId)=0
called by the BUFU Interface to trigger an I2O DISCARD message being built and sent ...
void allocate(const UIntVec_t &fuResourceIds, xdaq::ApplicationDescriptor *fuAppDesc)
Logger buLogger_
loggers
Definition: BUFUInterface.h:70
unsigned int UInt_t
Definition: FUTypes.h:12
BaseBU * bu_
pointer to connected BU, using BaseBU interface
Definition: BUFUInterface.h:66
static BUFUInterface * instance_
pointer to unique instance
Definition: BUFUInterface.h:49
bool directConnection() const
checks if both BU and FU are connected to the interface
Definition: BUFUInterface.h:58
void take(xdaq::ApplicationDescriptor *fuAppDesc, toolbox::mem::Reference *bufRef)
BU-&gt;FU TAKE.
tuple cout
Definition: gather_cfg.py:121
static BUFUInterface * forceNewInstance()
virtual void DIRECT_BU_ALLOCATE(const UIntVec_t &fuResourceIds, xdaq::ApplicationDescriptor *fuAppDesc)=0
ALLOCATE called by the BUFU Interface when BU and FU are in the same process.
void discard(UInt_t buResourceId)
FU-&gt;BU DISCARD.
static BUFUInterface * instance()
returns a pointer to a singleton instance of the interface
std::vector< UInt_t > UIntVec_t
Definition: FUTypes.h:15