// // AutoPilot.cpp // #include "DaqSetup.h" #include "AutoPilot.h" #include "ParseOption.h" #include "LogFile.h" extern "C" { #include #include #include } // ============================================== // constructor / destructor // ============================================== AutoPilot::AutoPilot (DetPlane *detPlane) : _runHandler (detPlane) { _detPlane = detPlane; } // ============================================== // // ============================================== void AutoPilot::execute (char* fileName) { // ------------------------------------------ // open autopilot file // ------------------------------------------ DaqSetup* daq = daq->Instance (); DaqEnv* daqEnv = daq->daqEnv (); ifstream inFile; if ( daqEnv->openFileDirIn (AutoPilotDir, fileName, inFile) == 0 ) return; ofstream calibLog; if ( daqEnv->openFileDir (DataDir, "calibLog.txt", calibLog) == 0 ) return; calibLog << "channels: " << _detPlane->nChan () << endl; logFile << " AutoPilot " << fileName << " Calib log file: calibLog " << endl; // -------------------------------------------------------- // read auto pilot file and interpret/execute commands // -------------------------------------------------------- int status; int intVal; double dValue; char key[50], arg[100]; ParseOption opt (inFile); while ( opt.nextKey (key, arg) ) { // -------- events ------------------------- if ( strcmp (key, "events:") == 0 ) { intVal = atoi (arg); _runHandler.setEvents (intVal); logFile << " Events : " << intVal << endl; } // -------- qinjScan -------------------- else if ( strcmp (key, "qinj:") == 0 ) { status = auto_Scan (arg, qinj); logFile << " QinjScan: " << arg << " status: " << status << endl; } // -------- calibScan -------------------- else if ( strcmp (key, "calib:") == 0 ) { status = auto_Scan (arg, calib); logFile << " CalibScan: " << arg << " status: " << status << endl; calibLog << arg << endl; } // -------- noiseScan -------------------- else if ( strcmp (key, "noise:") == 0 ) { status = auto_Scan (arg, noise); logFile << " NoiseScan: " << arg << " status: " << status << endl; calibLog << arg << endl; } // -------- qinjScan -------------------- else if ( strcmp (key, "thres:") == 0 ) { status = auto_Scan (arg, thres); logFile << " ThresScan: " << arg << " status: " << status << endl; } // -------- thres dac -------------------- else if ( strcmp (key, "thres_dac:") == 0 ) { dValue = atof (arg); _detPlane->setV_thres (dValue); logFile << " thresDac: (try/set) " << dValue << " " << _detPlane->getV_thres () << endl; } // -------- vref dac -------------------- else if ( strcmp (key, "vref_dac:") == 0 ) { dValue = atof (arg); _detPlane->setV_ref (dValue); logFile << " VrefDac: (try/set) " << dValue << " " << _detPlane->getV_ref () << endl; } // -------- vatt dac -------------------- else if ( strcmp (key, "vatt_dac:") == 0 ) { dValue = atof (arg); _detPlane->setV_att (dValue); logFile << " VattDac: (try/set) " << dValue << " " << _detPlane->getV_att () << endl; } // -------- cal dac -------------------- else if ( strcmp (key, "vcal_dac:") == 0 ) { dValue = atof (arg); _detPlane->setV_cal (dValue); logFile << " VcalDac: (try/set) " << dValue << " " << _detPlane->getV_cal () << endl; } } calibLog.close (); return; } // ======================================================================= // autopilot file // ======================================================================= int AutoPilot::auto_Scan (char *arg, RunModes mode) { int stat; double start, stop, stepSize, setValue; char fname[100]; stat = sscanf (arg, "%lf %lf %lf %lf %s", &start, &stop, &stepSize, &setValue, fname); if ( stat != 5 ) return 0; _runHandler.setFileName (fname); switch ( mode ) { case qinj : _runHandler.setMode (qinj); _runHandler.do_a_Run (start, stop, stepSize, setValue); break; case calib : _runHandler.setMode (calib); _runHandler.do_a_Run (start, stop, stepSize, setValue); break; case noise : _runHandler.setMode (noise); _runHandler.do_a_Run (start, stop, stepSize, setValue); break; case thres : _runHandler.setMode (thres); _runHandler.do_a_Run (start, stop, stepSize, setValue); break; } return 1; }