Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
pslocum committed Feb 12, 2021
2 parents 20afe64 + 2b161e3 commit c6d52c9
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cmake_minimum_required( VERSION 3.1 )

# Define the project
cmake_policy( SET CMP0048 NEW ) # version in project()
project( locust_mc VERSION 2.1.6)
project( locust_mc VERSION 2.1.7)

list( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/Scarab/cmake )
include( PackageBuilder )
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM project8/p8compute_dependencies:v0.9.0 as locust_common
ARG build_type=Release
ENV LOCUST_BUILD_TYPE=$build_type

ENV LOCUST_TAG=v2.1.6
ENV LOCUST_TAG=v2.1.7
ENV LOCUST_BUILD_PREFIX=/usr/local/p8/locust/$LOCUST_TAG

RUN mkdir -p $LOCUST_BUILD_PREFIX &&\
Expand Down
42 changes: 37 additions & 5 deletions Source/Generators/LMCArraySignalGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace locust
fTextFileWriting( 0 ),
fphiLO(0.),
fNPreEventSamples( 150000 ),
fThreadCheckTime(10000),
EFieldBuffer( 1 ),
EPhaseBuffer( 1 ),
EAmplitudeBuffer( 1 ),
Expand All @@ -42,6 +43,8 @@ namespace locust
ElementFIRBuffer( 1 ),
fFieldBufferSize( 50 ),
fSwapFrequency( 1000 ),
fKassNeverStarted( false ),
fSkippedSamples( false ),
fInterface( new KassLocustInterface() )
{
fRequiredSignalState = Signal::kTime;
Expand Down Expand Up @@ -298,6 +301,10 @@ namespace locust
{
fNPreEventSamples = aParam["event-spacing-samples"]().as_int();
}
if( aParam.has( "thread-check-time" ) )
{
fThreadCheckTime = aParam["thread-check-time"]().as_int();
}
if( aParam.has( "swap-frequency" ) )
{
fSwapFrequency = aParam["swap-frequency"]().as_int();
Expand Down Expand Up @@ -414,7 +421,7 @@ namespace locust
}


void ArraySignalGenerator::DriveAntenna(FILE *fp, int PreEventCounter, unsigned index, Signal* aSignal, int nfilterbins, double dtfilter)
bool ArraySignalGenerator::DriveAntenna(FILE *fp, int startingIndex, unsigned index, Signal* aSignal, int nfilterbins, double dtfilter)
{

const int signalSize = aSignal->TimeSize();
Expand Down Expand Up @@ -453,6 +460,11 @@ namespace locust

FillBuffers(aSignal, tFieldSolution[1], tFieldSolution[0], fphiLO, index, channelIndex, elementIndex);
double VoltageFIRSample = GetFIRSample(nfilterbins, dtfilter, channelIndex, elementIndex);
if ((VoltageFIRSample == 0.)&&(index-startingIndex > fFieldBufferSize*fPowerCombiner->GetNElementsPerStrip()))
{
LERROR(lmclog,"A digitizer sample was skipped due to likely unresponsive thread.\n");
return false;
}
fPowerCombiner->AddOneVoltageToStripSum(aSignal, VoltageFIRSample, fphiLO, elementIndex, IndexBuffer[channelIndex*fNElementsPerStrip+elementIndex].front());
PopBuffers(channelIndex, elementIndex);

Expand All @@ -464,6 +476,7 @@ namespace locust

fInterface->fTOld += 1./(fAcquisitionRate*1.e6*aSignal->DecimationFactor());
if ( index%fSwapFrequency == 0 ) CleanupBuffers(); // release memory
return true;

}

Expand Down Expand Up @@ -594,6 +607,7 @@ namespace locust
if (fTransmitter->IsKassiopeia())
{
bool fTruth = false;
int startingIndex;
fInterface->fKassTimeStep = 1./(fAcquisitionRate*1.e6*aSignal->DecimationFactor());
std::thread tKassiopeia (&ArraySignalGenerator::KassiopeiaInit, this, gxml_filename); // spawn new thread

Expand All @@ -620,6 +634,7 @@ namespace locust
{
fInterface->fPreEventInProgress = false; // reset.
fInterface->fEventInProgress = true;
startingIndex = index;
LPROG( lmclog, "LMC about to WakeBeforeEvent()" );
WakeBeforeEvent(); // trigger Kass event.
}
Expand All @@ -634,21 +649,35 @@ namespace locust
fInterface->fDigitizerCondition.wait( tLock );
if (fInterface->fEventInProgress)
{
DriveAntenna(fp, PreEventCounter, index, aSignal, nfilterbins, dtfilter);
PreEventCounter = 0; // reset
if (DriveAntenna(fp, startingIndex, index, aSignal, nfilterbins, dtfilter))
{
PreEventCounter = 0; // reset
}
else if (!DriveAntenna(fp, startingIndex, index, aSignal, nfilterbins, dtfilter))
{
LERROR(lmclog,"The antenna did not respond correctly after two tries. Exiting.\n");
fSkippedSamples = true;
tLock.unlock();
break;
}
}
tLock.unlock();
}
else // either Kass thread fell behind, or it has stopped generating events.
{
tLock.lock();
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
std::this_thread::sleep_for(std::chrono::milliseconds(fThreadCheckTime));
if (!fInterface->fKassEventReady) // Kass event did start. Continue but skip this sample.
{
tLock.unlock();
}
else // no Kass event ever started, unlock and break out of signal loop entirely.
else // Kass event has not started, unlock and exit.
{
if ( index < fNPreEventSamples+1 )
{
LERROR(lmclog,"Kass thread is unresponsive. Exiting.\n");
fKassNeverStarted = true;
}
tLock.unlock();
break;
}
Expand All @@ -660,8 +689,11 @@ namespace locust
fInterface->fDoneWithSignalGeneration = true;
if (fTextFileWriting==1) fclose(fp);
LPROG( lmclog, "Finished signal loop." );
fInterface->fWaitBeforeEvent = false;
WakeBeforeEvent();
tKassiopeia.join(); // finish thread
if (fKassNeverStarted == true) return false;
if (fSkippedSamples == true) return false;


} // fTransmitter->IsKassiopeia()
Expand Down
7 changes: 5 additions & 2 deletions Source/Generators/LMCArraySignalGenerator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "LMCSinglePatchPositioner.hh"
#include "LMCPlanarArrayPositioner.hh"
#include <vector>

#include "LMCException.hh"


namespace locust
Expand Down Expand Up @@ -82,6 +82,7 @@ namespace locust
std::vector< Channel<Receiver*> > allRxChannels; //Vector of channels with pointers to Rx elements.
double fLO_Frequency;
int fNPreEventSamples; // spacing between events. constant for now, could be randomized.
int fThreadCheckTime; // time (ms) to check for response from Kass thread.
double fArrayRadius;
int fNElementsPerStrip;
int fNSubarrays;
Expand All @@ -91,6 +92,8 @@ namespace locust
bool fTextFileWriting;
unsigned fFieldBufferSize;
int fSwapFrequency;
bool fKassNeverStarted;
bool fSkippedSamples;
double fphiLO; // voltage phase of LO in radians;

void KassiopeiaInit(const std::string &aFile);
Expand All @@ -116,7 +119,7 @@ namespace locust


bool DoGenerate( Signal* aSignal );
void DriveAntenna(FILE *fp, int PreEventCounter, unsigned index, Signal* aSignal, int nfilterbins, double dtfilter);
bool DriveAntenna(FILE *fp, int startingIndex, unsigned index, Signal* aSignal, int nfilterbins, double dtfilter);
bool InitializeElementArray();
AntennaElementPositioner* fAntennaElementPositioner;
Transmitter* fTransmitter; // transmitter object
Expand Down
28 changes: 25 additions & 3 deletions Source/Generators/LMCKassSignalGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace locust
fPhiLO_t(0.),
fNPreEventSamples( 15000 ),
fEventStartTime(-99.),
fThreadCheckTime(1000),
fEventToFile( false ),
fInterface( new KassLocustInterface() )

Expand Down Expand Up @@ -77,6 +78,11 @@ namespace locust
fNPreEventSamples = aParam["event-spacing-samples"]().as_int();
}

if( aParam.has( "thread-check-time" ) )
{
fThreadCheckTime = aParam["thread-check-time"]().as_int();
}

if( aParam.has( "center-to-short" ) )
{
fInterface->fCENTER_TO_SHORT = aParam["center-to-short"]().as_double();
Expand Down Expand Up @@ -323,13 +329,14 @@ namespace locust
fInterface->fEventInProgress = true;
LPROG( lmclog, "LMC about to WakeBeforeEvent()" );
WakeBeforeEvent(); // trigger Kass event.
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}

if ((fInterface->fEventInProgress)&&(!fInterface->fKassEventReady)) // fEventInProgress
if (fInterface->fEventInProgress) // fEventInProgress
{
std::unique_lock< std::mutex >tLock( fInterface->fMutexDigitizer, std::defer_lock );
std::unique_lock< std::mutex >tLock( fInterface->fMutexDigitizer, std::defer_lock );
if (!fInterface->fKassEventReady) // Kass confirms event is underway.
{
tLock.lock();
fInterface->fDigitizerCondition.wait( tLock );
if (fInterface->fEventInProgress)
Expand All @@ -338,6 +345,21 @@ namespace locust
PreEventCounter = 0; // reset
}
tLock.unlock();
}
else // either Kass thread fell behind, or it has stopped generating events.
{
tLock.lock();
std::this_thread::sleep_for(std::chrono::milliseconds(fThreadCheckTime));
if (!fInterface->fKassEventReady) // Kass event did start. Continue but skip this sample.
{
tLock.unlock();
}
else // no Kass event ever started, unlock and break out of signal loop entirely.
{
tLock.unlock();
break;
}
}
}
} // for loop

Expand Down
1 change: 1 addition & 0 deletions Source/Generators/LMCKassSignalGenerator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ namespace locust
double fPhi_t2; // reflecting short voltage phase in radians.
double fPhiLO_t; // voltage phase of LO in radians;
int fNPreEventSamples; // spacing between events. constant for now, could be randomized.
int fThreadCheckTime; // time (ms) to check for response from Kass thread.
mutable double fPreviousRetardedTime;
mutable int fPreviousRetardedIndex;
double fEventStartTime;
Expand Down

0 comments on commit c6d52c9

Please sign in to comment.