ATLAS Offline Software
Loading...
Searching...
No Matches
Analysis::CalibrationDataUpdater Class Reference

This algorithm is meant to be used in a stand-alone fashion, to update a ROOT file containing results to be entered in COOL with fresh (but possibly partial) information. More...

#include <CalibrationDataUpdater.h>

Inheritance diagram for Analysis::CalibrationDataUpdater:
Collaboration diagram for Analysis::CalibrationDataUpdater:

Public Member Functions

 CalibrationDataUpdater (const std::string &name, ISvcLocator *pSvcLocator)
 Standard Athena-Algorithm Constructor.
virtual ~CalibrationDataUpdater ()=default
 Default Destructor.
StatusCode initialize () override
 standard Athena-Algorithm method
virtual StatusCode sysInitialize () override
 Override sysInitialize.
virtual const DataObjIDColl & extraOutputDeps () const override
 Return the list of extra output dependencies.
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysStart () override
 Handle START transition.
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles.
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles.
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T, V, H > &t)
void updateVHKA (Gaudi::Details::PropertyBase &)
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const

Protected Member Functions

void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed.

Private Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t

Private Member Functions

void setDefaultResults (const std::string &Name, TFile *fOut) const
 auxiliary functions
void copyResults (const std::string &from, const std::string &to, TFile *fIn, TFile *fOut) const
bool isValidName (const std::string &Name) const
void writeOutput (TObject *in, const std::string &Name, TFile *fOut) const
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

std::string m_inputRootFile = ""
 input ROOT file containing new results
std::string m_DbRootFile = ""
 ROOT file to be entered in COOL.
std::vector< std::string > m_paramNames
 names of input and output parametrisations
Gaudi::Property m_overrideDefaults = false
 flag if these results are to be used as defaults (they will anyway if no other results exist for the particular combination of jet collection / tagging algorithm / operating point)
DataObjIDColl m_extendedExtraObjects
StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default)
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default)
std::vector< SG::VarHandleKeyArray * > m_vhka
bool m_varHandleArraysDeclared

Detailed Description

This algorithm is meant to be used in a stand-alone fashion, to update a ROOT file containing results to be entered in COOL with fresh (but possibly partial) information.

Alternatively, it can be used to change the default algorithm that is used (if multiple alternatives are available).

Author
Frank Filthaut F.Fil.nosp@m.thau.nosp@m.t@sci.nosp@m.ence.nosp@m..ru.n.nosp@m.l

Definition at line 37 of file CalibrationDataUpdater.h.

Member Typedef Documentation

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< Algorithm > >::StoreGateSvc_t
privateinherited

Definition at line 388 of file AthCommonDataStore.h.

Constructor & Destructor Documentation

◆ CalibrationDataUpdater()

Analysis::CalibrationDataUpdater::CalibrationDataUpdater ( const std::string & name,
ISvcLocator * pSvcLocator )

Standard Athena-Algorithm Constructor.

Definition at line 19 of file CalibrationDataUpdater.cxx.

20 :
21 AthAlgorithm(name,pSvcLocator)
22{
23 // property declarations
24 declareProperty("inputRootFile", m_inputRootFile, "ROOT file containing new parametrisations");
25 declareProperty("DbRootFile", m_DbRootFile, "ROOT file to be entered in COOL");
26 declareProperty("paramNames", m_paramNames, "list of input and output parametrisation names");
27 declareProperty("overrideDefaults", m_overrideDefaults, "true if new results are to be used as default");
28
29}
std::string m_inputRootFile
input ROOT file containing new results
std::string m_DbRootFile
ROOT file to be entered in COOL.
Gaudi::Property m_overrideDefaults
flag if these results are to be used as defaults (they will anyway if no other results exist for the ...
std::vector< std::string > m_paramNames
names of input and output parametrisations
AthAlgorithm()
Default constructor:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)

◆ ~CalibrationDataUpdater()

virtual Analysis::CalibrationDataUpdater::~CalibrationDataUpdater ( )
virtualdefault

Default Destructor.

Member Function Documentation

◆ copyResults()

void Analysis::CalibrationDataUpdater::copyResults ( const std::string & from,
const std::string & to,
TFile * fIn,
TFile * fOut ) const
private

Definition at line 136 of file CalibrationDataUpdater.cxx.

138{
139 if (! isValidName(to)) {
140 ATH_MSG_WARNING( name() << ": invalid parametrisation name: " << to );
141 return;
142 }
143
144 // copy the parametrisation itself
145 TObject* in = fIn->Get(from.c_str());
146 if (! in) {
147 ATH_MSG_WARNING( name() << ": input parametrisation name not found: "
148 << from );
149 return;
150 }
151 writeOutput(in, to, fOut);
152
153 // copy the corresponding covariance matrix
154 std::string fromCov(from); fromCov += "_stat";
155 std::string toCov(to); toCov += "_stat";
156 in = fIn->Get(fromCov.c_str());
157 if (! in) {
158 ATH_MSG_WARNING( name() << ": input parametrisation covariance matrix name not found: "
159 << fromCov );
160 return;
161 }
162 writeOutput(in, toCov, fOut);
163
164 // copy the corresponding covariance matrix
165 std::string fromSyst(from); fromSyst += "_syst";
166 std::string toSyst(to); toSyst += "_syst";
167 in = fIn->Get(fromSyst.c_str());
168 if (! in) {
169 ATH_MSG_WARNING( name() << ": input parametrisation systematics name not found: "
170 << fromSyst );
171 return;
172 }
173 writeOutput(in, toSyst, fOut);
174
175}
#define ATH_MSG_WARNING(x)
void writeOutput(TObject *in, const std::string &Name, TFile *fOut) const
bool isValidName(const std::string &Name) const

◆ declareGaudiProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< Algorithm > >::declareGaudiProperty ( Gaudi::Property< T, V, H > & hndl,
const SG::VarHandleKeyType &  )
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158 {
160 hndl.value(),
161 hndl.documentation());
162
163 }

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty ( Gaudi::Property< T, V, H > & t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145 {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>

◆ detStore()

const ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

◆ evtStore()

ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< Algorithm > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase & ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ extraOutputDeps()

const DataObjIDColl & AthAlgorithm::extraOutputDeps ( ) const
overridevirtualinherited

Return the list of extra output dependencies.

This list is extended to include symlinks implied by inheritance relations.

Definition at line 50 of file AthAlgorithm.cxx.

51{
52 // If we didn't find any symlinks to add, just return the collection
53 // from the base class. Otherwise, return the extended collection.
54 if (!m_extendedExtraObjects.empty()) {
56 }
57 return Algorithm::extraOutputDeps();
58}
DataObjIDColl m_extendedExtraObjects

◆ initialize()

StatusCode Analysis::CalibrationDataUpdater::initialize ( )
override

standard Athena-Algorithm method

Definition at line 33 of file CalibrationDataUpdater.cxx.

34{
35 // Code entered here will be executed once at program start.
36
37 ATH_MSG_INFO( name() << " initialize()" );
38
39 // basic sanity and consistency checks
40
41 TFile* fIn = 0;
42 bool newInput = (m_inputRootFile.empty());
43 if (newInput) {
44 fIn = new TFile(m_inputRootFile.c_str());
45 if (fIn->IsZombie()) {
46 ATH_MSG_FATAL( name() << ": requested input ROOT file invalid: "
47 << m_inputRootFile );
48 return StatusCode::FAILURE;
49 }
50 } else if (! m_overrideDefaults) {
51 ATH_MSG_FATAL( name() << ": no input ROOT file given and no defaults to be modified:"
52 << " no action to be taken" );
53 return StatusCode::FAILURE;
54 }
55 if (m_DbRootFile.empty()) {
56 ATH_MSG_FATAL( name() << ": no DB ROOT file given" );
57 return StatusCode::FAILURE;
58 }
59 TFile* fOut = new TFile(m_DbRootFile.c_str(), "UPDATE");
60 if (fOut->IsZombie()) {
61 ATH_MSG_FATAL( name() << ": DB ROOT file invalid: "
62 << m_DbRootFile );
63 return StatusCode::FAILURE;
64 }
65
66 for (const std::string& itname : m_paramNames){
67 string to = *itname;
68 // 1. determine whether to insert new results
69 if (newInput) {
70 // if no "->" is found, assume that the input and output object names are identical
71 const string::size_type delim = itname->find("->");
72 string from = (delim == string::npos) ? *itname : itname->substr(0, delim);
73 if (delim != string::npos) to = itname->substr(delim+2);
74 copyResults(from, to, fIn, fOut);
75 } else if (! isValidName(to)) {
76 ATH_MSG_WARNING( name() << ": invalid parametrisation name: " << to );
77 continue;
78 }
79 // 2. make these new results the default (if requested or if no default exists yet)
80 setDefaultResults(to, fOut);
81 }
82 ATH_MSG_DEBUG( name() << ": all done" );
83
84 if (fIn) fIn->Close();
85 fOut->Close();
86
87 ATH_MSG_DEBUG( "initialize() successful in " << name() );
88 return StatusCode::SUCCESS;
89}
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
void copyResults(const std::string &from, const std::string &to, TFile *fIn, TFile *fOut) const
void setDefaultResults(const std::string &Name, TFile *fOut) const
auxiliary functions
CONT to(RANGE &&r)
Definition ranges.h:39

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< Algorithm > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ isValidName()

bool Analysis::CalibrationDataUpdater::isValidName ( const std::string & Name) const
private

Definition at line 177 of file CalibrationDataUpdater.cxx.

178{
179 // this is a very basic check: the name should contain four slashes
180 // and should end either in "_SF" or "_Eff"
181 int slashes = 0;
182 string::size_type delim = Name.find("/");
183 while (delim != string::npos) {
184 ++slashes;
185 Name = Name.substr(delim+1);
186 delim = Name.find("/");
187 }
188 if (slashes != 4) return false;
189
190 delim = Name.rfind("_");
191 if (delim == string::npos) return false;
192 Name = Name.substr(delim+1);
193 return (Name == "SF" || Name == "Eff");
194}
JetDumper::Name Name
Definition JetDumper.cxx:19

◆ msg()

MsgStream & AthCommonMsg< Algorithm >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msgLvl()

bool AthCommonMsg< Algorithm >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ outputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< Algorithm > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ renounce()

std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > AthCommonDataStore< AthCommonMsg< Algorithm > >::renounce ( T & h)
inlineprotectedinherited

Definition at line 380 of file AthCommonDataStore.h.

381 {
382 h.renounce();
384 }
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< Algorithm > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364 {
366 }

◆ setDefaultResults()

void Analysis::CalibrationDataUpdater::setDefaultResults ( const std::string & Name,
TFile * fOut ) const
private

auxiliary functions

Definition at line 91 of file CalibrationDataUpdater.cxx.

92{
93 fOut->cd("/");
94 TObject* obj = fOut->Get(Name.c_str());
95 if (! obj) {
96 ATH_MSG_WARNING( name() << ": nonexistent parametrisation name: " << Name );
97 return;
98 }
99
100 string::size_type delim = Name.rfind("/");
101 string dir = Name.substr(0, delim);
102 TDirectory* newdir = fOut->GetDirectory(dir.c_str());
103 if (! newdir->cd()) {
104 // This should never happen, given that the object above apparently exists...
105 ATH_MSG_WARNING( name() << ": Name now: " << Name << "; pwd: "
106 << gDirectory->GetPath() << "; cd() to subdir "
107 << dir << " failed!" );
108 };
109
110 // if no change of defaults is requested to begin with, check whether a default
111 // exists already
112 delim = Name.rfind("_");
113 string defaultName("default"); defaultName += Name.substr(delim);
114 if (! m_overrideDefaults) {
115 string fullName(dir); fullName += "/"; fullName += defaultName;
116 if (fOut->Get(fullName.c_str())) return;
117 }
118
119 ATH_MSG_INFO( name() << ": copying parametrisation name: "
120 << Name << " (+ stat., syst.) as default" );
121
122 // do the actual copying for the parametrisation itself
123 obj->Write(defaultName.c_str());
124
125 // and for the parameter covariance matrix
126 string nameCov(Name); nameCov += "_stat";
127 string defaultNameCov(defaultName); defaultNameCov += "_stat";
128 fOut->Get(nameCov.c_str())->Write(defaultNameCov.c_str());
129
130 // and for the systematic uncertainty
131 string nameSyst(Name); nameSyst += "_syst";
132 string defaultNameSyst(defaultName); defaultNameSyst += "_syst";
133 fOut->Get(nameSyst.c_str())->Write(defaultNameSyst.c_str());
134}

◆ sysInitialize()

StatusCode AthAlgorithm::sysInitialize ( )
overridevirtualinherited

Override sysInitialize.

Override sysInitialize from the base class.

Loop through all output handles, and if they're WriteCondHandles, automatically register them and this Algorithm with the CondSvc

Scan through all outputHandles, and if they're WriteCondHandles, register them with the CondSvc

Reimplemented from AthCommonDataStore< AthCommonMsg< Algorithm > >.

Reimplemented in AthAnalysisAlgorithm, AthFilterAlgorithm, AthHistogramAlgorithm, and PyAthena::Alg.

Definition at line 66 of file AthAlgorithm.cxx.

66 {
68
69 if (sc.isFailure()) {
70 return sc;
71 }
72 ServiceHandle<ICondSvc> cs("CondSvc",name());
73 for (auto h : outputHandles()) {
74 if (h->isCondition() && h->mode() == Gaudi::DataHandle::Writer) {
75 // do this inside the loop so we don't create the CondSvc until needed
76 if ( cs.retrieve().isFailure() ) {
77 ATH_MSG_WARNING("no CondSvc found: won't autoreg WriteCondHandles");
78 return StatusCode::SUCCESS;
79 }
80 if (cs->regHandle(this,*h).isFailure()) {
81 sc = StatusCode::FAILURE;
82 ATH_MSG_ERROR("unable to register WriteCondHandle " << h->fullKey()
83 << " with CondSvc");
84 }
85 }
86 }
87 return sc;
88}
#define ATH_MSG_ERROR(x)
static Double_t sc
virtual StatusCode sysInitialize() override
Override sysInitialize.
AthCommonDataStore(const std::string &name, T... args)
virtual std::vector< Gaudi::DataHandle * > outputHandles() const override
::StatusCode StatusCode
StatusCode definition for legacy code.

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< Algorithm > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< Algorithm > >::updateVHKA ( Gaudi::Details::PropertyBase & )
inlineinherited

Definition at line 308 of file AthCommonDataStore.h.

308 {
309 // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310 // << " size: " << m_vhka.size() << endmsg;
311 for (auto &a : m_vhka) {
313 for (auto k : keys) {
314 k->setOwner(this);
315 }
316 }
317 }
std::vector< SG::VarHandleKeyArray * > m_vhka

◆ writeOutput()

void Analysis::CalibrationDataUpdater::writeOutput ( TObject * in,
const std::string & Name,
TFile * fOut ) const
private

Definition at line 196 of file CalibrationDataUpdater.cxx.

197{
198 // first check whether the output directory exists, and if not, create it
199 fOut->cd("/");
200 TDirectory* tdir = dynamic_cast<TDirectory*>(fOut);
201 string::size_type delim = Name.find("/");
202 while (delim != string::npos) {
203 string dir = Name.substr(0, delim);
204 TDirectory* newdir = tdir->GetDirectory(dir.c_str());
205 if (! newdir) newdir = tdir->mkdir(dir.c_str());
206 if (! newdir->cd()) {
207 ATH_MSG_WARNING( name() << ": Name now: " << Name << "; pwd: "
208 << gDirectory->GetPath() << "; cd() to subdir "
209 << dir << " failed!" );
210 };
211 tdir = newdir;
212 Name = Name.substr(delim+1, string::npos);
213 delim = Name.find("/");
214 }
215
216 // then write the named object
217 ATH_MSG_INFO( name() << ": writing object " << Name << " to directory "
218 << gDirectory->GetPath() );
219 in->Write(Name.c_str());
220}

Member Data Documentation

◆ m_DbRootFile

std::string Analysis::CalibrationDataUpdater::m_DbRootFile = ""
private

ROOT file to be entered in COOL.

Definition at line 64 of file CalibrationDataUpdater.h.

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< Algorithm > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default)

Definition at line 393 of file AthCommonDataStore.h.

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< Algorithm > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default)

Definition at line 390 of file AthCommonDataStore.h.

◆ m_extendedExtraObjects

DataObjIDColl AthAlgorithm::m_extendedExtraObjects
privateinherited

Definition at line 79 of file AthAlgorithm.h.

◆ m_inputRootFile

std::string Analysis::CalibrationDataUpdater::m_inputRootFile = ""
private

input ROOT file containing new results

Definition at line 61 of file CalibrationDataUpdater.h.

◆ m_overrideDefaults

Gaudi::Property Analysis::CalibrationDataUpdater::m_overrideDefaults = false
private

flag if these results are to be used as defaults (they will anyway if no other results exist for the particular combination of jet collection / tagging algorithm / operating point)

Definition at line 72 of file CalibrationDataUpdater.h.

◆ m_paramNames

std::vector<std::string> Analysis::CalibrationDataUpdater::m_paramNames
private

names of input and output parametrisations

Definition at line 67 of file CalibrationDataUpdater.h.

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< Algorithm > >::m_varHandleArraysDeclared
privateinherited

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< Algorithm > >::m_vhka
privateinherited

Definition at line 398 of file AthCommonDataStore.h.


The documentation for this class was generated from the following files: