38 #include "StDAQMaker/StDAQReader.h"
39 #include "StRtsTable.h"
42 #include "StETofCollection.h"
43 #include "StETofHeader.h"
44 #include "StETofDigi.h"
45 #include "StETofHit.h"
47 #include "StETofDigiMaker.h"
48 #include "StETofUtil/StETofConstants.h"
49 #include "StETofUtil/StETofHardwareMap.h"
50 #include "StETofUtil/StETofMessageFormat.h"
52 #include "tables/St_etofElectronicsMap_Table.h"
62 mFileNameElectronicsMap(
"" ),
65 LOG_DEBUG <<
"StETofDigiMaker::ctor" << endm;
66 const size_t kNbGet4sInSystem = 1728;
67 mMissMatchFlagVec = vector< bool >( kNbGet4sInSystem, false );
68 mGet4ActiveMap.clear();
72 StETofDigiMaker::~StETofDigiMaker()
79 StETofDigiMaker::Init()
81 LOG_INFO <<
"StETofDigiMaker::Init" << endm;
88 StETofDigiMaker::InitRun( Int_t runnumber )
90 mRunYear = ( runnumber + 727000 ) / 1000000 + 1999;
92 LOG_INFO <<
"runnumber: " << runnumber <<
" --> year: " << mRunYear << endm;
94 mGet4ActiveMap.clear();
98 if( mFileNameElectronicsMap.empty() ) {
99 LOG_INFO <<
"StETofDigiMaker::InitRun: no electronics map filename provided --> load database table" << endm;
101 dbDataSet = GetDataBase(
"Geometry/etof/etofElectronicsMap" );
103 St_etofElectronicsMap* etofElectronicsMap =
static_cast< St_etofElectronicsMap*
> ( dbDataSet->
Find(
"etofElectronicsMap" ) );
104 if( !etofElectronicsMap ) {
105 LOG_ERROR <<
"unable to get the electronics map from the database" << endm;
111 etofElectronicsMap_st* table = etofElectronicsMap->GetTable();
112 LOG_INFO <<
"StETofDigiMaker::InitRun: PRINTING CHANNEL MAP: " << endm;
113 for(
size_t i=0; i<576; i++ ) {
115 mGet4ActiveMap[ table->channelNumber[ i ] ] =
true;
119 LOG_INFO <<
"StETofDigiMaker::InitRun: etofElectronicsMap: filename provided --> use parameter file: " << mFileNameElectronicsMap.c_str() << endm;
124 std::ifstream paramFile;
126 paramFile.open( mFileNameElectronicsMap.c_str() );
128 if( !paramFile.is_open() ) {
129 LOG_ERROR <<
"StETofHardwareMap -- unable to get the parameters from local file --> file does not exist" << endm;
135 for(
int i=0; i<576; i++ ) {
136 if( !paramFile.eof() ) {
137 paramFile >> std::dec >> temp;
138 mGet4ActiveMap[ temp ] =
true;
148 StETofDigiMaker::FinishRun( Int_t runnumber )
171 mEvent =
dynamic_cast< StEvent*
>( GetInputDS(
"StEvent" ) );
174 etofCollection = mEvent->etofCollection();
177 if ( !etofCollection ) {
179 LOG_INFO <<
"StETofDigiMaker::getETofCollection - making new StETofCollection and giving it to StEvent" << endm;
181 mEvent->setETofCollection( etofCollection );
184 LOG_INFO <<
"StETofDigiMaker::getETofCollection - StEvent already has a StETofCollection - not making a new one" << endm;
188 LOG_WARN <<
"No StEvent found by StETofDigiMaker::getETofCollection" << endm;
191 return etofCollection;
198 LOG_INFO <<
"StETofDigiMaker::Make()" << endm;
203 LOG_DEBUG <<
"StETofDigiMaker::Make() - getting the etof collection " << mETofCollection << endm;
206 if ( mETofCollection ==
nullptr ) {
207 LOG_WARN <<
"No StEvent --> no ETofCollection --> nothing to do" << endm;
211 if( mETofCollection->digisPresent() ) {
212 LOG_WARN <<
"StETofDigiMaker::Make() - there are already ETOF DIGIS ... nothing to do." << endm;
221 if ( daqdta ==
nullptr ) {
222 LOG_WARN <<
"StETofDigiMaker::Make() - NO ETOF DATA found in event" << endm;
227 int inputSizeBytes = daqdta->GetSize();
230 LOG_DEBUG <<
"StETofDigiMaker::Make() - InputSize (bytes): " << inputSizeBytes << endm;
233 uint64_t* messageBuffer = ( uint64_t* ) ( *daqdta->begin() );
244 size_t nFullMessagesToRead = ( ( inputSizeBytes / eTofConst::daqMessageSize ) - 4 ) / 2;
245 LOG_INFO <<
"StETofDigiMaker::Make() - # full messages to read: " << nFullMessagesToRead << endm;
247 if( mRunYear == 2018 ) {
249 LOG_DEBUG <<
"processing event from 2018" << endm;
255 LOG_DEBUG <<
"processing event from 2019+" << endm;
272 vector< gdpbv100::FullMessage > triggerMessages;
273 const size_t kNbGet4sInSystem = 1728;
274 mMissMatchFlagVec.clear();
275 mMissMatchFlagVec.resize( kNbGet4sInSystem, 0 );
278 for(
size_t msgIndex = 0; msgIndex < nFullMessagesToRead; msgIndex++ ) {
280 gdpbv100::FullMessage mess( messageBuffer[ 4 + 2 * msgIndex ], messageBuffer[ 4 + 2 * msgIndex + 1 ] );
284 LOG_DEBUG << std::hex << messageBuffer[ 4 + 2 * msgIndex ] <<
" " << messageBuffer[ 4 + 2 * msgIndex + 1 ] << std::dec << endm;
285 mess.PrintMessage( gdpb::msg_print_Prefix | gdpb::msg_print_Data );
290 fillETofDigi( mess );
295 triggerMessages.push_back( mess );
300 if( mess.getGdpbSysSubType() != 3 )
continue;
302 int patternType = mess.getGdpbSysPattType();
303 int patternIndex = mess.getGdpbSysPattIndex();
304 int pattern = mess.getGdpbSysPattPattern();
306 int rocId = mess.getGdpbGenGdpbId();
308 mHwMap->mapToSector( rocId, sector );
311 if( patternType != 3 )
continue;
313 int nBits = ( 7 == patternIndex ? 16 : 32 );
317 for(
int bit = 0; bit < nBits; ++bit ) {
318 if( ( pattern >> bit ) & 0x1 ) {
320 int get4Id = 32 * patternIndex + bit;
321 if ( mGet4ActiveMap.count( 10*get4Id ) ){
322 std::vector< unsigned int > geomVec;
323 mHwMap->mapToGeom( rocId, get4Id, 0, geomVec );
325 LOG_INFO <<
" "<< sector << endm;
326 LOG_INFO <<
"-----------------------------"<< sector << endm;
327 LOG_INFO <<
"FOUND ACTIVE PATTERN! Sector: "<< sector << endm;
328 LOG_INFO <<
"-----------------------------"<< sector << endm;
329 LOG_INFO <<
" "<< sector << endm;
331 if( geomVec.size() < 5 ) {
332 LOG_WARN <<
"geometry vector has wrong size !!! --> skip message. size: "<< geomVec.size() << endm;
336 unsigned int zplane = geomVec.at( 1 );
337 unsigned int counter = geomVec.at( 2 );
338 unsigned int strip = geomVec.at( 3 );
339 unsigned int side = geomVec.at( 4 );
341 mMissMatchFlagVec.at( 144 * ( sector - 13 ) + 48 * ( zplane -1 ) + 16 * ( counter - 1 ) + 8 * ( side - 1 ) + ( ( strip - 1 ) / 4 ) ) =
true;
343 LOG_DEBUG <<
"Wrongly mapped get4 chip in message pattern --> skip message. ID: "<< get4Id << endm;
351 fillETofHeader( messageBuffer, triggerMessages );
364 map< unsigned int, uint64_t >& gdpbTsMap,
365 map< unsigned int, uint64_t >& starTsMap )
368 LOG_DEBUG <<
"StETofDigiMaker::convertTriggerMessages() - do the conversion... " << endm;
370 size_t nTriggerMessages = triggerMessages.size();
372 LOG_INFO <<
"StETofDigiMaker::convertTriggerMessages() - size of triggerMessage vector: " << nTriggerMessages << endm;
375 if( nTriggerMessages % 4 != 0 ) {
376 LOG_WARN <<
"number of trigger messages does not match expectations --> skip conversion " << endm;
380 array< int, 4 > messageTypesTemplate = { 0, 1, 2, 3 };
382 for(
unsigned int i=0; i<nTriggerMessages; i+=4 ) {
384 array< int, 4 > messageTypes;
385 messageTypes.at( 0 ) = triggerMessages.at( i ).getStarTrigMsgIndex();
386 messageTypes.at( 1 ) = triggerMessages.at( i+1 ).getStarTrigMsgIndex();
387 messageTypes.at( 2 ) = triggerMessages.at( i+2 ).getStarTrigMsgIndex();
388 messageTypes.at( 3 ) = triggerMessages.at( i+3 ).getStarTrigMsgIndex();
390 array< int, 4 > rocIds;
391 rocIds.at( 0 ) = triggerMessages.at( i ).getGdpbGenGdpbId();
392 rocIds.at( 1 ) = triggerMessages.at( i+1 ).getGdpbGenGdpbId();
393 rocIds.at( 2 ) = triggerMessages.at( i+2 ).getGdpbGenGdpbId();
394 rocIds.at( 3 ) = triggerMessages.at( i+3 ).getGdpbGenGdpbId();
396 if( !std::all_of( rocIds.begin(), rocIds.end(), [ rocIds ](
int i ) {
return i == rocIds[ 0 ]; } ) ||
397 messageTypes != messageTypesTemplate )
399 LOG_WARN <<
"Roc Id miss match --> skip conversion " << endm;
405 uint64_t gdpbTsMsb = triggerMessages.at( i ).getGdpbTsMsbStarA();
406 uint64_t gdpbTsLsb = triggerMessages.at( i+1 ).getGdpbTsLsbStarB();
407 uint64_t starTsMsb = triggerMessages.at( i+1 ).getStarTsMsbStarB();
408 uint64_t starTsMid = triggerMessages.at( i+2 ).getStarTsMidStarC();
410 uint64_t rocGdpbTs = ( gdpbTsMsb << 24 )
413 uint64_t rocStarTs = ( starTsMsb << 48 )
415 + triggerMessages.at( i+3 ).getStarTsLsbStarD();
421 gdpbTsMap[ rocIds.at( 0 ) ] = rocGdpbTs;
422 starTsMap[ rocIds.at( 0 ) ] = rocStarTs;
428 StETofDigiMaker::fillETofHeader( uint64_t* messageBuffer, vector< gdpbv100::FullMessage >& triggerMessages )
430 uint64_t trgGdpbFullTs = messageBuffer[ 0 ];
431 uint64_t trgStarFullTs = messageBuffer[ 1 ];
432 unsigned int starToken = ( messageBuffer[ 2 ] >> 32 ) & 0xFFF;
433 unsigned int starDaqCmdIn = ( messageBuffer[ 2 ] >> 16 ) & 0x00F;
434 unsigned int starTrigCmdIn = ( messageBuffer[ 2 ] ) & 0x00F;
435 uint64_t eventStatusFlag = messageBuffer[ 3 ];
438 LOG_INFO <<
"StETofDigiMaker::fillETofHeader(): " <<
" ";
439 LOG_INFO <<
"trgGdpbFullTs=" << trgGdpbFullTs <<
" ";
440 LOG_INFO <<
"trgStarFullTs=" << trgStarFullTs << endm;
441 LOG_DEBUG <<
"starToken=" << starToken <<
" ";
442 LOG_DEBUG <<
"starDaqCmdIn=" << starDaqCmdIn <<
" ";
443 LOG_DEBUG <<
"starTrigCmdIn=" << starTrigCmdIn << endm;
444 LOG_DEBUG <<
"eventStatusFlag=" << eventStatusFlag << endm;
447 map< unsigned int, uint64_t > gdpbTsMap;
448 map< unsigned int, uint64_t > starTsMap;
453 for(
const auto& kv : gdpbTsMap ) {
454 LOG_DEBUG <<
"GdpbTs( 0x" << std::hex << kv.first << std::dec <<
" ): " << kv.second << endm;
456 for(
const auto& kv : starTsMap ) {
457 LOG_DEBUG <<
"StarTs( 0x" << std::hex << kv.first << std::dec <<
" ): " << kv.second << endm;
463 trgStarFullTs * gdpbv100::kdClockCycleSizeNs,
473 mETofCollection->setHeader( etofHeader );
481 mETofCollection->addDigi(
new StETofDigi( mess.getGdpbGenGdpbId(),
482 mess.getGdpbGenChipId(),
483 mess.getGdpbHitChanId(),
484 mess.GetFullTimeNs(),
485 ( double ) mess.getGdpbHit32Tot() + 0.5 ) );
496 LOG_DEBUG <<
"StETofDigiMaker::fillEvent() starting..." << endm;
499 if( !mETofCollection ) {
500 LOG_WARN <<
"StETofDigiMaker::fillEvent() - no ETofCollection ... creating one in StEvent" << endm;
502 mEvent->setETofCollection( mETofCollection );
507 if( etofCollection ) {
508 if( etofCollection->digisPresent() ) {
509 StSPtrVecETofDigi& eTofDigiVec = etofCollection->etofDigis();
510 LOG_INFO <<
"StETofDigiMaker::fillEvent() - StETofCollection has " << eTofDigiVec.size() <<
" digis" << endm;
512 for(
size_t i=0; i<eTofDigiVec.size(); i++ ) {
513 LOG_INFO << ( *eTofDigiVec[ i ] ) << endm;
518 LOG_INFO <<
"StETofDigiMaker::fillEvent() - no digis in the StETofCollection" << endm;
522 LOG_WARN <<
"StETofDigiMaker::fillEvent() - no StETofCollection" << endm;
539 vector< gdpb::FullMessage > triggerMessages;
542 for(
size_t msgIndex = 0; msgIndex < nFullMessagesToRead; msgIndex++ ) {
544 gdpb::FullMessage mess( messageBuffer[ 4 + 2 * msgIndex ], messageBuffer[ 4 + 2 * msgIndex + 1 ] );
548 LOG_DEBUG << std::hex << messageBuffer[ 4 + 2 * msgIndex ] <<
" " << messageBuffer[ 4 + 2 * msgIndex + 1 ] << std::dec << endm;
549 mess.PrintMessage( gdpb::msg_print_Prefix | gdpb::msg_print_Data );
554 fillETofDigi( mess );
559 triggerMessages.push_back( mess );
565 fillETofHeader( messageBuffer, triggerMessages );
578 map< unsigned int, uint64_t >& gdpbTsMap,
579 map< unsigned int, uint64_t >& starTsMap )
582 LOG_DEBUG <<
"StETofDigiMaker::convertTriggerMessages() - do the conversion... " << endm;
584 size_t nTriggerMessages = triggerMessages.size();
586 LOG_INFO <<
"StETofDigiMaker::convertTriggerMessages() - size of triggerMessage vector: " << nTriggerMessages << endm;
589 if( nTriggerMessages % 4 != 0 ) {
590 LOG_WARN <<
"number of trigger messages does not match expectations --> skip conversion " << endm;
594 for(
unsigned int i=0; i<nTriggerMessages; i+=4 ) {
595 array< int, 4 > rocIds;
596 rocIds.at( 0 ) = triggerMessages.at( i ).getRocNumber();
597 rocIds.at( 1 ) = triggerMessages.at( i+1 ).getRocNumber();
598 rocIds.at( 2 ) = triggerMessages.at( i+2 ).getRocNumber();
599 rocIds.at( 3 ) = triggerMessages.at( i+3 ).getRocNumber();
602 if( !std::all_of( rocIds.begin(), rocIds.end(), [ rocIds ](
int i ) {
return i == rocIds[ 0 ]; } ) ) {
603 LOG_WARN <<
"Roc Id miss match --> skip conversion " << endm;
609 uint64_t gdpbTsMsb = triggerMessages.at( i ).getGdpbTsMsbStarA();
610 uint64_t gdpbTsLsb = triggerMessages.at( i+1 ).getGdpbTsLsbStarB();
611 uint64_t starTsMsb = triggerMessages.at( i+1 ).getStarTsMsbStarB();
612 uint64_t starTsMid = triggerMessages.at( i+2 ).getStarTsMidStarC();
614 uint64_t rocGdpbTs = ( gdpbTsMsb << 24 )
617 uint64_t rocStarTs = ( starTsMsb << 48 )
619 + triggerMessages.at( i+3 ).getStarTsLsbStarD();
625 gdpbTsMap[ rocIds.at( 0 ) ] = rocGdpbTs;
626 starTsMap[ rocIds.at( 0 ) ] = rocStarTs;
632 StETofDigiMaker::fillETofHeader( uint64_t* messageBuffer, vector< gdpb::FullMessage >& triggerMessages )
634 uint64_t trgGdpbFullTs = messageBuffer[ 0 ];
635 uint64_t trgStarFullTs = messageBuffer[ 1 ];
636 unsigned int starToken = ( messageBuffer[ 2 ] >> 32 ) & 0xFFF;
637 unsigned int starDaqCmdIn = ( messageBuffer[ 2 ] >> 16 ) & 0x00F;
638 unsigned int starTrigCmdIn = ( messageBuffer[ 2 ] ) & 0x00F;
639 uint64_t eventStatusFlag = messageBuffer[ 3 ];
642 LOG_DEBUG <<
"StETofDigiMaker::fillETofHeader()" << endm;
643 LOG_DEBUG <<
"trgGdpbFullTs=" << trgGdpbFullTs << endm;
644 LOG_DEBUG <<
"trgStarFullTs=" << trgStarFullTs << endm;
645 LOG_DEBUG <<
"starToken=" << starToken << endm;
646 LOG_DEBUG <<
"starDaqCmdIn=" << starDaqCmdIn << endm;
647 LOG_DEBUG <<
"starTrigCmdIn=" << starTrigCmdIn << endm;
648 LOG_DEBUG <<
"eventStatusFlag=" << eventStatusFlag << endm;
650 map< unsigned int, uint64_t > gdpbTsMap;
651 map< unsigned int, uint64_t > starTsMap;
656 for(
const auto& kv : gdpbTsMap ) {
657 LOG_DEBUG <<
"GdpbTs( 0x" << std::hex << kv.first << std::dec <<
" ): " << kv.second << endm;
659 for(
const auto& kv : starTsMap ) {
660 LOG_DEBUG <<
"StarTs( 0x" << std::hex << kv.first << std::dec <<
" ): " << kv.second << endm;
666 static_cast< double > ( trgStarFullTs ),
675 mETofCollection->setHeader( etofHeader );
684 mess.getGdpbGenChipId(),
685 mess.getGdpbHitChanId(),
686 mess.GetFullTimeNs(),
687 ( double ) mess.getGdpbHit32Tot() + 0.5 ) );
bool isSysMsg() const
Returns true is message type is #MSG_SYST (system message)
bool isStarTrigger() const
Returns true is message type is #MSG_STAR_TRI_A, _B, _C, _D (STAR Trigger message) ...
Class StRTSBaseMaker - is an abstract StMaker to define the interface to access the DAQ data from the...
uint16_t getRocNumber() const
Returns the number of the sending ROC. Valid for all message types.
void processEvent(uint64_t *messageBuffer, size_t nFullMessagesToRead)
bool isGet4Hit32Msg() const
Returns true is message type is #MSG_GET4_32B (GET4 Hit Data in 32b mode)
virtual StRtsTable * GetNextRaw()
This is an overloaded member function, provided for convenience.
void convertTriggerMessages(vector< gdpbv100::FullMessage > &triggerMessages, map< unsigned int, uint64_t > &gdpbTs, map< unsigned int, uint64_t > &starTs)
StETofDigiMaker(const char *name="etofDigi")
Default constructor.
bool isStarTrigger() const
Returns true is message type is #MSG_STAR_TRI (STAR Trigger message)
StETofCollection * getETofCollection()
void processEvent2018(uint64_t *messageBuffer, size_t nFullMessagesToRead)
bool isHitMsg() const
Returns true is message type is #MSG_HIT (Get4 hit data)
virtual TDataSet * Find(const char *path) const