Ejemplo n.º 1
0
int32_t PigsDAQ::AddBoardUSB() {
    // Adds board 0 & prints board information
    if(fVerbose) std::cout<<__PRETTY_FUNCTION__ << std::endl;
    // The following is for direct USB connection
    connParam.LinkType = CAENDPP_USB;
    connParam.LinkNum = 0;              // This defines the USB port to use and must increase with board number; ex: for board 3 must be 3
    connParam.ConetNode = 0;            // This MUST be 0
    connParam.VMEBaseAddress = 0x0;     // For direct connection the address must be 0
    brd = 0;                            // We only have one board

    // Add board to the Library
    fErrCode = CAENDPP_AddBoard(handle, connParam, &brd);
    if(fErrCode != CAENDPP_RetCode_Ok) {
        std::cerr<<"Error adding board with selected connection parameters: "<< decodeError(codeStr,fErrCode) << std::endl;
        return fErrCode;
    }

    // Get Board Info
    fErrCode  = CAENDPP_GetDPPInfo(handle, brd, &info);
    if(fErrCode != CAENDPP_RetCode_Ok) {
        std::cerr<<"Error getting board info: "<< decodeError(codeStr,fErrCode) << std::endl;
        return fErrCode;
    }
    if(fVerbose>9) PrintBoardInfo();

    // Prints board info into fBoardInfo
    fBoardInfo.Clear();
    fBoardInfo += Form("Board %s, Serial#: %d\n",info.ModelName, info.SerialNumber);
    fBoardInfo += Form("  Channels: %d, License: %s\n", info.Channels, info.License);
    fBoardInfo += Form("  Firmware AMC: %s, ROC %s\n", info.AMC_FirmwareRel,info.ROC_FirmwareRel);

    return fErrCode;
}
Ejemplo n.º 2
0
void
SourceBuffer::AppendData(const uint8_t* aData, uint32_t aLength, ErrorResult& aRv)
{
    MSE_DEBUG("SourceBuffer(%p)::AppendData(aLength=%u)", this, aLength);
    if (!PrepareAppend(aRv)) {
        return;
    }
    StartUpdating();

    if (!mTrackBuffer->AppendData(aData, aLength)) {
        Optional<MediaSourceEndOfStreamError> decodeError(MediaSourceEndOfStreamError::Decode);
        ErrorResult dummy;
        mMediaSource->EndOfStream(decodeError, dummy);
        aRv.Throw(NS_ERROR_FAILURE);
        return;
    }

    if (mTrackBuffer->HasInitSegment()) {
        mMediaSource->QueueInitializationEvent();
    }

    // Run the final step of the buffer append algorithm asynchronously to
    // ensure the SourceBuffer's updating flag transition behaves as required
    // by the spec.
    nsCOMPtr<nsIRunnable> event = NS_NewRunnableMethod(this, &SourceBuffer::StopUpdating);
    NS_DispatchToMainThread(event);
}
Ejemplo n.º 3
0
int32_t PigsDAQ::InitDPPLib() {
    // Initialize the DPP library
    if(fVerbose) std::cout<<__PRETTY_FUNCTION__ << std::endl;
    fErrCode = CAENDPP_InitLibrary(&handle);    // The handle will be used to command the library
    if(fErrCode != CAENDPP_RetCode_Ok)
        std::cerr<<"Problem initializing the library: "<< decodeError(codeStr,fErrCode) << std::endl;
    return fErrCode;
}
Ejemplo n.º 4
0
int32_t PigsDAQ::EndLibrary() {
    // Close the Library
    if(fVerbose) std::cout<<__PRETTY_FUNCTION__ << std::endl;
    fErrCode =  CAENDPP_EndLibrary(handle);
    if(fErrCode != CAENDPP_RetCode_Ok) {
        std::cerr<<"Error closing the library: "<< decodeError(codeStr,fErrCode) << std::endl;
    }
    return fErrCode;
}
Ejemplo n.º 5
0
int32_t PigsDAQ::StopAcquisition(int32_t ch) {
    if(fVerbose) std::cout<<__PRETTY_FUNCTION__ << std::endl;
    // Stop Acquisition for channel ch; -1 for all channels
    fErrCode = CAENDPP_StopAcquisition(handle, ch);
    if (fErrCode != CAENDPP_RetCode_Ok) {
        printf ("Error Stopping Acquisition for channel %d: %s\n", ch, decodeError(codeStr, fErrCode));
    } else {
        printf("Acquisition Stopped for channel %d\n", ch);
    }
    return fErrCode;
}
Ejemplo n.º 6
0
int32_t PigsDAQ::ConfigureBoard() {
    // Configures board 0
    if(fVerbose) std::cout<<__PRETTY_FUNCTION__ << std::endl;

    fErrCode  = CAENDPP_SetBoardConfiguration(handle, 0, acqMode, dgtzParams);
    if(fErrCode != CAENDPP_RetCode_Ok) {
        std::cerr<<"Can't configure board "<<info.ModelName << ", Serial#: " << info.SerialNumber
                << ": " << decodeError(codeStr,fErrCode) << std::endl;
        return fErrCode;
    }
    if(fVerbose && fErrCode == CAENDPP_RetCode_Ok) {
        std::cout << "Board "<< info.ModelName << ", Serial#: " << info.SerialNumber <<" configured."<< std::endl;
    }
    return fErrCode;
}
Ejemplo n.º 7
0
void
SourceBuffer::AppendError(bool aDecoderError)
{
  MOZ_ASSERT(NS_IsMainThread());

  ResetParserState();

  mUpdating = false;

  QueueAsyncSimpleEvent("error");
  QueueAsyncSimpleEvent("updateend");

  if (aDecoderError) {
    Optional<MediaSourceEndOfStreamError> decodeError(
      MediaSourceEndOfStreamError::Decode);
    ErrorResult dummy;
    mMediaSource->EndOfStream(decodeError, dummy);
  }
}
Ejemplo n.º 8
0
void
SourceBuffer::AppendError(bool aDecoderError)
{
  MOZ_ASSERT(NS_IsMainThread());
  if (!mUpdating) {
    // The buffer append algorithm has been interrupted by abort().
    return;
  }
  mTrackBuffer->ResetParserState();

  mUpdating = false;

  QueueAsyncSimpleEvent("error");
  QueueAsyncSimpleEvent("updateend");

  if (aDecoderError) {
    Optional<MediaSourceEndOfStreamError> decodeError(
      MediaSourceEndOfStreamError::Decode);
    ErrorResult dummy;
    mMediaSource->EndOfStream(decodeError, dummy);
  }
}
Ejemplo n.º 9
0
int32_t PigsDAQ::ConfigureChannel(int32_t ch) {
    // Configures channel with parameters set in the class data
    if(fVerbose) std::cout<<__PRETTY_FUNCTION__ << std::endl;
    if (isChannelDisabled(ch)) {
        printf("Warning: Channel %d disabled\n",ch);
        return 1;
    }
    fErrCode = CAENDPP_SetInputRange(handle, ch, iputLevel);
    if (fErrCode == CAENDPP_RetCode_Ok)  {
        printf("Input range for channel %d set to %d\n", ch, iputLevel);
    } else {
        printf("Error setting input range\n");
        return fErrCode;
    }
    fErrCode = CAENDPP_SetStopCriteria(handle, ch, StopCriteria, StopCriteriaValue);
    if (fErrCode == CAENDPP_RetCode_Ok) {
        printf("Stop Criteria successfully set: %d, %lu\n", StopCriteria, StopCriteriaValue);
    } else {
        printf("Can't set Stop Criteria for channel %d: %s\n", ch, decodeError(codeStr, fErrCode));
        return fErrCode;
    }
    return fErrCode;
}
Ejemplo n.º 10
0
int32_t PigsDAQ::AcquisitionSingleLoop() {
    // Currently does only one cycle in the loop...
    if(fVerbose) std::cout<<__PRETTY_FUNCTION__ << " begin " << std::endl;
    // reset counters
    Float_t pctProgress = 0.0;        // measures progress in acquisition
    Float_t pctIncrement = 100.*1000.*(Float_t)usecSleepPollDAQ/(Float_t)StopCriteriaValue;
    for (ch=0; ch<4; ch++) {
        totCounts[ch] = 0; realTime[ch] = 0; deadTime[ch] = 0;
        countsPerSecond[ch] = 0;
    }
    // Clear histogram on all channels
    for (ch=0; ch<4; ch++) {
        fErrCode = CAENDPP_ClearHistogram(handle, ch, 0);
        if (fErrCode != CAENDPP_RetCode_Ok) {
            std::cerr << "Error clearing histogram on channel" << ch << std::endl;
            return fErrCode;
        } else {
            if(fVerbose) std::cout << "Histogram on channel " << ch << " cleared." << std::endl;
        }
    }
    if(gui) gui->SetProgressBarPosition(pctProgress);    // If GUI is set, update the progress bar

    // Set starting date time
    fDt.Set();
    if(fVerbose) std::cout<<__PRETTY_FUNCTION__ << " timestamp set " << std::endl;

    // Start Acquisition for all channels
    fErrCode = CAENDPP_StartAcquisition(handle, -1); // -1 = all channe;s
    if (fErrCode != CAENDPP_RetCode_Ok) {
        printf("Error Starting Acquisition for all channels: %s\n",  decodeError(codeStr, fErrCode));
        return fErrCode;
    } else {
        if(fVerbose) printf("Acquisition Started for all channels\n");
    }

  uint32_t keepGoing = 0;
  do {
        if(gui) {  // If GUI is set, update the progress bar
            gui->SetProgressBarPosition(pctProgress);
            if(fVerbose>9) std::cout<<__PRETTY_FUNCTION__ << " progress: " << pctProgress << std::endl;
        }
/*        usleep(usecSleepPollDAQ);        // Waits to poll DT5781 // TODO re-implement using TTimer?*/
        gSystem->Sleep(usecSleepPollDAQ/1000);
        gSystem->ProcessEvents();

        keepGoing = 0;                   // Check if we still take data
        for (ch=0; ch<4; ch++) {
            CAENDPP_IsChannelAcquiring(handle, ch, &checkAcquiring[ch]);
            keepGoing += checkAcquiring[ch];
            if(fVerbose>3) printf("  -- %5.2f %%, ch %d acq status %d\n", pctProgress, ch, checkAcquiring[ch]);
        }
        pctProgress += pctIncrement;
        if(pctProgress > 200.0) {       // taking data too long, something is fishy
            std::cerr << "ERROR: taking data for too long, are all detectors connected?" << std::endl;
            keepGoing = 0;
            this->StopAcquisition(-1);
        }
  } while (keepGoing);
    if(fVerbose) std::cout<<__PRETTY_FUNCTION__ << " acquisition stopped " << std::endl;

    // Get The Histograms
    for (ch=0; ch<4; ch++) {
        fErrCode = CAENDPP_GetCurrentHistogram(handle, ch, h[ch], &goodCounts[ch], &realTime[ch], &deadTime[ch], &isAcquiring);
        if (fErrCode != CAENDPP_RetCode_Ok) {
            printf("ERROR: Can't get current Histogram for ch %d: %s\n", ch, decodeError(codeStr, fErrCode));
            return fErrCode;
        }
    }
    // Get the histogram bin numbers
    for (ch=0; ch<4; ch++) {
        fErrCode = CAENDPP_GetHistogramSize(handle, ch, HISTO_IDX_CURRENT, &hNBins[ch]);
        if (fErrCode != CAENDPP_RetCode_Ok) {
            printf("ERROR: Can't get current Histogram size for ch %d: %s\n", ch, decodeError(codeStr, fErrCode));
            return fErrCode;
        }
        totCounts[ch]       = (uint32_t)(goodCounts[ch] * (1.0 + (double)deadTime[ch] / (double)(realTime[ch])));
        countsPerSecond[ch] = (realTime[ch] - deadTime[ch]) > 0 ? (double)goodCounts[ch] / (double)((realTime[ch] - deadTime[ch]) / 1000000000.0) : 0;
        if(fVerbose) PrintAcquisotionInfo(ch);
    }
    if(fVerbose) std::cout<<__PRETTY_FUNCTION__ << " done " <<  hNBins[0]+hNBins[1]+hNBins[2]+hNBins[3] << std::endl;
    return fErrCode;
}
Ejemplo n.º 11
0
void
SourceBuffer::AppendData(const uint8_t* aData, uint32_t aLength, ErrorResult& aRv)
{
  MSE_DEBUG("SourceBuffer(%p)::AppendData(aLength=%u)", this, aLength);
  if (!IsAttached() || mUpdating) {
    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
    return;
  }
  if (mMediaSource->ReadyState() == MediaSourceReadyState::Ended) {
    mMediaSource->SetReadyState(MediaSourceReadyState::Open);
  }
  // TODO: Run coded frame eviction algorithm.
  // TODO: Test buffer full flag.
  StartUpdating();
  // TODO: Run buffer append algorithm asynchronously (would call StopUpdating()).
  if (mParser->IsInitSegmentPresent(aData, aLength)) {
    MSE_DEBUG("SourceBuffer(%p)::AppendData: New initialization segment.", this);
    if (mDecoderInitialized) {
      // Existing decoder has been used, time for a new one.
      DiscardDecoder();
    }

    // If we've got a decoder here, it's not initialized, so we can use it
    // rather than creating a new one.
    if (!mDecoder && !InitNewDecoder()) {
      aRv.Throw(NS_ERROR_FAILURE); // XXX: Review error handling.
      return;
    }
    MSE_DEBUG("SourceBuffer(%p)::AppendData: Decoder marked as initialized.", this);
    mDecoderInitialized = true;
  } else if (!mDecoderInitialized) {
    MSE_DEBUG("SourceBuffer(%p)::AppendData: Non-init segment appended during initialization.");
    Optional<MediaSourceEndOfStreamError> decodeError(MediaSourceEndOfStreamError::Decode);
    ErrorResult dummy;
    mMediaSource->EndOfStream(decodeError, dummy);
    aRv.Throw(NS_ERROR_FAILURE);
    return;
  }
  // XXX: For future reference: NDA call must run on the main thread.
  mDecoder->NotifyDataArrived(reinterpret_cast<const char*>(aData),
                              aLength,
                              mDecoder->GetResource()->GetLength());
  mDecoder->GetResource()->AppendData(aData, aLength);

  // Eviction uses a byte threshold. If the buffer is greater than the
  // number of bytes then data is evicted. The time range for this
  // eviction is reported back to the media source. It will then
  // evict data before that range across all SourceBuffers it knows
  // about.
  // TODO: Make the eviction threshold smaller for audio-only streams.
  // TODO: Drive evictions off memory pressure notifications.
  const uint32_t evict_threshold = 75 * (1 << 20);
  bool evicted = mDecoder->GetResource()->EvictData(evict_threshold);
  if (evicted) {
    MSE_DEBUG("SourceBuffer(%p)::AppendBuffer Evict; current buffered start=%f",
              this, GetBufferedStart());

    // We notify that we've evicted from the time range 0 through to
    // the current start point.
    mMediaSource->NotifyEvicted(0.0, GetBufferedStart());
  }
  StopUpdating();

  // Schedule the state machine thread to ensure playback starts
  // if required when data is appended.
  mMediaSource->GetDecoder()->ScheduleStateMachineThread();

  mMediaSource->NotifyGotData();
}
Ejemplo n.º 12
0
void CudaModule::checkError(const char* funcName, CUresult res)
{
  if (res != CUDA_SUCCESS) {
    fail( "%s() failed: %s!", funcName, decodeError(res));
  }
}
Ejemplo n.º 13
0
void
SourceBuffer::AppendData(const uint8_t* aData, uint32_t aLength, ErrorResult& aRv)
{
  MSE_DEBUG("SourceBuffer(%p)::AppendData(aLength=%u)", this, aLength);
  if (!PrepareAppend(aRv)) {
    return;
  }
  StartUpdating();
  // TODO: Run more of the buffer append algorithm asynchronously.
  if (mParser->IsInitSegmentPresent(aData, aLength)) {
    MSE_DEBUG("SourceBuffer(%p)::AppendData: New initialization segment.", this);
    mMediaSource->QueueInitializationEvent();
    mTrackBuffer->DiscardDecoder();
    if (!mTrackBuffer->NewDecoder()) {
      aRv.Throw(NS_ERROR_FAILURE); // XXX: Review error handling.
      return;
    }
    MSE_DEBUG("SourceBuffer(%p)::AppendData: Decoder marked as initialized.", this);
  } else if (!mTrackBuffer->HasInitSegment()) {
    MSE_DEBUG("SourceBuffer(%p)::AppendData: Non-init segment appended during initialization.", this);
    Optional<MediaSourceEndOfStreamError> decodeError(MediaSourceEndOfStreamError::Decode);
    ErrorResult dummy;
    mMediaSource->EndOfStream(decodeError, dummy);
    aRv.Throw(NS_ERROR_FAILURE);
    return;
  }
  int64_t start, end;
  if (mParser->ParseStartAndEndTimestamps(aData, aLength, start, end)) {
    int64_t lastStart, lastEnd;
    mTrackBuffer->LastTimestamp(lastStart, lastEnd);
    if (mParser->IsMediaSegmentPresent(aData, aLength) &&
        !mParser->TimestampsFuzzyEqual(start, lastEnd)) {
      MSE_DEBUG("SourceBuffer(%p)::AppendData: Data last=[%lld, %lld] overlaps [%lld, %lld]",
                this, lastStart, lastEnd, start, end);

      // This data is earlier in the timeline than data we have already
      // processed, so we must create a new decoder to handle the decoding.
      mTrackBuffer->DiscardDecoder();

      // If we've got a decoder here, it's not initialized, so we can use it
      // rather than creating a new one.
      if (!mTrackBuffer->NewDecoder()) {
        aRv.Throw(NS_ERROR_FAILURE); // XXX: Review error handling.
        return;
      }
      MSE_DEBUG("SourceBuffer(%p)::AppendData: Decoder marked as initialized.", this);
      const nsTArray<uint8_t>& initData = mParser->InitData();
      mTrackBuffer->AppendData(initData.Elements(), initData.Length());
      mTrackBuffer->SetLastStartTimestamp(start);
    }
    mTrackBuffer->SetLastEndTimestamp(end);
    MSE_DEBUG("SourceBuffer(%p)::AppendData: Segment last=[%lld, %lld] [%lld, %lld]",
              this, lastStart, lastEnd, start, end);
  }
  if (!mTrackBuffer->AppendData(aData, aLength)) {
    Optional<MediaSourceEndOfStreamError> decodeError(MediaSourceEndOfStreamError::Decode);
    ErrorResult dummy;
    mMediaSource->EndOfStream(decodeError, dummy);
    aRv.Throw(NS_ERROR_FAILURE);
    return;
  }

  // Schedule the state machine thread to ensure playback starts
  // if required when data is appended.
  mMediaSource->GetDecoder()->ScheduleStateMachineThread();

  // Run the final step of the buffer append algorithm asynchronously to
  // ensure the SourceBuffer's updating flag transition behaves as required
  // by the spec.
  nsCOMPtr<nsIRunnable> event = NS_NewRunnableMethod(this, &SourceBuffer::StopUpdating);
  NS_DispatchToMainThread(event);
}