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.1.1.1 2005/09/12 22:11:40 byordano
21 Revision 1.2 2005/08/30 10:53:23 byordano
22 some more descriptions added
28 // This class is a wrapper of AliDCSMessage.
29 // These are the messages which form AliDCSProtocol.
30 // Every message has header and body. The body size is written in the header.
31 // There are five message types:
32 // 1) Request - used by the client to form a single request to DCS server
33 // 2) Count - returned by the server to inidicate the total number of
34 // values which would be sent to the client.
35 // 3) ResultSet - returned by the server and contains part of values set
36 // which forms the server resposen.
37 // 4) Error - returned by the server in case of error
38 // 5) MultiRequest - used by the client to form multi request.
39 // This is a request which serves many aliases/dp at the same time
40 // For all aliases/dp the same time interval is used.
41 // Short description of the schema:
42 // The client sends a request (Request or MultiRequest) and the server
44 // 1) Count - the total number of values that the client should
46 // 2) ResultSet* - every ResultSet message contains a part
47 // of valueSet (some values) which the client should expect
48 // The client can wait for ResultMessage until it gets
49 // all values (total number) which was returned by the
50 // Count message at the beginning of the ResutlSet sereie.
52 // 1) Error - contains the error code and error description
55 #include "AliDCSMessage.h"
60 #include <TObjString.h>
65 ClassImp(AliDCSMessage)
67 AliDCSMessage::AliDCSMessage():
68 fMessage(NULL), fMessageSize(0), fType(kInvalid)
73 AliDCSMessage::AliDCSMessage(const char* message, UInt_t size):
74 fMessageSize(size), fType(kInvalid)
76 fMessage = new char[size];
78 memcpy(fMessage, message, size);
81 AliDCSMessage::~AliDCSMessage() {
86 void AliDCSMessage::CreateRequestMessage(RequestType type,
87 UInt_t startTime, UInt_t endTime, const char* request)
91 fType = AliDCSMessage::kRequest;
93 fStartTime = startTime;
95 fRequestString = request;
98 void AliDCSMessage::CreateMultiRequestMessage(RequestType type,
99 UInt_t startTime, UInt_t endTime)
103 fType = AliDCSMessage::kMultiRequest;
105 fStartTime = startTime;
109 void AliDCSMessage::CreateCountMessage(UInt_t count) {
112 fType = AliDCSMessage::kCount;
116 void AliDCSMessage::CreateResultSetMessage(AliSimpleValue::Type type) {
119 fType = AliDCSMessage::kResultSet;
120 fSimpleValueType = type;
123 void AliDCSMessage::CreateErrorMessage(ErrorCode errorCode,
124 const char* errorString)
128 fType = AliDCSMessage::kError;
129 fErrorCode = errorCode;
130 fErrorString = errorString;
134 void AliDCSMessage::CreateNextMessage() {
137 fType = AliDCSMessage::kNext;
140 void AliDCSMessage::DestroyMessage() {
143 ClearRequestStrings();
146 void AliDCSMessage::SetBool(char* buf, Bool_t val) {
150 void AliDCSMessage::SetByte(char* buf, Char_t val) {
154 void AliDCSMessage::SetUByte(char* buf, UChar_t val) {
158 void AliDCSMessage::SetInt(char* buf, Int_t val) {
162 void AliDCSMessage::SetUInt(char* buf, UInt_t val) {
166 void AliDCSMessage::SetFloat(char* buf, Float_t val) {
170 Bool_t AliDCSMessage::GetBool(const char* buf) {
172 char* aBuffer = (char*) buf;
174 frombuf(aBuffer, &val);
179 Char_t AliDCSMessage::GetByte(const char* buf) {
181 char* aBuffer = (char*) buf;
183 frombuf(aBuffer, &val);
188 UChar_t AliDCSMessage::GetUByte(const char* buf) {
190 char* aBuffer = (char*) buf;
192 frombuf(aBuffer, &val);
197 Int_t AliDCSMessage::GetInt(const char* buf) {
199 char* aBuffer = (char*) buf;
201 frombuf(aBuffer, &val);
206 UInt_t AliDCSMessage::GetUInt(const char* buf) {
208 char* aBuffer = (char*) buf;
210 frombuf(aBuffer, &val);
215 Float_t AliDCSMessage::GetFloat(const char* buf) {
217 char* aBuffer = (char*) buf;
219 frombuf(aBuffer, &val);
224 TString AliDCSMessage::GetString(const char* buf, Int_t maxLen) {
226 for (Int_t k = 0; k < maxLen; k ++) {
232 return TString(buf, maxLen);
235 void AliDCSMessage::StoreHeader() {
237 SetUByte(fMessage + ID_OFFSET, 'A');
238 SetUByte(fMessage + ID_OFFSET + 1, 'D');
240 SetUByte(fMessage + VERSION_OFFSET, 1);
242 SetUByte(fMessage + TYPE_OFFSET, fType);
244 SetUInt(fMessage + BODY_SIZE_OFFSET, fMessageSize - HEADER_SIZE);
247 void AliDCSMessage::StoreRequestMessage() {
249 fMessageSize = REQUEST_STRING_OFFSET +
250 fRequestString.Length() + 1;
252 fMessage = new char[fMessageSize];
256 SetUByte(fMessage + REQUEST_TYPE_OFFSET, fRequestType);
257 SetUInt(fMessage + START_TIME_OFFSET, fStartTime);
258 SetUInt(fMessage + END_TIME_OFFSET, fEndTime);
259 strcpy(fMessage + REQUEST_STRING_OFFSET, fRequestString.Data());
262 void AliDCSMessage::StoreCountMessage() {
264 fMessageSize = COUNT_OFFSET + sizeof(UInt_t);
266 fMessage = new char[fMessageSize];
270 SetUInt(fMessage + COUNT_OFFSET, fCount);
273 void AliDCSMessage::StoreResultSetMessage() {
275 TIter iter(&fValues);
278 UInt_t valueDataSize = 0;
279 while ((aValue = (AliDCSValue*) iter.Next())) {
280 if (AliSimpleValue::IsDynamic(fSimpleValueType)) {
284 valueDataSize += aValue->GetSize();
287 fMessageSize = VALUES_OFFSET + valueDataSize;
289 fMessage = new char[fMessageSize];
293 SetUByte(fMessage + SVT_OFFSET, fSimpleValueType);
294 SetUInt(fMessage + VALUE_COUNT_OFFSET, GetValueCount());
296 UInt_t cursor = VALUES_OFFSET;
300 if (fSimpleValueType == AliSimpleValue::kBool) {
301 while ((aValue = (AliDCSValue*) iter.Next())) {
302 SetBool(fMessage + cursor, aValue->
303 GetSimpleValue().GetBool());
305 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
306 cursor += sizeof(UInt_t);
308 } else if (fSimpleValueType == AliSimpleValue::kByte) {
309 while ((aValue = (AliDCSValue*) iter.Next())) {
310 SetByte(fMessage + cursor, aValue->
311 GetSimpleValue().GetByte());
312 cursor += sizeof(Char_t);
313 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
314 cursor += sizeof(UInt_t);
316 } else if (fSimpleValueType == AliSimpleValue::kInt) {
317 while ((aValue = (AliDCSValue*) iter.Next())) {
318 SetInt(fMessage + cursor, aValue->
319 GetSimpleValue().GetInt());
320 cursor += sizeof(Int_t);
321 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
322 cursor += sizeof(UInt_t);
324 } else if (fSimpleValueType == AliSimpleValue::kUInt) {
325 while ((aValue = (AliDCSValue*) iter.Next())) {
326 SetUInt(fMessage + cursor, aValue->
327 GetSimpleValue().GetUInt());
328 cursor += sizeof(UInt_t);
329 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
330 cursor += sizeof(UInt_t);
332 } else if (fSimpleValueType == AliSimpleValue::kFloat) {
333 while ((aValue = (AliDCSValue*) iter.Next())) {
334 SetFloat(fMessage + cursor, aValue->
335 GetSimpleValue().GetFloat());
336 cursor += sizeof(Float_t);
337 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
338 cursor += sizeof(UInt_t);
340 /* } else if (fSimpleValueType == AliSimpleValue::kDynBool) {
341 while ((aValue = (AliDCSValue*) iter.Next())) {
342 Int_t dynSize = aValue->GetSimpleValue().
344 SetUByte(fMessage + cursor, dynSize);
346 for (Int_t k = 0; k < dynSize; k ++) {
347 SetBool(fMessage + cursor, aValue->
348 GetSimpleValue().GetDynBool(k));
351 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
352 cursor += sizeof(UInt_t);
354 } else if (fSimpleValueType == AliSimpleValue::kDynByte) {
355 while ((aValue = (AliDCSValue*) iter.Next())) {
356 Int_t dynSize = aValue->GetSimpleValue().
358 SetUByte(fMessage + cursor, dynSize);
360 for (Int_t k = 0; k < dynSize; k ++) {
361 SetByte(fMessage + cursor, aValue->
362 GetSimpleValue().GetDynByte(k));
363 cursor += sizeof(Char_t);
365 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
366 cursor += sizeof(UInt_t);
368 } else if (fSimpleValueType == AliSimpleValue::kDynInt) {
369 while ((aValue = (AliDCSValue*) iter.Next())) {
370 Int_t dynSize = aValue->GetSimpleValue().
372 SetUByte(fMessage + cursor, dynSize);
374 for (Int_t k = 0; k < dynSize; k ++) {
375 SetInt(fMessage + cursor, aValue->
376 GetSimpleValue().GetDynInt(k));
377 cursor += sizeof(Int_t);
379 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
380 cursor += sizeof(UInt_t);
382 } else if (fSimpleValueType == AliSimpleValue::kDynUInt) {
383 while ((aValue = (AliDCSValue*) iter.Next())) {
384 Int_t dynSize = aValue->GetSimpleValue().
386 SetUByte(fMessage + cursor, dynSize);
388 for (Int_t k = 0; k < dynSize; k ++) {
389 SetUInt(fMessage + cursor, aValue->
390 GetSimpleValue().GetDynUInt(k));
391 cursor += sizeof(UInt_t);
393 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
394 cursor += sizeof(UInt_t);
396 } else if (fSimpleValueType == AliSimpleValue::kDynFloat) {
397 while ((aValue = (AliDCSValue*) iter.Next())) {
398 Int_t dynSize = aValue->GetSimpleValue().
400 SetUByte(fMessage + cursor, dynSize);
402 for (Int_t k = 0; k < dynSize; k ++) {
403 SetFloat(fMessage + cursor, aValue->
404 GetSimpleValue().GetDynFloat(k));
405 cursor += sizeof(Float_t);
407 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
408 cursor += sizeof(UInt_t);
411 AliError("Invalid or unknown SimpleValueType!");
417 void AliDCSMessage::StoreErrorMessage() {
419 fMessageSize = ERROR_STRING_OFFSET + fErrorString.Length() + 1;
421 fMessage = new char[fMessageSize];
425 SetUByte(fMessage + ERROR_CODE_OFFSET, fErrorCode);
426 strcpy(fMessage + ERROR_STRING_OFFSET, fErrorString.Data());
429 void AliDCSMessage::StoreMultiRequestMessage() {
431 UInt_t requestDataSize = 0;
433 TIter iter(&fRequestStrings);
434 TObjString* anObjString;
436 while ((anObjString = (TObjString*) iter.Next())) {
437 assert(anObjString->String().Length() <= 255);
438 requestDataSize += anObjString->String().Length() + 1;
441 fMessageSize = REQUEST_STRINGS_OFFSET + requestDataSize;
443 fMessage = new char[fMessageSize];
447 SetUByte(fMessage + REQUEST_TYPE_OFFSET, fRequestType);
448 SetUInt(fMessage + START_TIME_OFFSET, fStartTime);
449 SetUInt(fMessage + END_TIME_OFFSET, fEndTime);
453 UInt_t cursor = REQUEST_STRINGS_OFFSET;
455 while ((anObjString = (TObjString*) iter.Next())) {
456 UChar_t strLength = anObjString->String().Length();
457 SetUByte(fMessage + cursor, strLength);
459 strncpy(fMessage + cursor, anObjString->String().Data(),
466 void AliDCSMessage::StoreNextMessage() {
468 fMessageSize = HEADER_SIZE;
470 fMessage = new char[fMessageSize];
475 Bool_t AliDCSMessage::ValidateHeader(const char* buf) {
477 if (!(buf[ID_OFFSET] == 'A' && buf[ID_OFFSET + 1] == 'D')) {
478 AliError("Bad message ID!");
482 if (buf[VERSION_OFFSET] != 1) {
483 AliError("Bad message version!");
487 Type type = (Type) GetUByte(buf + TYPE_OFFSET);
496 AliError("Unknown message type!");
500 UInt_t bodySize = GetInt(buf + BODY_SIZE_OFFSET);
501 if (bodySize > MAX_BODY_SIZE) {
502 AliError("Too big message body size!");
509 void AliDCSMessage::LoadRequestMessage() {
511 if (fMessageSize < REQUEST_STRING_OFFSET) {
512 AliError("Body size is too small for request message!");
516 fRequestType = (RequestType) GetUByte(fMessage + REQUEST_TYPE_OFFSET);
518 fStartTime = GetUInt(fMessage + START_TIME_OFFSET);
519 fEndTime = GetUInt(fMessage + END_TIME_OFFSET);
520 fRequestString = GetString(fMessage + REQUEST_STRING_OFFSET,
521 fMessageSize - REQUEST_STRING_OFFSET);
523 switch (fRequestType) {
529 AliError("Invalid request type!");
533 void AliDCSMessage::LoadCountMessage() {
535 if (fMessageSize < HEADER_SIZE + sizeof(UInt_t)) {
536 AliError("Body size is too small for count message!");
540 fCount = GetUInt(fMessage + COUNT_OFFSET);
545 void AliDCSMessage::LoadResultSetMessage() {
547 if (fMessageSize < VALUES_OFFSET) {
548 AliError("Body size is too small for result set message!");
552 fSimpleValueType = (AliSimpleValue::Type) GetUByte(
553 fMessage + SVT_OFFSET);
554 UInt_t count = GetUInt(fMessage + VALUE_COUNT_OFFSET);
556 UInt_t cursor = VALUES_OFFSET;
558 if (fSimpleValueType == AliSimpleValue::kBool) {
559 if (VALUES_OFFSET + count + count * sizeof(UInt_t) >
561 AliError("Too many bool values for this buffer size!");
565 for (UInt_t k = 0; k < count; k ++) {
566 Bool_t aBool = GetBool(fMessage + cursor);
568 UInt_t timeStamp = GetUInt(fMessage + cursor);
569 cursor += sizeof(UInt_t);
570 fValues.Add(new AliDCSValue(aBool, timeStamp));
572 } else if (fSimpleValueType == AliSimpleValue::kByte) {
573 if (VALUES_OFFSET + count + count * sizeof(UInt_t) >
575 AliError("Too many byte values for this buffer size!");
579 for (UInt_t k = 0; k < count; k ++) {
580 Char_t aByte = GetByte(fMessage + cursor);
581 cursor += sizeof(Char_t);
582 UInt_t timeStamp = GetUInt(fMessage + cursor);
583 cursor += sizeof(UInt_t);
584 fValues.Add(new AliDCSValue(aByte, timeStamp));
586 } else if (fSimpleValueType == AliSimpleValue::kInt) {
587 if (VALUES_OFFSET + count * sizeof(Int_t) +
588 count * sizeof(UInt_t) > fMessageSize) {
589 AliError("Too many int values for this buffer size!");
593 for (UInt_t k = 0; k < count; k ++) {
594 Int_t aInt = GetInt(fMessage + cursor);
595 cursor += sizeof(Int_t);
596 UInt_t timeStamp = GetUInt(fMessage + cursor);
597 cursor += sizeof(UInt_t);
598 fValues.Add(new AliDCSValue(aInt, timeStamp));
601 } else if (fSimpleValueType == AliSimpleValue::kUInt) {
602 if (VALUES_OFFSET + count * sizeof(UInt_t) +
603 count * sizeof(UInt_t) > fMessageSize) {
604 AliError("Too many uint values for this buffer size!");
608 for (UInt_t k = 0; k < count; k ++) {
609 UInt_t aUInt = GetUInt(fMessage + cursor);
610 cursor += sizeof(UInt_t);
611 UInt_t timeStamp = GetUInt(fMessage + cursor);
612 cursor += sizeof(UInt_t);
613 fValues.Add(new AliDCSValue(aUInt, timeStamp));
615 } else if (fSimpleValueType == AliSimpleValue::kFloat) {
616 if (VALUES_OFFSET + count * sizeof(Float_t) +
617 count * sizeof(UInt_t) > fMessageSize) {
618 AliError("Too many float values for this buffer size!");
622 for (UInt_t k = 0; k < count; k ++) {
623 Float_t aFloat = GetFloat(fMessage + cursor);
624 cursor += sizeof(Float_t);
625 UInt_t timeStamp = GetUInt(fMessage + cursor);
626 cursor += sizeof(UInt_t);
627 fValues.Add(new AliDCSValue(aFloat, timeStamp));
631 AliError("Unknown or invalid simple value type!");
637 void AliDCSMessage::LoadErrorMessage() {
639 if (fMessageSize < ERROR_STRING_OFFSET) {
640 AliError("Body size is too small for error message!");
644 fErrorCode = (ErrorCode) GetUByte(fMessage + ERROR_CODE_OFFSET);
645 fErrorString = GetString(fMessage + ERROR_STRING_OFFSET,
646 fMessageSize - ERROR_STRING_OFFSET);
648 switch (fErrorCode) {
649 case kUnknownAliasDPName:
650 case kInvalidTimeRange:
651 case kInvalidBufferSize:
652 case kInvalidRequest:
653 case kUnsupportedType:
658 AliError("Invalid error code!");
662 void AliDCSMessage::LoadMultiRequestMessage() {
664 if (fMessageSize - HEADER_SIZE < REQUEST_STRINGS_OFFSET) {
665 AliError("Body size is too small for multi request message!");
669 fRequestType = (RequestType) GetUByte(fMessage + REQUEST_TYPE_OFFSET);
671 fStartTime = GetUInt(fMessage + START_TIME_OFFSET);
672 fEndTime = GetUInt(fMessage + END_TIME_OFFSET);
674 switch (fRequestType) {
680 AliError("Invalid request type!");
684 UInt_t cursor = REQUEST_STRINGS_OFFSET;
686 while ((cursor < fMessageSize)) {
687 UChar_t strSize = GetUByte(fMessage + cursor);
690 if (cursor + strSize > fMessageSize) {
691 AliError("Invalid multi request message!");
695 TObjString* anObjString = new TObjString(
696 GetString(fMessage + cursor, strSize));
697 fRequestStrings.Add(anObjString);
702 fType = kMultiRequest;
706 void AliDCSMessage::LoadNextMessage() {
711 void AliDCSMessage::StoreToBuffer() {
713 // Creates an underlying message buffer which can be sent to the
721 StoreRequestMessage();
727 StoreResultSetMessage();
733 StoreMultiRequestMessage();
739 AliError("Can't store to buffer invalid message!");
743 void AliDCSMessage::LoadFromBuffer() {
745 // Reads the underlying message buffer and if it's valid message
746 // creates the corresponding message.
747 // If not set the message type kInvalid.
748 // This buffer is read from the socket.
754 AliError("Message buffer is empty! Can't load it.");
758 if (fMessageSize < HEADER_SIZE) {
759 AliError("Invalid message buffer. Too small for the header!");
763 if (!ValidateHeader(fMessage)) {
764 AliError("Invalid message header!");
768 UInt_t bodySize = GetUInt(fMessage + BODY_SIZE_OFFSET);
769 if (bodySize > fMessageSize - HEADER_SIZE) {
770 AliError("Message size is to small for the message body!");
774 fMessageSize = HEADER_SIZE + bodySize;
776 Type aType = (Type) GetUByte(fMessage + TYPE_OFFSET);
780 LoadRequestMessage();
786 LoadResultSetMessage();
792 LoadMultiRequestMessage();
798 AliError("Invalid message type!");
802 AliDCSMessage::RequestType AliDCSMessage::GetRequestType() const {
804 // Request and MultiRequest.
805 // Returns the request type: alias or dp (Data Point)
808 if (!(fType == kRequest || fType == kMultiRequest)) {
809 AliError("Invalid AliDCSMessage type!");
816 UInt_t AliDCSMessage::GetStartTime() const {
818 // Request and MultiRequest.
819 // Returns the request start time. (begining of the time interval).
822 if (!(fType == kRequest || fType == kMultiRequest)) {
823 AliError("Invalid AliDCSMessage type!");
830 UInt_t AliDCSMessage::GetEndTime() const {
832 // Request and MultiRequest.
833 // Returns the request start time. (end of the time interval).
837 if (!(fType == kRequest || fType == kMultiRequest)) {
838 AliError("Invalid AliDCSMessage type!");
845 TString AliDCSMessage::GetRequestString() const {
848 // Returns the request string. (alias or dp)
851 if (fType != kRequest) {
852 AliError("Invalid AliDCSMessage type!");
856 return fRequestString;
859 Bool_t AliDCSMessage::AddRequestString(const char* request) {
862 // Add a request to the request set.
863 // Returns kFALSE in case of invalid request (too long request string).
864 // Otherwise returns kTRUE.
868 if (fType != kMultiRequest) {
869 AliError("Invalid AliDCSMessage type!");
873 if (strlen(request) > 255) {
874 AliError("Alias/dpName is too long! Max size 255.");
878 fRequestStrings.Add(new TObjString(request));
882 void AliDCSMessage::ClearRequestStrings() {
885 // Clears the request set.
888 fRequestStrings.Delete();
891 void AliDCSMessage::GetRequestStrings(TList& result) const {
894 // Returns all request strings in this message.
895 // result: container where the requests are returned. Collection of
900 if (fType != kMultiRequest) {
901 AliError("Invalid AliDCSMessage type!");
905 TIter iter(&fRequestStrings);
906 TObjString* anObjString;
908 while ((anObjString = (TObjString*) iter.Next())) {
909 result.Add(new TObjString(*anObjString));
913 UInt_t AliDCSMessage::GetCount() const {
916 // Returns the total number of values.
920 if (fType != kCount) {
921 AliError("Invalid AliDCSMessage type!");
928 AliSimpleValue::Type AliDCSMessage::GetSimpleValueType() const {
931 // Returns simple value type (see AliSimpleValue) for the values
932 // in this ResultSet.
936 if (fType != kResultSet) {
937 AliError("Invalid AliDCSMessage type!");
938 return AliSimpleValue::kInvalid;
941 return fSimpleValueType;
944 UInt_t AliDCSMessage::GetValueCount() const {
947 // Returns the count of values in this ResultSet.
951 if (fType != kResultSet) {
952 AliError("Invalid AliDCSMessage type!");
956 return fValues.GetSize();
959 UInt_t AliDCSMessage::GetValues(TList& result) const {
962 // Returns the number of values got from the message.
963 // result: used to return the values. Collection of AliDCSValue.
967 if (fType != kResultSet) {
968 AliError("Invalid AliDCSMessage type!");
972 TIter iter(&fValues);
975 while ((aValue = (AliDCSValue*) iter.Next())) {
976 result.Add(new AliDCSValue(*aValue));
979 return fValues.GetSize();
982 Bool_t AliDCSMessage::AddValue(const AliDCSValue& value) {
985 // Adds value to the ResultSet value list.
986 // Returns kFALSE in case of error.
987 // Otherwise returns kTRUE;
990 if (fType != kResultSet) {
991 AliError("Invalid AliDCSMessage type!");
995 if (value.GetSimpleValue().GetType() != fSimpleValueType) {
996 AliError(Form("Can't add value with type %s to this message!",
997 AliSimpleValue::GetTypeString(
998 value.GetSimpleValue().GetType())));
1002 fValues.Add(new AliDCSValue(value));
1007 void AliDCSMessage::ClearValues() {
1011 AliDCSMessage::ErrorCode AliDCSMessage::GetErrorCode() const {
1014 // Returns the error code which has this error message.
1017 if (fType != kError) {
1018 AliError("Invalid AliDCSMessage type!");
1025 TString AliDCSMessage::GetErrorString() const {
1028 // Returns the error string (error description) which has this
1032 if (GetType() != kError) {
1033 AliError("Invalid AliDCSMessage type!");
1037 return fErrorString;
1041 void AliDCSMessage::Print(Option_t* /*option*/) const {
1043 if (AliLog::GetGlobalDebugLevel() < 2) {
1047 TString printString;
1048 printString += "\n <<AliDCSMessage>>\n";
1050 printString += " Size: ";
1051 printString += fMessageSize;
1052 printString += '\n';
1054 printString += " Type: ";
1055 switch (GetType()) {
1057 printString += "Request\n";
1059 printString += " RequestType: ";
1060 if (GetRequestType() == kDPName) {
1061 printString += "DPName";
1063 printString += "Alias";
1065 printString += '\n';
1067 printString += " RequestString: ";
1068 printString += GetRequestString();
1069 printString += '\n';
1070 printString += " StartTime: ";
1071 printString += GetStartTime();
1072 printString += '\n';
1073 printString += " EndTime: ";
1074 printString += GetEndTime();
1075 printString += '\n';
1080 printString += "Count\n";
1081 printString += " Count: ";
1082 printString += GetCount();
1083 printString += '\n';
1088 printString += "ResultSet\n";
1089 printString += " SimpleValueType: ";
1090 printString += AliSimpleValue::GetTypeString(
1092 printString += '\n';
1093 printString += " ValueCount: ";
1094 printString += GetValueCount();
1095 printString += '\n';
1100 printString += "Error\n";
1101 printString += " ErrorCode: ";
1102 switch (GetErrorCode()) {
1103 case AliDCSMessage::kNoneError:
1104 printString += "NoneError";
1106 case AliDCSMessage::kUnknownAliasDPName:
1107 printString += "UnknownAliasDPName";
1109 case AliDCSMessage::kInvalidTimeRange:
1110 printString += "InvalidTimeRange";
1112 case AliDCSMessage::kInvalidBufferSize:
1113 printString += "InvalidBufferSize";
1115 case AliDCSMessage::kInvalidRequest:
1116 printString += "InvalidRequest";
1118 case AliDCSMessage::kUnsupportedType:
1119 printString += "UnsupportedType";
1121 case AliDCSMessage::kUnknownError:
1122 printString += "UnknownError";
1125 printString += "Invalid";
1128 printString += '\n';
1129 printString += " ErrorString: ";
1130 printString += GetErrorString();
1131 printString += '\n';
1135 case kMultiRequest: {
1136 printString += "MultiRequest\n";
1138 printString += " RequestType: ";
1139 if (GetRequestType() == kDPName) {
1140 printString += "DPName";
1142 printString += "Alias";
1144 printString += '\n';
1146 printString += " RequestStrings: ";
1147 TIter iter(&fRequestStrings);
1148 TObjString* anObjString;
1149 while ((anObjString = (TObjString*) iter.Next())) {
1150 printString += anObjString->String();
1153 printString += '\n';
1155 printString += " StartTime: ";
1156 printString += GetStartTime();
1157 printString += '\n';
1158 printString += " EndTime: ";
1159 printString += GetEndTime();
1160 printString += '\n';
1165 printString += "Next\n";
1170 printString += "Invalid\n";
1173 if (AliLog::GetGlobalDebugLevel() >= 3 && fMessage) {
1174 PrintBuffer(fMessage, fMessageSize, printString);
1177 AliDebug(2, printString);
1180 Bool_t AliDCSMessage::SetRawHeader(const char* header) {
1182 // Checks if the header buffer represents a valid header message.
1183 // If so it creates a message buffer with the appropriate body size
1184 // and returns true.
1185 // If not returns false.
1186 // header: header buffer
1189 if (!ValidateHeader(header)) {
1190 AliError("Invalid message header!");
1196 UInt_t bodySize = GetUInt(header + BODY_SIZE_OFFSET);
1197 fMessageSize = HEADER_SIZE + bodySize;
1199 fMessage = new char[fMessageSize];
1201 memcpy(fMessage, header, HEADER_SIZE);
1207 void AliDCSMessage::DestroyBuffer() {
1209 // Destroy the underlying message buffer.
1220 void AliDCSMessage::PrintBuffer(const char* buffer, UInt_t size,
1226 while (index < size) {
1227 if (!(index % 16)) {
1228 output += Form("\n %.4x:", index);
1235 output += Form(" %.2x", (UChar_t) buffer[index]);
1237 if (!((index + 1) % 16) || index + 1 == size) {
1238 if (index + 1 == size) {
1239 output.Append(' ',3 * (15 - index % 16));
1240 if (index % 16 < 8) {
1245 output.Append(' ', 2);
1246 for (Int_t k = index % 16; k >= 0; k --) {
1247 Char_t aChar = buffer[index - k];
1248 output += isgraph(aChar) ? aChar: '.';