// // RunHandler.cpp // #include "RunHandler.h" #include "LogFile.h" extern "C" { #include } #include "ThreshScan.h" #include "QinjScan.h" #include "StrobeScan.h" #include "VrefScan.h" #include "NoiseScan.h" #include "ReadoutScan.h" // #include "FitErrf.h" #include "DaqSetup.h" #include "fstream.h" #include "LogFile.h" // ================================================================= // constructor destructor // ================================================================= RunHandler::RunHandler (DetPlane *plane) { _detPlane = plane; if ( _detPlane == 0 ) _mode = none; else _mode = qinj; _nEvents = 0; _fileName = 0; } RunHandler::~RunHandler () { if ( _fileName != 0 ) delete []_fileName; } // ================================================================= // setMode // ================================================================= void RunHandler::setMode (RunModes mode) { if ( _detPlane == 0 ) _mode = none; else _mode = mode; } // ================================================================= // set events // ================================================================= void RunHandler::setEvents (int evts) { _nEvents = evts; } // ================================================================= // set events and file name // ================================================================= void RunHandler::setEvents_fName (int evts, char* fname) { _nEvents = evts; // file name if ( _fileName != 0 ) delete []_fileName; int length; length = strlen (fname) + 1; _fileName = new char[length]; strcpy (_fileName, fname); } // ================================================================= // set file name // ================================================================= void RunHandler::setFileName (char* fname) { if ( _fileName != 0 ) delete []_fileName; int length; length = strlen (fname) + 1; _fileName = new char[length]; strcpy (_fileName, fname); } // ================================================================= // do_a_Run // ================================================================= void RunHandler::do_a_Run (double start, double stop, double stepSize, double constVal) { switch ( _mode ) { case thres : { ThreshScan *scan; scan = new ThreshScan (start, stop, stepSize, _detPlane); scan->init ( constVal ); scan->run ( _nEvents, 1 ); scan->dataToFile ( _fileName ); delete scan; fileName_to_logFile ( _fileName ); break; } case qinj : { logFile << " charge injection scan " << endl; QinjScan *scan; scan = new QinjScan (start, stop, stepSize, _detPlane); scan->init ( constVal ); scan->run ( _nEvents, 1 ); scan->dataToFile ( _fileName ); delete scan; fileName_to_logFile ( _fileName ); break; } case noise : { NoiseScan *scan; scan = new NoiseScan (start, stop, stepSize, _detPlane); scan->init ( constVal ); scan->run ( _nEvents, 0); scan->dataToFile ( _fileName ); delete scan; fileName_to_logFile ( _fileName ); break; } case strobe : { StrobeScan *scan; scan = new StrobeScan (start, stop, stepSize, _detPlane); scan->init ( constVal ); scan->run ( _nEvents, 1 ); scan->dataToFile ( _fileName ); delete scan; fileName_to_logFile ( _fileName ); break; } case vref : { VrefScan *scan; scan = new VrefScan (start, stop, stepSize, _detPlane); scan->init ( constVal ); scan->run ( _nEvents, 1 ); scan->dataToFile ( _fileName ); delete scan; fileName_to_logFile ( _fileName ); break; } case readout : { ReadoutScan *scan; scan = new ReadoutScan (start, stop, stepSize, _detPlane); scan->run ( _nEvents, 1 ); scan->dataToFile ( _fileName ); delete scan; fileName_to_logFile ( _fileName ); break; } case calib : { logFile << " charge injection (calib) scan " << endl; QinjScan *scan; scan = new QinjScan (start, stop, stepSize, _detPlane); scan->init ( constVal ); CString ctrlName; int lines[4], nLines, linesUsed [4]; int i, j; int chanMax = _detPlane->nChan () - 1; for ( i = 0; i < 4; i++ ) linesUsed [i] = 0; for ( i = 0; i < 4; i++ ) { nLines = _detPlane->calib.get_calLine (ctrlName, lines, i); if ( nLines != 0 ) { // ------ load control Blk ----- _detPlane->ctrlBlk.load (1, (char *) (LPCTSTR) ctrlName); // ------ make new channel list ------ _detPlane->chanList.resetChanList (); for ( j = 0; j < nLines; j++ ) { _detPlane->chanList.addChan (lines[j], chanMax, 4); linesUsed [lines[j]] = 1; } _detPlane->chanList.makeChanList (); // ------ collect data ------ scan->run ( _nEvents, 1 ); } } _detPlane->chanList.resetChanList (); for ( i = 0; i < 4; i++ ) { if ( linesUsed [i] == 1 ) _detPlane->chanList.addChan (i, chanMax, 4); } _detPlane->chanList.makeChanList (); scan->dataToFile ( _fileName ); // end scan delete scan; // --------------------------------------------- // load first cal control block // --------------------------------------------- nLines = _detPlane->calib.get_calLine (ctrlName, lines, 0); if ( nLines != 0 ) { _detPlane->ctrlBlk.load (1, (char *) (LPCTSTR) ctrlName); _detPlane->chanList.resetChanList (); for ( j = 0; j < nLines; j++ ) { _detPlane->chanList.addChan (lines[j], chanMax, 4); } _detPlane->chanList.makeChanList (); } fileName_to_logFile ( _fileName ); break; } } } // =============================================================== // print file name to scanLog file in datadir // =============================================================== int RunHandler::fileName_to_logFile (char* fileName) { DaqSetup* daq = daq->Instance (); DaqEnv* daqEnv = daq->daqEnv (); ofstream scanLog; if ( daqEnv->openFileDir (DataDir, "scanLog.txt", scanLog) == 0 ) return 0; scanLog << fileName << endl; scanLog.close (); return 1; }