| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ThreadGaudi.cpp
Go to the documentation of this file.
1 // -*-C++-*-
2 // $Id: ThreadGaudi.cpp,v 1.4 2006/04/20 16:42:58 hmd Exp $
3 // $Name: $
4
5 #include "GaudiKernel/ThreadGaudi.h"
6
7 #include <sstream>
8
9 #include <iostream>
10
11 const std::string threadSeparator = "__" ;
12 const std::string algToolSeparator = "." ;
13
14 //
15 // getGaudiThreadIDfromName
16 // ------------------------
17
18 std::string getGaudiThreadIDfromID(int iCopy) {
19 std::ostringstream ost;
20 ost << threadSeparator << iCopy << std::ends;
21 return ost.str();
22 }
23
24 //
25 // getGaudiThreadIDfromName
26 // ------------------------
27
28 std::string getGaudiThreadIDfromName(const std::string& name) {
29 std::string threadAppendix = "" ;
30
31 // find parent if name of an AlgTool
32 std::string parent_name = name ;
33 std::string tool_name = "" ;
34 size_t pp = name.find(".") ;
35 if ( (pp > 0) && (pp <= name.length()) ) {
36 parent_name = name.substr(0,name.find(".")-1) ;
37 tool_name = name.substr(name.find("."));
38 }
39
40 // get from (parent_)name thread ID
41 pp = parent_name.find(threadSeparator) ;
42 if ( (pp > 0) && (pp <= parent_name.length()) ) {
43 threadAppendix = parent_name.substr(parent_name.find(threadSeparator)) ;
44 }
45 return threadAppendix ;
46 }
47
48 //
49 // getGaudiThreadGenericName
50 // -------------------------
51
52 std::string getGaudiThreadGenericName(const std::string& name) {
53 std::string genericName = name ;
54
55 // find parent if name of an AlgTool
56 std::string parent_name = name ;
57 std::string tool_name = "" ;
58 size_t pp = name.find(".") ;
59 if ( (pp > 0) && (pp <= name.length()) ) {
60 parent_name = name.substr(0,name.find(".")-1) ;
61 tool_name = name.substr(name.find("."));
62 }
63
64 // construct gneric name
65 pp = parent_name.find(threadSeparator) ;
66 if ( (pp > 0) && (pp <= parent_name.length()) ) {
67 genericName = parent_name.substr(0,parent_name.find(threadSeparator))+tool_name ;
68 }
69 return genericName ;
70 }
71
72 //
73 // isGaudiThreaded
74 //
75 bool isGaudiThreaded(const std::string& name) {
76 return (!(getGaudiThreadIDfromName(name).empty()));
77 }
78
79 //
80 // ThreadGaudi
81 // -----------
82
83 ThreadGaudi* ThreadGaudiInstance = 0 ;
84
85 ThreadGaudi::ThreadGaudi() {
86 m_threadMap = new ThreadMap();
87 (*m_threadMap)[0] = "" ;
88 }
89
90 ThreadGaudi::~ThreadGaudi() {
91 delete m_threadMap;
92 }
93
94 ThreadGaudi* ThreadGaudi::instance() {
95 if ( 0 == ThreadGaudiInstance ) {
96 ThreadGaudiInstance = new ThreadGaudi();
97 }
98 return ThreadGaudiInstance ;
99 }
100
101 void ThreadGaudi::setThreadID(const std::string& threadID) {
102 ThreadMap* p_threadMap = getThreadMap() ;
103 // get from name thread ID
104 System::ThreadHandle s_pid = System::threadSelf() ;
105 if (p_threadMap->count(s_pid) == 0 ) {
106 (*p_threadMap)[s_pid] = threadID ;
107 #ifdef THREAD_GAUDI__DEBUG
108 std::cout << " *** ThreadGaudi setThreadID *** value set for *** " << threadID << " thread ID : " << s_pid << std::endl ;
109 #endif
110 }
111 }
112
113 ThreadGaudi::ThreadMap* ThreadGaudi::getThreadMap() {
114 return ThreadGaudi::instance()->m_threadMap;
115 }
116
117 const std::string& ThreadGaudi::getThreadID() {
118 ThreadMap* p_threadMap = getThreadMap() ;
119 System::ThreadHandle s_pid = System::threadSelf() ;
120 if ( p_threadMap->find(s_pid) != p_threadMap->end() ) {
121 return (*p_threadMap->find(s_pid)).second ;
122 } else {
123 return (*p_threadMap->find(0)).second ; ;
124 }
125 }