ATLAS Offline Software
Loading...
Searching...
No Matches
RepeatAlgorithm.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// $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 <memory>
17
18#include <TCollection.h>
19#include <TDirectory.h>
20#include <TFile.h>
21#include <TGraph.h>
22#include <TKey.h>
23
24namespace {
26}
27
28namespace dqm_algorithms{
29
34
37operator=(const RepeatAlgorithm& other) {
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
54
55dqm_core::Algorithm*
57clone()
58{
59 return new RepeatAlgorithm(*this);
60}
61
62void
64printDescription(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
77dqm_core::Result*
79execute( const std::string& name, const TObject& data, const dqm_core::AlgorithmConfig& config )
80{
81 dqm_core::Result::Status status(dqm_core::Result::Undefined);
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
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 std::unique_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 ) {
110 status = ( status == dqm_core::Result::Undefined ) ? dqm_core::Result::Green : status;
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
138 dqm_core::Result* result = new dqm_core::Result( status );
139 result->tags_ = std::move(tags);
140 if (!returnObjs->IsEmpty()) {
141 result->object_.reset(returnObjs.release());
142 }
143
144 return result;
145}
146
147dqm_core::AlgorithmConfig*
149ConfigureSubAlg(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
const boost::regex ref(r_ef)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
std::map< std::string, double > instance
std::shared_ptr< dqm_core::Algorithm > m_subalg
virtual dqm_core::Algorithm * clone()
virtual void printDescription(std::ostream &out)
RepeatAlgorithm(const RepeatAlgorithm &other)
virtual dqm_core::Result * execute(const std::string &name, const TObject &data, const dqm_core::AlgorithmConfig &config)
dqm_core::AlgorithmConfig * ConfigureSubAlg(const dqm_core::AlgorithmConfig &config, TObject *reference)
RepeatAlgorithm & operator=(const RepeatAlgorithm &other)
std::vector< std::string > tags
Definition hcg.cxx:105
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
std::string ExtractAlgorithmName(const dqm_core::AlgorithmConfig &config)