Newer
Older
TB_Chris / TbUT / src / .svn / text-base / TbUTClusterCreatorAlgorithm.cpp.svn-base
  1. /*
  2. * TbUTClusterCreatorAlgorithm.cpp
  3. *
  4. * Created on: Jan 6, 2015
  5. * Author: ADendek
  6. */
  7.  
  8. #include "TbUTClusterCreatorAlgorithm.h"
  9.  
  10. using namespace TbUT;
  11.  
  12. DECLARE_NAMESPACE_ALGORITHM_FACTORY(TbUT,ClusterCreatorAlgorithm)
  13.  
  14. ClusterCreatorAlgorithm::ClusterCreatorAlgorithm(const std::string& name, ISvcLocator* pSvcLocator):
  15. GaudiAlgorithm(name, pSvcLocator),
  16. m_dataContainer(),
  17. m_data(),
  18. m_inputDataLocation(),
  19. m_outputDataLocation(),
  20. m_clusterCreatorOption(),
  21. m_noiseFile(),
  22. m_sensorType(),
  23. m_event(),
  24. m_skipEvent(),
  25. m_lowThreshold(),
  26. m_highThreshold(),
  27. m_zsThresholdProvider(m_noiseFile,m_lowThreshold,m_highThreshold),
  28. m_clusterCreatorFactory(m_sensorType,m_zsThresholdProvider),
  29. m_clusterCreator()
  30. {
  31. declareProperty("InputDataLocation", m_inputDataLocation=TbUT::DataLocations::CMSTES);
  32. declareProperty("OutputDataLocation", m_outputDataLocation=TbUT::DataLocations::Clusters_TES);
  33. declareProperty("ClusterCreatorOption",m_clusterCreatorOption=TbUT::ClusterCreatorType::defaultCreator);
  34. declareProperty("NoiseInputFile",m_noiseFile=TbUT::DataLocations::NoiseTreshold);
  35. declareProperty("skippEventNumber",m_skipEvent=0);
  36. declareProperty("sensorType",m_sensorType="PType");
  37. declareProperty("LowThreshold",m_lowThreshold=3);
  38. declareProperty("HighThreshold",m_highThreshold=4);
  39. }
  40.  
  41.  
  42. StatusCode ClusterCreatorAlgorithm::initialize()
  43. {
  44. if(StatusCode::SUCCESS !=initializeBase()) return StatusCode::FAILURE;
  45. if(StatusCode::SUCCESS !=buildClusterCreator()) return StatusCode::FAILURE;
  46. if(StatusCode::SUCCESS !=retreiveNoise()) return StatusCode::FAILURE;
  47.  
  48. info()<<"Cluster thresholds (unit of noise multiplicity):"<<endmsg;
  49. info()<<"Low:" <<m_lowThreshold <<endmsg;
  50. info()<<"high:" <<m_highThreshold <<endmsg;
  51.  
  52. info()<<"Initialized successfully!"<<endmsg;
  53. return StatusCode::SUCCESS;
  54. }
  55.  
  56. StatusCode ClusterCreatorAlgorithm::execute()
  57. {
  58. if(m_event<m_skipEvent)
  59. {
  60. m_event++;
  61. return StatusCode::SUCCESS;
  62. }
  63. if(StatusCode::SUCCESS != getData()) return StatusCode::FAILURE;
  64. if(m_dataContainer->isEmpty()){
  65. ClusterContainer *l_clontainer=new ClusterContainer();
  66. put(l_clontainer,m_outputDataLocation);
  67. return StatusCode::SUCCESS;
  68. }
  69. processAndSaveDataToTES();
  70. m_event++;
  71. return StatusCode::SUCCESS;
  72. }
  73.  
  74. StatusCode ClusterCreatorAlgorithm::finalize()
  75. {
  76. return GaudiAlgorithm::finalize();
  77. }
  78.  
  79. StatusCode ClusterCreatorAlgorithm::initializeBase()
  80. {
  81. return GaudiAlgorithm::initialize();
  82. }
  83.  
  84. StatusCode ClusterCreatorAlgorithm::buildClusterCreator()
  85. try{
  86. m_clusterCreator=m_clusterCreatorFactory.createClusterCreator(m_clusterCreatorOption);
  87. return StatusCode::SUCCESS;
  88. }catch(ClusterCreatorFactory::NoSuchState &exception)
  89. {
  90. error()<<"Invalid ZS Engine Type : "<<exception.what()<<endmsg;
  91. return StatusCode::FAILURE;
  92. }
  93.  
  94. StatusCode ClusterCreatorAlgorithm::retreiveNoise()
  95. try{
  96. m_zsThresholdProvider.retreiveTresholds();
  97. return StatusCode::SUCCESS;
  98. }catch(ITresholdProvider::ThresholdProviderError &err){
  99. error()<<"Cannot open Noise file: "<<err.what()<<endmsg;
  100. return StatusCode::FAILURE;
  101. }
  102.  
  103.  
  104. StatusCode ClusterCreatorAlgorithm::getData()
  105. {
  106. m_dataContainer=getIfExists<RawDataContainer <double> >(m_inputDataLocation);
  107. if(!m_dataContainer){
  108. error()<< " ==> There is no input data: "<< m_inputDataLocation <<endmsg;
  109. return StatusCode::FAILURE;
  110. }
  111. return StatusCode::SUCCESS;
  112. }
  113.  
  114. void ClusterCreatorAlgorithm::processAndSaveDataToTES()
  115. {
  116. ClusterContainer *l_container=new ClusterContainer();
  117. for(const auto& rawDataIt: m_dataContainer->getData()){
  118. m_data=new RawData<double>(rawDataIt);
  119. ClusterContainer::ClusterVector clusterVector=m_clusterCreator->createClusters(m_data);
  120. l_container->addClusters(clusterVector);
  121. l_container->setTDC(m_data->getTDC());
  122. l_container->setTiemestamp(m_data->getTime());
  123. delete m_data;
  124. }
  125. put(l_container,m_outputDataLocation);
  126. }