#include "PndOnlineManager.h" #include "PndSttHit.h" #include "PndGeoSttPar.h" #include "PndSttMapCreator.h" static bool online_hit_ordering(PndOnlineTrackHit *hit1, PndOnlineTrackHit *hit2) { return (hit1->BaseHit()->GetTimeStamp() < hit2->BaseHit()->GetTimeStamp()); } void PndOnlineManager::Clear() { ClearHits(); ClearTracks(); ClearEvents(); //hits.clear(); //tracks.clear(); //events.clear(); // go through other mappings and clear them } void PndOnlineManager::Process() { // should this be here?? /* if(is_end_of_revolution) { master->Clear(); Clear(); is_end_of_revolution = false; revolution_start_time += kHESRRevolution; } */ master->ExecuteTask(); if(is_end_of_revolution && outputTask) outputTask->ExecuteTask(); } void PndOnlineManager::LoadStream(int detector_id, char *branch_name, int timeout_length) { // debug info cout << "registering detector number " << detector_id << " with branch name " << branch_name << endl; input_branches.insert( pair< int, TString >(detector_id, TString(branch_name)) ); SetActiveDetector(detector_id, timeout_length); } void PndOnlineManager::LoadHits(double delta_t) { cout << "In PndOnlineManager::LoadHits()..." << endl; cout << " rev. start time = " << revolution_start_time << " rev. length = " << kHESRRevolution << endl; cout << " current time = " << GetCurrentTime() << " delta_t = " << delta_t << endl; cout << " number of detectors = " << active_detectors.size() << endl; cout << " is end of revolution? = " << is_end_of_revolution << endl; if(is_end_of_revolution) { master->Clear(); Clear(); is_end_of_revolution = false; revolution_start_time += kHESRRevolution; //cerr << "AM INCREMENTING REVOLUTION!!" << endl; } //cerr << "REVOLUTION START TIME = " << revolution_start_time << endl; if(delta_t < 0) // the functor interface to the sorted hits only reads forward in time, going backwards makes no sense return; // stop loading when we hit the end of a HESR revolution //if( GetCurrentTime()+delta_t > revolution_start_time + PndOnline::kHESRRevolution ) { //delta_t = revolution_start_time + PndOnline::kHESRRevolution - GetCurrentTime(); //} /**/ if( simulate_hesr_beam_structure ) { if( GetCurrentTime()+delta_t >= revolution_start_time + kHESRRevolution ) { delta_t = revolution_start_time + kHESRRevolution - GetCurrentTime(); is_end_of_revolution = true; //revolution_start_time += kHESRRevolution; cout << "corrected delta t = " << delta_t << " and rev. start = " << revolution_start_time << endl; } } /**/ double new_time = GetCurrentTime() + delta_t; // first clear out the old hits RemoveOldHits(new_time); //TClonesArray *new_hits = NULL; // load tracking hits for(int the_detector=0; the_detector *the_hits = hitProducer->GetHits(active_detectors[the_detector], delta_t); //cout << " number of hits = " << the_hits->size() << endl; TClonesArray *new_hits = FairRootManager::Instance()->GetData(input_branches[active_detectors[the_detector]].Data(), stop_time_functor, new_time); cout << " number of hits = " << new_hits->GetEntriesFast() << endl; //for(list::iterator it=the_hits->begin(); //it!=the_hits->end(); ++it) { //FairHit *newhit = (FairHit*)(*it); for(int i=0; iGetEntriesFast(); ++i) { FairHit *newhit = (FairHit*)(new_hits->At(i)); //cout << " check hit timestamp = " << newhit->GetTimeStamp() << endl; PndOnlineTrackHit *newonlinehit = new PndOnlineTrackHit(active_detectors[the_detector], newhit); //shared_ptr newonlinehit = make_shared(active_detectors[the_detector], newhit); AddHit(active_detectors[the_detector], newonlinehit); // handle cases in which we have alternate mappings, i.e. to the geometry if(active_detectors[the_detector] == PndOnline::kSTT) { PndSttHit *newstthit = (PndSttHit *)(newhit); int channel_num = newstthit->GetTubeID(); //cout << " loading hit ID " << channel_num // << " with timestamp " << newstthit->GetTimeStamp() << endl; hit_channel_map[PndOnline::kSTT][channel_num].push_back(newonlinehit); //// ?????? } } new_hits->Clear(); //delete the_hits; } // update time stamp AdvanceCurrentTime(delta_t); // sort the hits, since we can get hits from multiple detectors hits.sort(online_hit_ordering); } void PndOnlineManager::RemoveOldHits(double new_current_time) { cout << "In PndOnlineManager::RemoveOldHits()..." << endl; cout << " checking " << hits.size() << " hits... " << endl; //for(list::iterator it=hits.begin(); //it!=hits.end(); ++it) { list::iterator it=hits.begin(); while(it != hits.end()) { int the_detector = (*it)->BaseDetector(); double timeout_time = detector_timeouts[ the_detector ]; bool erase_hit = false; // a timeout of 0 means to not timeout at all - this should only be used during testing, though if(timeout_time > 0) { PndOnlineTrackHit *the_onlinehit = *it; FairHit *the_hit = (FairHit*)((*it)->BaseHit()); /* cerr << " checking time of hit = " << ((FairHit*)((*it)->BaseHit()))->GetTimeStamp() << " current time = " << new_current_time << " with delta_t = " << (new_current_time - (*it)->BaseHit()->GetTimeStamp()) << " against timeout time " << timeout_time << endl; */ if( (new_current_time - (*it)->BaseHit()->GetTimeStamp()) > timeout_time) { cout << " REMOVE HIT!" << endl; //cerr << " timestamp before = " << (*it)->BaseHit()->GetTimeStamp() << endl; //cerr << " timestamp before = " << the_hit->GetTimeStamp() << endl; // remove from other mappings as well // this is a little slow... can speed it up detector_hits[the_detector].remove(*it); //detector_hits[the_detector].erase(it); // remove from hit channel maps if(the_detector == PndOnline::kSTT) { PndSttHit *the_stthit = (PndSttHit *)(the_hit); int channel_num = the_stthit->GetTubeID(); hit_channel_map[the_detector][channel_num].remove(*it); //hit_channel_map[the_detector][channel_num].erase(it); } //cerr << " timestamp after = " << (*it)->BaseHit()->GetTimeStamp() << endl; //cerr << " timestamp after = " << the_hit->GetTimeStamp() << endl; // remove the hit from the main list //it = hits.erase(it); //hits.erase(it++); erase_hit = true; //cerr << " timestamp more after = " << the_hit->GetTimeStamp() << endl; // finally release the memory //delete the_onlinehit; } } if(erase_hit) it = hits.erase(it); else it++; } //check where hits are not removed for(list::iterator iter=hits.begin(); iter!=hits.end(); ++iter) { int the_detector = (*iter)->BaseDetector(); double timeout_time = detector_timeouts[ the_detector ]; if ((new_current_time - (*iter)->BaseHit()->GetTimeStamp()) > timeout_time) { cout << "Time Window Violation in storage: hits" << endl; } } for(list::iterator iter=detector_hits[PndOnline::kSTT].begin(); iter!=detector_hits[PndOnline::kSTT].end(); ++iter) { double timeout_time = detector_timeouts[ PndOnline::kSTT ]; if ((new_current_time - (*iter)->BaseHit()->GetTimeStamp()) > timeout_time) { cout << "Time Window Violation in storage: detector_hits" << endl; } } double timeout_time = detector_timeouts[ PndOnline::kSTT ]; for (int mychannel = 0; mychannel < hit_channel_map[PndOnline::kSTT].size(); mychannel++) { if (hit_channel_map[PndOnline::kSTT][mychannel].size() == 0) continue; for(list::iterator iter=hit_channel_map[PndOnline::kSTT][mychannel].begin(); iter!=hit_channel_map[PndOnline::kSTT][mychannel].end(); ++iter) { if ((new_current_time - (*iter)->BaseHit()->GetTimeStamp()) > timeout_time) { cout << "Time Window Violation in storage: hit_channel_map" << endl; } } } }