Extracting Branch and Revision from Git.
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalPreprocessor.cxx
index a5245a7..4d00a7f 100644 (file)
@@ -23,6 +23,7 @@
 // 
 
 #include "AliHLTGlobalPreprocessor.h"
+#include "AliPreprocessor.h"
 #include "AliHLTMisc.h"
 #include "AliCDBManager.h"
 #include "AliCDBEntry.h"
@@ -70,18 +71,13 @@ void AliHLTGlobalPreprocessor::Initialize(Int_t /*run*/, UInt_t /*startTime*/,
 
 }
 
-
-UInt_t AliHLTGlobalPreprocessor::Process(TMap* dcsAliasMap)
+UInt_t AliHLTGlobalPreprocessor::Process(TMap* /*dcsAliasMap*/)
 {
-  // processes the DCS value map
-  
-  if (!dcsAliasMap) return -EINVAL;
-  if (dcsAliasMap->GetEntries() == 0 ) return 0;
-  
-  TObject* streamerinfo=GetFromMap(dcsAliasMap, fgkStreamerInfoAlias);
-  if (streamerinfo) ProcessStreamerInfo(streamerinfo);
-
-  return 0;
+  Int_t returnValue = ProcessStreamerInfo();
+  if (returnValue < 0) {
+       AliInfo(Form("Processing for %s failed with return code %d", fgkStreamerInfoAlias, returnValue));
+  }
+  return 0; // return success
 }
 
 Int_t AliHLTGlobalPreprocessor::GetModuleNumber()
@@ -93,65 +89,102 @@ Int_t AliHLTGlobalPreprocessor::GetModuleNumber()
   return modulenumber;
 }
 
-int AliHLTGlobalPreprocessor::ProcessStreamerInfo(TObject* object)
-{
-  /// process the StreamerInfo object
-  int iResult=0;
-  if (!object) return -EINVAL;
-
-  TObjArray* streamerinfos=dynamic_cast<TObjArray*>(object);
-  if (!streamerinfos) {
-    AliError(Form("StreamerInfo object has wrong class type %s, expecting TObjArray", object->ClassName()));
-    return -EINVAL;
-  }
-  if (streamerinfos->GetEntriesFast()==0) return 0;
-
-  bool bStore=false;
-  AliCDBEntry* entry = GetFromOCDB(fgkStreamerInfoType, fgkStreamerInfoName);
-  TObjArray* clone=NULL;
-  if (entry && entry->GetObject()) {
-    TObject* cloneObj=entry->GetObject()->Clone();
-    if (cloneObj) clone=dynamic_cast<TObjArray*>(cloneObj);
-    bStore=AliHLTMisc::Instance().MergeStreamerInfo(clone, streamerinfos, 1)>0;
-  } else {
-    TObject* cloneObj=streamerinfos->Clone();
-    if (cloneObj) clone=dynamic_cast<TObjArray*>(cloneObj);
-    bStore=true;
-  }
-
-  if (clone) {
-    AliCDBMetaData* metaData=entry?entry->GetMetaData():NULL;
-    AliCDBMetaData* newMetaData=NULL;
-    if (!metaData) {
-      newMetaData=new AliCDBMetaData;
-      if (newMetaData) {
-       metaData=newMetaData;
-       metaData->SetBeamPeriod(0);
-       metaData->SetResponsible("ALICE HLT Matthias.Richter@cern.ch");
-       metaData->SetComment("Streamer info for HLTOUT payload");
-       //metaData->SetAliRootVersion(ALIROOT_SVN_BRANCH);
-      } else {
-       iResult=-ENOMEM;
-      }
+Int_t AliHLTGlobalPreprocessor::ProcessStreamerInfo() {
+       // get file sources
+       TList* list = GetFileSources(AliPreprocessor::kHLT, fgkStreamerInfoAlias);
+       if ((!list) || (list->GetEntries() == 0)) {
+               AliInfo(Form("No sources for %s found",fgkStreamerInfoAlias));
+               return -1; // no sources
+       }
+       bool bStore = false;
+    TObjArray* clone = NULL;
+       // get existing object or create new one
+    AliCDBEntry* entry = GetFromOCDB(fgkStreamerInfoType, fgkStreamerInfoName);
+    if (entry && entry->GetObject()) {
+       TObject* cloneObj = entry->GetObject()->Clone();
+       if (cloneObj) clone = dynamic_cast<TObjArray*>(cloneObj);
+    } else {
+       clone = new TObjArray();
+       bStore = true;
     }
-    if (bStore) {
-      // store new object with validity infinity (last parameter kTRUE)
-      Store(fgkStreamerInfoType, fgkStreamerInfoName, clone, metaData, GetRun(), kTRUE);
-    } else if (entry) {
-      AliInfo(Form("skipping object which is already up-to-date"));
-      entry->PrintId();
+    if (!clone) {
+       AliError(Form("Could not clone %s, %s", fgkStreamerInfoType, fgkStreamerInfoName));
+       return -2; // no clone
     }
+       // loop over all sources
+       TObjLink *lnk = list->FirstLink();
+       while (lnk) {
+               TObject* obj = lnk->GetObject();
+               TObjString* objStr = dynamic_cast<TObjString*>(obj);
+               if (!objStr) {
+                       AliError(Form("GetFileSources returned TList with no TObjString entry?! %s", obj->ClassName()));
+                       // continue with next list entry
+                       lnk = lnk->Next();
+                       continue;
+               }
+               TString fileName = GetFile(AliPreprocessor::kHLT,fgkStreamerInfoAlias ,objStr->GetString().Data());
+               if (fileName.Length() == 0) {
+                       AliError(Form("Could not get %d-%s-%s", AliPreprocessor::kHLT,fgkStreamerInfoAlias ,objStr->GetString().Data()));
+               }
+               // time to process the file...
+               TFile* f = new TFile(fileName.Data(), "READ");
+               if (!f || !f->IsOpen()) {
+                       AliError(Form("Could not open %s", objStr->GetString().Data()));
+                       return -3;
+               }
+               // loop over objects and create new TObjArrary to feed into merger...
+               TObjArray* streamerinfos = new TObjArray(100);
+               TList* keys = f->GetListOfKeys();
+               TObjLink *lnkFile = keys->FirstLink();
+               while (lnkFile) {
+                       // processing
+                       TObject* streamerobj = f->Get(lnkFile->GetObject()->GetName());
+                       TStreamerInfo* streamer=dynamic_cast<TStreamerInfo*>(streamerobj);
+                       if (!streamer) {
+                               AliError(Form("StreamerInfo object has wrong class type %s, expecting TStreamerInfo", streamerobj->ClassName()));
+                       } else {
+                               streamerinfos->Add(streamer);
+                       }
+                       lnkFile = lnkFile->Next();
+               }
+               if (streamerinfos->GetEntriesFast()!=0) {
+                       bStore |= AliHLTMisc::Instance().MergeStreamerInfo(clone, streamerinfos, 1)>0;
+               }
+               delete streamerinfos;
+               f->Close();
+               delete f;
+               lnk = lnk->Next();
+       }
+       // store if necessary
+       if (bStore) {
+           AliCDBMetaData* metaData=entry?entry->GetMetaData():NULL;
+           AliCDBMetaData* newMetaData=NULL;
+           if (!metaData) {
+               newMetaData=new AliCDBMetaData;
+               if (newMetaData) {
+                       metaData=newMetaData;
+                       metaData->SetBeamPeriod(0);
+                       metaData->SetResponsible("ALICE HLT alice-hlt-core@cern.ch");
+                       metaData->SetComment("Streamer info for HLTOUT payload");
+                       //metaData->SetAliRootVersion(ALIROOT_BRANCH);
+               } else {
+                       return -ENOMEM;
+               }
+           }
+            Store(fgkStreamerInfoType, fgkStreamerInfoName, clone, metaData, 0, kTRUE);
+            if (newMetaData) {
+               delete newMetaData;
+               newMetaData=NULL;
+               metaData=NULL;
+            }
+       } else {
+               if (entry) {
+             AliInfo(Form("StreamerInfo object in OCDB is already up-to-date, skipping new object"));
+             //entry->PrintId();
+               }
+       }
     delete clone;
-    if (newMetaData) delete newMetaData;
-    newMetaData=NULL;
-    metaData=NULL;
-    // TODO
-    // - what to do with variable 'entry', to be deleted?
-
-  } else {
-    AliError("failed to clone streamer info object array");
-    return -ENOMEM;
-  }
-
-  return iResult;
+       return 0;
 }
+
+