]>
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), | |
42 | fStore() | |
43 | { | |
44 | // see header file for class documentation | |
45 | // or | |
46 | // refer to README to build package | |
47 | // or | |
48 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
49 | } | |
50 | ||
51 | AliHLTGlobalHistoCollector::~AliHLTGlobalHistoCollector() { | |
52 | // see header file for class documentation | |
53 | Clear(); | |
54 | } | |
55 | ||
56 | ||
57 | ||
58 | // Public functions to implement AliHLTComponent's interface. | |
59 | // These functions are required for the registration process | |
60 | ||
61 | const char* AliHLTGlobalHistoCollector::GetComponentID() | |
62 | { | |
63 | // see header file for class documentation | |
64 | return "GlobalHistoCollector"; | |
65 | } | |
66 | ||
67 | void AliHLTGlobalHistoCollector::GetInputDataTypes( vector<AliHLTComponentDataType>& list) | |
68 | { | |
69 | // see header file for class documentation | |
70 | ||
71 | list.clear(); | |
72 | list.push_back( kAliHLTDataTypeHistogram ); | |
73 | } | |
74 | ||
75 | AliHLTComponentDataType AliHLTGlobalHistoCollector::GetOutputDataType() | |
76 | { | |
77 | // see header file for class documentation | |
78 | return kAliHLTDataTypeHistogram; | |
79 | } | |
80 | ||
81 | ||
82 | void AliHLTGlobalHistoCollector::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) | |
83 | { | |
84 | // see header file for class documentation | |
85 | constBase=0; | |
86 | inputMultiplier=1.0; | |
87 | } | |
88 | ||
89 | AliHLTComponent* AliHLTGlobalHistoCollector::Spawn() | |
90 | { | |
91 | // see header file for class documentation | |
92 | return new AliHLTGlobalHistoCollector(); | |
93 | } | |
94 | ||
95 | int AliHLTGlobalHistoCollector::DoInit( int argc, const char** argv ) | |
96 | { | |
97 | // see header file for class documentation | |
98 | ||
99 | Clear(); | |
100 | ||
101 | int iResult=0; | |
102 | ||
103 | TString configuration=""; | |
104 | TString argument=""; | |
105 | for (int j=0; j<argc && iResult>=0; j++) { | |
106 | ||
107 | argument=argv[j]; | |
108 | if (!configuration.IsNull()) configuration+=" "; | |
109 | configuration+=argument; | |
110 | } | |
111 | ||
112 | if (!configuration.IsNull()) { | |
113 | iResult=Configure(configuration.Data()); | |
114 | } else { | |
115 | iResult=Reconfigure(NULL, NULL); | |
116 | } | |
117 | fUID = 0; | |
118 | return iResult; | |
119 | } | |
120 | ||
121 | ||
122 | int AliHLTGlobalHistoCollector::DoDeinit() | |
123 | { | |
124 | // see header file for class documentation | |
125 | ||
126 | Clear(); | |
127 | fUID = 0; | |
128 | return 0; | |
129 | } | |
130 | ||
131 | int AliHLTGlobalHistoCollector::Configure(const char* arguments) | |
132 | { | |
133 | // see header file for class documentation | |
134 | ||
135 | int iResult=0; | |
136 | if (!arguments) return iResult; | |
137 | HLTInfo("parsing configuration string \'%s\'", arguments); | |
138 | ||
139 | TString allArgs=arguments; | |
140 | TString argument; | |
141 | int bMissingParam=0; | |
142 | ||
143 | TObjArray* pTokens=allArgs.Tokenize(" "); | |
144 | if (pTokens) { | |
145 | for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) { | |
146 | argument=((TObjString*)pTokens->At(i))->GetString(); | |
147 | if (argument.IsNull()) continue; | |
148 | ||
149 | //if (argument.CompareTo("-sum-noise-histograms")==0) { | |
150 | //fNoiseHistograms = kTRUE; | |
151 | //HLTInfo("got \'-sum-noise-histograms\': %s", ((TObjString*)pTokens->At(i))->GetString().Data()); | |
152 | //else | |
153 | { | |
154 | HLTError("unknown argument %s", argument.Data()); | |
155 | iResult=-EINVAL; | |
156 | break; | |
157 | } | |
158 | } // end for | |
159 | ||
160 | delete pTokens; | |
161 | ||
162 | } // end if pTokens | |
163 | ||
164 | if (bMissingParam) { | |
165 | HLTError("missing parameter for argument %s", argument.Data()); | |
166 | iResult=-EINVAL; | |
167 | } | |
168 | return iResult; | |
169 | } | |
170 | ||
171 | ||
172 | int AliHLTGlobalHistoCollector::Reconfigure(const char* cdbEntry, const char* chainId) { | |
173 | // see header file for class documentation | |
174 | ||
175 | return 0; // no CDB entry exist | |
176 | ||
177 | int iResult=0; | |
178 | const char* path="HLT/ConfigGlobal/GlobalHistoCollector"; | |
179 | const char* defaultNotify=""; | |
180 | if (cdbEntry) { | |
181 | path=cdbEntry; | |
182 | defaultNotify=" (default)"; | |
183 | } | |
184 | ||
185 | if (path) { | |
186 | HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>"); | |
187 | AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/); | |
188 | if (pEntry) { | |
189 | TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject()); | |
190 | if (pString) { | |
191 | HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data()); | |
192 | iResult=Configure(pString->GetString().Data()); | |
193 | } else { | |
194 | HLTError("configuration object \"%s\" has wrong type, required TObjString", path); | |
195 | } | |
196 | } else { | |
197 | HLTError("cannot fetch object \"%s\" from CDB", path); | |
198 | } | |
199 | } | |
200 | return iResult; | |
201 | } | |
202 | ||
203 | ||
204 | void AliHLTGlobalHistoCollector::Clear() | |
205 | { | |
206 | // reset the store | |
207 | ||
208 | for( unsigned int i=0; i<fStore.size(); i++ ){ | |
209 | for( unsigned int j=0; j<fStore[i].fHistos.size(); j++ ){ | |
210 | delete fStore[i].fHistos[j].fHisto; | |
211 | } | |
212 | delete fStore[i].fMergedHisto; | |
213 | } | |
214 | fStore.clear(); | |
215 | } | |
216 | ||
217 | ||
218 | ||
219 | ||
220 | int AliHLTGlobalHistoCollector::DoEvent(const AliHLTComponentEventData & evtData, AliHLTComponentTriggerData& /*trigData*/) | |
221 | { | |
222 | // see header file for class documentation | |
223 | ||
224 | if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )) return 0; | |
225 | ||
226 | if( fUID == 0 ){ | |
227 | TTimeStamp t; | |
228 | fUID = ( gSystem->GetPid() + t.GetNanoSec())*10 + evtData.fEventID; | |
229 | } | |
230 | ||
231 | ||
232 | const TObject *iter = NULL; | |
233 | for(iter = GetFirstInputObject(kAliHLTDataTypeHistogram); iter != NULL; iter = GetNextInputObject()){ | |
234 | ||
235 | if( !( GetDataType(iter) == kAliHLTDataTypeHistogram )) continue; | |
236 | ||
237 | const TH1 *h = dynamic_cast<TH1*>(const_cast<TObject*>( iter ) ); | |
238 | if( !h ) continue; | |
239 | //cout<<"received histo "<<h->GetName()<<" with id="<<GetSpecification(iter)<<endl; | |
240 | // search for the base entry, if not exist then create a new entry | |
241 | ||
242 | int iBase = -1; | |
243 | for( unsigned int i=0; i<fStore.size(); i++ ){ | |
244 | if( fStore[i].fDataType == GetDataType(iter) && | |
245 | TString(fStore[i].fMergedHisto->GetName()).CompareTo(h->GetName())==0){ | |
246 | iBase = i; | |
247 | break; | |
248 | } | |
249 | } | |
250 | ||
251 | if( iBase<0 ){ | |
252 | AliHLTHistoBaseData b; | |
253 | b.fDataType = GetDataType(iter); | |
254 | b.fMergedHisto = (TH1*) iter->Clone(); | |
255 | fStore.push_back(b); | |
256 | iBase = fStore.size()-1; | |
257 | } | |
258 | ||
259 | // search for the specific entry, if not exist then create a new one | |
260 | ||
261 | AliHLTHistoBaseData &b = fStore[iBase]; | |
262 | ||
263 | int iSpec=-1; | |
264 | for( unsigned int i=0; i<fStore[iBase].fHistos.size(); i++ ){ | |
265 | AliHLTHistoData &d = b.fHistos[i]; | |
266 | if( d.fSpecification == GetSpecification(iter) ){ | |
267 | iSpec = i; | |
268 | break; | |
269 | } | |
270 | } | |
271 | ||
272 | if( iSpec<0 ){ | |
273 | AliHLTHistoData d; | |
274 | d.fSpecification = GetSpecification(iter); | |
275 | d.fHisto = (TH1*) iter->Clone(); | |
276 | b.fHistos.push_back(d); | |
277 | iSpec = b.fHistos.size()-1; | |
278 | } | |
279 | b.fHistos[iSpec].fHisto->Reset(); | |
280 | b.fHistos[iSpec].fHisto->Add( (TH1*)iter, 1); | |
281 | //cout<<"index = "<<iBase<<","<<iSpec<<", nentr="<<b.fHistos[iSpec].fHisto->GetEntries()<<endl; | |
282 | ||
283 | // merge histos | |
284 | b.fMergedHisto->Reset(); | |
285 | ||
286 | for( unsigned int i=0; i<b.fHistos.size(); i++ ){ | |
287 | b.fMergedHisto->Add(b.fHistos[i].fHisto,1); | |
288 | } | |
289 | //cout<<" merged="<<b.fMergedHisto->GetEntries()<<endl; | |
290 | ||
291 | } // end for loop over histogram blocks | |
292 | ||
293 | for( unsigned int i=0; i<fStore.size(); i++ ){ | |
294 | PushBack((TObject*) fStore[i].fMergedHisto, fStore[i].fDataType, fUID ); | |
295 | } | |
296 | return 0; | |
297 | } | |
298 |