2   Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
    5 /// @author Nils Krumnack
 
   12 #include <AsgMessaging/MessageCheck.h>
 
   15 // method implementations
 
   20   template<typename T,typename Aux> template<typename T2> SysWriteHandle<T,Aux> ::
 
   21   SysWriteHandle (T2 *owner, const std::string& propertyName,
 
   22                  const std::string& propertyValue,
 
   23                  const std::string& propertyDescription)
 
   24     : AsgMessagingForward (owner), m_outputName (propertyValue)
 
   25     , m_evtStoreGetter ([owner] () {return &*owner->evtStore();})
 
   27     owner->declareProperty (propertyName, m_outputName, propertyDescription);
 
   31   template<typename T,typename Aux> template<typename T2> SysWriteHandle<T,Aux> ::
 
   32   SysWriteHandle (const std::string &outputName, T2 *owner)
 
   33     : AsgMessagingForward (owner), m_outputName (outputName)
 
   34     , m_evtStoreGetter ([owner] () {return &*owner->evtStore();})
 
   40   template<typename T,typename Aux> bool SysWriteHandle<T,Aux> ::
 
   41   empty () const noexcept
 
   43     return m_outputName.empty();
 
   48   template<typename T,typename Aux> SysWriteHandle<T,Aux> ::
 
   49   operator bool () const noexcept
 
   51     return !m_outputName.empty();
 
   56   template<typename T,typename Aux> std::string SysWriteHandle<T,Aux> ::
 
   57   getNamePattern () const
 
   64   template<typename T,typename Aux>
 
   65   StatusCode SysWriteHandle<T,Aux> ::
 
   66   initialize (SysListHandle& sysListHandle)
 
   68     return sysListHandle.addHandle (*this);
 
   73   template<typename T,typename Aux>
 
   74   StatusCode SysWriteHandle<T,Aux> ::
 
   75   initialize (SysListHandle& sysListHandle, SG::AllowEmptyEnum)
 
   78       return initialize (sysListHandle);
 
   80       return StatusCode::SUCCESS;
 
   85   template<typename T,typename Aux>
 
   86   const std::string& SysWriteHandle<T,Aux> ::
 
   87   getName (const CP::SystematicSet& sys) const
 
   89     auto cache = m_outputNameCache.find (sys);
 
   90     if (cache == m_outputNameCache.end())
 
   92       if (m_outputName.empty())
 
   93         throw std::logic_error ("uninitialized SysWriteHandle(" + m_outputName + ")");
 
   95         throw std::logic_error ("unknown systematic in SysWriteHandle(" + m_outputName + "): (" + sys.name() + ")");
 
  102   template<typename T,typename Aux>
 
  103   template<typename,typename>
 
  104   ::StatusCode SysWriteHandle<T,Aux> ::
 
  105   record (std::unique_ptr<T> object, const CP::SystematicSet& sys) const
 
  107     const std::string& name = getName (sys);
 
  109     return m_evtStore->record (object.release(), name);
 
  114   template<typename T,typename Aux>
 
  115   template<typename,typename>
 
  116   ::StatusCode SysWriteHandle<T,Aux> ::
 
  117   record (std::unique_ptr<T> object, std::unique_ptr<Aux> aux,
 
  118           const CP::SystematicSet& sys) const
 
  120     auto cache = m_outputNameCache.find (sys);
 
  121     if (cache == m_outputNameCache.end())
 
  123       if (m_outputName.empty())
 
  124         throw std::logic_error ("uninitialized SysWriteHandle(" + m_outputName + ")");
 
  126         throw std::logic_error ("unknown systematic in SysWriteHandle(" + m_outputName + "): (" + sys.name() + ")");
 
  129     if (m_evtStore->record (aux.release(), cache->second + "Aux.").isFailure())
 
  130       return StatusCode::FAILURE;
 
  131     if (m_evtStore->record (object.release(), cache->second).isFailure())
 
  132       return StatusCode::FAILURE;
 
  133     return StatusCode::SUCCESS;
 
  138   template<typename T,typename Aux>
 
  139   CP::SystematicSet SysWriteHandle<T,Aux> ::
 
  140   getInputAffecting (const ISystematicsSvc& /*svc*/) const
 
  142     return CP::SystematicSet ();
 
  147   template<typename T,typename Aux>
 
  148   StatusCode SysWriteHandle<T,Aux> ::
 
  149   fillSystematics (const ISystematicsSvc& svc,
 
  150                    const CP::SystematicSet& fullAffecting,
 
  151                    const std::vector<CP::SystematicSet>& sysList)
 
  154       m_evtStore = m_evtStoreGetter();
 
  155     for (auto& sys : sysList)
 
  158       ANA_CHECK (svc.makeSystematicsName (newName, m_outputName, sys));
 
  159       ANA_MSG_DEBUG ("SysWriteHandle: " << newName << " (" << sys.name() << ")");
 
  160       m_outputNameCache.emplace (sys, newName);
 
  162     ANA_CHECK (svc.setObjectSystematics (m_outputName, fullAffecting));
 
  163     return StatusCode::SUCCESS;