]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/SampleLib/AliHLTAgentSample.cxx
updated SampleLib and tutorial, sample macros added
[u/mrichter/AliRoot.git] / HLT / SampleLib / AliHLTAgentSample.cxx
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   AliHLTAgentSample.cxx
20     @author Matthias Richter
21     @date   
22     @brief  Agent of the libAliHLTSample library
23 */
24
25 #include <cassert>
26 #include "AliHLTAgentSample.h"
27 #include "AliHLTConfiguration.h"
28 #include "TSystem.h"
29
30 // header files of library components
31 #include "AliHLTDummyComponent.h"
32 #include "AliHLTSampleComponent1.h"
33 #include "AliHLTSampleComponent2.h"
34 #include "AliHLTSampleMonitoringComponent.h"
35
36 // header file of the module preprocessor
37 #include "AliHLTSamplePreprocessor.h"
38
39 // raw data handler of HLTOUT data
40 #include "AliHLTOUTHandlerEquId.h"
41
42 /** global instance for agent registration */
43 AliHLTAgentSample gAliHLTAgentSample;
44
45 const char* AliHLTAgentSample::fgkAliHLTAgentSampleData="/tmp/testdata";
46 const char* AliHLTAgentSample::fgkAliHLTAgentSampleOut="/tmp/hltout";
47
48 /** ROOT macro for the implementation of ROOT specific class methods */
49 ClassImp(AliHLTAgentSample)
50
51 AliHLTAgentSample::AliHLTAgentSample()
52   :
53   AliHLTModuleAgent("Sample")
54 {
55   // see header file for class documentation
56   // or
57   // refer to README to build package
58   // or
59   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
60 }
61
62 AliHLTAgentSample::~AliHLTAgentSample()
63 {
64   // see header file for class documentation
65
66   // delete the test data
67   ofstream dump(fgkAliHLTAgentSampleData, ios::in);
68   if (dump.good()) {
69     TString arg("rm -f ");
70     arg+=fgkAliHLTAgentSampleData;
71     gSystem->Exec(arg.Data());
72   }
73 }
74
75 int AliHLTAgentSample::CreateConfigurations(AliHLTConfigurationHandler* handler,
76                                             AliRawReader* /*rawReader*/,
77                                             AliRunLoader* runloader) const
78 {
79   // see header file for class documentation
80
81   // create some test data
82   ofstream dump(fgkAliHLTAgentSampleData, (ios::openmode)0);
83   dump << "This is just some test data for the ALICE HLT analysis example";
84   dump << "---- not copied" << endl;
85   dump.close();
86
87   if (handler) {
88     // the publisher configuration for the test data
89     TString arg("-datatype DUMMYDAT TEST -datafile ");
90     arg+=fgkAliHLTAgentSampleData;
91     HLTDebug(arg.Data());
92     handler->CreateConfiguration("sample-fp1"  , "FilePublisher", NULL , arg.Data());
93
94     // the configuration for the dummy component
95     handler->CreateConfiguration("sample-cp"   , "Dummy"        , "sample-fp1", "output_percentage 80");
96
97     // the writer configuration
98     arg="-datafile "; arg+=fgkAliHLTAgentSampleOut;
99     handler->CreateConfiguration("sample-sink1", "FileWriter"   , "sample-cp" , arg.Data());
100
101     // specific example for the AliRoot simulation (run loader present)
102     if (runloader) {
103     // sample offline source
104     handler->CreateConfiguration("sample-offsrc", "AliLoaderPublisher"   , NULL , "-loader TPCLoader -tree digits -verbose");
105
106     // sample offline sink
107     handler->CreateConfiguration("sample-offsnk", "SampleOfflineDataSink"   , "sample-offsrc" , NULL);
108     }
109   }
110   return 0;
111 }
112
113 const char* AliHLTAgentSample::GetReconstructionChains(AliRawReader* /*rawReader*/,
114                                                        AliRunLoader* runloader) const
115 {
116   // see header file for class documentation
117   if (runloader) return "sample-sink1 sample-offsnk";
118
119   return "sample-sink1";
120 }
121
122 const char* AliHLTAgentSample::GetRequiredComponentLibraries() const
123 {
124   // see header file for class documentation
125   return "libAliHLTUtil.so libAliHLTSample.so";
126 }
127
128 int AliHLTAgentSample::RegisterComponents(AliHLTComponentHandler* pHandler) const
129 {
130   // see header file for class documentation
131   assert(pHandler);
132   if (!pHandler) return -EINVAL;
133   pHandler->AddComponent(new AliHLTDummyComponent);
134   pHandler->AddComponent(new AliHLTSampleComponent1);
135   pHandler->AddComponent(new AliHLTSampleComponent2);
136   pHandler->AddComponent(new AliHLTSampleMonitoringComponent);
137
138   return 0;
139 }
140
141 AliHLTModulePreprocessor* AliHLTAgentSample::GetPreprocessor()
142 {
143   // see header file for class documentation
144   return new AliHLTSamplePreprocessor;
145 }
146
147 int AliHLTAgentSample::GetHandlerDescription(AliHLTComponentDataType dt,
148                                              AliHLTUInt32_t spec,
149                                              AliHLTOUTHandlerDesc& desc) const
150 {
151   // see header file for class documentation
152   if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginSample)) {
153       desc=AliHLTOUTHandlerDesc(kRawReader, dt, GetModuleId());
154       HLTInfo("module %s handles data block type %s specification %d (0x%x)", 
155               GetModuleId(), AliHLTComponent::DataType2Text(dt).c_str(), spec, spec);
156       return 1;
157   }
158   return 0;
159 }
160
161 AliHLTOUTHandler* AliHLTAgentSample::GetOutputHandler(AliHLTComponentDataType dt,
162                                                    AliHLTUInt32_t /*spec*/)
163 {
164   // see header file for class documentation
165   if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginSample)) {
166     // use the default handler
167     return new AliHLTOUTHandlerEquId;
168   }
169   return NULL;
170 }
171
172 int AliHLTAgentSample::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
173 {
174   // see header file for class documentation
175   if (pInstance==NULL) return -EINVAL;
176
177   delete pInstance;
178   return 0;
179 }