/* * BaseIURecordMaker.cpp * * Created on: February 18, 2014 * Author: Hovanes Egiyan */ #include "BaseIURecordMaker.hh" string BaseIURecordMaker::brmCfgFileNameDB = "readConfigBaseIU.db"; string BaseIURecordMaker::brmBaseFileNameDB = "pmtBaseIU.db"; string BaseIURecordMaker::brmChassisFileNameDB = "powerChassisIU.db"; string BaseIURecordMaker::brmDirDB = "db/"; // Load records for all buses based on the specified crate name and bus name. void BaseIURecordMaker::LoadRecords( const string prefix, const string crateName, const string busNameReq ) { string fullFileName; cout << "BaseIURecordMaker::LoadRecords: Will load records with prefix " << prefix << " for portName " << crateName << " and bus name " << busNameReq << endl; map > busMap = BaseIUMgr::GetBusMap(); // Loop over all CAN bus object registered with the bus manager then loop over all bases. // Note that crateName is not the same as the portName. for (map >::iterator itBus = busMap.begin(); itBus != busMap.end(); itBus++) { string portName = itBus->first; // port name BaseIUVirtBus* bus = itBus->second.second; // pointer to the bus object // string busType = bus->GetBusID().GetType(); string busName = bus->GetDevice()->GetBusStr(); BaseIUVirtBusID reqBusID( "", "E", crateName, "base"); reqBusID = reqBusID + busNameReq; string portNameReq = reqBusID.GetPort(); cout << "Comparing bus " << busName << " with port name " << portName << " with requested " << " port name " << portNameReq << " for bus " << busNameReq << endl; if ( ( crateName == "" && (busNameReq == "E" || busNameReq == busName) ) || ( portNameReq == portName && (busNameReq == "E" || busNameReq == busName) ) ) { // If the cratename and busname match, load records for this asyn port LoadRecords( prefix, portName ); } } return; } // Method to load records for a particular bus void BaseIURecordMaker::LoadRecords( const string prefix, const string portName ) { map > busMap = BaseIUMgr::GetBusMap(); if( busMap.count( portName ) > 0 ) { BaseIUVirtBus* bus = busMap[portName].second; LoadBusRecords(prefix, bus); LoadBaseRecords(prefix, bus); } } // Load DB files pertaining to a bus void BaseIURecordMaker::LoadBusRecords(const string prefix, BaseIUVirtBus* bus) { string busType = bus->GetBusID().GetType(); if (busType == "base") { string fullFileName = brmDirDB + brmCfgFileNameDB; string substitString = "PREFIX=" + prefix +",PORT=" + bus->GetDevice()->GetPortName() + ",SCAN=5 second"; cout << "Will load from " << fullFileName << " with arguments <" << substitString << ">" << endl; dbLoadRecords(fullFileName.c_str(), substitString.c_str()); cout << "Base Bus database loaded for bus on port " << bus->GetDevice()->GetPortName() << endl; } else if (busType == "chassis") { ; } else { cerr << "Bad bus type " << busType << endl; throw "Bad bus type !!! The valid bus types are 'base' and 'power'"; } return; } // Load DB files pertaining to a base void BaseIURecordMaker::LoadBaseRecords(const string prefix, BaseIUVirtBus* bus) { string fullFileName; string busType = bus->GetBusID().GetType(); if (busType == "base") fullFileName = brmDirDB + brmBaseFileNameDB; else if (busType == "chassis") fullFileName = brmDirDB + brmChassisFileNameDB; else { cerr << "Bad bus type " << busType << endl; throw "Bad bus type !!! The valid bus types are 'base' and 'power'"; } map addrMap = bus->GetBoardMap(); // Loop over all IU bases on this bus and add load EPICS records for them for (map::iterator itBoard = addrMap.begin(); itBoard != addrMap.end(); itBoard++) { int boardAddr = itBoard->first; if (boardAddr != 0) { stringstream ssAddr; ssAddr << hex << showbase << boardAddr; string substitString = "PREFIX=" + prefix + ",PORT=" + bus->GetDevice()->GetPortName() + ",SCAN=5 second,ADDR=" + ssAddr.str(); cout << "Will load from " << fullFileName << " with arguments <" << substitString << ">" << endl; dbLoadRecords(fullFileName.c_str(), substitString.c_str()); cout << "Channel Database loaded for board " << ssAddr.str() << " on connection" << bus->GetDevice()->GetPortName() << endl; } } return; }