Skip to content

Commit

Permalink
Add a utility function to return objects index inside a provided LCCo…
Browse files Browse the repository at this point in the history
…llection
  • Loading branch information
dudarboh committed Sep 12, 2022
1 parent 49c0961 commit db5c9ff
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ SET( LCIO_UTIL_SRCS
./src/UTIL/ILDConf.cc
./src/UTIL/ProcessFlag.cc
./src/UTIL/TrackTools.cc
./src/UTIL/LCCollectionTools.cc
)

SET( LCIO_MT_SRCS
Expand Down
15 changes: 15 additions & 0 deletions src/cpp/include/UTIL/LCCollectionTools.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#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. If object is not found, return -1.
* @author Bohdan Dudar
* @version August 2022
*/
int getElementIndex(const EVENT::LCObject* item, EVENT::LCCollection* collection);
}

#endif
10 changes: 10 additions & 0 deletions src/cpp/src/UTIL/LCCollectionTools.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "UTIL/LCCollectionTools.h"

namespace UTIL{
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;
}
}

0 comments on commit db5c9ff

Please sign in to comment.