diff --git a/Rich/Panoptes/options/RichOnlineCalib_Offline.py b/Rich/Panoptes/options/RichOnlineCalib_Offline.py index 2e269dcae3b48fcb5c400757f77a9c48454ac5eb..d1ce9de682b1886f3224337e1be6a587f511c3b9 100644 --- a/Rich/Panoptes/options/RichOnlineCalib_Offline.py +++ b/Rich/Panoptes/options/RichOnlineCalib_Offline.py @@ -25,6 +25,7 @@ def setup(): ] for path in searchPaths : RefIndexAlg.InputFiles += sorted(glob.glob(path+"*/*/*EOR.root")) + RefIndexAlg.InputFiles += sorted(glob.glob(path+"*EOR.root")) #print RefIndexAlg.InputFiles RefIndexAlg.xmlFilePath = "/tmp/HPDCalib" diff --git a/Rich/RichOnlineCalib/src/OMARichRefIndex.cpp b/Rich/RichOnlineCalib/src/OMARichRefIndex.cpp index a3e4f4e1903f6dfa285f484f7052f6a30d67b788..1c62f0c803bf847175507f3d2d712ff26163ba97 100644 --- a/Rich/RichOnlineCalib/src/OMARichRefIndex.cpp +++ b/Rich/RichOnlineCalib/src/OMARichRefIndex.cpp @@ -59,6 +59,8 @@ OMARichRefIndex::OMARichRefIndex( const std::string& name, declareProperty("MaxCachedCalibsInARow", m_maxCachedCalibs = 5 ); + declareProperty("RunNumHistSize", m_runNumHistSize = 100 ); + // Partition const char* partitionName = getenv("PARTITION"); if ( partitionName ) { m_Name += std::string(partitionName); } @@ -138,8 +140,8 @@ StatusCode OMARichRefIndex::execute() //============================================================================= // Analyze //============================================================================= -StatusCode OMARichRefIndex::analyze (std::string& SaveSet, - std::string Task) +StatusCode OMARichRefIndex::analyze ( std::string& SaveSet, + std::string Task ) { if ( msgLevel(MSG::DEBUG) ) debug() << "==> Analyze" << endmsg; @@ -192,7 +194,7 @@ StatusCode OMARichRefIndex::analyze (std::string& SaveSet, // Fix me!? not do fit for the run withtout "-EOR" just before stopping the calib job... // Extract the file name from the full path - const std::string fileName = boost::filesystem::path(SaveSet).stem().string(); + const auto fileName = boost::filesystem::path(SaveSet).stem().string(); // Extract the run number const auto runNumber = getRunNumber( fileName ); @@ -212,14 +214,23 @@ StatusCode OMARichRefIndex::analyze (std::string& SaveSet, cameraTool()->Append("TEXT",mess1.str()); cameraTool()->Append("TEXT",mess2.str()); - // check the run number is sensible ... - if ( UNLIKELY( 0 == runNumber ) ) + // check the run number is not 0 ... + if ( UNLIKELY( 0 == runNumber ) ) { const std::string mess = "Run number in Brunel Saveset is '0' !! -> Calibration skipped"; cameraTool()->SendAndClearTS( ICameraTool::ERROR, m_Name, mess ); error() << mess << endmsg; } + // Check run number is not too old... + else if ( UNLIKELY( m_maxSeenRunNum - runNumber > m_runNumHistSize ) ) + { + std::ostringstream mess; + mess << "Run " << runNumber << " too old ( Newest seen is " << m_maxSeenRunNum + << " ). Calibration Aborted."; + cameraTool()->SendAndClearTS( ICameraTool::ERROR, m_Name, mess.str() ); + error() << mess.str() << endmsg; + } else { if ( fileName.find(m_EoRSignal) != std::string::npos ) @@ -244,7 +255,7 @@ StatusCode OMARichRefIndex::analyze (std::string& SaveSet, else if ( runNumber != m_lastRun.run ) // new Run, use previous file { // is last run recent enough to do a calibration for ? - if ( abs( runNumber - m_lastRun.run ) < 1000 ) + if ( abs( runNumber - m_lastRun.run ) < m_runNumHistSize ) { std::ostringstream mess; mess << "Refractive index calibration for run " << m_lastRun.run @@ -686,7 +697,7 @@ OMARichRefIndex::fitCKThetaHistogram( TH1* hist, fitOK &= finalCheck; // return final fit parameter for shift - return FitResult( fitOK, + return FitResult( fitOK, fitOK ? bestFitF.GetParameter(1) : 0.0, fitOK ? bestFitF.GetParError(1) : 0.0, fitOK ? bestFitF.GetParameter(2) : 0.0, @@ -1021,7 +1032,7 @@ bool OMARichRefIndex::writeCKThetaLog( const std::string& rad, if ( file.is_open() ) { // write out the result for this run - file << runNumber << " " << m_fileTime << " " + file << runNumber << " " << m_fileTime << " " << fitResult.ckResolution << " " << fitResult.ckResolutionErr << std::endl; // close the file @@ -1229,8 +1240,8 @@ void OMARichRefIndex::printCanvas( const std::string& tag ) const info() << mess.str() << endmsg; cameraTool()->Append("TEXT",mess.str()); - // limit the PDF map to (last) 10 entries - while ( m_pdfFile.size() > 10 ) + // limit the PDF file name map to N entries + while ( m_pdfFile.size() > m_runNumHistSize + 10 ) { m_pdfFile.erase( m_pdfFile.begin() ); } } diff --git a/Rich/RichOnlineCalib/src/OMARichRefIndex.h b/Rich/RichOnlineCalib/src/OMARichRefIndex.h index dfae982474d5683f778286957ec5b5cbcc308b22..823928be8d3fa4d78aa51222877d7c6f2f6353f5 100644 --- a/Rich/RichOnlineCalib/src/OMARichRefIndex.h +++ b/Rich/RichOnlineCalib/src/OMARichRefIndex.h @@ -139,7 +139,13 @@ private: { const std::string firstName = fileName.substr(fileName.find_first_of("-")+1); const std::string runString = firstName.substr(0,firstName.find_first_of("-")); - return atoi( runString.c_str() ); + const unsigned int runN = atoi( runString.c_str() ); + if ( runN > m_maxSeenRunNum ) + { + m_maxSeenRunNum = runN; + info() << "Set latest seen run number to " << runN << endmsg; + } + return runN; } // Function to get time stamp from the file name @@ -479,6 +485,12 @@ private: /// maximum cached calibrations to allow in a row unsigned int m_maxCachedCalibs; + + /// Max run number history + unsigned int m_runNumHistSize; + + /// Max seen run number + unsigned int m_maxSeenRunNum{0}; };