ATLAS Offline Software
han_config_print.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 #include <iostream>
9 #include <string>
10 #include <cstdlib>
11 
12 #include <TFile.h>
13 #include <TKey.h>
14 
16 
20 
21 namespace {
22 
23 int usage( const std::string& command_name, int exit_code );
24 
25 struct CmdLineArgs {
26  int parse( int argc, char *argv[] );
27 
28  std::string command;
29  std::string hconfig;
30  std::string conditions;
31 };
32 
33 } // unnamed namespace
34 
35 
36 int main ATLAS_NOT_THREAD_SAFE ( int argc, char *argv[] )
37 {
38  CmdLineArgs arg;
39  int rc = arg.parse( argc, argv );
40  if (rc!=0) return rc;
41 
43  //std::cout<<__PRETTY_FUNCTION__<<"Input Conditions="<<dqi::ConditionsSingleton::getInstance().getCondition()
44  // <<std::endl;
45  std::string configName( arg.hconfig );
46  TFile* config = TFile::Open( configName.c_str() );
47  if( config == 0 ) {
48  std::cerr << "Cannot open file \"" << configName << "\"\n";
49  return 1;
50  }
51 
52  TKey* key = config->FindKey("HanMetadata");
53  if (key) {
54  std::cout << "Metadata:\n";
55  TDirectory* metadatadir = dynamic_cast<TDirectory*>(key->ReadObj());
56  if (! metadatadir) {
57  std::cerr << "Metadata directory is malformed\n";
58  return 1;
59  }
60  dqi::HanConfigMetadata* hcm(0); TKey* mdkey(0);
61  TIter next(metadatadir->GetListOfKeys());
62  while ((mdkey = dynamic_cast<TKey*>(next()))) {
63  metadatadir->GetObject(mdkey->GetName(), hcm);
64  if (hcm) {
65  std::cout << *hcm << std::endl;
66  }
67  }
68  delete metadatadir;
69  }
70 
71  key = config->FindKey("top_level");
72  if( key == 0 ) {
73  std::cerr << "Cannot find configuration in file \"" << configName << "\"\n";
74  return 1;
75  }
76 
77  dqi::HanConfigGroup* g = dynamic_cast<dqi::HanConfigGroup*>( key->ReadObj() );
78  if( g == 0 ) {
79  std::cerr << "Cannot find configuration in file \"" << configName << "\"\n";
80  return 1;
81  }
82 
83  std::cout << g;
84  return 0;
85 }
86 
87 
88 // ************************************************************
89 // Private Functions
90 // ************************************************************
91 
92 namespace {
93 
94 int CmdLineArgs::parse( int argc, char *argv[] )
95 {
96  command = argv[0];
97  if( argc > 3 ) return usage( command, 1 );
98  if( argc < 2 ) return usage( command, 0 );
99 
100  hconfig = argv[1];
101  if(argc==3)conditions = argv[2];
102  return 0;
103 }
104 
105 
106 int usage( const std::string& command_name, int exit_code )
107 {
108  std::string message;
109  message += "\n";
110  message += "This program takes as an argument the name of a \'han\' configuration\n";
111  message += "file and prints the configuration.\n";
112 
113  std::string::size_type s = command_name.size();
114  std::string::size_type p = command_name.rfind( '/', s );
115  std::string short_name = command_name.substr( p+1, s );
116 
117  std::cout << "\n";
118  std::cout << "Usage: " << short_name << " <filename>\n";
119  std::cout << message << "\n";
120  return exit_code;
121 }
122 
123 
124 } // unnamed namespace
AtlCoolConsole.usage
tuple usage
Definition: AtlCoolConsole.py:443
HanConfigGroup.h
dqi::ConditionsSingleton::getInstance
static ConditionsSingleton & getInstance()
Definition: ConditionsSingleton.cxx:20
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1054
ReweightUtils.message
message
Definition: ReweightUtils.py:15
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
dqi::HanConfigGroup
Definition: HanConfigGroup.h:23
main
int main(int, char **)
Main class for all the CppUnit test classes
Definition: CppUnit_SGtestdriver.cxx:141
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
fillPileUpNoiseLumi.next
next
Definition: fillPileUpNoiseLumi.py:52
ConditionsSingleton.h
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
ATLAS_NOT_THREAD_SAFE
int main ATLAS_NOT_THREAD_SAFE(int argc, char *argv[])
Definition: han_config_print.cxx:36
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
create_dcsc_inputs_sqlite.arg
list arg
Definition: create_dcsc_inputs_sqlite.py:48
HanConfigMetadata.h
dqi::HanConfigMetadata
Definition: HanConfigMetadata.h:22
dqi::ConditionsSingleton::setCondition
void setCondition(const std::string &c)
Definition: ConditionsSingleton.cxx:25
checker_macros.h
Define macros for attributes used to control the static checker.
get_generator_info.command
string command
Definition: get_generator_info.py:38
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37