00001 #ifdef linux
00002 #undef linux
00003 #endif
00004
00005 #include "SctApiCall.h"
00006 #include "RunController.h"
00007 #include "SctApiAccessException.h"
00008 #include "CalibrationControllerImpl.h"
00009 #include "ipc/CalibrationController.h"
00010 #include "Sct/SctNames.h"
00011 #include "Sct/Exception.h"
00012 #include "Sct/LogicErrors.h"
00013 #include <rc/RunParamsInfo.h>
00014 #include <ipc/partition.h>
00015 #include <is/isinfo.h>
00016 #include <iostream>
00017 #include <fstream>
00018 #include <ilu/iluxport.h>
00019
00020 using namespace std;
00021 using namespace Sct;
00022
00023 int main(int argc, char** argv) {
00024 using namespace SctCalibrationController;
00025
00026 cout << "Starting Calibration controller" << endl;
00027 setExceptionHandlers(argv[0]);
00028
00029 IPCCore::init(true);
00030
00031
00032 RunControl& rc = RunControl::instance();
00033 cout << "Instance created" << endl;
00034
00035 rc.rc_start("CalibrationController", "SCT");
00036 cout << "All over" << endl;
00037
00038 return 0;
00039 }
00040
00041 namespace SctCalibrationController {
00042
00043 RunControl::RunControl() : cc (CalibrationControllerImpl::initialize(*this)) {
00044 }
00045
00046 RunControl& RunControl::instance() {
00047 static RunControl rc;
00048 return rc;
00049 }
00050
00051
00052 int RunControl::loadaction () {
00053 cout << "Loadaction" << endl;
00054 api = (Sct_SctApi_T_SctApi*)ipcPartition().lookup(Sct_SctApi_C_SctApi_serverName, Sct_SctApi_C_SctApi_instanceName, Sct_SctApi_T_SctApi::ILUClassRecord);
00055 if (!api) {
00056 SctNames::Mrs() << "RC_INIT" << MRS_TEXT("RunController failed to find SctApi") << MRS_ERROR << ENDM;
00057 return 1;
00058 }
00059 cc.setApi(*api);
00060 try {
00061 APICALL(api, initialiseAll(&st, 0), "SctApi failed to initialiseAll")
00062 } catch(SctApiAccessException& e) {
00063 e.sendToMrs(MRS_ERROR);
00064 return 1;
00065 }
00066
00067 return 0;
00068 }
00069
00070 int RunControl::configaction() {
00071 try {
00072 APICALL(api, configureAllModules(&st), "SctApi failed to configureAllModules")
00073 } catch(SctApiAccessException& e) {
00074 e.sendToMrs(MRS_ERROR);
00075 return 1;
00076 }
00077
00078 return 0;
00079 }
00080
00081 int RunControl::startaction() {
00082 if (!api) {
00083 cout << "Can't enter running as we don't have the api" << endl;
00084 return 2;
00085 }
00086 cout << "enter Running" << endl;
00087
00089 RunParamsInfo runParams;
00090 ISInfoDictionary& is = SctNames::getISDictionary();
00091 ISInfo::Status isStatus;
00092
00093 isStatus = is.findValue("RunParams.RunParams", runParams);
00094
00095 try {
00096 APICALL(api, setRunNumber(&st, runParams.run_number), "Failed to set run number")
00097 APICALL(api, setScanNumber(&st, 0), "Failed to set scan number")
00098 cout << "New Run, setting run number and scan number: " << runParams.run_number << " " << 0 << endl;
00099 cc.takeControl(runParams.run_number);
00100 } catch (SctApiAccessException& e) {
00101 e.sendToMrs(MRS_ERROR);
00102 return 1;
00103 }
00104
00105 return 0;
00106 }
00107
00108 void RunControl::exitRunning() {
00109 cout << "exit Running" << endl;
00110 cc.giveupControl();
00111 }
00112
00113 int RunControl::unloadaction () {
00114 cout << "unloadaction" << endl;
00115
00116 try {
00117 APICALL(api, shutdownAll(&st), "Could not shutdown all")
00118 } catch (SctApiAccessException& e) {
00119 e.sendToMrs(MRS_ERROR);
00120 return 1;
00121 }
00122 cc.reset();
00123
00124 return 0;
00125 }
00126
00127 int RunControl::resetaction () {
00128 cc.reset();
00129 return 0;
00130 }
00131
00132 void RunControl::sctApiError(ErrorState state, const string& reason) {
00133 this->setError(state, reason);
00134 cc.giveupControl();
00135 }
00136
00137 }