From 4668a95cbc6263c990a4eb57ddc6a6c1afdaed26 Mon Sep 17 00:00:00 2001 From: Bohdan Dudar Date: Wed, 31 Aug 2022 13:43:25 +0200 Subject: [PATCH] Add a utility function to return objects index inside a provided LCCollection --- src/cpp/include/UTIL/LCCollectionTools.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/cpp/include/UTIL/LCCollectionTools.h 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