/* * Scan.cpp * * Created on: Dec 25, 2014 * Author: Hovanes Egiyan */ #include "Scan.hh" #include "ScanCorrection.hh" ClassImp( Scan ) using namespace std; // Define the name of the detector to be used for normalization purposes string Scan::sNormDetName = " IBCAD00CRCUR6"; Scan::Scan() : TObject(), scanNumber(9999), sScanFile(), sScanStream(), sScanPlot(), xPosCombined(0), yPosCombined(0), zValCombined(), sOverviewMainFrame(0){ cout << "Default Scan constructor" << endl; return; } Scan::Scan( ScanFile* scanFile, int scNumber ) : TObject(), scanNumber(9999), sScanFile( scanFile ), sScanStream( new ScanStream( sScanFile ) ), sScanPlot(), xPosCombined(0), yPosCombined(0), zValCombined(), sOverviewMainFrame(0) { if( sScanStream->getScanNumber() < 0 ) sScanStream->setScanNumber( scNumber ); cout << "Scan name is " << sScanStream->getScanName() << endl; cout << "Scan number is " << sScanStream->getScanNumber() << " with rank " << sScanStream->getScanRank() << endl; scanNumber = sScanStream->getScanNumber(); scanRank = sScanStream->getScanRank(); nPoints = sScanStream->getNPoints(); nDetectors = sScanStream->getNDetectors(); nTriggers = sScanStream->getNTriggers(); cout << "Building plots" << endl; buildPlots(); cout << "Finished building plots for scan #" << scanNumber <::iterator itD; // loop over detectors for ( itD = sScanPlot.begin(); itD != sScanPlot.end(); itD++ ) { ScanPlot* plot2delete = itD->second; if ( plot2delete != 0 ) delete plot2delete; plot2delete = 0; } try { if ( sOverviewMainFrame != 0 && sOverviewMainFrame->IsActive() ) sOverviewMainFrame->CloseWindow(); } catch ( ... ) { cout << "Failed to delete OvervewMainFrame " << endl; } if( xPosCombined != 0 ) delete xPosCombined; if( yPosCombined != 0 ) delete yPosCombined; for ( map::iterator itDet = zValCombined.begin(); itDet != zValCombined.end(); itDet++ ) { ScanDetector* zDetector = itDet->second; if( zDetector!= 0 ) delete zDetector; } if ( sScanStream != 0 ) delete sScanStream; return; } void Scan::buildPlots() { cout << "Inside buildPlots" << endl; if ( scanRank == 2 ) { if ( sScanStream->getPositioners().size() != 1 ) return; ScanPositioner* yPos = this->getPositioners()[1]; vector zeroVector; yPosCombined = new ScanPositioner( *yPos ); yPosCombined->getData() = zeroVector; cout << "Created combinedY called " << yPosCombined->getName() << " from original called " << yPos->getName() << endl; map& subScanMap = sScanStream->getSubScans(); cout << "sub-scan map size is " << subScanMap.size() << endl; for ( map::iterator itScan = subScanMap.begin(); itScan != subScanMap.end(); itScan++ ) { int iY = itScan->first - 1; Scan* subScan = itScan->second; cout << "Scan number (y point ) is " << iY << endl; cout << "Y point is " << yPos->getData()[iY] << endl; ScanPositioner* xPos = subScan->getPositioners()[1]; if ( xPosCombined == 0 ) { xPosCombined = new ScanPositioner( *xPos ); xPosCombined->getData() = zeroVector; cout << "Created combinedX called " << xPosCombined->getName() << " from original called " << xPos->getName() << endl; } std::map& detMap = subScan->getDetectors(); vector tmpVecX; vector tmpVecY; map > tmpVecZ; for ( unsigned iX = 0; iX < xPos->getData().size(); iX++ ) { cout << "X point is " << xPos->getData()[iX] << endl; tmpVecX.push_back( xPos->getData()[iX] ); tmpVecY.push_back( yPos->getData()[iY] ); for ( map::iterator itD = detMap.begin(); itD != detMap.end(); itD++ ) { int iDet = itD->first; ScanDetector* detPtr = itD->second; tmpVecZ[iDet].push_back( detPtr->getData()[iX] ); } } xPosCombined->getData().insert( xPosCombined->getData().end(), tmpVecX.begin(), tmpVecX.end() ); yPosCombined->getData().insert( yPosCombined->getData().end(), tmpVecY.begin(), tmpVecY.end() ); for ( map::iterator itD = detMap.begin(); itD != detMap.end(); itD++ ) { int iDet = itD->first; ScanDetector* detPtr = itD->second; if ( zValCombined.count( iDet ) == 0 ) { zValCombined[iDet] = new ScanDetector( *const_cast( detPtr ) ); zValCombined[iDet]->getData() = zeroVector; } zValCombined[iDet]->getData().insert( zValCombined[iDet]->getData().end(), tmpVecZ[iDet].begin(), tmpVecZ[iDet].end() ); } } cout << "First pass for building plots is complete" << endl; for ( map::iterator itDet = zValCombined.begin(); itDet != zValCombined.end(); itDet++ ) { int detNum = itDet->first; ScanDetector* detector = itDet->second; cout << "Creating ScanPlot for detector number " << detNum << endl; sScanPlot[detNum] = new ScanPlot( detector, xPosCombined, yPosCombined, sScanStream->getScanName(), sScanStream->getScanTime(), true ); } cout << "ScanPlot objects have been built" << endl; // Create a new frame for this positioner string frameName = sScanFile->getFileName(); OverviewMainFrame* newMainFrame = new OverviewMainFrame( gClient->GetRoot(), frameName.c_str(), 1500, 500, sScanPlot, zValCombined.size() ); sOverviewMainFrame = newMainFrame; cout << "OverviewMainFrame object has been created" << endl; } return; }