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.7 2006/10/02 16:38:39 jgrosseo
21 storing of objects that failed to be stored to the grid before
22 interfacing of shuttle status table in daq system
24 Revision 1.6 2006/08/15 10:50:00 jgrosseo
25 effc++ corrections (alberto)
27 Revision 1.5 2006/07/20 09:54:40 jgrosseo
28 introducing status management: The processing per subdetector is divided into several steps,
29 after each step the status is stored on disk. If the system crashes in any of the steps the Shuttle
30 can keep track of the number of failures and skips further processing after a certain threshold is
31 exceeded. These thresholds can be configured in LDAP.
33 Revision 1.4 2006/07/04 14:59:57 jgrosseo
34 revision of AliDCSValue: Removed wrapper classes, reduced storage size per value by factor 2
36 Revision 1.3 2006/06/12 09:11:16 jgrosseo
37 coding conventions (Alberto)
39 Revision 1.2 2006/03/07 07:52:34 hristov
40 New version (B.Yordanov)
42 Revision 1.3 2005/11/17 17:47:34 byordano
43 TList changed to TObjArray
45 Revision 1.2 2005/11/17 14:43:23 byordano
48 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
49 Initial import as subdirectory in AliRoot
51 Revision 1.1.1.1 2005/09/12 22:11:40 byordano
54 Revision 1.2 2005/08/30 10:53:23 byordano
55 some more descriptions added
61 // This class is a wrapper of AliDCSMessage.
62 // These are the messages which form AliDCSProtocol.
63 // Every message has header and body. The body size is written in the header.
64 // There are five message types:
65 // 1) Request - used by the client to form a single request to DCS server
66 // 2) Count - returned by the server to inidicate the total number of
67 // values which would be sent to the client.
68 // 3) ResultSet - returned by the server and contains part of values set
69 // which forms the server resposen.
70 // 4) Error - returned by the server in case of error
71 // 5) MultiRequest - used by the client to form multi request.
72 // This is a request which serves many aliases/dp at the same time
73 // For all aliases/dp the same time interval is used.
74 // Short description of the schema:
75 // The client sends a request (Request or MultiRequest) and the server
77 // 1) Count - the total number of values that the client should
79 // 2) ResultSet* - every ResultSet message contains a part
80 // of valueSet (some values) which the client should expect
81 // The client can wait for ResultMessage until it gets
82 // all values (total number) which was returned by the
83 // Count message at the beginning of the ResutlSet sereie.
85 // 1) Error - contains the error code and error description
88 #include "AliDCSMessage.h"
93 #include <TObjString.h>
98 ClassImp(AliDCSMessage)
100 //______________________________________________________________________
101 AliDCSMessage::AliDCSMessage():
102 TObject(), fMessage(NULL), fMessageSize(0), fType(kInvalid),
103 fRequestType(kNoneType), fStartTime(0), fEndTime(0),
104 fRequestString(""), fCount(0),
105 fValueType(AliDCSValue::kInvalid), fValues(),
106 fErrorCode(kNoneError), fErrorString(""),
109 // default constructor
110 fValues = new TObjArray();
111 fValues->SetOwner(0);
115 //______________________________________________________________________
116 AliDCSMessage::AliDCSMessage(const char* message, UInt_t size):
117 TObject(), fMessage(NULL), fMessageSize(size), fType(kInvalid),
118 fRequestType(kNoneType), fStartTime(0), fEndTime(0),
119 fRequestString(""), fCount(0),
120 fValueType(AliDCSValue::kInvalid), fValues(),
121 fErrorCode(kNoneError), fErrorString(""),
124 // default constructor
126 fMessage = new char[size];
128 memcpy(fMessage, message, size);
129 fValues = new TObjArray();
130 fValues->SetOwner(0);
133 //______________________________________________________________________
134 AliDCSMessage::AliDCSMessage(const AliDCSMessage& /*other*/):
135 TObject(), fMessage(NULL), fMessageSize(0), fType(kInvalid),
136 fRequestType(kNoneType), fStartTime(0), fEndTime(0),
137 fRequestString(""), fCount(0),
138 fValueType(AliDCSValue::kInvalid), fValues(),
139 fErrorCode(kNoneError), fErrorString(""),
142 // copy constructor (not implemented)
146 //______________________________________________________________________
147 AliDCSMessage &AliDCSMessage::operator=(const AliDCSMessage& /*other*/)
149 // assignment operator (not implemented)
154 //______________________________________________________________________
155 AliDCSMessage::~AliDCSMessage()
161 if(fValues) delete fValues; fValues=0;
164 //______________________________________________________________________
165 void AliDCSMessage::CreateRequestMessage(RequestType type,
166 UInt_t startTime, UInt_t endTime, const char* request)
168 // Create request message
172 fType = AliDCSMessage::kRequest;
174 fStartTime = startTime;
176 fRequestString = request;
179 //______________________________________________________________________
180 void AliDCSMessage::CreateMultiRequestMessage(RequestType type,
181 UInt_t startTime, UInt_t endTime)
183 // Create multi request message
187 fType = AliDCSMessage::kMultiRequest;
189 fStartTime = startTime;
193 //______________________________________________________________________
194 void AliDCSMessage::CreateCountMessage(UInt_t count)
196 // Create count request message
200 fType = AliDCSMessage::kCount;
204 //______________________________________________________________________
205 void AliDCSMessage::CreateResultSetMessage(AliDCSValue::Type type)
207 // Create result set message
211 fType = AliDCSMessage::kResultSet;
215 //______________________________________________________________________
216 void AliDCSMessage::CreateErrorMessage(ErrorCode errorCode,
217 const char* errorString)
219 // Create error message
223 fType = AliDCSMessage::kError;
224 fErrorCode = errorCode;
225 fErrorString = errorString;
229 void AliDCSMessage::CreateNextMessage() {
232 fType = AliDCSMessage::kNext;
235 //______________________________________________________________________
236 void AliDCSMessage::DestroyMessage()
242 ClearRequestStrings();
245 //______________________________________________________________________
246 void AliDCSMessage::SetBool(char* buf, Bool_t val)
248 // Set bool value to buf
253 //______________________________________________________________________
254 void AliDCSMessage::SetByte(char* buf, Char_t val)
256 // Set byte value to buf
261 //______________________________________________________________________
262 void AliDCSMessage::SetUByte(char* buf, UChar_t val)
264 // Set ubyte value to buf
269 //______________________________________________________________________
270 void AliDCSMessage::SetInt(char* buf, Int_t val)
272 // Set int value to buf
277 //______________________________________________________________________
278 void AliDCSMessage::SetUInt(char* buf, UInt_t val)
280 // Set uint value to buf
285 //______________________________________________________________________
286 void AliDCSMessage::SetFloat(char* buf, Float_t val)
288 // Set float value to buf
293 //______________________________________________________________________
294 Bool_t AliDCSMessage::GetBool(const char* buf)
296 // get bool value from buf
299 char* aBuffer = (char*) buf;
301 frombuf(aBuffer, &val);
306 //______________________________________________________________________
307 Char_t AliDCSMessage::GetByte(const char* buf)
309 // get byte value from buf
312 char* aBuffer = (char*) buf;
314 frombuf(aBuffer, &val);
319 //______________________________________________________________________
320 UChar_t AliDCSMessage::GetUByte(const char* buf)
322 // get ubyte value from buf
325 char* aBuffer = (char*) buf;
327 frombuf(aBuffer, &val);
332 //______________________________________________________________________
333 Int_t AliDCSMessage::GetInt(const char* buf)
335 // get int value from buf
338 char* aBuffer = (char*) buf;
340 frombuf(aBuffer, &val);
345 //______________________________________________________________________
346 UInt_t AliDCSMessage::GetUInt(const char* buf)
348 // get uint value from buf
351 char* aBuffer = (char*) buf;
353 frombuf(aBuffer, &val);
358 //______________________________________________________________________
359 Float_t AliDCSMessage::GetFloat(const char* buf)
361 // get float value from buf
364 char* aBuffer = (char*) buf;
366 frombuf(aBuffer, &val);
371 //______________________________________________________________________
372 TString AliDCSMessage::GetString(const char* buf, Int_t maxLen)
374 // get string from buf
376 for (Int_t k = 0; k < maxLen; k ++) {
382 return TString(buf, maxLen);
385 //______________________________________________________________________
386 void AliDCSMessage::StoreHeader()
388 // store header message
390 SetUByte(fMessage + ID_OFFSET, 'A');
391 SetUByte(fMessage + ID_OFFSET + 1, 'D');
393 SetUByte(fMessage + VERSION_OFFSET, 1);
395 SetUByte(fMessage + TYPE_OFFSET, fType);
397 SetUInt(fMessage + BODY_SIZE_OFFSET, fMessageSize - HEADER_SIZE);
400 //______________________________________________________________________
401 void AliDCSMessage::StoreRequestMessage()
403 // store request message
405 fMessageSize = REQUEST_STRING_OFFSET +
406 fRequestString.Length() + 1;
408 fMessage = new char[fMessageSize];
412 SetUByte(fMessage + REQUEST_TYPE_OFFSET, fRequestType);
413 SetUInt(fMessage + START_TIME_OFFSET, fStartTime);
414 SetUInt(fMessage + END_TIME_OFFSET, fEndTime);
415 strcpy(fMessage + REQUEST_STRING_OFFSET, fRequestString.Data());
418 //______________________________________________________________________
419 void AliDCSMessage::StoreCountMessage()
421 // store count message
423 fMessageSize = COUNT_OFFSET + sizeof(UInt_t);
425 fMessage = new char[fMessageSize];
429 SetUInt(fMessage + COUNT_OFFSET, fCount);
432 //______________________________________________________________________
433 void AliDCSMessage::StoreResultSetMessage()
435 // store result set message
440 UInt_t valueDataSize = 0;
441 while ((aValue = (AliDCSValue*) iter.Next())) {
442 valueDataSize += aValue->GetSize();
445 fMessageSize = VALUES_OFFSET + valueDataSize;
447 fMessage = new char[fMessageSize];
451 SetUByte(fMessage + SVT_OFFSET, fValueType);
452 SetUInt(fMessage + VALUE_COUNT_OFFSET, GetValueCount());
454 UInt_t cursor = VALUES_OFFSET;
458 if (fValueType == AliDCSValue::kBool) {
459 while ((aValue = (AliDCSValue*) iter.Next())) {
460 SetBool(fMessage + cursor, aValue->GetBool());
462 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
463 cursor += sizeof(UInt_t);
465 } else if (fValueType == AliDCSValue::kChar) {
466 while ((aValue = (AliDCSValue*) iter.Next())) {
467 SetByte(fMessage + cursor, aValue->GetChar());
468 cursor += sizeof(Char_t);
469 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
470 cursor += sizeof(UInt_t);
472 } else if (fValueType == AliDCSValue::kInt) {
473 while ((aValue = (AliDCSValue*) iter.Next())) {
474 SetInt(fMessage + cursor, aValue->GetInt());
475 cursor += sizeof(Int_t);
476 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
477 cursor += sizeof(UInt_t);
479 } else if (fValueType == AliDCSValue::kUInt) {
480 while ((aValue = (AliDCSValue*) iter.Next())) {
481 SetUInt(fMessage + cursor, aValue->GetUInt());
482 cursor += sizeof(UInt_t);
483 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
484 cursor += sizeof(UInt_t);
486 } else if (fValueType == AliDCSValue::kFloat) {
487 while ((aValue = (AliDCSValue*) iter.Next())) {
488 SetFloat(fMessage + cursor, aValue->GetFloat());
489 cursor += sizeof(Float_t);
490 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
491 cursor += sizeof(UInt_t);
494 AliError("Invalid or unknown ValueType!");
500 //______________________________________________________________________
501 void AliDCSMessage::StoreErrorMessage()
503 // store error message
505 fMessageSize = ERROR_STRING_OFFSET + fErrorString.Length() + 1;
507 fMessage = new char[fMessageSize];
511 SetUByte(fMessage + ERROR_CODE_OFFSET, fErrorCode);
512 strcpy(fMessage + ERROR_STRING_OFFSET, fErrorString.Data());
515 //______________________________________________________________________
516 void AliDCSMessage::StoreMultiRequestMessage()
518 // store multi request message
520 UInt_t requestDataSize = 0;
522 TIter iter(&fRequestStrings);
523 TObjString* anObjString;
525 while ((anObjString = (TObjString*) iter.Next())) {
526 assert(anObjString->String().Length() <= 255);
527 requestDataSize += anObjString->String().Length() + 1;
530 fMessageSize = REQUEST_STRINGS_OFFSET + requestDataSize;
532 fMessage = new char[fMessageSize];
536 SetUByte(fMessage + REQUEST_TYPE_OFFSET, fRequestType);
537 SetUInt(fMessage + START_TIME_OFFSET, fStartTime);
538 SetUInt(fMessage + END_TIME_OFFSET, fEndTime);
542 UInt_t cursor = REQUEST_STRINGS_OFFSET;
544 while ((anObjString = (TObjString*) iter.Next())) {
545 UChar_t strLength = anObjString->String().Length();
546 SetUByte(fMessage + cursor, strLength);
548 strncpy(fMessage + cursor, anObjString->String().Data(),
554 //______________________________________________________________________
556 void AliDCSMessage::StoreNextMessage() {
558 fMessageSize = HEADER_SIZE;
560 fMessage = new char[fMessageSize];
565 //______________________________________________________________________
566 Bool_t AliDCSMessage::ValidateHeader(const char* buf)
568 // validate message header
570 if (!(buf[ID_OFFSET] == 'A' && buf[ID_OFFSET + 1] == 'D')) {
571 AliError("Bad message ID!");
575 if (buf[VERSION_OFFSET] != 1) {
576 AliError("Bad message version!");
580 Type type = (Type) GetUByte(buf + TYPE_OFFSET);
589 AliError("Unknown message type!");
593 UInt_t bodySize = GetInt(buf + BODY_SIZE_OFFSET);
594 if (bodySize > MAX_BODY_SIZE) {
595 AliError("Too big message body size!");
602 //______________________________________________________________________
603 void AliDCSMessage::LoadRequestMessage()
605 // load request message
607 if (fMessageSize < REQUEST_STRING_OFFSET) {
608 AliError("Body size is too small for request message!");
612 fRequestType = (RequestType) GetUByte(fMessage + REQUEST_TYPE_OFFSET);
614 fStartTime = GetUInt(fMessage + START_TIME_OFFSET);
615 fEndTime = GetUInt(fMessage + END_TIME_OFFSET);
616 fRequestString = GetString(fMessage + REQUEST_STRING_OFFSET,
617 fMessageSize - REQUEST_STRING_OFFSET);
619 switch (fRequestType) {
625 AliError("Invalid request type!");
629 //______________________________________________________________________
630 void AliDCSMessage::LoadCountMessage()
632 // load count message
634 if (fMessageSize < HEADER_SIZE + sizeof(UInt_t)) {
635 AliError("Body size is too small for count message!");
639 fCount = GetUInt(fMessage + COUNT_OFFSET);
644 //______________________________________________________________________
645 void AliDCSMessage::LoadResultSetMessage()
647 // load result message
649 if (fMessageSize < VALUES_OFFSET) {
650 AliError("Body size is too small for result set message!");
654 fValueType = (AliDCSValue::Type) GetUByte(fMessage + SVT_OFFSET);
655 UInt_t count = GetUInt(fMessage + VALUE_COUNT_OFFSET);
657 UInt_t cursor = VALUES_OFFSET;
659 if (fValueType == AliDCSValue::kBool) {
660 if (VALUES_OFFSET + count + count * sizeof(UInt_t) >
662 AliError("Too many bool values for this buffer size!");
666 for (UInt_t k = 0; k < count; k ++) {
667 Bool_t aBool = GetBool(fMessage + cursor);
669 UInt_t timeStamp = GetUInt(fMessage + cursor);
670 cursor += sizeof(UInt_t);
671 fValues->Add(new AliDCSValue(aBool, timeStamp));
673 } else if (fValueType == AliDCSValue::kChar) {
674 if (VALUES_OFFSET + count + count * sizeof(UInt_t) >
676 AliError("Too many byte values for this buffer size!");
680 for (UInt_t k = 0; k < count; k ++) {
681 Char_t aByte = GetByte(fMessage + cursor);
682 cursor += sizeof(Char_t);
683 UInt_t timeStamp = GetUInt(fMessage + cursor);
684 cursor += sizeof(UInt_t);
685 fValues->Add(new AliDCSValue(aByte, timeStamp));
687 } else if (fValueType == AliDCSValue::kInt) {
688 if (VALUES_OFFSET + count * sizeof(Int_t) +
689 count * sizeof(UInt_t) > fMessageSize) {
690 AliError("Too many int values for this buffer size!");
694 for (UInt_t k = 0; k < count; k ++) {
695 Int_t aInt = GetInt(fMessage + cursor);
696 cursor += sizeof(Int_t);
697 UInt_t timeStamp = GetUInt(fMessage + cursor);
698 cursor += sizeof(UInt_t);
699 fValues->Add(new AliDCSValue(aInt, timeStamp));
702 } else if (fValueType == AliDCSValue::kUInt) {
703 if (VALUES_OFFSET + count * sizeof(UInt_t) +
704 count * sizeof(UInt_t) > fMessageSize) {
705 AliError("Too many uint values for this buffer size!");
709 for (UInt_t k = 0; k < count; k ++) {
710 UInt_t aUInt = GetUInt(fMessage + cursor);
711 cursor += sizeof(UInt_t);
712 UInt_t timeStamp = GetUInt(fMessage + cursor);
713 cursor += sizeof(UInt_t);
714 fValues->Add(new AliDCSValue(aUInt, timeStamp));
716 } else if (fValueType == AliDCSValue::kFloat) {
717 if (VALUES_OFFSET + count * sizeof(Float_t) +
718 count * sizeof(UInt_t) > fMessageSize) {
719 AliError("Too many float values for this buffer size!");
723 for (UInt_t k = 0; k < count; k ++) {
724 Float_t aFloat = GetFloat(fMessage + cursor);
725 cursor += sizeof(Float_t);
726 UInt_t timeStamp = GetUInt(fMessage + cursor);
727 cursor += sizeof(UInt_t);
728 fValues->Add(new AliDCSValue(aFloat, timeStamp));
732 AliError("Unknown or invalid value type!");
738 //______________________________________________________________________
739 void AliDCSMessage::LoadErrorMessage()
741 // load error message
743 if (fMessageSize < ERROR_STRING_OFFSET) {
744 AliError("Body size is too small for error message!");
748 fErrorCode = (ErrorCode) GetUByte(fMessage + ERROR_CODE_OFFSET);
749 fErrorString = GetString(fMessage + ERROR_STRING_OFFSET,
750 fMessageSize - ERROR_STRING_OFFSET);
752 switch (fErrorCode) {
753 case kUnknownAliasDPName:
754 case kInvalidTimeRange:
755 case kInvalidBufferSize:
756 case kInvalidRequest:
757 case kUnsupportedType:
762 AliError("Invalid error code!");
766 //______________________________________________________________________
767 void AliDCSMessage::LoadMultiRequestMessage()
769 // load multi request message
771 if (fMessageSize - HEADER_SIZE < REQUEST_STRINGS_OFFSET) {
772 AliError("Body size is too small for multi request message!");
776 fRequestType = (RequestType) GetUByte(fMessage + REQUEST_TYPE_OFFSET);
778 fStartTime = GetUInt(fMessage + START_TIME_OFFSET);
779 fEndTime = GetUInt(fMessage + END_TIME_OFFSET);
781 switch (fRequestType) {
787 AliError("Invalid request type!");
791 UInt_t cursor = REQUEST_STRINGS_OFFSET;
793 while ((cursor < fMessageSize)) {
794 UChar_t strSize = GetUByte(fMessage + cursor);
797 if (cursor + strSize > fMessageSize) {
798 AliError("Invalid multi request message!");
802 TObjString* anObjString = new TObjString(
803 GetString(fMessage + cursor, strSize));
804 fRequestStrings.AddLast(anObjString);
809 fType = kMultiRequest;
812 //______________________________________________________________________
814 void AliDCSMessage::LoadNextMessage() {
819 //______________________________________________________________________
820 void AliDCSMessage::StoreToBuffer()
822 // Creates an underlying message buffer which can be sent to the socket.
828 StoreRequestMessage();
834 StoreResultSetMessage();
840 StoreMultiRequestMessage();
846 AliError("Can't store to buffer invalid message!");
850 //______________________________________________________________________
851 void AliDCSMessage::LoadFromBuffer()
853 // Reads the underlying message buffer and if it's valid message
854 // creates the corresponding message.
855 // If not set the message type kInvalid.
856 // This buffer is read from the socket.
861 AliError("Message buffer is empty! Can't load it.");
865 if (fMessageSize < HEADER_SIZE) {
866 AliError("Invalid message buffer. Too small for the header!");
870 if (!ValidateHeader(fMessage)) {
871 AliError("Invalid message header!");
875 UInt_t bodySize = GetUInt(fMessage + BODY_SIZE_OFFSET);
876 if (bodySize > fMessageSize - HEADER_SIZE) {
877 AliError("Message size is to small for the message body!");
881 fMessageSize = HEADER_SIZE + bodySize;
883 Type aType = (Type) GetUByte(fMessage + TYPE_OFFSET);
887 LoadRequestMessage();
893 LoadResultSetMessage();
899 LoadMultiRequestMessage();
905 AliError("Invalid message type!");
909 //______________________________________________________________________
910 AliDCSMessage::RequestType AliDCSMessage::GetRequestType() const
912 // Request and MultiRequest.
913 // Returns the request type: alias or dp (Data Point)
915 if (!(fType == kRequest || fType == kMultiRequest)) {
916 AliError("Invalid AliDCSMessage type!");
923 //______________________________________________________________________
924 UInt_t AliDCSMessage::GetStartTime() const
926 // Request and MultiRequest.
927 // Returns the request start time. (begining of the time interval).
929 if (!(fType == kRequest || fType == kMultiRequest)) {
930 AliError("Invalid AliDCSMessage type!");
937 //______________________________________________________________________
938 UInt_t AliDCSMessage::GetEndTime() const
940 // Request and MultiRequest.
941 // Returns the request start time. (end of the time interval).
944 if (!(fType == kRequest || fType == kMultiRequest)) {
945 AliError("Invalid AliDCSMessage type!");
952 //______________________________________________________________________
953 TString AliDCSMessage::GetRequestString() const
956 // Returns the request string. (alias or dp)
958 if (fType != kRequest) {
959 AliError("Invalid AliDCSMessage type!");
963 return fRequestString;
966 //______________________________________________________________________
967 Bool_t AliDCSMessage::AddRequestString(const char* request)
970 // Add a request to the request set.
971 // Returns kFALSE in case of invalid request (too long request string).
972 // Otherwise returns kTRUE.
975 if (fType != kMultiRequest) {
976 AliError("Invalid AliDCSMessage type!");
980 if (strlen(request) > 255) {
981 AliError("Alias/dpName is too long! Max size 255.");
985 fRequestStrings.AddLast(new TObjString(request));
989 //______________________________________________________________________
990 void AliDCSMessage::ClearRequestStrings()
993 // Clears the request set.
995 fRequestStrings.Delete();
998 //______________________________________________________________________
999 void AliDCSMessage::GetRequestStrings(TObjArray& result) const
1002 // Returns all request strings in this message.
1003 // result: container where the requests are returned. Collection of
1007 if (fType != kMultiRequest) {
1008 AliError("Invalid AliDCSMessage type!");
1012 TIter iter(&fRequestStrings);
1013 TObjString* anObjString;
1015 while ((anObjString = (TObjString*) iter.Next())) {
1016 result.AddLast(new TObjString(*anObjString));
1020 //______________________________________________________________________
1021 UInt_t AliDCSMessage::GetCount() const
1024 // Returns the total number of values.
1027 if (fType != kCount) {
1028 AliError("Invalid AliDCSMessage type!");
1035 //______________________________________________________________________
1036 AliDCSValue::Type AliDCSMessage::GetValueType() const
1039 // Returns simple value type (see AliDCSValue) for the values
1040 // in this ResultSet.
1042 if (fType != kResultSet) {
1043 AliError("Invalid AliDCSMessage type!");
1044 return AliDCSValue::kInvalid;
1050 //______________________________________________________________________
1051 UInt_t AliDCSMessage::GetValueCount() const
1054 // Returns the count of values in this ResultSet.
1057 if (fType != kResultSet) {
1058 AliError("Invalid AliDCSMessage type!");
1062 return fValues->GetEntriesFast();
1065 //______________________________________________________________________
1066 UInt_t AliDCSMessage::GetValues(TObjArray* result) const
1069 // Returns the number of values got from the message.
1070 // result: used to return the values. Collection of AliDCSValue.
1071 // result must be owner of the AliDCSValues because fVaule is not!
1072 // creator of the result array and used GetValues to fill it must delete object by himself!
1074 // TODO do not copy -> corrected?
1076 if (fType != kResultSet) {
1077 AliError("Invalid AliDCSMessage type!");
1081 TIter iter(fValues);
1082 AliDCSValue* aValue;
1084 while ((aValue = (AliDCSValue*) iter.Next())) {
1085 result->AddLast(aValue);
1088 return fValues->GetEntriesFast();
1092 //______________________________________________________________________
1093 Bool_t AliDCSMessage::AddValue(AliDCSValue& value)
1095 // Adds value to the ResultSet value list.
1096 // Returns kFALSE in case of error.
1097 // Otherwise returns kTRUE;
1099 if (fType != kResultSet) {
1100 AliError("Invalid AliDCSMessage type!");
1104 if (value.GetType() != fValueType) {
1105 AliError(Form("Can't add value with type %d to this message!", value.GetType()));
1109 fValues->Add(&value);
1115 //______________________________________________________________________
1116 void AliDCSMessage::ClearValues()
1118 // clear values array
1120 if(fValues) fValues->Clear();
1123 //______________________________________________________________________
1124 AliDCSMessage::ErrorCode AliDCSMessage::GetErrorCode() const
1128 // Returns the error code which has this error message.
1131 if (fType != kError) {
1132 AliError("Invalid AliDCSMessage type!");
1139 //______________________________________________________________________
1140 TString AliDCSMessage::GetErrorString() const
1144 // Returns the error string (error description) which has this
1148 if (GetType() != kError) {
1149 AliError("Invalid AliDCSMessage type!");
1153 return fErrorString;
1157 //______________________________________________________________________
1158 void AliDCSMessage::Print(Option_t* /*option*/) const
1162 if (AliLog::GetGlobalDebugLevel() < 2) {
1166 TString printString;
1167 printString += "\n <<AliDCSMessage>>\n";
1169 printString += " Size: ";
1170 printString += fMessageSize;
1171 printString += '\n';
1173 printString += " Type: ";
1174 switch (GetType()) {
1176 printString += "Request\n";
1178 printString += " RequestType: ";
1179 if (GetRequestType() == kDPName) {
1180 printString += "DPName";
1182 printString += "Alias";
1184 printString += '\n';
1186 printString += " RequestString: ";
1187 printString += GetRequestString();
1188 printString += '\n';
1189 printString += " StartTime: ";
1190 printString += GetStartTime();
1191 printString += '\n';
1192 printString += " EndTime: ";
1193 printString += GetEndTime();
1194 printString += '\n';
1199 printString += "Count\n";
1200 printString += " Count: ";
1201 printString += GetCount();
1202 printString += '\n';
1207 printString += "ResultSet\n";
1208 printString += " SimpleValueType: ";
1209 printString += fValueType;
1210 printString += '\n';
1211 printString += " ValueCount: ";
1212 printString += GetValueCount();
1213 printString += '\n';
1218 printString += "Error\n";
1219 printString += " ErrorCode: ";
1220 switch (GetErrorCode()) {
1221 case AliDCSMessage::kNoneError:
1222 printString += "NoneError";
1224 case AliDCSMessage::kUnknownAliasDPName:
1225 printString += "UnknownAliasDPName";
1227 case AliDCSMessage::kInvalidTimeRange:
1228 printString += "InvalidTimeRange";
1230 case AliDCSMessage::kInvalidBufferSize:
1231 printString += "InvalidBufferSize";
1233 case AliDCSMessage::kInvalidRequest:
1234 printString += "InvalidRequest";
1236 case AliDCSMessage::kUnsupportedType:
1237 printString += "UnsupportedType";
1239 case AliDCSMessage::kUnknownError:
1240 printString += "UnknownError";
1243 printString += "Invalid";
1246 printString += '\n';
1247 printString += " ErrorString: ";
1248 printString += GetErrorString();
1249 printString += '\n';
1253 case kMultiRequest: {
1254 printString += "MultiRequest\n";
1256 printString += " RequestType: ";
1257 if (GetRequestType() == kDPName) {
1258 printString += "DPName";
1260 printString += "Alias";
1262 printString += '\n';
1264 printString += " RequestStrings: ";
1265 TIter iter(&fRequestStrings);
1266 TObjString* anObjString;
1267 while ((anObjString = (TObjString*) iter.Next())) {
1268 printString += anObjString->String();
1271 printString += '\n';
1273 printString += " StartTime: ";
1274 printString += GetStartTime();
1275 printString += '\n';
1276 printString += " EndTime: ";
1277 printString += GetEndTime();
1278 printString += '\n';
1283 printString += "Next\n";
1288 printString += "Invalid\n";
1291 if (AliLog::GetGlobalDebugLevel() >= 3 && fMessage) {
1292 PrintBuffer(fMessage, fMessageSize, printString);
1295 AliDebug(2, printString);
1298 //______________________________________________________________________
1299 Bool_t AliDCSMessage::SetRawHeader(const char* header)
1302 // Checks if the header buffer represents a valid header message.
1303 // If so it creates a message buffer with the appropriate body size
1304 // and returns true.
1305 // If not returns false.
1306 // header: header buffer
1309 if (!ValidateHeader(header)) {
1310 AliError("Invalid message header!");
1316 UInt_t bodySize = GetUInt(header + BODY_SIZE_OFFSET);
1317 fMessageSize = HEADER_SIZE + bodySize;
1319 fMessage = new char[fMessageSize];
1321 memcpy(fMessage, header, HEADER_SIZE);
1327 //______________________________________________________________________
1328 void AliDCSMessage::DestroyBuffer()
1331 // Destroy the underlying message buffer.
1342 //______________________________________________________________________
1343 void AliDCSMessage::PrintBuffer(const char* buffer, UInt_t size,
1350 while (index < size) {
1351 if (!(index % 16)) {
1352 output += Form("\n %.4x:", index);
1359 output += Form(" %.2x", (UChar_t) buffer[index]);
1361 if (!((index + 1) % 16) || index + 1 == size) {
1362 if (index + 1 == size) {
1363 output.Append(' ',3 * (15 - index % 16));
1364 if (index % 16 < 8) {
1369 output.Append(' ', 2);
1370 for (Int_t k = index % 16; k >= 0; k --) {
1371 Char_t aChar = buffer[index - k];
1372 output += isgraph(aChar) ? aChar: '.';