LCOV - code coverage report
Current view: top level - HLT/BASE/util - AliHLTMonitoringRelay.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 9 133 6.8 %
Date: 2016-06-14 17:26:59 Functions: 6 29 20.7 %

          Line data    Source code
       1             : // $Id$
       2             : 
       3             : //**************************************************************************
       4             : //* This file is property of and copyright by the                          * 
       5             : //* ALICE Experiment at CERN, All rights reserved.                         *
       6             : //*                                                                        *
       7             : //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
       8             : //*                  for The ALICE HLT Project.                            *
       9             : //*                                                                        *
      10             : //* Permission to use, copy, modify and distribute this software and its   *
      11             : //* documentation strictly for non-commercial purposes is hereby granted   *
      12             : //* without fee, provided that the above copyright notice appears in all   *
      13             : //* copies and that both the copyright notice and this permission notice   *
      14             : //* appear in the supporting documentation. The authors make no claims     *
      15             : //* about the suitability of this software for any purpose. It is          *
      16             : //* provided "as is" without express or implied warranty.                  *
      17             : //**************************************************************************
      18             : 
      19             : /// @file   AliHLTMonitoringRelay.cxx
      20             : /// @author Matthias Richter
      21             : /// @date   2009-11-11
      22             : /// @brief  Relay components for monitoring objects.
      23             : ///
      24             : 
      25             : #include <cstdlib>
      26             : #include <cassert>
      27             : #include "AliHLTMonitoringRelay.h"
      28             : #include "AliHLTMessage.h"
      29             : #include "TArrayC.h"
      30             : #include "TObject.h"
      31             : #include "TDatime.h"
      32             : 
      33             : /** ROOT macro for the implementation of ROOT specific class methods */
      34           8 : ClassImp(AliHLTMonitoringRelay)
      35             : 
      36             : AliHLTMonitoringRelay::AliHLTMonitoringRelay()
      37           3 :   : AliHLTProcessor()
      38           3 :   , fItems()
      39           3 :   , fOutputSize()
      40           3 :   , fFlags(0)
      41          15 : {
      42             :   // A relay component for monitoring data objects.
      43             :   // It keeps a copy of the last block of every parent and forwards all
      44             :   // the blocks together. By that, the output of histograms (rarely to
      45             :   // be published but for every event filled.
      46             :   //
      47             :   // Component ID: \b MonitoringRelay
      48             :   // Library: \b libAliHLTUtil.so
      49             :   // Input Data Types: kAliHLTAnyDataType
      50             :   // Output Data Types: according to input blocks
      51           6 : }
      52             : 
      53             : AliHLTMonitoringRelay::~AliHLTMonitoringRelay()
      54          18 : {
      55             :   // destructor
      56           9 : }
      57             : 
      58             : void AliHLTMonitoringRelay::GetInputDataTypes(AliHLTComponentDataTypeList& list)
      59             : {
      60             :   // overloaded from AliHLTComponent
      61           0 :   list.clear();
      62           0 :   list.push_back(kAliHLTAnyDataType);
      63           0 : }
      64             : 
      65             : AliHLTComponentDataType AliHLTMonitoringRelay::GetOutputDataType()
      66             : {
      67             :   // overloaded from AliHLTComponent
      68           0 :   return kAliHLTAnyDataType;
      69             : }
      70             : 
      71             : void AliHLTMonitoringRelay::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
      72             : {
      73             :   // overloaded from AliHLTComponent
      74           0 :   constBase=fOutputSize;
      75           0 :   inputMultiplier=1.0;
      76           0 : }
      77             : 
      78             : int AliHLTMonitoringRelay::DoInit( int argc, const char** argv )
      79             : {
      80             :   // overloaded from AliHLTComponent: initialization
      81             :   int iResult=0;
      82           0 :   fOutputSize=0;
      83             : 
      84           0 :   iResult=ConfigureFromArgumentString(argc, argv);
      85             : 
      86           0 :   return iResult;
      87             : }
      88             : 
      89             : int AliHLTMonitoringRelay::ScanConfigurationArgument(int argc, const char** argv)
      90             : {
      91             :   // overloaded from AliHLTComponent: argument scan
      92           0 :   if (argc<=0) return 0;
      93             :   int i=0;
      94           0 :   TString argument=argv[i];
      95             : 
      96             :   // -verbose
      97           0 :   if (argument.CompareTo("-verbose")==0) {
      98             :     // 
      99           0 :     return 1;
     100           0 :   } else if (argument.CompareTo("-check-object")==0) { // check the objects in the blocks
     101           0 :     SetFlag(kCheckObject);
     102           0 :     return 1;
     103             :   }
     104             : 
     105           0 :   return 0;
     106           0 : }
     107             : 
     108             : int AliHLTMonitoringRelay::DoDeinit()
     109             : {
     110             :   // overloaded from AliHLTComponent: cleanup
     111             :   int iResult=0;
     112           0 :   AliHLTMonitoringItemPList::iterator element=fItems.begin();
     113           0 :   while (element!=fItems.end()) {
     114           0 :     AliHLTMonitoringItem* pItem=*element;
     115           0 :     element=fItems.erase(element);
     116           0 :     if (pItem) {
     117           0 :       delete pItem;
     118             :     }
     119             :   }
     120           0 :   return iResult;
     121           0 : }
     122             : 
     123             : int AliHLTMonitoringRelay::DoEvent(const AliHLTComponentEventData& /*evtData*/,
     124             :                                    AliHLTComponentTriggerData& /*trigData*/)
     125             : {
     126             :   // overloaded from AliHLTProcessor: event processing
     127             :   int iResult=0;
     128           0 :   for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock();
     129           0 :        pBlock!=NULL; 
     130           0 :        pBlock=GetNextInputBlock()) {
     131             :     // ignore private blocks
     132           0 :     if (pBlock->fDataType==(kAliHLTAnyDataType|kAliHLTDataOriginPrivate)) continue;
     133             :     TObject* pObject=NULL;
     134           0 :     if (CheckFlag(kCheckObject)) pObject=AliHLTMessage::Extract(pBlock->fPtr, pBlock->fSize);
     135             :     
     136           0 :     AliHLTMonitoringItem* pItem=FindItem(pBlock, pObject);
     137           0 :     if (pItem) {
     138           0 :       HLTInfo("found block %s 0x%0lx %s %s", DataType2Text(pItem->GetDataType()).c_str(), pItem->GetSpecification(), pObject?pObject->GetName():"", pObject?pObject->GetName():"");
     139           0 :       if (pItem->GetSize()<pBlock->fSize) {
     140             :         // update with the new maximum
     141           0 :         assert(fOutputSize>=pItem->GetSize());
     142           0 :         fOutputSize-=pItem->GetSize();
     143           0 :         fOutputSize+=pBlock->fSize;
     144           0 :       }
     145           0 :       pItem->SetData(pBlock->fPtr, pBlock->fSize);
     146           0 :       HLTInfo("setting item size %d, total size %d", pItem->GetSize(), fOutputSize);
     147             :     } else {
     148           0 :       pItem=new AliHLTMonitoringItem(pBlock, pObject);
     149           0 :       fItems.push_back(pItem);
     150           0 :       fOutputSize+=pBlock->fSize;
     151           0 :       HLTInfo("new item size %d (%d),  %s 0x%0lx %s %s", pItem->GetSize(), fOutputSize, DataType2Text(pItem->GetDataType()).c_str(), pItem->GetSpecification(), pObject?pObject->GetName():"", pObject?pObject->GetName():"");
     152             :     }
     153           0 :     if (pObject) delete pObject;
     154           0 :   }
     155             : 
     156             :   int nofObjects=0;
     157           0 :   for (AliHLTMonitoringItemPList::iterator element=fItems.begin();
     158           0 :        element!=fItems.end(); element++) {
     159           0 :     AliHLTMonitoringItem* pItem=*element;
     160           0 :     if (pItem) {
     161           0 :       HLTInfo("push back item size %d (%d),  %s 0x%0lx", pItem->GetSize(), fOutputSize, DataType2Text(pItem->GetDataType()).c_str(), pItem->GetSpecification());
     162           0 :       PushBack(pItem->GetBuffer(), pItem->GetSize(), pItem->GetDataType(), pItem->GetSpecification());
     163           0 :       if (!pItem->GetObjectName().IsNull()) nofObjects++;
     164             :     }
     165             :   }
     166             :   // info output once every 5 seconds
     167           0 :   const TDatime time;
     168             :   static UInt_t lastTime=0;
     169           0 :   if (time.Get()-lastTime>5) {
     170           0 :       lastTime=time.Get();
     171           0 :       HLTBenchmark("accumulated %d items containing %d TObjects", fItems.size(), nofObjects);
     172             :   }
     173             : 
     174             :   return iResult;
     175           0 : }
     176             : 
     177             : AliHLTMonitoringRelay::AliHLTMonitoringItem* AliHLTMonitoringRelay::FindItem(const AliHLTComponentBlockData* pBlock, const TObject* pObject) const
     178             : {
     179             :   // find an item by data type, specification, name and title
     180           0 :   for (unsigned i=0; i<fItems.size(); i++) {
     181           0 :     AliHLTMonitoringItem* pItem=fItems[i];
     182           0 :     if (pItem &&
     183           0 :         (*pItem)==(*pBlock) &&
     184           0 :         (pObject==NULL || (*pItem)==(*pObject))) {
     185           0 :       return pItem;
     186             :     }
     187           0 :   }
     188           0 :   return NULL;  
     189           0 : }
     190             : 
     191             : AliHLTMonitoringRelay::AliHLTMonitoringItem::AliHLTMonitoringItem()
     192           0 :   : fDt(kAliHLTVoidDataType)
     193           0 :   , fSpecification(kAliHLTVoidDataSpec)
     194           0 :   , fName()
     195           0 :   , fTitle()
     196           0 :   , fData(new TArrayC)
     197           0 :   , fDataSize(0)
     198           0 : {
     199             :   // standard constructor
     200           0 : }
     201             : 
     202             : AliHLTMonitoringRelay::AliHLTMonitoringItem::AliHLTMonitoringItem(const AliHLTComponentBlockData* pBlock, const TObject* pObject)
     203           0 :   : fDt(kAliHLTVoidDataType)
     204           0 :   , fSpecification(kAliHLTVoidDataSpec)
     205           0 :   , fName()
     206           0 :   , fTitle()
     207           0 :   , fData(new TArrayC)
     208           0 :   , fDataSize(0)
     209           0 : {
     210             :   // constructor
     211           0 :   if (pBlock) {
     212           0 :     fDt=pBlock->fDataType;
     213           0 :     fSpecification=pBlock->fSpecification;
     214           0 :     if (fData) {
     215           0 :       fData->Set(pBlock->fSize, reinterpret_cast<const Char_t*>(pBlock->fPtr));
     216           0 :       fDataSize=pBlock->fSize;
     217           0 :     }
     218             :   }
     219           0 :   if (pObject) {
     220           0 :     fName=pObject->GetName();
     221           0 :     fTitle=pObject->GetTitle();
     222             :   }
     223           0 : }
     224             : 
     225             : AliHLTMonitoringRelay::AliHLTMonitoringItem::~AliHLTMonitoringItem()
     226           0 : {
     227             :   // desstructor
     228           0 :   if (fData) delete fData;
     229           0 : }
     230             : 
     231             : int AliHLTMonitoringRelay::AliHLTMonitoringItem::SetData(void* pBuffer, int size)
     232             : {
     233             :   // copy the data buffer
     234           0 :   if (!fData) {
     235           0 :     fData=new TArrayC(size, reinterpret_cast<const Char_t*>(pBuffer));
     236           0 :   }
     237           0 :   if (!fData) {
     238           0 :     return -ENOMEM;
     239             :   }
     240             : 
     241           0 :   if (fData->GetSize()<size) {
     242           0 :     fData->Set(size, reinterpret_cast<const Char_t*>(pBuffer));
     243           0 :   } else {
     244           0 :     memcpy(fData->GetArray(), pBuffer, size);
     245             :   }
     246             : 
     247           0 :   fDataSize=size;
     248           0 :   return 0;
     249           0 : }
     250             : 
     251             : 
     252             : void* AliHLTMonitoringRelay::AliHLTMonitoringItem::GetBuffer() const
     253             : {
     254             :   // get buffer pointer of the current data
     255           0 :   return fData!=NULL?fData->GetArray():NULL;
     256             : }
     257             : 
     258             : unsigned AliHLTMonitoringRelay::AliHLTMonitoringItem::GetSize() const
     259             : {
     260             :   // get size of the current data
     261           0 :   return fDataSize;
     262             : }
     263             : 
     264             : const AliHLTComponentDataType& AliHLTMonitoringRelay::AliHLTMonitoringItem::GetDataType() const
     265             : {
     266             :   // get data type
     267           0 :   return fDt;
     268             : }
     269             : 
     270             : AliHLTUInt32_t AliHLTMonitoringRelay::AliHLTMonitoringItem::GetSpecification() const
     271             : {
     272             :   // get specification
     273           0 :   return fSpecification;
     274             : }
     275             : 
     276             : bool AliHLTMonitoringRelay::AliHLTMonitoringItem::operator==(const AliHLTComponentBlockData& bd) const
     277             : {
     278             :   // equal to data type and specification
     279           0 :   if (bd.fDataType!=fDt) return false;
     280           0 :   if (bd.fSpecification!=fSpecification) return false;
     281           0 :   return true;
     282           0 : }
     283             : 
     284             : bool AliHLTMonitoringRelay::AliHLTMonitoringItem::operator!=(const AliHLTComponentBlockData& bd) const
     285             : {
     286             :   // not equal to data type and specification
     287           0 :   return not operator==(bd);
     288             : }
     289             : 
     290             : bool AliHLTMonitoringRelay::AliHLTMonitoringItem::operator==(const TObject& object) const
     291             : {
     292             :   // equal to name and title
     293           0 :   if (fName.CompareTo(object.GetName())!=0) return false;
     294           0 :   if (!fTitle.IsNull() && fTitle.CompareTo(object.GetTitle())!=0) return false;
     295           0 :   return true;
     296           0 : }
     297             : 
     298             : bool AliHLTMonitoringRelay::AliHLTMonitoringItem::operator!=(const TObject& object) const
     299             : {
     300             :   // not equal to name and title
     301           0 :   return not operator==(object);
     302             : }

Generated by: LCOV version 1.11