/* * VetrocBlockData.cpp * * Created on: Nov 7, 2017 * Author: Hovanes Egiyan */ #include "VetrocBlockData.hh" using namespace std; unsigned VetrocBlockData::sizeIncrement = 10000; double pulseFrequency = 200; using namespace std; VetrocBlockData::VetrocBlockData( unsigned long nElem, const uint32_t* dataPointer ) : std::vector( nElem ), blockNumber( 0 ), eventMap(), nextInsertPosition( 0 ) { // std::cout << "Creating VetrocBlockData with " << nElem << " words " << std::endl; // Find the first type defining word VetrocWordBase* lastTypeDefinerWord = 0; VetrocEvent* lastEvent = 0; static unsigned long lastEventNumber = 0; static uint64_t oldTriggerTime = 0; static uint64_t newTriggerTime = 0; for ( unsigned wordNumber = 0; wordNumber < nElem; wordNumber++ ) { const uint32_t& swappedData = LSWAP( dataPointer[wordNumber] ); // std::cout << "Swapped data # " << dec << wordNumber << " is " << std::hex << std::showbase << swappedData // << " , unswapped " << dataPointer[wordNumber] << std::endl; VetrocWordInterface::dataType newType = (lastTypeDefinerWord == 0) ? VetrocWordInterface::UndefinedType : lastTypeDefinerWord->getType(); if ( VetrocWordBase::isDataTypeDefinitionFromBits( swappedData ) ) { newType = VetrocWordBase::getTypeFromBits( swappedData ); } VetrocWordBase* newWord = VetrocWord::createInstance( swappedData, newType ); if ( newWord != 0 ) { this->addWord( newWord ); // cout << "Vector location is at " << hex << this << " , data location is at " // << &((*this)[0]) << " next entry will be at " << this->getNextInsertPosition() // << " , data() method returns " << this->data() << endl; if ( newWord->isDataTypeDefinitionFromBits() && (newWord->getTypeFromBits() == VetrocWordInterface::BlockHeaderType) ) { blockNumber = newWord->getBlockNumber(); // cout << "Block number is " << dec << blockNumber << " , Block size is " // << newWord->getBlockSize() << endl; lastEvent = 0; } else if ( newWord->isDataTypeDefinitionFromBits() && (newWord->getTypeFromBits() == VetrocWordInterface::BlockTrailerType) ) { lastEvent = 0; } else if ( newWord->isDataTypeDefinitionFromBits() && (newWord->getTypeFromBits() == VetrocWordInterface::EventHeaderType) ) { // cout << "Starting a new event with a number " << dec << newWord->getEventNumber() // << " from type " << newWord->getTypeFromBits() << endl; const vector::iterator currentIterator = getLastInsertionIterator(); eventMap[newWord->getEventNumber()] = new VetrocEvent( this, getLastInsertionPosition() ); lastEvent = eventMap[newWord->getEventNumber()]; if ( (newWord->getEventNumber() - lastEventNumber) != 1 ) { cout << "The event after " << dec << lastEventNumber << " is event number " << newWord->getEventNumber() << endl; } lastEventNumber = newWord->getEventNumber(); if ( (lastEventNumber % 1000) == 0 ) { cout << "Read VETROC event number " << dec << lastEventNumber << endl; } // cout << "Started event at " << lastEvent << " with event number " // << (*this)[lastEvent->getHeaderPosition()]->getEventNumber() << endl; } else if ( newWord->getType() == VetrocWordInterface::TriggerTimeType || newWord->getType() == VetrocWordInterface::TDCHitType || newWord->getType() == VetrocWordInterface::Profiler1DType || newWord->getType() == VetrocWordInterface::Profiler2DType || newWord->getType() == VetrocWordInterface::FillerWordType ) { if ( lastEvent != 0 ) { lastEvent->setNumberOfWords( lastEvent->getNumberOfWords() + 1 ); } } if ( newWord->getType() == VetrocWordInterface::Profiler1DType && !newWord->isDataTypeDefinition() && newWord->getScalerCounts() > 0 ) { cout << "1D bin number " << dec << newWord->getBinID() << " scaler count is " << newWord->getScalerCounts() << endl; // cout << "Swapped data is " << hex << showbase << swappedData << endl; } else if ( newWord->getType() == VetrocWordInterface::Profiler2DType && !newWord->isDataTypeDefinition() && newWord->getScalerCounts() > 0 ) { cout << "2D bin (X,Y)=(" << dec << newWord->getBinX() << ", " << newWord->getBinY() << ") scaler count is " << newWord->getScalerCounts() << endl; cout << "Swapped data is " << hex << showbase << swappedData << endl; } else if ( newWord->getType() == VetrocWordInterface::TriggerTimeType ) { if ( newWord->isDataTypeDefinition() ) { oldTriggerTime = newTriggerTime; // cout << "Set oldTriggerTime to " << hex << showbase << oldTriggerTime << endl; newTriggerTime = 0; uint64_t deletionMask = VetrocWord::getTriggerTimeMask(); deletionMask = ~deletionMask; newTriggerTime = newTriggerTime & deletionMask; uint64_t triggerTimeLow = newWord->getTriggerTime(); // cout << "TriggerTimeLow is " << hex << showbase << triggerTimeLow << endl; newTriggerTime = newTriggerTime | triggerTimeLow; } else { uint64_t deletionMask = VetrocWord::getTriggerTimeMask(); deletionMask = ~(deletionMask << 24); newTriggerTime = newTriggerTime & deletionMask; uint64_t triggerTimeHigh = newWord->getTriggerTime(); // cout << "TriggerTimeHigh is " << hex << showbase << triggerTimeHigh << endl; newTriggerTime = newTriggerTime | (triggerTimeHigh << 24); // cout << "newTriggerTime is " << hex << showbase << newTriggerTime << endl; // cout << "Trigger time interval is " << hex << showbase // << newTriggerTime - oldTriggerTime << endl; if ( (newTriggerTime - oldTriggerTime) > (1.01 * 125000000.0 / pulseFrequency) ) { cout << "There is a large trigger time interval " << dec << newTriggerTime - oldTriggerTime << endl; } } } lastTypeDefinerWord = newWord; } } // cout << endl; return; }