The Gaudi Framework  v33r0 (d5ea422b)
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/Property.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 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  // if (m_props.find(prop) == m_props.end())
93  m_ppl.emplace_back( client, prop );
94 }
95 
96 void JobHistory::dump( std::ostream& ost, const bool isXML, int /*ind*/ ) const {
97 
98  if ( !isXML ) {
99  ost << "Release: " << release_version() << endl;
100  ost << "OS: " << os() << endl;
101  ost << "OS ver: " << os_version() << endl;
102  ost << "Host: " << hostname() << endl;
103  ost << "Machine: " << machine() << endl;
104  ost << "Run dir: " << dir() << endl;
105  ost << "CMTCONFIG: " << cmtconfig() << endl;
106  ost << "Job start time: " << start_time() << endl << endl;
107  ost << "Properties: [" << endl;
108  ;
109  for ( const auto& ipprop : propertyPairs() ) {
110  const std::string& client = ipprop.first;
111  const PropertyBase* prop = ipprop.second;
112  ost << client << ": ";
113  prop->fillStream( ost );
114  ost << endl;
115  }
116  ost << "]" << endl;
117  for ( const auto& itr : environment() ) ost << itr << endl;
118  } else {
119  }
120 }
121 
122 //**********************************************************************
123 // Free functions.
124 //**********************************************************************
125 
126 // Output stream.
127 
128 ostream& operator<<( ostream& lhs, const JobHistory& rhs ) {
129  rhs.dump( lhs, false );
130  return lhs;
131 }
132 
133 //**********************************************************************
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:379
PropertyPairList m_ppl
Definition: JobHistory.h:50
std::string m_dir
Definition: JobHistory.h:39
T endl(T... args)
std::string m_os_version
Definition: JobHistory.h:44
std::string os() const
Definition: JobHistory.h:73
struct GAUDI_API vector
Parametrisation class for vector-like implementation.
std::string machine() const
Definition: JobHistory.h:76
std::string m_osname
Definition: JobHistory.h:42
std::string dir() const
Definition: JobHistory.h:77
virtual ~JobHistory()
std::string m_hostname
Definition: JobHistory.h:43
std::vector< std::string > environment() const
Definition: JobHistory.h:79
JobHistory class definition.
Definition: JobHistory.h:32
time_t start_time() const
Definition: JobHistory.h:82
STL class.
std::vector< std::string > m_environ
Definition: JobHistory.h:47
time_t m_start_time
Definition: JobHistory.h:53
void addProperty(const std::string &, const Gaudi::Details::PropertyBase *)
Definition: JobHistory.cpp:91
std::string hostname() const
Definition: JobHistory.h:74
std::string cmtconfig() const
Definition: JobHistory.h:78
ostream & operator<<(ostream &lhs, const JobHistory &rhs)
Definition: JobHistory.cpp:128
void dump(std::ostream &, const bool isXML=false, int indent=0) const override
Definition: JobHistory.cpp:96
std::string m_cmtconfig
Definition: JobHistory.h:40
GAUDI_API const std::string & osName()
OS name.
Definition: System.cpp:319
std::string m_machine
Definition: JobHistory.h:45
std::string os_version() const
Definition: JobHistory.h:75
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:42
unsigned int CLID
Class ID definition.
Definition: ClassID.h:18
virtual std::ostream & fillStream(std::ostream &) const
the printout of the property value
Definition: Property.cpp:59
std::string m_release_version
Definition: JobHistory.h:38
GAUDI_API const std::string & hostName()
Host name.
Definition: System.cpp:313
const PropertyPairList & propertyPairs() const
Definition: JobHistory.h:81
GAUDI_API const std::string & osVersion()
OS version.
Definition: System.cpp:325
static const CLID & classID()
Definition: JobHistory.cpp:85
GAUDI_API const std::string & machineType()
Machine type.
Definition: System.cpp:331
std::string release_version() const
Definition: JobHistory.h:72
STL class.
T emplace_back(T... args)