From 01cd4452354359753baace2e9471cf592ef47e34 Mon Sep 17 00:00:00 2001 From: aszostak Date: Tue, 22 Feb 2011 16:04:10 +0000 Subject: [PATCH] Changes required to publish custom data structures over DIM. --- HLT/BASE/AliHLTDimServer.cxx | 65 +++++++++++++++++++++++++++++++----- HLT/BASE/AliHLTDimServer.h | 52 ++++++++++++++++++++++++++++- 2 files changed, 108 insertions(+), 9 deletions(-) diff --git a/HLT/BASE/AliHLTDimServer.cxx b/HLT/BASE/AliHLTDimServer.cxx index 915983d348a..87b20beeb62 100644 --- a/HLT/BASE/AliHLTDimServer.cxx +++ b/HLT/BASE/AliHLTDimServer.cxx @@ -153,7 +153,10 @@ AliHLTDimServer::AliHLTDimInterface* AliHLTDimServer::Interface() if (!fgpInterface) { fgpInterface=new AliHLTDimInterface; if (fgpInterface) { - fgpInterface->Init(); + if (fgpInterface->Init() != 0) { + delete fgpInterface; + fgpInterface = NULL; + } } } return fgpInterface; @@ -265,13 +268,11 @@ void* AliHLTDimServer::ServerLoop() void* buffer=pService->GetLocation(); int size=0; switch (pService->GetType()) { + case kDataTypeCustom: case kDataTypeInt: - type="I"; - size=sizeof(int); - break; case kDataTypeFloat: - type="F"; - size=sizeof(float); + type=pService->GetTypeString(); + size=pService->GetDataSize(); break; case kDataTypeString: log.LoggingVarargs(kHLTLogError, "AliHLTDimServer::AliHLTDimService", "ServerLoop" , __FILE__ , __LINE__ , "ignoring dim service %s: type 'string' not yet implemented", name.Data()); @@ -318,6 +319,9 @@ AliHLTDimServer::AliHLTDimService::AliHLTDimService() : TNamed() , fData() , fType(kDataTypeUnknown) + , fTypeString() + , fDataBuffer(NULL) + , fDataSize(0) , fId(-1) { // see header file for class documentation @@ -327,13 +331,27 @@ AliHLTDimServer::AliHLTDimService::AliHLTDimService(enum AliHLTDimServiceDataTyp : TNamed(servicename, "AliHLTDimService") , fData() , fType(type) + , fTypeString() + , fDataBuffer(NULL) + , fDataSize(0) , fId(-1) { // see header file for class documentation AliHLTLogging log; switch (fType) { - case kDataTypeInt: break; - case kDataTypeFloat: break; + case kDataTypeCustom: + log.LoggingVarargs(kHLTLogError, "AliHLTDimServer", "AliHLTDimService" , __FILE__ , __LINE__ , "cannot use the kDataTypeCustom type with this method"); + break; + case kDataTypeInt: + fTypeString="I"; + fDataBuffer=&fData.iVal; + fDataSize=sizeof(int); + break; + case kDataTypeFloat: + fTypeString="F"; + fDataBuffer=&fData.fVal; + fDataSize=sizeof(float); + break; case kDataTypeString: log.LoggingVarargs(kHLTLogError, "AliHLTDimServer", "AliHLTDimService" , __FILE__ , __LINE__ , "dim service type 'string' not yet implemented"); break; @@ -342,12 +360,43 @@ AliHLTDimServer::AliHLTDimService::AliHLTDimService(enum AliHLTDimServiceDataTyp }; } +AliHLTDimServer::AliHLTDimService::AliHLTDimService(const char* type, void* data, int size, const char* servicename) + : TNamed(servicename, "AliHLTDimService") + , fData() + , fType(kDataTypeCustom) + , fTypeString(type) + , fDataBuffer(data) + , fDataSize(size) + , fId(-1) +{ + // see header file for class documentation +} + +void AliHLTDimServer::AliHLTDimService::Update() +{ + // see header file for class documentation + static bool bWarning=true; + AliHLTLogging log; + switch (fType) { + case kDataTypeCustom: break; + default: + if (bWarning) log.LoggingVarargs(kHLTLogError, "AliHLTDimServer::AliHLTDimService", "Update" , __FILE__ , __LINE__ , "The service %s must be a custom type (kDataTypeCustom) to use this form of Update", GetName()); + bWarning=false; + }; + + AliHLTDimServer::Interface()->DisUpdateService(fId); +} + void AliHLTDimServer::AliHLTDimService::Update(const AliHLTDimServicePoint_t& sp) { // see header file for class documentation static bool bWarning=true; AliHLTLogging log; switch (fType) { + case kDataTypeCustom: + if (bWarning) log.LoggingVarargs(kHLTLogError, "AliHLTDimServer::AliHLTDimService", "Update" , __FILE__ , __LINE__ , "Should not call this form of Update for custom type (kDataTypeCustom) service %s", GetName()); + bWarning=false; + return; case kDataTypeInt: fData.iVal=sp.iVal; break; case kDataTypeFloat: fData.fVal=sp.fVal; break; case kDataTypeString: diff --git a/HLT/BASE/AliHLTDimServer.h b/HLT/BASE/AliHLTDimServer.h index 525bd09c49e..f6cb2e2684f 100644 --- a/HLT/BASE/AliHLTDimServer.h +++ b/HLT/BASE/AliHLTDimServer.h @@ -34,6 +34,7 @@ public: /// Data type identifiers for services. enum AliHLTDimServiceDataType{ kDataTypeUnknown = 0, /// initializer + kDataTypeCustom, /// Custom format maintained by the user. kDataTypeInt, /// Integer type kDataTypeFloat, /// Float type kDataTypeString, /// String type @@ -54,17 +55,66 @@ public: class AliHLTDimService : public TNamed { public: AliHLTDimService(); + + /** + * Create a new service with a particular predefined type and name. + * \param type The type of the service + * \param servicename The name of the service. + */ AliHLTDimService(AliHLTDimServiceDataType type, const char* servicename); + /** + * Create a new service with a particular custom type. + * \param type The type of the service as a string. + * The format parameter specifies the contents of the structure in the + * form T:N[;T:N]*[;T] where T is the item type: (I)nteger, (C)arachter, + * (L)ong, (S)hort, (F)loat, (D)ouble, X(tra long) and N is the number + * of such items. The type alone at the end means all following items + * are of the same type. Example: "I:3;F:2;C" means 3 Integers, 2 Floats + * and Characters until the end. The format parameter is used for + * communicating between different platforms. + * \param data Points to a buffer maintained by the user which stores the + * data to publish. This buffer must exist as long as the DIM service + * is registered and active. + * \param size The size of the data structure pointed to by data. + * \param servicename The name of the service. + */ + AliHLTDimService(const char* type, void* data, int size, const char* servicename); + + /** + * Updates the DIM data point for custom data structures. + * i.e. This method should be used if the service was created with: + * AliHLTDimService(const char* type, void* data, int size, const char* servicename) + */ + void Update(); + + /** + * Updates the DIM data point. + * This method should be used if the service was created with: + * AliHLTDimService(AliHLTDimServiceDataType type, const char* servicename) + * \param sp The new data point to publish via DIM. + */ void Update(const AliHLTDimServicePoint_t& sp); + AliHLTDimServiceDataType GetType() const {return fType;} - void* GetLocation() {return &fData.iVal;} + const char* GetTypeString() const { return fTypeString.Data(); } + void* GetLocation() {return fDataBuffer;} int GetId() const {return fId;} int SetId(int id) {fId=id;return id;} + void* GetDataBuffer() const { return fDataBuffer; } + int GetDataSize() const { return fDataSize; } private: + + // Do not allow copying of this class + AliHLTDimService(const AliHLTDimService&); + AliHLTDimService& operator = (const AliHLTDimService&); + AliHLTDimServicePoint_t fData; /// the data point AliHLTDimServiceDataType fType; /// type of this service + TString fTypeString; /// The string representing the service type. + void* fDataBuffer; /// Pointer to the data buffer. + int fDataSize; /// The size of the data buffer. int fId; /// id of the service }; -- 2.43.0