diff --git a/src/cpp/include/UTIL/LCCollectionTools.h b/src/cpp/include/UTIL/LCCollectionTools.h new file mode 100644 index 000000000..aa3e8580d --- /dev/null +++ b/src/cpp/include/UTIL/LCCollectionTools.h @@ -0,0 +1,20 @@ +#ifndef UTIL_LCCollectionTools_H +#define UTIL_LCCollectionTools_H 1 + +#include "EVENT/LCObject.h" +#include "EVENT/LCCollection.h" + +namespace UTIL{ + /** Extract object index inside a given LCCollection. + * @author Bohdan Dudar + * @version August 2022 + */ + int getElementIndex(const EVENT::LCObject* item, EVENT::LCCollection* collection){ + for(int i=0; i < collection->getNumberOfElements(); ++i){ + if ( item == collection->getElementAt(i) ) return i; + } + return -1; + } +} + +#endif