Format fixed in Logs lines.
[u/mrichter/AliRoot.git] / SHUTTLE / DCSClient / AliDCSClient.cxx
index f0903e532a71f23662aaa9715ab05c94452bbff6..bb8d3096de4c6f703c0b8e2ef403671118e18a43 100644 (file)
 
 /*
 $Log$
+Revision 1.8  2007/10/17 17:43:02  acolla
+nextMessage removed from client
+
+Revision 1.7  2007/10/16 15:02:20  jgrosseo
+fixed bug if zero values collected
+
 Revision 1.6  2007/10/16 14:37:16  jgrosseo
 changing to AMANDA protocol version 2
 
@@ -101,6 +107,7 @@ some more descriptions added
 #include <TMap.h>
 #include <TObjString.h>
 #include <TSystem.h>
+#include <TTimeStamp.h>
 
 ClassImp(AliDCSClient)
 
@@ -110,6 +117,7 @@ const char* AliDCSClient::fgkTimeoutString = "Timeout";
 const char* AliDCSClient::fgkBadMessageString = "BadMessage";
 const char* AliDCSClient::fgkCommErrorString = "CommunicationError";
 const char* AliDCSClient::fgkServerErrorString = "ServerError";
+const char* AliDCSClient::fgkUnknownDPString = "UnknownAlias/DP";
 
 //______________________________________________________________________
 AliDCSClient::AliDCSClient(const char* host, Int_t port, UInt_t timeout,
@@ -142,23 +150,27 @@ Bool_t AliDCSClient::Connect()
        
        Close();
        
-       Int_t tries = 0;        
+       Int_t tries = 0;
+       Int_t sleeptime=300;
+       
        while (tries < fRetries) 
        {
                fSocket = new TSocket(fHost, fPort);
-               if (fSocket->IsValid()) 
+                       
+               if (fSocket && fSocket->IsValid()) 
                {
-                       AliDebug(1, Form("Connected to %s:%d", fHost.Data(), fPort));
+                       AliDebug(1, Form("%s  *** Connected to %s:%d", TTimeStamp(time(0)).AsString("s"), fHost.Data(), fPort));
                        fSocket->SetOption(kNoBlock, 1);
                        return kTRUE;
                }
 
-               AliDebug(1, Form("Connection timeout! tries <%d> ...", tries));
+               AliError(Form(" *** Connection to AMANDA server failed Tried <%d> times ...", tries+1));
+               if(tries<fRetries-1) AliInfo(Form(" *** Waiting %d seconds before next retry.", sleeptime));
 
                delete fSocket;
                fSocket = NULL;
 
-               gSystem->Sleep(fTimeout);
+               gSystem->Sleep(sleeptime);
                tries ++;
        }
        
@@ -175,7 +187,7 @@ Int_t AliDCSClient::SendBuffer(const char* buffer, Int_t size)
 
         while (sentSize < size && tries < fRetries) {
 
-                Int_t sResult = fSocket->Select(TSocket::kWrite, fTimeout);
+                Int_t sResult = fSocket->Select(TSocket::kWrite, fTimeout*1000); //timeout for TSocket::Select is in msec
 
                 if (sResult == 0) {
                        AliDebug(1, Form("Timeout! tries <%d> ...", tries));
@@ -217,9 +229,10 @@ Int_t AliDCSClient::ReceiveBuffer(char* buffer, Int_t size)
 
         while (receivedSize < size && tries < fRetries) {
 
-                Int_t sResult = fSocket->Select(TSocket::kRead, fTimeout);
+                Int_t sResult = fSocket->Select(TSocket::kRead, fTimeout*1000); //timeout for TSocket::Select is in msec
 
                 if (sResult == 0) {
+                       AliDebug(1, Form("Time when timing out: %s   Timeout value: %d seconds",TTimeStamp(time(0)).AsString("s"),fTimeout));
                         AliDebug(1, Form("Timeout! tries <%d> ...", tries));
                         tries ++;
                         continue;
@@ -420,6 +433,11 @@ TMap* AliDCSClient::GetValues(AliDCSMessage::RequestType reqType,
 
                        if (fResultErrorCode < 0)
                        {
+                               if (fResultErrorCode == fgkUnknownDP)
+                               {
+                                       AliError(Form("%s",fServerError.Data()));
+                               }
+                               
                                AliError("Can't get values");
 
                                delete resultSet;
@@ -486,16 +504,16 @@ Int_t AliDCSClient::ReceiveValueSet(TObjArray* result, Int_t& ownerIndex)
 
                sResult = message.GetValues(result);
 
-               AliDCSMessage nextMessage;
-               nextMessage.CreateNextMessage();
-
-               if ((fResultErrorCode = SendMessage(nextMessage)) < 0)
-               {
-                       AliError(Form("Can't send next message! Reason: %s",
-                               GetErrorString(fResultErrorCode)));
-                       Close();
-                       return AliDCSClient::fgkCommError;
-               }
+//             AliDCSMessage nextMessage;
+//             nextMessage.CreateNextMessage();
+// 
+//             if ((fResultErrorCode = SendMessage(nextMessage)) < 0)
+//             {
+//                     AliError(Form("Can't send next message! Reason: %s",
+//                             GetErrorString(fResultErrorCode)));
+//                     Close();
+//                     return AliDCSClient::fgkCommError;
+//             }
 
                return sResult;
        }
@@ -506,6 +524,14 @@ Int_t AliDCSClient::ReceiveValueSet(TObjArray* result, Int_t& ownerIndex)
 
                return AliDCSClient::fgkServerError;
        }
+       
+       else if (message.GetType() == AliDCSMessage::kUnknownDP)
+       {
+               fServerError = message.GetErrorString();
+
+               return AliDCSClient::fgkUnknownDP;
+       }
+       
 
        AliError("Bad message type received!");
        return AliDCSClient::fgkBadMessage;
@@ -607,6 +633,7 @@ void AliDCSClient::Close()
        //
 
        if (fSocket) {
+               AliDebug(1, Form("%s  *** Closing connection to %s:%d", TTimeStamp(time(0)).AsString("s"), fHost.Data(), fPort));
                fSocket->Close();
                delete fSocket;
                fSocket = 0;
@@ -640,6 +667,9 @@ const char* AliDCSClient::GetErrorString(Int_t code)
 
                case AliDCSClient::fgkServerError:
                        return AliDCSClient::fgkServerErrorString;
+               
+               case AliDCSClient::fgkUnknownDP:
+                       return AliDCSClient::fgkUnknownDPString;
 
                default:
                        AliErrorGeneral("AliDCSClient::GetErrorString",