-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add shared utilities to retrieve collections from the store
- Loading branch information
Showing
6 changed files
with
91 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "GaudiKernel/AlgTool.h" | ||
#include "GaudiKernel/AnyDataWrapper.h" | ||
#include "GaudiKernel/IDataManagerSvc.h" | ||
#include "GaudiKernel/IDataProviderSvc.h" | ||
#include "GaudiKernel/SmartDataPtr.h" | ||
|
||
#include "StoreUtils.h" | ||
#include "podio/Frame.h" | ||
|
||
#include "k4FWCore/FunctionalUtils.h" | ||
|
||
#include <vector> | ||
#include <string> | ||
|
||
std::vector<std::string> getAvailableCollectionsFromStore(const AlgTool* thisClass, | ||
std::optional<std::map<uint32_t, std::string>>& idToName, | ||
bool returnFrameCollections | ||
) { | ||
std::vector<std::string> collectionNames; | ||
|
||
SmartIF<IDataManagerSvc> mgr; | ||
mgr = thisClass->evtSvc(); | ||
|
||
SmartDataPtr<DataObject> root(thisClass->evtSvc(), "/Event"); | ||
if (!root) { | ||
thisClass->error() << "Failed to retrieve root object /Event" << endmsg; | ||
} | ||
|
||
auto pObj = root->registry(); | ||
if (!pObj) { | ||
thisClass->error() << "Failed to retrieve the root registry object" << endmsg; | ||
} | ||
std::vector<IRegistry*> leaves; | ||
StatusCode sc = mgr->objectLeaves(pObj, leaves); | ||
if (!sc.isSuccess()) { | ||
thisClass->error() << "Failed to retrieve object leaves" << endmsg; | ||
} | ||
for (const auto& pReg : leaves) { | ||
if (pReg->name() == k4FWCore::frameLocation) { | ||
if (!returnFrameCollections) | ||
continue; | ||
auto wrapper = dynamic_cast<AnyDataWrapper<podio::Frame>*>(pReg->object()); | ||
if (!wrapper) { | ||
throw std::runtime_error("Could not cast object to Frame"); | ||
} | ||
for (const auto& name : wrapper->getData().getAvailableCollections()) { | ||
collectionNames.push_back(name); | ||
} | ||
} | ||
DataObject* p; | ||
sc = thisClass->evtSvc()->retrieveObject("/Event" + pReg->name(), p); | ||
if (sc.isFailure()) { | ||
thisClass->error() << "Could not retrieve object " << pReg->name() << " from the EventStore" << endmsg; | ||
} | ||
auto wrapper = dynamic_cast<AnyDataWrapper<std::unique_ptr<podio::CollectionBase>>*>(p); | ||
if (!wrapper) { | ||
continue; | ||
} | ||
// Remove the leading / | ||
collectionNames.push_back(pReg->name().substr(1, pReg->name().size() - 1)); | ||
if (idToName) { | ||
idToName->emplace(wrapper->getData()->getID(), pReg->name()); | ||
} | ||
} | ||
return collectionNames; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include "GaudiKernel/AlgTool.h" | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
std::vector<std::string> getAvailableCollectionsFromStore(const AlgTool* thisClass, | ||
std::optional<std::map<uint32_t, std::string>>& idToName, | ||
bool returnFrameCollections = false); |