CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/EventFilter/Utilities/src/BUFUInterface.cc

Go to the documentation of this file.
00001 /*
00002  * BUFUInterface.cc
00003  *
00004  *  Created on: Aug 16, 2011
00005  *      Author: aspataru
00006  */
00007 
00008 #include "EventFilter/Utilities/interface/BUFUInterface.h"
00009 
00010 #define BUFU_VERBOSE
00011 //#define BUFU_DEBUG
00012 
00013 using namespace evf;
00014 
00015 // initialize instance_ to 0
00016 BUFUInterface* evf::BUFUInterface::instance_ = 0;
00017 
00018 //______________________________________________________________________________
00019 BUFUInterface::~BUFUInterface() {
00020         // delete instance_;
00021         instance_ = 0;
00022 }
00023 
00024 //______________________________________________________________________________
00025 BUFUInterface* BUFUInterface::instance() {
00026         if (instance_ == 0) {
00027                 instance_ = new BUFUInterface();
00028         }
00029         return instance_;
00030 
00031 }
00032 
00033 //______________________________________________________________________________
00034 BUFUInterface* BUFUInterface::forceNewInstance() {
00035         return new BUFUInterface();
00036 }
00037 
00038 //______________________________________________________________________________
00039 bool BUFUInterface::registerBU(BaseBU* bu, Logger log) {
00040         bool succeeded = false;
00041         if (bu != 0) {
00042                 bu_ = bu;
00043                 buLogger_ = log;
00044                 buConn_ = true;
00045                 succeeded = true;
00046 
00047 #ifdef BUFU_VERBOSE
00048                 LOG4CPLUS_INFO(buLogger_, "BU registered to BUFU interface!");
00049                 if (directConnection()) {
00050                         LOG4CPLUS_INFO(buLogger_, "BU and FU : DIRECTLY CONNECTED!");
00051                 }
00052 #endif
00053 
00054         }
00055         return succeeded;
00056 }
00057 
00058 //______________________________________________________________________________
00059 bool BUFUInterface::registerFU(BaseFU* fu, Logger log) {
00060         bool succeeded = false;
00061         if (fu != 0) {
00062                 fu_ = fu;
00063                 fuLogger_ = log;
00064                 fuConn_ = true;
00065                 succeeded = true;
00066 
00067 #ifdef BUFU_VERBOSE
00068                 LOG4CPLUS_INFO(fuLogger_, "FU registered to BUFU interface!");
00069                 if (directConnection()) {
00070                         LOG4CPLUS_INFO(buLogger_, "BU and FU : DIRECTLY CONNECTED!");
00071                 }
00072 #endif
00073 
00074         }
00075         return succeeded;
00076 }
00077 
00078 //______________________________________________________________________________
00079 void BUFUInterface::allocate(const UIntVec_t& fuResourceIds,
00080                 xdaq::ApplicationDescriptor* fuAppDesc) {
00081 
00082         // direct connection -> method call
00083         if (directConnection()) {
00084 
00085                 bu_->DIRECT_BU_ALLOCATE(fuResourceIds, fuAppDesc);
00086 
00087 #ifdef BUFU_DEBUG
00088                 std::cout << "ALLOCATE FU->BU message sent directly!" << std::endl;
00089 #endif
00090         }
00091 
00092         // no connection -> line protocol
00093         else {
00094                 // call FU to build I2O allocate message and send it
00095                 fu_->buildAndSendAllocate(fuResourceIds);
00096 
00097 #ifdef BUFU_DEBUG
00098                 std::cout << "ALLOCATE FU->BU message sent through I2O!" << std::endl;
00099 #endif
00100         }
00101 
00102 }
00103 
00104 //______________________________________________________________________________
00105 void BUFUInterface::discard(UInt_t buResourceId) {
00106 
00107         // direct connection -> method call
00108         if (directConnection()) {
00109 
00110                 bu_->DIRECT_BU_DISCARD(buResourceId);
00111 
00112 #ifdef BUFU_DEBUG
00113                 std::cout << "DISCARD FU->BU message sent directly!" << std::endl;
00114 #endif
00115         }
00116 
00117         // no connection -> line protocol
00118         else {
00119                 // call FU to build I2O discard and send it
00120                 fu_->buildAndSendDiscard(buResourceId);
00121 
00122 #ifdef BUFU_DEBUG
00123                 std::cout << "DISCARD FU->BU message sent through I2O!" << std::endl;
00124 #endif
00125         }
00126 
00127 }
00128 
00129 //______________________________________________________________________________
00130 void BUFUInterface::take(xdaq::ApplicationDescriptor* fuAppDesc,
00131                 toolbox::mem::Reference* bufRef) {
00132 
00133         // direct connection -> method call
00134         if (directConnection()) {
00135 
00136                 fu_->I2O_FU_TAKE_Callback(bufRef);
00137 
00138 #ifdef BUFU_DEBUG
00139                 std::cout << "TAKE BU->FU message sent directly!" << std::endl;
00140 #endif
00141         }
00142 
00143         // no connection -> line protocol
00144         else {
00145                 bu_->postI2OFrame(fuAppDesc, bufRef);
00146 
00147 #ifdef BUFU_DEBUG
00148                 std::cout << "TAKE BU->FU message sent through I2O!" << std::endl;
00149 #endif
00150         }
00151 
00152 }
00153 
00154 //______________________________________________________________________________
00155 BUFUInterface::BUFUInterface() :
00156         bu_(0), fu_(0), /*buLogger_(0), fuLogger_(0),*/ buConn_(false), fuConn_(false) {
00157 
00158 }