This commit was generated by cvs2svn to compensate for changes in r12269,
[u/mrichter/AliRoot.git] / SHUTTLE / test / TestClient.C
1 void GetValues(const char* host, Int_t port, const char* request,
2         Long_t startTime, Long_t endTime) 
3 {
4
5         AliDCSClient client(host, port, 10000, 5);
6
7         Int_t result;
8
9         TTimeStamp currentTime;
10         TMap values;
11
12         TString rString(request);
13
14         TObjArray* requests = rString.Tokenize(",");
15
16         cout<<"Requests: "<<requests->GetEntries()<<endl;
17
18         TStopwatch sw;
19         sw.Start();
20
21         if (requests->GetEntries() > 1) {
22                 
23                 TIter iter(requests);
24                 TObjString* aString;
25                 while ((aString = (TObjString*) iter.Next())) {
26                         values.Add(new TObjString(aString->String()), NULL);
27                 }       
28                 
29                 result = client.GetDPValues(startTime, endTime, values);
30
31         } else {
32                 TList* valueSet = new TList();
33                 valueSet->SetOwner(1);
34
35                 values.Add(new TObjString(request), valueSet);
36
37                 result = client.GetDPValues(request, startTime,
38                                 endTime, *valueSet);
39         }
40
41         if (result < 0) {
42                 cout<<"Communication failure: "<<
43                         AliDCSClient::GetErrorString(result)<<endl;
44
45                 if (result == AliDCSClient::fgkServerError) {
46                         cout<<"Server error code: "<<
47                                 client.GetServerErrorCode()<<endl;
48                         cout<<client.GetServerError()<<endl;
49                 }
50         }
51         
52         sw.Stop();
53         cout<<"Elapsed time: "<<sw.RealTime()<<endl;
54         if (result > 0) {
55                 cout<<"Time per value: "<<sw.RealTime()/result<<endl;
56         }
57         cout<<"Received values: "<<result<<endl;
58
59         TIter iter(&values);
60         TObjString* aRequest;
61         while ((aRequest = (TObjString*) iter.Next())) {
62
63                 TList* valueSet = (TList*) values.GetValue(aRequest);
64                 
65                 cout<<" '"<<aRequest->String()<<"' values: " 
66                         <<valueSet->GetSize()<<endl;
67
68 /*              TIter valIter(valueSet);
69                 AliDCSValue* aValue;
70                 while ((aValue = (AliDCSValue*) valIter.Next())) {
71                         cout<<aValue->ToString()<<endl;
72                 } */
73         }
74
75 /*      TFile file("dump.root", "UPDATE");
76         file.WriteTObject(values, "values");
77         file.Close(); */
78
79         values.DeleteAll();
80         delete requests;
81
82         cout<<"All values returned in runrange:  "<<endl;
83         cout<<"StartTime: "<<TTimeStamp(startTime).AsString()<<endl;
84         cout<<"EndTime: "<<TTimeStamp(endTime).AsString()<<endl;
85 }
86
87 void TestClient(const char* host, Int_t port, const char* request,
88         UInt_t startShift, UInt_t endShift) {
89
90         gSystem->Load("libSHUTTLE");
91
92 //      AliLog::EnableDebug(kFALSE);
93 //      AliLog::SetGlobalDebugLevel(3);
94
95         TTimeStamp currentTime;
96
97         GetValues(host, port, request,
98                 currentTime.GetSec() - startShift, 
99                 currentTime.GetSec() - endShift);
100
101         cout<<"Client done"<<endl;
102 }