#include #include #include #include #include "ICOMETInputSelected.hxx" #include "ICOMETEvent.hxx" #include "IOADatabase.hxx" #include "ICOMETLog.hxx" #include "IEntryList.hxx" COMET::ICOMETInputSelected::ICOMETInputSelected(const char* name, Option_t* option, Int_t compress) : ICOMETInput(name, option, compress), fListContainer(NULL), fSelected(NULL), fSelectIdx(0) {} COMET::ICOMETInputSelected::ICOMETInputSelected(const char* name, Option_t* option, Int_t compress, const char* listName) : ICOMETInput(name, option, compress), fListContainer(NULL), fSelected(NULL), fSelectIdx(0) { SetSelection(listName); } COMET::ICOMETInputSelected::ICOMETInputSelected(const char* name, Option_t* option, Int_t compress, Int_t listIndex) : ICOMETInput(name, option, compress), fListContainer(NULL), fSelected(NULL), fSelectIdx(0) { SetSelection(listIndex); } COMET::ICOMETInputSelected::ICOMETInputSelected(TFile* file) : ICOMETInput(file), fListContainer(NULL), fSelected(NULL), fSelectIdx(0) {} COMET::ICOMETInputSelected::ICOMETInputSelected(TFile* file, const char* listName) : ICOMETInput(file), fListContainer(NULL), fSelected(NULL), fSelectIdx(0) {SetSelection(listName);} COMET::ICOMETInputSelected::ICOMETInputSelected(TFile* file, int listIndex) : ICOMETInput(file), fListContainer(NULL), fSelected(NULL), fSelectIdx(0) {SetSelection(listIndex);} COMET::ICOMETInputSelected::~ICOMETInputSelected(void) {} Int_t COMET::ICOMETInputSelected::GetEntriesInFile() { // Returns number of events in this file that can be read. if (!IsAttached()) return 0; else if (fSelected) return static_cast(fSelected->GetList().GetN()); else return COMET::ICOMETInput::GetEntriesInFile(); } COMET::ICOMETEvent* COMET::ICOMETInputSelected::NextEvent(int skip) { fSelectIdx += skip; return ReadEvent(++fSelectIdx); } COMET::ICOMETEvent* COMET::ICOMETInputSelected::PreviousEvent(int skip) { fSelectIdx -= skip; return ReadEvent(--fSelectIdx); } COMET::ICOMETEvent* COMET::ICOMETInputSelected::ReadEvent(Int_t n) { // Get the selected event fSelectIdx = n; // Assign a new dummy integer int sel_n; // If we have a selection, use it if (fSelected) sel_n = fSelected->GetList().GetEntry(fSelectIdx); else sel_n = fSelectIdx; return COMET::ICOMETInput::ReadEvent(sel_n); } void COMET::ICOMETInputSelected::SetListContainer(){ // Get the TFile pointer TFile* thisFile = GetFilePointer(); fListContainer = dynamic_cast(thisFile->Get("event_selection_lists")); // Check this actually exists if (!fListContainer) throw COMET::ENoSelectedListContainter(); } void COMET::ICOMETInputSelected::SetSelection(const char* select_name){ // Check we have the event selection list container if (!fListContainer) SetListContainer(); // Try to get the selected entry list COMET::IHandle thisSelect = fListContainer->Get(select_name); // Set the internal selection if it exists if (thisSelect) { fSelected = &(*thisSelect); COMETNamedLog("ICOMETInputSelected", "Using IEntryList : " << fSelected->GetName()); } // Otherwise complain else { COMETError("List of name: " << select_name << " not found!!"); throw COMET::EListNotFound(); } } void COMET::ICOMETInputSelected::SetSelection(int listIndex){ // Check we have the event selection list container if (!fListContainer) SetListContainer(); // Try to get the selected entry list try { COMET::IEntryList* thisSelect = fListContainer->At(listIndex); // Set the internal selection if it exists fSelected = &(*thisSelect); COMETNamedLog("ICOMETInputSelected", "Using IEntryList : " << fSelected->GetName()); }catch(ENoSuchElement& e){ // Otherwise complain COMETError("List of index: " << listIndex << " not found!!"); throw COMET::EListNotFound(); } } ClassImp(COMET::ICOMETInputSelected)