The Gaudi Framework  v36r9p1 (5c15b2bb)
JobHistory.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2022 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& key, const std::string& value ) {
93  std::string prop_value = value;
94  if ( !prop_value.empty() && prop_value[0] == '"' && prop_value[prop_value.size() - 1] == '"' )
95  prop_value = prop_value.substr( 1, prop_value.size() - 2 );
96 
97  std::string client, prop_name;
98  auto pos = key.rfind( '.' );
99  if ( pos == std::string::npos ) {
100  prop_name = key;
101  } else {
102  client = key.substr( 0, pos );
103  prop_name = key.substr( pos + 1 );
104  }
105 
106  m_ppl.emplace_back( client, std::make_unique<Gaudi::Property<std::string>>( prop_name, prop_value ) );
107 }
108 
109 std::ostream& JobHistory::dump( std::ostream& ost, const bool isXML, int /*ind*/ ) const {
110 
111  if ( !isXML ) {
112  ost << "Release: " << release_version() << endl;
113  ost << "OS: " << os() << endl;
114  ost << "OS ver: " << os_version() << endl;
115  ost << "Host: " << hostname() << endl;
116  ost << "Machine: " << machine() << endl;
117  ost << "Run dir: " << dir() << endl;
118  ost << "CMTCONFIG: " << cmtconfig() << endl;
119  ost << "Job start time: " << start_time() << endl << endl;
120  ost << "Properties: [" << endl;
121  ;
122  for ( const auto& ipprop : propertyPairs() ) {
123  const auto& client = ipprop.first;
124  const auto& prop = ipprop.second;
125  ost << client << ": ";
126  prop->fillStream( ost );
127  ost << endl;
128  }
129  ost << "]" << endl;
130  for ( const auto& itr : environment() ) ost << itr << endl;
131  } else {
132  }
133 
134  return ost;
135 }
136 
137 //**********************************************************************
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:73
std::string
STL class.
JobHistory::cmtconfig
std::string cmtconfig() const
Definition: JobHistory.h:79
System.h
JobHistory::os
std::string os() const
Definition: JobHistory.h:74
System::getEnv
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:385
std::string::size
T size(T... args)
JobHistory::dump
std::ostream & dump(std::ostream &, bool isXML, int indent) const override
Definition: JobHistory.cpp:109
JobHistory::os_version
std::string os_version() const
Definition: JobHistory.h:76
JobHistory::m_machine
std::string m_machine
Definition: JobHistory.h:46
JobHistory::hostname
std::string hostname() const
Definition: JobHistory.h:75
JobHistory::JobHistory
JobHistory()
Definition: JobHistory.cpp:43
JobHistory::machine
std::string machine() const
Definition: JobHistory.h:77
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:321
plotSpeedupsPyRoot.time
def time
Definition: plotSpeedupsPyRoot.py:175
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:83
JobHistory::m_ppl
PropertyPairList m_ppl
Definition: JobHistory.h:51
JobHistory::addProperty
void addProperty(const std::string &key, const std::string &value)
Definition: JobHistory.cpp:91
JobHistory::m_hostname
std::string m_hostname
Definition: JobHistory.h:44
System::machineType
GAUDI_API const std::string & machineType()
Machine type.
Definition: System.cpp:333
JobHistory::dir
std::string dir() const
Definition: JobHistory.h:78
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:315
JobHistory::propertyPairs
const PropertyPairList & propertyPairs() const
Definition: JobHistory.h:82
JobHistory::m_cmtconfig
std::string m_cmtconfig
Definition: JobHistory.h:41
JobHistory::~JobHistory
virtual ~JobHistory()
ProduceConsume.key
key
Definition: ProduceConsume.py:81
System::osVersion
GAUDI_API const std::string & osVersion()
OS version.
Definition: System.cpp:327
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:80
Property.h