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.3 2005/11/17 17:47:34 byordano
19 TList changed to TObjArray
21 Revision 1.2 2005/11/17 14:43:23 byordano
24 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
25 Initial import as subdirectory in AliRoot
27 Revision 1.1.1.1 2005/09/12 22:11:40 byordano
30 Revision 1.2 2005/08/30 10:53:23 byordano
31 some more descriptions added
37 // This class is a wrapper of AliDCSMessage.
38 // These are the messages which form AliDCSProtocol.
39 // Every message has header and body. The body size is written in the header.
40 // There are five message types:
41 // 1) Request - used by the client to form a single request to DCS server
42 // 2) Count - returned by the server to inidicate the total number of
43 // values which would be sent to the client.
44 // 3) ResultSet - returned by the server and contains part of values set
45 // which forms the server resposen.
46 // 4) Error - returned by the server in case of error
47 // 5) MultiRequest - used by the client to form multi request.
48 // This is a request which serves many aliases/dp at the same time
49 // For all aliases/dp the same time interval is used.
50 // Short description of the schema:
51 // The client sends a request (Request or MultiRequest) and the server
53 // 1) Count - the total number of values that the client should
55 // 2) ResultSet* - every ResultSet message contains a part
56 // of valueSet (some values) which the client should expect
57 // The client can wait for ResultMessage until it gets
58 // all values (total number) which was returned by the
59 // Count message at the beginning of the ResutlSet sereie.
61 // 1) Error - contains the error code and error description
64 #include "AliDCSMessage.h"
69 #include <TObjString.h>
74 ClassImp(AliDCSMessage)
76 AliDCSMessage::AliDCSMessage():
77 fMessage(NULL), fMessageSize(0), fType(kInvalid)
82 AliDCSMessage::AliDCSMessage(const char* message, UInt_t size):
83 fMessageSize(size), fType(kInvalid)
85 fMessage = new char[size];
87 memcpy(fMessage, message, size);
90 AliDCSMessage::~AliDCSMessage() {
95 void AliDCSMessage::CreateRequestMessage(RequestType type,
96 UInt_t startTime, UInt_t endTime, const char* request)
100 fType = AliDCSMessage::kRequest;
102 fStartTime = startTime;
104 fRequestString = request;
107 void AliDCSMessage::CreateMultiRequestMessage(RequestType type,
108 UInt_t startTime, UInt_t endTime)
112 fType = AliDCSMessage::kMultiRequest;
114 fStartTime = startTime;
118 void AliDCSMessage::CreateCountMessage(UInt_t count) {
121 fType = AliDCSMessage::kCount;
125 void AliDCSMessage::CreateResultSetMessage(AliSimpleValue::Type type) {
128 fType = AliDCSMessage::kResultSet;
129 fSimpleValueType = type;
132 void AliDCSMessage::CreateErrorMessage(ErrorCode errorCode,
133 const char* errorString)
137 fType = AliDCSMessage::kError;
138 fErrorCode = errorCode;
139 fErrorString = errorString;
143 void AliDCSMessage::CreateNextMessage() {
146 fType = AliDCSMessage::kNext;
149 void AliDCSMessage::DestroyMessage() {
152 ClearRequestStrings();
155 void AliDCSMessage::SetBool(char* buf, Bool_t val) {
159 void AliDCSMessage::SetByte(char* buf, Char_t val) {
163 void AliDCSMessage::SetUByte(char* buf, UChar_t val) {
167 void AliDCSMessage::SetInt(char* buf, Int_t val) {
171 void AliDCSMessage::SetUInt(char* buf, UInt_t val) {
175 void AliDCSMessage::SetFloat(char* buf, Float_t val) {
179 Bool_t AliDCSMessage::GetBool(const char* buf) {
181 char* aBuffer = (char*) buf;
183 frombuf(aBuffer, &val);
188 Char_t AliDCSMessage::GetByte(const char* buf) {
190 char* aBuffer = (char*) buf;
192 frombuf(aBuffer, &val);
197 UChar_t AliDCSMessage::GetUByte(const char* buf) {
199 char* aBuffer = (char*) buf;
201 frombuf(aBuffer, &val);
206 Int_t AliDCSMessage::GetInt(const char* buf) {
208 char* aBuffer = (char*) buf;
210 frombuf(aBuffer, &val);
215 UInt_t AliDCSMessage::GetUInt(const char* buf) {
217 char* aBuffer = (char*) buf;
219 frombuf(aBuffer, &val);
224 Float_t AliDCSMessage::GetFloat(const char* buf) {
226 char* aBuffer = (char*) buf;
228 frombuf(aBuffer, &val);
233 TString AliDCSMessage::GetString(const char* buf, Int_t maxLen) {
235 for (Int_t k = 0; k < maxLen; k ++) {
241 return TString(buf, maxLen);
244 void AliDCSMessage::StoreHeader() {
246 SetUByte(fMessage + ID_OFFSET, 'A');
247 SetUByte(fMessage + ID_OFFSET + 1, 'D');
249 SetUByte(fMessage + VERSION_OFFSET, 1);
251 SetUByte(fMessage + TYPE_OFFSET, fType);
253 SetUInt(fMessage + BODY_SIZE_OFFSET, fMessageSize - HEADER_SIZE);
256 void AliDCSMessage::StoreRequestMessage() {
258 fMessageSize = REQUEST_STRING_OFFSET +
259 fRequestString.Length() + 1;
261 fMessage = new char[fMessageSize];
265 SetUByte(fMessage + REQUEST_TYPE_OFFSET, fRequestType);
266 SetUInt(fMessage + START_TIME_OFFSET, fStartTime);
267 SetUInt(fMessage + END_TIME_OFFSET, fEndTime);
268 strcpy(fMessage + REQUEST_STRING_OFFSET, fRequestString.Data());
271 void AliDCSMessage::StoreCountMessage() {
273 fMessageSize = COUNT_OFFSET + sizeof(UInt_t);
275 fMessage = new char[fMessageSize];
279 SetUInt(fMessage + COUNT_OFFSET, fCount);
282 void AliDCSMessage::StoreResultSetMessage() {
284 TIter iter(&fValues);
287 UInt_t valueDataSize = 0;
288 while ((aValue = (AliDCSValue*) iter.Next())) {
289 if (AliSimpleValue::IsDynamic(fSimpleValueType)) {
293 valueDataSize += aValue->GetSize();
296 fMessageSize = VALUES_OFFSET + valueDataSize;
298 fMessage = new char[fMessageSize];
302 SetUByte(fMessage + SVT_OFFSET, fSimpleValueType);
303 SetUInt(fMessage + VALUE_COUNT_OFFSET, GetValueCount());
305 UInt_t cursor = VALUES_OFFSET;
309 if (fSimpleValueType == AliSimpleValue::kBool) {
310 while ((aValue = (AliDCSValue*) iter.Next())) {
311 SetBool(fMessage + cursor, aValue->
312 GetSimpleValue().GetBool());
314 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
315 cursor += sizeof(UInt_t);
317 } else if (fSimpleValueType == AliSimpleValue::kByte) {
318 while ((aValue = (AliDCSValue*) iter.Next())) {
319 SetByte(fMessage + cursor, aValue->
320 GetSimpleValue().GetByte());
321 cursor += sizeof(Char_t);
322 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
323 cursor += sizeof(UInt_t);
325 } else if (fSimpleValueType == AliSimpleValue::kInt) {
326 while ((aValue = (AliDCSValue*) iter.Next())) {
327 SetInt(fMessage + cursor, aValue->
328 GetSimpleValue().GetInt());
329 cursor += sizeof(Int_t);
330 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
331 cursor += sizeof(UInt_t);
333 } else if (fSimpleValueType == AliSimpleValue::kUInt) {
334 while ((aValue = (AliDCSValue*) iter.Next())) {
335 SetUInt(fMessage + cursor, aValue->
336 GetSimpleValue().GetUInt());
337 cursor += sizeof(UInt_t);
338 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
339 cursor += sizeof(UInt_t);
341 } else if (fSimpleValueType == AliSimpleValue::kFloat) {
342 while ((aValue = (AliDCSValue*) iter.Next())) {
343 SetFloat(fMessage + cursor, aValue->
344 GetSimpleValue().GetFloat());
345 cursor += sizeof(Float_t);
346 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
347 cursor += sizeof(UInt_t);
349 /* } else if (fSimpleValueType == AliSimpleValue::kDynBool) {
350 while ((aValue = (AliDCSValue*) iter.Next())) {
351 Int_t dynSize = aValue->GetSimpleValue().
353 SetUByte(fMessage + cursor, dynSize);
355 for (Int_t k = 0; k < dynSize; k ++) {
356 SetBool(fMessage + cursor, aValue->
357 GetSimpleValue().GetDynBool(k));
360 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
361 cursor += sizeof(UInt_t);
363 } else if (fSimpleValueType == AliSimpleValue::kDynByte) {
364 while ((aValue = (AliDCSValue*) iter.Next())) {
365 Int_t dynSize = aValue->GetSimpleValue().
367 SetUByte(fMessage + cursor, dynSize);
369 for (Int_t k = 0; k < dynSize; k ++) {
370 SetByte(fMessage + cursor, aValue->
371 GetSimpleValue().GetDynByte(k));
372 cursor += sizeof(Char_t);
374 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
375 cursor += sizeof(UInt_t);
377 } else if (fSimpleValueType == AliSimpleValue::kDynInt) {
378 while ((aValue = (AliDCSValue*) iter.Next())) {
379 Int_t dynSize = aValue->GetSimpleValue().
381 SetUByte(fMessage + cursor, dynSize);
383 for (Int_t k = 0; k < dynSize; k ++) {
384 SetInt(fMessage + cursor, aValue->
385 GetSimpleValue().GetDynInt(k));
386 cursor += sizeof(Int_t);
388 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
389 cursor += sizeof(UInt_t);
391 } else if (fSimpleValueType == AliSimpleValue::kDynUInt) {
392 while ((aValue = (AliDCSValue*) iter.Next())) {
393 Int_t dynSize = aValue->GetSimpleValue().
395 SetUByte(fMessage + cursor, dynSize);
397 for (Int_t k = 0; k < dynSize; k ++) {
398 SetUInt(fMessage + cursor, aValue->
399 GetSimpleValue().GetDynUInt(k));
400 cursor += sizeof(UInt_t);
402 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
403 cursor += sizeof(UInt_t);
405 } else if (fSimpleValueType == AliSimpleValue::kDynFloat) {
406 while ((aValue = (AliDCSValue*) iter.Next())) {
407 Int_t dynSize = aValue->GetSimpleValue().
409 SetUByte(fMessage + cursor, dynSize);
411 for (Int_t k = 0; k < dynSize; k ++) {
412 SetFloat(fMessage + cursor, aValue->
413 GetSimpleValue().GetDynFloat(k));
414 cursor += sizeof(Float_t);
416 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
417 cursor += sizeof(UInt_t);
420 AliError("Invalid or unknown SimpleValueType!");
426 void AliDCSMessage::StoreErrorMessage() {
428 fMessageSize = ERROR_STRING_OFFSET + fErrorString.Length() + 1;
430 fMessage = new char[fMessageSize];
434 SetUByte(fMessage + ERROR_CODE_OFFSET, fErrorCode);
435 strcpy(fMessage + ERROR_STRING_OFFSET, fErrorString.Data());
438 void AliDCSMessage::StoreMultiRequestMessage() {
440 UInt_t requestDataSize = 0;
442 TIter iter(&fRequestStrings);
443 TObjString* anObjString;
445 while ((anObjString = (TObjString*) iter.Next())) {
446 assert(anObjString->String().Length() <= 255);
447 requestDataSize += anObjString->String().Length() + 1;
450 fMessageSize = REQUEST_STRINGS_OFFSET + requestDataSize;
452 fMessage = new char[fMessageSize];
456 SetUByte(fMessage + REQUEST_TYPE_OFFSET, fRequestType);
457 SetUInt(fMessage + START_TIME_OFFSET, fStartTime);
458 SetUInt(fMessage + END_TIME_OFFSET, fEndTime);
462 UInt_t cursor = REQUEST_STRINGS_OFFSET;
464 while ((anObjString = (TObjString*) iter.Next())) {
465 UChar_t strLength = anObjString->String().Length();
466 SetUByte(fMessage + cursor, strLength);
468 strncpy(fMessage + cursor, anObjString->String().Data(),
475 void AliDCSMessage::StoreNextMessage() {
477 fMessageSize = HEADER_SIZE;
479 fMessage = new char[fMessageSize];
484 Bool_t AliDCSMessage::ValidateHeader(const char* buf) {
486 if (!(buf[ID_OFFSET] == 'A' && buf[ID_OFFSET + 1] == 'D')) {
487 AliError("Bad message ID!");
491 if (buf[VERSION_OFFSET] != 1) {
492 AliError("Bad message version!");
496 Type type = (Type) GetUByte(buf + TYPE_OFFSET);
505 AliError("Unknown message type!");
509 UInt_t bodySize = GetInt(buf + BODY_SIZE_OFFSET);
510 if (bodySize > MAX_BODY_SIZE) {
511 AliError("Too big message body size!");
518 void AliDCSMessage::LoadRequestMessage() {
520 if (fMessageSize < REQUEST_STRING_OFFSET) {
521 AliError("Body size is too small for request message!");
525 fRequestType = (RequestType) GetUByte(fMessage + REQUEST_TYPE_OFFSET);
527 fStartTime = GetUInt(fMessage + START_TIME_OFFSET);
528 fEndTime = GetUInt(fMessage + END_TIME_OFFSET);
529 fRequestString = GetString(fMessage + REQUEST_STRING_OFFSET,
530 fMessageSize - REQUEST_STRING_OFFSET);
532 switch (fRequestType) {
538 AliError("Invalid request type!");
542 void AliDCSMessage::LoadCountMessage() {
544 if (fMessageSize < HEADER_SIZE + sizeof(UInt_t)) {
545 AliError("Body size is too small for count message!");
549 fCount = GetUInt(fMessage + COUNT_OFFSET);
554 void AliDCSMessage::LoadResultSetMessage() {
556 if (fMessageSize < VALUES_OFFSET) {
557 AliError("Body size is too small for result set message!");
561 fSimpleValueType = (AliSimpleValue::Type) GetUByte(
562 fMessage + SVT_OFFSET);
563 UInt_t count = GetUInt(fMessage + VALUE_COUNT_OFFSET);
565 UInt_t cursor = VALUES_OFFSET;
567 if (fSimpleValueType == AliSimpleValue::kBool) {
568 if (VALUES_OFFSET + count + count * sizeof(UInt_t) >
570 AliError("Too many bool values for this buffer size!");
574 for (UInt_t k = 0; k < count; k ++) {
575 Bool_t aBool = GetBool(fMessage + cursor);
577 UInt_t timeStamp = GetUInt(fMessage + cursor);
578 cursor += sizeof(UInt_t);
579 fValues.Add(new AliDCSValue(aBool, timeStamp));
581 } else if (fSimpleValueType == AliSimpleValue::kByte) {
582 if (VALUES_OFFSET + count + count * sizeof(UInt_t) >
584 AliError("Too many byte values for this buffer size!");
588 for (UInt_t k = 0; k < count; k ++) {
589 Char_t aByte = GetByte(fMessage + cursor);
590 cursor += sizeof(Char_t);
591 UInt_t timeStamp = GetUInt(fMessage + cursor);
592 cursor += sizeof(UInt_t);
593 fValues.Add(new AliDCSValue(aByte, timeStamp));
595 } else if (fSimpleValueType == AliSimpleValue::kInt) {
596 if (VALUES_OFFSET + count * sizeof(Int_t) +
597 count * sizeof(UInt_t) > fMessageSize) {
598 AliError("Too many int values for this buffer size!");
602 for (UInt_t k = 0; k < count; k ++) {
603 Int_t aInt = GetInt(fMessage + cursor);
604 cursor += sizeof(Int_t);
605 UInt_t timeStamp = GetUInt(fMessage + cursor);
606 cursor += sizeof(UInt_t);
607 fValues.Add(new AliDCSValue(aInt, timeStamp));
610 } else if (fSimpleValueType == AliSimpleValue::kUInt) {
611 if (VALUES_OFFSET + count * sizeof(UInt_t) +
612 count * sizeof(UInt_t) > fMessageSize) {
613 AliError("Too many uint values for this buffer size!");
617 for (UInt_t k = 0; k < count; k ++) {
618 UInt_t aUInt = GetUInt(fMessage + cursor);
619 cursor += sizeof(UInt_t);
620 UInt_t timeStamp = GetUInt(fMessage + cursor);
621 cursor += sizeof(UInt_t);
622 fValues.Add(new AliDCSValue(aUInt, timeStamp));
624 } else if (fSimpleValueType == AliSimpleValue::kFloat) {
625 if (VALUES_OFFSET + count * sizeof(Float_t) +
626 count * sizeof(UInt_t) > fMessageSize) {
627 AliError("Too many float values for this buffer size!");
631 for (UInt_t k = 0; k < count; k ++) {
632 Float_t aFloat = GetFloat(fMessage + cursor);
633 cursor += sizeof(Float_t);
634 UInt_t timeStamp = GetUInt(fMessage + cursor);
635 cursor += sizeof(UInt_t);
636 fValues.Add(new AliDCSValue(aFloat, timeStamp));
640 AliError("Unknown or invalid simple value type!");
646 void AliDCSMessage::LoadErrorMessage() {
648 if (fMessageSize < ERROR_STRING_OFFSET) {
649 AliError("Body size is too small for error message!");
653 fErrorCode = (ErrorCode) GetUByte(fMessage + ERROR_CODE_OFFSET);
654 fErrorString = GetString(fMessage + ERROR_STRING_OFFSET,
655 fMessageSize - ERROR_STRING_OFFSET);
657 switch (fErrorCode) {
658 case kUnknownAliasDPName:
659 case kInvalidTimeRange:
660 case kInvalidBufferSize:
661 case kInvalidRequest:
662 case kUnsupportedType:
667 AliError("Invalid error code!");
671 void AliDCSMessage::LoadMultiRequestMessage() {
673 if (fMessageSize - HEADER_SIZE < REQUEST_STRINGS_OFFSET) {
674 AliError("Body size is too small for multi request message!");
678 fRequestType = (RequestType) GetUByte(fMessage + REQUEST_TYPE_OFFSET);
680 fStartTime = GetUInt(fMessage + START_TIME_OFFSET);
681 fEndTime = GetUInt(fMessage + END_TIME_OFFSET);
683 switch (fRequestType) {
689 AliError("Invalid request type!");
693 UInt_t cursor = REQUEST_STRINGS_OFFSET;
695 while ((cursor < fMessageSize)) {
696 UChar_t strSize = GetUByte(fMessage + cursor);
699 if (cursor + strSize > fMessageSize) {
700 AliError("Invalid multi request message!");
704 TObjString* anObjString = new TObjString(
705 GetString(fMessage + cursor, strSize));
706 fRequestStrings.AddLast(anObjString);
711 fType = kMultiRequest;
715 void AliDCSMessage::LoadNextMessage() {
720 void AliDCSMessage::StoreToBuffer() {
722 // Creates an underlying message buffer which can be sent to the
730 StoreRequestMessage();
736 StoreResultSetMessage();
742 StoreMultiRequestMessage();
748 AliError("Can't store to buffer invalid message!");
752 void AliDCSMessage::LoadFromBuffer() {
754 // Reads the underlying message buffer and if it's valid message
755 // creates the corresponding message.
756 // If not set the message type kInvalid.
757 // This buffer is read from the socket.
763 AliError("Message buffer is empty! Can't load it.");
767 if (fMessageSize < HEADER_SIZE) {
768 AliError("Invalid message buffer. Too small for the header!");
772 if (!ValidateHeader(fMessage)) {
773 AliError("Invalid message header!");
777 UInt_t bodySize = GetUInt(fMessage + BODY_SIZE_OFFSET);
778 if (bodySize > fMessageSize - HEADER_SIZE) {
779 AliError("Message size is to small for the message body!");
783 fMessageSize = HEADER_SIZE + bodySize;
785 Type aType = (Type) GetUByte(fMessage + TYPE_OFFSET);
789 LoadRequestMessage();
795 LoadResultSetMessage();
801 LoadMultiRequestMessage();
807 AliError("Invalid message type!");
811 AliDCSMessage::RequestType AliDCSMessage::GetRequestType() const {
813 // Request and MultiRequest.
814 // Returns the request type: alias or dp (Data Point)
817 if (!(fType == kRequest || fType == kMultiRequest)) {
818 AliError("Invalid AliDCSMessage type!");
825 UInt_t AliDCSMessage::GetStartTime() const {
827 // Request and MultiRequest.
828 // Returns the request start time. (begining of the time interval).
831 if (!(fType == kRequest || fType == kMultiRequest)) {
832 AliError("Invalid AliDCSMessage type!");
839 UInt_t AliDCSMessage::GetEndTime() const {
841 // Request and MultiRequest.
842 // Returns the request start time. (end of the time interval).
846 if (!(fType == kRequest || fType == kMultiRequest)) {
847 AliError("Invalid AliDCSMessage type!");
854 TString AliDCSMessage::GetRequestString() const {
857 // Returns the request string. (alias or dp)
860 if (fType != kRequest) {
861 AliError("Invalid AliDCSMessage type!");
865 return fRequestString;
868 Bool_t AliDCSMessage::AddRequestString(const char* request) {
871 // Add a request to the request set.
872 // Returns kFALSE in case of invalid request (too long request string).
873 // Otherwise returns kTRUE.
877 if (fType != kMultiRequest) {
878 AliError("Invalid AliDCSMessage type!");
882 if (strlen(request) > 255) {
883 AliError("Alias/dpName is too long! Max size 255.");
887 fRequestStrings.AddLast(new TObjString(request));
891 void AliDCSMessage::ClearRequestStrings() {
894 // Clears the request set.
897 fRequestStrings.Delete();
900 void AliDCSMessage::GetRequestStrings(TObjArray& result) const {
903 // Returns all request strings in this message.
904 // result: container where the requests are returned. Collection of
909 if (fType != kMultiRequest) {
910 AliError("Invalid AliDCSMessage type!");
914 TIter iter(&fRequestStrings);
915 TObjString* anObjString;
917 while ((anObjString = (TObjString*) iter.Next())) {
918 result.AddLast(new TObjString(*anObjString));
922 UInt_t AliDCSMessage::GetCount() const {
925 // Returns the total number of values.
929 if (fType != kCount) {
930 AliError("Invalid AliDCSMessage type!");
937 AliSimpleValue::Type AliDCSMessage::GetSimpleValueType() const {
940 // Returns simple value type (see AliSimpleValue) for the values
941 // in this ResultSet.
945 if (fType != kResultSet) {
946 AliError("Invalid AliDCSMessage type!");
947 return AliSimpleValue::kInvalid;
950 return fSimpleValueType;
953 UInt_t AliDCSMessage::GetValueCount() const {
956 // Returns the count of values in this ResultSet.
960 if (fType != kResultSet) {
961 AliError("Invalid AliDCSMessage type!");
965 return fValues.GetEntriesFast();
968 UInt_t AliDCSMessage::GetValues(TObjArray& result) const {
971 // Returns the number of values got from the message.
972 // result: used to return the values. Collection of AliDCSValue.
976 if (fType != kResultSet) {
977 AliError("Invalid AliDCSMessage type!");
981 TIter iter(&fValues);
984 while ((aValue = (AliDCSValue*) iter.Next())) {
985 result.AddLast(new AliDCSValue(*aValue));
988 return fValues.GetEntriesFast();
991 Bool_t AliDCSMessage::AddValue(const AliDCSValue& value) {
994 // Adds value to the ResultSet value list.
995 // Returns kFALSE in case of error.
996 // Otherwise returns kTRUE;
999 if (fType != kResultSet) {
1000 AliError("Invalid AliDCSMessage type!");
1004 if (value.GetSimpleValue().GetType() != fSimpleValueType) {
1005 AliError(Form("Can't add value with type %s to this message!",
1006 AliSimpleValue::GetTypeString(
1007 value.GetSimpleValue().GetType())));
1011 fValues.Add(new AliDCSValue(value));
1016 void AliDCSMessage::ClearValues() {
1020 AliDCSMessage::ErrorCode AliDCSMessage::GetErrorCode() const {
1023 // Returns the error code which has this error message.
1026 if (fType != kError) {
1027 AliError("Invalid AliDCSMessage type!");
1034 TString AliDCSMessage::GetErrorString() const {
1037 // Returns the error string (error description) which has this
1041 if (GetType() != kError) {
1042 AliError("Invalid AliDCSMessage type!");
1046 return fErrorString;
1050 void AliDCSMessage::Print(Option_t* /*option*/) const {
1052 if (AliLog::GetGlobalDebugLevel() < 2) {
1056 TString printString;
1057 printString += "\n <<AliDCSMessage>>\n";
1059 printString += " Size: ";
1060 printString += fMessageSize;
1061 printString += '\n';
1063 printString += " Type: ";
1064 switch (GetType()) {
1066 printString += "Request\n";
1068 printString += " RequestType: ";
1069 if (GetRequestType() == kDPName) {
1070 printString += "DPName";
1072 printString += "Alias";
1074 printString += '\n';
1076 printString += " RequestString: ";
1077 printString += GetRequestString();
1078 printString += '\n';
1079 printString += " StartTime: ";
1080 printString += GetStartTime();
1081 printString += '\n';
1082 printString += " EndTime: ";
1083 printString += GetEndTime();
1084 printString += '\n';
1089 printString += "Count\n";
1090 printString += " Count: ";
1091 printString += GetCount();
1092 printString += '\n';
1097 printString += "ResultSet\n";
1098 printString += " SimpleValueType: ";
1099 printString += AliSimpleValue::GetTypeString(
1101 printString += '\n';
1102 printString += " ValueCount: ";
1103 printString += GetValueCount();
1104 printString += '\n';
1109 printString += "Error\n";
1110 printString += " ErrorCode: ";
1111 switch (GetErrorCode()) {
1112 case AliDCSMessage::kNoneError:
1113 printString += "NoneError";
1115 case AliDCSMessage::kUnknownAliasDPName:
1116 printString += "UnknownAliasDPName";
1118 case AliDCSMessage::kInvalidTimeRange:
1119 printString += "InvalidTimeRange";
1121 case AliDCSMessage::kInvalidBufferSize:
1122 printString += "InvalidBufferSize";
1124 case AliDCSMessage::kInvalidRequest:
1125 printString += "InvalidRequest";
1127 case AliDCSMessage::kUnsupportedType:
1128 printString += "UnsupportedType";
1130 case AliDCSMessage::kUnknownError:
1131 printString += "UnknownError";
1134 printString += "Invalid";
1137 printString += '\n';
1138 printString += " ErrorString: ";
1139 printString += GetErrorString();
1140 printString += '\n';
1144 case kMultiRequest: {
1145 printString += "MultiRequest\n";
1147 printString += " RequestType: ";
1148 if (GetRequestType() == kDPName) {
1149 printString += "DPName";
1151 printString += "Alias";
1153 printString += '\n';
1155 printString += " RequestStrings: ";
1156 TIter iter(&fRequestStrings);
1157 TObjString* anObjString;
1158 while ((anObjString = (TObjString*) iter.Next())) {
1159 printString += anObjString->String();
1162 printString += '\n';
1164 printString += " StartTime: ";
1165 printString += GetStartTime();
1166 printString += '\n';
1167 printString += " EndTime: ";
1168 printString += GetEndTime();
1169 printString += '\n';
1174 printString += "Next\n";
1179 printString += "Invalid\n";
1182 if (AliLog::GetGlobalDebugLevel() >= 3 && fMessage) {
1183 PrintBuffer(fMessage, fMessageSize, printString);
1186 AliDebug(2, printString);
1189 Bool_t AliDCSMessage::SetRawHeader(const char* header) {
1191 // Checks if the header buffer represents a valid header message.
1192 // If so it creates a message buffer with the appropriate body size
1193 // and returns true.
1194 // If not returns false.
1195 // header: header buffer
1198 if (!ValidateHeader(header)) {
1199 AliError("Invalid message header!");
1205 UInt_t bodySize = GetUInt(header + BODY_SIZE_OFFSET);
1206 fMessageSize = HEADER_SIZE + bodySize;
1208 fMessage = new char[fMessageSize];
1210 memcpy(fMessage, header, HEADER_SIZE);
1216 void AliDCSMessage::DestroyBuffer() {
1218 // Destroy the underlying message buffer.
1229 void AliDCSMessage::PrintBuffer(const char* buffer, UInt_t size,
1235 while (index < size) {
1236 if (!(index % 16)) {
1237 output += Form("\n %.4x:", index);
1244 output += Form(" %.2x", (UChar_t) buffer[index]);
1246 if (!((index + 1) % 16) || index + 1 == size) {
1247 if (index + 1 == size) {
1248 output.Append(' ',3 * (15 - index % 16));
1249 if (index % 16 < 8) {
1254 output.Append(' ', 2);
1255 for (Int_t k = index % 16; k >= 0; k --) {
1256 Char_t aChar = buffer[index - k];
1257 output += isgraph(aChar) ? aChar: '.';