2   Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
 
    5 #include "VP1Base/VP1Msg.h"
 
    8 inline toolT * VP1ToolAccessHelper::getToolPointer( const QString& tooltypeandname, bool silent, bool createIfNotExists )
 
   10   //We use the typeid for dynamic type-checking, since, for unknown
 
   11   //reasons, we have to static_cast through void pointers in order to
 
   12   //keep correct pointers and avoid dynamic casts to null!
 
   13   QString typeidstr(typeid(toolT*).name());
 
   15   if (VP1Msg::verbose())
 
   16     messageVerbose("getToolPointer(..) called with tool type/name = "+tooltypeandname
 
   17            +", with return typeid = "+typeidstr);
 
   19     messageVerbose("getToolPointer(..) WARNING does not have toolSvc pointer. Returning NULL.");
 
   22   if (tooltypeandname.isEmpty()||!tooltypeandname.contains('/')) {
 
   23     messageDebug("getToolPointer(..) WARNING requested tool name has incorrect format ("+tooltypeandname+")!");
 
   27   std::pair<QString,QString> id(tooltypeandname,typeidstr);
 
   28   const typename std::map<std::pair<QString,QString>,IAlgTool*>::iterator it = m_toolname2pointer.find(id);
 
   29   if (it==m_toolname2pointer.end()) {
 
   30     //This is the first attempt at retrieval.
 
   32     //Fixme/todo: Should we check that tool exists before any attempts
 
   33     //at retrieval are done??
 
   36     ToolHandle<toolT> toolhandle( tooltypeandname.toStdString(),
 
   37                   0/*public tools only*/,
 
   39     bool exception = true;
 
   40     bool retrieveok = false;
 
   42       retrieveok = !toolhandle.retrieve().isFailure();
 
   44     } catch (const std::runtime_error& e) {
 
   49     messageVerbose("ToolHandle<>::retrieve() throws exception.");
 
   51     messageDebug("ToolHandle<>::retrieve() throws exception.");
 
   52       m_toolname2pointer[id] = 0;
 
   58     messageVerbose("getToolPointer(..) ERROR: Failed to retrieve tool: "+tooltypeandname);
 
   60     message("getToolPointer(..) ERROR: Failed to retrieve tool: "+tooltypeandname);
 
   61       m_toolname2pointer[id] = 0;
 
   66     toolT * thetool = &(*toolhandle);
 
   68       message("getToolPointer(..) ERROR: Tool retrieve claimed to be succesful, but pointer is NULL!");
 
   72     if (VP1Msg::verbose())
 
   73       messageVerbose("Returning "+str(thetool)+" tool pointer.");
 
   74     //We need the cast to void ptr to work around some WEIRD pointer
 
   75     //values introduced by a more straight-forward casting:
 
   76     void* voidptr = static_cast<void*>(thetool);
 
   77     IAlgTool* algptr = static_cast<IAlgTool*>(voidptr);
 
   78     if (VP1Msg::verbose())
 
   79       messageVerbose("getToolPointer(..) Storing ptr = "+str(algptr));
 
   80     m_toolname2pointer[id] = algptr;
 
   85       messageVerbose("getToolPointer(..) Returning null tool pointer since previous retrieval attempts failed)).");
 
   88     toolT* pointer = static_cast<toolT*>(static_cast<void*>(it->second));
 
   90       //Fixme: Respect silent flag here?
 
   91       message("getToolPointer(..) ERROR: Could not cast IAlgTool pointer "+str(it->second)
 
   92           +" to type "+QString(typeid(toolT*).name())+". Returning 0.");
 
   95     if (VP1Msg::verbose())
 
   96       messageVerbose("getToolPointer(..) Retrieved tool pointer ("+str(pointer)+") succesfully");