// $Id: IEventFolder.cxx,v 1.8 2011/05/18 11:35:12 mcgrew Exp $ // // Implement an type of folder specifically for holding TEvents. #include #include #include #include #include #include #include "ICOMETEvent.hxx" #include "IEventFolder.hxx" #include "ICOMETLog.hxx" COMET::IEventFolder* COMET::IEventFolder::fEventFolder = NULL; COMET::ICOMETEvent* COMET::IEventFolder::fCurrentEvent = NULL; COMET::IEventFolder::IEventFolder() { fFolderOfEvents = NULL; } COMET::IEventFolder::~IEventFolder() { fFolderOfEvents = NULL; fEventFolder = NULL; fCurrentEvent = NULL; } TFolder* COMET::IEventFolder::GetFolder(void) const { if (!fFolderOfEvents) return NULL; return fFolderOfEvents; } COMET::IEventFolder* COMET::IEventFolder::GetEventFolder(void) { if (!fEventFolder) { fEventFolder = new COMET::IEventFolder(); } if (!fEventFolder->fFolderOfEvents) { fEventFolder->fFolderOfEvents = gROOT->GetRootFolder()->AddFolder("Events","COMET Events"); gROOT->GetListOfBrowsables()->Add(fEventFolder->fFolderOfEvents, "Events"); gROOT->GetListOfCleanups()->Add(fEventFolder->fFolderOfEvents); } #define CONNECT_SLOT #ifdef CONNECT_SLOT TQObject::Connect("TEvent","Selected(COMET::IDatum*)", "IEventFolder",fEventFolder,"EventSelected(TObject*)"); #endif return fEventFolder; } COMET::ICOMETEvent* COMET::IEventFolder::GetEvent(int indx) const { if (!fFolderOfEvents) return NULL; TList* folder = dynamic_cast(fFolderOfEvents->GetListOfFolders()); if (!folder) return NULL; COMET::ICOMETEvent* current = NULL; int count = 0; for ( TObjLink* objlink = folder->LastLink(); objlink != NULL; objlink = objlink->Prev()) { current = dynamic_cast(objlink->GetObject()); if (current) ++count; if (count > indx) break; } if (current) fCurrentEvent = current; return current; } void COMET::IEventFolder::SetCurrentEvent(COMET::ICOMETEvent* event) { if (!event) return; if (!fFolderOfEvents) return; TList* folder = dynamic_cast(fFolderOfEvents->GetListOfFolders()); if (!folder) return; COMET::ICOMETEvent* oldEvent = fCurrentEvent; for (TObjLink* objlink = folder->LastLink(); objlink != NULL; objlink = objlink->Prev()) { COMET::ICOMETEvent* inList = dynamic_cast(objlink->GetObject()); if (inList == event) { fCurrentEvent = event; } } COMETInfo("Current event changed from " << oldEvent << " to " << fCurrentEvent); } COMET::ICOMETEvent* COMET::IEventFolder::FindEvent(int, int) const { return NULL; } COMET::ICOMETEvent* COMET::IEventFolder::GetCurrentEvent(void) { return fCurrentEvent; } void COMET::IEventFolder::RegisterEvent(COMET::ICOMETEvent* event) { fCurrentEvent = event; if (fCurrentEvent && fEventFolder && fEventFolder->fFolderOfEvents) { fEventFolder->fFolderOfEvents->Add(event); event->SetBit(kMustCleanup); } } void COMET::IEventFolder::RemoveEvent(COMET::ICOMETEvent* event) { // Check if the event is the current event. if (fCurrentEvent == event) fCurrentEvent = NULL; // Check if the folder is active. If not, then just return. if (!fEventFolder) return; if (!fEventFolder->GetFolder()) return; TList* folder = dynamic_cast(fEventFolder->GetFolder()->GetListOfFolders()); if (!folder) return; // The folder is active, so find another event in the folder and make it // the current event. for (TObjLink* objlink = folder->LastLink(); objlink != NULL; objlink = objlink->Prev()) { fCurrentEvent = dynamic_cast(objlink->GetObject()); // Any event is OK as long as it's not the event being removed. if (fCurrentEvent != event) break; } } void COMET::IEventFolder::EventSelected(TObject* theObject) { COMETInfo("EventFolder had " << theObject->ClassName() << " at " << theObject << " selected"); COMET::ICOMETEvent* event = dynamic_cast(theObject); SetCurrentEvent(event); } void COMET::IEventFolder::ls(const Option_t* opt) const { if (fFolderOfEvents) fFolderOfEvents->ls(opt); else std::cout << "No Event Folder" << std::endl; } ClassImp(COMET::IEventFolder);