9d1977993eeee82396fc5401dffc965bf8f2d8e5
[u/mrichter/AliRoot.git] / SHUTTLE / DCSClient / macros / TestClientAlias.C
1 TMap* GetValues(const char* host, Int_t port, const char* request,
2         UInt_t startTime, UInt_t endTime, Int_t multiSplit) 
3 {
4         AliDCSClient client(host, port, 1000, 20, multiSplit);
5         // The 5th parameter switches from single alias to multi aliases!
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         TMap* values=0;
19         
20         TStopwatch sw;
21         sw.Start();
22         
23         if(requests->GetEntries() == 0) return NULL;
24
25 //              TIter iter(requests);
26 //              TObjString* aString;
27 //              TObjArray* valueSet;
28 //              while ((aString = (TObjString*) iter.Next())) {
29 //                    cout<<"  Querying: "<<aString->GetName()<<endl;
30 //                    valueSet = new TObjArray();
31 //                    valueSet->SetOwner(1);
32 // 
33 //                      result = client.GetAliasValues(aString->GetName(), startTime,
34 //                              endTime, valueSet);
35 //                      values.Add(aString->Clone(), valueSet);
36 //              }
37  
38         values = client.GetAliasValues(requests, startTime, endTime);
39
40         if (!values) {
41                 cout<<"Query failed! Result error: "<<
42                         client.GetErrorString(client.GetResultErrorCode()) <<endl;
43                 if(client.GetResultErrorCode() == AliDCSClient::fgkServerError) 
44                         cout<<"Server error: "<<
45                                 client.GetServerError().Data() <<endl;
46                 return NULL;
47         }
48         
49         sw.Stop();
50         cout<<"Elapsed time: "<<sw.RealTime()<<endl;
51
52         cout<<"Time per alias: "<<sw.RealTime()/requests->GetEntries()<<endl;
53
54         cout<<"Received values: "<<endl;
55
56         Int_t nValues=0;
57
58         TIter iter(values);
59         TObjString* aRequest;
60         while ((aRequest = (TObjString*) iter.Next())) {
61
62                 TObjArray* valueSet = (TObjArray*) values->GetValue(aRequest);
63                 
64                 cout<<" '"<<aRequest->String()<<"' values: " 
65                         <<valueSet->GetEntriesFast()<<endl;
66
67                 TIter valIter(valueSet);
68                 AliDCSValue* aValue;
69                 while ((aValue = (AliDCSValue*) valIter.Next())) {
70                         cout<<aValue->ToString()<<endl;
71                         nValues++;
72                 } 
73         }
74         
75         cout<<"Number of received values: "<< nValues <<endl;
76         
77
78 /*
79         TFile file("dump.root", "UPDATE");
80         file.cd();
81         values.Write("DCSAliasMap", TObject::kSingleKey);
82         file.Close(); 
83 */
84
85         //values.DeleteAll();
86         //delete requests;
87
88         cout<<"All values returned in runrange:  "<<endl;
89         cout<<"StartTime: "<<TTimeStamp(startTime).AsString()<<endl;
90         cout<<"EndTime: "<<TTimeStamp(endTime).AsString()<<endl;
91         
92         return values;
93 }
94
95 TMap* TestClientAlias(const char* host, Int_t port, const char* request,
96         UInt_t startShift, UInt_t endShift, UInt_t multiSplit) {
97
98         gSystem->Load("$ALICE_ROOT/SHUTTLE/DCSClient/AliDCSClient");
99
100 //      AliLog::EnableDebug(kFALSE);
101 //      AliLog::SetGlobalDebugLevel(3);
102
103         TTimeStamp currentTime;
104
105         
106 /*      
107         TMap* values = GetValues(host, port, request,
108                 currentTime.GetSec() - startShift, 
109                 currentTime.GetSec() - endShift, multiSplit);
110 */
111                 
112 // SHUTTLE query interval 
113         
114         TMap* values = GetValues(host, port, request,
115                 1181300060, 1181307260, multiSplit);
116
117         if(values) values->Print();
118
119         cout << endl;
120         cout <<"Client done"<<endl;
121         
122         return values;
123 }