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.6 2006/08/15 10:50:00 jgrosseo
19 effc++ corrections (alberto)
21 Revision 1.5 2006/07/20 09:54:40 jgrosseo
22 introducing status management: The processing per subdetector is divided into several steps,
23 after each step the status is stored on disk. If the system crashes in any of the steps the Shuttle
24 can keep track of the number of failures and skips further processing after a certain threshold is
25 exceeded. These thresholds can be configured in LDAP.
27 Revision 1.4 2006/07/04 14:59:57 jgrosseo
28 revision of AliDCSValue: Removed wrapper classes, reduced storage size per value by factor 2
30 Revision 1.3 2006/06/12 09:11:16 jgrosseo
31 coding conventions (Alberto)
33 Revision 1.2 2006/03/07 07:52:34 hristov
34 New version (B.Yordanov)
36 Revision 1.3 2005/11/17 17:47:34 byordano
37 TList changed to TObjArray
39 Revision 1.2 2005/11/17 14:43:23 byordano
42 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
43 Initial import as subdirectory in AliRoot
45 Revision 1.1.1.1 2005/09/12 22:11:40 byordano
48 Revision 1.2 2005/08/30 10:53:23 byordano
49 some more descriptions added
55 // This class is a wrapper of AliDCSMessage.
56 // These are the messages which form AliDCSProtocol.
57 // Every message has header and body. The body size is written in the header.
58 // There are five message types:
59 // 1) Request - used by the client to form a single request to DCS server
60 // 2) Count - returned by the server to inidicate the total number of
61 // values which would be sent to the client.
62 // 3) ResultSet - returned by the server and contains part of values set
63 // which forms the server resposen.
64 // 4) Error - returned by the server in case of error
65 // 5) MultiRequest - used by the client to form multi request.
66 // This is a request which serves many aliases/dp at the same time
67 // For all aliases/dp the same time interval is used.
68 // Short description of the schema:
69 // The client sends a request (Request or MultiRequest) and the server
71 // 1) Count - the total number of values that the client should
73 // 2) ResultSet* - every ResultSet message contains a part
74 // of valueSet (some values) which the client should expect
75 // The client can wait for ResultMessage until it gets
76 // all values (total number) which was returned by the
77 // Count message at the beginning of the ResutlSet sereie.
79 // 1) Error - contains the error code and error description
82 #include "AliDCSMessage.h"
87 #include <TObjString.h>
92 ClassImp(AliDCSMessage)
94 //______________________________________________________________________
95 AliDCSMessage::AliDCSMessage():
96 fMessage(NULL), fMessageSize(0), fType(kInvalid),
97 fStartTime(0), fEndTime(0),
98 fRequestString(""), fCount(0),
99 fValueType(AliDCSValue::kInvalid),
100 fErrorCode(kNoneError), fErrorString(""),
103 // default constructor
104 fValues = new TObjArray();
105 fValues->SetOwner(0);
109 //______________________________________________________________________
110 AliDCSMessage::AliDCSMessage(const char* message, UInt_t size):
111 fMessageSize(size), fType(kInvalid),
112 fStartTime(0), fEndTime(0),
113 fRequestString(""), fCount(0),
114 fValueType(AliDCSValue::kInvalid),
115 fErrorCode(kNoneError), fErrorString(""),
118 // default constructor
120 fMessage = new char[size];
122 memcpy(fMessage, message, size);
123 fValues = new TObjArray();
124 fValues->SetOwner(0);
127 //______________________________________________________________________
128 AliDCSMessage::AliDCSMessage(const AliDCSMessage& /*other*/):
129 TObject(), fMessage(NULL), fMessageSize(0), fType(kInvalid),
130 fStartTime(0), fEndTime(0),
131 fRequestString(""), fCount(0),
132 fValueType(AliDCSValue::kInvalid),
133 fErrorCode(kNoneError), fErrorString(""),
136 // copy constructor (not implemented)
140 //______________________________________________________________________
141 AliDCSMessage &AliDCSMessage::operator=(const AliDCSMessage& /*other*/)
143 // assignment operator (not implemented)
148 //______________________________________________________________________
149 AliDCSMessage::~AliDCSMessage()
155 if(fValues) delete fValues; fValues=0;
158 //______________________________________________________________________
159 void AliDCSMessage::CreateRequestMessage(RequestType type,
160 UInt_t startTime, UInt_t endTime, const char* request)
162 // Create request message
166 fType = AliDCSMessage::kRequest;
168 fStartTime = startTime;
170 fRequestString = request;
173 //______________________________________________________________________
174 void AliDCSMessage::CreateMultiRequestMessage(RequestType type,
175 UInt_t startTime, UInt_t endTime)
177 // Create multi request message
181 fType = AliDCSMessage::kMultiRequest;
183 fStartTime = startTime;
187 //______________________________________________________________________
188 void AliDCSMessage::CreateCountMessage(UInt_t count)
190 // Create count request message
194 fType = AliDCSMessage::kCount;
198 //______________________________________________________________________
199 void AliDCSMessage::CreateResultSetMessage(AliDCSValue::Type type)
201 // Create result set message
205 fType = AliDCSMessage::kResultSet;
209 //______________________________________________________________________
210 void AliDCSMessage::CreateErrorMessage(ErrorCode errorCode,
211 const char* errorString)
213 // Create error message
217 fType = AliDCSMessage::kError;
218 fErrorCode = errorCode;
219 fErrorString = errorString;
223 void AliDCSMessage::CreateNextMessage() {
226 fType = AliDCSMessage::kNext;
229 //______________________________________________________________________
230 void AliDCSMessage::DestroyMessage()
236 ClearRequestStrings();
239 //______________________________________________________________________
240 void AliDCSMessage::SetBool(char* buf, Bool_t val)
242 // Set bool value to buf
247 //______________________________________________________________________
248 void AliDCSMessage::SetByte(char* buf, Char_t val)
250 // Set byte value to buf
255 //______________________________________________________________________
256 void AliDCSMessage::SetUByte(char* buf, UChar_t val)
258 // Set ubyte value to buf
263 //______________________________________________________________________
264 void AliDCSMessage::SetInt(char* buf, Int_t val)
266 // Set int value to buf
271 //______________________________________________________________________
272 void AliDCSMessage::SetUInt(char* buf, UInt_t val)
274 // Set uint value to buf
279 //______________________________________________________________________
280 void AliDCSMessage::SetFloat(char* buf, Float_t val)
282 // Set float value to buf
287 //______________________________________________________________________
288 Bool_t AliDCSMessage::GetBool(const char* buf)
290 // get bool value from buf
293 char* aBuffer = (char*) buf;
295 frombuf(aBuffer, &val);
300 //______________________________________________________________________
301 Char_t AliDCSMessage::GetByte(const char* buf)
303 // get byte value from buf
306 char* aBuffer = (char*) buf;
308 frombuf(aBuffer, &val);
313 //______________________________________________________________________
314 UChar_t AliDCSMessage::GetUByte(const char* buf)
316 // get ubyte value from buf
319 char* aBuffer = (char*) buf;
321 frombuf(aBuffer, &val);
326 //______________________________________________________________________
327 Int_t AliDCSMessage::GetInt(const char* buf)
329 // get int value from buf
332 char* aBuffer = (char*) buf;
334 frombuf(aBuffer, &val);
339 //______________________________________________________________________
340 UInt_t AliDCSMessage::GetUInt(const char* buf)
342 // get uint value from buf
345 char* aBuffer = (char*) buf;
347 frombuf(aBuffer, &val);
352 //______________________________________________________________________
353 Float_t AliDCSMessage::GetFloat(const char* buf)
355 // get float value from buf
358 char* aBuffer = (char*) buf;
360 frombuf(aBuffer, &val);
365 //______________________________________________________________________
366 TString AliDCSMessage::GetString(const char* buf, Int_t maxLen)
368 // get string from buf
370 for (Int_t k = 0; k < maxLen; k ++) {
376 return TString(buf, maxLen);
379 //______________________________________________________________________
380 void AliDCSMessage::StoreHeader()
382 // store header message
384 SetUByte(fMessage + ID_OFFSET, 'A');
385 SetUByte(fMessage + ID_OFFSET + 1, 'D');
387 SetUByte(fMessage + VERSION_OFFSET, 1);
389 SetUByte(fMessage + TYPE_OFFSET, fType);
391 SetUInt(fMessage + BODY_SIZE_OFFSET, fMessageSize - HEADER_SIZE);
394 //______________________________________________________________________
395 void AliDCSMessage::StoreRequestMessage()
397 // store request message
399 fMessageSize = REQUEST_STRING_OFFSET +
400 fRequestString.Length() + 1;
402 fMessage = new char[fMessageSize];
406 SetUByte(fMessage + REQUEST_TYPE_OFFSET, fRequestType);
407 SetUInt(fMessage + START_TIME_OFFSET, fStartTime);
408 SetUInt(fMessage + END_TIME_OFFSET, fEndTime);
409 strcpy(fMessage + REQUEST_STRING_OFFSET, fRequestString.Data());
412 //______________________________________________________________________
413 void AliDCSMessage::StoreCountMessage()
415 // store count message
417 fMessageSize = COUNT_OFFSET + sizeof(UInt_t);
419 fMessage = new char[fMessageSize];
423 SetUInt(fMessage + COUNT_OFFSET, fCount);
426 //______________________________________________________________________
427 void AliDCSMessage::StoreResultSetMessage()
429 // store result set message
434 UInt_t valueDataSize = 0;
435 while ((aValue = (AliDCSValue*) iter.Next())) {
436 valueDataSize += aValue->GetSize();
439 fMessageSize = VALUES_OFFSET + valueDataSize;
441 fMessage = new char[fMessageSize];
445 SetUByte(fMessage + SVT_OFFSET, fValueType);
446 SetUInt(fMessage + VALUE_COUNT_OFFSET, GetValueCount());
448 UInt_t cursor = VALUES_OFFSET;
452 if (fValueType == AliDCSValue::kBool) {
453 while ((aValue = (AliDCSValue*) iter.Next())) {
454 SetBool(fMessage + cursor, aValue->GetBool());
456 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
457 cursor += sizeof(UInt_t);
459 } else if (fValueType == AliDCSValue::kChar) {
460 while ((aValue = (AliDCSValue*) iter.Next())) {
461 SetByte(fMessage + cursor, aValue->GetChar());
462 cursor += sizeof(Char_t);
463 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
464 cursor += sizeof(UInt_t);
466 } else if (fValueType == AliDCSValue::kInt) {
467 while ((aValue = (AliDCSValue*) iter.Next())) {
468 SetInt(fMessage + cursor, aValue->GetInt());
469 cursor += sizeof(Int_t);
470 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
471 cursor += sizeof(UInt_t);
473 } else if (fValueType == AliDCSValue::kUInt) {
474 while ((aValue = (AliDCSValue*) iter.Next())) {
475 SetUInt(fMessage + cursor, aValue->GetUInt());
476 cursor += sizeof(UInt_t);
477 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
478 cursor += sizeof(UInt_t);
480 } else if (fValueType == AliDCSValue::kFloat) {
481 while ((aValue = (AliDCSValue*) iter.Next())) {
482 SetFloat(fMessage + cursor, aValue->GetFloat());
483 cursor += sizeof(Float_t);
484 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
485 cursor += sizeof(UInt_t);
488 AliError("Invalid or unknown ValueType!");
494 //______________________________________________________________________
495 void AliDCSMessage::StoreErrorMessage()
497 // store error message
499 fMessageSize = ERROR_STRING_OFFSET + fErrorString.Length() + 1;
501 fMessage = new char[fMessageSize];
505 SetUByte(fMessage + ERROR_CODE_OFFSET, fErrorCode);
506 strcpy(fMessage + ERROR_STRING_OFFSET, fErrorString.Data());
509 //______________________________________________________________________
510 void AliDCSMessage::StoreMultiRequestMessage()
512 // store multi request message
514 UInt_t requestDataSize = 0;
516 TIter iter(&fRequestStrings);
517 TObjString* anObjString;
519 while ((anObjString = (TObjString*) iter.Next())) {
520 assert(anObjString->String().Length() <= 255);
521 requestDataSize += anObjString->String().Length() + 1;
524 fMessageSize = REQUEST_STRINGS_OFFSET + requestDataSize;
526 fMessage = new char[fMessageSize];
530 SetUByte(fMessage + REQUEST_TYPE_OFFSET, fRequestType);
531 SetUInt(fMessage + START_TIME_OFFSET, fStartTime);
532 SetUInt(fMessage + END_TIME_OFFSET, fEndTime);
536 UInt_t cursor = REQUEST_STRINGS_OFFSET;
538 while ((anObjString = (TObjString*) iter.Next())) {
539 UChar_t strLength = anObjString->String().Length();
540 SetUByte(fMessage + cursor, strLength);
542 strncpy(fMessage + cursor, anObjString->String().Data(),
548 //______________________________________________________________________
550 void AliDCSMessage::StoreNextMessage() {
552 fMessageSize = HEADER_SIZE;
554 fMessage = new char[fMessageSize];
559 //______________________________________________________________________
560 Bool_t AliDCSMessage::ValidateHeader(const char* buf)
562 // validate message header
564 if (!(buf[ID_OFFSET] == 'A' && buf[ID_OFFSET + 1] == 'D')) {
565 AliError("Bad message ID!");
569 if (buf[VERSION_OFFSET] != 1) {
570 AliError("Bad message version!");
574 Type type = (Type) GetUByte(buf + TYPE_OFFSET);
583 AliError("Unknown message type!");
587 UInt_t bodySize = GetInt(buf + BODY_SIZE_OFFSET);
588 if (bodySize > MAX_BODY_SIZE) {
589 AliError("Too big message body size!");
596 //______________________________________________________________________
597 void AliDCSMessage::LoadRequestMessage()
599 // load request message
601 if (fMessageSize < REQUEST_STRING_OFFSET) {
602 AliError("Body size is too small for request message!");
606 fRequestType = (RequestType) GetUByte(fMessage + REQUEST_TYPE_OFFSET);
608 fStartTime = GetUInt(fMessage + START_TIME_OFFSET);
609 fEndTime = GetUInt(fMessage + END_TIME_OFFSET);
610 fRequestString = GetString(fMessage + REQUEST_STRING_OFFSET,
611 fMessageSize - REQUEST_STRING_OFFSET);
613 switch (fRequestType) {
619 AliError("Invalid request type!");
623 //______________________________________________________________________
624 void AliDCSMessage::LoadCountMessage()
626 // load count message
628 if (fMessageSize < HEADER_SIZE + sizeof(UInt_t)) {
629 AliError("Body size is too small for count message!");
633 fCount = GetUInt(fMessage + COUNT_OFFSET);
638 //______________________________________________________________________
639 void AliDCSMessage::LoadResultSetMessage()
641 // load result message
643 if (fMessageSize < VALUES_OFFSET) {
644 AliError("Body size is too small for result set message!");
648 fValueType = (AliDCSValue::Type) GetUByte(fMessage + SVT_OFFSET);
649 UInt_t count = GetUInt(fMessage + VALUE_COUNT_OFFSET);
651 UInt_t cursor = VALUES_OFFSET;
653 if (fValueType == AliDCSValue::kBool) {
654 if (VALUES_OFFSET + count + count * sizeof(UInt_t) >
656 AliError("Too many bool values for this buffer size!");
660 for (UInt_t k = 0; k < count; k ++) {
661 Bool_t aBool = GetBool(fMessage + cursor);
663 UInt_t timeStamp = GetUInt(fMessage + cursor);
664 cursor += sizeof(UInt_t);
665 fValues->Add(new AliDCSValue(aBool, timeStamp));
667 } else if (fValueType == AliDCSValue::kChar) {
668 if (VALUES_OFFSET + count + count * sizeof(UInt_t) >
670 AliError("Too many byte values for this buffer size!");
674 for (UInt_t k = 0; k < count; k ++) {
675 Char_t aByte = GetByte(fMessage + cursor);
676 cursor += sizeof(Char_t);
677 UInt_t timeStamp = GetUInt(fMessage + cursor);
678 cursor += sizeof(UInt_t);
679 fValues->Add(new AliDCSValue(aByte, timeStamp));
681 } else if (fValueType == AliDCSValue::kInt) {
682 if (VALUES_OFFSET + count * sizeof(Int_t) +
683 count * sizeof(UInt_t) > fMessageSize) {
684 AliError("Too many int values for this buffer size!");
688 for (UInt_t k = 0; k < count; k ++) {
689 Int_t aInt = GetInt(fMessage + cursor);
690 cursor += sizeof(Int_t);
691 UInt_t timeStamp = GetUInt(fMessage + cursor);
692 cursor += sizeof(UInt_t);
693 fValues->Add(new AliDCSValue(aInt, timeStamp));
696 } else if (fValueType == AliDCSValue::kUInt) {
697 if (VALUES_OFFSET + count * sizeof(UInt_t) +
698 count * sizeof(UInt_t) > fMessageSize) {
699 AliError("Too many uint values for this buffer size!");
703 for (UInt_t k = 0; k < count; k ++) {
704 UInt_t aUInt = GetUInt(fMessage + cursor);
705 cursor += sizeof(UInt_t);
706 UInt_t timeStamp = GetUInt(fMessage + cursor);
707 cursor += sizeof(UInt_t);
708 fValues->Add(new AliDCSValue(aUInt, timeStamp));
710 } else if (fValueType == AliDCSValue::kFloat) {
711 if (VALUES_OFFSET + count * sizeof(Float_t) +
712 count * sizeof(UInt_t) > fMessageSize) {
713 AliError("Too many float values for this buffer size!");
717 for (UInt_t k = 0; k < count; k ++) {
718 Float_t aFloat = GetFloat(fMessage + cursor);
719 cursor += sizeof(Float_t);
720 UInt_t timeStamp = GetUInt(fMessage + cursor);
721 cursor += sizeof(UInt_t);
722 fValues->Add(new AliDCSValue(aFloat, timeStamp));
726 AliError("Unknown or invalid value type!");
732 //______________________________________________________________________
733 void AliDCSMessage::LoadErrorMessage()
735 // load error message
737 if (fMessageSize < ERROR_STRING_OFFSET) {
738 AliError("Body size is too small for error message!");
742 fErrorCode = (ErrorCode) GetUByte(fMessage + ERROR_CODE_OFFSET);
743 fErrorString = GetString(fMessage + ERROR_STRING_OFFSET,
744 fMessageSize - ERROR_STRING_OFFSET);
746 switch (fErrorCode) {
747 case kUnknownAliasDPName:
748 case kInvalidTimeRange:
749 case kInvalidBufferSize:
750 case kInvalidRequest:
751 case kUnsupportedType:
756 AliError("Invalid error code!");
760 //______________________________________________________________________
761 void AliDCSMessage::LoadMultiRequestMessage()
763 // load multi request message
765 if (fMessageSize - HEADER_SIZE < REQUEST_STRINGS_OFFSET) {
766 AliError("Body size is too small for multi request message!");
770 fRequestType = (RequestType) GetUByte(fMessage + REQUEST_TYPE_OFFSET);
772 fStartTime = GetUInt(fMessage + START_TIME_OFFSET);
773 fEndTime = GetUInt(fMessage + END_TIME_OFFSET);
775 switch (fRequestType) {
781 AliError("Invalid request type!");
785 UInt_t cursor = REQUEST_STRINGS_OFFSET;
787 while ((cursor < fMessageSize)) {
788 UChar_t strSize = GetUByte(fMessage + cursor);
791 if (cursor + strSize > fMessageSize) {
792 AliError("Invalid multi request message!");
796 TObjString* anObjString = new TObjString(
797 GetString(fMessage + cursor, strSize));
798 fRequestStrings.AddLast(anObjString);
803 fType = kMultiRequest;
806 //______________________________________________________________________
808 void AliDCSMessage::LoadNextMessage() {
813 //______________________________________________________________________
814 void AliDCSMessage::StoreToBuffer()
816 // Creates an underlying message buffer which can be sent to the socket.
822 StoreRequestMessage();
828 StoreResultSetMessage();
834 StoreMultiRequestMessage();
840 AliError("Can't store to buffer invalid message!");
844 //______________________________________________________________________
845 void AliDCSMessage::LoadFromBuffer()
847 // Reads the underlying message buffer and if it's valid message
848 // creates the corresponding message.
849 // If not set the message type kInvalid.
850 // This buffer is read from the socket.
855 AliError("Message buffer is empty! Can't load it.");
859 if (fMessageSize < HEADER_SIZE) {
860 AliError("Invalid message buffer. Too small for the header!");
864 if (!ValidateHeader(fMessage)) {
865 AliError("Invalid message header!");
869 UInt_t bodySize = GetUInt(fMessage + BODY_SIZE_OFFSET);
870 if (bodySize > fMessageSize - HEADER_SIZE) {
871 AliError("Message size is to small for the message body!");
875 fMessageSize = HEADER_SIZE + bodySize;
877 Type aType = (Type) GetUByte(fMessage + TYPE_OFFSET);
881 LoadRequestMessage();
887 LoadResultSetMessage();
893 LoadMultiRequestMessage();
899 AliError("Invalid message type!");
903 //______________________________________________________________________
904 AliDCSMessage::RequestType AliDCSMessage::GetRequestType() const
906 // Request and MultiRequest.
907 // Returns the request type: alias or dp (Data Point)
909 if (!(fType == kRequest || fType == kMultiRequest)) {
910 AliError("Invalid AliDCSMessage type!");
917 //______________________________________________________________________
918 UInt_t AliDCSMessage::GetStartTime() const
920 // Request and MultiRequest.
921 // Returns the request start time. (begining of the time interval).
923 if (!(fType == kRequest || fType == kMultiRequest)) {
924 AliError("Invalid AliDCSMessage type!");
931 //______________________________________________________________________
932 UInt_t AliDCSMessage::GetEndTime() const
934 // Request and MultiRequest.
935 // Returns the request start time. (end of the time interval).
938 if (!(fType == kRequest || fType == kMultiRequest)) {
939 AliError("Invalid AliDCSMessage type!");
946 //______________________________________________________________________
947 TString AliDCSMessage::GetRequestString() const
950 // Returns the request string. (alias or dp)
952 if (fType != kRequest) {
953 AliError("Invalid AliDCSMessage type!");
957 return fRequestString;
960 //______________________________________________________________________
961 Bool_t AliDCSMessage::AddRequestString(const char* request)
964 // Add a request to the request set.
965 // Returns kFALSE in case of invalid request (too long request string).
966 // Otherwise returns kTRUE.
969 if (fType != kMultiRequest) {
970 AliError("Invalid AliDCSMessage type!");
974 if (strlen(request) > 255) {
975 AliError("Alias/dpName is too long! Max size 255.");
979 fRequestStrings.AddLast(new TObjString(request));
983 //______________________________________________________________________
984 void AliDCSMessage::ClearRequestStrings()
987 // Clears the request set.
989 fRequestStrings.Delete();
992 //______________________________________________________________________
993 void AliDCSMessage::GetRequestStrings(TObjArray& result) const
996 // Returns all request strings in this message.
997 // result: container where the requests are returned. Collection of
1001 if (fType != kMultiRequest) {
1002 AliError("Invalid AliDCSMessage type!");
1006 TIter iter(&fRequestStrings);
1007 TObjString* anObjString;
1009 while ((anObjString = (TObjString*) iter.Next())) {
1010 result.AddLast(new TObjString(*anObjString));
1014 //______________________________________________________________________
1015 UInt_t AliDCSMessage::GetCount() const
1018 // Returns the total number of values.
1021 if (fType != kCount) {
1022 AliError("Invalid AliDCSMessage type!");
1029 //______________________________________________________________________
1030 AliDCSValue::Type AliDCSMessage::GetValueType() const
1033 // Returns simple value type (see AliDCSValue) for the values
1034 // in this ResultSet.
1036 if (fType != kResultSet) {
1037 AliError("Invalid AliDCSMessage type!");
1038 return AliDCSValue::kInvalid;
1044 //______________________________________________________________________
1045 UInt_t AliDCSMessage::GetValueCount() const
1048 // Returns the count of values in this ResultSet.
1051 if (fType != kResultSet) {
1052 AliError("Invalid AliDCSMessage type!");
1056 return fValues->GetEntriesFast();
1059 //______________________________________________________________________
1060 UInt_t AliDCSMessage::GetValues(TObjArray* result) const
1063 // Returns the number of values got from the message.
1064 // result: used to return the values. Collection of AliDCSValue.
1065 // result must be owner of the AliDCSValues because fVaule is not!
1066 // creator of the result array and used GetValues to fill it must delete object by himself!
1068 // TODO do not copy -> corrected?
1070 if (fType != kResultSet) {
1071 AliError("Invalid AliDCSMessage type!");
1075 TIter iter(fValues);
1076 AliDCSValue* aValue;
1078 while ((aValue = (AliDCSValue*) iter.Next())) {
1079 result->AddLast(aValue);
1082 return fValues->GetEntriesFast();
1086 //______________________________________________________________________
1087 Bool_t AliDCSMessage::AddValue(AliDCSValue& value)
1089 // Adds value to the ResultSet value list.
1090 // Returns kFALSE in case of error.
1091 // Otherwise returns kTRUE;
1093 if (fType != kResultSet) {
1094 AliError("Invalid AliDCSMessage type!");
1098 if (value.GetType() != fValueType) {
1099 AliError(Form("Can't add value with type %d to this message!", value.GetType()));
1103 fValues->Add(&value);
1109 //______________________________________________________________________
1110 void AliDCSMessage::ClearValues()
1112 // clear values array
1114 if(fValues) fValues->Clear();
1117 //______________________________________________________________________
1118 AliDCSMessage::ErrorCode AliDCSMessage::GetErrorCode() const
1122 // Returns the error code which has this error message.
1125 if (fType != kError) {
1126 AliError("Invalid AliDCSMessage type!");
1133 //______________________________________________________________________
1134 TString AliDCSMessage::GetErrorString() const
1138 // Returns the error string (error description) which has this
1142 if (GetType() != kError) {
1143 AliError("Invalid AliDCSMessage type!");
1147 return fErrorString;
1151 //______________________________________________________________________
1152 void AliDCSMessage::Print(Option_t* /*option*/) const
1156 if (AliLog::GetGlobalDebugLevel() < 2) {
1160 TString printString;
1161 printString += "\n <<AliDCSMessage>>\n";
1163 printString += " Size: ";
1164 printString += fMessageSize;
1165 printString += '\n';
1167 printString += " Type: ";
1168 switch (GetType()) {
1170 printString += "Request\n";
1172 printString += " RequestType: ";
1173 if (GetRequestType() == kDPName) {
1174 printString += "DPName";
1176 printString += "Alias";
1178 printString += '\n';
1180 printString += " RequestString: ";
1181 printString += GetRequestString();
1182 printString += '\n';
1183 printString += " StartTime: ";
1184 printString += GetStartTime();
1185 printString += '\n';
1186 printString += " EndTime: ";
1187 printString += GetEndTime();
1188 printString += '\n';
1193 printString += "Count\n";
1194 printString += " Count: ";
1195 printString += GetCount();
1196 printString += '\n';
1201 printString += "ResultSet\n";
1202 printString += " SimpleValueType: ";
1203 printString += fValueType;
1204 printString += '\n';
1205 printString += " ValueCount: ";
1206 printString += GetValueCount();
1207 printString += '\n';
1212 printString += "Error\n";
1213 printString += " ErrorCode: ";
1214 switch (GetErrorCode()) {
1215 case AliDCSMessage::kNoneError:
1216 printString += "NoneError";
1218 case AliDCSMessage::kUnknownAliasDPName:
1219 printString += "UnknownAliasDPName";
1221 case AliDCSMessage::kInvalidTimeRange:
1222 printString += "InvalidTimeRange";
1224 case AliDCSMessage::kInvalidBufferSize:
1225 printString += "InvalidBufferSize";
1227 case AliDCSMessage::kInvalidRequest:
1228 printString += "InvalidRequest";
1230 case AliDCSMessage::kUnsupportedType:
1231 printString += "UnsupportedType";
1233 case AliDCSMessage::kUnknownError:
1234 printString += "UnknownError";
1237 printString += "Invalid";
1240 printString += '\n';
1241 printString += " ErrorString: ";
1242 printString += GetErrorString();
1243 printString += '\n';
1247 case kMultiRequest: {
1248 printString += "MultiRequest\n";
1250 printString += " RequestType: ";
1251 if (GetRequestType() == kDPName) {
1252 printString += "DPName";
1254 printString += "Alias";
1256 printString += '\n';
1258 printString += " RequestStrings: ";
1259 TIter iter(&fRequestStrings);
1260 TObjString* anObjString;
1261 while ((anObjString = (TObjString*) iter.Next())) {
1262 printString += anObjString->String();
1265 printString += '\n';
1267 printString += " StartTime: ";
1268 printString += GetStartTime();
1269 printString += '\n';
1270 printString += " EndTime: ";
1271 printString += GetEndTime();
1272 printString += '\n';
1277 printString += "Next\n";
1282 printString += "Invalid\n";
1285 if (AliLog::GetGlobalDebugLevel() >= 3 && fMessage) {
1286 PrintBuffer(fMessage, fMessageSize, printString);
1289 AliDebug(2, printString);
1292 //______________________________________________________________________
1293 Bool_t AliDCSMessage::SetRawHeader(const char* header)
1296 // Checks if the header buffer represents a valid header message.
1297 // If so it creates a message buffer with the appropriate body size
1298 // and returns true.
1299 // If not returns false.
1300 // header: header buffer
1303 if (!ValidateHeader(header)) {
1304 AliError("Invalid message header!");
1310 UInt_t bodySize = GetUInt(header + BODY_SIZE_OFFSET);
1311 fMessageSize = HEADER_SIZE + bodySize;
1313 fMessage = new char[fMessageSize];
1315 memcpy(fMessage, header, HEADER_SIZE);
1321 //______________________________________________________________________
1322 void AliDCSMessage::DestroyBuffer()
1325 // Destroy the underlying message buffer.
1336 //______________________________________________________________________
1337 void AliDCSMessage::PrintBuffer(const char* buffer, UInt_t size,
1344 while (index < size) {
1345 if (!(index % 16)) {
1346 output += Form("\n %.4x:", index);
1353 output += Form(" %.2x", (UChar_t) buffer[index]);
1355 if (!((index + 1) % 16) || index + 1 == size) {
1356 if (index + 1 == size) {
1357 output.Append(' ',3 * (15 - index % 16));
1358 if (index % 16 < 8) {
1363 output.Append(' ', 2);
1364 for (Int_t k = index % 16; k >= 0; k --) {
1365 Char_t aChar = buffer[index - k];
1366 output += isgraph(aChar) ? aChar: '.';