Skip to content
Snippets Groups Projects
Commit 8261d11d authored by Marco Clemencic's avatar Marco Clemencic
Browse files

Remove deprecated header GaudiKernel/ThreadGaudi.h

Revert "Restored GaudiKernel/ThreadGaudi.h, needed by ATLAS"

This reverts commit 1f86f043.
parent 1f86f043
No related branches found
No related tags found
1 merge request!608Remove deprecated header GaudiKernel/ThreadGaudi.h
#ifndef GaudiKernel_EXPORTS // defined when compiling GaudiKernel
#warning deprecated header (will be removed in Gaudi v30r3)
#endif
#ifndef GAUDI_KERNEL_THREADLIBGAUDI_H
#define GAUDI_KERNEL_THREADLIBGAUDI_H
#include "GaudiKernel/System.h" /* ThreadHandle */
#include <map>
#include <memory>
#include <string>
/** @class ThreadGaudi ThreadGaudi.h GaudiKernel/ThreadGaudi.h
* @brief singleton mapping the pthread ID to the Gaudi thread ID
* @author Werner Wiedenmann
*/
class GAUDI_API ThreadGaudi
{
public:
typedef std::map<System::ThreadHandle, std::string> ThreadMap;
/// singleton access
static ThreadGaudi* instance();
/// associate Gaudi ID to pthread
void setThreadID( const std::string& threadID );
/// access the whole map
ThreadMap* getThreadMap();
/// get Gaudi ID of current pthread
const std::string& getThreadID();
protected:
ThreadGaudi();
virtual ~ThreadGaudi() = default;
std::unique_ptr<ThreadMap> m_threadMap;
};
/// helper function to extract Gaudi Thread ID from thread copy number
GAUDI_API std::string getGaudiThreadIDfromID( int iCopy );
/// helper function to extract Gaudi Thread ID from thread copy name
GAUDI_API std::string getGaudiThreadIDfromName( const std::string& name );
/// helper function to extract Gaudi instance name from thread copy name
GAUDI_API std::string getGaudiThreadGenericName( const std::string& name );
/// test if current Gaudi object is running /will run in a thread
GAUDI_API bool isGaudiThreaded( const std::string& name );
#endif // GAUDI_KERNEL_THREADLIBGAUDI_H
// -*-C++-*-
#include "GaudiKernel/ThreadGaudi.h"
#include <sstream>
#include <iostream>
const std::string threadSeparator = "__";
const std::string algToolSeparator = ".";
//
// getGaudiThreadIDfromName
// ------------------------
std::string getGaudiThreadIDfromID( int iCopy )
{
std::ostringstream ost;
ost << threadSeparator << iCopy << std::ends;
return ost.str();
}
//
// getGaudiThreadIDfromName
// ------------------------
std::string getGaudiThreadIDfromName( const std::string& name )
{
std::string threadAppendix = "";
// find parent if name of an AlgTool
std::string parent_name = name;
std::string tool_name = "";
size_t pp = name.find( "." );
if ( ( pp > 0 ) && ( pp <= name.length() ) ) {
parent_name = name.substr( 0, name.find( "." ) - 1 );
tool_name = name.substr( name.find( "." ) );
}
// get from (parent_)name thread ID
pp = parent_name.find( threadSeparator );
if ( ( pp > 0 ) && ( pp <= parent_name.length() ) ) {
threadAppendix = parent_name.substr( parent_name.find( threadSeparator ) );
}
return threadAppendix;
}
//
// getGaudiThreadGenericName
// -------------------------
std::string getGaudiThreadGenericName( const std::string& name )
{
std::string genericName = name;
// find parent if name of an AlgTool
std::string parent_name = name;
std::string tool_name = "";
size_t pp = name.find( "." );
if ( ( pp > 0 ) && ( pp <= name.length() ) ) {
parent_name = name.substr( 0, name.find( "." ) - 1 );
tool_name = name.substr( name.find( "." ) );
}
// construct gneric name
pp = parent_name.find( threadSeparator );
if ( ( pp > 0 ) && ( pp <= parent_name.length() ) ) {
genericName = parent_name.substr( 0, parent_name.find( threadSeparator ) ) + tool_name;
}
return genericName;
}
//
// isGaudiThreaded
//
bool isGaudiThreaded( const std::string& name ) { return ( !( getGaudiThreadIDfromName( name ).empty() ) ); }
//
// ThreadGaudi
// -----------
ThreadGaudi* ThreadGaudiInstance = nullptr;
ThreadGaudi::ThreadGaudi() : m_threadMap{new ThreadMap()} { ( *m_threadMap )[0] = ""; }
ThreadGaudi* ThreadGaudi::instance()
{
if ( !ThreadGaudiInstance ) ThreadGaudiInstance = new ThreadGaudi();
return ThreadGaudiInstance;
}
void ThreadGaudi::setThreadID( const std::string& threadID )
{
ThreadMap* p_threadMap = getThreadMap();
// get from name thread ID
System::ThreadHandle s_pid = System::threadSelf();
if ( p_threadMap->count( s_pid ) == 0 ) {
( *p_threadMap )[s_pid] = threadID;
#ifdef THREAD_GAUDI__DEBUG
std::cout << " *** ThreadGaudi setThreadID *** value set for *** " << threadID << " thread ID : " << s_pid
<< std::endl;
#endif
}
}
ThreadGaudi::ThreadMap* ThreadGaudi::getThreadMap() { return ThreadGaudi::instance()->m_threadMap.get(); }
const std::string& ThreadGaudi::getThreadID()
{
ThreadMap* p_threadMap = getThreadMap();
System::ThreadHandle s_pid = System::threadSelf();
if ( p_threadMap->find( s_pid ) != p_threadMap->end() ) {
return ( *p_threadMap->find( s_pid ) ).second;
} else {
return ( *p_threadMap->find( 0 ) ).second;
;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment