Switching to retrieval of several DCS DPs at a time (multiDPrequest)
authorjgrosseo <jgrosseo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sat, 9 Jun 2007 13:01:09 +0000 (13:01 +0000)
committerjgrosseo <jgrosseo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sat, 9 Jun 2007 13:01:09 +0000 (13:01 +0000)
SHUTTLE/AliShuttle.cxx
SHUTTLE/AliShuttle.h
SHUTTLE/DCSClient/AliDCSClient.cxx
SHUTTLE/DCSClient/AliDCSClient.h
SHUTTLE/DCSClient/Makefile
SHUTTLE/DCSClient/macros/TestMultialiases.C

index 82f7399..5203264 100644 (file)
 
 /*
 $Log$
+Revision 1.45  2007/05/30 06:35:20  jgrosseo
+Adding functionality to the Shuttle/TestShuttle:
+o) Function to retrieve list of sources from a given system (GetFileSources with id=0)
+o) Function to retrieve list of IDs for a given source      (GetFileIDs)
+These functions are needed for dealing with the tag files that are saved for the GRP preprocessor
+Example code has been added to the TestProcessor in TestShuttle
+
 Revision 1.44  2007/05/11 16:09:32  acolla
 Reference files for ITS, MUON and PHOS are now stored in OfflineDetName/OnlineDetName/run_...
 example: ITS/SPD/100_filename.root
@@ -1483,10 +1490,7 @@ Bool_t AliShuttle::ProcessCurrentDetector()
        if (!CleanReferenceStorage(fCurrentDetector.Data()))
                return kFALSE;
 
-       TMap dcsMap;
-       dcsMap.SetOwner(1);
-
-       Bool_t aDCSError = kFALSE;
+       TMap* dcsMap = 0;
 
        // call preprocessor
        AliPreprocessor* aPreprocessor =
@@ -1517,73 +1521,61 @@ Bool_t AliShuttle::ProcessCurrentDetector()
                TString host(fConfig->GetDCSHost(fCurrentDetector));
                Int_t port = fConfig->GetDCSPort(fCurrentDetector);
 
-               // Retrieval of Aliases
-               TObjString* anAlias = 0;
-               Int_t iAlias = 0;
-               Int_t nTotAliases= ((TMap*)fConfig->GetDCSAliases(fCurrentDetector))->GetEntries();
-               TIter iterAliases(fConfig->GetDCSAliases(fCurrentDetector));
-               while ((anAlias = (TObjString*) iterAliases.Next()))
+               if (fConfig->GetDCSAliases(fCurrentDetector)->GetEntries() > 0)
                {
-                       TObjArray *valueSet = new TObjArray();
-                       valueSet->SetOwner(1);
-
-                       iAlias++;
-                       aDCSError = (GetValueSet(host, port, anAlias->String(), valueSet, kAlias) == 0);
-
-                       if(!aDCSError)
+                       dcsMap = GetValueSet(host, port, fConfig->GetDCSAliases(fCurrentDetector), kAlias);
+                       if (!dcsMap)
                        {
-                               if (((iAlias-1) % 500) == 0 || iAlias == nTotAliases)
-                                       AliInfo(Form("Alias %s (%d of %d) - %d values collected",
-                                                       anAlias->GetName(), iAlias, nTotAliases, valueSet->GetEntriesFast()));
-                               dcsMap.Add(anAlias->Clone(), valueSet);
-                       } else {
-                               Log(fCurrentDetector,
-                                       Form("ProcessCurrentDetector - Error while retrieving alias %s",
-                                               anAlias->GetName()));
+                               Log(fCurrentDetector, "ProcessCurrentDetector - Error while retrieving DCS aliases");
                                UpdateShuttleStatus(AliShuttleStatus::kDCSError);
-                               dcsMap.DeleteAll();
                                return kFALSE;
                        }
                }
-
-               // Retrieval of Data Points
-               TObjString* aDP = 0;
-               Int_t iDP = 0;
-               Int_t nTotDPs= ((TMap*)fConfig->GetDCSDataPoints(fCurrentDetector))->GetEntries();
-               TIter iterDP(fConfig->GetDCSDataPoints(fCurrentDetector));
-               while ((aDP = (TObjString*) iterDP.Next()))
+               
+               if (fConfig->GetDCSDataPoints(fCurrentDetector)->GetEntries() > 0)
                {
-                       TObjArray *valueSet = new TObjArray();
-                       valueSet->SetOwner(1);
-                       if (((iDP-1) % 500) == 0 || iDP == nTotDPs)
-                               AliInfo(Form("Querying DCS archive: DP %s (%d of %d)",
-                                               aDP->GetName(), iDP++, nTotDPs));
-                       aDCSError = (GetValueSet(host, port, aDP->String(), valueSet, kDP) == 0);
-
-                       if(!aDCSError)
+                       TMap* dcsMap2 = GetValueSet(host, port, fConfig->GetDCSDataPoints(fCurrentDetector), kDP);
+                       if (!dcsMap2)
                        {
-                               dcsMap.Add(aDP->Clone(), valueSet);
-                       } else {
-                               Log(fCurrentDetector,
-                                       Form("ProcessCurrentDetector - Error while retrieving data point %s",
-                                               aDP->GetName()));
+                               Log(fCurrentDetector, "ProcessCurrentDetector - Error while retrieving DCS data points");
                                UpdateShuttleStatus(AliShuttleStatus::kDCSError);
-                               dcsMap.DeleteAll();
+                               if (dcsMap)
+                                       delete dcsMap;
                                return kFALSE;
                        }
+                       
+                       if (!dcsMap)
+                       {
+                               dcsMap = dcsMap2;
+                       }
+                       else // merge
+                       {
+                               TIter iter(dcsMap2);
+                               TObjString* key = 0;
+                               while ((key = (TObjString*) iter.Next()))
+                                       dcsMap->Add(key, dcsMap2->GetValue(key->String()));
+                                       
+                               dcsMap2->SetOwner(kFALSE);
+                               delete dcsMap2;
+                       }
                }
+               
+               // still no map?
+               if (!dcsMap)
+                       dcsMap = new TMap;
        }
 
        // DCS Archive DB processing successful. Call Preprocessor!
        UpdateShuttleStatus(AliShuttleStatus::kPPStarted);
 
-       UInt_t returnValue = aPreprocessor->Process(&dcsMap);
+       UInt_t returnValue = aPreprocessor->Process(dcsMap);
 
        if (returnValue > 0) // Preprocessor error!
        {
                Log(fCurrentDetector, Form("Preprocessor failed. Process returned %d.", returnValue));
                UpdateShuttleStatus(AliShuttleStatus::kPPError);
-               dcsMap.DeleteAll();
+               dcsMap->DeleteAll();
+               delete dcsMap;
                return kFALSE;
        }
        
@@ -1592,7 +1584,8 @@ Bool_t AliShuttle::ProcessCurrentDetector()
        Log(fCurrentDetector, Form("ProcessCurrentDetector - %s preprocessor returned success",
                                fCurrentDetector.Data()));
 
-       dcsMap.DeleteAll();
+       dcsMap->DeleteAll();
+       delete dcsMap;
 
        return kTRUE;
 }
@@ -1766,6 +1759,77 @@ Bool_t AliShuttle::GetValueSet(const char* host, Int_t port, const char* entry,
        return kTRUE;
 }
 
+//______________________________________________________________________________________________
+TMap* AliShuttle::GetValueSet(const char* host, Int_t port, const TSeqCollection* entries,
+                             DCSType type)
+{
+       // Retrieve all "entry" data points from the DCS server
+       // host, port: TSocket connection parameters
+       // entries: list of name of the alias or data point
+       // type: kAlias or kDP
+       // returns TMap of values, 0 when failure
+
+       const Int_t kSplit = 100; // maximum number of DPs at a time
+       
+       Int_t totalEntries = entries->GetEntries();
+       
+       TMap* result = 0;
+       
+       for (Int_t index=0; index < totalEntries; index += kSplit)
+       {
+               Int_t endIndex = index + kSplit;
+       
+               AliDCSClient client(host, port, fTimeout, fRetries);
+               if (!client.IsConnected())
+                       return 0;
+
+               TMap* partialResult = 0;
+
+               if (type == kAlias)
+               {
+                       partialResult = client.GetAliasValues(entries, GetCurrentStartTime(), 
+                               GetCurrentEndTime(), index, endIndex);
+               } 
+               else if (type == kDP)
+               {
+                       partialResult = client.GetDPValues(entries, GetCurrentStartTime(), 
+                               GetCurrentEndTime(), index, endIndex);
+               }
+
+               if (partialResult == 0)
+               {
+                       Log(fCurrentDetector.Data(), Form("GetValueSet - Can't get entries (%d...%d)! Reason: %s",
+                               index, endIndex, client.GetServerError().Data()));
+       
+                       if (result)
+                               delete result;
+                               
+                       return 0;
+               }
+               
+               AliInfo(Form("Retrieved entries %d..%d (total %d); E.g. %s has %d values collected",
+                                       index, endIndex, totalEntries, entries->At(index)->GetName(), ((TObjArray*)
+                                       partialResult->GetValue(entries->At(index)->GetName()))->GetEntriesFast()));
+               
+               if (!result)
+               {
+                       result = partialResult;
+               }
+               else
+               {               
+                       TIter iter(partialResult);
+                       TObjString* key = 0;
+                       while ((key = (TObjString*) iter.Next()))
+                               result->Add(key, partialResult->GetValue(key->String()));
+                               
+                       partialResult->SetOwner(kFALSE);
+                       delete partialResult;
+               }
+       
+       }
+
+       return result;
+}
 //______________________________________________________________________________________________
 const char* AliShuttle::GetFile(Int_t system, const char* detector,
                const char* id, const char* source)
index b3ead58..95ba1b5 100644 (file)
@@ -92,6 +92,8 @@ private:
 
        Bool_t GetValueSet(const char* host, Int_t port, const char* alias,
                                TObjArray* result, DCSType type);
+       TMap* GetValueSet(const char* host, Int_t port, const TSeqCollection* entries,
+                             DCSType type);
 
        Bool_t RetrieveFile(UInt_t system, const char* daqFileName, const char* localFileName);
 
index 4327b9b..04c73f7 100644 (file)
 
 /*
 $Log$
+Revision 1.1  2006/11/06 14:22:47  jgrosseo
+major update (Alberto)
+o) reading of run parameters from the logbook
+o) online offline naming conversion
+o) standalone DCSclient package
+
 Revision 1.6  2006/10/02 16:38:39  jgrosseo
 update (alberto):
 fixed memory leaks
@@ -315,51 +321,51 @@ Int_t AliDCSClient::GetValues(AliDCSMessage::RequestType reqType,
 }
 
 //______________________________________________________________________
-Int_t AliDCSClient::GetValues(AliDCSMessage::RequestType reqType,
-       UInt_t startTime, UInt_t endTime, TMap& result)
+TMap* AliDCSClient::GetValues(AliDCSMessage::RequestType reqType,
+       const TSeqCollection* list, UInt_t startTime, UInt_t endTime,
+       Int_t startIndex, Int_t endIndex)
 {
-// get array of DCS values from the DCS server
-// startTime, endTime: start time and end time of the query
-// result: map containing the array of alias names. It will be filled with
-// the values retrieved for each alias
+       // get array of DCS values from the DCS server
+       // list, startTime, endTime: list of dp/alias names, start time and end time of the query
+       //
+       // Result: map containing the array of alias names. It will be filled with
+       // the values retrieved for each alias
 
        if (!IsConnected()) {
                AliError("Not connected!");
-               return AliDCSClient::fgkBadState;
+               return 0;
        }
 
        AliDCSMessage multiRequestMessage;
        multiRequestMessage.CreateMultiRequestMessage(reqType,
                        startTime, endTime);
 
-       TObjArray requests;
-
-       TIter iter(&result);
-       TObjString* aRequest;
-
-       // copy request strings to temporary TObjArray because
-       // TMap doesn't guarantee the order of elements!!!
-       while ((aRequest = (TObjString*) iter.Next())) {
-               requests.AddLast(aRequest);
+       if (endIndex < 0 || endIndex > list->GetEntries())
+               endIndex = list->GetEntries();
+                       
+       for (Int_t i=startIndex; i<endIndex; i++)
+       {
+               TObjString* aRequest = (TObjString*) list->At(i);
                if (!multiRequestMessage.AddRequestString(aRequest->String()))
-               {
-                       return AliDCSClient::fgkInvalidParameter;
-               }
+                       return 0;
        }
-
-       Int_t sResult;
-       if ((sResult = SendMessage(multiRequestMessage)) < 0) {
+       
+       Int_t sResult = 0;
+       if ((sResult = SendMessage(multiRequestMessage)) < 0)
+       {
                 AliError(Form("Can't send request message! Reason: %s",
                         GetErrorString(sResult)));
                 Close();
-                return sResult;
+                return 0;
         }
 
-       result.SetOwner(0);
-       result.Clear();
+       TMap* result = new TMap;
+       result->SetOwner(1);
 
-       TIter reqIter(&requests);
-       while ((aRequest = (TObjString*) reqIter.Next())) {
+       for (Int_t i=startIndex; i<endIndex; i++)
+       {
+               TObjString* aRequest = (TObjString*) list->At(i);
+               
                TObjArray* resultSet = new TObjArray();
                resultSet->SetOwner(1);
 
@@ -368,24 +374,17 @@ Int_t AliDCSClient::GetValues(AliDCSMessage::RequestType reqType,
                                aRequest->String().Data()));
 
                        delete resultSet;
-                       break;
+                       result->DeleteValues();
+                       delete result;
+                       return 0;
                }
 
-               result.Add(aRequest, resultSet);
-       }
-
-       if (sResult < 0) {
-               result.DeleteValues();
-               result.Clear();
-
-               requests.Delete();
-       } else {
-               result.SetOwner(1);
+               result->Add(aRequest, resultSet);
        }
 
        Close();
 
-       return sResult;
+       return result;
 }
        
 //______________________________________________________________________
@@ -502,11 +501,11 @@ Int_t AliDCSClient::GetAliasValues(const char* alias, UInt_t startTime,
 }
 
 //______________________________________________________________________
-Int_t AliDCSClient::GetDPValues(UInt_t startTime, UInt_t endTime, 
-                               TMap& result
+TMap* AliDCSClient::GetDPValues(const TSeqCollection* dpList, UInt_t startTime, UInt_t endTime,
+       Int_t startIndex, Int_t endIndex
 {
        //
-        // For every key of 'result' (which must be TObjString) 
+        // For every entry (fron startIndex to endIndex) in dpList (which must be TObjString) 
        // reads a valueSet. The key represents particular DataPoint to be read.
         // For all DataPoints time interval (startTime - endTime) is used.
         // After the read, the correspoding value for every key is a 
@@ -514,19 +513,18 @@ Int_t AliDCSClient::GetDPValues(UInt_t startTime, UInt_t endTime,
        // case of error.
        // 
         // Returns:
-        //      If >= 0 , the number of values read.
-        //      if < 0, the error code which has occured during the read.
+        //      TMap of results, 0 in case of failure
         //
 
-       return GetValues(AliDCSMessage::kDPName, startTime, endTime, result);
+       return GetValues(AliDCSMessage::kDPName, dpList, startTime, endTime, startIndex, endIndex);
 }
 
 //______________________________________________________________________
-Int_t AliDCSClient::GetAliasValues(UInt_t startTime, UInt_t endTime,
-                               TMap& result)
+TMap* AliDCSClient::GetAliasValues(const TSeqCollection* aliasList, UInt_t startTime, UInt_t endTime,
+       Int_t startIndex, Int_t endIndex)
 {
        //
-        // For every key of 'result' (which must be TObjString) 
+        // For every entry (fron startIndex to endIndex) in dpList (which must be TObjString) 
         // reads a valueSet. The key represents particular Alias to be read.
         // For all aliases time interval (startTime - endTime) is used.
         // After the read, the correspoding value for every key is a 
@@ -534,11 +532,10 @@ Int_t AliDCSClient::GetAliasValues(UInt_t startTime, UInt_t endTime,
         // case of error.
         // 
         // Returns:
-        //      If >= 0 , the number of values read.
-        //      if < 0, the error code which has occured during the read.
+        //      TMap of results, 0 in case of failure
         //
 
-       return GetValues(AliDCSMessage::kAlias, startTime, endTime, result);
+       return GetValues(AliDCSMessage::kAlias, aliasList, startTime, endTime, startIndex, endIndex);
 }
 
 //______________________________________________________________________
index a019171..c2dabdb 100644 (file)
@@ -17,6 +17,7 @@
 class TObjArray;
 class TSocket;
 class TMap;
+class TCollection;
 
 class AliDCSClient: public TObject {
 public:
@@ -43,10 +44,9 @@ public:
         Int_t GetAliasValues(const char* alias, UInt_t startTime,
                                 UInt_t endTime, TObjArray* result);
 
-        Int_t GetDPValues(UInt_t startTime, UInt_t endTime, TMap& result);
-
-        Int_t GetAliasValues(UInt_t startTime, UInt_t endTime, TMap& result);
+        TMap* GetDPValues(const TSeqCollection* dpList, UInt_t startTime, UInt_t endTime, Int_t startIndex = 0, Int_t endIndex = -1);
 
+        TMap* GetAliasValues(const TSeqCollection* aliasList, UInt_t startTime, UInt_t endTime, Int_t startIndex = 0, Int_t endIndex = -1);
 
         AliDCSMessage::ErrorCode GetServerErrorCode() const
                 { return fServerErrorCode;};
@@ -95,8 +95,9 @@ private:
                const char* requestString, UInt_t startTime, UInt_t endTime,
                TObjArray* result);
 
-       Int_t GetValues(AliDCSMessage::RequestType requestType,
-               UInt_t startTime, UInt_t endTime, TMap& result);
+       TMap* GetValues(AliDCSMessage::RequestType requestType,
+               const TSeqCollection* list, UInt_t startTime, UInt_t endTime,
+               Int_t startIndex, Int_t endIndex);
 
        Int_t ReceiveValueSet(TObjArray* result);
 
index 22b8510..ef7a2b7 100644 (file)
@@ -14,7 +14,7 @@ INCLUDES := $(ALICE_ROOT)/include
 LIBDIR := $(shell root-config --libdir)
 SHARED = -shared
 
-CXXFLAGS += -I$(INCLUDES)
+CXXFLAGS += -I$(INCLUDES) -g
 
 OBJS := $(patsubst %.$(SrcSuf),.obj/%.$(ObjSuf),$(SRCS))
 DEPS := $(patsubst .obj/%.$(ObjSuf),.dep/%.d,$(OBJS))
index 5c84188..639dca8 100644 (file)
@@ -1,8 +1,8 @@
-void TestMultiAliases(){
+void TestMultialiases(){
 // Simple test for the multi request query
 
 gSystem->Load("AliDCSClient.so");
- AliDCSClient client("192.168.39.54",4242,1000,5);
+ AliDCSClient client("aldcs053.cern.ch",4242,1000,5);
 
 
 //TObjArray *arr = new TObjArray();
@@ -11,27 +11,27 @@ gSystem->Load("AliDCSClient.so");
 
 
 
-TMap map;
-map.Add(new TObjString("tpc_PT_322.Temperature"), new TObjArray());
-map.Add(new TObjString("tpc_PT_323.Temperature"), new TObjArray());
-map.Add(new TObjString("tpc_PT_324.Temperature"), new TObjArray());
-map.Add(new TObjString("tpc_PT_325.Temperature"), new TObjArray());
-map.Add(new TObjString("tpc_PT_326.Temperature"), new TObjArray());
-map.Add(new TObjString("tpc_PT_327.Temperature"), new TObjArray());
-map.Add(new TObjString("tpc_PT_328.Temperature"), new TObjArray());
-map.Add(new TObjString("tpc_PT_329.Temperature"), new TObjArray());
-map.Add(new TObjString("tpc_PT_330.Temperature"), new TObjArray());
-map.Add(new TObjString("tpc_PT_331.Temperature"), new TObjArray());
+TList list;
+list.Add(new TObjString("tpc_PT_322.Temperature"));
+list.Add(new TObjString("tpc_PT_323.Temperature"));
+list.Add(new TObjString("tpc_PT_324.Temperature"));
+list.Add(new TObjString("tpc_PT_325.Temperature"));
+list.Add(new TObjString("tpc_PT_326.Temperature"));
+list.Add(new TObjString("tpc_PT_327.Temperature"));
+list.Add(new TObjString("tpc_PT_328.Temperature"));
+list.Add(new TObjString("tpc_PT_329.Temperature"));
+list.Add(new TObjString("tpc_PT_330.Temperature"));
+list.Add(new TObjString("tpc_PT_331.Temperature"));
 
-client.GetAliasValues(1180586575, 1180686575, map);
+TMap *map = client.GetAliasValues(&list, 1180586575, 1180686575, 2, 4);
 
-TIter iter(&map);
+TIter iter(map);
 TObjString *objstr=0;
 
 while(objstr = dynamic_cast<TObjString*>(iter.Next())){
 
    cout << objstr->GetName() << endl;
-   TObjArray *arr = map.GetValue(objstr->GetName());   
+   TObjArray *arr = map->GetValue(objstr->GetName());   
 
    cout << "N of values: " << arr->GetEntries() << endl;
    //arr->Print();