new option for tests in alifakedisplay
[u/mrichter/AliRoot.git] / MONITOR / alistoragemanager / alifakedisplay.cxx
CommitLineData
164d3d29 1#include "AliStorageEventManager.h"
2#include "AliStorageTypes.h"
3#include "AliESDEvent.h"
4#include "AliESDRun.h"
5
6#include <iostream>
7
8#include <TThread.h>
9
10using namespace std;
11
12/* parameters:
68242b61 13
14 0 - connect directly to reconstruction socket
15 1 - connect to Storage Manager and ask for last event
16 2 - connect to alieventserver, receive in thread and use in main thread
17
18 */
164d3d29 19
20// global variables:
21AliESDEvent *currentEvent[2];
22TTree *currentTree[2];
0790c3e6 23TMutex myMutex;
164d3d29 24int eventInUse=1;
25int writingToEventIndex=0;
26bool isNewEventAvaliable=false;
27//-----------------
28
29static void* GetNextEvent(void*);
30
31int main(int argc, char **argv)
32{
68242b61 33 if(argc<2)
34 {
35 cout<<"Usage: alifakedisplay <mode>"<<endl;
36 cout<<"mode:"<<endl;
37 cout<<"0 - connect directly to reconstruction socket"<<endl;
38 cout<<"1 - connect to Storage Manager and ask for last event"<<endl;
39 cout<<"3 - connect to Storage Manager, download list of perm events and ask for them in loop"<<endl;
40 return 0;
41 }
42
43 storageSockets socket;
44 AliStorageEventManager *manager = AliStorageEventManager::GetEventManagerInstance();
45 AliESDEvent *event;
46
47 if(atoi(argv[1])==0)
48 {
49 socket = EVENTS_SERVER_SUB;
50 manager->CreateSocket(socket);
51 cout<<"Socket created"<<endl;
52 while(1)
53 {
54 cout<<"waiting for event..."<<flush;
55 event = manager->GetEvent(socket);
56
57 if(event)
58 {
59 cout<<"Received event. Run:"<<event->GetRunNumber()<<"\t event:"<<event->GetEventNumberInFile()<<endl;
60
61 cout<<event->GetPeriodNumber()<<endl;
62 cout<<event->GetOrbitNumber()<<endl;
63 cout<<event->GetBunchCrossNumber()<<endl;
64 for(int i=0;i<100;i++)
65 {
66 if(strcmp(event->GetESDRun()->GetTriggerClass(i),"")){
67 cout<<event->GetESDRun()->GetTriggerClass(i)<<endl;}
68 }
69 delete event;
70 }
71 else
72 {
73 cout<<"NO EVENT"<<endl;
74 }
75 }
76 }
77 else if(atoi(argv[1])==1)
78 {
79 socket = SERVER_COMMUNICATION_REQ;
80 manager->CreateSocket(socket);
81 while(1)
82 {
83 struct serverRequestStruct *requestMessage = new struct serverRequestStruct;
84 requestMessage->messageType = REQUEST_GET_LAST_EVENT;
85
86 manager->Send(requestMessage,socket);
87 event = manager->GetEvent(socket);
88 if(event)
89 {
90 cout<<"Last event - Run:"<<event->GetRunNumber()<<"\t event:"<<event->GetEventNumberInFile()<<endl;
91
92 delete event;
93 }
94 else
95 {
96 cout<<"NO EVENT"<<endl;
97 }
98 sleep(1);
99 }
100 }
101 else if(atoi(argv[1])==2)
102 {
103 TThread *getEventThread = new TThread("getEventThread",GetNextEvent,nullptr);
104 getEventThread->Run();
105
106 int counter=0;
107
108 while(1)
109 {
164d3d29 110 counter++;
111 if(isNewEventAvaliable)
112 {
68242b61 113 cout<<"new event"<<endl;
114 myMutex.Lock();
115 if(writingToEventIndex == 0) eventInUse = 0;
116 else if(writingToEventIndex == 1) eventInUse = 1;
117 cout<<"Using:"<<eventInUse<<endl;
118
119 if(currentEvent[eventInUse])
164d3d29 120 {
68242b61 121 if(currentEvent[eventInUse]->GetRunNumber() >= 0)
122 {
123 cout<<"CURRENT EVENT:"<<currentEvent[eventInUse]->GetEventNumberInFile()<<endl;
124 }
164d3d29 125 }
68242b61 126 isNewEventAvaliable = false;
127 myMutex.UnLock();
164d3d29 128 }
129 else{cout<<"No new event is avaliable."<<endl;}
68242b61 130
164d3d29 131 sleep(2);
68242b61 132 }
133 }
134 else if(atoi(argv[1])==3)
135 {
136 socket = SERVER_COMMUNICATION_REQ;
137 manager->CreateSocket(socket);
138
139
140 struct listRequestStruct list;
141 list.runNumber[0]=0;
142 list.runNumber[1]=999999;
143 list.eventNumber[0]=0;
144 list.eventNumber[1]=999999;
145 list.marked[0]=1;
146 list.marked[1]=1;
147 list.multiplicity[0]=1;
148 list.multiplicity[1]=999999;
149 strcpy(list.system[0],"p-p");
150 strcpy(list.system[1],"A-A");
151 struct serverRequestStruct *requestMessage = new struct serverRequestStruct;
152 requestMessage->messageType = REQUEST_LIST_EVENTS;
153 requestMessage->list = list;
154
155 manager->Send(requestMessage,socket);
156 vector<serverListStruct> receivedList = manager->GetServerListVector(socket,3000);
157
158 cout<<"FAKE DISPLAY -- received list of marked events"<<endl;
159
160 for(int i=0;i<receivedList.size();i++){
161 cout<<"ev:"<<receivedList[i].eventNumber<<endl;
162 }
164d3d29 163
68242b61 164 int iter=0;
165 while(1)
166 {
167 if(iter<receivedList.size())
168 {
169 struct eventStruct mark;
170 mark.runNumber = receivedList[iter].runNumber;
171 mark.eventNumber = receivedList[iter].eventNumber;
172
173 requestMessage->messageType = REQUEST_GET_EVENT;
174 requestMessage->event = mark;
175
176 manager->Send(requestMessage,socket);
177 event = manager->GetEvent(socket);
178
179 if(event)
180 {
181 cout<<"i:"<<iter<<"\tevent:"<<event->GetEventNumberInFile()<<endl;
182 }
183 else
184 {
185 cout<<"Received NO event"<<endl;
186 }
187 iter++;
188 sleep(1);
189 }
190 else{iter=0;}
191 }
192 }
193
194 return 0;
164d3d29 195}
196
197void* GetNextEvent(void*)
198{
68242b61 199 AliStorageEventManager *eventManager = AliStorageEventManager::GetEventManagerInstance();
200 eventManager->CreateSocket(EVENTS_SERVER_SUB);
201
202 currentEvent[0]=0;
203 currentEvent[1]=0;
204 currentTree[0]=0;
205 currentTree[1]=0;
206 AliESDEvent *tmpEvent;
207
208 while(1)
164d3d29 209 {
68242b61 210 //if(tmpEvent){delete tmpEvent;tmpEvent=0;}
211 tmpEvent = eventManager->GetEvent(EVENTS_SERVER_SUB);
212
213 if(tmpEvent)
164d3d29 214 {
68242b61 215 if(tmpEvent->GetRunNumber()>=0)
216 {
217 myMutex.Lock();
218 if(eventInUse == 0){writingToEventIndex = 1;}
219 else if(eventInUse == 1){writingToEventIndex = 0;}
220
221 if(currentEvent[writingToEventIndex])
222 {
223 delete currentEvent[writingToEventIndex];
224 currentEvent[writingToEventIndex]=0;
225 }
226 currentEvent[writingToEventIndex] = tmpEvent;
227 isNewEventAvaliable = true;
228 myMutex.UnLock();
229 }
230 }
231 }
164d3d29 232}