ATLAS Offline Software
PFO_v1.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 // -*-c++-*-
7 
8 #include "xAODPFlow/versions/PFOAttributesAccessor_v1.h"
9 
10 namespace xAOD{
11 
12  template<class T> void PFO_v1::setAttribute(PFODetails::PFOAttributes AttributeType, const T& anAttribute) {
13  (*(PFOAttributesAccessor_v1<T>::constAccessor(AttributeType)))(*this) = anAttribute;
14  }
15 
16  template<class T> bool PFO_v1::attribute(PFODetails::PFOAttributes AttributeType, T& anAttribute) const {
17 
18  const ConstAccessor<T>* acc = PFOAttributesAccessor_v1<T>::constAccessor(AttributeType);
19  //check if accessor pointer is NULL
20  if( ! acc ) { return false ;}
21  //check if variable is avaialable
22  if( ! acc->isAvailable( *this ) ) return false;
23  //set variable and return true
24  anAttribute =( *acc )( *this );
25  return true;
26  }
27 
28  template<class T> void PFO_v1::setAttribute(const std::string& AttributeType, const T& anAttribute) {
29 
30  const static Accessor<T> acc(AttributeType);
31  acc(*this) = anAttribute;
32 
33  }
34 
35  template<class T> bool PFO_v1::attribute(const std::string& AttributeType, T& anAttribute) const {
36  const static ConstAccessor<T> acc(AttributeType);
37  //Check if variable is available
38  if( !acc.isAvailable( *this ) ) return false;
39  else {
40  anAttribute = acc(*this);
41  return true;
42  }
43  }
44 
45  // Not good enough to just define the specialisations in the source file -- they must be declared publicly
46  /** Setter specialisation for PFOLeptonType */
47  template<> void PFO_v1::setAttribute(const std::string& AttributeType, const xAOD::PFODetails::PFOLeptonType& anAttribute);
48  /** Getter specialisation for PFOLeptonType */
49  template<> bool PFO_v1::attribute(const std::string& AttributeType, xAOD::PFODetails::PFOLeptonType& anAttribute) const;
50 
51  /** Setter specialisation for float */
52  template<> void PFO_v1::setAttribute(PFODetails::PFOAttributes AttributeType, const float& anAttribute);
53  /** Getter specialisation for float */
54  template<> bool PFO_v1::attribute(PFODetails::PFOAttributes AttributeType, float& anAttribute) const;
55 
56 
57  /** Setter specialisation for double with enum type argument */
58  template<> void PFO_v1::setAttribute(PFODetails::PFOAttributes AttributeType, const double& anAttribute);
59  /** Getter specialisation for double with enum type argument */
60  template<> bool PFO_v1::attribute(PFODetails::PFOAttributes AttributeType, double& anAttribute) const;
61 
62  /** Setter specialisation for double with string type argument */
63  template<> void PFO_v1::setAttribute(const std::string& AttributeType, const double& anAttribute);
64  /** Getter specialisation for double with string type argument */
65  template<> bool PFO_v1::attribute(const std::string& AttributeType, double& anAttribute) const;
66 
67  template<class T> void PFO_v1::convertLink(ElementLink<IParticleContainer>& IParticleLink, const ElementLink<T>& templateLink) {
68  ElementLink<T> tempLink;
69  tempLink.setElement(*templateLink);
70  tempLink.setStorableObject(templateLink.getStorableObjectRef());
71  tempLink.toPersistent();
72  IParticleLink.resetWithKeyAndIndex( tempLink.persKey(), tempLink.persIndex() );
73  }
74 
75 
76 
77 }//namespace xAOD