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 2006/11/06 14:22:47 jgrosseo
19 major update (Alberto)
20 o) reading of run parameters from the logbook
21 o) online offline naming conversion
22 o) standalone DCSclient package
24 Revision 1.7 2006/10/02 16:38:39 jgrosseo
27 storing of objects that failed to be stored to the grid before
28 interfacing of shuttle status table in daq system
30 Revision 1.6 2006/08/15 10:50:00 jgrosseo
31 effc++ corrections (alberto)
33 Revision 1.5 2006/07/20 09:54:40 jgrosseo
34 introducing status management: The processing per subdetector is divided into several steps,
35 after each step the status is stored on disk. If the system crashes in any of the steps the Shuttle
36 can keep track of the number of failures and skips further processing after a certain threshold is
37 exceeded. These thresholds can be configured in LDAP.
39 Revision 1.4 2006/07/04 14:59:57 jgrosseo
40 revision of AliDCSValue: Removed wrapper classes, reduced storage size per value by factor 2
42 Revision 1.3 2006/06/12 09:11:16 jgrosseo
43 coding conventions (Alberto)
45 Revision 1.2 2006/03/07 07:52:34 hristov
46 New version (B.Yordanov)
48 Revision 1.3 2005/11/17 17:47:34 byordano
49 TList changed to TObjArray
51 Revision 1.2 2005/11/17 14:43:23 byordano
54 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
55 Initial import as subdirectory in AliRoot
57 Revision 1.1.1.1 2005/09/12 22:11:40 byordano
60 Revision 1.2 2005/08/30 10:53:23 byordano
61 some more descriptions added
67 // This class is a wrapper of AliDCSMessage.
68 // These are the messages which form AliDCSProtocol.
69 // Every message has header and body. The body size is written in the header.
70 // There are five message types:
71 // 1) Request - used by the client to form a single request to DCS server
72 // 2) Count - returned by the server to inidicate the total number of
73 // values which would be sent to the client.
74 // 3) ResultSet - returned by the server and contains part of values set
75 // which forms the server resposen.
76 // 4) Error - returned by the server in case of error
77 // 5) MultiRequest - used by the client to form multi request.
78 // This is a request which serves many aliases/dp at the same time
79 // For all aliases/dp the same time interval is used.
80 // Short description of the schema:
81 // The client sends a request (Request or MultiRequest) and the server
83 // 1) Count - the total number of values that the client should
85 // 2) ResultSet* - every ResultSet message contains a part
86 // of valueSet (some values) which the client should expect
87 // The client can wait for ResultMessage until it gets
88 // all values (total number) which was returned by the
89 // Count message at the beginning of the ResutlSet sereie.
91 // 1) Error - contains the error code and error description
94 #include "AliDCSMessage.h"
99 #include <TObjString.h>
104 ClassImp(AliDCSMessage)
106 //______________________________________________________________________
107 AliDCSMessage::AliDCSMessage():
108 TObject(), fMessage(NULL), fMessageSize(0), fType(kInvalid),
109 fRequestType(kNoneType), fStartTime(0), fEndTime(0),
110 fRequestString(""), fCount(0),
111 fOwnerIndex(0), fValueType(AliDCSValue::kInvalid), fValues(),
112 fErrorCode(kNoneError), fErrorString(""),
115 // default constructor
116 fValues = new TObjArray();
117 fValues->SetOwner(0);
121 //______________________________________________________________________
122 AliDCSMessage::AliDCSMessage(const char* message, UInt_t size):
123 TObject(), fMessage(NULL), fMessageSize(size), fType(kInvalid),
124 fRequestType(kNoneType), fStartTime(0), fEndTime(0),
125 fRequestString(""), fCount(0),
126 fOwnerIndex(0), fValueType(AliDCSValue::kInvalid), fValues(),
127 fErrorCode(kNoneError), fErrorString(""),
130 // default constructor
132 fMessage = new char[size];
134 memcpy(fMessage, message, size);
135 fValues = new TObjArray();
136 fValues->SetOwner(0);
139 //______________________________________________________________________
140 AliDCSMessage::AliDCSMessage(const AliDCSMessage& /*other*/):
141 TObject(), fMessage(NULL), fMessageSize(0), fType(kInvalid),
142 fRequestType(kNoneType), fStartTime(0), fEndTime(0),
143 fRequestString(""), fCount(0),
144 fOwnerIndex(0), fValueType(AliDCSValue::kInvalid), fValues(),
145 fErrorCode(kNoneError), fErrorString(""),
148 // copy constructor (not implemented)
152 //______________________________________________________________________
153 AliDCSMessage &AliDCSMessage::operator=(const AliDCSMessage& /*other*/)
155 // assignment operator (not implemented)
160 //______________________________________________________________________
161 AliDCSMessage::~AliDCSMessage()
167 if(fValues) delete fValues; fValues=0;
170 //______________________________________________________________________
171 void AliDCSMessage::CreateRequestMessage(RequestType type,
172 UInt_t startTime, UInt_t endTime, const char* request)
174 // Create request message
178 fType = AliDCSMessage::kRequest;
180 fStartTime = startTime;
182 fRequestString = request;
185 //______________________________________________________________________
186 void AliDCSMessage::CreateMultiRequestMessage(RequestType type,
187 UInt_t startTime, UInt_t endTime)
189 // Create multi request message
193 fType = AliDCSMessage::kMultiRequest;
195 fStartTime = startTime;
199 //______________________________________________________________________
200 void AliDCSMessage::CreateCountMessage(UInt_t count)
202 // Create count request message
206 fType = AliDCSMessage::kCount;
210 //______________________________________________________________________
211 void AliDCSMessage::CreateResultSetMessage(AliDCSValue::Type type)
213 // Create result set message
217 fType = AliDCSMessage::kResultSet;
221 //______________________________________________________________________
222 void AliDCSMessage::CreateErrorMessage(ErrorCode errorCode,
223 const char* errorString)
225 // Create error message
229 fType = AliDCSMessage::kError;
230 fErrorCode = errorCode;
231 fErrorString = errorString;
235 void AliDCSMessage::CreateNextMessage() {
238 fType = AliDCSMessage::kNext;
241 //______________________________________________________________________
242 void AliDCSMessage::DestroyMessage()
248 ClearRequestStrings();
251 //______________________________________________________________________
252 void AliDCSMessage::SetBool(char* buf, Bool_t val)
254 // Set bool value to buf
259 //______________________________________________________________________
260 void AliDCSMessage::SetByte(char* buf, Char_t val)
262 // Set byte value to buf
267 //______________________________________________________________________
268 void AliDCSMessage::SetUByte(char* buf, UChar_t val)
270 // Set ubyte value to buf
275 //______________________________________________________________________
276 void AliDCSMessage::SetInt(char* buf, Int_t val)
278 // Set int value to buf
283 //______________________________________________________________________
284 void AliDCSMessage::SetUInt(char* buf, UInt_t val)
286 // Set uint value to buf
291 //______________________________________________________________________
292 void AliDCSMessage::SetFloat(char* buf, Float_t val)
294 // Set float value to buf
299 //______________________________________________________________________
300 Bool_t AliDCSMessage::GetBool(const char* buf)
302 // get bool value from buf
305 char* aBuffer = (char*) buf;
307 frombuf(aBuffer, &val);
312 //______________________________________________________________________
313 Char_t AliDCSMessage::GetByte(const char* buf)
315 // get byte value from buf
318 char* aBuffer = (char*) buf;
320 frombuf(aBuffer, &val);
325 //______________________________________________________________________
326 UChar_t AliDCSMessage::GetUByte(const char* buf)
328 // get ubyte value from buf
331 char* aBuffer = (char*) buf;
333 frombuf(aBuffer, &val);
338 //______________________________________________________________________
339 Int_t AliDCSMessage::GetInt(const char* buf)
341 // get int value from buf
344 char* aBuffer = (char*) buf;
346 frombuf(aBuffer, &val);
351 //______________________________________________________________________
352 UInt_t AliDCSMessage::GetUInt(const char* buf)
354 // get uint value from buf
357 char* aBuffer = (char*) buf;
359 frombuf(aBuffer, &val);
364 //______________________________________________________________________
365 Float_t AliDCSMessage::GetFloat(const char* buf)
367 // get float value from buf
370 char* aBuffer = (char*) buf;
372 frombuf(aBuffer, &val);
377 //______________________________________________________________________
378 TString AliDCSMessage::GetString(const char* buf, Int_t maxLen)
380 // get string from buf
382 for (Int_t k = 0; k < maxLen; k ++) {
388 return TString(buf, maxLen);
391 //______________________________________________________________________
392 void AliDCSMessage::StoreHeader()
394 // store header message
396 SetUByte(fMessage + ID_OFFSET, 'A');
397 SetUByte(fMessage + ID_OFFSET + 1, 'D');
399 SetUByte(fMessage + VERSION_OFFSET, 2);
401 SetUByte(fMessage + TYPE_OFFSET, fType);
403 SetUInt(fMessage + BODY_SIZE_OFFSET, fMessageSize - HEADER_SIZE);
406 //______________________________________________________________________
407 void AliDCSMessage::StoreRequestMessage()
409 // store request message
411 fMessageSize = REQUEST_STRING_OFFSET +
412 fRequestString.Length() + 1;
414 fMessage = new char[fMessageSize];
418 SetUByte(fMessage + REQUEST_TYPE_OFFSET, fRequestType);
419 SetUInt(fMessage + START_TIME_OFFSET, fStartTime);
420 SetUInt(fMessage + END_TIME_OFFSET, fEndTime);
421 strcpy(fMessage + REQUEST_STRING_OFFSET, fRequestString.Data());
424 //______________________________________________________________________
425 void AliDCSMessage::StoreCountMessage()
427 // store count message
429 fMessageSize = COUNT_OFFSET + sizeof(UInt_t);
431 fMessage = new char[fMessageSize];
435 SetUInt(fMessage + COUNT_OFFSET, fCount);
438 //______________________________________________________________________
439 void AliDCSMessage::StoreResultSetMessage()
441 // store result set message
446 UInt_t valueDataSize = 0;
447 while ((aValue = (AliDCSValue*) iter.Next())) {
448 valueDataSize += aValue->GetSize();
451 fMessageSize = VALUES_OFFSET + valueDataSize;
453 fMessage = new char[fMessageSize];
457 SetUByte(fMessage + SVT_OFFSET, fValueType);
458 SetUInt(fMessage + VALUE_COUNT_OFFSET, GetValueCount());
460 UInt_t cursor = VALUES_OFFSET;
464 if (fValueType == AliDCSValue::kBool) {
465 while ((aValue = (AliDCSValue*) iter.Next())) {
466 SetBool(fMessage + cursor, aValue->GetBool());
468 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
469 cursor += sizeof(UInt_t);
471 } else if (fValueType == AliDCSValue::kChar) {
472 while ((aValue = (AliDCSValue*) iter.Next())) {
473 SetByte(fMessage + cursor, aValue->GetChar());
474 cursor += sizeof(Char_t);
475 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
476 cursor += sizeof(UInt_t);
478 } else if (fValueType == AliDCSValue::kInt) {
479 while ((aValue = (AliDCSValue*) iter.Next())) {
480 SetInt(fMessage + cursor, aValue->GetInt());
481 cursor += sizeof(Int_t);
482 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
483 cursor += sizeof(UInt_t);
485 } else if (fValueType == AliDCSValue::kUInt) {
486 while ((aValue = (AliDCSValue*) iter.Next())) {
487 SetUInt(fMessage + cursor, aValue->GetUInt());
488 cursor += sizeof(UInt_t);
489 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
490 cursor += sizeof(UInt_t);
492 } else if (fValueType == AliDCSValue::kFloat) {
493 while ((aValue = (AliDCSValue*) iter.Next())) {
494 SetFloat(fMessage + cursor, aValue->GetFloat());
495 cursor += sizeof(Float_t);
496 SetUInt(fMessage + cursor, aValue->GetTimeStamp());
497 cursor += sizeof(UInt_t);
500 AliError("Invalid or unknown ValueType!");
506 //______________________________________________________________________
507 void AliDCSMessage::StoreErrorMessage()
509 // store error message
511 fMessageSize = ERROR_STRING_OFFSET + fErrorString.Length() + 1;
513 fMessage = new char[fMessageSize];
517 SetUByte(fMessage + ERROR_CODE_OFFSET, fErrorCode);
518 strcpy(fMessage + ERROR_STRING_OFFSET, fErrorString.Data());
521 //______________________________________________________________________
522 void AliDCSMessage::StoreMultiRequestMessage()
524 // store multi request message
526 UInt_t requestDataSize = 0;
528 TIter iter(&fRequestStrings);
529 TObjString* anObjString;
531 while ((anObjString = (TObjString*) iter.Next())) {
532 requestDataSize += anObjString->String().Length() + 1;
535 fMessageSize = REQUEST_STRINGS_OFFSET + requestDataSize;
537 fMessage = new char[fMessageSize];
541 SetUByte(fMessage + REQUEST_TYPE_OFFSET, fRequestType);
542 SetUInt(fMessage + START_TIME_OFFSET, fStartTime);
543 SetUInt(fMessage + END_TIME_OFFSET, fEndTime);
547 UInt_t cursor = REQUEST_STRINGS_OFFSET;
549 while ((anObjString = (TObjString*) iter.Next())) {
550 UChar_t strLength = anObjString->String().Length();
551 strncpy(fMessage + cursor, anObjString->String().Data(),
554 SetUByte(fMessage + cursor, 0);
559 //______________________________________________________________________
560 void AliDCSMessage::StoreNextMessage()
562 fMessageSize = HEADER_SIZE;
564 fMessage = new char[fMessageSize];
569 //______________________________________________________________________
570 Bool_t AliDCSMessage::ValidateHeader(const char* buf)
572 // validate message header
574 if (!(buf[ID_OFFSET] == 'A' && buf[ID_OFFSET + 1] == 'D')) {
575 AliError("Bad message ID!");
579 if (buf[VERSION_OFFSET] != 2) {
580 AliError("Bad message version!");
584 Type type = (Type) GetUByte(buf + TYPE_OFFSET);
593 AliError("Unknown message type!");
597 UInt_t bodySize = GetInt(buf + BODY_SIZE_OFFSET);
598 if (bodySize > MAX_BODY_SIZE) {
599 AliError("Too big message body size!");
606 //______________________________________________________________________
607 void AliDCSMessage::LoadRequestMessage()
609 // load request message
611 if (fMessageSize < REQUEST_STRING_OFFSET) {
612 AliError("Body size is too small for request message!");
616 fRequestType = (RequestType) GetUByte(fMessage + REQUEST_TYPE_OFFSET);
618 fStartTime = GetUInt(fMessage + START_TIME_OFFSET);
619 fEndTime = GetUInt(fMessage + END_TIME_OFFSET);
620 fRequestString = GetString(fMessage + REQUEST_STRING_OFFSET,
621 fMessageSize - REQUEST_STRING_OFFSET);
623 switch (fRequestType) {
629 AliError("Invalid request type!");
633 //______________________________________________________________________
634 void AliDCSMessage::LoadCountMessage()
636 // load count message
638 if (fMessageSize < HEADER_SIZE + sizeof(UInt_t)) {
639 AliError("Body size is too small for count message!");
643 fCount = GetUInt(fMessage + COUNT_OFFSET);
648 //______________________________________________________________________
649 void AliDCSMessage::LoadResultSetMessage()
651 // load result message
653 if (fMessageSize < VALUES_OFFSET) {
654 AliError("Body size is too small for result set message!");
658 fOwnerIndex = GetInt(fMessage + INDEX_OFFSET);
660 fValueType = (AliDCSValue::Type) GetUByte(fMessage + SVT_OFFSET);
661 UInt_t count = GetUInt(fMessage + VALUE_COUNT_OFFSET);
663 UInt_t cursor = VALUES_OFFSET;
666 if (fOwnerIndex >= 0)
668 if (fValueType == AliDCSValue::kBool) {
669 if (VALUES_OFFSET + count + count * sizeof(UInt_t) >
671 AliError("Too many bool values for this buffer size!");
675 for (UInt_t k = 0; k < count; k ++) {
676 Bool_t aBool = GetBool(fMessage + cursor);
678 UInt_t timeStamp = GetUInt(fMessage + cursor);
679 cursor += sizeof(UInt_t);
680 fValues->Add(new AliDCSValue(aBool, timeStamp));
682 } else if (fValueType == AliDCSValue::kChar) {
683 if (VALUES_OFFSET + count + count * sizeof(UInt_t) >
685 AliError("Too many byte values for this buffer size!");
689 for (UInt_t k = 0; k < count; k ++) {
690 Char_t aByte = GetByte(fMessage + cursor);
691 cursor += sizeof(Char_t);
692 UInt_t timeStamp = GetUInt(fMessage + cursor);
693 cursor += sizeof(UInt_t);
694 fValues->Add(new AliDCSValue(aByte, timeStamp));
696 } else if (fValueType == AliDCSValue::kInt) {
697 if (VALUES_OFFSET + count * sizeof(Int_t) +
698 count * sizeof(UInt_t) > fMessageSize) {
699 AliError("Too many int values for this buffer size!");
703 for (UInt_t k = 0; k < count; k ++) {
704 Int_t aInt = GetInt(fMessage + cursor);
705 cursor += sizeof(Int_t);
706 UInt_t timeStamp = GetUInt(fMessage + cursor);
707 cursor += sizeof(UInt_t);
708 fValues->Add(new AliDCSValue(aInt, timeStamp));
711 } else if (fValueType == AliDCSValue::kUInt) {
712 if (VALUES_OFFSET + count * sizeof(UInt_t) +
713 count * sizeof(UInt_t) > fMessageSize) {
714 AliError("Too many uint values for this buffer size!");
718 for (UInt_t k = 0; k < count; k ++) {
719 UInt_t aUInt = GetUInt(fMessage + cursor);
720 cursor += sizeof(UInt_t);
721 UInt_t timeStamp = GetUInt(fMessage + cursor);
722 cursor += sizeof(UInt_t);
723 fValues->Add(new AliDCSValue(aUInt, timeStamp));
725 } else if (fValueType == AliDCSValue::kFloat) {
726 if (VALUES_OFFSET + count * sizeof(Float_t) +
727 count * sizeof(UInt_t) > fMessageSize) {
728 AliError("Too many float values for this buffer size!");
732 for (UInt_t k = 0; k < count; k ++) {
733 Float_t aFloat = GetFloat(fMessage + cursor);
734 cursor += sizeof(Float_t);
735 UInt_t timeStamp = GetUInt(fMessage + cursor);
736 cursor += sizeof(UInt_t);
737 fValues->Add(new AliDCSValue(aFloat, timeStamp));
741 AliError("Unknown or invalid value type!");
748 //______________________________________________________________________
749 void AliDCSMessage::LoadErrorMessage()
751 // load error message
753 if (fMessageSize < ERROR_STRING_OFFSET) {
754 AliError("Body size is too small for error message!");
758 fErrorCode = (ErrorCode) GetUByte(fMessage + ERROR_CODE_OFFSET);
759 fErrorString = GetString(fMessage + ERROR_STRING_OFFSET,
760 fMessageSize - ERROR_STRING_OFFSET);
762 switch (fErrorCode) {
763 case kUnknownAliasDPName:
764 case kInvalidTimeRange:
765 case kInvalidBufferSize:
766 case kInvalidRequest:
767 case kUnsupportedType:
772 AliError("Invalid error code!");
776 //______________________________________________________________________
777 void AliDCSMessage::LoadMultiRequestMessage()
779 // load multi request message
781 if (fMessageSize - HEADER_SIZE < REQUEST_STRINGS_OFFSET) {
782 AliError("Body size is too small for multi request message!");
786 fRequestType = (RequestType) GetUByte(fMessage + REQUEST_TYPE_OFFSET);
788 fStartTime = GetUInt(fMessage + START_TIME_OFFSET);
789 fEndTime = GetUInt(fMessage + END_TIME_OFFSET);
791 switch (fRequestType) {
797 AliError("Invalid request type!");
801 UInt_t cursor = REQUEST_STRINGS_OFFSET;
803 while ((cursor < fMessageSize)) {
804 UChar_t strSize = GetUByte(fMessage + cursor);
807 if (cursor + strSize > fMessageSize) {
808 AliError("Invalid multi request message!");
812 TObjString* anObjString = new TObjString(
813 GetString(fMessage + cursor, strSize));
814 fRequestStrings.AddLast(anObjString);
819 fType = kMultiRequest;
822 //______________________________________________________________________
823 void AliDCSMessage::LoadNextMessage()
830 //______________________________________________________________________
831 void AliDCSMessage::StoreToBuffer()
833 // Creates an underlying message buffer which can be sent to the socket.
839 StoreRequestMessage();
845 StoreResultSetMessage();
851 StoreMultiRequestMessage();
857 AliError("Can't store to buffer invalid message!");
861 //______________________________________________________________________
862 void AliDCSMessage::LoadFromBuffer()
864 // Reads the underlying message buffer and if it's valid message
865 // creates the corresponding message.
866 // If not set the message type kInvalid.
867 // This buffer is read from the socket.
872 AliError("Message buffer is empty! Can't load it.");
876 if (fMessageSize < HEADER_SIZE) {
877 AliError("Invalid message buffer. Too small for the header!");
881 if (!ValidateHeader(fMessage)) {
882 AliError("Invalid message header!");
886 UInt_t bodySize = GetUInt(fMessage + BODY_SIZE_OFFSET);
887 if (bodySize > fMessageSize - HEADER_SIZE) {
888 AliError("Message size is to small for the message body!");
892 fMessageSize = HEADER_SIZE + bodySize;
894 Type aType = (Type) GetUByte(fMessage + TYPE_OFFSET);
898 LoadRequestMessage();
904 LoadResultSetMessage();
910 LoadMultiRequestMessage();
916 AliError("Invalid message type!");
920 //______________________________________________________________________
921 AliDCSMessage::RequestType AliDCSMessage::GetRequestType() const
923 // Request and MultiRequest.
924 // Returns the request type: alias or dp (Data Point)
926 if (!(fType == kRequest || fType == kMultiRequest)) {
927 AliError("Invalid AliDCSMessage type!");
934 //______________________________________________________________________
935 UInt_t AliDCSMessage::GetStartTime() const
937 // Request and MultiRequest.
938 // Returns the request start time. (begining of the time interval).
940 if (!(fType == kRequest || fType == kMultiRequest)) {
941 AliError("Invalid AliDCSMessage type!");
948 //______________________________________________________________________
949 UInt_t AliDCSMessage::GetEndTime() const
951 // Request and MultiRequest.
952 // Returns the request start time. (end of the time interval).
955 if (!(fType == kRequest || fType == kMultiRequest)) {
956 AliError("Invalid AliDCSMessage type!");
963 //______________________________________________________________________
964 TString AliDCSMessage::GetRequestString() const
967 // Returns the request string. (alias or dp)
969 if (fType != kRequest) {
970 AliError("Invalid AliDCSMessage type!");
974 return fRequestString;
977 //______________________________________________________________________
978 Bool_t AliDCSMessage::AddRequestString(const char* request)
981 // Add a request to the request set.
982 // Returns kFALSE in case of invalid request (too long request string).
983 // Otherwise returns kTRUE.
986 if (fType != kMultiRequest) {
987 AliError("Invalid AliDCSMessage type!");
991 if (strlen(request) > 255) {
992 AliError("Alias/dpName is too long! Max size 255.");
996 fRequestStrings.AddLast(new TObjString(request));
1000 //______________________________________________________________________
1001 void AliDCSMessage::ClearRequestStrings()
1004 // Clears the request set.
1006 fRequestStrings.Delete();
1009 //______________________________________________________________________
1010 void AliDCSMessage::GetRequestStrings(TObjArray& result) const
1013 // Returns all request strings in this message.
1014 // result: container where the requests are returned. Collection of
1018 if (fType != kMultiRequest) {
1019 AliError("Invalid AliDCSMessage type!");
1023 TIter iter(&fRequestStrings);
1024 TObjString* anObjString;
1026 while ((anObjString = (TObjString*) iter.Next())) {
1027 result.AddLast(new TObjString(*anObjString));
1031 //______________________________________________________________________
1032 UInt_t AliDCSMessage::GetCount() const
1035 // Returns the total number of values.
1038 if (fType != kCount) {
1039 AliError("Invalid AliDCSMessage type!");
1046 //______________________________________________________________________
1047 AliDCSValue::Type AliDCSMessage::GetValueType() const
1050 // Returns simple value type (see AliDCSValue) for the values
1051 // in this ResultSet.
1053 if (fType != kResultSet) {
1054 AliError("Invalid AliDCSMessage type!");
1055 return AliDCSValue::kInvalid;
1061 //______________________________________________________________________
1062 UInt_t AliDCSMessage::GetValueCount() const
1065 // Returns the count of values in this ResultSet.
1068 if (fType != kResultSet) {
1069 AliError("Invalid AliDCSMessage type!");
1073 return fValues->GetEntriesFast();
1076 //______________________________________________________________________
1077 UInt_t AliDCSMessage::GetValues(TObjArray* result) const
1080 // Returns the number of values got from the message.
1081 // result: used to return the values. Collection of AliDCSValue.
1082 // result must be owner of the AliDCSValues because fVaule is not!
1083 // creator of the result array and used GetValues to fill it must delete object by himself!
1085 // TODO do not copy -> corrected?
1087 if (fType != kResultSet) {
1088 AliError("Invalid AliDCSMessage type!");
1092 TIter iter(fValues);
1093 AliDCSValue* aValue;
1095 while ((aValue = (AliDCSValue*) iter.Next())) {
1096 result->AddLast(aValue);
1099 return fValues->GetEntriesFast();
1103 //______________________________________________________________________
1104 Bool_t AliDCSMessage::AddValue(AliDCSValue& value)
1106 // Adds value to the ResultSet value list.
1107 // Returns kFALSE in case of error.
1108 // Otherwise returns kTRUE;
1110 if (fType != kResultSet) {
1111 AliError("Invalid AliDCSMessage type!");
1115 if (value.GetType() != fValueType) {
1116 AliError(Form("Can't add value with type %d to this message!", value.GetType()));
1120 fValues->Add(&value);
1126 //______________________________________________________________________
1127 void AliDCSMessage::ClearValues()
1129 // clear values array
1131 if(fValues) fValues->Clear();
1134 //______________________________________________________________________
1135 AliDCSMessage::ErrorCode AliDCSMessage::GetErrorCode() const
1139 // Returns the error code which has this error message.
1142 if (fType != kError) {
1143 AliError("Invalid AliDCSMessage type!");
1150 //______________________________________________________________________
1151 TString AliDCSMessage::GetErrorString() const
1155 // Returns the error string (error description) which has this
1159 if (GetType() != kError) {
1160 AliError("Invalid AliDCSMessage type!");
1164 return fErrorString;
1168 //______________________________________________________________________
1169 void AliDCSMessage::Print(Option_t* /*option*/) const
1173 if (AliLog::GetGlobalDebugLevel() < 2) {
1177 TString printString;
1178 printString += "\n <<AliDCSMessage>>\n";
1180 printString += " Size: ";
1181 printString += fMessageSize;
1182 printString += '\n';
1184 printString += " Type: ";
1185 switch (GetType()) {
1187 printString += "Request\n";
1189 printString += " RequestType: ";
1190 if (GetRequestType() == kDPName) {
1191 printString += "DPName";
1193 printString += "Alias";
1195 printString += '\n';
1197 printString += " RequestString: ";
1198 printString += GetRequestString();
1199 printString += '\n';
1200 printString += " StartTime: ";
1201 printString += GetStartTime();
1202 printString += '\n';
1203 printString += " EndTime: ";
1204 printString += GetEndTime();
1205 printString += '\n';
1210 printString += "Count\n";
1211 printString += " Count: ";
1212 printString += GetCount();
1213 printString += '\n';
1218 printString += "ResultSet\n";
1219 printString += " OwnerIndex: ";
1220 printString += fOwnerIndex;
1221 printString += '\n';
1222 printString += " SimpleValueType: ";
1223 printString += fValueType;
1224 printString += '\n';
1225 printString += " ValueCount: ";
1226 printString += GetValueCount();
1227 printString += '\n';
1232 printString += "Error\n";
1233 printString += " ErrorCode: ";
1234 switch (GetErrorCode()) {
1235 case AliDCSMessage::kNoneError:
1236 printString += "NoneError";
1238 case AliDCSMessage::kUnknownAliasDPName:
1239 printString += "UnknownAliasDPName";
1241 case AliDCSMessage::kInvalidTimeRange:
1242 printString += "InvalidTimeRange";
1244 case AliDCSMessage::kInvalidBufferSize:
1245 printString += "InvalidBufferSize";
1247 case AliDCSMessage::kInvalidRequest:
1248 printString += "InvalidRequest";
1250 case AliDCSMessage::kUnsupportedType:
1251 printString += "UnsupportedType";
1253 case AliDCSMessage::kUnknownError:
1254 printString += "UnknownError";
1257 printString += "Invalid";
1260 printString += '\n';
1261 printString += " ErrorString: ";
1262 printString += GetErrorString();
1263 printString += '\n';
1267 case kMultiRequest: {
1268 printString += "MultiRequest\n";
1270 printString += " RequestType: ";
1271 if (GetRequestType() == kDPName) {
1272 printString += "DPName";
1274 printString += "Alias";
1276 printString += '\n';
1278 printString += " RequestStrings: ";
1279 TIter iter(&fRequestStrings);
1280 TObjString* anObjString;
1281 while ((anObjString = (TObjString*) iter.Next())) {
1282 printString += anObjString->String();
1285 printString += '\n';
1287 printString += " StartTime: ";
1288 printString += GetStartTime();
1289 printString += '\n';
1290 printString += " EndTime: ";
1291 printString += GetEndTime();
1292 printString += '\n';
1297 printString += "Next\n";
1302 printString += "Invalid\n";
1305 if (AliLog::GetGlobalDebugLevel() >= 3 && fMessage) {
1306 PrintBuffer(fMessage, fMessageSize, printString);
1309 AliDebug(2, printString);
1312 //______________________________________________________________________
1313 Bool_t AliDCSMessage::SetRawHeader(const char* header)
1316 // Checks if the header buffer represents a valid header message.
1317 // If so it creates a message buffer with the appropriate body size
1318 // and returns true.
1319 // If not returns false.
1320 // header: header buffer
1323 if (!ValidateHeader(header)) {
1324 AliError("Invalid message header!");
1330 UInt_t bodySize = GetUInt(header + BODY_SIZE_OFFSET);
1331 fMessageSize = HEADER_SIZE + bodySize;
1333 fMessage = new char[fMessageSize];
1335 memcpy(fMessage, header, HEADER_SIZE);
1341 //______________________________________________________________________
1342 void AliDCSMessage::DestroyBuffer()
1345 // Destroy the underlying message buffer.
1356 //______________________________________________________________________
1357 void AliDCSMessage::PrintBuffer(const char* buffer, UInt_t size,
1364 while (index < size) {
1365 if (!(index % 16)) {
1366 output += Form("\n %.4x:", index);
1373 output += Form(" %.2x", (UChar_t) buffer[index]);
1375 if (!((index + 1) % 16) || index + 1 == size) {
1376 if (index + 1 == size) {
1377 output.Append(' ',3 * (15 - index % 16));
1378 if (index % 16 < 8) {
1383 output.Append(' ', 2);
1384 for (Int_t k = index % 16; k >= 0; k --) {
1385 Char_t aChar = buffer[index - k];
1386 output += isgraph(aChar) ? aChar: '.';