The Gaudi Framework  v36r1 (3e2fb5a8)
JobHistory.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
12 //
13 // GaudiHistory/JobHistory.cpp
14 //
15 // Contains history information for a job. Imports all environment vars
16 // and info from uname
17 //
18 //
19 // @author: Charles Leggett
20 //
22 
23 #include "GaudiKernel/JobHistory.h"
24 #include "GaudiKernel/System.h"
25 #include <Gaudi/Property.h>
26 
27 #include <cstdlib>
28 #include <iostream>
29 
30 using std::endl;
31 using std::ostream;
32 using std::string;
33 using std::vector;
34 
36 
37 //**********************************************************************
38 // Member functions.
39 //**********************************************************************
40 
41 // Constructor.
42 
43 JobHistory::JobHistory() : m_start_time( 0 ) {
44 
45  time( &m_start_time );
46 
47  std::string rel;
48 
49  if ( ( rel = System::getEnv( "ATLAS_BASE_RELEASE" ) ) != "UNKNOWN" ) {
50  m_release_version = rel;
51  } else if ( ( rel = System::getEnv( "GAUDIROOT" ) ) != "UNKNOWN" ) {
52  m_release_version = rel;
53  } else {
54  m_release_version = "UNKNOWN";
55  }
56  m_dir = System::getEnv( "PWD" );
57  m_cmtconfig = System::getEnv( "CMTCONFIG" );
58 
63 
65 }
66 
67 JobHistory::JobHistory( const std::string& rel, const std::string& os, const std::string& host, const std::string& dir,
68  const std::string& osver, const std::string& mach, const std::string& cmtconfig,
69  const time_t& time )
70  : m_release_version( rel )
71  , m_dir( dir )
72  , m_cmtconfig( cmtconfig )
73  , m_osname( os )
74  , m_hostname( host )
75  , m_os_version( osver )
76  , m_machine( mach )
77  , m_start_time( time ) {}
78 
79 //**********************************************************************
80 
81 // Destructor.
82 
83 JobHistory::~JobHistory() = default;
84 
86 
87  static const CLID CLID_JobHistory = 247994533;
88  return CLID_JobHistory;
89 }
90 
91 void JobHistory::addProperty( const std::string& client, const PropertyBase* prop ) {
92  addProperty( client + '.' + prop->name(), prop->toString() );
93 }
94 
95 void JobHistory::addProperty( const std::string& key, const std::string& value ) {
97  std::string prop_value = value;
98  if ( !prop_value.empty() && prop_value[0] == '"' && prop_value[prop_value.size() - 1] == '"' )
99  prop_value = prop_value.substr( 1, prop_value.size() - 2 );
100 
101  std::string client, prop_name;
102  auto pos = key.rfind( '.' );
103  if ( pos == std::string::npos ) {
104  prop_name = key;
105  } else {
106  client = key.substr( 0, pos );
107  prop_name = key.substr( pos + 1 );
108  }
109 
110  m_ppl.emplace_back( client, std::make_unique<Gaudi::Property<std::string>>( prop_name, prop_value ) );
111 }
112 
113 std::ostream& JobHistory::dump( std::ostream& ost, const bool isXML, int /*ind*/ ) const {
114 
115  if ( !isXML ) {
116  ost << "Release: " << release_version() << endl;
117  ost << "OS: " << os() << endl;
118  ost << "OS ver: " << os_version() << endl;
119  ost << "Host: " << hostname() << endl;
120  ost << "Machine: " << machine() << endl;
121  ost << "Run dir: " << dir() << endl;
122  ost << "CMTCONFIG: " << cmtconfig() << endl;
123  ost << "Job start time: " << start_time() << endl << endl;
124  ost << "Properties: [" << endl;
125  ;
126  for ( const auto& ipprop : propertyPairs() ) {
127  const auto& client = ipprop.first;
128  const auto& prop = ipprop.second;
129  ost << client << ": ";
130  prop->fillStream( ost );
131  ost << endl;
132  }
133  ost << "]" << endl;
134  for ( const auto& itr : environment() ) ost << itr << endl;
135  } else {
136  }
137 
138  return ost;
139 }
140 
141 //**********************************************************************
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: PropertyBase.h:35
JobHistory::release_version
std::string release_version() const
Definition: JobHistory.h:75
Gaudi::Details::PropertyBase::name
const std::string name() const
property name
Definition: PropertyBase.h:39
std::string
STL class.
JobHistory::cmtconfig
std::string cmtconfig() const
Definition: JobHistory.h:81
System.h
JobHistory::os
std::string os() const
Definition: JobHistory.h:76
System::getEnv
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:379
std::string::size
T size(T... args)
JobHistory::dump
std::ostream & dump(std::ostream &, bool isXML, int indent) const override
Definition: JobHistory.cpp:113
JobHistory::os_version
std::string os_version() const
Definition: JobHistory.h:78
JobHistory::m_machine
std::string m_machine
Definition: JobHistory.h:46
JobHistory::hostname
std::string hostname() const
Definition: JobHistory.h:77
JobHistory::JobHistory
JobHistory()
Definition: JobHistory.cpp:43
JobHistory::machine
std::string machine() const
Definition: JobHistory.h:79
JobHistory::m_dir
std::string m_dir
Definition: JobHistory.h:40
JobHistory::classID
static const CLID & classID()
Definition: JobHistory.cpp:85
System::osName
GAUDI_API const std::string & osName()
OS name.
Definition: System.cpp:319
plotSpeedupsPyRoot.time
def time
Definition: plotSpeedupsPyRoot.py:163
std::ostream
STL class.
JobHistory::m_os_version
std::string m_os_version
Definition: JobHistory.h:45
JobHistory::m_osname
std::string m_osname
Definition: JobHistory.h:43
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:18
JobHistory.h
std::string::substr
T substr(T... args)
Containers::vector
struct GAUDI_API vector
Parametrisation class for vector-like implementation.
Definition: KeyedObjectManager.h:39
JobHistory::m_environ
std::vector< std::string > m_environ
Definition: JobHistory.h:48
std::vector::emplace_back
T emplace_back(T... args)
std::endl
T endl(T... args)
JobHistory::start_time
time_t start_time() const
Definition: JobHistory.h:85
Gaudi::Details::PropertyBase::toString
virtual std::string toString() const =0
value -> string
JobHistory::m_ppl
PropertyPairList m_ppl
Definition: JobHistory.h:51
JobHistory::m_hostname
std::string m_hostname
Definition: JobHistory.h:44
JobHistory::addProperty
void addProperty(const std::string &, const Gaudi::Details::PropertyBase *)
Definition: JobHistory.cpp:91
System::machineType
GAUDI_API const std::string & machineType()
Machine type.
Definition: System.cpp:331
JobHistory::dir
std::string dir() const
Definition: JobHistory.h:80
std::string::empty
T empty(T... args)
JobHistory::m_release_version
std::string m_release_version
Definition: JobHistory.h:39
System::hostName
GAUDI_API const std::string & hostName()
Host name.
Definition: System.cpp:313
JobHistory::propertyPairs
const PropertyPairList & propertyPairs() const
Definition: JobHistory.h:84
JobHistory::m_cmtconfig
std::string m_cmtconfig
Definition: JobHistory.h:41
JobHistory::~JobHistory
virtual ~JobHistory()
ProduceConsume.key
key
Definition: ProduceConsume.py:52
System::osVersion
GAUDI_API const std::string & osVersion()
OS version.
Definition: System.cpp:325
Gaudi::Property< std::string >
JobHistory::m_start_time
time_t m_start_time
Definition: JobHistory.h:54
JobHistory::environment
std::vector< std::string > environment() const
Definition: JobHistory.h:82
Property.h