]>
Commit | Line | Data |
---|---|---|
e419c1ae | 1 | |
2 | //************************************************************************** | |
3 | //* This file is property of and copyright by the ALICE HLT Project * | |
4 | //* ALICE Experiment at CERN, All rights reserved. * | |
5 | //* * | |
6 | //* Primary Authors: Kalliopi Kanaki <Kalliopi.Kanaki@ift.uib.no> * | |
7 | //* for The ALICE HLT Project. * | |
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 AliHLTGlobalHistoCollector.cxx | |
19 | @author Kalliopi Kanaki | |
20 | @date | |
21 | @brief The Histogram Handler component | |
22 | */ | |
23 | ||
24 | #if __GNUC__>= 3 | |
25 | using namespace std; | |
26 | #endif | |
27 | #include "AliHLTGlobalHistoCollector.h" | |
28 | #include "AliCDBEntry.h" | |
29 | #include "AliCDBManager.h" | |
30 | #include "TString.h" | |
31 | #include "TObjArray.h" | |
32 | #include "TObjString.h" | |
33 | #include "TH1.h" | |
34 | #include "TTimeStamp.h" | |
35 | #include "TSystem.h" | |
36 | ||
37 | ClassImp(AliHLTGlobalHistoCollector) //ROOT macro for the implementation of ROOT specific class methods | |
38 | ||
39 | AliHLTGlobalHistoCollector::AliHLTGlobalHistoCollector() | |
40 | : | |
41 | fUID(0), | |
776446ad | 42 | fStore(), |
43 | fBenchmark("GlobalHistoCollector") | |
e419c1ae | 44 | { |
45 | // see header file for class documentation | |
46 | // or | |
47 | // refer to README to build package | |
48 | // or | |
49 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
50 | } | |
51 | ||
52 | AliHLTGlobalHistoCollector::~AliHLTGlobalHistoCollector() { | |
53 | // see header file for class documentation | |
54 | Clear(); | |
55 | } | |
56 | ||
57 | ||
58 | ||
59 | // Public functions to implement AliHLTComponent's interface. | |
60 | // These functions are required for the registration process | |
61 | ||
62 | const char* AliHLTGlobalHistoCollector::GetComponentID() | |
63 | { | |
64 | // see header file for class documentation | |
65 | return "GlobalHistoCollector"; | |
66 | } | |
67 | ||
68 | void AliHLTGlobalHistoCollector::GetInputDataTypes( vector<AliHLTComponentDataType>& list) | |
69 | { | |
70 | // see header file for class documentation | |
71 | ||
72 | list.clear(); | |
776446ad | 73 | list.push_back( kAliHLTAllDataTypes ); |
e419c1ae | 74 | } |
75 | ||
76 | AliHLTComponentDataType AliHLTGlobalHistoCollector::GetOutputDataType() | |
77 | { | |
78 | // see header file for class documentation | |
776446ad | 79 | return kAliHLTAllDataTypes; |
e419c1ae | 80 | } |
81 | ||
82 | ||
83 | void AliHLTGlobalHistoCollector::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) | |
84 | { | |
85 | // see header file for class documentation | |
86 | constBase=0; | |
87 | inputMultiplier=1.0; | |
88 | } | |
89 | ||
90 | AliHLTComponent* AliHLTGlobalHistoCollector::Spawn() | |
91 | { | |
92 | // see header file for class documentation | |
93 | return new AliHLTGlobalHistoCollector(); | |
94 | } | |
95 | ||
96 | int AliHLTGlobalHistoCollector::DoInit( int argc, const char** argv ) | |
97 | { | |
98 | // see header file for class documentation | |
99 | ||
100 | Clear(); | |
776446ad | 101 | fBenchmark.Reset(); |
102 | fBenchmark.SetTimer(0,"total"); | |
103 | fBenchmark.SetTimer(1,"merging"); | |
104 | ||
e419c1ae | 105 | int iResult=0; |
106 | ||
107 | TString configuration=""; | |
108 | TString argument=""; | |
109 | for (int j=0; j<argc && iResult>=0; j++) { | |
110 | ||
111 | argument=argv[j]; | |
112 | if (!configuration.IsNull()) configuration+=" "; | |
113 | configuration+=argument; | |
114 | } | |
115 | ||
116 | if (!configuration.IsNull()) { | |
117 | iResult=Configure(configuration.Data()); | |
118 | } else { | |
119 | iResult=Reconfigure(NULL, NULL); | |
120 | } | |
121 | fUID = 0; | |
122 | return iResult; | |
123 | } | |
124 | ||
125 | ||
126 | int AliHLTGlobalHistoCollector::DoDeinit() | |
127 | { | |
128 | // see header file for class documentation | |
129 | ||
130 | Clear(); | |
131 | fUID = 0; | |
132 | return 0; | |
133 | } | |
134 | ||
135 | int AliHLTGlobalHistoCollector::Configure(const char* arguments) | |
136 | { | |
137 | // see header file for class documentation | |
138 | ||
139 | int iResult=0; | |
140 | if (!arguments) return iResult; | |
141 | HLTInfo("parsing configuration string \'%s\'", arguments); | |
142 | ||
143 | TString allArgs=arguments; | |
144 | TString argument; | |
145 | int bMissingParam=0; | |
146 | ||
147 | TObjArray* pTokens=allArgs.Tokenize(" "); | |
148 | if (pTokens) { | |
149 | for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) { | |
150 | argument=((TObjString*)pTokens->At(i))->GetString(); | |
151 | if (argument.IsNull()) continue; | |
152 | ||
153 | //if (argument.CompareTo("-sum-noise-histograms")==0) { | |
154 | //fNoiseHistograms = kTRUE; | |
155 | //HLTInfo("got \'-sum-noise-histograms\': %s", ((TObjString*)pTokens->At(i))->GetString().Data()); | |
156 | //else | |
157 | { | |
158 | HLTError("unknown argument %s", argument.Data()); | |
159 | iResult=-EINVAL; | |
160 | break; | |
161 | } | |
162 | } // end for | |
163 | ||
164 | delete pTokens; | |
165 | ||
166 | } // end if pTokens | |
167 | ||
168 | if (bMissingParam) { | |
169 | HLTError("missing parameter for argument %s", argument.Data()); | |
170 | iResult=-EINVAL; | |
171 | } | |
172 | return iResult; | |
173 | } | |
174 | ||
175 | ||
176 | int AliHLTGlobalHistoCollector::Reconfigure(const char* cdbEntry, const char* chainId) { | |
177 | // see header file for class documentation | |
178 | ||
179 | return 0; // no CDB entry exist | |
180 | ||
181 | int iResult=0; | |
182 | const char* path="HLT/ConfigGlobal/GlobalHistoCollector"; | |
183 | const char* defaultNotify=""; | |
184 | if (cdbEntry) { | |
185 | path=cdbEntry; | |
186 | defaultNotify=" (default)"; | |
187 | } | |
188 | ||
189 | if (path) { | |
190 | HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>"); | |
191 | AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/); | |
192 | if (pEntry) { | |
193 | TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject()); | |
194 | if (pString) { | |
195 | HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data()); | |
196 | iResult=Configure(pString->GetString().Data()); | |
197 | } else { | |
198 | HLTError("configuration object \"%s\" has wrong type, required TObjString", path); | |
199 | } | |
200 | } else { | |
201 | HLTError("cannot fetch object \"%s\" from CDB", path); | |
202 | } | |
203 | } | |
204 | return iResult; | |
205 | } | |
206 | ||
207 | ||
208 | void AliHLTGlobalHistoCollector::Clear() | |
209 | { | |
210 | // reset the store | |
211 | ||
212 | for( unsigned int i=0; i<fStore.size(); i++ ){ | |
dcb913a8 | 213 | for( unsigned int j=0; j<fStore[i].fInstances.size(); j++ ){ |
214 | delete fStore[i].fInstances[j].fObject; | |
e419c1ae | 215 | } |
dcb913a8 | 216 | delete fStore[i].fMergedObject; |
e419c1ae | 217 | } |
218 | fStore.clear(); | |
219 | } | |
220 | ||
221 | ||
222 | ||
223 | ||
224 | int AliHLTGlobalHistoCollector::DoEvent(const AliHLTComponentEventData & evtData, AliHLTComponentTriggerData& /*trigData*/) | |
225 | { | |
226 | // see header file for class documentation | |
776446ad | 227 | //cout<<"\n\nDoEvent called"<<endl; |
e419c1ae | 228 | |
229 | if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )) return 0; | |
230 | ||
776446ad | 231 | fBenchmark.StartNewEvent(); |
232 | fBenchmark.Start(0); | |
233 | ||
e419c1ae | 234 | if( fUID == 0 ){ |
235 | TTimeStamp t; | |
236 | fUID = ( gSystem->GetPid() + t.GetNanoSec())*10 + evtData.fEventID; | |
237 | } | |
238 | ||
776446ad | 239 | for( const AliHLTComponentBlockData *i= GetFirstInputBlock(); i!=NULL; i=GetNextInputBlock() ){ |
240 | fBenchmark.AddInput(i->fSize); | |
241 | } | |
242 | ||
dcb913a8 | 243 | const TObject *iter = NULL; |
244 | for(iter = GetFirstInputObject(); iter != NULL; iter = GetNextInputObject()){ | |
e419c1ae | 245 | |
dcb913a8 | 246 | if( !iter ) continue; |
776446ad | 247 | |
248 | if( !iter->InheritsFrom(TH1::Class()) | |
249 | && !iter->InheritsFrom(TSeqCollection::Class()) ) continue; | |
dcb913a8 | 250 | |
776446ad | 251 | //cout<<"received object "<<iter->GetName()<<" with id="<<GetSpecification(iter)<<endl; |
dcb913a8 | 252 | |
253 | //search for the base entry, if not exist then create a new entry | |
e419c1ae | 254 | |
776446ad | 255 | int iColl = -1; |
e419c1ae | 256 | for( unsigned int i=0; i<fStore.size(); i++ ){ |
776446ad | 257 | if( fStore[i].fHLTDataType != GetDataType(iter) ) continue; |
258 | if( fStore[i].fInstances.size()<1 ) continue; | |
259 | TObject * obj = fStore[i].fInstances[0].fObject; | |
260 | if( !obj ) continue; | |
261 | if( TString(obj->GetName()).CompareTo(iter->GetName())==0){ | |
262 | iColl = i; | |
e419c1ae | 263 | break; |
264 | } | |
265 | } | |
776446ad | 266 | //cout<<"Collection found: "<<iColl<<endl; |
267 | if( iColl<0 ){ | |
dcb913a8 | 268 | AliHLTGlobalHCCollection c; |
269 | c.fHLTDataType = GetDataType(iter); | |
776446ad | 270 | c.fMergedObject = 0; |
271 | c.fNeedToMerge = 1; | |
dcb913a8 | 272 | fStore.push_back(c); |
776446ad | 273 | iColl = fStore.size()-1; |
274 | }else{ | |
275 | fStore[iColl].fNeedToMerge = 1; | |
e419c1ae | 276 | } |
277 | ||
278 | // search for the specific entry, if not exist then create a new one | |
dcb913a8 | 279 | |
776446ad | 280 | AliHLTGlobalHCCollection &c = fStore[iColl]; |
281 | ||
e419c1ae | 282 | int iSpec=-1; |
dcb913a8 | 283 | for( unsigned int i=0; i<c.fInstances.size(); i++ ){ |
284 | AliHLTGlobalHCInstance &inst = c.fInstances[i]; | |
285 | if( inst.fHLTSpecification == GetSpecification(iter) ){ | |
e419c1ae | 286 | iSpec = i; |
287 | break; | |
288 | } | |
289 | } | |
776446ad | 290 | //cout<<"Instance found:"<<iSpec<<endl; |
e419c1ae | 291 | if( iSpec<0 ){ |
dcb913a8 | 292 | AliHLTGlobalHCInstance inst; |
293 | inst.fHLTSpecification = GetSpecification(iter); | |
294 | inst.fObject = 0; | |
295 | c.fInstances.push_back(inst); | |
296 | iSpec = c.fInstances.size()-1; | |
297 | }else{ | |
298 | delete c.fInstances[iSpec].fObject; | |
e419c1ae | 299 | } |
dcb913a8 | 300 | |
dcb913a8 | 301 | c.fInstances[iSpec].fObject = iter->Clone(); |
302 | ||
776446ad | 303 | //cout<<"index = "<<iColl<<","<<iSpec<<endl; |
304 | ||
305 | } // end for loop over input blocks | |
e419c1ae | 306 | |
776446ad | 307 | fBenchmark.Start(1); |
308 | ||
309 | ||
310 | // merge histos | |
311 | ||
312 | for( unsigned int iColl = 0; iColl<fStore.size(); iColl++){ | |
313 | AliHLTGlobalHCCollection &c = fStore[iColl]; | |
314 | if( !c.fNeedToMerge && c.fMergedObject ) continue; | |
315 | if( c.fInstances.size() <1 ) continue; | |
dcb913a8 | 316 | delete c.fMergedObject; |
317 | c.fMergedObject = c.fInstances[0].fObject->Clone(); | |
776446ad | 318 | TList l; |
dcb913a8 | 319 | for( unsigned int i=1; i<c.fInstances.size(); i++ ){ |
776446ad | 320 | l.Add(c.fInstances[i].fObject); |
e419c1ae | 321 | } |
e419c1ae | 322 | |
776446ad | 323 | if( c.fMergedObject->InheritsFrom(TH1::Class()) ){ |
324 | TH1 *histo = dynamic_cast<TH1*>(c.fMergedObject); | |
325 | if( histo ) histo->Merge(&l); | |
326 | } | |
327 | else if( c.fMergedObject->InheritsFrom(TSeqCollection::Class()) ){ | |
328 | TSeqCollection *list = dynamic_cast<TSeqCollection*>(c.fMergedObject); | |
329 | if( list ) list->Merge(&l); | |
330 | } | |
331 | c.fNeedToMerge = 0; | |
332 | } | |
333 | fBenchmark.Stop(1); | |
334 | ||
335 | // send output | |
e419c1ae | 336 | |
337 | for( unsigned int i=0; i<fStore.size(); i++ ){ | |
776446ad | 338 | if( fStore[i].fMergedObject ){ |
339 | PushBack((TObject*) fStore[i].fMergedObject, fStore[i].fHLTDataType, fUID ); | |
340 | fBenchmark.AddOutput(GetLastObjectSize()); | |
341 | } | |
e419c1ae | 342 | } |
776446ad | 343 | |
344 | fBenchmark.Stop(0); | |
345 | HLTInfo(fBenchmark.GetStatistics()); | |
346 | ||
e419c1ae | 347 | return 0; |
348 | } | |
349 |