// ----------------------------------------------------------------------------- // ----- ----- // ----- CbmGet4EventDumper ----- // ----- Created 16.04.2015 by ----- // ----- P.-A. Loizeau ----- // ----- ----- // ----------------------------------------------------------------------------- #include "CbmGet4EventDumper.h" // TOF Classes and includes #include "CbmGet4EventBuffer.h" #include "CbmGet4v1xDef.h" #include "CbmGet4v1xHackDef.h" #include "TTofGet4Board.h" #include "TTofGet4Data.h" // CBMroot classes and includes // FAIR classes and includes //#include "FairRunOnline.h" //#include "FairEventHeader.h" #include "FairLogger.h" // ROOT Classes and includes #include "TH1.h" #include "TROOT.h" #include "TClonesArray.h" // C++ std headers //___________________________________________________________________ // // ------------------------------------------------------------------ CbmGet4EventDumper::CbmGet4EventDumper() : FairTask("CbmGet4EventDumper"), fuInputEvents(0), fuOutputEvents(0), fInputBuffer(NULL), fEvtHeader(NULL), fIOMan(NULL), fGet4BoardCollection(NULL), fuNbGet4(0), fvbActiveChips(), fuNbEvtBuffEmptyCall(0), fbWriteDataInCbmOut(kFALSE), fdMaxTimePerLoopS(0.0), fStart(), fStop() { LOG(INFO)<<" CbmGet4EventDumper: Task started"< Invalid chip index " << uChipsIndex < New loop"<GetSize() ) { // From FairRunOnline EventLoop method fIOMan->StoreWriteoutBufferData(fIOMan->GetEventTime()); iNbHitsDumped = this->ReadEvent(); fuOutputEvents ++; // Fill histos if needed FillHistos(); // From FairRunOnline EventLoop method fIOMan->Fill(); fIOMan->DeleteOldWriteoutBufferData(); } // if( 0 < fInputBuffer->GetSize() ) /* else if( kTRUE == fbWriteDataInCbmOut) LOG(INFO)<<" CbmGet4EventDumper => No event to dump in this execution loop\n" <<" => Empty event in output tree!" <GetSize() ) { iNbHitsDumped += this->ReadEventMore(); fuOutputEvents ++; // Fill histos if needed FillHistos(); if( 0 == ( fuOutputEvents%100000 ) && 0 < fuOutputEvents ) { LOG(INFO)<< "CbmGet4EventDumper::Exec : " << fuOutputEvents << " events dumped." << FairLogger::endl; } // if( 0 == ( fuOutputEvents%100 ) && 0 < fuOutputEvents ) // if total looping time larger than limit: stop looping for now // We can start on the backlog later fStop.Set(); Double_t dLooptTime = fStop.GetSec() - fStart.GetSec() + (fStop.GetNanoSec() - fStart.GetNanoSec())/1e9; if( fdMaxTimePerLoopS < dLooptTime ) break; } // while( fuNbEvtBuffEmptyCall < fInputBuffer->GetSize() ) // Update execution loop counter fuInputEvents++; } void CbmGet4EventDumper::Finish() { LOG(INFO)<<"CbmGet4EventDumper::Finish up with " << fuInputEvents << " loops done and " << fuOutputEvents << " events dumped" < (fIOMan->GetObject("EventHeader.")); if( NULL == fEvtHeader ) { LOG(WARNING)<<"CbmGet4EventDumper::RegisterOutputs: No event Header was found!!!" <Register( "TofGet4Tdc","TofUnpack",fGet4BoardCollection, fbWriteDataInCbmOut); } // if( 0 < fMbsUnpackPar->GetNbActiveBoards( tofMbs::get4 ) ) if(NULL == fGet4BoardCollection) { LOG(ERROR)<<"CbmGet4EventDumper::RegisterOutputs: no TOF GET4 TDC array created! "<Clear("C"); return kTRUE; } /************************************************************************************/ Int_t CbmGet4EventDumper::ReadEvent() { Int_t iNbHitsDumped = 0; // Clear storage ClearOutput(); // First obtain a pointer on an input event std::pair< CbmGet4EventHeader, std::vector< get4v1x::FullMessage >* > pvEvent = fInputBuffer->GetNextEvent(); /* * Missing: * 1) Trigger time in Event buffer => Done * 2) Trigger type and trigger epoch in output event => needed? * */ // Initialize all board objects std::vector vGet4Board; vGet4Board.resize( fuNbGet4, NULL ); for( UInt_t uGet4 = 0; uGet4 < fuNbGet4; uGet4++ ) { vGet4Board[uGet4] = dynamic_cast ( fGet4BoardCollection->ConstructedAt(uGet4) ); vGet4Board[uGet4]->SetTriggerFullTime( ( ( (pvEvent.first).fuTriggerExtEp ) & 0xFFFFFFFF ) *get4v1x::kdEpochInPs + (pvEvent.first).fuTriggerTs *get4v1x::kdClockCycleSize ); // in ps vGet4Board[uGet4]->SetTriggerTime( (pvEvent.first).fuTriggerTs ); // in clock cycles // This class uses unsigned integer => remapped trigger index // < -256: unknown trigger => 512 // -256 to -1: multiplicity triggers => 256 to 511 // 0 < : usual coincidence trigger => 0 to 255, hope nobody implement more than that vGet4Board[uGet4]->SetTriggIndx( 0 <= (pvEvent.first).fiTriggerType? static_cast( (pvEvent.first).fiTriggerType ) : -256 < (pvEvent.first).fiTriggerType? static_cast( 512 + (pvEvent.first).fiTriggerType ) : 512 ); } // for( UInt_t uGet4 = 0; uGet4 < fuNbGet4; uGet4++ ) // Do stuff with our hits for( UInt_t uHit = 0; uHit < (pvEvent.second)->size(); uHit++ ) { get4v1x::FullMessage mess = (pvEvent.second)->at(uHit); uint8_t cRocId = mess.getRocNumber(); uint8_t cChipId = mess.getGet4V10R32ChipId(); uint32_t uChipFullId = cChipId + get4v1x::kuMaxGet4PerRoc*cRocId; TTofGet4Data data( mess.getGet4V10R32HitChan(), mess.getGet4V10R32HitFt(), mess.getGet4V10R32HitTs(), mess.getMsgFullTime( mess.getExtendedEpoch() & 0xFFFFFFFF ), mess.getMsgFullTimeD( mess.getExtendedEpoch() & 0xFFFFFFFF ), ( mess.getExtendedEpoch() & 0xFFFFFFFF ), ( ( mess.getExtendedEpoch() >> 32 ) & 0xFFFFFFFF ), mess.getGet4V10R32HitTot(), kTRUE ); vGet4Board[ uChipFullId ]->AddData( data ); } // for( Int_t iHit = 0; iHit < (pvEvent.second)->size(); iHit++ ) vGet4Board.clear(); /* TTofGet4Board * Get4Board = (TTofGet4Board*) fGet4BoardCollection->ConstructedAt(uGet4); // Get4Board->SetTriggerFullTime (not needed?) // Get4Board->SetTriggerTime // Get4Board->SetTriggIndx // Get4Board->SetValid // Get4Board->AddData // TTofGet4Data( UInt_t uChan, UInt_t uFt, // UInt_t uCoarseT, // ULong64_t uFulltime = 0, Double_t dFullTime = 0.0, // UInt_t uGet4Epoch = 0, UInt_t uGet4EpCycle = 0, // UInt_t uTot = 0, Bool_t bIs32Bit = kFALSE ); */ // Now clear the input event object and delete it if( 0 < (pvEvent.second)->size() ) (pvEvent.second)->clear(); delete (pvEvent.second); return iNbHitsDumped; } // ------------------------------------------------------------------ Int_t CbmGet4EventDumper::ReadEventMore() { Int_t iNbHitsDumped = 0; // From FairRunOnline EventLoop method fIOMan->StoreWriteoutBufferData(fIOMan->GetEventTime()); iNbHitsDumped = this->ReadEvent(); // From FairRunOnline EventLoop method fIOMan->Fill(); fIOMan->DeleteOldWriteoutBufferData(); return iNbHitsDumped; } /************************************************************************************/ // ------------------------------------------------------------------ Bool_t CbmGet4EventDumper::CreateHistos() { // Create histogramms TDirectory * oldir = gDirectory; // <= To prevent histos from being sucked in by the param file of the TRootManager! gROOT->cd(); // <= To prevent histos from being sucked in by the param file of the TRootManager ! gDirectory->cd( oldir->GetPath() ); // <= To prevent histos from being sucked in by the param file of the TRootManager! return kTRUE; } // ------------------------------------------------------------------ Bool_t CbmGet4EventDumper::FillHistos() { return kTRUE; } // ------------------------------------------------------------------ Bool_t CbmGet4EventDumper::WriteHistos() { /* // Write histogramms to the file TDirectory * oldir = gDirectory; TFile *fHist = new TFile("./get4EventDumper.hst.root","RECREATE"); fHist->cd(); fhMaxMulPerEpochDist->Write(); fHist->Close(); */ return kTRUE; } Bool_t CbmGet4EventDumper::DeleteHistos() { return kTRUE; } ClassImp(CbmGet4EventDumper)