Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
PrintToolConfigAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //
6 // includes
7 //
8 
10 #include <AsgTools/ToolStore.h>
11 
12 #include <filesystem>
13 #include <fstream>
14 #include <iostream>
15 
16 namespace CP {
17 
19  // Log the current working directory
20  ANA_MSG_INFO("The current filesystem path is: " +
21  std::filesystem::current_path().generic_string());
22 
23  // Log file where configuration will be dumped
24  ANA_MSG_INFO("Dumping the tool configuration to: " + m_outputFileName);
25 
26  // Open the output file stream
27  std::ofstream configFileStream(m_outputFileName);
28  if (!configFileStream) {
29  ANA_MSG_ERROR("Failed to open file: " + m_outputFileName);
30  return StatusCode::FAILURE;
31  }
32 
33  // Redirect std::cout to the file stream
34  std::streambuf* originalCoutBuf = std::cout.rdbuf(configFileStream.rdbuf());
35 
36  try {
37  asg::ToolStore::dumpToolConfig(); // Dump the configuration
38  } catch (const std::exception& e) {
39  ANA_MSG_ERROR("Exception while dumping tool configuration: " +
40  std::string(e.what()));
41  std::cout.rdbuf(
42  originalCoutBuf); // Restore original buffer before returning
43  return StatusCode::FAILURE;
44  }
45 
46  // Restore original std::cout buffer
47  std::cout.rdbuf(originalCoutBuf);
48 
49  // Close file stream (optional, as destructor will handle it)
50  configFileStream.close();
51 
52  ANA_MSG_INFO("Tool configuration dump complete");
53 
54  return StatusCode::SUCCESS;
55 }
56 
57 } // namespace CP
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:49
CP::PrintToolConfigAlg::finalize
StatusCode finalize() override
Definition: PrintToolConfigAlg.cxx:18
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CP::PrintToolConfigAlg::m_outputFileName
Gaudi::Property< std::string > m_outputFileName
Definition: PrintToolConfigAlg.h:20
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
calibdata.exception
exception
Definition: calibdata.py:496
PrintToolConfigAlg.h
ToolStore.h