ATLAS Offline Software
HanAlgorithmConfig.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // **********************************************************************
6 // $Id: HanAlgorithmConfig.cxx,v 1.3 2009-05-07 14:45:54 ponyisi Exp $
7 // **********************************************************************
8 
9 #include <TDirectory.h>
10 #include <TFile.h>
11 #include <TKey.h>
12 #include <TH1.h>
13 #include <TMap.h>
14 
22 
23 
24 namespace dqi {
25 
26 // *********************************************************************
27 // Public Methods
28 // *********************************************************************
29 
31 HanAlgorithmConfig( const HanConfigAssessor& hca, TFile* config )
32  : m_file(config)
33  , m_ref(0)
34 {
35  CopyAlgConfig( hca );
37 }
38 
40 HanAlgorithmConfig( TObject* reference,
41  const std::map< std::string, double >& parameters,
42  const std::map< std::string, std::string>& stringParameters,
43  const std::map< std::string, double >& greenThresholds,
44  const std::map< std::string, double >& redThresholds,
45  const HanConfigAssessor* hca)
46  : m_file(0)
47  , m_ref(reference)
48  , m_hca(hca)
49 {
50  m_parameters = parameters;
51  m_generic_parameters = stringParameters;
52  m_green_thresholds = greenThresholds;
53  m_red_thresholds = redThresholds;
55 }
56 
59 {
60  delete m_ref;
61 }
62 
63 
64 TObject*
66 getReference() const
67 {
68  if (m_ref) {
69  TObject* rv = m_ref->Clone();
70  if (rv) {
71  return rv;
72  } else {
73  const char* parname = m_hca ? m_hca->GetName() : "???";
74  throw dqm_core::BadConfig( ERS_HERE, parname,
75  "Unable to clone reference" );
76  }
77  }
78  const char* parname = m_hca ? m_hca->GetName() : "???";
79  throw dqm_core::BadConfig( ERS_HERE, parname,
80  "No reference histogram provided" );
81 }
82 
83 
84 // *********************************************************************
85 // Protected Methods
86 // *********************************************************************
87 
88 void
90 CopyAlgConfig( const HanConfigAssessor& hca )
91 {
92  typedef std::map< std::string, double >::value_type ParsVal_t;
93  typedef std::map< std::string, double >::value_type ThrVal_t;
94 
95  m_hca = &hca;
96 
97  std::string parName;
98  TIter nextPar( hca.GetAllAlgPars() );
100  while( (par = dynamic_cast<HanConfigAlgPar*>( nextPar() )) != 0 ) {
101  parName = std::string( par->GetName() );
102  ParsVal_t parMapVal( parName, par->GetValue() );
103  m_parameters.insert( parMapVal );
104  }
105  TIter nextStrPar( hca.GetAllAlgStrPars() );
106  HanConfigParMap* strPar;
107  while( (strPar = dynamic_cast<HanConfigParMap*>( nextStrPar() )) != 0 ) {
108  m_generic_parameters.emplace( strPar->GetName(), strPar->GetValue() );
109  }
110 
111  std::string limName;
112  TIter nextLim( hca.GetAllAlgLimits() );
113  HanConfigAlgLimit* lim;
114  while( (lim = dynamic_cast<HanConfigAlgLimit*>( nextLim() )) != 0 ) {
115  limName = std::string( lim->GetName() );
116  ThrVal_t greenMapVal( limName, lim->GetGreen() );
117  m_green_thresholds.insert( greenMapVal );
118  ThrVal_t redMapVal( limName, lim->GetRed() );
119  m_red_thresholds.insert( redMapVal );
120  }
121 
122  std::string refName( hca.GetAlgRefName() );
123  if( refName != "" ) {
124  TKey* key = dqi::getObjKey( m_file, refName );
125  if (key == NULL) {
126  std::cout << "ERROR: can't find reference " << refName << std::endl;
127  } else {
128  if (hca.GetIsRegex()) {
129  TMap* map = dynamic_cast<TMap*>(key->ReadObj());
130  if (! map) {
131  std::cerr << "Problem reading TMap input for regex" << std::endl;
132  m_ref = nullptr;
133  } else {
134  std::cout << "Get reference for " << hca.GetHistPath() << std::endl;
135  m_ref = map->GetValue(hca.GetHistPath());
136  }
137  } else {
138  // not a regex
139  m_ref = key->ReadObj();
140  }
141  }
142  }
143 }
144 
145 void
148 {
149  auto& runtime = HanRuntimeConfigSingleton::getInstance();
150 
151  m_generic_parameters.emplace( "runtime_path", runtime.getPath() );
152  if ( runtime.pathIsRunDirectory() )
153  m_parameters.emplace( "run_number", runtime.getPathRunNumber() );
154 }
155 
156 
157 // *********************************************************************
158 // Private Methods
159 // *********************************************************************
160 
161 } // namespace dqi
dqi::HanAlgorithmConfig::m_file
TFile * m_file
Definition: HanAlgorithmConfig.h:44
dqi::HanConfigAlgLimit
Definition: HanConfigAlgLimit.h:18
dqi::HanConfigAssessor::GetIsRegex
virtual bool GetIsRegex() const
Definition: HanConfigAssessor.cxx:385
dqi::HanAlgorithmConfig::~HanAlgorithmConfig
virtual ~HanAlgorithmConfig()
Definition: HanAlgorithmConfig.cxx:58
python.CreateTierZeroArgdict.parname
parname
Definition: CreateTierZeroArgdict.py:194
HanConfigParMap.h
HanRuntimeConfigSingleton.h
dqi::HanConfigAssessor::GetAlgRefName
virtual std::string GetAlgRefName() const
Definition: HanConfigAssessor.cxx:229
reference
Definition: hcg.cxx:437
dqi::HanConfigAssessor::GetHistPath
virtual const char * GetHistPath() const
Definition: HanConfigAssessor.cxx:177
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
dqi::HanConfigAlgLimit::GetGreen
virtual float GetGreen() const
Definition: HanConfigAlgLimit.cxx:71
m_file
std::unique_ptr< TFile > m_file
description: this is a custom writer for the old-school drivers that don't use an actual writer
Definition: OutputStreamData.cxx:52
dqi::HanConfigParMap
Definition: HanConfigParMap.h:18
dqi::HanConfigAssessor::GetName
virtual const char * GetName() const
Definition: HanConfigAssessor.cxx:170
dqi::HanConfigParMap::GetValue
virtual const char * GetValue() const
Definition: HanConfigParMap.cxx:77
HanAlgorithmConfig.h
dqi::HanConfigAlgLimit::GetName
virtual const char * GetName() const
Definition: HanConfigAlgLimit.cxx:55
dqi::HanAlgorithmConfig::CopyAlgConfig
void CopyAlgConfig(const HanConfigAssessor &hca)
Definition: HanAlgorithmConfig.cxx:90
dqi::HanAlgorithmConfig::m_hca
const HanConfigAssessor * m_hca
Definition: HanAlgorithmConfig.h:47
HanUtils.h
HanConfigAssessor.h
beamspotnt.parName
list parName
Definition: bin/beamspotnt.py:1287
dqi::HanConfigAssessor
Definition: HanConfigAssessor.h:37
dqi::HanAlgorithmConfig::m_ref
TObject * m_ref
Definition: HanAlgorithmConfig.h:46
dqi::HanConfigAssessor::GetAllAlgPars
virtual TIter GetAllAlgPars() const
Definition: HanConfigAssessor.cxx:268
HanConfigAlgLimit.h
dqi::HanConfigAssessor::GetAllAlgLimits
virtual TIter GetAllAlgLimits() const
Definition: HanConfigAssessor.cxx:328
dqi::HanConfigParMap::GetName
virtual const char * GetName() const
Definition: HanConfigParMap.cxx:61
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:29
dqi::HanAlgorithmConfig::CopyRuntimeConfig
void CopyRuntimeConfig()
Definition: HanAlgorithmConfig.cxx:147
dq_make_web_display.rv
def rv
Definition: dq_make_web_display.py:219
dqi::HanConfigAlgPar
Definition: HanConfigAlgPar.h:18
dqi::HanRuntimeConfigSingleton::getInstance
static HanRuntimeConfigSingleton & getInstance()
Definition: HanRuntimeConfigSingleton.cxx:15
dqi::HanConfigAlgLimit::GetRed
virtual float GetRed() const
Definition: HanConfigAlgLimit.cxx:87
physics_parameters.parameters
parameters
Definition: physics_parameters.py:144
dqi::HanAlgorithmConfig::getReference
virtual TObject * getReference() const override
Definition: HanAlgorithmConfig.cxx:66
HanConfigAlgPar.h
dqi::HanConfigAssessor::GetAllAlgStrPars
virtual TIter GetAllAlgStrPars() const
Definition: HanConfigAssessor.cxx:298
dqi
Definition: CompositeAlgorithm.h:16
dqi::HanAlgorithmConfig::HanAlgorithmConfig
HanAlgorithmConfig(const HanConfigAssessor &hca, TFile *config)
Definition: HanAlgorithmConfig.cxx:31
dqi::getObjKey
TKey * getObjKey(TDirectory *dir, const std::string &path)
Definition: HanUtils.cxx:36
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37