ATLAS Offline Software
RepeatAlgorithm.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // **********************************************************************
6 // $Id: RepeatAlgorithm.cxx,v 1.5 2009-05-07 14:45:54 ponyisi Exp $
7 // **********************************************************************
8 
10 #include "dqm_core/LibraryManager.h"
11 #include "dqm_core/AlgorithmManager.h"
13 #include "dqm_core/test/DummyAlgorithmConfig.h"
14 
15 #include <iostream>
16 #include <boost/scoped_ptr.hpp>
17 
18 #include <TCollection.h>
19 #include <TDirectory.h>
20 #include <TFile.h>
21 #include <TGraph.h>
22 #include <TKey.h>
23 
24 namespace {
26 }
27 
28 namespace dqm_algorithms{
29 
32  m_subalg() {
33 }
34 
38  if (this != &other) {
39  m_subalg = other.m_subalg;
40  }
41  return *this;
42 }
43 
46 {
47  dqm_core::AlgorithmManager::instance().registerAlgorithm("RepeatAlgorithm", this);
48 }
49 
52 {
53 }
54 
57 clone()
58 {
59  return new RepeatAlgorithm(*this);
60 }
61 
62 void
64 printDescription(std::ostream& out)
65 {
66  std::string message;
67  message += "\n";
68  message += "Algorithm: RepeatAlgorithm\n";
69  message += "Description: Repeats the specified algorithm for each input reference.\n";
70  message += "Parameters: AuxAlgName--xxx: run algorithm xxx\n";
71  message += " RepeatAlgorithm--ResultsNEntries: return # of entries of reference histogram as a result\n";
72 
73  out << message;
74 }
75 
76 
79 execute( const std::string& name, const TObject& data, const dqm_core::AlgorithmConfig& config )
80 {
82  std::map<std::string,double> tags;
83  std::unique_ptr<TObjArray> returnObjs(new TObjArray);
84 
85  if (!m_subalg.get()) {
86  // rely on requested subalg not changing over time
87  std::string subalgname(dqm_algorithms::tools::ExtractAlgorithmName(config));
88  try {
89  m_subalg.reset(dqm_core::AlgorithmManager::instance().getAlgorithm(subalgname));
90  }
91  catch (dqm_core::Exception& ex) {
92  throw dqm_core::BadConfig( ERS_HERE, "RepeatAlgorithm", ex.what(), ex );
93  }
94  }
95  TObject* ref(0);
96  try {
97  ref = config.getReference();
98  } catch (dqm_core::BadConfig &) {
99  throw dqm_core::BadConfig( ERS_HERE, "RepeatAlgorithm", "No references defined for RepeatAlgorithm - this makes no sense" );
100  }
101  const TCollection* listptr(dynamic_cast<const TCollection*>(ref));
102  if (!listptr) {
103  throw dqm_core::BadConfig( ERS_HERE, "RepeatAlgorithm", "Reference needs to be a TCollection" );
104  }
105  TIter itr(listptr);
106  while ( TObject* ireference = itr.Next() ) {
107  boost::scoped_ptr<dqm_core::AlgorithmConfig> subConfig(ConfigureSubAlg(config, ireference));
108  dqm_core::Result* subResult = m_subalg->execute( name, data, *subConfig );
109  if( subResult->status_ != dqm_core::Result::Undefined ) {
111  status = ( subResult->status_ < status ) ? subResult->status_ : status;
112  }
113 
114  std::map<std::string,double>::const_iterator tagsEnd = subResult->tags_.end();
115  std::map<std::string,double>::const_iterator tagsIter = subResult->tags_.begin();
116  for( ; tagsIter != tagsEnd; ++tagsIter ) {
117  tags[ireference->GetName() + std::string("|") + tagsIter->first] = tagsIter->second;
118  }
119  tags[ireference->GetName() + std::string("|Status")] = subResult->status_;
120  if ( dqm_algorithms::tools::GetFirstFromMap("RepeatAlgorithm--ResultsNEntries", config.getParameters(), 0) > 0 ) {
121 
122  if( ireference->IsA()->InheritsFrom( "TH1" )){
123  TH1* hireference = dynamic_cast<TH1*>(ireference);
124  if (hireference) {
125  tags[ireference->GetName() + std::string("|NEntries")] = hireference->GetEntries();
126  }
127  }
128  }
129 
130  if (subResult->getObject()) {
131  // do nothing here; ROOT handling is terrible
132  // returnObjs->Add(subResult->getObject()->Clone());
133  }
134  //delete subConfig;
135  delete subResult;
136  }
137 
139  result->tags_ = tags;
140  if (!returnObjs->IsEmpty()) {
141  result->object_.reset(returnObjs.release());
142  }
143 
144  return result;
145 }
146 
147 dqm_core::AlgorithmConfig*
149 ConfigureSubAlg(const dqm_core::AlgorithmConfig& config, TObject* reference)
150 {
151 // caller owns the returned object
152 
153 // what we do: copy reference, params, limits to newly created config
154 // copy all params except AuxAlgName--blah and RepeatAlgorithm--blah
155 
156  auto rv(new dqm_core::test::DummyAlgorithmConfig(reference));
157 
158  for (const auto& parVal : config.getParameters()) {
159  if (parVal.first.find("AuxAlgName--") == std::string::npos
160  && parVal.first.find("RepeatAlgorithm--") == std::string::npos) {
161  rv->addParameter(parVal.first, parVal.second);
162  }
163  }
164  for (const auto& grthr : config.getGreenThresholds()) {
165  rv->addGreenThreshold(grthr.first, grthr.second);
166  }
167  for (const auto& rdthr : config.getRedThresholds()) {
168  rv->addRedThreshold(rdthr.first, rdthr.second);
169  }
170  return rv;
171 }
172 
173 
174 
175 }//namespace dqi
dqm_algorithms::RepeatAlgorithm
Definition: RepeatAlgorithm.h:17
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
Undefined
@ Undefined
Definition: MaterialTypes.h:8
get_generator_info.result
result
Definition: get_generator_info.py:21
python.FakeAthena.Algorithm
def Algorithm(name)
Definition: FakeAthena.py:41
dqm_algorithms::RepeatAlgorithm::~RepeatAlgorithm
virtual ~RepeatAlgorithm()
Definition: RepeatAlgorithm.cxx:51
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
dqm_algorithms::RepeatAlgorithm::m_subalg
std::shared_ptr< dqm_core::Algorithm > m_subalg
Definition: RepeatAlgorithm.h:35
reference
Definition: hcg.cxx:437
dqm_algorithms::RepeatAlgorithm::execute
virtual dqm_core::Result * execute(const std::string &name, const TObject &data, const dqm_core::AlgorithmConfig &config)
Definition: RepeatAlgorithm.cxx:79
ReweightUtils.message
message
Definition: ReweightUtils.py:15
dqm_algorithms::tools::ExtractAlgorithmName
std::string ExtractAlgorithmName(const dqm_core::AlgorithmConfig &config)
Definition: AlgorithmHelper.cxx:615
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
tags
std::vector< std::string > tags
Definition: hcg.cxx:102
RepeatAlgorithm.h
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
dqm_algorithms::RepeatAlgorithm::RepeatAlgorithm
RepeatAlgorithm()
Definition: RepeatAlgorithm.cxx:45
python.handimod.Green
int Green
Definition: handimod.py:524
dqm_algorithms::RepeatAlgorithm::printDescription
virtual void printDescription(std::ostream &out)
Definition: RepeatAlgorithm.cxx:64
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
dq_make_web_display.rv
def rv
Definition: dq_make_web_display.py:219
dqm_algorithms::RepeatAlgorithm::operator=
RepeatAlgorithm & operator=(const RepeatAlgorithm &other)
Definition: RepeatAlgorithm.cxx:37
dqm_algorithms
Definition: AddReference.h:17
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
Athena::Status
Status
Athena specific StatusCode values.
Definition: AthStatusCode.h:22
ref
const boost::regex ref(r_ef)
TH1
Definition: rootspy.cxx:268
AlgorithmHelper.h
dqm_algorithms::RepeatAlgorithm::clone
virtual dqm_core::Algorithm * clone()
Definition: RepeatAlgorithm.cxx:57
merge.status
status
Definition: merge.py:17
dqm_algorithms::tools::GetFirstFromMap
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:339
dqm_algorithms::RepeatAlgorithm::ConfigureSubAlg
dqm_core::AlgorithmConfig * ConfigureSubAlg(const dqm_core::AlgorithmConfig &config, TObject *reference)
Definition: RepeatAlgorithm.cxx:149