The Gaudi Framework  master (37c0b60a)
JobHistory.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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 <Gaudi/Property.h>
24 #include <GaudiKernel/JobHistory.h>
25 #include <GaudiKernel/System.h>
26 
27 #include <cstdlib>
28 #include <iostream>
29 
30 using std::endl;
31 using std::ostream;
32 using std::string;
33 
34 //**********************************************************************
35 // Member functions.
36 //**********************************************************************
37 
38 // Constructor.
39 
40 JobHistory::JobHistory() : m_start_time( 0 ) {
41 
42  time( &m_start_time );
43 
44  std::string rel;
45 
46  if ( ( rel = System::getEnv( "ATLAS_BASE_RELEASE" ) ) != "UNKNOWN" ) {
47  m_release_version = rel;
48  } else if ( ( rel = System::getEnv( "GAUDIROOT" ) ) != "UNKNOWN" ) {
49  m_release_version = rel;
50  } else {
51  m_release_version = "UNKNOWN";
52  }
53  m_dir = System::getEnv( "PWD" );
54  m_cmtconfig = System::getEnv( "CMTCONFIG" );
55 
60 
62 }
63 
64 JobHistory::JobHistory( const std::string& rel, const std::string& os, const std::string& host, const std::string& dir,
65  const std::string& osver, const std::string& mach, const std::string& cmtconfig,
66  const time_t& time )
67  : m_release_version( rel )
68  , m_dir( dir )
69  , m_cmtconfig( cmtconfig )
70  , m_osname( os )
71  , m_hostname( host )
72  , m_os_version( osver )
73  , m_machine( mach )
74  , m_start_time( time ) {}
75 
76 //**********************************************************************
77 
78 // Destructor.
79 
80 JobHistory::~JobHistory() = default;
81 
83 
84  static const CLID CLID_JobHistory = 247994533;
85  return CLID_JobHistory;
86 }
87 
88 void JobHistory::addProperty( const std::string& key, const std::string& value ) {
90  std::string prop_value = value;
91  if ( !prop_value.empty() && prop_value[0] == '"' && prop_value[prop_value.size() - 1] == '"' )
92  prop_value = prop_value.substr( 1, prop_value.size() - 2 );
93 
94  std::string client, prop_name;
95  auto pos = key.rfind( '.' );
96  if ( pos == std::string::npos ) {
97  prop_name = key;
98  } else {
99  client = key.substr( 0, pos );
100  prop_name = key.substr( pos + 1 );
101  }
102 
103  m_ppl.emplace_back( client, std::make_unique<Gaudi::Property<std::string>>( prop_name, prop_value ) );
104 }
105 
106 std::ostream& JobHistory::dump( std::ostream& ost, const bool isXML, int /*ind*/ ) const {
107 
108  if ( !isXML ) {
109  ost << "Release: " << release_version() << endl;
110  ost << "OS: " << os() << endl;
111  ost << "OS ver: " << os_version() << endl;
112  ost << "Host: " << hostname() << endl;
113  ost << "Machine: " << machine() << endl;
114  ost << "Run dir: " << dir() << endl;
115  ost << "CMTCONFIG: " << cmtconfig() << endl;
116  ost << "Job start time: " << start_time() << endl << endl;
117  ost << "Properties: [" << endl;
118  ;
119  for ( const auto& ipprop : propertyPairs() ) {
120  const auto& client = ipprop.first;
121  const auto& prop = ipprop.second;
122  ost << client << ": ";
123  prop->fillStream( ost );
124  ost << endl;
125  }
126  ost << "]" << endl;
127  for ( const auto& itr : environment() ) ost << itr << endl;
128  } else {
129  }
130 
131  return ost;
132 }
133 
134 //**********************************************************************
std::string
STL class.
JobHistory::os
const std::string & os() const
Definition: JobHistory.h:74
System.h
JobHistory::environment
const std::vector< std::string > & environment() const
Definition: JobHistory.h:80
System::getEnv
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:390
std::string::size
T size(T... args)
JobHistory::dump
std::ostream & dump(std::ostream &, bool isXML, int indent) const override
Definition: JobHistory.cpp:106
JobHistory::m_machine
std::string m_machine
Definition: JobHistory.h:46
JobHistory::machine
const std::string & machine() const
Definition: JobHistory.h:77
JobHistory::cmtconfig
const std::string & cmtconfig() const
Definition: JobHistory.h:79
JobHistory::JobHistory
JobHistory()
Definition: JobHistory.cpp:40
JobHistory::dir
const std::string & dir() const
Definition: JobHistory.h:78
JobHistory::m_dir
std::string m_dir
Definition: JobHistory.h:40
JobHistory::classID
static const CLID & classID()
Definition: JobHistory.cpp:82
System::osName
GAUDI_API const std::string & osName()
OS name.
Definition: System.cpp:326
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
plotSpeedupsPyRoot.time
time
Definition: plotSpeedupsPyRoot.py:180
std::string::substr
T substr(T... args)
JobHistory::os_version
const std::string & os_version() const
Definition: JobHistory.h:76
JobHistory::m_environ
std::vector< std::string > m_environ
Definition: JobHistory.h:48
std::vector::emplace_back
T emplace_back(T... args)
JobHistory::hostname
const std::string & hostname() const
Definition: JobHistory.h:75
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:88
JobHistory::m_hostname
std::string m_hostname
Definition: JobHistory.h:44
System::machineType
GAUDI_API const std::string & machineType()
Machine type.
Definition: System.cpp:338
std::string::empty
T empty(T... args)
JobHistory::m_release_version
std::string m_release_version
Definition: JobHistory.h:39
JobHistory::release_version
const std::string & release_version() const
Definition: JobHistory.h:73
System::hostName
GAUDI_API const std::string & hostName()
Host name.
Definition: System.cpp:320
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:84
System::osVersion
GAUDI_API const std::string & osVersion()
OS version.
Definition: System.cpp:332
Gaudi::Property< std::string >
JobHistory::m_start_time
time_t m_start_time
Definition: JobHistory.h:54
Property.h