]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/util/AliHLTCompStatCollector.cxx
- cleaning up debug output
[u/mrichter/AliRoot.git] / HLT / BASE / util / AliHLTCompStatCollector.cxx
index 288f06b1b1daae96933e5ee1e960b6d8e4173690..456848c57fd06754b7aebbaea6c961fa942594cb 100644 (file)
@@ -23,6 +23,7 @@
 */
 
 #include "AliHLTCompStatCollector.h"
+#include "TFile.h"
 #include "TStopwatch.h"
 #include "TH1F.h"
 #include "TH2F.h"
@@ -63,8 +64,21 @@ AliHLTCompStatCollector::AliHLTCompStatCollector()
   fpCTimeArray(NULL),
   fpInputBlockCountArray(NULL),
   fpTotalInputSizeArray(NULL),
+  fpNormalizedInputSizeArray(NULL),
   fpOutputBlockCountArray(NULL),
   fpTotalOutputSizeArray(NULL)
+  , fpInputOutputRatioArray(NULL)
+  , fpNormalizedInputOutputRatioArray(NULL)
+  , fpComponentCycleTimeArray(NULL)
+  , fpEventTypeArray(NULL)
+  , fpEventCountArray(NULL)
+  , fSizeEstimator(1000)
+  , fMode(kPublishObjects)
+  , fFileName()
+  , fFile(NULL)
+  , fLastTime(time(NULL))
+  , fPeriod(0)
+  , fEventModulo(0)
 {
   // see header file for class documentation
   // or
@@ -103,7 +117,7 @@ int AliHLTCompStatCollector::GetOutputDataTypes(AliHLTComponentDataTypeList& tgt
 void AliHLTCompStatCollector::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
 {
   // see header file for class documentation
-  constBase=1000;
+  constBase=fSizeEstimator;
   inputMultiplier=100.0;
 }
 
@@ -117,18 +131,63 @@ int AliHLTCompStatCollector::DoInit( int argc, const char** argv )
     argument=argv[i];
     if (argument.IsNull()) continue;
 
-    // -array-size
-    if (argument.CompareTo("-array-size")==0) {
+    // -file
+    if (argument.CompareTo("-file")==0) {
       if ((bMissingParam=(++i>=argc))) break;
-      TString param=argv[argc];
+      fFileName=argv[i];
+      fMode|=kSaveObjects;
+
+    // -modulo
+    } else if (argument.CompareTo("-modulo")==0) {
+      if ((bMissingParam=(++i>=argc))) break;
+      TString param=argv[i];
+      if (param.IsDigit()) {
+       fEventModulo=param.Atoi();
+      } else {
+       HLTError("expecting number as parameter for option %s", argument.Data());
+       iResult=-EINVAL;
+      }
+
+    // -period
+    } else if (argument.CompareTo("-period")==0) {
+      if ((bMissingParam=(++i>=argc))) break;
+      TString param=argv[i];
+      if (param.IsDigit()) {
+       fPeriod=param.Atoi();
+      } else {
+       HLTError("expecting number as parameter for option %s", argument.Data());
+       iResult=-EINVAL;
+      }
+
+    // -publish
+    } else if (argument.CompareTo("-publish")==0) {
+      if ((bMissingParam=(++i>=argc))) break;
+      TString param=argv[i];
+      if (param.IsDigit()) {
+       if (param.Atoi()==1) fMode|=kPublishObjects;
+       else if (param.Atoi()==0) fMode&=~kPublishObjects;
+       else {
+         HLTError("expecting 0 or 1 as parameter for option %s", argument.Data());
+         iResult=-EINVAL;
+       }
+      } else {
+       HLTError("expecting number as parameter for option %s", argument.Data());
+       iResult=-EINVAL;
+      }
+
+    // -arraysize
+    } else if (argument.CompareTo("-arraysize")==0) {
+      if ((bMissingParam=(++i>=argc))) break;
+      TString param=argv[i];
       if (param.IsDigit()) {
        fArraySize=param.Atoi();
       } else {
-       HLTError("expecting number as parameter for option '-array-size'");
+       HLTError("expecting number as parameter for option %s", argument.Data());
        iResult=-EINVAL;
       }
 
     } else {
+      HLTError("unknown argument %s", argument.Data());
       iResult=-EINVAL;
     }
   }
@@ -146,8 +205,14 @@ int AliHLTCompStatCollector::DoInit( int argc, const char** argv )
     fpCTimeArray=new UInt_t[fArraySize];
     fpInputBlockCountArray=new UInt_t[fArraySize];
     fpTotalInputSizeArray=new UInt_t[fArraySize];
+    fpNormalizedInputSizeArray=new UInt_t[fArraySize];
     fpOutputBlockCountArray=new UInt_t[fArraySize];
     fpTotalOutputSizeArray=new UInt_t[fArraySize];
+    fpInputOutputRatioArray=new UInt_t[fArraySize];
+    fpNormalizedInputOutputRatioArray=new UInt_t[fArraySize];
+    fpComponentCycleTimeArray=new UInt_t[fArraySize];
+    fpEventTypeArray=new UInt_t[fArraySize];
+    fpEventCountArray=new UInt_t[fArraySize];
 
     fpStatTree=new TTree("CompStat", "HLT component statistics");
     if (fpStatTree) {
@@ -162,10 +227,20 @@ int AliHLTCompStatCollector::DoInit( int argc, const char** argv )
       fpStatTree->Branch("CTime",            fpCTimeArray, "CTime[nofSets]/i");
       fpStatTree->Branch("InputBlockCount",  fpInputBlockCountArray, "InputBlockCount[nofSets]/i");
       fpStatTree->Branch("TotalInputSize",   fpTotalInputSizeArray, "TotalInputSize[nofSets]/i");
+      fpStatTree->Branch("NormalizedInputSize",   fpNormalizedInputSizeArray, "NormalizedInputSize[nofSets]/i");
       fpStatTree->Branch("OutputBlockCount", fpOutputBlockCountArray, "OutputBlockCount[nofSets]/i");
       fpStatTree->Branch("TotalOutputSize",  fpTotalOutputSizeArray, "TotalOutputSize[nofSets]/i");
+      fpStatTree->Branch("InputOutputRatio",  fpInputOutputRatioArray, "InputOutputRatio[nofSets]/i");
+      fpStatTree->Branch("NormalizedInputOutputRatio",  fpNormalizedInputOutputRatioArray, "NormalizedInputOutputRatio[nofSets]/i");
+      fpStatTree->Branch("ComponentCycleTime",fpComponentCycleTimeArray, "ComponentCycleTime[nofSets]/i");
+      fpStatTree->Branch("EventType",fpEventTypeArray, "EventType[nofSets]/i");
+      fpStatTree->Branch("EventCount",fpEventCountArray, "EventCount[nofSets]/i");
     }
   }
+
+  if (!fFileName.empty()) {
+    fFile=new TFile(fFileName.c_str(), "RECREATE");
+  }
   return iResult;
 }
 
@@ -174,6 +249,11 @@ int AliHLTCompStatCollector::DoDeinit( )
   // see header file for class documentation
   ClearAll();
 
+  if (fFile) {
+    fFile->Close();
+    delete fFile;
+    fFile=NULL;
+  }
   return 0;
 }
 
@@ -192,7 +272,7 @@ int AliHLTCompStatCollector::DoEvent( const AliHLTComponentEventData& /*evtData*
 
   bool bEmbeddedTree=false;
   bool bFolderCreated=false;
-  if (bFolderCreated=(fpFolder==NULL)) {
+  if ((bFolderCreated=(fpFolder==NULL))) {
     fpFolder=new TFolder(HLTSTAT_FOLDER_NAME, HLTSTAT_FOLDER_DESC);
     if (bEmbeddedTree) fpFolder->Add(fpStatTree);
   }
@@ -297,8 +377,10 @@ int AliHLTCompStatCollector::DoEvent( const AliHLTComponentEventData& /*evtData*
          if (parentFolder) {
            TIter entries(parentFolder->GetListOfFolders());
            while (TObject* entry=entries.Next())
-             if (entry) HLTDebug("   searching %s in %s: %s", idstr.Data(), (*consumer)->GetName(), entry->GetName());
-
+             if (entry) {
+               Bool_t foo; foo=kTRUE;// only to avoid warning in non-debug compile
+               HLTDebug("   searching %s in %s: %s", idstr.Data(), (*consumer)->GetName(), entry->GetName());
+             }
            TObject* parent=parentFolder->FindObjectAny(idstr);
            if (parent) {
              parentFolder->Add(*publisher);
@@ -324,7 +406,7 @@ int AliHLTCompStatCollector::DoEvent( const AliHLTComponentEventData& /*evtData*
        pBlock && iResult>=0;
        pBlock=GetNextInputBlock(), blockNo++) {
     unsigned int current=fPosition;
-    iResult=FillVariablesSorted(pBlock->fPtr, pBlock->fSize);
+    iResult=FillVariablesSorted(pBlock->fPtr, pBlock->fSize, eventType);
     for (; current<fPosition; current++) {
       fpSpecArray[current]=pBlock->fSpecification;
       fpBlockNoArray[current]=blockNo;
@@ -333,11 +415,10 @@ int AliHLTCompStatCollector::DoEvent( const AliHLTComponentEventData& /*evtData*
     iResult=1;
   }
 
-  if (iResult>0) {
+  int totalOutputSize=0;
+  if (iResult>0 && eventType) {
     fNofSets=fPosition;
     fpStatTree->Fill();
-    if (!bEmbeddedTree)
-      iResult=PushBack(fpStatTree, kAliHLTDataTypeTTree|kAliHLTDataOriginOut);
 
     // init the timer for the next cycle
     if (!fpTimer)  fpTimer=new TStopwatch;
@@ -347,8 +428,32 @@ int AliHLTCompStatCollector::DoEvent( const AliHLTComponentEventData& /*evtData*
     }
   }
 
-  if (iResult>=0 /*&& eventType==gkAliEventTypeEndOfRun*/) {
-    PushBack(fpFolder, kAliHLTDataTypeTObject|kAliHLTDataOriginOut);
+  if (eventType==gkAliEventTypeEndOfRun ||
+      (iResult>=0 && CheckPeriod())) {
+
+    // publish objects to component output
+    if ((fMode&kPublishObjects)!=0) {
+      if (!bEmbeddedTree) {
+       iResult=PushBack(fpStatTree, kAliHLTDataTypeTTree|kAliHLTDataOriginOut);
+       totalOutputSize+=GetLastObjectSize();
+      }
+      iResult=PushBack(fpFolder, kAliHLTDataTypeTObject|kAliHLTDataOriginOut);
+      totalOutputSize+=GetLastObjectSize();
+    }
+
+    // save objects to file
+    if ((fMode&kSaveObjects)!=0 && fFile!=NULL) {
+      HLTDebug("saving objects to file %s", fFileName.c_str());
+      fFile->cd();
+      if (!bEmbeddedTree) {
+       fpStatTree->Write("", TObject::kOverwrite);
+      }
+      fpFolder->Write("", TObject::kOverwrite);
+    }
+  }
+
+  if (iResult==-ENOSPC) {
+    fSizeEstimator+=totalOutputSize;
   }
 
   if (iResult>0) iResult=0;
@@ -369,18 +474,26 @@ void AliHLTCompStatCollector::ResetFillingVariables()
   memset(fpCTimeArray, 0, sizeof(UInt_t)*fArraySize);
   memset(fpInputBlockCountArray, 0, sizeof(UInt_t)*fArraySize);
   memset(fpTotalInputSizeArray, 0, sizeof(UInt_t)*fArraySize);
+  memset(fpNormalizedInputSizeArray, 0, sizeof(UInt_t)*fArraySize);
   memset(fpOutputBlockCountArray, 0, sizeof(UInt_t)*fArraySize);
   memset(fpTotalOutputSizeArray, 0, sizeof(UInt_t)*fArraySize);
+  memset(fpInputOutputRatioArray, 0, sizeof(UInt_t)*fArraySize);
+  memset(fpNormalizedInputOutputRatioArray, 0, sizeof(UInt_t)*fArraySize);
+  memset(fpComponentCycleTimeArray, 0, sizeof(UInt_t)*fArraySize);
+  memset(fpEventTypeArray, 0, sizeof(UInt_t)*fArraySize);
+  memset(fpEventCountArray, 0, sizeof(UInt_t)*fArraySize);
 }
 
-int AliHLTCompStatCollector::FillVariablesSorted(void* ptr, int size)
+int AliHLTCompStatCollector::FillVariablesSorted(void* ptr, int size, AliHLTUInt32_t eventType)
 {
   // see header file for class documentation
   int iResult=0;
   if (size%sizeof(AliHLTComponentStatistics)) {
+    // older or invalid structure
     HLTError("data block is not aligned to the size of the AliHLTComponentStatistics struct");
     return -EINVAL;
   }
+  
   AliHLTComponentStatistics* pStat=reinterpret_cast<AliHLTComponentStatistics*>(ptr);
   UInt_t nofStats=size/sizeof(AliHLTComponentStatistics);
   vector<int> indexList;
@@ -406,8 +519,20 @@ int AliHLTCompStatCollector::FillVariablesSorted(void* ptr, int size)
       fpCTimeArray[i]=pStat[*element].fCTime;
       fpInputBlockCountArray[i]=pStat[*element].fInputBlockCount;
       fpTotalInputSizeArray[i]=pStat[*element].fTotalInputSize;
+      fpNormalizedInputSizeArray[i]=pStat[*element].fTotalInputSize;
+      if (pStat[*element].fInputBlockCount>0) 
+       fpNormalizedInputSizeArray[i]/=pStat[*element].fInputBlockCount;
       fpOutputBlockCountArray[i]=pStat[*element].fOutputBlockCount;
       fpTotalOutputSizeArray[i]=pStat[*element].fTotalOutputSize;
+      if (pStat[*element].fTotalOutputSize>0)
+       fpInputOutputRatioArray[i]=pStat[*element].fTotalInputSize/pStat[*element].fTotalOutputSize;
+      if (pStat[*element].fInputBlockCount>0)
+       fpNormalizedInputOutputRatioArray[i]=fpInputOutputRatioArray[i]*pStat[*element].fOutputBlockCount/pStat[*element].fInputBlockCount;
+      fpComponentCycleTimeArray[i]=pStat[*element].fComponentCycleTime;
+      fpEventTypeArray[i]=eventType;
+      fpEventCountArray[i]=GetEventCount();
+    } else {
+      // TODO: dynamically grow arrays with placement new
     }
   }
 
@@ -435,8 +560,14 @@ void AliHLTCompStatCollector::ClearAll()
   if (fpCTimeArray) delete fpCTimeArray; fpCTimeArray=NULL;
   if (fpInputBlockCountArray) delete fpInputBlockCountArray; fpInputBlockCountArray=NULL;
   if (fpTotalInputSizeArray) delete fpTotalInputSizeArray; fpTotalInputSizeArray=NULL;
+  if (fpNormalizedInputSizeArray) delete fpNormalizedInputSizeArray; fpNormalizedInputSizeArray=NULL;
   if (fpOutputBlockCountArray) delete fpOutputBlockCountArray; fpOutputBlockCountArray=NULL;
   if (fpTotalOutputSizeArray) delete fpTotalOutputSizeArray; fpTotalOutputSizeArray=NULL;
+  if (fpInputOutputRatioArray) delete fpInputOutputRatioArray; fpInputOutputRatioArray=NULL;
+  if (fpNormalizedInputOutputRatioArray) delete fpNormalizedInputOutputRatioArray; fpNormalizedInputOutputRatioArray=NULL;
+  if (fpComponentCycleTimeArray) delete fpComponentCycleTimeArray; fpComponentCycleTimeArray=NULL;
+  if (fpEventTypeArray) delete fpEventTypeArray; fpEventTypeArray=NULL;
+  if (fpEventCountArray) delete fpEventCountArray; fpEventCountArray=NULL;
 }
 
 int AliHLTCompStatCollector::RemoveRecurrence(TFolder* pRoot) const
@@ -476,3 +607,21 @@ int AliHLTCompStatCollector::RemoveRecurrence(TFolder* pRoot) const
   
   return iResult;  
 }
+
+bool AliHLTCompStatCollector::CheckPeriod(bool bUpdate)
+{
+  // see header file for class documentation
+  bool result=true;
+  if (fEventModulo>0) {
+    if ((result=((GetEventCount()+1)%fEventModulo)==0)) {
+      return true;
+    }
+  }
+  if (fPeriod>0) {
+    if ((result=((difftime(time(NULL), fLastTime)>(double)fPeriod))) &&
+       bUpdate) {
+      fLastTime=time(NULL);
+    }
+  }
+  return result;
+}