282 #include <sys/types.h>
283 #include <sys/stat.h>
286 #include "StMessMgr.h"
287 #include "StDAQReader.h"
289 #include "StDaqLib/GENERIC/EventReader.hh"
290 # include "RTS/src/DAQ_READER/daqReader.h"
292 #include "StDaqLib/RICH/RICH_Reader.hh"
293 #include "StDaqLib/L3/L3_Reader.hh"
294 #include "StDaqLib/TOF/TOF_Reader.hh"
295 #include "StDaqLib/FPD/FPD_Reader.hh"
297 #include "StTPCReader.h"
298 #include "StEMCReader.h"
299 #include "StSSDReader.h"
300 #include "StEEMCReader.h"
301 #include "StPMDReader.h"
302 #include "StFTPCReader.h"
303 #include "StTRGReader.h"
304 #include "StSVTReader.h"
305 #include "StMessMgr.h"
307 #include "StRtsReaderMaker.h"
308 #include "StStreamFileFactory.h"
309 #include "StStreamFile.h"
346 if(file && file[0]) open(file);
350 int StDAQReader::open(
const char *file)
354 if (StStreamFileFactory::Factory()) {
356 const char *dat_ext=
".dat";
357 LOG_INFO <<
" StDAQReader::open(const char *file): " << file <<
" - "
358 << (
const char*)&file[strlen(file)-
sizeof(dat_ext)]
359 <<
" len=" << strlen(file)
360 <<
" size=" <<
sizeof(dat_ext)
361 << fDatFileReader << endm;
362 if (TString(dat_ext) == (
const char*)&file[strlen(file)-
sizeof(dat_ext)] && !fDatFileReader) {
363 fDatFileReader = StStreamFileFactory::Factory()->Create();
364 fRtsMaker->SetDatReader(fDatFileReader);
367 if (fDatFileReader) {
368 fDatFileReader->open(file);
370 if (fDaqFileReader) close();
371 fDaqFileReader =
new daqReader((
char *)file);
372 fRtsMaker->SetDaqReader(fDaqFileReader);
374 LOG_INFO <<
"StDAQReader::open the DAQ " << file <<
" via "
375 << (fDatFileReader ?
"DAT reader ->" :
"" ) << fDatFileReader
376 << (fDaqFileReader ?
"daqReader ->" :
"") << fDaqFileReader
382 void StDAQReader::clear()
384 delete fEventReader; fEventReader = 0;
387 int StDAQReader::close()
389 if (fDaqFileReader ) {
390 delete fDaqFileReader;
392 }
else if (fDatFileReader) {
393 fDatFileReader->close();
396 fRtsMaker->SetDaqReader(0);
398 delete fEventReader; fEventReader = 0;
400 if(fTPCReader) fTPCReader ->close();
401 if(fSSDReader) fSSDReader ->close();
402 if(fEMCReader) fEMCReader ->close();
403 if(fEEMCReader) fEEMCReader->close();
404 if(fPMDReader) fPMDReader ->close();
405 if(fSVTReader) fSVTReader ->close();
407 if(fFTPCReader) fFTPCReader->close();
408 if(fTRGReader) fTRGReader ->close();
409 delete fL3Reader; fL3Reader = 0;
414 StDAQReader::~StDAQReader()
416 if (m_ZeroTokens > 1){
417 LOG_WARN << m_ZeroTokens <<
" events with token==0" << endm;
422 delete fDatFileReader; fDatFileReader=0;
430 char *currentData = fDaqFileReader->get(0,EVP_TYPE_ANY);
431 LOG_DEBUG <<
" StEvpReader::NextEvent - data = "
432 << (
void *)currentData <<
" :: " << fDaqFileReader
433 <<
" status " << fDaqFileReader->status <<
" EVP_STAT_OK=" << EVP_STAT_OK
434 <<
" token " << fDaqFileReader->token
439 if(currentData && (fDaqFileReader->status == EVP_STAT_OK) ) {
445 switch(fDaqFileReader->status) {
447 if(fDaqFileReader->IsEvp()) {
448 LOG_FATAL <<
"StEvpReader::NextEvent - waiting event" << endm;
451 LOG_DEBUG <<
"StEvpReader::NextEvent - End Of File" << endm;
455 LOG_ERROR <<
"Problem getting event - skipping" << endm;
459 LOG_ERROR <<
"Critical error - halting..." << endm;
463 LOG_FATAL <<
"Unknow DAQ file I/O problem " << endm;
466 fEventStatus = fDaqFileReader->status;
469 int StDAQReader::Make()
471 int ret = readEvent();
472 if (fRtsMaker) fRtsMaker->
Make();
476 int StDAQReader::readEvent()
478 int retStatus =
kStOk;
480 if (fDatFileReader) {
481 fDatFileReader->Read();
482 if (!fDatFileReader->good()) {
485 if (fDatFileReader->eof() ) retStatus =
kStEOF;
487 }
else if (fDaqFileReader) {
489 if (fOffset == -1) retStatus =
kStEOF;
492 delete fEventReader; fEventReader=0;
493 delete fRICHReader; fRICHReader = 0;
494 delete fL3Reader; fL3Reader = 0;
495 delete fTOFReader; fTOFReader = 0;
496 delete fFPDReader; fFPDReader = 0;
497 if (retStatus ==
kStOk) {
499 fEventReader->setVerbose(fVerbose);
501 fEventReader->setDaqReader(fDaqFileReader);
502 if (fDaqFileReader) {
503 if (fDaqFileReader->mem) {
511 fDATAP = (
char *)realloc(fDATAP, fDaqFileReader->bytes);
512 memcpy(fDATAP,fDaqFileReader->mem, fDaqFileReader->bytes);
514 fDaqFileReader->fixDatapSummary((
DATAP*)fDATAP);
516 fDATAP = (
char *)realloc(fDATAP, fDaqFileReader->bytes_mapped);
517 memcpy(fDATAP,fDaqFileReader->mem, fDaqFileReader->bytes_mapped);
519 fEventReader->InitEventReader(fDATAP);
520 *fEventInfo = fEventReader->getEventInfo();
521 if(fEventInfo->Token==0){
523 Form(
"StDAQReader::readEvent: found event with token==0") << endm;
528 else if(fDaqFileReader && fDaqFileReader->token==0){
530 Form(
"StDAQReader::readEvent: found event with token==0") << endm;
533 if (fTPCReader && TPCPresent() ) fTPCReader ->Update();
534 if (fFTPCReader && FTPCPresent()) fFTPCReader->Update();
535 if (fTRGReader && TRGPresent() ) {
536 fTRGReader ->Update();
537 if ( ! fTRGReader->thereIsTriggerData() ){
539 Form(
"StDAQReader::readEvent: No or bad TRG data - Skipping event: ")
540 << getRunNumber() <<
" : " <<getEventNumber()<< endm;
544 if (fSVTReader && SVTPresent() ) fSVTReader ->Update();
545 if (fSSDReader && SSDPresent() ) fSSDReader ->Update();
546 if (fEMCReader && EMCPresent() ) fEMCReader ->Update();
547 if (fEEMCReader && EMCPresent() ) fEEMCReader->Update();
548 if (fPMDReader && PMDPresent() ) fPMDReader ->Update();
552 for(i=0;i<2;i++) fTrigSummary->L1summary[i]=fDaqFileReader->L1summary[i];
553 for(i=0;i<2;i++) fTrigSummary->L2summary[i]=fDaqFileReader->L2summary[i];
554 for(i=0;i<4;i++) fTrigSummary->L3summary[i]=fDaqFileReader->L3summary[i];
559 int StDAQReader::skipEvent(
int nskip)
564 char *currentData = 0;
565 if (nskip == 2) currentData = fDaqFileReader->get(0,EVP_TYPE_ANY);
566 else currentData = fDaqFileReader->skip_then_get(nskip-2,0,EVP_TYPE_ANY);
568 if(currentData && (fDaqFileReader->status == EVP_STAT_OK) ) {
576 LOG_WARN << Form(
"EOF with skipEvent(%d)",nskip)<< endm;
583 void StDAQReader::setTPCVersion(
const char* vers)
584 {strcpy(fTPCVersion,vers);}
586 void StDAQReader::setFTPCVersion(
const char* vers)
587 {strcpy(fFTPCVersion,vers);}
590 int StDAQReader::getRunNumber()
const
596 runNum = fDatFileReader->RunNumber();
597 else if (fDaqFileReader )
598 runNum = fDaqFileReader->run;
600 runNum = fEventReader->runno();
604 int StDAQReader::getEventNumber()
const {
605 return fDaqFileReader ?
608 fEventInfo->EventSeqNo;
611 unsigned int StDAQReader::getUnixTime()
const
615 unixTime = fDatFileReader->RecordUnixTime();
616 else if (fDaqFileReader )
617 unixTime = fDaqFileReader->evt_time;
619 unixTime = fEventInfo->UnixTime;
624 unsigned int StDAQReader::getTrigWord()
const {
625 return fDaqFileReader ?
626 fDaqFileReader->trgword
628 fEventInfo->TrigWord;
631 unsigned int StDAQReader::getTrigInputWord()
const {
return fEventInfo->TrigInputWord;}
633 int StDAQReader::TPCPresent()
const {
return fEventInfo->TPCPresent;}
635 int StDAQReader::SVTPresent()
const {
return fEventInfo->SVTPresent;}
637 int StDAQReader::TOFPresent()
const {
return fEventInfo->TOFPresent;}
639 int StDAQReader::FPDPresent()
const {
return fEventInfo->FPDPresent;}
641 int StDAQReader::SSDPresent()
const {
return fEventInfo->SSDPresent;}
643 int StDAQReader::EMCPresent()
const {
return fEventInfo->EMCPresent;}
645 int StDAQReader::PMDPresent()
const {
return fEventInfo->PMDPresent;}
647 int StDAQReader::SMDPresent()
const {
return fEventInfo->BSMDPresent|fEventInfo->ESMDPresent;}
649 int StDAQReader::FTPCPresent()
const {
return fEventInfo->FTPCPresent;}
651 int StDAQReader::RICHPresent()
const {
return fEventInfo->RICHPresent;}
653 int StDAQReader::TRGPresent()
const {
return ( fEventInfo && fEventInfo->TRGPresent) || (fDatFileReader && StTRGReader::OldFormat(fDatFileReader->Version()));}
655 int StDAQReader::L3Present()
const {
return fEventInfo->L3Present;}
657 int StDAQReader::getEventSize()
const
661 eventSize = fDatFileReader->Length();
663 eventSize = fEventInfo->EventLength;
667 StTPCReader *StDAQReader::getTPCReader(
char mergeSequences)
670 if(!TPCPresent())
return 0;
673 updateStatus=fTPCReader->Update();
674 if(updateStatus) {
delete fTPCReader; fTPCReader=0;
return 0; }
689 if (!EMCPresent())
return 0;
698 if (!SSDPresent())
return 0;
707 if (!PMDPresent())
return 0;
717 if (!RICHPresent())
return 0;
719 fRICHReader = ::getRICHReader(fEventReader);
720 if (!fRICHReader) fEventInfo->RICHPresent=0;
728 if (!L3Present())
return 0;
730 fL3Reader = ::getL3Reader(fEventReader);
731 if (!fL3Reader) fEventInfo->L3Present=0;
738 if (!FTPCPresent())
return 0;
741 fFTPCReader->Update();
748 if (!TOFPresent())
return 0;
750 fTOFReader = ::getTOFReader(fEventReader);
751 if(!fTOFReader) fEventInfo->TOFPresent=0;
758 if (!FPDPresent())
return 0;
760 fFPDReader = ::getFPDReader(fEventReader);
761 if (!fFPDReader) fEventInfo->FPDPresent=0;
768 if (!TRGPresent())
return 0;
778 if (!SVTPresent())
return 0;
781 fSVTReader->Update();
787 void StDAQReader::printEventInfo()
788 {fEventReader->printEventInfo();}
void nextEvent()
NextEvent - this method is called to advance the next daq event if any.