]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTOUTHandlerChain.cxx
CMake: removing qpythia from the depedencies
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTOUTHandlerChain.cxx
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   AliHLTOUTHandlerChain.cxx
20 /// @author Matthias Richter
21 /// @date   24.06.2008
22 /// @brief  HLTOUT handler of type kChain.
23 ///
24
25 #include "AliHLTOUTHandlerChain.h"
26 #include "AliHLTOUT.h"
27 #include "AliHLTSystem.h"
28 #include "AliHLTOUTTask.h"
29 #include "TString.h"
30 #include "TObjString.h"
31 #include "TObjArray.h"
32 #include <cassert>
33
34 /** ROOT macro for the implementation of ROOT specific class methods */
35 ClassImp(AliHLTOUTHandlerChain)
36
37 AliHLTOUTHandlerChain::AliHLTOUTHandlerChain(const char* arguments)
38   :
39   fChains(),
40   fOptions(),
41   fpSystem(NULL),
42   fbHaveOutput(false)
43
44   // The handler implements the kChain processing of HLTOUT data.
45   // The ids of the chains to be run during processing are provided
46   // as parameter to the constructor. The AliHLTModuleAgent
47   // can just create a new instance and specify the chains in order
48   // to define the HLTOUT handling of type kChain for a certain data
49   // block. The same instance can be returned for multiple data blocks.
50   // The handler will run once on all data blocks.
51   if (arguments) {
52     TString args=arguments;
53     TObjArray* pTokens=args.Tokenize(" ");
54     if (pTokens) {
55       int iEntries=pTokens->GetEntries();
56       for (int i=0; i<iEntries; i++) {
57         TString token=(((TObjString*)pTokens->At(i))->GetString());
58         if (token.Contains("chains=")) {
59           TString param=token.ReplaceAll("chains=", "");
60           fChains=param.ReplaceAll(",", " ");
61         } else {
62           if (!fOptions.IsNull()) fOptions+=" ";
63           fOptions+=token;
64         }
65       }
66       delete pTokens;
67     }
68   } 
69 }
70
71 AliHLTOUTHandlerChain::~AliHLTOUTHandlerChain()
72 {
73   // destructor
74   if (fpSystem) {
75     // TODO: the EOR is currenttly not send because the reconstruction
76     // chian is not stopped. Trying it here gives an error, there is
77     // some state mismatch in AliHLTSystem. Probably due to the fact,
78     // that the AliHLTSystem::Reconstruct method is not used
79 //     if (!fpSystem->CheckStatus(AliHLTSystem::kError)) {
80 //       // send specific 'event' to execute the stop sequence
81 //       fpSystem->Reconstruct(0, NULL, NULL);
82 //     }
83     delete fpSystem;
84   }
85 }
86
87 int AliHLTOUTHandlerChain::ProcessData(AliHLTOUT* pData)
88 {
89   // data processing function
90   if (!pData) return -EINVAL;
91   int iResult=0;
92
93   if (CheckStatus(kHandlerError)) {
94     HLTWarning("kChain handler '%s' in error state, skipping processing of associated HLTOUT blocks", fChains.Data());
95     return -EPERM;
96   }
97
98   if (!fpSystem && (iResult=InitSystem())<0) {
99     return iResult;
100   }
101
102   if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
103     HLTWarning("kChain handler '%s': system in error state, skipping processing of associated HLTOUT blocks", fChains.Data());
104     return -EACCES;
105   }
106
107   // run one event and do not stop the chain
108   {
109     AliHLTOUT::AliHLTOUTGlobalInstanceGuard g(pData);
110     if ((iResult=fpSystem->Run(1,0))>=0) {
111       // sub-collection is going to be reset from the
112       // parent HLTOUT collection
113       AliHLTOUTTask* pTask=fpSystem->GetHLTOUTTask();
114
115       // either have the task or none of the chains controlled by the chain
116       // handler has output
117       assert(pTask || !fbHaveOutput);
118       if (pTask) {
119       AliHLTOUT* pSubCollection=dynamic_cast<AliHLTOUT*>(pTask);
120       pSubCollection->Init();
121
122       // filter out some data blocks which should not be processed
123       // in the next stage:
124       // 1. we are not interested in the component statistics
125       //    produced in the HLTOUT handler chain
126       for (iResult=pSubCollection->SelectFirstDataBlock();
127            iResult>=0;
128            iResult=pSubCollection->SelectNextDataBlock()) {
129         AliHLTComponentDataType dt=kAliHLTVoidDataType;
130         AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
131         pSubCollection->GetDataBlockDescription(dt, spec);
132         if (dt==kAliHLTDataTypeComponentStatistics) {
133           pSubCollection->MarkDataBlockProcessed();
134         }
135       }
136       pData->AddSubCollection(pSubCollection);
137       } else if (fbHaveOutput) {
138         // this is an error condition since task has been created and should
139         // be available
140         HLTError("can not get instance of HLTOUT task from HLT system %p", fpSystem);
141       }
142     }
143   }
144
145   return iResult;
146 }
147
148 int AliHLTOUTHandlerChain::CreateConfigurations(AliHLTConfigurationHandler* /*handler*/)
149 {
150   //default implementation, nothing to do
151   return 0;
152 }
153
154 int AliHLTOUTHandlerChain::InitSystem()
155 {
156   // initialize the AliHLTSystem instance
157   int iResult=0;
158   if (!fpSystem) {
159     // init AliHLTSystem
160     TString systemName="kChain_"; systemName+=fChains;
161     systemName.ReplaceAll(" ", "_");
162     fpSystem = new AliHLTSystem(GetGlobalLoggingLevel(), systemName);
163     if (fpSystem) {
164       if ((iResult=fpSystem->ScanOptions(fOptions.Data()))>=0) {
165         // load configurations if not specified by external macro
166         if (!fOptions.Contains("config="))
167           iResult=CreateConfigurations(fpSystem->GetConfigurationHandler());
168
169         if (iResult>=0) {
170           iResult=fpSystem->BuildTaskList(fChains.Data());
171         }
172
173         // add AliHLTOUTTask on top of the configuartions in order to
174         // collect the data
175         // remember if task has been created (result>0)
176         fbHaveOutput=((iResult=fpSystem->AddHLTOUTTask(fChains.Data()))>0);
177       }
178     } else {
179       iResult=-ENOMEM;
180     }
181     if (iResult<0) {
182       SetStatusFlag(kHandlerError);
183       if (fpSystem) delete fpSystem; fpSystem=NULL;
184     }
185   }
186   return iResult;
187 }