LCOV - code coverage report
Current view: top level - HLT/BASE - AliHLTModuleAgent.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 57 104 54.8 %
Date: 2016-06-14 17:26:59 Functions: 11 27 40.7 %

          Line data    Source code
       1             : // $Id$
       2             : 
       3             : /**************************************************************************
       4             :  * This file is property of and copyright by the ALICE HLT Project        * 
       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   AliHLTModuleAgent.cxx
      20             :     @author Matthias Richter
      21             :     @date   
      22             :     @brief  Agent helper class for component libraries.
      23             :     @note   The class is used in Offline (AliRoot) context
      24             : */
      25             : 
      26             : // see header file for class documentation
      27             : // or
      28             : // refer to README to build package
      29             : // or
      30             : // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
      31             : 
      32             : #include "AliHLTModuleAgent.h"
      33             : #include "AliHLTOUTHandler.h"
      34             : 
      35             : /** ROOT macro for the implementation of ROOT specific class methods */
      36         126 : ClassImp(AliHLTModuleAgent)
      37             : 
      38          66 : AliHLTModuleAgent::AliHLTModuleAgent(const char* id)
      39             :   :
      40          33 :   fpNext(NULL),
      41          33 :   fpComponentHandler(NULL),
      42          33 :   fModuleId(id)
      43         132 : {
      44             :   // see header file for class documentation
      45             :   // or
      46             :   // refer to README to build package
      47             :   // or
      48             :   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
      49          33 :   Register(this);
      50          33 : }
      51             : 
      52             : const char* AliHLTModuleAgent::GetQAPlugins() const
      53             : {
      54             :   // default implementation, childs can overload
      55          36 :   return "";
      56             : }
      57             : 
      58         126 : const AliHLTModuleAgent::AliHLTOUTHandlerDesc AliHLTModuleAgent::fgkVoidHandlerDesc;
      59             : 
      60           0 : AliHLTModuleAgent::~AliHLTModuleAgent()
      61          66 : {
      62             :   // see header file for function documentation
      63          33 :   Unregister(this);
      64          33 : }
      65             : 
      66             : const char* AliHLTModuleAgent::GetModuleId() const
      67             : {
      68             :   // see header file for function documentation
      69         100 :   return fModuleId.Data();
      70             : }
      71             : 
      72             : void AliHLTModuleAgent::PrintStatus(const char* agent)
      73             : {
      74             :   // see header file for function documentation
      75           0 :   AliHLTLogging log;
      76           0 :  if (agent) {
      77           0 :    AliHLTModuleAgent* pCurrent=fgAnchor;
      78           0 :    while (pCurrent!=NULL && strcmp(pCurrent->GetName(), agent)!=0) pCurrent=pCurrent->fpNext;
      79           0 :    if (pCurrent) {
      80           0 :      log.Logging(kHLTLogInfo, "AliHLTModuleAgent::PrintStatus", "module agents", 
      81           0 :                  "agent %s available", pCurrent->GetName());
      82             :    } else {
      83           0 :      log.Logging(kHLTLogInfo, "AliHLTModuleAgent::PrintStatus", "module agents", 
      84             :                  "agent %s not found", agent);
      85             :    }
      86           0 :   } else {
      87           0 :    AliHLTModuleAgent* pCurrent=fgAnchor;
      88           0 :    log.Logging(kHLTLogInfo, "AliHLT", "", "-----------------------");
      89           0 :    log.Logging(kHLTLogInfo, "AliHLT", "", "available module agents");
      90           0 :    if (pCurrent==NULL)
      91           0 :      log.Logging(kHLTLogInfo, "AliHLT", "", "   none");
      92           0 :    while (pCurrent) {
      93           0 :      TString msg;
      94           0 :      msg.Form("   %s : %p", pCurrent->GetName(), pCurrent);
      95           0 :      log.Logging(kHLTLogInfo, "AliHLT", "", msg.Data());
      96           0 :      pCurrent=pCurrent->fpNext;
      97           0 :    }
      98           0 :    log.Logging(kHLTLogInfo, "AliHLT", "", "-----------------------");
      99             :   }
     100           0 : }
     101             : 
     102             : UInt_t AliHLTModuleAgent::GetDetectorMask() const
     103             : {
     104             :   /* all detectors */
     105           0 :   return (UInt_t)(-1);
     106             : }
     107             : 
     108             : int AliHLTModuleAgent::CreateConfigurations(AliHLTConfigurationHandler* /*handler*/,
     109             :                                             AliRawReader* /*rawReader*/,
     110             :                                             AliRunLoader* /*runloader*/) const
     111             : {
     112             :   // default method, nothing to be done, child classes can overload
     113           0 :   return 0;
     114             : }
     115             : 
     116             : const char* AliHLTModuleAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
     117             :                                                        AliRunLoader* /*runloader*/) const
     118             : {
     119             :   // default method, nothing to be done, child classes can overload
     120           0 :   return NULL;
     121             : }
     122             : 
     123             : const char* AliHLTModuleAgent::GetRequiredComponentLibraries() const
     124             : {
     125             :   // default method, nothing to be done, child classes can overload
     126           0 :   return NULL;
     127             : }
     128             : 
     129             : int AliHLTModuleAgent::GetHandlerDescription(AliHLTComponentDataType /*dt*/,
     130             :                                              AliHLTUInt32_t /*spec*/,
     131             :                                              AliHLTOUTHandlerDesc& /*desc*/) const
     132             : {
     133             :   // default method, nothing to be done, child classes can overload
     134           0 :   return 0;
     135             : }
     136             : 
     137             : AliHLTOUTHandler* AliHLTModuleAgent::GetOutputHandler(AliHLTComponentDataType /*dt*/,
     138             :                                                       AliHLTUInt32_t /*spec*/)
     139             : {
     140             :   // default method, nothing to be done, child classes can overload
     141           0 :   return NULL;
     142             : }
     143             : 
     144             : int AliHLTModuleAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
     145             : {
     146             :   // default method, simply deletes object
     147           0 :   if (!pInstance) return -EINVAL;
     148           0 :   HLTWarning("potential memory leak due to missing implementation, agent %s must implement function DeleteOutputHandler", GetModuleId());
     149           0 :   return -ENOSYS;
     150           0 : }
     151             : 
     152             : // likely to be moved to AliHLTOUTHandler
     153             : // AliRawStream* AliHLTModuleAgent::GetRawStream(AliHLTComponentDataType /*dt*/,
     154             : //                                            AliHLTUInt32_t /*spec*/,
     155             : //                                            const AliHLTOUT* /*pData*/) const
     156             : // {
     157             : //   // default method, nothing to be done, child classes can overload
     158             : //   return NULL;
     159             : // }
     160             : 
     161             : int AliHLTModuleAgent::ActivateComponentHandler(AliHLTComponentHandler* pHandler)
     162             : {
     163             :   // see header file for function documentation
     164             :   int iResult=0;
     165         234 :   if (pHandler==NULL) {
     166         106 :     if (fpComponentHandler!=NULL) {
     167             :       // reset and think about deregistration
     168          28 :       fpComponentHandler=NULL;
     169             :       //HLTWarning("deregistration of components not yet implemented");
     170          28 :     }
     171          28 :     return 0;
     172             :   }
     173          50 :   if (fpComponentHandler!=NULL) {
     174          22 :     if (pHandler!=fpComponentHandler) {
     175           0 :       HLTError("only one component handler can be activated per agent");
     176           0 :       return -EINVAL;
     177             :     }
     178          22 :     return 0;
     179             :   }
     180          28 :   if ((iResult=RegisterComponents(pHandler))>=0) {
     181          28 :     fpComponentHandler=pHandler;
     182          28 :   }
     183          28 :   return iResult;
     184          78 : }
     185             : 
     186             : int AliHLTModuleAgent::RegisterComponents(AliHLTComponentHandler* /*pHandler*/) const
     187             : {
     188             :   // default method, nothing to be done, child classes can overload
     189           0 :   return 0;
     190             : }
     191             : 
     192             : AliHLTModulePreprocessor* AliHLTModuleAgent::GetPreprocessor()
     193             : {
     194             :   // default method, nothing to be done, child classes can overload
     195           0 :   return NULL;
     196             : }
     197             : 
     198             : AliHLTModuleAgent* AliHLTModuleAgent::fgAnchor=NULL;
     199             : AliHLTModuleAgent* AliHLTModuleAgent::fgCurrent=NULL;
     200             : int AliHLTModuleAgent::fgCount=0;
     201             : 
     202             : AliHLTModuleAgent* AliHLTModuleAgent::GetFirstAgent()
     203             : {
     204             :   // see header file for function documentation
     205          76 :   fgCurrent=fgAnchor;
     206          38 :   return fgAnchor;
     207             : }
     208             : 
     209             : AliHLTModuleAgent* AliHLTModuleAgent::GetNextAgent()
     210             : {
     211             :   // see header file for function documentation
     212         219 :   if (fgCurrent!=NULL) fgCurrent=fgCurrent->fpNext;
     213          73 :   return fgCurrent;
     214             : }
     215             : 
     216             : string AliHLTModuleAgent::GetAgentIds()
     217             : {
     218             :   // see header file for function documentation
     219           0 :   string ids;
     220           0 :   ids.clear();
     221           0 :   for (AliHLTModuleAgent* pCurrent=fgAnchor;
     222           0 :        pCurrent;
     223           0 :        pCurrent=pCurrent->fpNext) {
     224           0 :     if (ids.size()>0) ids+=" ";
     225           0 :     ids+=pCurrent->GetModuleId();
     226             :   }
     227             : 
     228             :   return ids;
     229           0 : }
     230             : 
     231             : int AliHLTModuleAgent::Register(AliHLTModuleAgent* pAgent)
     232             : {
     233             :   // see header file for function documentation
     234          66 :   AliHLTLogging log;
     235          33 :   if (!pAgent) return -EINVAL;
     236             :   // The following check is for extra protection. In some strange cases the agent might
     237             :   // try to register itself more than once. So we need to check for that and prevent it.
     238             :   // Otherwise we create a cycle in our linked list and go into an infinite loop.
     239          33 :   AliHLTModuleAgent* current=fgAnchor;
     240         358 :   while (current!=NULL) {
     241         146 :     if (current == pAgent) return 0;
     242         146 :     current = current->fpNext;
     243             :   }
     244          33 :   if (fgAnchor==NULL) {
     245           4 :     fgAnchor=pAgent;
     246           4 :   } else {
     247          29 :     pAgent->fpNext=fgAnchor;
     248          29 :     fgAnchor=pAgent;
     249             :   }
     250             :   //  log.Logging(kHLTLogDebug, "AliHLTModuleAgent::Register", "", "module agent %p registered", pAgent);
     251          33 :   fgCount++;
     252          33 :   return 0;     
     253          33 : }
     254             : 
     255             : int AliHLTModuleAgent::Unregister(AliHLTModuleAgent* pAgent)
     256             : {
     257             :   // see header file for function documentation
     258          66 :   AliHLTLogging log;
     259          33 :   if (!pAgent) return -EINVAL;
     260          33 :   fgCurrent=NULL;
     261             :   AliHLTModuleAgent* prev=NULL;
     262          33 :   AliHLTModuleAgent* handler=fgAnchor;
     263         132 :   while (handler!=NULL && handler!=pAgent) {
     264             :     prev=handler;
     265           0 :     handler=handler->fpNext;
     266             :   }
     267          33 :   if (handler) {
     268          66 :     if (prev==NULL) {
     269          66 :       fgAnchor=handler->fpNext;
     270          33 :     } else {
     271           0 :       prev->fpNext=handler->fpNext;
     272             :     }
     273             :     //log.Logging(kHLTLogDebug, "AliHLTModuleAgent::Unregister", "", "module agent %p removed", pAgent);
     274          33 :     fgCount--;
     275          33 :   }
     276             :   return 0;
     277          33 : }

Generated by: LCOV version 1.11