• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

abbplugin/src/AbbFactory.cxx (r4864/r3116)

Go to the documentation of this file.
00001 #include "roc/AbbFactory.h"
00002 
00003 #include "base/Url.h"
00004 
00005 #include "roc/AbbDevice.h"
00006 #include "roc/ReadoutModule.h"
00007 #include "roc/SplitterModule.h"
00008 #include "roc/AbbBoard.h"
00009 #include "sp605/OpticBoard.h"
00010 
00011 #include "dabc/Command.h"
00012 #include "dabc/logging.h"
00013 #include "dabc/Manager.h"
00014 #include "dabc/MemoryPool.h"
00015 
00016 dabc::FactoryPlugin rocabbfactory(new roc::AbbFactory("abb"));
00017 
00018 roc::AbbFactory::AbbFactory(const char* name) :
00019    dabc::Factory(name),
00020    base::BoardFactory()
00021 {
00022 }
00023 
00024 dabc::Device* roc::AbbFactory::CreateDevice(const char* classname, const char* devname, dabc::Command cmd)
00025 {
00026    if (strcmp(classname, roc::typeAbbDevice)==0) {
00027       DOUT2(("roc::AbbFactory::CreateDevice - Creating Abb UdpDevice %s ...", devname));
00028 
00029       roc::AbbDevice* dev = new roc::AbbDevice(devname, cmd.GetStr("Thread"), cmd);
00030 
00031       if (!dev->IsConnected()) {
00032          dabc::Object::Destroy(dev);
00033          return 0;
00034       }
00035 
00036       return dev;
00037    }
00038 
00039    return 0;
00040 }
00041 
00042 dabc::Module* roc::AbbFactory::CreateModule(const char* classname, const char* modulename, dabc::Command cmd)
00043 {
00044    DOUT2(("roc::AbbFactory::CreateModule called for class:%s, module:%s", classname, modulename));
00045 
00046    if (strcmp(classname, "roc::SplitterModule")==0) {
00047       DOUT2(("roc::AbbFactory::CreateModule - Created roc::SplitterModule %s ", modulename));
00048       return new roc::SplitterModule(modulename, cmd);
00049    }
00050 
00051    return 0;
00052 }
00053 
00054 void roc::AbbFactory::ShowDebug(int lvl, const char* msg)
00055 {
00056    if (lvl<0) EOUT((msg));
00057         else DOUT0((msg));
00058 }
00059 
00060 
00061 bool roc::AbbFactory::IsFactoryFor(const char* name)
00062 {
00063    return roc::Board::IsOpticAddress(name);
00064 }
00065 
00066 
00067 base::Board* roc::AbbFactory::DoConnect(const char* name, base::ClientRole role)
00068 {
00069    // name is always start with prefix abb
00070    // Allowed following names:
00071    //     "abbN"   - N is SFP number on ABB board
00072    //     "abbNY"  - N is SFP number (0,1) on ABB board and Y is SFP number on DCB board (0,1,2,3)
00073    // For boards other than ROC bord type must be specified like:
00074    //     "abb1/sp605" - Means board sp605 is connected to the second SFP of ABB
00075    // Optionally, optic:// protocol can be specified:
00076    //   optic://abb1/syscore2
00077 
00078    if (!roc::Board::IsOpticAddress(name)) return false;
00079 
00080    unsigned path = roc::AbbDevice::GetOpticPath(name);
00081 
00082    if (path == roc::AbbDevice::UndefinedOpticPath) {
00083       EOUT(("Optic path cannot be defined"));
00084       return false;
00085    }
00086 
00087 
00088    DOUT3(("Found optic address"));
00089 
00090 //   dabc::SetDebugLevel(0);
00091 
00092    if (dabc::mgr.null()) {
00093       if (!dabc::Factory::CreateManager("dabc")) return 0;
00094 
00095       dabc::SetDebugLevel(0);
00096       dabc::lgr()->SetLogLimit(1000000);
00097       dabc::lgr()->SetDebugMask(dabc::lgr()->GetDebugMask() & ~dabc::Logger::lTStamp);
00098 
00099       dabc::Manager::SetAutoDestroy(true);
00100    }
00101 
00102 
00103    std::string devname = "/roc/Abb";
00104    
00105    DOUT3(("Creating ABB device"));
00106    if (!dabc::mgr.FindDevice(devname).null()) {
00107       EOUT(("Device with name %s already exists!!!", devname.c_str()));
00108       return 0;
00109    }
00110    
00111    dabc::mgr.CreateDevice(typeAbbDevice, devname.c_str(), "RocAbbThrd");
00112 
00113    AbbDevice* dev = dynamic_cast<roc::AbbDevice*> (dabc::mgr.FindDevice(devname).GetObject());
00114    
00115    if (dev==0) {
00116       EOUT(("Cannot create AbbDevice class !!!"));
00117       return 0;
00118    }
00119    
00120    DOUT3(("Creating ABB board"));
00121 
00122    roc::AbbBoard* brd = 0;
00123    sp605::OpticBoard* brd2 = 0;
00124    base::Board* resbrd = 0;
00125 
00126    base::Url url(name);
00127    if (url.IsValid()) {
00128       if (url.HasOption(roleToString(base::roleDAQ))) role = base::roleDAQ; else
00129       if (url.HasOption(roleToString(base::roleControl))) role = base::roleControl; else
00130       if (url.HasOption(roleToString(base::roleObserver))) role = base::roleObserver;
00131    }
00132 
00133    if (role==base::roleNone) role = base::roleObserver;
00134 
00135    if (url.GetFileName() == "sp605") {
00136 
00137       brd2 = new sp605::OpticBoard(dev, path, role);
00138 
00139       if (!brd2->initAbbBoard()) { delete brd2; return 0; }
00140 
00141       resbrd = brd2;
00142 
00143    } else {
00144 
00145       brd = new roc::AbbBoard(dev, path, role);
00146 
00147       if (!brd->initAbbBoard()) { delete brd; return 0; }
00148 
00149       resbrd = brd;
00150    }
00151 
00152    if (role == base::roleDAQ) {
00153 
00154       DOUT3(("Creating readout module"));
00155 
00156       std::string modname = "/roc/AbbReadout";
00157       std::string poolname = "/roc/AbbPool";
00158 
00159       bool res = dabc::mgr.CreateMemoryPool(poolname.c_str(), 16384, 100);
00160 
00161       dabc::CmdCreateModule cmd("roc::ReadoutModule", modname.c_str(), "RocAbbThrd");
00162       cmd.SetStr("PoolName", poolname);
00163       if (!dabc::mgr.Execute(cmd)) res = false;
00164 
00165       dabc::CmdCreateTransport cmd2(FORMAT(("%s/Input",modname.c_str())), devname);
00166       cmd2.SetStr(roc::xmlBoardAddr, name);
00167 
00168       if (res && !dabc::mgr.Execute(cmd2)) res = false;
00169 
00170       ReadoutModule* rm = dynamic_cast<roc::ReadoutModule*>(dabc::mgr.FindModule(modname.c_str()).GetObject());
00171 
00172       if (!res || (rm==0)) { DoClose(resbrd); return 0; }
00173 
00174       if (brd)
00175          brd->setReadout(rm);
00176       else
00177          brd2->setReadout(rm);
00178    }
00179 
00180    DOUT3(("Did connect %p", resbrd));
00181 
00182    return resbrd;
00183 }
00184 
00185 bool roc::AbbFactory::DoClose(base::Board* brd)
00186 {
00187    if (brd==0) return true;
00188    
00189    roc::AbbBoard* abbbrd = dynamic_cast<roc::AbbBoard*> (brd);
00190    sp605::OpticBoard* sp605brd = dynamic_cast<sp605::OpticBoard*> (brd);
00191    
00192    if (abbbrd!=0) { delete abbbrd; } else
00193    if (sp605brd!=0) { delete sp605brd; } else {
00194       EOUT(("Wrong board class"));
00195       return false;
00196    }
00197 
00198 
00199 //   DOUT0(("Manager = %s", DBOOL(dabc::mgr.null())));
00200    
00201    // delete device when no more board classes
00202 
00203    if (dabc::mgr.null()) return true;
00204 
00205 //   dabc::mgr.StopModule("/roc/AbbReadout");
00206    dabc::mgr.DeleteModule("/roc/AbbReadout");
00207    dabc::mgr.FindDevice("/roc/Abb").Destroy();
00208    dabc::mgr.FindItem("/roc/AbbPool").Destroy();
00209 
00210    dabc::mgr.SyncWorker();
00211    
00212    return true;
00213 }

Generated on Tue Dec 10 2013 04:52:16 for ROCsoft by  doxygen 1.7.1