]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - SHUTTLE/DCSClient/AliDCSClient.cxx
Update master to aliroot
[u/mrichter/AliRoot.git] / SHUTTLE / DCSClient / AliDCSClient.cxx
index 82b33dd15f48f86a43a9b68ed7248ca513c26e2b..d531d72c467dac02b3021166d96693bda0faca65 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-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
-
-Revision 1.5  2007/10/05 12:40:55  acolla
-
-Result error code added to AliDCSClient data members (it was "lost" with the new implementation of TMap* GetAliasValues and GetDPValues).
-
-Revision 1.4  2007/09/14 16:46:14  jgrosseo
-1) Connect and Close are called before and after each query, so one can
-keep the same AliDCSClient object.
-2) The splitting of a query is moved to GetDPValues/GetAliasValues.
-3) Splitting interval can be specified in constructor
-
-Revision 1.3  2007/09/11 16:42:02  jgrosseo
-starting modifying AliDCSClient to transparently switch between single and multi query
-first step: same alidcsclient can be used for several queries
-
-Revision 1.2  2007/06/09 13:01:09  jgrosseo
-Switching to retrieval of several DCS DPs at a time (multiDPrequest)
-
-Revision 1.1  2006/11/06 14:22:47  jgrosseo
-major update (Alberto)
-o) reading of run parameters from the logbook
-o) online offline naming conversion
-o) standalone DCSclient package
-
-Revision 1.6  2006/10/02 16:38:39  jgrosseo
-update (alberto):
-fixed memory leaks
-storing of objects that failed to be stored to the grid before
-interfacing of shuttle status table in daq system
-
-Revision 1.5  2006/08/15 10:50:00  jgrosseo
-effc++ corrections (alberto)
-
-Revision 1.4  2006/07/04 14:59:57  jgrosseo
-revision of AliDCSValue: Removed wrapper classes, reduced storage size per value by factor 2
-
-Revision 1.3  2006/06/12 09:11:16  jgrosseo
-coding conventions (Alberto)
-
-Revision 1.2  2006/03/07 07:52:34  hristov
-New version (B.Yordanov)
-
-Revision 1.3  2005/11/17 17:47:34  byordano
-TList changed to TObjArray
-
-Revision 1.2  2005/11/17 14:43:23  byordano
-import to local CVS
-
-Revision 1.1.1.1  2005/10/28 07:33:58  hristov
-Initial import as subdirectory in AliRoot
-
-Revision 1.1.1.1  2005/09/12 22:11:40  byordano
-SHUTTLE package
-
-Revision 1.3  2005/08/30 10:53:23  byordano
-some more descriptions added
-
-*/
-
 //
-// This class represents the AliDCSClient.
-// The client used for data retrieval from DCS server.
-// There are two way for retrieving data from the server.
+// This class represents the AliDCSClient, the client used for
+// data retrieval from the DCS server.
+// There are two ways for retrieving data from the server:
 //     1) asking for DP (DataPoint) - usually changed frequently.
-//     2) asking for Alias (Alias) - alias should be the same through whole
-//             experimnet.
+//     2) asking for Alias (Alias) - alias should be the same through
+//             the whole experiment.
 //             
-// There are two type of read operations:
-//     Asking for single alias/dp or asking for set of aliases/dp
+// There are two types of read operations:
+//     Asking for a single alias/DP or asking for a set of aliases/DPs
 //
-// In case of ServerError the coresponding error code and 
+// In case of ServerError the corresponding error code and 
 // error string (description) could be got by GetServerErrorCode() and
 // GetServerErrorString()
 //
@@ -104,6 +38,7 @@ some more descriptions added
 #include <TMap.h>
 #include <TObjString.h>
 #include <TSystem.h>
+#include <TTimeStamp.h>
 
 ClassImp(AliDCSClient)
 
@@ -113,6 +48,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,
@@ -145,23 +81,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 ++;
        }
        
@@ -178,7 +118,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));
@@ -220,9 +160,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;
@@ -268,7 +209,7 @@ Int_t AliDCSClient::SendMessage(AliDCSMessage& message)
 //______________________________________________________________________
 Int_t AliDCSClient::ReceiveMessage(AliDCSMessage& message)
 {
-// receive message from the DCS server
+       // receive message from the DCS server
        
        char header[HEADER_SIZE];
 
@@ -340,7 +281,7 @@ Int_t AliDCSClient::GetValues(AliDCSMessage::RequestType reqType,
        }
 
        Close();
-
+       
        return receivedValues;
 }
 
@@ -423,6 +364,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;
@@ -439,14 +385,20 @@ TMap* AliDCSClient::GetValues(AliDCSMessage::RequestType reqType,
                        }
 
                        TObjString* aRequest = (TObjString*) list->At(ownerIndex + subsetBegin);
-                       //AliInfo(Form("Received %d values for entry %d, that is %s", resultSet->GetEntries(),
-                       //      ownerIndex + subsetBegin, aRequest->String().Data()));
-
+                       
+                       for (Int_t i=0; i<resultSet->GetEntries(); i++)
+                       {
+                               AliDCSValue* value = (AliDCSValue*) resultSet->At(i);
+                               if (!value)
+                                       continue;
+                               if (value->GetTimeStamp() < startTime || value->GetTimeStamp() > endTime)
+                                       AliWarning(Form("Value for %s outside of queried interval (%d to %d): %d", aRequest->String().Data(), startTime, endTime, value->GetTimeStamp()));
+                       }
+               
                        TObjArray* target = dynamic_cast<TObjArray*> (result->GetValue(aRequest));
                        if (target)
                        {
                                target->AddAll(resultSet);
-                               //AliInfo(Form("Now we have %d entries", target->GetEntries()));
                                resultSet->SetOwner(0);
                                delete resultSet;
                        }
@@ -489,17 +441,6 @@ 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;
-//             }
-
                return sResult;
        }
        else if (message.GetType() == AliDCSMessage::kError)
@@ -509,6 +450,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;
@@ -610,6 +559,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;
@@ -643,6 +593,9 @@ const char* AliDCSClient::GetErrorString(Int_t code)
 
                case AliDCSClient::fgkServerError:
                        return AliDCSClient::fgkServerErrorString;
+               
+               case AliDCSClient::fgkUnknownDP:
+                       return AliDCSClient::fgkUnknownDPString;
 
                default:
                        AliErrorGeneral("AliDCSClient::GetErrorString",