bugfix
[u/mrichter/AliRoot.git] / EVE / EveHLT / AliEveHOMERManager.cxx
CommitLineData
a82a31af 1//-*- Mode: C++ -*-
2
d810d0de 3// $Id$
33791895 4// Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007 *
fd31e9de 5// Author: Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
33791895 6// Author: 2010 Svein Lindal <slindal@fys.uio.no> *
fd31e9de 7// for The ALICE HLT Project. *
059c30e4 8
a82a31af 9
7279ee15 10
d810d0de 11/** @file AliEveHOMERManager.cxx
30e7579c 12 @author Jochen Thaeder,
13 @author Svein Lindal <slindal@fys.uio.no>
51346b82 14 @date
30e7579c 15 @brief Manager for HOMER events
059c30e4 16*/
17
18#if __GNUC__>= 3
19 using namespace std;
20#endif
21
9e78371d 22#include "unistd.h"
33791895 23
30e7579c 24#include "AliHLTTriggerDecision.h"
d810d0de 25#include "AliEveHOMERManager.h"
cfa641b1 26#include "AliHLTHOMERBlockDesc.h"
cfa641b1 27#include "AliHLTHOMERManager.h"
33791895 28#include "AliEveHOMERSourceList.h"
29
30e7579c 30#include "TTimer.h"
a15e6d7d 31
d810d0de 32ClassImp(AliEveHOMERManager)
a82a31af 33
30e7579c 34//____________________________________________________________________________________
a82a31af 35AliEveHOMERManager::AliEveHOMERManager() :
33791895 36TEveElementList("Homer Manager"),
37 AliHLTHOMERManager(),
38 fSrcList(NULL),
39 fRetryCount(1000),
40 fRetrySleeptime(15),
30e7579c 41 fSourceListTimer(NULL)
cfa641b1 42{
30e7579c 43 fSourceListTimer = new TTimer();
44 fSourceListTimer->Connect("Timeout()", "AliEveHOMERManager", this, "CreateEveSourcesListLoop()");
059c30e4 45}
46
30e7579c 47//____________________________________________________________________________________
d810d0de 48AliEveHOMERManager::~AliEveHOMERManager() {
30e7579c 49 // see header file for class documentation
50
a82a31af 51 if (fSrcList)
46eadbb4 52 delete fSrcList;
53 fSrcList = NULL;
33791895 54
30e7579c 55
33791895 56
57
30e7579c 58}
059c30e4 59
30e7579c 60 //____________________________________________________________________________________
a82a31af 61Int_t AliEveHOMERManager::CreateEveSourcesList() {
62 // see header file for class documentation
059c30e4 63
059c30e4 64 DestroyElements();
059c30e4 65
a82a31af 66 Int_t iResult = CreateSourcesList();
33791895 67
30e7579c 68 fStateHasChanged = kTRUE;
46eadbb4 69
dd407e8c 70 HLTDebug(Form("iResult XXX %d", iResult));
a82a31af 71 if ( iResult )
059c30e4 72 return iResult;
51346b82 73
30e7579c 74
33791895 75
dd407e8c 76 HLTDebug(Form("iResult %d", iResult));
33791895 77 if (fSrcList) {
a5af8000 78 HLTInfo("delete source list");
33791895 79 DestroyElements();
80 //delete fSrcList;
81 fSrcList = NULL;
82 //fSrcList->Clear();
a5af8000 83 HLTInfo("cleared source list");
33791895 84 }
85
51346b82 86
a82a31af 87 // -- Create new AliEVE sources list
33791895 88 if(!fSrcList){
a5af8000 89 HLTInfo("no source list");
33791895 90 fSrcList = new AliEveHOMERSourceList("HLT Sources");
91 fSrcList->SetManager(this);
33791895 92 AddElement(fSrcList);
93 }
dd407e8c 94
95 //HLTInfo(Form("createbytype", iResult));
33791895 96 fSrcList->CreateByDet();
dd407e8c 97
30e7579c 98 HLTDebug(Form("Done creating source list %d", iResult));
99
059c30e4 100 return iResult;
101}
102
30e7579c 103///_______________________________________________________________
104void AliEveHOMERManager::StartEveSourceListLoop() {
105 HLTInfo("Starting source list timer");
cc87822c 106 fSourceListTimer->Start(1000);
30e7579c 107}
108///_______________________________________________________________
109void AliEveHOMERManager::StopEveSourceListLoop() {
110 fSourceListTimer->Stop();
111}
33791895 112
33791895 113
30e7579c 114//________________________________________________________________###
115Int_t AliEveHOMERManager::CreateEveSourcesListLoop() {
116 // see header file for class documentation
33791895 117
30e7579c 118 HLTInfo("Attempting to create source list");
119 Int_t iResult = CreateEveSourcesList();
33791895 120
30e7579c 121 if (!iResult) {
122 HLTInfo("Source list successfully created.");
123 StopEveSourceListLoop();
124 HLTInfo("Conneting to sources");
125 return ConnectEVEtoHOMER();
9e78371d 126 }
30e7579c 127
9e78371d 128
30e7579c 129 else if (iResult == 1) {
130 HLTWarning( Form("Couldn't find active services,"));
131
132 } else if (iResult == 2) {
133 HLTWarning( Form("Services List empty, sleeping %d s before making new attempt.", fRetrySleeptime) ) ;
134
135 } else {
136 HLTError( Form("Other problem ... \n") );
9e78371d 137 }
a82a31af 138
9e78371d 139 return iResult;
140}
059c30e4 141
30e7579c 142//________________________________________________________________
703482d8 143Int_t AliEveHOMERManager::ConnectEVEtoHOMER( TString detector ) {
9e78371d 144 // see header file for class documentation
33791895 145 HLTInfo("");
9e78371d 146 fStateHasChanged = fSrcList->GetSelectedSources();
33791895 147 HLTInfo(Form("has state changed % d", fStateHasChanged));
703482d8 148 return ConnectHOMER(detector);
059c30e4 149}
cfa641b1 150
33791895 151
30e7579c 152//________________________________________________________________
8b21b920 153Int_t AliEveHOMERManager::ReConnectHOMER( TString /*detector*/ ){
33791895 154 // see header file for class documentation
33791895 155 Int_t iResult = 0;
30e7579c 156 if (Connected()) DisconnectHOMER();
cc87822c 157 CreateEveSourcesListLoop();
33791895 158 return iResult;
159}
160
33791895 161//_____________________________________________________________________________________
30e7579c 162TList * AliEveHOMERManager::NextHOMEREvent() {
33791895 163 //See header file for documentation
30e7579c 164
165 if(!Connected()) {
cc87822c 166 HLTInfo("Homer is not connected, trying to reconnect!");
167 Int_t iResult = ReConnectHOMER();
168 if(iResult) {
169 HLTError("Error establishing connection to sources");
170 return NULL;
171 } else {
172 HLTInfo("New connection established, trying again to fetch event");
173 return NextHOMEREvent();
174 }
30e7579c 175 }
cc87822c 176
33791895 177
33791895 178 if ( NextEvent() ) {
179
180 HLTInfo("Failed getting next event, trying to reconnect");
30e7579c 181 Int_t iResult = ReConnectHOMER();
182 if(iResult) {
183 HLTError("Error establishing connection to sources");
cc87822c 184 return NULL;
185 }
33791895 186 }
cc87822c 187
30e7579c 188 return GetBlockList();
33791895 189
30e7579c 190}