]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/SampleLib/AliHLTAgentSample.cxx
Update z position of ADA (Z=1699.7)
[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 "TSystem.h"
28
29 // header files of library components
30 #include "AliHLTDummyComponent.h"
31 #include "AliHLTSampleComponent1.h"
32 #include "AliHLTSampleComponent2.h"
33 #include "AliHLTSampleMonitoringComponent.h"
34 #include "AliHLTSampleCalibrationComponent.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 #include "AliHLTOUTHandlerEsdBranch.h"
42
43 /** global instance for agent registration */
44 AliHLTAgentSample gAliHLTAgentSample;
45
46 const char* AliHLTAgentSample::fgkAliHLTAgentSampleData="/tmp/testdata";
47 const char* AliHLTAgentSample::fgkAliHLTAgentSampleOut="/tmp/hltout";
48
49 /** ROOT macro for the implementation of ROOT specific class methods */
50 ClassImp(AliHLTAgentSample)
51
52 AliHLTAgentSample::AliHLTAgentSample()
53   :
54   AliHLTModuleAgent("Sample")
55 {
56   // see header file for class documentation
57   // or
58   // refer to README to build package
59   // or
60   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
61 }
62
63 AliHLTAgentSample::~AliHLTAgentSample()
64 {
65   // see header file for class documentation
66
67   // delete the test data
68   ofstream dump(fgkAliHLTAgentSampleData, ios::in);
69   if (dump.good()) {
70     TString arg("rm -f ");
71     arg+=fgkAliHLTAgentSampleData;
72     gSystem->Exec(arg.Data());
73   }
74 }
75
76 int AliHLTAgentSample::CreateConfigurations(AliHLTConfigurationHandler* handler,
77                                             AliRawReader* /*rawReader*/,
78                                             AliRunLoader* runloader) const
79 {
80   // see header file for class documentation
81
82   // create some test data
83   ofstream dump(fgkAliHLTAgentSampleData, (ios::openmode)0);
84   dump << "This is just some test data for the ALICE HLT analysis example";
85   dump << "---- not copied" << endl;
86   dump.close();
87
88   if (handler) {
89     // the publisher configuration for the test data
90     TString arg("-datatype DUMMYDAT TEST -datafile ");
91     arg+=fgkAliHLTAgentSampleData;
92     HLTDebug(arg.Data());
93     handler->CreateConfiguration("sample-fp1"  , "FilePublisher", NULL , arg.Data());
94
95     // the configuration for the dummy component
96     handler->CreateConfiguration("sample-cp"   , "Dummy"        , "sample-fp1", "output_percentage 80");
97
98     // the writer configuration
99     arg="-datafile "; arg+=fgkAliHLTAgentSampleOut;
100     handler->CreateConfiguration("sample-sink1", "FileWriter"   , "sample-cp" , arg.Data());
101
102     // specific example for the AliRoot simulation (run loader present)
103     if (runloader) {
104     // sample offline source
105     handler->CreateConfiguration("sample-offsrc", "AliLoaderPublisher"   , NULL , "-loader TPCLoader -tree digits -verbose");
106
107     // sample offline sink
108     handler->CreateConfiguration("sample-offsnk", "SampleOfflineDataSink"   , "sample-offsrc" , NULL);
109     }
110   }
111   return 0;
112 }
113
114 const char* AliHLTAgentSample::GetReconstructionChains(AliRawReader* /*rawReader*/,
115                                                        AliRunLoader* runloader) const
116 {
117   // see header file for class documentation
118   if (runloader) return "sample-sink1 sample-offsnk";
119
120   return "sample-sink1";
121 }
122
123 const char* AliHLTAgentSample::GetRequiredComponentLibraries() const
124 {
125   // see header file for class documentation
126   return "libAliHLTUtil.so libAliHLTSample.so";
127 }
128
129 int AliHLTAgentSample::RegisterComponents(AliHLTComponentHandler* pHandler) const
130 {
131   // see header file for class documentation
132   assert(pHandler);
133   if (!pHandler) return -EINVAL;
134   pHandler->AddComponent(new AliHLTDummyComponent);
135   pHandler->AddComponent(new AliHLTSampleComponent1);
136   pHandler->AddComponent(new AliHLTSampleComponent2);
137   pHandler->AddComponent(new AliHLTSampleMonitoringComponent);
138   pHandler->AddComponent(new AliHLTSampleCalibrationComponent);
139
140   return 0;
141 }
142
143 AliHLTModulePreprocessor* AliHLTAgentSample::GetPreprocessor()
144 {
145   // see header file for class documentation
146   return new AliHLTSamplePreprocessor;
147 }
148
149 int AliHLTAgentSample::GetHandlerDescription(AliHLTComponentDataType dt,
150                                              AliHLTUInt32_t spec,
151                                              AliHLTOUTHandlerDesc& desc) const
152 {
153   // see header file for class documentation
154   if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginSample)) {
155       desc=AliHLTOUTHandlerDesc(kRawReader, dt, GetModuleId());
156       HLTInfo("module %s handles data block type %s specification %d (0x%x)", 
157               GetModuleId(), AliHLTComponent::DataType2Text(dt).c_str(), spec, spec);
158       return 1;
159   }
160
161   // add TObject data blocks of type {ROOTTOBJ:SMPL} to ESD
162   if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginSample)) {
163       desc=AliHLTOUTHandlerDesc(kEsd, dt, GetModuleId());
164       HLTInfo("module %s handles data block type %s specification %d (0x%x)", 
165               GetModuleId(), AliHLTComponent::DataType2Text(dt).c_str(), spec, spec);
166       return 1;
167   }
168
169   return 0;
170 }
171
172 AliHLTOUTHandler* AliHLTAgentSample::GetOutputHandler(AliHLTComponentDataType dt,
173                                                    AliHLTUInt32_t /*spec*/)
174 {
175   // see header file for class documentation
176   if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginSample)) {
177     // use the default handler
178     static AliHLTOUTHandlerEquId handler;
179     return &handler;
180   }
181
182   if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginSample)) {
183     // use AliHLTOUTHandlerEsdBranch handler to add the TObject
184     // to the ESD branch
185     // Note: the object should have an appropriate name returned
186     // by GetName(). Use SetName() to prepare the object before streaming
187     static AliHLTOUTHandlerEsdBranch handler;
188     return &handler;
189   }
190
191   return NULL;
192 }
193
194 int AliHLTAgentSample::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
195 {
196   // see header file for class documentation
197   if (pInstance==NULL) return -EINVAL;
198
199   // nothing to delete, the handler have been defined static
200   return 0;
201 }