Small fix for case of no time structure
[u/mrichter/AliRoot.git] / HLT / trigger / AliHLTGlobalTriggerComponent.cxx
CommitLineData
1b9a175e 1/**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * ALICE Experiment at CERN, All rights reserved. *
4 * *
5 * Primary Authors: Artur Szostak <artursz@iafrica.com> *
6 * for The ALICE HLT Project. *
7 * *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
16
17/// @file AliHLTGlobalTriggerComponent.cxx
18/// @author Artur Szostak <artursz@iafrica.com>
19/// @date 26 Nov 2008
20/// @brief Implementation of the AliHLTGlobalTriggerComponent component class.
21///
22/// The AliHLTGlobalTriggerComponentComponent class applies the global HLT trigger to all
23/// trigger information produced by components deriving from AliHLTTrigger.
24
25#include "AliHLTGlobalTriggerComponent.h"
e2bb8ddd 26#include "AliHLTGlobalTriggerDecision.h"
27#include "AliHLTGlobalTrigger.h"
28#include "TUUID.h"
29#include "TROOT.h"
30#include "TSystem.h"
31#include <fstream>
32#include <cerrno>
1b9a175e 33
34ClassImp(AliHLTGlobalTriggerComponent)
35
36
37AliHLTGlobalTriggerComponent::AliHLTGlobalTriggerComponent() :
e2bb8ddd 38 AliHLTTrigger(),
39 fTrigger(NULL)
1b9a175e 40{
41 // Default constructor.
42}
43
44
45AliHLTGlobalTriggerComponent::~AliHLTGlobalTriggerComponent()
46{
47 // Default destructor.
e2bb8ddd 48
49 if (fTrigger != NULL) delete fTrigger;
1b9a175e 50}
51
52
53void AliHLTGlobalTriggerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
54{
55 // Returns the output data size estimate.
56
e2bb8ddd 57 constBase = sizeof(AliHLTGlobalTriggerDecision);
1b9a175e 58 inputMultiplier = 1;
59}
60
61
e2bb8ddd 62Int_t AliHLTGlobalTriggerComponent::DoInit(int /*argc*/, const char** /*argv*/)
1b9a175e 63{
e2bb8ddd 64 // Initialises the global trigger component.
65
66 AliHLTTriggerMenu* menu = NULL;
67 TString classname;
68 int result = GenerateTrigger(menu, classname);
69 if (result != 0) return result;
70
71 fTrigger = AliHLTGlobalTrigger::CreateNew(classname.Data());
72 if (fTrigger == NULL)
73 {
74 HLTError("Could not create a new instance of '%s'.", classname.Data());
75 return -EIO;
76 }
77
78 return 0;
79}
80
1b9a175e 81
e2bb8ddd 82Int_t AliHLTGlobalTriggerComponent::DoDeinit()
83{
84 // Cleans up the global trigger component.
85
86 if (fTrigger != NULL)
87 {
88 delete fTrigger;
89 fTrigger = NULL;
90 }
91
1b9a175e 92 return 0;
93}
4f1d6b68 94
95
96AliHLTComponent* AliHLTGlobalTriggerComponent::Spawn()
97{
98 // Creates a new object instance.
99
100 return new AliHLTGlobalTriggerComponent;
101}
102
e2bb8ddd 103
104int AliHLTGlobalTriggerComponent::DoTrigger()
105{
106 // This method will apply the global trigger decision.
107
108 if (fTrigger == NULL)
109 {
110 HLTFatal("Global trigger implementation object is NULL!");
111 return -EIO;
112 }
113
114 fTrigger->NewEvent();
115
116 // Fill in the input data.
117 const TObject* obj = GetFirstInputObject();
118 while (obj != NULL)
119 {
120 if (obj->IsA() == AliHLTTriggerDecision::Class())
121 {
122 const AliHLTTriggerDecision* decision = static_cast<const AliHLTTriggerDecision*>(obj);
123 fTrigger->Add(decision);
124 }
125 else
126 {
127 fTrigger->Add(obj, GetDataType(), GetSpecification());
128 }
129 obj = GetNextInputObject();
130 }
131
132 // Apply the trigger.
133 TriggerEvent(fTrigger->CalculateTriggerDecision());
134 return 0;
135}
136
137
138int AliHLTGlobalTriggerComponent::GenerateTrigger(const AliHLTTriggerMenu* /*menu*/, TString& name)
139{
140 // Generates the global trigger class that will implement the specified trigger menu.
141
142 // Create a new UUID and replace the '-' characters with '_' to make it a valid
143 // C++ symbol name.
144 TUUID uuid;
145 TString uuidstr = uuid.AsString();
146 for (Int_t i = 0; i < uuidstr.Length(); i++)
147 {
148 if (uuidstr[i] == '-') uuidstr[i] = '_';
149 }
150
151 // Create the name of the new class.
152 name = "AliHLTGlobalTriggerImpl_";
153 name += uuidstr;
154 TString filename = name + ".cxx";
155
156 fstream code(filename.Data(), ios_base::out | ios_base::trunc);
157 if (not code.good())
158 {
159 HLTError("Could not open file '%s' for writing.", filename.Data());
160 return -EIO;
161 }
162
163 code << "#include \"AliHLTGlobalTrigger.h\"" << endl;
164 code << "#include \"AliHLTGlobalTriggerDecision.h\"" << endl;
165 code << "class " << name << " : public AliHLTGlobalTrigger" << endl;
166 code << "{" << endl;
167 code << "public:" << endl;
168 code << " " << name << "() : AliHLTGlobalTrigger(), fDecision() {" << endl;
169 code << " }" << endl;
170 code << " virtual ~" << name << "() {" << endl;
171 code << " }" << endl;
172 code << " virtual void NewEvent() {" << endl;
173 //code << " ;" << endl;
174 code << " }" << endl;
175 code << " virtual void Add(const AliHLTTriggerDecision* decision) {" << endl;
176 //code << " ;" << endl;
177 code << " }" << endl;
178 code << " virtual void Add(const TObject* object, const AliHLTComponentDataType& type, AliHLTUInt32_t spec) {" << endl;
179 //code << " ;" << endl;
180 code << " }" << endl;
181 code << " virtual AliHLTGlobalTriggerDecision* CalculateTriggerDecision() {" << endl;
182 code << " return &fDecision;" << endl;
183 code << " }" << endl;
184 code << " class FactoryImpl : public AliHLTGlobalTrigger::Factory" << endl;
185 code << " {" << endl;
186 code << " public:" << endl;
187 code << " virtual const char* ClassName() const {" << endl;
188 code << " return \"" << name << "\";" << endl;
189 code << " }" << endl;
190 code << " virtual AliHLTGlobalTrigger* New() const {" << endl;
191 code << " return new " << name << "();" << endl;
192 code << " }" << endl;
193 code << " private:" << endl;
194 code << " static FactoryImpl fFactoryImpl; // for registration only." << endl;
195 code << " };" << endl;
196 code << "private:" << endl;
197 code << " AliHLTGlobalTriggerDecision fDecision;" << endl;
198 code << "};" << endl;
199 code << name << "::FactoryImpl " << name << "::FactoryImpl::fFactoryImpl;" << endl;
200
201 TString includePath = "-I${ALICE_ROOT}/include -I${ALICE_ROOT}/HLT/BASE -I${ALICE_ROOT}/HLT/trigger";
202 gSystem->SetIncludePath(includePath);
203
204 TString cmd = ".L ";
205 cmd += filename;
206 cmd += "++";
207 gROOT->ProcessLine(cmd);
208
209 code.close();
210
211 return 0;
212}
213