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.5 2006/07/20 09:54:40 jgrosseo
19 introducing status management: The processing per subdetector is divided into several steps,
20 after each step the status is stored on disk. If the system crashes in any of the steps the Shuttle
21 can keep track of the number of failures and skips further processing after a certain threshold is
22 exceeded. These thresholds can be configured in LDAP.
24 Revision 1.4 2006/07/04 14:59:57 jgrosseo
25 revision of AliDCSValue: Removed wrapper classes, reduced storage size per value by factor 2
27 Revision 1.3 2006/06/12 09:11:16 jgrosseo
28 coding conventions (Alberto)
30 Revision 1.2 2006/03/07 07:52:34 hristov
31 New version (B.Yordanov)
33 Revision 1.3 2005/11/17 17:47:34 byordano
34 TList changed to TObjArray
36 Revision 1.2 2005/11/17 14:43:23 byordano
39 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
40 Initial import as subdirectory in AliRoot
42 Revision 1.1.1.1 2005/09/12 22:11:40 byordano
45 Revision 1.2 2005/08/30 10:53:23 byordano
46 some more descriptions added
52 // This class is a wrapper of AliDCSMessage.
53 // These are the messages which form AliDCSProtocol.
54 // Every message has header and body. The body size is written in the header.
55 // There are five message types:
56 // 1) Request - used by the client to form a single request to DCS server
57 // 2) Count - returned by the server to inidicate the total number of
58 // values which would be sent to the client.
59 // 3) ResultSet - returned by the server and contains part of values set
60 // which forms the server resposen.
61 // 4) Error - returned by the server in case of error
62 // 5) MultiRequest - used by the client to form multi request.
63 // This is a request which serves many aliases/dp at the same time
64 // For all aliases/dp the same time interval is used.
65 // Short description of the schema:
66 // The client sends a request (Request or MultiRequest) and the server
68 // 1) Count - the total number of values that the client should
70 // 2) ResultSet* - every ResultSet message contains a part
71 // of valueSet (some values) which the client should expect
72 // The client can wait for ResultMessage until it gets
73 // all values (total number) which was returned by the
74 // Count message at the beginning of the ResutlSet sereie.
76 // 1) Error - contains the error code and error description
79 #include "AliDCSMessage.h"
84 #include <TObjString.h>
89 ClassImp(AliDCSMessage)
91 //______________________________________________________________________
92 AliDCSMessage::AliDCSMessage():
93 fMessage(NULL), fMessageSize(0), fType(kInvalid),
94 fStartTime(0), fEndTime(0),
95 fRequestString(""), fCount(0),
96 fValueType(AliDCSValue::kInvalid), fValues(),
97 fErrorCode(kNoneError), fErrorString(""),
100 // default constructor
104 //______________________________________________________________________
105 AliDCSMessage::AliDCSMessage(const char* message, UInt_t size):
106 fMessageSize(size), fType(kInvalid),
107 fStartTime(0), fEndTime(0),
108 fRequestString(""), fCount(0),
109 fValueType(AliDCSValue::kInvalid), fValues(),
110 fErrorCode(kNoneError), fErrorString(""),
113 // default constructor
115 fMessage = new char[size];
117 memcpy(fMessage, message, size);
120 //______________________________________________________________________
121 AliDCSMessage::AliDCSMessage(const AliDCSMessage& /*other*/):
122 TObject(), fMessage(NULL), fMessageSize(0), fType(kInvalid),
123 fStartTime(0), fEndTime(0),
124 fRequestString(""), fCount(0),
125 fValueType(AliDCSValue::kInvalid), fValues(),
126 fErrorCode(kNoneError), fErrorString(""),
129 // copy constructor (not implemented)
133 //______________________________________________________________________
134 AliDCSMessage &AliDCSMessage::operator=(const AliDCSMessage& /*other*/)
136 // assignment operator (not implemented)
141 //______________________________________________________________________
142 AliDCSMessage::~AliDCSMessage()
150 //______________________________________________________________________
151 void AliDCSMessage::CreateRequestMessage(RequestType type,
152 UInt_t startTime, UInt_t endTime, const char* request)
154 // Create request message
158 fType = AliDCSMessage::kRequest;
160 fStartTime = startTime;
162 fRequestString = request;
165 //______________________________________________________________________
166 void AliDCSMessage::CreateMultiRequestMessage(RequestType type,
167 UInt_t startTime, UInt_t endTime)
169 // Create multi request message
173 fType = AliDCSMessage::kMultiRequest;
175 fStartTime = startTime;
179 //______________________________________________________________________
180 void AliDCSMessage::CreateCountMessage(UInt_t count)
182 // Create count request message
186 fType = AliDCSMessage::kCount;
190 //______________________________________________________________________
191 void AliDCSMessage::CreateResultSetMessage(AliDCSValue::Type type)
193 // Create result set message
197 fType = AliDCSMessage::kResultSet;
201 //______________________________________________________________________
202 void AliDCSMessage::CreateErrorMessage(ErrorCode errorCode,
203 const char* errorString)
205 // Create error message
209 fType = AliDCSMessage::kError;
210 fErrorCode = errorCode;
211 fErrorString = errorString;
215 void AliDCSMessage::CreateNextMessage() {
218 fType = AliDCSMessage::kNext;
221 //______________________________________________________________________
222 void AliDCSMessage::DestroyMessage()
228 ClearRequestStrings();
231 //______________________________________________________________________
232 void AliDCSMessage::SetBool(char* buf, Bool_t val)
234 // Set bool value to buf
239 //______________________________________________________________________
240 void AliDCSMessage::SetByte(char* buf, Char_t val)
242 // Set byte value to buf
247 //______________________________________________________________________
248 void AliDCSMessage::SetUByte(char* buf, UChar_t val)
250 // Set ubyte value to buf
255 //______________________________________________________________________
256 void AliDCSMessage::SetInt(char* buf, Int_t val)
258 // Set int value to buf
263 //______________________________________________________________________
264 void AliDCSMessage::SetUInt(char* buf, UInt_t val)
266 // Set uint value to buf
271 //______________________________________________________________________
272 void AliDCSMessage::SetFloat(char* buf, Float_t val)
274 // Set float value to buf
279 //______________________________________________________________________
280 Bool_t AliDCSMessage::GetBool(const char* buf)
282 // get bool value from buf
285 char* aBuffer = (char*) buf;
287 frombuf(aBuffer, &val);
292 //______________________________________________________________________
293 Char_t AliDCSMessage::GetByte(const char* buf)
295 // get byte value from buf
298 char* aBuffer = (char*) buf;
300 frombuf(aBuffer, &val);
305 //______________________________________________________________________
306 UChar_t AliDCSMessage::GetUByte(const char* buf)
308 // get ubyte value from buf
311 char* aBuffer = (char*) buf;
313 frombuf(aBuffer, &val);
318 //______________________________________________________________________
319 Int_t AliDCSMessage::GetInt(const char* buf)
321 // get int value from buf
324 char* aBuffer = (char*) buf;
326 frombuf(aBuffer, &val);
331 //______________________________________________________________________
332 UInt_t AliDCSMessage::GetUInt(const char* buf)
334 // get uint value from buf
337 char* aBuffer = (char*) buf;
339 frombuf(aBuffer, &val);
344 //______________________________________________________________________
345 Float_t AliDCSMessage::GetFloat(const char* buf)
347 // get float value from buf
350 char* aBuffer = (char*) buf;
352 frombuf(aBuffer, &val);
357 //______________________________________________________________________
358 TString AliDCSMessage::GetString(const char* buf, Int_t maxLen)
360 // get string from buf
362 for (Int_t k = 0; k < maxLen; k ++) {
368 return TString(buf, maxLen);
371 //______________________________________________________________________
372 void AliDCSMessage::StoreHeader()
374 // store header message
376 SetUByte(fMessage + ID_OFFSET, 'A');
377 SetUByte(fMessage + ID_OFFSET + 1, 'D');
379 SetUByte(fMessage + VERSION_OFFSET, 1);
381 SetUByte(fMessage + TYPE_OFFSET, fType);
383 SetUInt(fMessage + BODY_SIZE_OFFSET, fMessageSize - HEADER_SIZE);
386 //______________________________________________________________________
387 void AliDCSMessage::StoreRequestMessage()
389 // store request message
391 fMessageSize = REQUEST_STRING_OFFSET +
392 fRequestString.Length() + 1;
394 fMessage = new char[fMessageSize];
398 SetUByte(fMessage + REQUEST_TYPE_OFFSET, fRequestType);
399 SetUInt(fMessage + START_TIME_OFFSET, fStartTime);
400 SetUInt(fMessage + END_TIME_OFFSET, fEndTime);
401 strcpy(fMessage + REQUEST_STRING_OFFSET, fRequestString.Data());
404 //______________________________________________________________________
405 void AliDCSMessage::StoreCountMessage()
407 // store count message
409 fMessageSize = COUNT_OFFSET + sizeof(UInt_t);
411 fMessage = new char[fMessageSize];
415 SetUInt(fMessage + COUNT_OFFSET, fCount);
418 //______________________________________________________________________
419 void AliDCSMessage::StoreResultSetMessage()
421 // store result set message
423 TIter iter(&fValues);
426 UInt_t valueDataSize = 0;
427 while ((aValue = (AliDCSValue*) iter.Next())) {
428 valueDataSize += aValue->GetSize();
431 fMessageSize = VALUES_OFFSET + valueDataSize;
433 fMessage = new char[fMessageSize];
437 SetUByte(fMessage + SVT_OFFSET, fValueType);
438 SetUInt(fMessage + VALUE_COUNT_OFFSET, GetValueCount());
440 UInt_t cursor = VALUES_OFFSET;
444 if (fValueType == AliDCSValue::kBool) {
445 while ((aValue = (AliDCSValue*) iter.Next())) {
446 SetBool(fMessage + cursor, aValue->GetBool());
448 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
449 cursor += sizeof(UInt_t);
451 } else if (fValueType == AliDCSValue::kChar) {
452 while ((aValue = (AliDCSValue*) iter.Next())) {
453 SetByte(fMessage + cursor, aValue->GetChar());
454 cursor += sizeof(Char_t);
455 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
456 cursor += sizeof(UInt_t);
458 } else if (fValueType == AliDCSValue::kInt) {
459 while ((aValue = (AliDCSValue*) iter.Next())) {
460 SetInt(fMessage + cursor, aValue->GetInt());
461 cursor += sizeof(Int_t);
462 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
463 cursor += sizeof(UInt_t);
465 } else if (fValueType == AliDCSValue::kUInt) {
466 while ((aValue = (AliDCSValue*) iter.Next())) {
467 SetUInt(fMessage + cursor, aValue->GetUInt());
468 cursor += sizeof(UInt_t);
469 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
470 cursor += sizeof(UInt_t);
472 } else if (fValueType == AliDCSValue::kFloat) {
473 while ((aValue = (AliDCSValue*) iter.Next())) {
474 SetFloat(fMessage + cursor, aValue->GetFloat());
475 cursor += sizeof(Float_t);
476 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
477 cursor += sizeof(UInt_t);
480 AliError("Invalid or unknown ValueType!");
486 //______________________________________________________________________
487 void AliDCSMessage::StoreErrorMessage()
489 // store error message
491 fMessageSize = ERROR_STRING_OFFSET + fErrorString.Length() + 1;
493 fMessage = new char[fMessageSize];
497 SetUByte(fMessage + ERROR_CODE_OFFSET, fErrorCode);
498 strcpy(fMessage + ERROR_STRING_OFFSET, fErrorString.Data());
501 //______________________________________________________________________
502 void AliDCSMessage::StoreMultiRequestMessage()
504 // store multi request message
506 UInt_t requestDataSize = 0;
508 TIter iter(&fRequestStrings);
509 TObjString* anObjString;
511 while ((anObjString = (TObjString*) iter.Next())) {
512 assert(anObjString->String().Length() <= 255);
513 requestDataSize += anObjString->String().Length() + 1;
516 fMessageSize = REQUEST_STRINGS_OFFSET + requestDataSize;
518 fMessage = new char[fMessageSize];
522 SetUByte(fMessage + REQUEST_TYPE_OFFSET, fRequestType);
523 SetUInt(fMessage + START_TIME_OFFSET, fStartTime);
524 SetUInt(fMessage + END_TIME_OFFSET, fEndTime);
528 UInt_t cursor = REQUEST_STRINGS_OFFSET;
530 while ((anObjString = (TObjString*) iter.Next())) {
531 UChar_t strLength = anObjString->String().Length();
532 SetUByte(fMessage + cursor, strLength);
534 strncpy(fMessage + cursor, anObjString->String().Data(),
540 //______________________________________________________________________
542 void AliDCSMessage::StoreNextMessage() {
544 fMessageSize = HEADER_SIZE;
546 fMessage = new char[fMessageSize];
551 //______________________________________________________________________
552 Bool_t AliDCSMessage::ValidateHeader(const char* buf)
554 // validate message header
556 if (!(buf[ID_OFFSET] == 'A' && buf[ID_OFFSET + 1] == 'D')) {
557 AliError("Bad message ID!");
561 if (buf[VERSION_OFFSET] != 1) {
562 AliError("Bad message version!");
566 Type type = (Type) GetUByte(buf + TYPE_OFFSET);
575 AliError("Unknown message type!");
579 UInt_t bodySize = GetInt(buf + BODY_SIZE_OFFSET);
580 if (bodySize > MAX_BODY_SIZE) {
581 AliError("Too big message body size!");
588 //______________________________________________________________________
589 void AliDCSMessage::LoadRequestMessage()
591 // load request message
593 if (fMessageSize < REQUEST_STRING_OFFSET) {
594 AliError("Body size is too small for request message!");
598 fRequestType = (RequestType) GetUByte(fMessage + REQUEST_TYPE_OFFSET);
600 fStartTime = GetUInt(fMessage + START_TIME_OFFSET);
601 fEndTime = GetUInt(fMessage + END_TIME_OFFSET);
602 fRequestString = GetString(fMessage + REQUEST_STRING_OFFSET,
603 fMessageSize - REQUEST_STRING_OFFSET);
605 switch (fRequestType) {
611 AliError("Invalid request type!");
615 //______________________________________________________________________
616 void AliDCSMessage::LoadCountMessage()
618 // load count message
620 if (fMessageSize < HEADER_SIZE + sizeof(UInt_t)) {
621 AliError("Body size is too small for count message!");
625 fCount = GetUInt(fMessage + COUNT_OFFSET);
630 //______________________________________________________________________
631 void AliDCSMessage::LoadResultSetMessage()
633 // load result message
635 if (fMessageSize < VALUES_OFFSET) {
636 AliError("Body size is too small for result set message!");
640 fValueType = (AliDCSValue::Type) GetUByte(fMessage + SVT_OFFSET);
641 UInt_t count = GetUInt(fMessage + VALUE_COUNT_OFFSET);
643 UInt_t cursor = VALUES_OFFSET;
645 if (fValueType == AliDCSValue::kBool) {
646 if (VALUES_OFFSET + count + count * sizeof(UInt_t) >
648 AliError("Too many bool values for this buffer size!");
652 for (UInt_t k = 0; k < count; k ++) {
653 Bool_t aBool = GetBool(fMessage + cursor);
655 UInt_t timeStamp = GetUInt(fMessage + cursor);
656 cursor += sizeof(UInt_t);
657 fValues.Add(new AliDCSValue(aBool, timeStamp));
659 } else if (fValueType == AliDCSValue::kChar) {
660 if (VALUES_OFFSET + count + count * sizeof(UInt_t) >
662 AliError("Too many byte values for this buffer size!");
666 for (UInt_t k = 0; k < count; k ++) {
667 Char_t aByte = GetByte(fMessage + cursor);
668 cursor += sizeof(Char_t);
669 UInt_t timeStamp = GetUInt(fMessage + cursor);
670 cursor += sizeof(UInt_t);
671 fValues.Add(new AliDCSValue(aByte, timeStamp));
673 } else if (fValueType == AliDCSValue::kInt) {
674 if (VALUES_OFFSET + count * sizeof(Int_t) +
675 count * sizeof(UInt_t) > fMessageSize) {
676 AliError("Too many int values for this buffer size!");
680 for (UInt_t k = 0; k < count; k ++) {
681 Int_t aInt = GetInt(fMessage + cursor);
682 cursor += sizeof(Int_t);
683 UInt_t timeStamp = GetUInt(fMessage + cursor);
684 cursor += sizeof(UInt_t);
685 fValues.Add(new AliDCSValue(aInt, timeStamp));
688 } else if (fValueType == AliDCSValue::kUInt) {
689 if (VALUES_OFFSET + count * sizeof(UInt_t) +
690 count * sizeof(UInt_t) > fMessageSize) {
691 AliError("Too many uint values for this buffer size!");
695 for (UInt_t k = 0; k < count; k ++) {
696 UInt_t aUInt = GetUInt(fMessage + cursor);
697 cursor += sizeof(UInt_t);
698 UInt_t timeStamp = GetUInt(fMessage + cursor);
699 cursor += sizeof(UInt_t);
700 fValues.Add(new AliDCSValue(aUInt, timeStamp));
702 } else if (fValueType == AliDCSValue::kFloat) {
703 if (VALUES_OFFSET + count * sizeof(Float_t) +
704 count * sizeof(UInt_t) > fMessageSize) {
705 AliError("Too many float values for this buffer size!");
709 for (UInt_t k = 0; k < count; k ++) {
710 Float_t aFloat = GetFloat(fMessage + cursor);
711 cursor += sizeof(Float_t);
712 UInt_t timeStamp = GetUInt(fMessage + cursor);
713 cursor += sizeof(UInt_t);
714 fValues.Add(new AliDCSValue(aFloat, timeStamp));
718 AliError("Unknown or invalid value type!");
724 //______________________________________________________________________
725 void AliDCSMessage::LoadErrorMessage()
727 // load error message
729 if (fMessageSize < ERROR_STRING_OFFSET) {
730 AliError("Body size is too small for error message!");
734 fErrorCode = (ErrorCode) GetUByte(fMessage + ERROR_CODE_OFFSET);
735 fErrorString = GetString(fMessage + ERROR_STRING_OFFSET,
736 fMessageSize - ERROR_STRING_OFFSET);
738 switch (fErrorCode) {
739 case kUnknownAliasDPName:
740 case kInvalidTimeRange:
741 case kInvalidBufferSize:
742 case kInvalidRequest:
743 case kUnsupportedType:
748 AliError("Invalid error code!");
752 //______________________________________________________________________
753 void AliDCSMessage::LoadMultiRequestMessage()
755 // load multi request message
757 if (fMessageSize - HEADER_SIZE < REQUEST_STRINGS_OFFSET) {
758 AliError("Body size is too small for multi request message!");
762 fRequestType = (RequestType) GetUByte(fMessage + REQUEST_TYPE_OFFSET);
764 fStartTime = GetUInt(fMessage + START_TIME_OFFSET);
765 fEndTime = GetUInt(fMessage + END_TIME_OFFSET);
767 switch (fRequestType) {
773 AliError("Invalid request type!");
777 UInt_t cursor = REQUEST_STRINGS_OFFSET;
779 while ((cursor < fMessageSize)) {
780 UChar_t strSize = GetUByte(fMessage + cursor);
783 if (cursor + strSize > fMessageSize) {
784 AliError("Invalid multi request message!");
788 TObjString* anObjString = new TObjString(
789 GetString(fMessage + cursor, strSize));
790 fRequestStrings.AddLast(anObjString);
795 fType = kMultiRequest;
798 //______________________________________________________________________
800 void AliDCSMessage::LoadNextMessage() {
805 //______________________________________________________________________
806 void AliDCSMessage::StoreToBuffer()
808 // Creates an underlying message buffer which can be sent to the socket.
814 StoreRequestMessage();
820 StoreResultSetMessage();
826 StoreMultiRequestMessage();
832 AliError("Can't store to buffer invalid message!");
836 //______________________________________________________________________
837 void AliDCSMessage::LoadFromBuffer()
839 // Reads the underlying message buffer and if it's valid message
840 // creates the corresponding message.
841 // If not set the message type kInvalid.
842 // This buffer is read from the socket.
847 AliError("Message buffer is empty! Can't load it.");
851 if (fMessageSize < HEADER_SIZE) {
852 AliError("Invalid message buffer. Too small for the header!");
856 if (!ValidateHeader(fMessage)) {
857 AliError("Invalid message header!");
861 UInt_t bodySize = GetUInt(fMessage + BODY_SIZE_OFFSET);
862 if (bodySize > fMessageSize - HEADER_SIZE) {
863 AliError("Message size is to small for the message body!");
867 fMessageSize = HEADER_SIZE + bodySize;
869 Type aType = (Type) GetUByte(fMessage + TYPE_OFFSET);
873 LoadRequestMessage();
879 LoadResultSetMessage();
885 LoadMultiRequestMessage();
891 AliError("Invalid message type!");
895 //______________________________________________________________________
896 AliDCSMessage::RequestType AliDCSMessage::GetRequestType() const
898 // Request and MultiRequest.
899 // Returns the request type: alias or dp (Data Point)
901 if (!(fType == kRequest || fType == kMultiRequest)) {
902 AliError("Invalid AliDCSMessage type!");
909 //______________________________________________________________________
910 UInt_t AliDCSMessage::GetStartTime() const
912 // Request and MultiRequest.
913 // Returns the request start time. (begining of the time interval).
915 if (!(fType == kRequest || fType == kMultiRequest)) {
916 AliError("Invalid AliDCSMessage type!");
923 //______________________________________________________________________
924 UInt_t AliDCSMessage::GetEndTime() const
926 // Request and MultiRequest.
927 // Returns the request start time. (end of the time interval).
930 if (!(fType == kRequest || fType == kMultiRequest)) {
931 AliError("Invalid AliDCSMessage type!");
938 //______________________________________________________________________
939 TString AliDCSMessage::GetRequestString() const
942 // Returns the request string. (alias or dp)
944 if (fType != kRequest) {
945 AliError("Invalid AliDCSMessage type!");
949 return fRequestString;
952 //______________________________________________________________________
953 Bool_t AliDCSMessage::AddRequestString(const char* request)
956 // Add a request to the request set.
957 // Returns kFALSE in case of invalid request (too long request string).
958 // Otherwise returns kTRUE.
961 if (fType != kMultiRequest) {
962 AliError("Invalid AliDCSMessage type!");
966 if (strlen(request) > 255) {
967 AliError("Alias/dpName is too long! Max size 255.");
971 fRequestStrings.AddLast(new TObjString(request));
975 //______________________________________________________________________
976 void AliDCSMessage::ClearRequestStrings()
979 // Clears the request set.
981 fRequestStrings.Delete();
984 //______________________________________________________________________
985 void AliDCSMessage::GetRequestStrings(TObjArray& result) const
988 // Returns all request strings in this message.
989 // result: container where the requests are returned. Collection of
993 if (fType != kMultiRequest) {
994 AliError("Invalid AliDCSMessage type!");
998 TIter iter(&fRequestStrings);
999 TObjString* anObjString;
1001 while ((anObjString = (TObjString*) iter.Next())) {
1002 result.AddLast(new TObjString(*anObjString));
1006 //______________________________________________________________________
1007 UInt_t AliDCSMessage::GetCount() const
1010 // Returns the total number of values.
1013 if (fType != kCount) {
1014 AliError("Invalid AliDCSMessage type!");
1021 //______________________________________________________________________
1022 AliDCSValue::Type AliDCSMessage::GetValueType() const
1025 // Returns simple value type (see AliDCSValue) for the values
1026 // in this ResultSet.
1028 if (fType != kResultSet) {
1029 AliError("Invalid AliDCSMessage type!");
1030 return AliDCSValue::kInvalid;
1036 //______________________________________________________________________
1037 UInt_t AliDCSMessage::GetValueCount() const
1040 // Returns the count of values in this ResultSet.
1043 if (fType != kResultSet) {
1044 AliError("Invalid AliDCSMessage type!");
1048 return fValues.GetEntriesFast();
1051 //______________________________________________________________________
1052 UInt_t AliDCSMessage::GetValues(TObjArray& result) const
1055 // Returns the number of values got from the message.
1056 // result: used to return the values. Collection of AliDCSValue.
1060 if (fType != kResultSet) {
1061 AliError("Invalid AliDCSMessage type!");
1065 TIter iter(&fValues);
1066 AliDCSValue* aValue;
1068 while ((aValue = (AliDCSValue*) iter.Next())) {
1069 result.AddLast(new AliDCSValue(*aValue));
1072 return fValues.GetEntriesFast();
1075 //______________________________________________________________________
1076 Bool_t AliDCSMessage::AddValue(const AliDCSValue& value)
1078 // Adds value to the ResultSet value list.
1079 // Returns kFALSE in case of error.
1080 // Otherwise returns kTRUE;
1082 if (fType != kResultSet) {
1083 AliError("Invalid AliDCSMessage type!");
1087 if (value.GetType() != fValueType) {
1088 AliError(Form("Can't add value with type %d to this message!", value.GetType()));
1092 fValues.Add(new AliDCSValue(value));
1097 //______________________________________________________________________
1098 void AliDCSMessage::ClearValues()
1100 // clear values array
1105 //______________________________________________________________________
1106 AliDCSMessage::ErrorCode AliDCSMessage::GetErrorCode() const
1110 // Returns the error code which has this error message.
1113 if (fType != kError) {
1114 AliError("Invalid AliDCSMessage type!");
1121 //______________________________________________________________________
1122 TString AliDCSMessage::GetErrorString() const
1126 // Returns the error string (error description) which has this
1130 if (GetType() != kError) {
1131 AliError("Invalid AliDCSMessage type!");
1135 return fErrorString;
1139 //______________________________________________________________________
1140 void AliDCSMessage::Print(Option_t* /*option*/) const
1144 if (AliLog::GetGlobalDebugLevel() < 2) {
1148 TString printString;
1149 printString += "\n <<AliDCSMessage>>\n";
1151 printString += " Size: ";
1152 printString += fMessageSize;
1153 printString += '\n';
1155 printString += " Type: ";
1156 switch (GetType()) {
1158 printString += "Request\n";
1160 printString += " RequestType: ";
1161 if (GetRequestType() == kDPName) {
1162 printString += "DPName";
1164 printString += "Alias";
1166 printString += '\n';
1168 printString += " RequestString: ";
1169 printString += GetRequestString();
1170 printString += '\n';
1171 printString += " StartTime: ";
1172 printString += GetStartTime();
1173 printString += '\n';
1174 printString += " EndTime: ";
1175 printString += GetEndTime();
1176 printString += '\n';
1181 printString += "Count\n";
1182 printString += " Count: ";
1183 printString += GetCount();
1184 printString += '\n';
1189 printString += "ResultSet\n";
1190 printString += " SimpleValueType: ";
1191 printString += fValueType;
1192 printString += '\n';
1193 printString += " ValueCount: ";
1194 printString += GetValueCount();
1195 printString += '\n';
1200 printString += "Error\n";
1201 printString += " ErrorCode: ";
1202 switch (GetErrorCode()) {
1203 case AliDCSMessage::kNoneError:
1204 printString += "NoneError";
1206 case AliDCSMessage::kUnknownAliasDPName:
1207 printString += "UnknownAliasDPName";
1209 case AliDCSMessage::kInvalidTimeRange:
1210 printString += "InvalidTimeRange";
1212 case AliDCSMessage::kInvalidBufferSize:
1213 printString += "InvalidBufferSize";
1215 case AliDCSMessage::kInvalidRequest:
1216 printString += "InvalidRequest";
1218 case AliDCSMessage::kUnsupportedType:
1219 printString += "UnsupportedType";
1221 case AliDCSMessage::kUnknownError:
1222 printString += "UnknownError";
1225 printString += "Invalid";
1228 printString += '\n';
1229 printString += " ErrorString: ";
1230 printString += GetErrorString();
1231 printString += '\n';
1235 case kMultiRequest: {
1236 printString += "MultiRequest\n";
1238 printString += " RequestType: ";
1239 if (GetRequestType() == kDPName) {
1240 printString += "DPName";
1242 printString += "Alias";
1244 printString += '\n';
1246 printString += " RequestStrings: ";
1247 TIter iter(&fRequestStrings);
1248 TObjString* anObjString;
1249 while ((anObjString = (TObjString*) iter.Next())) {
1250 printString += anObjString->String();
1253 printString += '\n';
1255 printString += " StartTime: ";
1256 printString += GetStartTime();
1257 printString += '\n';
1258 printString += " EndTime: ";
1259 printString += GetEndTime();
1260 printString += '\n';
1265 printString += "Next\n";
1270 printString += "Invalid\n";
1273 if (AliLog::GetGlobalDebugLevel() >= 3 && fMessage) {
1274 PrintBuffer(fMessage, fMessageSize, printString);
1277 AliDebug(2, printString);
1280 //______________________________________________________________________
1281 Bool_t AliDCSMessage::SetRawHeader(const char* header)
1284 // Checks if the header buffer represents a valid header message.
1285 // If so it creates a message buffer with the appropriate body size
1286 // and returns true.
1287 // If not returns false.
1288 // header: header buffer
1291 if (!ValidateHeader(header)) {
1292 AliError("Invalid message header!");
1298 UInt_t bodySize = GetUInt(header + BODY_SIZE_OFFSET);
1299 fMessageSize = HEADER_SIZE + bodySize;
1301 fMessage = new char[fMessageSize];
1303 memcpy(fMessage, header, HEADER_SIZE);
1309 //______________________________________________________________________
1310 void AliDCSMessage::DestroyBuffer()
1313 // Destroy the underlying message buffer.
1324 //______________________________________________________________________
1325 void AliDCSMessage::PrintBuffer(const char* buffer, UInt_t size,
1332 while (index < size) {
1333 if (!(index % 16)) {
1334 output += Form("\n %.4x:", index);
1341 output += Form(" %.2x", (UChar_t) buffer[index]);
1343 if (!((index + 1) % 16) || index + 1 == size) {
1344 if (index + 1 == size) {
1345 output.Append(' ',3 * (15 - index % 16));
1346 if (index % 16 < 8) {
1351 output.Append(' ', 2);
1352 for (Int_t k = index % 16; k >= 0; k --) {
1353 Char_t aChar = buffer[index - k];
1354 output += isgraph(aChar) ? aChar: '.';