/*
$Log$
+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
//______________________________________________________________________
AliDCSClient::AliDCSClient(const char* host, Int_t port, UInt_t timeout,
Int_t retries):
- fSocket(NULL), fTimeout(timeout), fRetries(retries),
+ fSocket(NULL), fHost(host), fPort(port), fTimeout(timeout), fRetries(retries),
fServerErrorCode(AliDCSMessage::kNoneError), fServerError("")
{
//
// retries: the number of retries after which the connection is
// is considered as invalid and error is returned.
//
-
- Int_t tries = 0;
-
- while (tries < fRetries) {
- fSocket = new TSocket(host, port);
- if (fSocket->IsValid()) {
- AliDebug(1, Form("Connected to %s:%d", host, port));
- fSocket->SetOption(kNoBlock, 1);
- break;
- }
-
- AliDebug(1, Form("Connection timeout! tries <%d> ...", tries));
-
- delete fSocket;
- fSocket = NULL;
-
- gSystem->Sleep(fTimeout);
- tries ++;
- }
}
//______________________________________________________________________
-AliDCSClient::AliDCSClient(const AliDCSClient& /*other*/):
- TObject(), fSocket(NULL), fTimeout(0), fRetries(0),
- fServerErrorCode(AliDCSMessage::kNoneError), fServerError("")
-
+AliDCSClient::~AliDCSClient()
{
-// copy constructor (not implemented)
+ // destructor
+ Close();
}
//______________________________________________________________________
-AliDCSClient &AliDCSClient::operator=(const AliDCSClient& /*other*/)
+Bool_t AliDCSClient::Connect()
{
-// assignment operator (not implemented)
-
-return *this;
-}
+ // connects to the AMANDA server
+
+ Close();
+
+ Int_t tries = 0;
+ while (tries < fRetries)
+ {
+ fSocket = new TSocket(fHost, fPort);
+ if (fSocket->IsValid())
+ {
+ AliDebug(1, Form("Connected to %s:%d", fHost.Data(), fPort));
+ fSocket->SetOption(kNoBlock, 1);
+ return kTRUE;
+ }
-//______________________________________________________________________
-AliDCSClient::~AliDCSClient()
-{
-// destructor
+ AliDebug(1, Form("Connection timeout! tries <%d> ...", tries));
- if (fSocket) {
- Close();
delete fSocket;
+ fSocket = NULL;
+
+ gSystem->Sleep(fTimeout);
+ tries ++;
}
+
+ return kFALSE;
}
//______________________________________________________________________
Int_t AliDCSClient::GetValues(AliDCSMessage::RequestType reqType,
const char* reqString, UInt_t startTime, UInt_t endTime, TObjArray* result)
{
-// get array of DCS values from the DCS server
-// reqString: alias name
-// startTime, endTime: start time and end time of the query
-// result: contains the array of retrieved AliDCSValue's
+ // get array of DCS values from the DCS server
+ // reqString: alias name
+ // startTime, endTime: start time and end time of the query
+ // result: contains the array of retrieved AliDCSValue's
+ Connect();
+
if (!IsConnected()) {
AliError("Not connected!");
return AliDCSClient::fgkBadState;
}
- Int_t sResult;
+ Int_t sResult = -1;
AliDCSMessage requestMessage;
requestMessage.CreateRequestMessage(reqType, startTime, endTime,
reqString);
// Result: map containing the array of alias names. It will be filled with
// the values retrieved for each alias
+ Connect();
+
if (!IsConnected()) {
AliError("Not connected!");
return 0;
if (fSocket) {
fSocket->Close();
+ delete fSocket;
+ fSocket = 0;
}
}
TMap* GetAliasValues(const TSeqCollection* aliasList, UInt_t startTime, UInt_t endTime, Int_t startIndex = 0, Int_t endIndex = -1);
AliDCSMessage::ErrorCode GetServerErrorCode() const
- { return fServerErrorCode;};
+ { return fServerErrorCode;}
- const TString& GetServerError() const {return fServerError;};
+ const TString& GetServerError() const {return fServerError;}
Bool_t IsConnected();
static const char* fgkCommErrorString; // Communication error string
static const char* fgkServerErrorString; // Server error string
- AliDCSClient(const AliDCSClient& other);
- AliDCSClient& operator= (const AliDCSClient& other);
-
TSocket* fSocket; // Pointer to the TCP socket client
-
+ TString fHost; // server host
+ Int_t fPort; // server port
UInt_t fTimeout; // timeout parameter
-
Int_t fRetries; // number of retries
-
AliDCSMessage::ErrorCode fServerErrorCode; // error code
-
TString fServerError; // server error string
+ Bool_t Connect();
Int_t SendBuffer(const char* buffer, Int_t size);
Int_t ReceiveValueSet(TObjArray* result);
+ AliDCSClient(const AliDCSClient& other); // not implemented
+ AliDCSClient& operator= (const AliDCSClient& other); // not implemented
ClassDef(AliDCSClient, 0);
};
void GetValues(const char* host, Int_t port, const char* request,
- Long_t startTime, Long_t endTime)
+ UInt_t startTime, UInt_t endTime)
{
-
- AliDCSClient client(host, port, 1000, 5);
+ AliDCSClient client(host, port, 1000, 20);
Int_t result;
TStopwatch sw;
sw.Start();
- if (requests->GetEntries() > 1) {
-
+ if (requests->GetEntries() > 0) {
TIter iter(requests);
TObjString* aString;
TObjArray* valueSet;
valueSet = new TObjArray();
valueSet->SetOwner(1);
- result = client.GetDPValues(aString->GetName(), startTime,
+ result = client.GetAliasValues(aString->GetName(), startTime,
endTime, valueSet);
values.Add(aString->Clone(), valueSet);
}
-
- } else {
- TObjArray* valueSet = new TObjArray();
- valueSet->SetOwner(1);
-
- values.Add(new TObjString(request), valueSet);
-
- result = client.GetAliasValues(request, startTime,
- endTime, valueSet);
}
if (result < 0) {