LCOV - code coverage report
Current view: top level - HLT/rec - AliHLTReconstructor.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 161 410 39.3 %
Date: 2016-06-14 17:26:59 Functions: 14 21 66.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             : //*                                                                        *
       9             : //* Permission to use, copy, modify and distribute this software and its   *
      10             : //* documentation strictly for non-commercial purposes is hereby granted   *
      11             : //* without fee, provided that the above copyright notice appears in all   *
      12             : //* copies and that both the copyright notice and this permission notice   *
      13             : //* appear in the supporting documentation. The authors make no claims     *
      14             : //* about the suitability of this software for any purpose. It is          *
      15             : //* provided "as is" without express or implied warranty.                  *
      16             : //**************************************************************************
      17             : 
      18             : //  @file   AliHLTReconstructor.cxx
      19             : //  @author Matthias Richter
      20             : //  @date   
      21             : //  @brief  Binding class for HLT reconstruction in AliRoot
      22             : //          Implements bot the interface to run HLT chains embedded into
      23             : //          AliReconstruction and the unpacking and treatment of HLTOUT
      24             : 
      25             : #include <TSystem.h>
      26             : #include <TObjString.h>
      27             : #include "TFile.h"
      28             : #include "TTree.h"
      29             : #include "TObject.h"
      30             : #include "TObjArray.h"
      31             : #include "TClass.h"
      32             : #include "TStreamerInfo.h"
      33             : #include "AliHLTReconstructor.h"
      34             : #include "AliLog.h"
      35             : #include "AliRawReader.h"
      36             : #include "AliESDEvent.h"
      37             : #include "AliHLTSystem.h"
      38             : #include "AliHLTOUTRawReader.h"
      39             : #include "AliHLTOUTDigitReader.h"
      40             : #include "AliHLTEsdManager.h"
      41             : #include "AliHLTPluginBase.h"
      42             : #include "AliHLTMisc.h"
      43             : #include "AliCDBManager.h"
      44             : #include "AliCDBEntry.h"
      45             : #include "AliHLTMessage.h"
      46             : #include "AliCentralTrigger.h"
      47             : #include "AliTriggerConfiguration.h"
      48             : #include "AliTriggerClass.h"
      49             : #include "AliTriggerCluster.h"
      50             : #include "AliDAQ.h"
      51             : #include "AliRunLoader.h"
      52             : #include "AliRunInfo.h"
      53             : 
      54             : class AliCDBEntry;
      55             : 
      56             : /** ROOT macro for the implementation of ROOT specific class methods */
      57           6 : ClassImp(AliHLTReconstructor)
      58             : 
      59             : AliHLTReconstructor::AliHLTReconstructor()
      60           2 :   : AliReconstructor()
      61           2 :   , fpEsdManager(NULL)
      62           6 :   , fpPluginBase(new AliHLTPluginBase)
      63           2 :   , fFlags(0)
      64           2 :   , fProcessingStep(kProcessingStepUndefined)
      65          10 : { 
      66             :   //constructor
      67           4 : }
      68             : 
      69             : AliHLTReconstructor::AliHLTReconstructor(const char* options)
      70           0 :   : AliReconstructor()
      71           0 :   , fpEsdManager(NULL)
      72           0 :   , fpPluginBase(new AliHLTPluginBase)
      73           0 :   , fFlags(0)
      74           0 :   , fProcessingStep(kProcessingStepUndefined)
      75           0 : { 
      76             :   //constructor
      77           0 :   if (options) Init(options);
      78           0 : }
      79             : 
      80             : AliHLTReconstructor::~AliHLTReconstructor()
      81          12 : { 
      82             :   //destructor
      83             : 
      84           2 :   if (fpEsdManager) AliHLTEsdManager::Delete(fpEsdManager);
      85           2 :   fpEsdManager=NULL;
      86             : 
      87           2 :   if (fpPluginBase) {
      88           2 :   AliHLTSystem* pSystem=fpPluginBase->GetInstance();
      89           2 :   if (pSystem) {
      90          18 :     AliDebug(0, Form("terminate HLT system: status %#x", pSystem->GetStatusFlags()));
      91           4 :     if (pSystem->CheckStatus(AliHLTSystem::kStarted)) {
      92             :       // send specific 'event' to execute the stop sequence
      93           0 :       pSystem->Reconstruct(0, NULL, NULL);
      94             :     }
      95             :   }
      96           4 :   delete fpPluginBase;
      97           2 :   }
      98           2 :   fpPluginBase=NULL;
      99             : 
     100           6 : }
     101             : 
     102             : void AliHLTReconstructor::Init(const char* options)
     103             : {
     104             :   // init the reconstructor
     105           0 :   SetOption(options);
     106           0 :   Init();
     107           0 : }
     108             : 
     109             : void AliHLTReconstructor::Init()
     110             : {
     111             :   // init the reconstructor
     112           4 :   if (!fpPluginBase) {
     113           0 :     AliError("internal memory error: can not get AliHLTSystem instance from plugin");
     114           0 :     return;
     115             :   }
     116             : 
     117           2 :   AliHLTSystem* pSystem=fpPluginBase->GetInstance();
     118           2 :   if (!pSystem) {
     119           0 :     AliError("can not create AliHLTSystem object");
     120           0 :     return;
     121             :   }
     122           2 :   if (pSystem->CheckStatus(AliHLTSystem::kError)) {
     123           0 :     AliError("HLT system in error state");
     124           0 :     return;
     125             :   }
     126             : 
     127           2 :   TString esdManagerOptions;
     128             : 
     129             :   // the options scan has been moved to AliHLTSystem, the old code
     130             :   // here is kept to be able to run an older version of the HLT code
     131             :   // with newer AliRoot versions.
     132           4 :   TString option = GetOption();
     133           6 :   TObjArray* pTokens=option.Tokenize(" ");
     134           2 :   option="";
     135           2 :   if (pTokens) {
     136           2 :     int iEntries=pTokens->GetEntries();
     137           4 :     for (int i=0; i<iEntries; i++) {
     138           0 :       TString token=(((TObjString*)pTokens->At(i))->GetString());
     139           0 :       if (token.Contains("loglevel=")) {
     140           0 :         TString param=token.ReplaceAll("loglevel=", "");
     141           0 :         if (param.IsDigit()) {
     142           0 :           pSystem->SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi());
     143           0 :         } else if (param.BeginsWith("0x") &&
     144           0 :                    param.Replace(0,2,"",0).IsHex()) {
     145           0 :           int severity=0;
     146           0 :           sscanf(param.Data(),"%x", &severity);
     147           0 :           pSystem->SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity);
     148           0 :         } else {
     149           0 :           AliWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
     150             :         }
     151           0 :       } else if (token.Contains("alilog=off")) {
     152           0 :         pSystem->SwitchAliLog(0);
     153           0 :       } else if (token.CompareTo("ignore-hltout")==0) {
     154           0 :         fFlags|=kAliHLTReconstructorIgnoreHLTOUT;
     155           0 :         if (option.Length()>0) option+=" ";
     156           0 :         option+=token;
     157           0 :      } else if (token.CompareTo("run-online-config")==0) {
     158           0 :         fFlags|=kAliHLTReconstructorIgnoreHLTOUT;
     159           0 :         if (option.Length()>0) option+=" ";
     160           0 :         option+=token;
     161           0 :       } else if (token.CompareTo("ignore-ctp")==0) {
     162           0 :         fFlags|=kAliHLTReconstructorIgnoreCTP;
     163           0 :       } else if (token.Contains("esdmanager=")) {
     164           0 :         token.ReplaceAll("esdmanager=", "");
     165           0 :         token.ReplaceAll(","," ");
     166           0 :         token.ReplaceAll("'","");
     167           0 :         esdManagerOptions=token;
     168             :       } else {
     169           0 :         if (option.Length()>0) option+=" ";
     170           0 :         option+=token;
     171             :       }
     172           0 :     }
     173           4 :     delete pTokens;
     174           2 :   }
     175             : 
     176           2 :   TString ecsParam;
     177           2 :   TString ctpParam;
     178           4 :   if ((fFlags&kAliHLTReconstructorIgnoreCTP)==0 &&
     179           4 :       BuildCTPTriggerClassString(ctpParam)>=0) {
     180           4 :     if (!ecsParam.IsNull()) ecsParam+=";";
     181           2 :     ecsParam+="CTP_TRIGGER_CLASS=";
     182           2 :     ecsParam+=ctpParam;
     183             :   }
     184             : 
     185           4 :   if (!ecsParam.IsNull()) {
     186           2 :     option+=" ECS=";
     187           2 :     option+=ecsParam;
     188             :   }
     189             : 
     190           4 :   if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
     191           2 :     pSystem->SetDetectorMask(GetRunInfo()->GetDetectorMask());
     192           6 :     if (pSystem->ScanOptions(option.Data())<0) {
     193           4 :       AliError("error setting options for HLT system");
     194           2 :       return;
     195             :     }
     196           0 :     if ((pSystem->Configure())<0) {
     197           0 :       AliError("error during HLT system configuration");
     198           0 :       return;
     199             :     }
     200             :   }
     201             : 
     202           0 :   fpEsdManager=AliHLTEsdManager::New();
     203           0 :   if (fpEsdManager) {
     204           0 :     fpEsdManager->SetOption(esdManagerOptions.Data());
     205             :   }
     206             : 
     207           0 :   AliHLTMisc::Instance().InitStreamerInfos(fgkCalibStreamerInfoEntry);
     208           4 : }
     209             : 
     210             : void AliHLTReconstructor::Terminate()
     211             : {
     212             :   /// overloaded from AliReconstructor: terminate event processing
     213             : 
     214             :   // indicate step 'Terminate'
     215           4 :   SetProcessingStep(kProcessingStepTerminate);
     216             : 
     217           2 :   if (fpPluginBase) {
     218           2 :     AliHLTSystem* pSystem=fpPluginBase->GetInstance();
     219           2 :     if (pSystem) {
     220             :       // 2012-04-02
     221             :       // clean up the HLTOUT instance if still existing, currently FinishEvent
     222             :       // is not called at the end of the event processing and the cleanup
     223             :       // needs to be done here to avoid a warning message. Later it can be
     224             :       // declared a malfunction if the HLTOUT instance is still existing at
     225             :       // this point.
     226           2 :       AliHLTOUT* pHLTOUT=NULL;
     227           2 :       pSystem->InvalidateHLTOUT(&pHLTOUT);
     228           2 :       if (pHLTOUT) {
     229           0 :         pHLTOUT->Reset();
     230           0 :         delete pHLTOUT;
     231           0 :         pHLTOUT=NULL;
     232           0 :       }
     233             : 
     234           8 :       AliDebug(0, Form("terminate HLT system: status %#x", pSystem->GetStatusFlags()));
     235           2 :       if (pSystem->CheckStatus(AliHLTSystem::kStarted)) {
     236             :         // send specific 'event' to execute the stop sequence
     237           0 :         pSystem->Reconstruct(0, NULL, NULL);
     238           0 :       }
     239           2 :     }
     240           2 :   }
     241           2 : }
     242             : 
     243             : void AliHLTReconstructor::FinishEvent()
     244             : {
     245             :   /// overloaded from AliReconstructor: finish current event
     246          16 :   if (!fpPluginBase) return;
     247             : 
     248             :   // indicate step 'FinishEvent'
     249           8 :   SetProcessingStep(kProcessingStepFinishEvent);
     250             : 
     251           8 :   AliInfo("finishing event");
     252           8 :   AliHLTSystem* pSystem=fpPluginBase->GetInstance();
     253           8 :   if (pSystem) {
     254             :     // this is the end of the lifetime of the HLTOUT instance
     255             :     // called after all other modules have been reconstructed
     256           8 :     AliHLTOUT* pHLTOUT=NULL;
     257           8 :     pSystem->InvalidateHLTOUT(&pHLTOUT);
     258           8 :     if (pHLTOUT) {
     259           4 :       pHLTOUT->Reset();
     260           8 :       delete pHLTOUT;
     261           4 :       pHLTOUT=NULL;
     262           4 :     }
     263           8 :   }
     264          16 : }
     265             : 
     266             : const char* AliHLTReconstructor::fgkCalibStreamerInfoEntry="HLT/Calib/StreamerInfo";
     267             : 
     268             : void AliHLTReconstructor::Reconstruct(AliRawReader* rawReader, TTree* /*clustersTree*/) const 
     269             : {
     270             :   // reconstruction of real data without writing of ESD
     271             :   // For each event, HLT reconstruction chains can be executed and
     272             :   // added to the existing HLTOUT data
     273             :   // The HLTOUT data is finally processed in FillESD
     274             : 
     275           8 :   if (!fpPluginBase) {
     276           0 :     AliError("internal memory error: can not get AliHLTSystem instance from plugin");
     277           0 :     return;
     278             :   }
     279             : 
     280             :   int iResult=0;
     281           4 :   AliHLTSystem* pSystem=fpPluginBase->GetInstance();
     282             : 
     283           4 :   if (pSystem) {
     284           4 :     AliHLTOUT* pHLTOUT=NULL;
     285           4 :     pSystem->InvalidateHLTOUT(&pHLTOUT);
     286           4 :     if (pHLTOUT) {
     287             :       // at this stage we always have a new event, regardless state of
     288             :       // fProcessingStep; build the HLTOUT instance from scratch
     289           0 :       pHLTOUT->Reset();
     290           0 :       delete pHLTOUT;
     291           0 :       pHLTOUT=NULL;
     292           0 :     }
     293             :     // same for HLTInput
     294           4 :     AliHLTOUT* pHLTInput=NULL;
     295           4 :     pSystem->InvalidateHLTInput(&pHLTInput);
     296           4 :     if (pHLTInput) {
     297           0 :       pHLTInput->Reset();
     298           0 :       delete pHLTInput;
     299           0 :       pHLTInput=NULL;
     300           0 :     }
     301           4 :     if (pSystem->CheckStatus(AliHLTSystem::kError)) {
     302             :       // this is the highest level where an error can be detected, no error
     303             :       // codes can be returned
     304           0 :       AliFatal("HLT system in error state");
     305           0 :       return;
     306             :     }
     307           4 :     if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
     308           4 :       AliError("HLT system in wrong state");
     309           4 :       return;
     310             :     }
     311             : 
     312             :     // indicate the local reconstruction step
     313           0 :     SetProcessingStep(kProcessingStepLocal);
     314             : 
     315             :     // init the HLTOUT instance for the current event
     316             :     // not nice. Have to query the global run loader to get the current event no.
     317             :     Int_t eventNo=-1;
     318           0 :     AliRunLoader* runloader = AliRunLoader::Instance();
     319           0 :     if (runloader) {
     320           0 :       eventNo=runloader->GetEventNumber();
     321           0 :     }
     322           0 :     if (eventNo>=0) {
     323             :       AliRawReader* input=NULL;
     324           0 :       if ((fFlags&kAliHLTReconstructorIgnoreHLTOUT) == 0 ) {
     325             :         input=rawReader;
     326           0 :       }
     327           0 :       pHLTOUT=new AliHLTOUTRawReader(input, eventNo, fpEsdManager);
     328           0 :       pHLTInput=new AliHLTOUTRawReader(rawReader);
     329           0 :       if (pHLTOUT && pHLTInput) {
     330           0 :         if (pHLTOUT->Init()>=0 && pHLTInput->Init()>=0) {
     331           0 :           pSystem->InitHLTOUT(pHLTOUT);
     332           0 :           pSystem->InitHLTInput(pHLTInput);
     333           0 :         } else {
     334           0 :           AliError("error : initialization of HLTOUT handler failed");
     335             :         }
     336             :       } else {
     337           0 :         AliError("memory allocation failed: can not create AliHLTOUT object");
     338             :       }
     339           0 :     } else {
     340           0 :       AliError("can not get event number");
     341             :     }
     342             : 
     343           0 :     if ((iResult=pSystem->Reconstruct(1, NULL, rawReader))>=0) {
     344             :     }
     345           0 :     pSystem->InvalidateHLTInput(&pHLTInput);
     346           0 :     delete pHLTInput;
     347           4 :    }
     348           4 : }
     349             : 
     350             : void AliHLTReconstructor::FillESD(AliRawReader* rawReader, TTree* /*clustersTree*/, 
     351             :                                   AliESDEvent* esd) const
     352             : {
     353             :   // reconstruct real data and fill ESD
     354           8 :   if (!rawReader || !esd) {
     355           0 :     AliError("missing raw reader or esd object");
     356           0 :     return;
     357             :   }
     358             : 
     359           4 :   if (!fpPluginBase) {
     360           0 :     AliError("internal memory error: can not get AliHLTSystem instance from plugin");
     361           0 :     return;
     362             :   }
     363             : 
     364           4 :   AliHLTSystem* pSystem=fpPluginBase->GetInstance();
     365             : 
     366           4 :   if (pSystem) {
     367           4 :     if (pSystem->CheckStatus(AliHLTSystem::kError)) {
     368             :       // this is the highest level where an error can be detected, no error
     369             :       // codes can be returned
     370           0 :       AliFatal("HLT system in error state");
     371           0 :       return;
     372             :     }
     373           4 :     if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
     374           4 :       AliError("HLT system in wrong state");
     375           4 :       return;
     376             :     }
     377           0 :     pSystem->FillESD(-1, NULL, esd);
     378             : 
     379             :     // the HLTOUT handler has either been created in the AliHLTReconstructor::Reconstruct
     380             :     // step of this event or is created now. In either case the instance is deleted after
     381             :     // the processing
     382           0 :     AliHLTOUT* pHLTOUT=NULL;
     383           0 :     pSystem->InvalidateHLTOUT(&pHLTOUT);
     384           0 :     if (pHLTOUT && fProcessingStep!=kProcessingStepLocal) {
     385             :       // this is a new event, if local reconstruction would have been executed
     386             :       // the HLTOUT instance would have been created for the current event already,
     387             :       // in all other cases one has to create the HLTOUT instance here
     388           0 :       pHLTOUT->Reset();
     389           0 :       delete pHLTOUT;
     390           0 :       pHLTOUT=NULL;
     391           0 :     }
     392           0 :     if (!pHLTOUT) {
     393             :       AliRawReader* input=NULL;
     394           0 :       if ((fFlags&kAliHLTReconstructorIgnoreHLTOUT) == 0 ) {
     395             :         input=rawReader;
     396           0 :       }
     397           0 :       pHLTOUT=new AliHLTOUTRawReader(input, esd->GetEventNumberInFile(), fpEsdManager);
     398           0 :     }
     399             : 
     400             :     // indicate step 'ESD filling'
     401           0 :     SetProcessingStep(kProcessingStepESD);
     402             : 
     403           0 :     if (pHLTOUT) {
     404           0 :       ProcessHLTOUT(pHLTOUT, esd, (pSystem->GetGlobalLoggingLevel()&kHLTLogDebug)!=0);
     405             :       // 2012-03-30: a change in the module sequence of AliReconstruction is soon
     406             :       // going to be applied: HLT reconstruction is executed fully (i.e. both local
     407             :       // reconstruction and FillESD) before all the other modules. In order to make the
     408             :       // HLTOUT data available for other modules it is kept here and released in the method
     409             :       // FinishEvent
     410           0 :       pSystem->InitHLTOUT(pHLTOUT);
     411           0 :     } else {
     412           0 :       AliError("error creating HLTOUT handler");
     413             :     }
     414           0 :   }
     415           4 : }
     416             : 
     417             : void AliHLTReconstructor::Reconstruct(TTree* /*digitsTree*/, TTree* /*clustersTree*/) const
     418             : {
     419             :   // reconstruct simulated data
     420             : 
     421           8 :   AliHLTSystem* pSystem=fpPluginBase->GetInstance();
     422             : 
     423           4 :   if (pSystem) {
     424             :     // create the HLTOUT instance in order to be available for other detector reconstruction
     425             :     // first cleanup any existing instance
     426           4 :     AliHLTOUT* pHLTOUT=NULL;
     427           4 :     pSystem->InvalidateHLTOUT(&pHLTOUT);
     428           4 :     if (pHLTOUT) {
     429             :       // at this stage we always have a new event, regardless state of
     430             :       // fProcessingStep; build the HLTOUT instance from scratch
     431           0 :       pHLTOUT->Reset();
     432           0 :       delete pHLTOUT;
     433           0 :       pHLTOUT=NULL;
     434           0 :     }
     435             : 
     436             :     // indicate the local reconstruction step
     437           4 :     SetProcessingStep(kProcessingStepLocal);
     438             : 
     439             :     // not nice. Have to query the global run loader to get the current event no.
     440             :     // This is related to the missing AliLoader for HLT.
     441             :     // Since AliReconstruction can not provide a digits tree, the file needs to be accessed
     442             :     // explicitely, and the corresponding event needs to be selected.
     443             :     Int_t eventNo=-1;
     444           4 :     AliRunLoader* runloader = AliRunLoader::Instance();
     445           4 :     if (runloader) {
     446           4 :       eventNo=runloader->GetEventNumber();
     447           4 :     }
     448           4 :     if (eventNo>=0) {
     449             :       const char* digitfile=NULL;
     450           4 :       if ((fFlags&kAliHLTReconstructorIgnoreHLTOUT) == 0 ) {
     451             :         digitfile="HLT.Digits.root";
     452             :       }
     453             : 
     454           8 :       pHLTOUT=new AliHLTOUTDigitReader(eventNo, fpEsdManager, digitfile);
     455           4 :       if (pHLTOUT) {
     456           4 :         if (pHLTOUT->Init()>=0) {
     457           4 :           pSystem->InitHLTOUT(pHLTOUT);
     458           4 :         } else {
     459           0 :           AliError("error : initialization of HLTOUT handler failed");
     460             :         }
     461             :       } else {
     462           0 :         AliError("memory allocation failed: can not create AliHLTOUT object");
     463             :       }
     464           4 :     } else {
     465           0 :       AliError("can not get event number");
     466             :     }
     467             : 
     468             :     // all data processing happens in FillESD
     469           4 :   }
     470           4 : }
     471             : 
     472             : void AliHLTReconstructor::FillESD(TTree* /*digitsTree*/, TTree* /*clustersTree*/, AliESDEvent* esd) const
     473             : {
     474             :   // reconstruct simulated data and fill ESD
     475             : 
     476             :   // later this is the place to extract the simulated HLT data
     477             :   // for now it's only an user failure condition as he tries to run HLT reconstruction
     478             :   // on simulated data 
     479           8 :   TString option = GetOption();
     480           8 :   if (!option.IsNull() && 
     481           0 :       (option.Contains("config=") || option.Contains("chains="))) {
     482           0 :     AliWarning(Form("You are trying to run a custom HLT chain on digits data.\n\n"
     483             :                     "HLT reconstruction can be run embedded into AliReconstruction from\n"
     484             :                     "raw data (real or simulated)). Reconstruction of digit data takes\n"
     485             :                     "place in AliSimulation, appropriate input conversion is needed to\n"
     486             :                     "feed data from the detector digits into the HLT chain.\n"
     487             :                     "Consider running embedded into AliSimulation.\n"
     488             :                     "        /***  run macro *****************************************/\n"
     489             :                     "        AliSimulation sim;\n"
     490             :                     "        sim.SetRunHLT(\"%s\");\n"
     491             :                     "        sim.SetRunGeneration(kFALSE);\n"
     492             :                     "        sim.SetMakeDigits(\"\");\n"
     493             :                     "        sim.SetMakeSDigits(\"\");\n"
     494             :                     "        sim.SetMakeDigitsFromHits(\"\");\n"
     495             :                     "        sim.Run();\n"
     496             :                     "        /*********************************************************/\n\n",
     497             :                     option.Data()));
     498             :   }
     499           4 :   if (!fpPluginBase) {
     500           0 :     AliError("internal memory error: can not get AliHLTSystem instance from plugin");
     501           0 :     return;
     502             :   }
     503             : 
     504           4 :   AliHLTSystem* pSystem=fpPluginBase->GetInstance();
     505           4 :   if (pSystem) {
     506           8 :     if (pSystem->CheckStatus(AliHLTSystem::kError)) {
     507             :       // this is the highest level where an error can be detected, no error
     508             :       // codes can be returned
     509           0 :       AliFatal("HLT system in error state");
     510           0 :       return;
     511             :     }
     512           8 :     if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
     513           8 :       AliError("HLT system in wrong state");
     514           4 :       return;
     515             :     }
     516             : 
     517             :     // the HLTOUT handler has either been created in the AliHLTReconstructor::Reconstruct
     518             :     // step of this event or is created now. In either case the instance is deleted after
     519             :     // the processing
     520           0 :     AliHLTOUT* pHLTOUT=NULL;
     521           0 :     pSystem->InvalidateHLTOUT(&pHLTOUT);
     522           0 :     if (pHLTOUT && fProcessingStep!=kProcessingStepLocal) {
     523             :       // this is a new event, if local reconstruction would have been executed
     524             :       // the HLTOUT instance would have been created for the current event already,
     525             :       // in all other cases one has to create the HLTOUT instance here
     526           0 :       pHLTOUT->Reset();
     527           0 :       delete pHLTOUT;
     528           0 :       pHLTOUT=NULL;
     529           0 :     }
     530           0 :     if (!pHLTOUT) {
     531             :       const char* digitfile=NULL;
     532           0 :       if ((fFlags&kAliHLTReconstructorIgnoreHLTOUT) == 0 ) {
     533             :         digitfile="HLT.Digits.root";
     534             :       }
     535           0 :       pHLTOUT=new AliHLTOUTDigitReader(esd->GetEventNumberInFile(), fpEsdManager, digitfile);
     536           0 :     }
     537             : 
     538             :     // indicate step 'ESD filling'
     539           0 :     SetProcessingStep(kProcessingStepESD);
     540             : 
     541           0 :     if (pHLTOUT) {
     542           0 :       ProcessHLTOUT(pHLTOUT, esd, (pSystem->GetGlobalLoggingLevel()&kHLTLogDebug)!=0);
     543             :       // 2012-03-30: a change in the module sequence of AliReconstruction is soon
     544             :       // going to be applied: HLT reconstruction is executed fully (i.e. both local
     545             :       // reconstruction and FillESD) before all the other modules. In order to make the
     546             :       // HLTOUT data available for other modules it is kept here and released in the method
     547             :       // FinishEvent
     548           0 :       pSystem->InitHLTOUT(pHLTOUT);
     549             :     } else {
     550           0 :       AliError("error creating HLTOUT handler");
     551             :     }
     552           0 :   }
     553           4 : }
     554             : 
     555             : void AliHLTReconstructor::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd, bool bVerbose) const
     556             : {
     557             :   // treatment of simulated or real HLTOUT data
     558           0 :   if (!pHLTOUT) return;
     559           0 :   if (!fpPluginBase) {
     560           0 :     AliError("internal memory error: can not get AliHLTSystem instance from plugin");
     561           0 :     return;
     562             :   }
     563             : 
     564           0 :   AliHLTSystem* pSystem=fpPluginBase->GetInstance();
     565           0 :   if (!pSystem) {
     566           0 :     AliError("error getting HLT system instance");
     567           0 :     return;
     568             :   }
     569             : 
     570           0 :   if (pHLTOUT->Init()<0) {
     571           0 :     AliError("error : initialization of HLTOUT handler failed");
     572           0 :     return;
     573             :   }
     574             : 
     575           0 :   if (bVerbose)
     576           0 :     PrintHLTOUTContent(pHLTOUT);
     577             : 
     578           0 :   int blockindex=pHLTOUT->SelectFirstDataBlock(kAliHLTDataTypeStreamerInfo);
     579           0 :   if (blockindex>=0) {
     580           0 :     const AliHLTUInt8_t* pBuffer=NULL;
     581           0 :     AliHLTUInt32_t size=0;
     582           0 :     if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) {
     583           0 :       TObject* pObject=AliHLTMessage::Extract(pBuffer, size);
     584           0 :       if (pObject) {
     585           0 :         TObjArray* pArray=dynamic_cast<TObjArray*>(pObject);
     586           0 :         if (pArray) {
     587           0 :           AliHLTMisc::Instance().InitStreamerInfos(pArray);
     588           0 :         } else {
     589           0 :           AliError(Form("wrong class type of streamer info list: expected TObjArray, but object is of type %s", pObject->Class()->GetName()));
     590             :         }
     591           0 :       } else {
     592           0 :         AliError(Form("failed to extract object from data block of type %s", AliHLTComponent::DataType2Text(kAliHLTDataTypeStreamerInfo).c_str()));
     593             :       }
     594           0 :     } else {
     595           0 :       AliError(Form("failed to get data buffer for block of type %s", AliHLTComponent::DataType2Text(kAliHLTDataTypeStreamerInfo).c_str()));
     596             :     }
     597           0 :   }
     598             : 
     599           0 :   if (pSystem->ProcessHLTOUT(pHLTOUT, esd)<0) {
     600           0 :     AliError("error processing HLTOUT");
     601           0 :   }
     602             : 
     603           0 :   if (bVerbose && esd) {
     604           0 :     AliInfo("HLT ESD content:");
     605           0 :     esd->Print();
     606           0 :   }
     607           0 : }
     608             : 
     609             : void AliHLTReconstructor::ProcessHLTOUT(const char* digitFile, AliESDEvent* pEsd) const
     610             : {
     611             :   // debugging/helper function to examine simulated data
     612           0 :   if (!digitFile) return;
     613             : 
     614             :   // read the number of events
     615           0 :   TFile f(digitFile);
     616           0 :   if (f.IsZombie()) return;
     617           0 :   TTree* pTree=NULL;
     618           0 :   f.GetObject("rawhltout", pTree);
     619           0 :   if (!pTree) {
     620           0 :     AliWarning(Form("can not find tree rawhltout in file %s", digitFile));
     621           0 :     return ;
     622             :   }
     623           0 :   int nofEvents=pTree->GetEntries();
     624           0 :   f.Close();
     625             :   //delete pTree; OF COURSE NOT! its an object in the file
     626           0 :   pTree=NULL;
     627             : 
     628           0 :   for (int event=0; event<nofEvents; event++) {
     629           0 :     AliHLTOUTDigitReader* pHLTOUT=new AliHLTOUTDigitReader(event, fpEsdManager, digitFile);
     630           0 :     if (pHLTOUT) {
     631           0 :       AliInfo(Form("event %d", event));
     632           0 :       ProcessHLTOUT(pHLTOUT, pEsd, true);
     633           0 :       delete pHLTOUT;
     634             :     } else {
     635           0 :       AliError("error creating HLTOUT handler");
     636             :     }
     637             :   }
     638           0 : }
     639             : 
     640             : void AliHLTReconstructor::ProcessHLTOUT(AliRawReader* pRawReader, AliESDEvent* pEsd) const
     641             : {
     642             :   // debugging/helper function to examine simulated or real HLTOUT data
     643           0 :   if (!pRawReader) return;
     644             : 
     645           0 :   pRawReader->RewindEvents();
     646           0 :   for (int event=0; pRawReader->NextEvent(); event++) {
     647           0 :     AliHLTOUTRawReader* pHLTOUT=new AliHLTOUTRawReader(pRawReader, event, fpEsdManager);
     648           0 :     if (pHLTOUT) {
     649           0 :       AliInfo(Form("event %d", event));
     650             :       // the two event fields contain: period - orbit - bunch crossing counter
     651             :       //        id[0]               id[1]
     652             :       // |32                0|32                0|
     653             :       //
     654             :       // |      28 bit    |       24 bit     | 12|
     655             :       //        period          orbit         bcc
     656             :       AliHLTUInt64_t eventId=0;
     657           0 :       const UInt_t* rawreaderEventId=pRawReader->GetEventId();
     658           0 :       if (rawreaderEventId) {
     659           0 :         eventId=rawreaderEventId[0];
     660           0 :         eventId=eventId<<32;
     661           0 :         eventId|=rawreaderEventId[1];
     662           0 :       }
     663           0 :       AliInfo(Form("Event Id from rawreader:\t 0x%016llx", eventId));
     664           0 :       ProcessHLTOUT(pHLTOUT, pEsd, true);
     665           0 :       delete pHLTOUT;
     666           0 :     } else {
     667           0 :       AliError("error creating HLTOUT handler");
     668             :     }
     669             :   }
     670           0 : }
     671             : 
     672             : void AliHLTReconstructor::PrintHLTOUTContent(AliHLTOUT* pHLTOUT) const
     673             : {
     674             :   // print the block specifications of the HLTOUT data blocks
     675           0 :   if (!pHLTOUT) return;
     676             :   int iResult=0;
     677             : 
     678           0 :   AliInfo(Form("Event Id from hltout:\t 0x%016llx", pHLTOUT->EventId()));
     679           0 :   for (iResult=pHLTOUT->SelectFirstDataBlock();
     680           0 :        iResult>=0;
     681           0 :        iResult=pHLTOUT->SelectNextDataBlock()) {
     682           0 :     AliHLTComponentDataType dt=kAliHLTVoidDataType;
     683           0 :     AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
     684           0 :     pHLTOUT->GetDataBlockDescription(dt, spec);
     685           0 :     const AliHLTUInt8_t* pBuffer=NULL;
     686           0 :     AliHLTUInt32_t size=0;
     687           0 :     if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) {
     688           0 :       pHLTOUT->ReleaseDataBuffer(pBuffer);
     689           0 :       pBuffer=NULL; // just a dummy
     690           0 :     }
     691           0 :     AliInfo(Form("   %s  0x%x: size %d", AliHLTComponent::DataType2Text(dt).c_str(), spec, size));
     692           0 :   }
     693           0 : }
     694             : 
     695             : int AliHLTReconstructor::BuildCTPTriggerClassString(TString& triggerclasses) const
     696             : {
     697             :   // build the CTP trigger class string from the OCDB entry of the CTP trigger
     698             :   int iResult=0;
     699             :   
     700           4 :   triggerclasses.Clear();
     701           2 :   AliCentralTrigger* pCTP = new AliCentralTrigger();
     702             :   AliTriggerConfiguration *config=NULL;
     703           2 :   TString configstr("");
     704           6 :   if (pCTP->LoadConfiguration(configstr) && 
     705           2 :       (config = pCTP->GetConfiguration())!=NULL) {
     706           2 :     const TObjArray& classesArray = config->GetClasses();
     707           2 :     int nclasses = classesArray.GetEntriesFast();
     708          78 :     for( int iclass=0; iclass < nclasses; iclass++ ) {
     709             :       AliTriggerClass* trclass = NULL;
     710         216 :       if (classesArray.At(iclass) && (trclass=dynamic_cast<AliTriggerClass*>(classesArray.At(iclass)))!=NULL) {
     711          36 :         TString entry;
     712             :   //trigger classes in the OCDB start at offset 1, not zero we need to subtract 1 when constructing
     713             :   //the ECS param string, this is done also in offline: Bool_t AliReconstruction::GetEventInfo()
     714          36 :         int trindex = trclass->GetIndex()-1;
     715          72 :         entry.Form("%02d:%s:", trindex, trclass->GetName());
     716             :         AliTriggerCluster* cluster=NULL;
     717          36 :         TObject* clusterobj=config->GetClusters().FindObject(trclass->GetCluster());
     718         144 :         if (clusterobj && (cluster=dynamic_cast<AliTriggerCluster*>(clusterobj))!=NULL) {
     719          72 :           TString detectors=cluster->GetDetectorsInCluster();
     720         108 :           TObjArray* pTokens=detectors.Tokenize(" ");
     721          36 :           if (pTokens) {
     722        1620 :             for (int dix=0; dix<pTokens->GetEntriesFast(); dix++) {
     723        2460 :               int id=AliDAQ::DetectorID(((TObjString*)pTokens->At(dix))->GetString());
     724         492 :               if (id>=0) {
     725         984 :                 TString detstr; detstr.Form("%s%02d", dix>0?"-":"", id);
     726         492 :                 entry+=detstr;
     727         492 :               } else {
     728           0 :                 AliError(Form("invalid detector name extracted from trigger cluster: %s (%s)", ((TObjString*)pTokens->At(dix))->GetString().Data(), detectors.Data()));
     729             :                 iResult=-EPROTO;
     730           0 :                 break;
     731             :               }
     732         492 :             }
     733          72 :             delete pTokens;
     734             :           }
     735          36 :         } else {
     736           0 :           AliError(Form("can not find trigger cluster %s in config", trclass->GetCluster()?trclass->GetCluster()->GetName():"NULL"));
     737             :           iResult=-EPROTO;
     738           0 :           break;
     739             :         }
     740         106 :         if (!triggerclasses.IsNull()) triggerclasses+=",";
     741          36 :         triggerclasses+=entry;
     742          72 :       }
     743          36 :     }
     744           2 :   }
     745             : 
     746             :   return iResult;
     747           2 : }

Generated by: LCOV version 1.11