]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/rec/AliHLTMiscImplementation.cxx
fix event type from raw reader
[u/mrichter/AliRoot.git] / HLT / rec / AliHLTMiscImplementation.cxx
CommitLineData
2b545cdd 1// $Id$
2
3//**************************************************************************
abb64a61 4//* This file is property of and copyright by the *
2b545cdd 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 AliHLTMisc.cxx
20/// @author Matthias Richter
abb64a61 21/// @date 2009-07-07
22/// @brief Implementation of various glue functions implemented in dynamically
23/// loaded libraries
2b545cdd 24
25#include "AliHLTMiscImplementation.h"
26#include "AliHLTLogging.h"
88bb1fd0 27#include "AliHLTErrorGuard.h"
79c426cf 28#include "AliLog.h"
2b545cdd 29#include "AliCDBManager.h"
22d17395 30#include "AliCDBStorage.h"
2b545cdd 31#include "AliCDBEntry.h"
cc484ed9 32#include "AliGRPManager.h"
73305a93 33#include "AliRawReader.h"
2572a09f 34#include "AliRawEventHeaderBase.h"
a5e775ec 35#include "AliTracker.h"
ee15809c 36#include "AliESDtrack.h"
95ea76b5 37#include "AliESDHLTDecision.h"
cc484ed9 38#include "TGeoGlobalMagField.h"
95ea76b5 39#include "AliHLTGlobalTriggerDecision.h"
79c426cf 40#include "TClass.h"
41#include "TStreamerInfo.h"
42#include "TObjArray.h"
aae32bac 43#include <stdexcept>
2b545cdd 44
45/** ROOT macro for the implementation of ROOT specific class methods */
46ClassImp(AliHLTMiscImplementation);
47
48AliHLTMiscImplementation::AliHLTMiscImplementation()
49{
50}
51
52AliHLTMiscImplementation::~AliHLTMiscImplementation()
53{
54 // see header file for function documentation
55}
56
57int AliHLTMiscImplementation::InitCDB(const char* cdbpath)
58{
59 // see header file for function documentation
60 int iResult=0;
61 AliCDBManager* pCDB = AliCDBManager::Instance();
62 AliHLTLogging log;
63 if (!pCDB) {
64 log.Logging(kHLTLogError, "InitCDB", "CDB handling", "Could not get CDB instance");
65 } else {
66 if (cdbpath && cdbpath[0]!=0) {
cc484ed9 67 TString uri=cdbpath;
68 if (!uri.BeginsWith("local://") &&
69 !uri.Contains("://")) {
70 // assume a local path if no uri specifier is found
71 uri="local://";
72 uri+=cdbpath;
73 }
74 pCDB->SetDefaultStorage(uri);
2b545cdd 75 log.Logging(kHLTLogDebug, "InitCDB", "CDB handling", "CDB instance 0x%x", pCDB);
76 } else if (!pCDB->IsDefaultStorageSet()) {
77 const char* cdbUri="local://$ALICE_ROOT/OCDB";
78 pCDB->SetDefaultStorage(cdbUri);
79 pCDB->SetRun(0);
80 log.Logging(kHLTLogInfo, "InitCDB", "CDB handling", "set default URI: %s", cdbUri);
81 }
82 }
83 return iResult;
84}
85
86int AliHLTMiscImplementation::SetCDBRunNo(int runNo)
87{
88 // see header file for function documentation
89 int iResult=0;
90 AliCDBManager* pCDB = AliCDBManager::Instance();
91 AliHLTLogging log;
92 if (!pCDB) {
cc484ed9 93 log.Logging(kHLTLogError, "SetCDBRunNo", "CDB handling", "Could not get CDB instance");
2b545cdd 94 } else {
95 pCDB->SetRun(runNo);
96 }
97 return iResult;
98}
99
74c1905c 100int AliHLTMiscImplementation::GetCDBRunNo() const
df5d2b78 101{
102 // see header file for function documentation
103 AliCDBManager* pCDB = AliCDBManager::Instance();
104 AliHLTLogging log;
105 if (!pCDB) {
106 log.Logging(kHLTLogError, "SetCDBRunNo", "CDB handling", "Could not get CDB instance");
107 } else {
108 return pCDB->GetRun();
109 }
110 return -1;
111}
112
5df320bf 113AliCDBEntry* AliHLTMiscImplementation::LoadOCDBEntry(const char* path, int runNo) const
2b545cdd 114{
115 // see header file for function documentation
88bb1fd0 116 if (!path) return NULL;
117 AliHLTLogging log;
118
de254f89 119 AliCDBManager* man = AliCDBManager::Instance();
88bb1fd0 120 if (!man) {
121 ALIHLTERRORGUARD(1, "failed to access CDB manager");
122 return NULL;
123 }
3ed9cacd 124 if (runNo<0) runNo=man->GetRun();
de254f89 125
aae32bac 126 AliCDBEntry* entry=NULL;
127 try {
128 // exceptions for the loading of OCDB objects have been introduced in r61012 on
129 // Feb 20 2013. This allows to reduce this function to try and catch of AliCDBManager::Get
130 entry=man->Get(path, runNo);
88bb1fd0 131 }
aae32bac 132 catch (...) {
133 // ignore the exception, missing object can be a valid condition, and is handled
134 // downstream
88bb1fd0 135 }
5df320bf 136 return entry;
2b545cdd 137}
138
74c1905c 139TObject* AliHLTMiscImplementation::ExtractObject(AliCDBEntry* entry) const
2b545cdd 140{
141 // see header file for function documentation
142 if (!entry) return NULL;
143 return entry->GetObject();
144}
145
74c1905c 146int AliHLTMiscImplementation::CheckOCDBEntries(const TMap* const pMap) const
147{
148 // check the availability of the OCDB entry descriptions in the TMap
149 // key : complete OCDB path of the entry
150 // value : auxiliary object - short description
88bb1fd0 151 // check uses AliCDBStorage::GetLatestVersion, which is the only method
152 // to check the existence without risking AliFatal
153
74c1905c 154 int iResult=0;
155 if (!pMap) return -EINVAL;
88bb1fd0 156 AliHLTLogging log;
157
158 AliCDBManager* man = AliCDBManager::Instance();
159 if (!man) {
160 ALIHLTERRORGUARD(1, "failed to access CDB manager");
726d36e7 161 return -ENOSYS;
88bb1fd0 162 }
74c1905c 163 Int_t runNo = GetCDBRunNo();
164
165 TIterator* next=pMap->MakeIterator();
726d36e7 166 if (!next) return -EFAULT;
5d99ef2a 167
74c1905c 168 TObject* pEntry=NULL;
169 while ((pEntry=next->Next())) {
aae32bac 170 try {
171 // exceptions for the loading of OCDB objects have been introduced in r61012 on
172 // Feb 20 2013. This allows to reduce this function to try and catch of AliCDBManager::Get
173 man->Get(pEntry->GetName(), runNo);
74c1905c 174 }
aae32bac 175 catch (...) {
176 // find out the storage for more details in the error message
177 AliCDBStorage* pStorage=NULL;
178 const char* uri=man->GetURI(pEntry->GetName());
179 if (uri) {
180 pStorage = AliCDBManager::Instance()->GetStorage(uri);
181 }
74c1905c 182
aae32bac 183 log.Logging(kHLTLogError, "AliHLTMiscImplementation::CheckOCDBEntries", "CDB handling", "can not find required OCDB object %s for run number %d in storage %s", pEntry->GetName(), runNo, (pStorage!=NULL?pStorage->GetURI().Data():"<unavailable>"));
74c1905c 184 iResult=-ENOENT;
74c1905c 185 }
186 }
5d99ef2a 187 delete next;
188 next=NULL;
74c1905c 189
190 return iResult;
191}
192
cc484ed9 193int AliHLTMiscImplementation::InitMagneticField() const
2b545cdd 194{
cc484ed9 195 // see header file for function documentation
196
197 // BAD: unit test fails if I call TGeoGlobalMagField::Instance()
198 // at this point. Something goes wrong in the cleaning of the global
199 // ROOT onject
200 /*
201 if (TGeoGlobalMagField::Instance()->GetField()) {
202 // everything set, but think about storing the currents for
203 // a cross-check
204 return 0;
2b545cdd 205 }
cc484ed9 206 */
2b545cdd 207
cc484ed9 208 // The magnetic field is initialized once at the start
209 // of run. The fields are supposed to be constant througout the
210 // data taking of one run. The run is aborted if the changes
211 // exceed a certain limit.
212 AliGRPManager grpman;
213 if (grpman.ReadGRPEntry() && grpman.SetMagField()) {
214 return 0;
2b545cdd 215 }
cc484ed9 216
217 return -ENOENT;
2b545cdd 218}
73305a93 219
220AliHLTUInt64_t AliHLTMiscImplementation::GetTriggerMask(AliRawReader* rawReader) const
221{
222 // see header file for function documentation
223 if (!rawReader) return 0;
224 AliHLTUInt64_t trgMask=0;
225 if (rawReader) {
226 const UInt_t* pattern=rawReader->GetTriggerPattern();
227 trgMask=pattern[1]&0xfffffff; // 28 upper bits of the 50 bit mask
228 trgMask<<=32;
229 trgMask|=pattern[0]; // 32 lower bits of the mask
230 }
231 return trgMask;
232}
a5e775ec 233
2572a09f 234AliHLTUInt32_t AliHLTMiscImplementation::GetTimeStamp(AliRawReader* rawReader) const
235{
236 // extract time stamp of the event from the event header
462b8b22 237 if (!rawReader) return kMaxUInt;
2572a09f 238 const AliRawEventHeaderBase* eventHeader = rawReader->GetEventHeader();
462b8b22 239 if (!eventHeader) return kMaxUInt;
2572a09f 240 return eventHeader->Get("Timestamp");
241}
242
243AliHLTUInt32_t AliHLTMiscImplementation::GetEventType(AliRawReader* rawReader) const
244{
245 // extract event type from the event header
246 if (!rawReader) return 0;
247 const AliRawEventHeaderBase* eventHeader = rawReader->GetEventHeader();
248 if (!eventHeader) return 0;
20ab3d87
TB
249 UInt_t daqType = eventHeader->Get("Type");
250 switch(daqType){
251 case AliRawEventHeaderBase::kStartOfRun:
252 case AliRawEventHeaderBase::kStartOfData:
253 return gkAliEventTypeStartOfRun;
254
255 case AliRawEventHeaderBase::kEndOfRun:
256 case AliRawEventHeaderBase::kEndOfData:
257 return gkAliEventTypeEndOfRun;
258
259 case AliRawEventHeaderBase::kPhysicsEvent:
260 return gkAliEventTypeData;
261
262 case AliRawEventHeaderBase::kCalibrationEvent:
263 return gkAliEventTypeCalibration;
264
265 case AliRawEventHeaderBase::kFormatError:
266 return gkAliEventTypeCorruptID;
267
268 case AliRawEventHeaderBase::kSystemSoftwareTriggerEvent:
269 case AliRawEventHeaderBase::kDetectorSoftwareTriggerEvent:
270 return gkAliEventTypeSoftware;
271
272 // TODO: Sync Event Type not implemented!
273 //case AliRawEventHeaderBase::kSyncEvent:
274 }
275 return gkAliEventTypeUnknown;
2572a09f 276}
277
de254f89 278const char* AliHLTMiscImplementation::GetBeamTypeFromGRP() const
279{
280 // get beam type from GRP
281 return NULL;
282}
283
a5e775ec 284Double_t AliHLTMiscImplementation::GetBz()
285{
286 // Returns Bz.
287 return AliTracker::GetBz();
288}
289
290Double_t AliHLTMiscImplementation::GetBz(const Double_t *r)
291{
292 // Returns Bz (kG) at the point "r" .
293 return AliTracker::GetBz(r);
294}
295
296void AliHLTMiscImplementation::GetBxByBz(const Double_t r[3], Double_t b[3])
297{
298 // Returns Bx, By and Bz (kG) at the point "r" .
299 return AliTracker::GetBxByBz(r, b);
300}
95ea76b5 301
302const TClass* AliHLTMiscImplementation::IsAliESDHLTDecision() const
303{
304 // Return the IsA of the AliESDHLTDecision class
95ea76b5 305 return AliESDHLTDecision::Class();
95ea76b5 306}
307
308int AliHLTMiscImplementation::Copy(const AliHLTGlobalTriggerDecision* pDecision, TObject* object) const
309{
310 // Copy HLT global trigger decision to AliESDHLTDecision container
311 if (!pDecision || !object) return -EINVAL;
95ea76b5 312 AliESDHLTDecision* pESDHLTDecision=NULL;
313 if (object->IsA()==NULL ||
314 object->IsA() != AliESDHLTDecision::Class() ||
315 (pESDHLTDecision=dynamic_cast<AliESDHLTDecision*>(object))==NULL) {
316// HLTError("can not copy HLT global decision to object of class \"%s\"",
317// object->IsA()?object->IsA()->GetName():"NULL");
318 return -EINVAL;
319 }
320
321 pESDHLTDecision->~AliESDHLTDecision();
84f84689 322 new (pESDHLTDecision) AliESDHLTDecision(pDecision->Result(), pDecision->GetTitle());
95ea76b5 323
95ea76b5 324 return 0;
325}
79c426cf 326
327int AliHLTMiscImplementation::InitStreamerInfos(const char* ocdbEntry) const
328{
329 // init streamer infos for HLT reconstruction
330 // Root schema evolution is not enabled for AliHLTMessage and all streamed objects.
331 // Objects in the raw data payload rely on the availability of the correct stream info.
332 // The relevant streamer info for a specific run is stored in the OCDB.
333 int iResult=0;
334
335 AliCDBEntry* pEntry=LoadOCDBEntry(ocdbEntry);
336 TObject* pObject=NULL;
337 if (pEntry && (pObject=ExtractObject(pEntry))!=NULL)
338 {
339 TObjArray* pSchemas=dynamic_cast<TObjArray*>(pObject);
340 if (pSchemas) {
341 iResult=InitStreamerInfos(pSchemas);
342 } else {
343 AliError(Form("internal mismatch in OCDB entry %s: wrong class type", ocdbEntry));
344 }
345 } else {
346 AliWarning(Form("missing HLT reco data (%s), skipping initialization of streamer info for TObjects in HLT raw data payload", ocdbEntry));
347 }
348 return iResult;
349}
350
351int AliHLTMiscImplementation::InitStreamerInfos(TObjArray* pSchemas) const
352{
353 // init streamer infos for HLT reconstruction from an array of TStreamerInfo objects
354
355 for (int i=0; i<pSchemas->GetEntriesFast(); i++) {
356 if (pSchemas->At(i)) {
357 TStreamerInfo* pSchema=dynamic_cast<TStreamerInfo*>(pSchemas->At(i));
358 if (pSchema) {
359 int version=pSchema->GetClassVersion();
360 TClass* pClass=TClass::GetClass(pSchema->GetName());
361 if (pClass) {
362 if (pClass->GetClassVersion()==version) {
363 AliDebug(0,Form("skipping schema definition %d version %d to class %s as this is the native version", i, version, pSchema->GetName()));
364 continue;
365 }
366 TObjArray* pInfos=pClass->GetStreamerInfos();
367 if (pInfos /*&& version<pInfos->GetEntriesFast()*/) {
368 if (pInfos->At(version)==NULL) {
369 TStreamerInfo* pClone=(TStreamerInfo*)pSchema->Clone();
370 if (pClone) {
371 pClone->SetClass(pClass);
372 pClone->BuildOld();
373 pInfos->AddAtAndExpand(pClone, version);
374 AliDebug(0,Form("adding schema definition %d version %d to class %s", i, version, pSchema->GetName()));
375 } else {
376 AliError(Form("skipping schema definition %d (%s), unable to create clone object", i, pSchema->GetName()));
377 }
378 } else {
379 TStreamerInfo* pInfo=dynamic_cast<TStreamerInfo*>(pInfos->At(version));
380 if (pInfo && pInfo->GetClassVersion()==version) {
381 AliDebug(0,Form("schema definition %d version %d already available in class %s, skipping ...", i, version, pSchema->GetName()));
382 } else {
383 AliError(Form("can not verify version for already existing schema definition %d (%s) version %d: version of existing definition is %d", i, pSchema->GetName(), version, pInfo?pInfo->GetClassVersion():-1));
384 }
385 }
386 } else {
387 AliError(Form("skipping schema definition %d (%s), unable to set version %d in info array of size %d", i, pSchema->GetName(), version, pInfos?pInfos->GetEntriesFast():-1));
388 }
389 } else {
390 AliError(Form("skipping schema definition %d (%s), unable to find class", i, pSchema->GetName()));
391 }
392 } else {
393 AliError(Form("skipping schema definition %d, not of TStreamerInfo", i));
394 }
395 }
396 }
397
398 return 0;
399}
ee15809c 400
abb64a61 401int AliHLTMiscImplementation::MergeStreamerInfo(TObjArray* tgt, const TObjArray* src, int iVerbosity) const
402{
403 /// merge streamer info entries from source array to target array
404 /// return 1 if target array has been changed
405
406 // add all existing infos if not existing in the current one, or having
407 // different class version
408 int iResult=0;
409 if (!tgt || !src) return -EINVAL;
410
411 {
412 // check if all infos from the existing entry are in the new entry and with
413 // identical class version
414 TIter next(src);
415 TObject* nextobj=NULL;
416 while ((nextobj=next())) {
417 TStreamerInfo* srcInfo=dynamic_cast<TStreamerInfo*>(nextobj);
418 if (!srcInfo) continue;
419 TString srcInfoName=srcInfo->GetName();
420
421 int i=0;
422 for (; i<tgt->GetEntriesFast(); i++) {
423 if (tgt->At(i)==NULL) continue;
424 if (srcInfoName.CompareTo(tgt->At(i)->GetName())!=0) continue;
425 // TODO: 2010-08-23 some more detailed investigation is needed.
426 // Structures used for data exchange, e.g. AliHLTComponentDataType
427 // or AliHLTEventDDLV1 do not have a class version, but need to be stored in the
428 // streamer info. Strictly speaking not, because those structures are not supposed
429 // to be changed at all, so they should be the same in all versions in the future.
430 // There has been a problem with detecting whether the streamer info is already in
431 // the target array if the srcInfo has class version -1. As it just concerns
432 // structures not going to be changed we can safely skip checking the class version,
433 // as long as the entry is already in the target streamer infos it does not need
434 // to be copied again.
435 if (srcInfo->GetClassVersion()<0) break;
436 TStreamerInfo* tgtInfo=dynamic_cast<TStreamerInfo*>(tgt->At(i));
437 if (tgtInfo && tgtInfo->GetClassVersion()==srcInfo->GetClassVersion()) break;
438 }
439 if (i<tgt->GetEntriesFast()) continue;
440
441 iResult=1;
442 if (iVerbosity>0) {
443 AliInfo(Form("adding streamer info for class %s version %d", srcInfoName.Data(), srcInfo->GetClassVersion()));
444 }
445 tgt->Add(srcInfo);
446 }
447 }
448
449 return iResult;
450}
451
ee15809c 452void AliHLTMiscImplementation::SetAliESDtrackOnlineModeFlag(bool mode) const
453{
454 /// set the online mode flag of AliESDtrack
455 AliESDtrack::OnlineMode(mode);
456}
457
458bool AliHLTMiscImplementation::GetAliESDtrackOnlineModeFlag() const
459{
460 /// get status of the online mode flag of AliESDtrack
461 return AliESDtrack::OnlineMode();
462}