From 60788cfd2396f8680096ac3ea01f5c7dd7df1ec5 Mon Sep 17 00:00:00 2001
From: Walter Lampl <Walter.Lampl@cern.ch>
Date: Thu, 10 May 2012 14:27:29 +0200
Subject: [PATCH] Adapt ATN test to new UserDataSvc (UserDataExamples-00-09-00)

---
 .../UserDataExamples/cmt/requirements         |  49 ++++
 .../share/UserDataExamples_Reader.py          |  55 ++++
 .../share/UserDataExamples_Writer.py          |  63 +++++
 .../src/CreateDataWithUserData.cxx            | 261 ++++++++++++++++++
 .../src/CreateDataWithUserData.h              |  65 +++++
 .../src/ReadDataWithUserData.cxx              | 150 ++++++++++
 .../src/ReadDataWithUserData.h                |  49 ++++
 .../components/UserDataExamples_entries.cxx   |  13 +
 .../src/components/UserDataExamples_load.cxx  |   5 +
 .../test/UserDataExamples.xml                 |  33 +++
 10 files changed, 743 insertions(+)
 create mode 100644 Control/AthenaExamples/UserDataExamples/cmt/requirements
 create mode 100644 Control/AthenaExamples/UserDataExamples/share/UserDataExamples_Reader.py
 create mode 100644 Control/AthenaExamples/UserDataExamples/share/UserDataExamples_Writer.py
 create mode 100644 Control/AthenaExamples/UserDataExamples/src/CreateDataWithUserData.cxx
 create mode 100644 Control/AthenaExamples/UserDataExamples/src/CreateDataWithUserData.h
 create mode 100644 Control/AthenaExamples/UserDataExamples/src/ReadDataWithUserData.cxx
 create mode 100644 Control/AthenaExamples/UserDataExamples/src/ReadDataWithUserData.h
 create mode 100644 Control/AthenaExamples/UserDataExamples/src/components/UserDataExamples_entries.cxx
 create mode 100644 Control/AthenaExamples/UserDataExamples/src/components/UserDataExamples_load.cxx
 create mode 100644 Control/AthenaExamples/UserDataExamples/test/UserDataExamples.xml

diff --git a/Control/AthenaExamples/UserDataExamples/cmt/requirements b/Control/AthenaExamples/UserDataExamples/cmt/requirements
new file mode 100644
index 000000000000..85b1b03a6f06
--- /dev/null
+++ b/Control/AthenaExamples/UserDataExamples/cmt/requirements
@@ -0,0 +1,49 @@
+package UserDataExamples
+
+author Yushu Yao <yyao@lbl.gov>
+
+use AtlasPolicy		AtlasPolicy-* 
+use AthenaKernel 	AthenaKernel-* 		Control
+use AthenaBaseComps	AthenaBaseComps-*	Control
+use AtlasReflex  	AtlasReflex-*  		External -no_auto_imports
+
+use GaudiInterface      GaudiInterface-*        External 
+use AtlasBoost          AtlasBoost-*            External
+use AtlasCLHEP          AtlasCLHEP-*            External
+use AtlasROOT           AtlasROOT-*             External
+use AtlasReflex         AtlasReflex-*           External -no_auto_imports
+use DataModel           DataModel-*             Control
+use StoreGate           StoreGate-*             Control
+use Navigation	        Navigation-*            Control
+
+use CaloEvent         CaloEvent-*	        Calorimeter
+
+library UserDataExamples *.cxx -s=components *.cxx 
+apply_pattern component_library
+
+apply_pattern declare_joboptions \
+   files="*.py"
+
+#private
+#apply_pattern install_runtime
+
+#use TestTools      TestTools-*        AtlasTest -no_auto_imports 
+
+#apply_pattern athenarun_test name="TUserDataMakeData" \
+#              pre_script="../cmt/setup.sh"      \             
+#              options="UserDataExamples/UserDataExamples_Writer.py" \
+#              post_script="${TESTTOOLSROOT}/share/post.sh TUserDataMakeData \"^[^UCR]\|^.[^sre]\""
+
+#apply_pattern athenarun_test name="TUserDataReadData" \
+#              pre_script="../cmt/setup.sh"      \             
+#              options="UserDataExamples/UserDataExamples_Reader.py" \
+#              post_script="${TESTTOOLSROOT}/share/post.sh TUserDataReadData \"^[^UCR]\|^.[^sre]\""
+
+
+
+macro UserDataExample_TestConfiguration "../test/UserDataExample.xml"
+
+private
+use TestPolicy TestPolicy-*
+apply_pattern validate_xml
+public
\ No newline at end of file
diff --git a/Control/AthenaExamples/UserDataExamples/share/UserDataExamples_Reader.py b/Control/AthenaExamples/UserDataExamples/share/UserDataExamples_Reader.py
new file mode 100644
index 000000000000..825953443f1e
--- /dev/null
+++ b/Control/AthenaExamples/UserDataExamples/share/UserDataExamples_Reader.py
@@ -0,0 +1,55 @@
+PoolESDInput=['UserDataIncluded.pool.root']
+
+# Get a handle to the ServiceManager
+from AthenaCommon.AppMgr import ServiceMgr as svcMgr
+# Get a handle to the ApplicationManager
+from AthenaCommon.AppMgr import theApp
+
+from AthenaCommon.AlgSequence import AlgSequence
+topSequence = AlgSequence()
+topSequence.StopOverride = False
+
+#Pool input
+import AthenaPoolCnvSvc.ReadAthenaPool
+# EventInfo Converters
+include( "EventAthenaPool/EventAthenaPool_joboptions.py" )
+
+# Pool input (Change this to use a different file)
+from AthenaCommon.AppMgr import ServiceMgr
+if not hasattr(ServiceMgr, 'EventSelector'):
+   import AthenaPoolCnvSvc.ReadAthenaPool
+ServiceMgr.EventSelector.InputCollections = PoolESDInput
+
+from RecExConfig.ObjKeyStore import objKeyStore
+objKeyStore.readInputFile('RecExPers/OKS_streamESD.py')
+
+
+#--------------------------------------------------------------
+# Set output level threshold (2=DEBUG, 3=INFO, 4=WARNING, 5=ERROR, 6=FATAL )
+#-------------------------------------------------------------
+svcMgr.MessageSvc.OutputLevel      = INFO
+#increase the number of letter reserved to the alg/tool name from 18 to 30
+svcMgr.MessageSvc.Format = "% F%50W%S%7W%R%T %0W%M" 
+svcMgr.MessageSvc.defaultLimit = 9999999  # all messages
+svcMgr.MessageSvc.useColors = False
+svcMgr.MessageSvc.defaultLimit=1000000000
+
+
+
+#--------------------------------------------------------------
+# Event related parameters
+#--------------------------------------------------------------
+# Number of events to be processed (default is 10)
+theApp.EvtMax = 1000
+theApp.EvtSel = "EventSelector"
+
+from UserDataExamples.UserDataExamplesConf import UserDataExamples__ReadDataWithUserData as UserDataStoreReader
+theUserDataStoreReader=UserDataStoreReader("UserDataReader")
+theUserDataStoreReader.ContainerName="CaloCalTopoCluster"
+theUserDataStoreReader.OutputLevel=DEBUG
+topSequence+=theUserDataStoreReader
+
+
+#theAuditorSvc = svcMgr.AuditorSvc
+#theAuditorSvc.Auditors  += [ "ChronoAuditor"]
+#theApp.AuditAlgorithms = True
diff --git a/Control/AthenaExamples/UserDataExamples/share/UserDataExamples_Writer.py b/Control/AthenaExamples/UserDataExamples/share/UserDataExamples_Writer.py
new file mode 100644
index 000000000000..e8ab2b15e054
--- /dev/null
+++ b/Control/AthenaExamples/UserDataExamples/share/UserDataExamples_Writer.py
@@ -0,0 +1,63 @@
+ #use McEventSelector
+import AthenaCommon.AtlasUnixGeneratorJob
+
+# Get a handle to the ServiceManager
+from AthenaCommon.AppMgr import ServiceMgr as svcMgr
+# Get a handle to the ApplicationManager
+from AthenaCommon.AppMgr import theApp
+
+from AthenaCommon.AlgSequence import AlgSequence
+topSequence = AlgSequence()
+topSequence.StopOverride = False
+
+
+svcMgr.EventSelector.RunNumber         = 100
+svcMgr.EventSelector.EventsPerRun      = 1000
+svcMgr.EventSelector.FirstEvent        = 1
+svcMgr.EventSelector.EventsPerLB       = 100
+svcMgr.EventSelector.FirstLB           = 1
+svcMgr.EventSelector.InitialTimeStamp  = 0
+svcMgr.EventSelector.TimeStampInterval = 5
+theApp.EvtMax                          = 20
+
+
+#--------------------------------------------------------------
+# Set output level threshold (2=DEBUG, 3=INFO, 4=WARNING, 5=ERROR, 6=FATAL )
+#-------------------------------------------------------------
+svcMgr.MessageSvc.OutputLevel      = INFO 
+#increase the number of letter reserved to the alg/tool name from 18 to 30
+svcMgr.MessageSvc.Format = "% F%50W%S%7W%R%T %0W%M" 
+svcMgr.MessageSvc.defaultLimit = 9999999  # all messages
+svcMgr.MessageSvc.useColors = False
+svcMgr.MessageSvc.defaultLimit=100000000
+
+from AthenaServices.TheUserDataSvc import TheUserDataSvc
+svcMgr += TheUserDataSvc("UserDataSvc")
+#svcMgr.UserDataSvc.OutputLevel=DEBUG
+
+from UserDataExamples.UserDataExamplesConf import UserDataExamples__CreateDataWithUserData as UserDataSvcWriter 
+theUserDataSvcWriter=UserDataSvcWriter("UserDataWriter")
+theUserDataSvcWriter.ContainerName="CaloCalTopoCluster"
+#theUserDataStoreWriter.OutputLevel=DEBUG
+topSequence+=theUserDataSvcWriter
+
+from UserDataExamples.UserDataExamplesConf import UserDataExamples__ReadDataWithUserData as UserDataStoreReader
+theUserDataStoreReader=UserDataStoreReader("UserDataReader")
+theUserDataStoreReader.ContainerName="CaloCalTopoCluster"
+theUserDataStoreReader.OutputLevel=DEBUG
+topSequence+=theUserDataStoreReader
+
+# create stream
+from AthenaPoolCnvSvc import WriteAthenaPool
+
+
+from AthenaServices.AthenaServicesConf import AthenaOutputStream
+streamOut = AthenaOutputStream("StreamOut")
+streamOut.WritingTool = "AthenaPoolOutputStreamTool"
+streamOut.EvtConversionSvc = "AthenaPoolCnvSvc" 
+streamOut.OutputFile    = "UserDataIncluded.pool.root"
+#streamOut.ForceRead = True
+streamOut.ItemList+=["EventInfo#*","CaloClusterContainer#*","UserDataStore#*"]
+
+
+topSequence+=streamOut
diff --git a/Control/AthenaExamples/UserDataExamples/src/CreateDataWithUserData.cxx b/Control/AthenaExamples/UserDataExamples/src/CreateDataWithUserData.cxx
new file mode 100644
index 000000000000..9dc0c55a1da8
--- /dev/null
+++ b/Control/AthenaExamples/UserDataExamples/src/CreateDataWithUserData.cxx
@@ -0,0 +1,261 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+#include "CreateDataWithUserData.h"
+#include "CaloEvent/CaloClusterContainer.h"
+#include "DataModel/UserDataStore.h"
+#include "AthenaKernel/errorcheck.h"
+
+using namespace UserDataExamples;
+
+CreateDataWithUserData::CreateDataWithUserData( const std::string& name, 
+				      ISvcLocator* pSvcLocator ) : 
+  ::AthAlgorithm( name, pSvcLocator ), m_userDataSvc("UserDataSvc",name)
+{
+  declareProperty("UserDataSvc",m_userDataSvc);
+  declareProperty("ContainerName",m_contName="");
+  declareProperty("VecSize",m_vecSize=10);
+  nEvents=0;
+  nClusters=0;
+  nAttributes=0;
+}
+
+// Destructor
+///////////////
+CreateDataWithUserData::~CreateDataWithUserData()
+{}
+
+
+StatusCode CreateDataWithUserData::initialize() {
+  ATH_MSG_INFO ("Initializing " << name() << "...");
+
+  StatusCode sc=m_userDataSvc.retrieve();
+  if (sc.isFailure()) {
+    msg(MSG::ERROR) << "Failed to retrieve UserDataSvc " << m_userDataSvc << endreq;
+    return sc;
+  }
+
+
+
+  return StatusCode::SUCCESS;
+}
+
+StatusCode CreateDataWithUserData::finalize() {
+  msg(MSG::INFO) << "Counters: Events: " << nEvents << ", Clusters: " << nClusters << ", Attributes: " << nAttributes << endreq;
+
+  return StatusCode::SUCCESS;
+}
+
+StatusCode CreateDataWithUserData::execute() { 
+  
+  std::vector<int32_t> vec(m_vecSize,-5);
+  std::vector<uint32_t> vecu(m_vecSize,15);
+  std::vector<float> vecf(m_vecSize,5.5);
+  std::vector<double> vecd(m_vecSize,5.55);
+
+  ++nEvents;
+  CaloClusterContainer* clusterContainer=new CaloClusterContainer();
+
+  StatusCode sc=evtStore()->record(clusterContainer,m_contName);
+  if (sc.isFailure()) {
+    msg(MSG::ERROR) << "Failed to record CaloClusterContainer with name " << m_contName << endreq;
+    return sc;
+  }
+  std::string label;
+  int counter=0;
+  for(unsigned nClu=0;nClu<500;++nClu) {
+    CaloCluster* cluster=new CaloCluster(1.0,1.0);
+    clusterContainer->push_back(cluster);
+    ++nClusters;
+    //Create 20 attributes for caloCluster:
+    for (unsigned i=0;i<2;++i) {
+      std::stringstream sLabel;
+      sLabel << "Counter_" << i;
+      label=sLabel.str();
+      sc=m_userDataSvc->decorateElement(*cluster,label,counter);
+      if (sc.isFailure()) {
+	msg(MSG::ERROR) << "Failed to decorate CaloCluster with an attribute called " << label << endreq;
+	return sc;
+      }
+      else {
+	ATH_MSG_DEBUG("Successfully decorate CaloCluster with an attribute called " << label);
+	++nAttributes;
+      }
+
+      int counterOut=0;
+      CHECK(m_userDataSvc->retrieve(*cluster,label,counterOut));
+      if (!checkvalues(counter,counterOut,label)) return StatusCode::FAILURE;
+      
+      //Same with double;
+      double dbl=0.5+counter;
+      label=sLabel.str()+"d";
+      sc=m_userDataSvc->decorateElement(*cluster,label,dbl);
+      if (sc.isFailure()) {
+	msg(MSG::ERROR) << "Failed to decorate CaloCluster with an attribute called " << label << endreq;
+	return sc;
+      }
+      else {
+	ATH_MSG_DEBUG("Successfully decorate CaloCluster with an attribute called " << label);
+	++nAttributes;
+      }
+
+      double dblOut=0;
+      CHECK(m_userDataSvc->retrieve(*cluster,label,dblOut));
+      if (!checkvalues(dbl,dblOut,label)) return StatusCode::FAILURE;
+
+
+      //Same with unsigned:
+      uint32_t cnt_u=counter+1000;
+      label=sLabel.str()+"u";
+      sc=m_userDataSvc->decorateElement(*cluster,label,cnt_u);
+      if (sc.isFailure()) {
+	msg(MSG::ERROR) << "Failed to decorate CaloCluster with an attribute called " << label << endreq;
+	return sc;
+      }
+      else {
+	ATH_MSG_DEBUG("Successfully decorate CaloCluster with an attribute called " << label);
+	++nAttributes;
+      }
+      
+
+      uint32_t cnt_uOut=0;
+      CHECK(m_userDataSvc->retrieve(*cluster,label,cnt_uOut));
+      if (!checkvalues(cnt_u,cnt_uOut,label)) return StatusCode::FAILURE;
+
+
+      //Same with float:
+      float cnt_f=counter*3.14;
+      label=sLabel.str()+"f";
+      sc=m_userDataSvc->decorateElement(*cluster,label,cnt_f);
+      if (sc.isFailure()) {
+	msg(MSG::ERROR) << "Failed to decorate CaloCluster with an attribute called " << label << endreq;
+	return sc;
+      }
+      else {
+	ATH_MSG_DEBUG("Successfully decorate CaloCluster with an attribute called " << label);
+	++nAttributes;
+      }
+      
+      float cnt_fOut=0;
+      CHECK(m_userDataSvc->getElementDecoration(*cluster,label,cnt_fOut));
+      if (!checkvalues(cnt_fOut,cnt_fOut,label)) return StatusCode::FAILURE;
+
+
+      //Same with bool
+      bool b=(counter%2)==1;
+      label=sLabel.str()+"b";
+      sc=m_userDataSvc->decorateElement(*cluster,label,b);
+      if (sc.isFailure()) {
+	msg(MSG::ERROR) << "Failed to decorate CaloCluster with an attribute called " << label << endreq;
+	return sc;
+      }
+      else {
+	ATH_MSG_DEBUG("Successfully decorate CaloCluster with an attribute called " << label);
+	++nAttributes;
+      }
+      bool bout=false;
+      CHECK(m_userDataSvc->getElementDecoration(*cluster,label,bout));
+      if (!checkvalues(b,bout,label)) return StatusCode::FAILURE;
+
+
+      void* x=(void*)(&vec);
+      //std::string l=labelidx+"vVirt";
+      label=sLabel.str()+"vVirt";
+      if (m_userDataSvc->vdecorateElement(*cluster,label,typeid(std::vector<int32_t>),x)) {
+	msg(MSG::ERROR) << "vdecorateElement failed" << endreq;
+	return StatusCode::FAILURE;
+      }
+      
+      void* vecOut=0;
+      int stat=m_userDataSvc->vgetElementDecoration(*cluster,label,typeid(std::vector<int32_t>),vecOut);
+      if (stat) {
+	msg(MSG::ERROR) << "vgetElementDecoration with label=" << label << " failed." << endreq;
+	return StatusCode::FAILURE;
+      }
+      
+      std::vector<int32_t>* vptrOut=static_cast<std::vector<int32_t>* >(vecOut); 
+      if (!checkvalues(vec,*vptrOut,label)) return StatusCode::FAILURE;
+            
+
+      label=sLabel.str()+"v";
+      sc=m_userDataSvc->decorateElement(*cluster,label,vec);
+      if (sc.isFailure()) {
+	msg(MSG::ERROR) << "Failed to decorate CaloCluster with an attribute called " << label << endreq;
+	return sc;
+      }
+      else {
+	ATH_MSG_DEBUG("Successfully decorate CaloCluster with an attribute called " << label);
+	++nAttributes;
+      }
+
+
+      std::vector<int32_t> vecOut1;
+      CHECK(m_userDataSvc->retrieve(*cluster,label,vecOut1));
+      if (!checkvalues(vec,vecOut1,label)) return StatusCode::FAILURE;
+
+
+      label=sLabel.str()+"vu";
+      sc=m_userDataSvc->decorateElement(*cluster,label,vecu);
+      if (sc.isFailure()) {
+	msg(MSG::ERROR) << "Failed to decorate CaloCluster with an attribute called " << label << endreq;
+	return sc;
+      }
+      else {
+	ATH_MSG_DEBUG("Successfully decorate CaloCluster with an attribute called " << label);
+	++nAttributes;
+      }
+
+      std::vector<uint32_t> vecuOut;
+      CHECK(m_userDataSvc->retrieve(*cluster,label,vecuOut));
+      if (!checkvalues(vecu,vecuOut,label)) return StatusCode::FAILURE;
+
+
+      label=sLabel.str()+"vf";
+      sc=m_userDataSvc->decorateElement(*cluster,label,vecf);
+      if (sc.isFailure()) {
+	msg(MSG::ERROR) << "Failed to decorate CaloCluster with an attribute called " << label << endreq;
+	return sc;
+      }
+      else {
+	ATH_MSG_DEBUG("Successfully decorate CaloCluster with an attribute called " << label);
+	++nAttributes;
+      }
+
+      std::vector<float> vecfOut;
+      CHECK(m_userDataSvc->retrieve(*cluster,label,vecfOut));
+      if (!checkvalues(vecf,vecfOut,label)) return StatusCode::FAILURE;
+
+
+      label=sLabel.str()+"vd";
+      sc=m_userDataSvc->decorateElement(*cluster,label,vecd);
+      if (sc.isFailure()) {
+	msg(MSG::ERROR) << "Failed to decorate CaloCluster with an attribute called " << label << endreq;
+	return sc;
+      }
+      else {
+	ATH_MSG_DEBUG("Successfully decorate CaloCluster with an attribute called " << label);
+	++nAttributes;
+      }
+
+      std::vector<double> vecdOut;
+      CHECK(m_userDataSvc->retrieve(*cluster,label,vecdOut));
+      if (!checkvalues(vecd,vecdOut,label)) return StatusCode::FAILURE;
+      
+    }
+    ++counter;
+  } // loop over clusters
+
+  label="EventDeco";
+  sc=m_userDataSvc->decorateEvent(label,42.0);
+  if (sc.isFailure()) {
+    msg(MSG::ERROR) << "Failed to record EventDecoration called " << label << endreq;
+  }
+
+  double fOut;
+  CHECK(m_userDataSvc->retrieve(label,fOut));
+  if (!checkvalues(42.0,fOut,label)) return StatusCode::FAILURE;
+
+  return StatusCode::SUCCESS;
+}
+
diff --git a/Control/AthenaExamples/UserDataExamples/src/CreateDataWithUserData.h b/Control/AthenaExamples/UserDataExamples/src/CreateDataWithUserData.h
new file mode 100644
index 000000000000..27df0b2106c5
--- /dev/null
+++ b/Control/AthenaExamples/UserDataExamples/src/CreateDataWithUserData.h
@@ -0,0 +1,65 @@
+///////////////////////// -*- C++ -*- /////////////////////////////
+
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef USERDATASTORETEST_CREATEUSERDATAWITHDATA_H
+#define USERDATASTORETEST_CREATEUSERDATAWITHDATA_H
+
+#include <string>
+#include "AthenaBaseComps/AthAlgorithm.h"
+#include "GaudiKernel/ServiceHandle.h"
+#include "AthenaKernel/IUserDataSvc.h"
+
+
+namespace UserDataExamples {
+
+  class CreateDataWithUserData
+    : public ::AthAlgorithm
+  { 
+    
+  public: 
+    /// Constructor with parameters: 
+    CreateDataWithUserData( const std::string& name, ISvcLocator* pSvcLocator );
+    
+    /// Destructor: 
+    virtual ~CreateDataWithUserData(); 
+    
+    // Athena algorithm's Hooks
+    virtual StatusCode  initialize();
+    virtual StatusCode  execute();
+    virtual StatusCode  finalize();
+    
+  private: 
+    
+    /// Default constructor: 
+    CreateDataWithUserData();
+    
+    ServiceHandle<IUserDataSvc> m_userDataSvc; 
+    
+    std::string m_contName;
+    unsigned m_vecSize;
+    
+    //counters:
+    unsigned nEvents;
+    unsigned nClusters;
+    unsigned nAttributes;
+    
+    template<typename T>
+    bool checkvalues(const T& a, const T& b, const std::string& label);
+
+
+  }; 
+  template<typename T>
+  bool CreateDataWithUserData::checkvalues(const T& a, const T& b, const std::string& label) {
+    if (a==b) 
+      return true;
+    else {
+      msg(MSG::ERROR) << "Values with label << " << label << " differ!" << endreq;
+      return false;
+    }
+  }
+
+}
+#endif
diff --git a/Control/AthenaExamples/UserDataExamples/src/ReadDataWithUserData.cxx b/Control/AthenaExamples/UserDataExamples/src/ReadDataWithUserData.cxx
new file mode 100644
index 000000000000..a0ccb481bdd0
--- /dev/null
+++ b/Control/AthenaExamples/UserDataExamples/src/ReadDataWithUserData.cxx
@@ -0,0 +1,150 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+#include "ReadDataWithUserData.h"
+#include "CaloEvent/CaloClusterContainer.h"
+#include "DataModel/UserDataStore.h"
+#include "AthenaKernel/errorcheck.h"
+
+using namespace UserDataExamples;
+
+ReadDataWithUserData::ReadDataWithUserData( const std::string& name, 
+					    ISvcLocator* pSvcLocator ) : 
+  ::AthAlgorithm( name, pSvcLocator ), m_userDataSvc("UserDataSvc",name)
+{
+  declareProperty("UserDataSvc",m_userDataSvc);
+  declareProperty("ContainerName",m_contName="");
+  m_events=0;
+  nAttributes=0;
+}
+
+// Destructor
+///////////////
+ReadDataWithUserData::~ReadDataWithUserData()
+{}
+
+
+StatusCode ReadDataWithUserData::initialize() {
+  ATH_MSG_INFO ("Initializing " << name() << "...");
+
+  StatusCode sc=m_userDataSvc.retrieve();
+  if (sc.isFailure()) {
+    msg(MSG::ERROR) << "Failed to retrieve UserDataSvc " << m_userDataSvc << endreq;
+    return sc;
+  }
+
+
+
+  return StatusCode::SUCCESS;
+}
+
+StatusCode ReadDataWithUserData::finalize() {
+  //msg(MSG::INFO) << "Counters: Events: " << m_events << ", Clusters: " << nCluster << ", Attributes: " << nAttibutes << endreq;
+
+  return StatusCode::SUCCESS;
+}
+
+StatusCode ReadDataWithUserData::execute() { 
+  
+  ++m_events;
+  const CaloClusterContainer* clusterContainer=NULL;
+
+  StatusCode sc=evtStore()->retrieve(clusterContainer,m_contName);
+  if (sc.isFailure()) {
+    msg(MSG::ERROR) << "Failed to retrieve CaloClusterContainer with name " << m_contName << endreq;
+    return sc;
+  }
+  
+
+  std::string label;
+  int counter=0;
+  size_t vidx=0;
+  unsigned nCluster=0;
+  CaloClusterContainer::const_iterator cit=clusterContainer->begin();
+  CaloClusterContainer::const_iterator cit_e=clusterContainer->end();
+  for(;cit!=cit_e;++cit) {
+    const CaloCluster* cluster=*cit;
+    ++nCluster;
+    for (unsigned i=0;i<2;++i) {
+      std::stringstream sLabel;
+      sLabel << "Counter_" << i;
+      label=sLabel.str();
+      int counterOut=0;
+      CHECK(m_userDataSvc->retrieve(*cluster,label,counterOut));
+      msg(MSG::DEBUG) << "Cluster #" << nCluster << ", label '" << label << "' value=" << counterOut << endreq;          
+
+      //Same with double;
+      label=sLabel.str()+"d";
+      double dblOut=0;
+      CHECK(m_userDataSvc->retrieve(*cluster,label,dblOut));
+      msg(MSG::DEBUG) << "Cluster #" << nCluster << ", label '" << label << "' value=" << dblOut << endreq;          
+
+      //Same with unsigned:
+      label=sLabel.str()+"u";
+      uint32_t cnt_uOut=0;
+      CHECK(m_userDataSvc->retrieve(*cluster,label,cnt_uOut));
+      msg(MSG::DEBUG) << "Cluster #" << nCluster << ", label '" << label << "' value=" << cnt_uOut << endreq;
+
+      //Same with float:
+      label=sLabel.str()+"f";
+      float cnt_fOut=0;
+      CHECK(m_userDataSvc->getElementDecoration(*cluster,label,cnt_fOut));
+      msg(MSG::DEBUG) << "Cluster #" << nCluster << ", label '" << label << "' value=" << cnt_fOut << endreq;
+
+
+      label=sLabel.str()+"b";
+      bool bout=false;
+      CHECK(m_userDataSvc->getElementDecoration(*cluster,label,bout));
+      msg(MSG::DEBUG) << "Cluster #" << nCluster << ", label '" << label << "' value=" << bout << endreq;
+
+
+      label=sLabel.str()+"vVirt";
+      void* vecOutvoid=0;
+      if (m_userDataSvc->vgetElementDecoration(*cluster,label,typeid(std::vector<int32_t>),vecOutvoid)) {
+	msg(MSG::ERROR) << "vgetElementDecoration failed" << endreq;
+	return StatusCode::FAILURE;
+      }
+      std::vector<int32_t>* vptrOut=static_cast<std::vector<int32_t>* >(vecOutvoid); 
+      vidx=m_events%(vptrOut->size()-1);
+      msg(MSG::DEBUG) << "Cluster #" << nCluster << ", label '" << label << "' size=" << vptrOut->size() << "value[" << vidx << "]=" << vptrOut->at(vidx) << endreq;
+            
+
+      label=sLabel.str()+"v";
+      std::vector<int32_t> vecOut1;
+      CHECK(m_userDataSvc->retrieve(*cluster,label,vecOut1));
+      vidx=m_events%(vecOut1.size()-1);
+      msg(MSG::DEBUG) << "Cluster #" << nCluster << ", label '" << label << "' size=" << vecOut1.size() << "value[" << vidx << "]=" << vecOut1[vidx] << endreq;
+
+
+      label=sLabel.str()+"vu";
+      std::vector<uint32_t> vecuOut;
+      CHECK(m_userDataSvc->retrieve(*cluster,label,vecuOut));
+      vidx=m_events%(vecuOut.size()-1);
+      msg(MSG::DEBUG) << "Cluster #" << nCluster << ", label '" << label << "' size=" << vecuOut.size() << "value[" << vidx << "]=" << vecuOut[vidx] << endreq;
+
+
+      label=sLabel.str()+"vf";
+      std::vector<float> vecfOut;
+      CHECK(m_userDataSvc->retrieve(*cluster,label,vecfOut));
+      vidx=m_events%(vecfOut.size()-1);
+      msg(MSG::DEBUG) << "Cluster #" << nCluster << ", label '" << label << "' size=" << vecfOut.size() << "value[" << vidx << "]=" << vecfOut[vidx] << endreq;
+
+
+      label=sLabel.str()+"vd";
+      std::vector<double> vecdOut;
+      CHECK(m_userDataSvc->retrieve(*cluster,label,vecdOut));
+      vidx=m_events%(vecfOut.size()-1);
+      msg(MSG::DEBUG) << "Cluster #" << nCluster << ", label '" << label << "' size=" << vecdOut.size() << "value[" << vidx << "]=" << vecdOut[vidx] << endreq;      
+    }
+    ++counter;
+  } // loop over clusters
+
+  label="EventDeco";
+  double fOut;
+  CHECK(m_userDataSvc->retrieve(label,fOut));
+  msg(MSG::DEBUG) << "EventDeco with label '" << label << "' value=" << fOut << endreq;
+
+  return StatusCode::SUCCESS;
+}
+
diff --git a/Control/AthenaExamples/UserDataExamples/src/ReadDataWithUserData.h b/Control/AthenaExamples/UserDataExamples/src/ReadDataWithUserData.h
new file mode 100644
index 000000000000..7e954d3c4080
--- /dev/null
+++ b/Control/AthenaExamples/UserDataExamples/src/ReadDataWithUserData.h
@@ -0,0 +1,49 @@
+///////////////////////// -*- C++ -*- /////////////////////////////
+
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef USERDATASTORETEST_READUSERDATAWITHDATA_H
+#define USERDATASTORETEST_READUSERDATAWITHDATA_H
+
+#include <string>
+#include "AthenaBaseComps/AthAlgorithm.h"
+#include "GaudiKernel/ServiceHandle.h"
+#include "AthenaKernel/IUserDataSvc.h"
+
+
+namespace UserDataExamples {
+
+  class ReadDataWithUserData
+    : public ::AthAlgorithm
+  { 
+    
+  public: 
+    /// Constructor with parameters: 
+    ReadDataWithUserData( const std::string& name, ISvcLocator* pSvcLocator );
+    
+    /// Destructor: 
+    virtual ~ReadDataWithUserData(); 
+    
+    // Athena algorithm's Hooks
+    virtual StatusCode  initialize();
+    virtual StatusCode  execute();
+    virtual StatusCode  finalize();
+    
+  private: 
+    
+    /// Default constructor: 
+    ReadDataWithUserData();
+    
+    ServiceHandle<IUserDataSvc> m_userDataSvc; 
+    
+    std::string m_contName;
+    
+    //counters:
+    unsigned m_events;
+    unsigned nAttributes;
+    
+  }; 
+}
+#endif
diff --git a/Control/AthenaExamples/UserDataExamples/src/components/UserDataExamples_entries.cxx b/Control/AthenaExamples/UserDataExamples/src/components/UserDataExamples_entries.cxx
new file mode 100644
index 000000000000..0d232ce753da
--- /dev/null
+++ b/Control/AthenaExamples/UserDataExamples/src/components/UserDataExamples_entries.cxx
@@ -0,0 +1,13 @@
+//$Id: UserDataExamples_entries.cxx,v 1.6 2008-07-07 05:35:52 yyao Exp $
+#include "GaudiKernel/DeclareFactoryEntries.h"
+#include "../CreateDataWithUserData.h"
+#include "../ReadDataWithUserData.h"
+
+
+DECLARE_NAMESPACE_ALGORITHM_FACTORY( UserDataExamples, CreateDataWithUserData )
+DECLARE_NAMESPACE_ALGORITHM_FACTORY( UserDataExamples, ReadDataWithUserData )
+
+DECLARE_FACTORY_ENTRIES(UserDataExamples) {
+  DECLARE_NAMESPACE_ALGORITHM( UserDataExamples, CreateDataWithUserData )
+  DECLARE_NAMESPACE_ALGORITHM( UserDataExamples, ReadDataWithUserData )
+}
diff --git a/Control/AthenaExamples/UserDataExamples/src/components/UserDataExamples_load.cxx b/Control/AthenaExamples/UserDataExamples/src/components/UserDataExamples_load.cxx
new file mode 100644
index 000000000000..747de88123c7
--- /dev/null
+++ b/Control/AthenaExamples/UserDataExamples/src/components/UserDataExamples_load.cxx
@@ -0,0 +1,5 @@
+//$Id: UserDataExamples_load.cxx,v 1.4 2008-07-07 05:35:52 yyao Exp $
+#include "GaudiKernel/LoadFactoryEntries.h"
+
+LOAD_FACTORY_ENTRIES(UserDataExamples)
+
diff --git a/Control/AthenaExamples/UserDataExamples/test/UserDataExamples.xml b/Control/AthenaExamples/UserDataExamples/test/UserDataExamples.xml
new file mode 100644
index 000000000000..29f234658c81
--- /dev/null
+++ b/Control/AthenaExamples/UserDataExamples/test/UserDataExamples.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0"?>
+<!DOCTYPE unifiedTestConfiguration SYSTEM "http://www.hep.ucl.ac.uk/atlas/AtlasTesting/DTD/unifiedTestConfiguration.dtd">
+ 
+<unifiedTestConfiguration> 
+<atn>
+ <TEST name="UserDataWriter" type="athena" suite="Examples">
+     <options_atn>UserDataExamples/UserDataExamples_Writer.py</options_atn>
+     <author>Walter Lampl</author>
+     <mailto>walter.lampl@cern.ch</mailto>
+     <package_atn>Control/AthenaExamples/UserDataExamples</package_atn>
+     <expectations>
+        <successMessage>Finalized successfully</successMessage>
+        <errorMessage>ERROR</errorMessage>
+     </expectations>
+ </TEST>
+ <TEST name="UserDataReader" type="athena" suite="Examples">
+     <options_atn>UserDataExamples/UserDataExamples_Reader.py</options_atn>
+     <author>Walter Lampl</author>
+     <mailto>walter.lampl@cern.ch</mailto>
+     <package_atn>Control/AthenaExamples/UserDataExamples</package_atn>
+     <expectations>
+        <successMessage>Finalized successfully</successMessage>
+        <errorMessage>ERROR</errorMessage>
+     </expectations>
+     <prerequisite>UserDataWriter</prerequisite>
+
+
+ </TEST>
+
+
+
+</atn>
+</unifiedTestConfiguration>
\ No newline at end of file
-- 
GitLab