1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 Revision 1.2 2007/10/16 14:37:17 jgrosseo
19 changing to AMANDA protocol version 2
21 Revision 1.1 2006/11/06 14:22:47 jgrosseo
22 major update (Alberto)
23 o) reading of run parameters from the logbook
24 o) online offline naming conversion
25 o) standalone DCSclient package
27 Revision 1.7 2006/10/02 16:38:39 jgrosseo
30 storing of objects that failed to be stored to the grid before
31 interfacing of shuttle status table in daq system
33 Revision 1.6 2006/08/15 10:50:00 jgrosseo
34 effc++ corrections (alberto)
36 Revision 1.5 2006/07/20 09:54:40 jgrosseo
37 introducing status management: The processing per subdetector is divided into several steps,
38 after each step the status is stored on disk. If the system crashes in any of the steps the Shuttle
39 can keep track of the number of failures and skips further processing after a certain threshold is
40 exceeded. These thresholds can be configured in LDAP.
42 Revision 1.4 2006/07/04 14:59:57 jgrosseo
43 revision of AliDCSValue: Removed wrapper classes, reduced storage size per value by factor 2
45 Revision 1.3 2006/06/12 09:11:16 jgrosseo
46 coding conventions (Alberto)
48 Revision 1.2 2006/03/07 07:52:34 hristov
49 New version (B.Yordanov)
51 Revision 1.3 2005/11/17 17:47:34 byordano
52 TList changed to TObjArray
54 Revision 1.2 2005/11/17 14:43:23 byordano
57 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
58 Initial import as subdirectory in AliRoot
60 Revision 1.1.1.1 2005/09/12 22:11:40 byordano
63 Revision 1.2 2005/08/30 10:53:23 byordano
64 some more descriptions added
70 // This class is a wrapper of AliDCSMessage.
71 // These are the messages which form AliDCSProtocol.
72 // Every message has header and body. The body size is written in the header.
73 // There are five message types:
74 // 1) Request - used by the client to form a single request to DCS server
75 // 2) Count - returned by the server to inidicate the total number of
76 // values which would be sent to the client.
77 // 3) ResultSet - returned by the server and contains part of values set
78 // which forms the server resposen.
79 // 4) Error - returned by the server in case of error
80 // 5) MultiRequest - used by the client to form multi request.
81 // This is a request which serves many aliases/dp at the same time
82 // For all aliases/dp the same time interval is used.
83 // Short description of the schema:
84 // The client sends a request (Request or MultiRequest) and the server
86 // 1) Count - the total number of values that the client should
88 // 2) ResultSet* - every ResultSet message contains a part
89 // of valueSet (some values) which the client should expect
90 // The client can wait for ResultMessage until it gets
91 // all values (total number) which was returned by the
92 // Count message at the beginning of the ResutlSet sereie.
94 // 1) Error - contains the error code and error description
97 #include "AliDCSMessage.h"
102 #include <TObjString.h>
107 ClassImp(AliDCSMessage)
109 //______________________________________________________________________
110 AliDCSMessage::AliDCSMessage():
111 TObject(), fMessage(NULL), fMessageSize(0), fType(kInvalid),
112 fRequestType(kNoneType), fStartTime(0), fEndTime(0),
113 fRequestString(""), fCount(0),
114 fOwnerIndex(0), fValueType(AliDCSValue::kInvalid), fValues(),
115 fErrorCode(kNoneError), fErrorString(""),
118 // default constructor
119 fValues = new TObjArray();
120 fValues->SetOwner(0);
124 //______________________________________________________________________
125 AliDCSMessage::AliDCSMessage(const char* message, UInt_t size):
126 TObject(), fMessage(NULL), fMessageSize(size), fType(kInvalid),
127 fRequestType(kNoneType), fStartTime(0), fEndTime(0),
128 fRequestString(""), fCount(0),
129 fOwnerIndex(0), fValueType(AliDCSValue::kInvalid), fValues(),
130 fErrorCode(kNoneError), fErrorString(""),
133 // default constructor
135 fMessage = new char[size];
137 memcpy(fMessage, message, size);
138 fValues = new TObjArray();
139 fValues->SetOwner(0);
142 //______________________________________________________________________
143 AliDCSMessage::AliDCSMessage(const AliDCSMessage& /*other*/):
144 TObject(), fMessage(NULL), fMessageSize(0), fType(kInvalid),
145 fRequestType(kNoneType), fStartTime(0), fEndTime(0),
146 fRequestString(""), fCount(0),
147 fOwnerIndex(0), fValueType(AliDCSValue::kInvalid), fValues(),
148 fErrorCode(kNoneError), fErrorString(""),
151 // copy constructor (not implemented)
155 //______________________________________________________________________
156 AliDCSMessage &AliDCSMessage::operator=(const AliDCSMessage& /*other*/)
158 // assignment operator (not implemented)
163 //______________________________________________________________________
164 AliDCSMessage::~AliDCSMessage()
170 if(fValues) delete fValues; fValues=0;
173 //______________________________________________________________________
174 void AliDCSMessage::CreateRequestMessage(RequestType type,
175 UInt_t startTime, UInt_t endTime, const char* request)
177 // Create request message
181 fType = AliDCSMessage::kRequest;
183 fStartTime = startTime;
185 fRequestString = request;
188 //______________________________________________________________________
189 void AliDCSMessage::CreateMultiRequestMessage(RequestType type,
190 UInt_t startTime, UInt_t endTime)
192 // Create multi request message
196 fType = AliDCSMessage::kMultiRequest;
198 fStartTime = startTime;
202 //______________________________________________________________________
203 void AliDCSMessage::CreateCountMessage(UInt_t count)
205 // Create count request message
209 fType = AliDCSMessage::kCount;
213 //______________________________________________________________________
214 void AliDCSMessage::CreateResultSetMessage(AliDCSValue::Type type)
216 // Create result set message
220 fType = AliDCSMessage::kResultSet;
224 //______________________________________________________________________
225 void AliDCSMessage::CreateErrorMessage(ErrorCode errorCode,
226 const char* errorString)
228 // Create error message
232 fType = AliDCSMessage::kError;
233 fErrorCode = errorCode;
234 fErrorString = errorString;
238 //______________________________________________________________________
239 void AliDCSMessage::CreateNextMessage() {
242 fType = AliDCSMessage::kNext;
245 //______________________________________________________________________
246 void AliDCSMessage::DestroyMessage()
252 ClearRequestStrings();
255 //______________________________________________________________________
256 void AliDCSMessage::SetBool(char* buf, Bool_t val)
258 // Set bool value to buf
263 //______________________________________________________________________
264 void AliDCSMessage::SetByte(char* buf, Char_t val)
266 // Set byte value to buf
271 //______________________________________________________________________
272 void AliDCSMessage::SetUByte(char* buf, UChar_t val)
274 // Set ubyte value to buf
279 //______________________________________________________________________
280 void AliDCSMessage::SetInt(char* buf, Int_t val)
282 // Set int value to buf
287 //______________________________________________________________________
288 void AliDCSMessage::SetUInt(char* buf, UInt_t val)
290 // Set uint value to buf
295 //______________________________________________________________________
296 void AliDCSMessage::SetFloat(char* buf, Float_t val)
298 // Set float value to buf
303 //______________________________________________________________________
304 Bool_t AliDCSMessage::GetBool(const char* buf)
306 // get bool value from buf
309 char* aBuffer = (char*) buf;
311 frombuf(aBuffer, &val);
316 //______________________________________________________________________
317 Char_t AliDCSMessage::GetByte(const char* buf)
319 // get byte value from buf
322 char* aBuffer = (char*) buf;
324 frombuf(aBuffer, &val);
329 //______________________________________________________________________
330 UChar_t AliDCSMessage::GetUByte(const char* buf)
332 // get ubyte value from buf
335 char* aBuffer = (char*) buf;
337 frombuf(aBuffer, &val);
342 //______________________________________________________________________
343 Int_t AliDCSMessage::GetInt(const char* buf)
345 // get int value from buf
348 char* aBuffer = (char*) buf;
350 frombuf(aBuffer, &val);
355 //______________________________________________________________________
356 UInt_t AliDCSMessage::GetUInt(const char* buf)
358 // get uint value from buf
361 char* aBuffer = (char*) buf;
363 frombuf(aBuffer, &val);
368 //______________________________________________________________________
369 Float_t AliDCSMessage::GetFloat(const char* buf)
371 // get float value from buf
374 char* aBuffer = (char*) buf;
376 frombuf(aBuffer, &val);
381 //______________________________________________________________________
382 TString AliDCSMessage::GetString(const char* buf, Int_t maxLen)
384 // get string from buf
386 for (Int_t k = 0; k < maxLen; k ++) {
392 return TString(buf, maxLen);
395 //______________________________________________________________________
396 void AliDCSMessage::StoreHeader()
398 // store header message
400 SetUByte(fMessage + ID_OFFSET, 'A');
401 SetUByte(fMessage + ID_OFFSET + 1, 'D');
403 SetUByte(fMessage + VERSION_OFFSET, 2);
405 SetUByte(fMessage + TYPE_OFFSET, fType);
407 SetUInt(fMessage + BODY_SIZE_OFFSET, fMessageSize - HEADER_SIZE);
410 //______________________________________________________________________
411 void AliDCSMessage::StoreRequestMessage()
413 // store request message
415 fMessageSize = REQUEST_STRING_OFFSET +
416 fRequestString.Length() + 1;
418 fMessage = new char[fMessageSize];
422 SetUByte(fMessage + REQUEST_TYPE_OFFSET, fRequestType);
423 SetUInt(fMessage + START_TIME_OFFSET, fStartTime);
424 SetUInt(fMessage + END_TIME_OFFSET, fEndTime);
425 strcpy(fMessage + REQUEST_STRING_OFFSET, fRequestString.Data());
428 //______________________________________________________________________
429 void AliDCSMessage::StoreCountMessage()
431 // store count message
433 fMessageSize = COUNT_OFFSET + sizeof(UInt_t);
435 fMessage = new char[fMessageSize];
439 SetUInt(fMessage + COUNT_OFFSET, fCount);
442 //______________________________________________________________________
443 void AliDCSMessage::StoreResultSetMessage()
445 // store result set message
450 UInt_t valueDataSize = 0;
451 while ((aValue = (AliDCSValue*) iter.Next())) {
452 valueDataSize += aValue->GetSize();
455 fMessageSize = VALUES_OFFSET + valueDataSize;
457 fMessage = new char[fMessageSize];
461 SetUByte(fMessage + SVT_OFFSET, fValueType);
462 SetUInt(fMessage + VALUE_COUNT_OFFSET, GetValueCount());
464 UInt_t cursor = VALUES_OFFSET;
468 if (fValueType == AliDCSValue::kBool) {
469 while ((aValue = (AliDCSValue*) iter.Next())) {
470 SetBool(fMessage + cursor, aValue->GetBool());
472 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
473 cursor += sizeof(UInt_t);
475 } else if (fValueType == AliDCSValue::kChar) {
476 while ((aValue = (AliDCSValue*) iter.Next())) {
477 SetByte(fMessage + cursor, aValue->GetChar());
478 cursor += sizeof(Char_t);
479 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
480 cursor += sizeof(UInt_t);
482 } else if (fValueType == AliDCSValue::kInt) {
483 while ((aValue = (AliDCSValue*) iter.Next())) {
484 SetInt(fMessage + cursor, aValue->GetInt());
485 cursor += sizeof(Int_t);
486 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
487 cursor += sizeof(UInt_t);
489 } else if (fValueType == AliDCSValue::kUInt) {
490 while ((aValue = (AliDCSValue*) iter.Next())) {
491 SetUInt(fMessage + cursor, aValue->GetUInt());
492 cursor += sizeof(UInt_t);
493 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
494 cursor += sizeof(UInt_t);
496 } else if (fValueType == AliDCSValue::kFloat) {
497 while ((aValue = (AliDCSValue*) iter.Next())) {
498 SetFloat(fMessage + cursor, aValue->GetFloat());
499 cursor += sizeof(Float_t);
500 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
501 cursor += sizeof(UInt_t);
504 AliError("Invalid or unknown ValueType!");
510 //______________________________________________________________________
511 void AliDCSMessage::StoreErrorMessage()
513 // store error message
515 fMessageSize = ERROR_STRING_OFFSET + fErrorString.Length() + 1;
517 fMessage = new char[fMessageSize];
521 SetUByte(fMessage + ERROR_CODE_OFFSET, fErrorCode);
522 strcpy(fMessage + ERROR_STRING_OFFSET, fErrorString.Data());
525 //______________________________________________________________________
526 void AliDCSMessage::StoreMultiRequestMessage()
528 // store multi request message
530 UInt_t requestDataSize = 0;
532 TIter iter(&fRequestStrings);
533 TObjString* anObjString;
535 while ((anObjString = (TObjString*) iter.Next())) {
536 requestDataSize += anObjString->String().Length() + 1;
539 fMessageSize = REQUEST_STRINGS_OFFSET + requestDataSize;
541 fMessage = new char[fMessageSize];
545 SetUByte(fMessage + REQUEST_TYPE_OFFSET, fRequestType);
546 SetUInt(fMessage + START_TIME_OFFSET, fStartTime);
547 SetUInt(fMessage + END_TIME_OFFSET, fEndTime);
551 UInt_t cursor = REQUEST_STRINGS_OFFSET;
553 while ((anObjString = (TObjString*) iter.Next())) {
554 UChar_t strLength = anObjString->String().Length();
555 strncpy(fMessage + cursor, anObjString->String().Data(),
558 SetUByte(fMessage + cursor, 0);
563 //______________________________________________________________________
564 void AliDCSMessage::StoreNextMessage()
566 fMessageSize = HEADER_SIZE;
568 fMessage = new char[fMessageSize];
573 //______________________________________________________________________
574 Bool_t AliDCSMessage::ValidateHeader(const char* buf)
576 // validate message header
578 if (!(buf[ID_OFFSET] == 'A' && buf[ID_OFFSET + 1] == 'D')) {
579 AliError("Bad message ID!");
583 if (buf[VERSION_OFFSET] != 2) {
584 AliError("Bad message version!");
590 Type type = (Type) GetUByte(buf + TYPE_OFFSET);
601 AliError("Unknown message type!");
605 UInt_t bodySize = GetInt(buf + BODY_SIZE_OFFSET);
606 if (bodySize > MAX_BODY_SIZE) {
607 AliError("Too big message body size!");
614 //______________________________________________________________________
615 void AliDCSMessage::LoadRequestMessage()
617 // load request message
619 if (fMessageSize < REQUEST_STRING_OFFSET) {
620 AliError("Body size is too small for request message!");
624 fRequestType = (RequestType) GetUByte(fMessage + REQUEST_TYPE_OFFSET);
626 fStartTime = GetUInt(fMessage + START_TIME_OFFSET);
627 fEndTime = GetUInt(fMessage + END_TIME_OFFSET);
628 fRequestString = GetString(fMessage + REQUEST_STRING_OFFSET,
629 fMessageSize - REQUEST_STRING_OFFSET);
631 switch (fRequestType) {
637 AliError("Invalid request type!");
641 //______________________________________________________________________
642 void AliDCSMessage::LoadCountMessage()
644 // load count message
646 if (fMessageSize < HEADER_SIZE + sizeof(UInt_t)) {
647 AliError("Body size is too small for count message!");
651 fCount = GetUInt(fMessage + COUNT_OFFSET);
656 //______________________________________________________________________
657 void AliDCSMessage::LoadResultSetMessage()
659 // load result message
661 if (fMessageSize < VALUES_OFFSET) {
662 AliError("Body size is too small for result set message!");
666 fOwnerIndex = GetInt(fMessage + INDEX_OFFSET);
668 fValueType = (AliDCSValue::Type) GetUByte(fMessage + SVT_OFFSET);
669 UInt_t count = GetUInt(fMessage + VALUE_COUNT_OFFSET);
671 UInt_t cursor = VALUES_OFFSET;
674 if (fOwnerIndex >= 0)
676 if (fValueType == AliDCSValue::kBool) {
677 if (VALUES_OFFSET + count + count * sizeof(UInt_t) >
679 AliError("Too many bool values for this buffer size!");
683 for (UInt_t k = 0; k < count; k ++) {
684 Bool_t aBool = GetBool(fMessage + cursor);
686 UInt_t timeStamp = GetUInt(fMessage + cursor);
687 cursor += sizeof(UInt_t);
688 fValues->Add(new AliDCSValue(aBool, timeStamp));
690 } else if (fValueType == AliDCSValue::kChar) {
691 if (VALUES_OFFSET + count + count * sizeof(UInt_t) >
693 AliError("Too many byte values for this buffer size!");
697 for (UInt_t k = 0; k < count; k ++) {
698 Char_t aByte = GetByte(fMessage + cursor);
699 cursor += sizeof(Char_t);
700 UInt_t timeStamp = GetUInt(fMessage + cursor);
701 cursor += sizeof(UInt_t);
702 fValues->Add(new AliDCSValue(aByte, timeStamp));
704 } else if (fValueType == AliDCSValue::kInt) {
705 if (VALUES_OFFSET + count * sizeof(Int_t) +
706 count * sizeof(UInt_t) > fMessageSize) {
707 AliError("Too many int values for this buffer size!");
711 for (UInt_t k = 0; k < count; k ++) {
712 Int_t aInt = GetInt(fMessage + cursor);
713 cursor += sizeof(Int_t);
714 UInt_t timeStamp = GetUInt(fMessage + cursor);
715 cursor += sizeof(UInt_t);
716 fValues->Add(new AliDCSValue(aInt, timeStamp));
719 } else if (fValueType == AliDCSValue::kUInt) {
720 if (VALUES_OFFSET + count * sizeof(UInt_t) +
721 count * sizeof(UInt_t) > fMessageSize) {
722 AliError("Too many uint values for this buffer size!");
726 for (UInt_t k = 0; k < count; k ++) {
727 UInt_t aUInt = GetUInt(fMessage + cursor);
728 cursor += sizeof(UInt_t);
729 UInt_t timeStamp = GetUInt(fMessage + cursor);
730 cursor += sizeof(UInt_t);
731 fValues->Add(new AliDCSValue(aUInt, timeStamp));
733 } else if (fValueType == AliDCSValue::kFloat) {
734 if (VALUES_OFFSET + count * sizeof(Float_t) +
735 count * sizeof(UInt_t) > fMessageSize) {
736 AliError("Too many float values for this buffer size!");
740 for (UInt_t k = 0; k < count; k ++) {
741 Float_t aFloat = GetFloat(fMessage + cursor);
742 cursor += sizeof(Float_t);
743 UInt_t timeStamp = GetUInt(fMessage + cursor);
744 cursor += sizeof(UInt_t);
745 fValues->Add(new AliDCSValue(aFloat, timeStamp));
749 AliError("Unknown or invalid value type!");
756 //______________________________________________________________________
757 void AliDCSMessage::LoadErrorMessage()
759 // load error message
761 if (fMessageSize < ERROR_STRING_OFFSET) {
762 AliError("Body size is too small for error message!");
766 fErrorCode = (ErrorCode) GetUByte(fMessage + ERROR_CODE_OFFSET);
767 fErrorString = GetString(fMessage + ERROR_STRING_OFFSET,
768 fMessageSize - ERROR_STRING_OFFSET);
770 switch (fErrorCode) {
771 case kConnectionFailed:
772 case kUnexpectedPacketFormat:
773 case kDataRetrievingFailed:
774 case kUnsupportedProtocolVersion:
779 AliError("Invalid error code!");
784 //______________________________________________________________________
785 void AliDCSMessage::LoadUnknownDPMessage()
787 // load unknown message
789 if (fMessageSize < ERROR_STRING_OFFSET) {
790 AliError("Body size is too small for error message!");
796 fErrorString = GetString(fMessage + UNKNOWN_DP_OFFSET,
797 fMessageSize - UNKNOWN_DP_OFFSET);
801 //______________________________________________________________________
802 void AliDCSMessage::LoadMultiRequestMessage()
804 // load multi request message
806 if (fMessageSize - HEADER_SIZE < REQUEST_STRINGS_OFFSET) {
807 AliError("Body size is too small for multi request message!");
811 fRequestType = (RequestType) GetUByte(fMessage + REQUEST_TYPE_OFFSET);
813 fStartTime = GetUInt(fMessage + START_TIME_OFFSET);
814 fEndTime = GetUInt(fMessage + END_TIME_OFFSET);
816 switch (fRequestType) {
822 AliError("Invalid request type!");
826 UInt_t cursor = REQUEST_STRINGS_OFFSET;
828 while ((cursor < fMessageSize)) {
829 UChar_t strSize = GetUByte(fMessage + cursor);
832 if (cursor + strSize > fMessageSize) {
833 AliError("Invalid multi request message!");
837 TObjString* anObjString = new TObjString(
838 GetString(fMessage + cursor, strSize));
839 fRequestStrings.AddLast(anObjString);
844 fType = kMultiRequest;
847 //______________________________________________________________________
848 void AliDCSMessage::LoadNextMessage()
855 //______________________________________________________________________
856 void AliDCSMessage::LoadHeartBeatMessage()
863 //______________________________________________________________________
864 void AliDCSMessage::StoreToBuffer()
866 // Creates an underlying message buffer which can be sent to the socket.
872 StoreRequestMessage();
878 StoreResultSetMessage();
884 StoreMultiRequestMessage();
890 AliError("Can't store to buffer invalid message!");
894 //______________________________________________________________________
895 void AliDCSMessage::LoadFromBuffer()
897 // Reads the underlying message buffer and if it's valid message
898 // creates the corresponding message.
899 // If not set the message type kInvalid.
900 // This buffer is read from the socket.
905 AliError("Message buffer is empty! Can't load it.");
909 if (fMessageSize < HEADER_SIZE) {
910 AliError("Invalid message buffer. Too small for the header!");
914 if (!ValidateHeader(fMessage)) {
915 AliError("Invalid message header!");
919 UInt_t bodySize = GetUInt(fMessage + BODY_SIZE_OFFSET);
920 if (bodySize > fMessageSize - HEADER_SIZE) {
921 AliError("Message size is to small for the message body!");
925 fMessageSize = HEADER_SIZE + bodySize;
927 Type aType = (Type) GetUByte(fMessage + TYPE_OFFSET);
931 LoadRequestMessage();
937 LoadResultSetMessage();
943 LoadUnknownDPMessage();
946 LoadMultiRequestMessage();
951 LoadHeartBeatMessage();
954 AliError("Invalid message type!");
958 //______________________________________________________________________
959 AliDCSMessage::RequestType AliDCSMessage::GetRequestType() const
961 // Request and MultiRequest.
962 // Returns the request type: alias or dp (Data Point)
964 if (!(fType == kRequest || fType == kMultiRequest)) {
965 AliError("Invalid AliDCSMessage type!");
972 //______________________________________________________________________
973 UInt_t AliDCSMessage::GetStartTime() const
975 // Request and MultiRequest.
976 // Returns the request start time. (begining of the time interval).
978 if (!(fType == kRequest || fType == kMultiRequest)) {
979 AliError("Invalid AliDCSMessage type!");
986 //______________________________________________________________________
987 UInt_t AliDCSMessage::GetEndTime() const
989 // Request and MultiRequest.
990 // Returns the request start time. (end of the time interval).
993 if (!(fType == kRequest || fType == kMultiRequest)) {
994 AliError("Invalid AliDCSMessage type!");
1001 //______________________________________________________________________
1002 TString AliDCSMessage::GetRequestString() const
1005 // Returns the request string. (alias or dp)
1007 if (fType != kRequest) {
1008 AliError("Invalid AliDCSMessage type!");
1012 return fRequestString;
1015 //______________________________________________________________________
1016 Bool_t AliDCSMessage::AddRequestString(const char* request)
1019 // Add a request to the request set.
1020 // Returns kFALSE in case of invalid request (too long request string).
1021 // Otherwise returns kTRUE.
1024 if (fType != kMultiRequest) {
1025 AliError("Invalid AliDCSMessage type!");
1029 if (strlen(request) > 255) {
1030 AliError("Alias/dpName is too long! Max size 255.");
1034 fRequestStrings.AddLast(new TObjString(request));
1038 //______________________________________________________________________
1039 void AliDCSMessage::ClearRequestStrings()
1042 // Clears the request set.
1044 fRequestStrings.Delete();
1047 //______________________________________________________________________
1048 void AliDCSMessage::GetRequestStrings(TObjArray& result) const
1051 // Returns all request strings in this message.
1052 // result: container where the requests are returned. Collection of
1056 if (fType != kMultiRequest) {
1057 AliError("Invalid AliDCSMessage type!");
1061 TIter iter(&fRequestStrings);
1062 TObjString* anObjString;
1064 while ((anObjString = (TObjString*) iter.Next())) {
1065 result.AddLast(new TObjString(*anObjString));
1069 //______________________________________________________________________
1070 UInt_t AliDCSMessage::GetCount() const
1073 // Returns the total number of values.
1076 if (fType != kCount) {
1077 AliError("Invalid AliDCSMessage type!");
1084 //______________________________________________________________________
1085 AliDCSValue::Type AliDCSMessage::GetValueType() const
1088 // Returns simple value type (see AliDCSValue) for the values
1089 // in this ResultSet.
1091 if (fType != kResultSet) {
1092 AliError("Invalid AliDCSMessage type!");
1093 return AliDCSValue::kInvalid;
1099 //______________________________________________________________________
1100 UInt_t AliDCSMessage::GetValueCount() const
1103 // Returns the count of values in this ResultSet.
1106 if (fType != kResultSet) {
1107 AliError("Invalid AliDCSMessage type!");
1111 return fValues->GetEntriesFast();
1114 //______________________________________________________________________
1115 UInt_t AliDCSMessage::GetValues(TObjArray* result) const
1118 // Returns the number of values got from the message.
1119 // result: used to return the values. Collection of AliDCSValue.
1120 // result must be owner of the AliDCSValues because fVaule is not!
1121 // creator of the result array and used GetValues to fill it must delete object by himself!
1123 // TODO do not copy -> corrected?
1125 if (fType != kResultSet) {
1126 AliError("Invalid AliDCSMessage type!");
1130 TIter iter(fValues);
1131 AliDCSValue* aValue;
1133 while ((aValue = (AliDCSValue*) iter.Next())) {
1134 result->AddLast(aValue);
1137 return fValues->GetEntriesFast();
1141 //______________________________________________________________________
1142 Bool_t AliDCSMessage::AddValue(AliDCSValue& value)
1144 // Adds value to the ResultSet value list.
1145 // Returns kFALSE in case of error.
1146 // Otherwise returns kTRUE;
1148 if (fType != kResultSet) {
1149 AliError("Invalid AliDCSMessage type!");
1153 if (value.GetType() != fValueType) {
1154 AliError(Form("Can't add value with type %d to this message!", value.GetType()));
1158 fValues->Add(&value);
1164 //______________________________________________________________________
1165 void AliDCSMessage::ClearValues()
1167 // clear values array
1169 if(fValues) fValues->Clear();
1172 //______________________________________________________________________
1173 AliDCSMessage::ErrorCode AliDCSMessage::GetErrorCode() const
1177 // Returns the error code which has this error message.
1180 if (fType != kError) {
1181 AliError("Invalid AliDCSMessage type!");
1188 //______________________________________________________________________
1189 TString AliDCSMessage::GetErrorString() const
1193 // Returns the error string (error description) which has this
1197 if (GetType() == kError || GetType() == kUnknownDP) {
1198 return fErrorString;
1201 AliError("Invalid AliDCSMessage type!");
1206 //______________________________________________________________________
1207 void AliDCSMessage::Print(Option_t* /*option*/) const
1211 if (AliLog::GetGlobalDebugLevel() < 2) {
1215 TString printString;
1216 printString += "\n <<AliDCSMessage>> - ";
1218 printString += " Size: ";
1219 printString += fMessageSize;
1221 printString += " - Type: ";
1222 switch (GetType()) {
1224 printString += "Request\n";
1226 printString += " RequestType: ";
1227 if (GetRequestType() == kDPName) {
1228 printString += "DPName";
1230 printString += "Alias";
1232 printString += '\n';
1234 printString += " RequestString: ";
1235 printString += GetRequestString();
1236 printString += '\n';
1237 printString += " StartTime: ";
1238 printString += GetStartTime();
1239 printString += '\n';
1240 printString += " EndTime: ";
1241 printString += GetEndTime();
1242 printString += '\n';
1247 printString += "Count\n";
1248 printString += " Count: ";
1249 printString += GetCount();
1250 printString += '\n';
1255 printString += "ResultSet\n";
1256 printString += " OwnerIndex: ";
1257 printString += fOwnerIndex;
1258 printString += '\n';
1259 printString += " SimpleValueType: ";
1260 printString += fValueType;
1261 printString += '\n';
1262 printString += " ValueCount: ";
1263 printString += GetValueCount();
1264 printString += '\n';
1269 printString += "Error\n";
1270 printString += " ErrorCode: ";
1271 switch (GetErrorCode()) {
1272 case AliDCSMessage::kNoneError:
1273 printString += "NoneError";
1275 case AliDCSMessage::kConnectionFailed:
1276 printString += "ConnectionFailed";
1278 case AliDCSMessage::kUnexpectedPacketFormat:
1279 printString += "UnexpectedPacketFormat";
1281 case AliDCSMessage::kDataRetrievingFailed:
1282 printString += "DataRetrievingFailed";
1284 case AliDCSMessage::kUnsupportedProtocolVersion:
1285 printString += "UnsupportedProtocolVersion";
1287 case AliDCSMessage::kUnknownError:
1288 printString += "UnknownError";
1291 printString += "Invalid";
1294 printString += '\n';
1295 printString += " ErrorString: ";
1296 printString += GetErrorString();
1297 printString += '\n';
1302 printString += "UnknownAlias/DP\n";
1303 printString += '\n';
1304 printString += " Message: ";
1305 printString += GetErrorString();
1306 printString += '\n';
1310 case kMultiRequest: {
1311 printString += "MultiRequest\n";
1313 printString += " RequestType: ";
1314 if (GetRequestType() == kDPName) {
1315 printString += "DPName";
1317 printString += "Alias";
1319 printString += '\n';
1321 printString += " RequestStrings: ";
1322 TIter iter(&fRequestStrings);
1323 TObjString* anObjString;
1324 while ((anObjString = (TObjString*) iter.Next())) {
1325 printString += anObjString->String();
1328 printString += '\n';
1330 printString += " StartTime: ";
1331 printString += GetStartTime();
1332 printString += '\n';
1333 printString += " EndTime: ";
1334 printString += GetEndTime();
1335 printString += '\n';
1340 printString += "Next\n";
1345 printString += "HeartBeat\n";
1350 printString += "Invalid\n";
1353 if (AliLog::GetGlobalDebugLevel() >= 3 && fMessage) {
1354 PrintBuffer(fMessage, fMessageSize, printString);
1357 AliDebug(2, printString);
1360 //______________________________________________________________________
1361 Bool_t AliDCSMessage::SetRawHeader(const char* header)
1364 // Checks if the header buffer represents a valid header message.
1365 // If so it creates a message buffer with the appropriate body size
1366 // and returns true.
1367 // If not returns false.
1368 // header: header buffer
1371 if (!ValidateHeader(header)) {
1372 AliError("Invalid message header!");
1378 UInt_t bodySize = GetUInt(header + BODY_SIZE_OFFSET);
1379 fMessageSize = HEADER_SIZE + bodySize;
1381 fMessage = new char[fMessageSize];
1383 memcpy(fMessage, header, HEADER_SIZE);
1389 //______________________________________________________________________
1390 void AliDCSMessage::DestroyBuffer()
1393 // Destroy the underlying message buffer.
1404 //______________________________________________________________________
1405 void AliDCSMessage::PrintBuffer(const char* buffer, UInt_t size,
1412 while (index < size) {
1413 if (!(index % 16)) {
1414 output += Form("\n %.4x:", index);
1421 output += Form(" %.2x", (UChar_t) buffer[index]);
1423 if (!((index + 1) % 16) || index + 1 == size) {
1424 if (index + 1 == size) {
1425 output.Append(' ',3 * (15 - index % 16));
1426 if (index % 16 < 8) {
1431 output.Append(' ', 2);
1432 for (Int_t k = index % 16; k >= 0; k --) {
1433 Char_t aChar = buffer[index - k];
1434 output += isgraph(aChar) ? aChar: '.';