3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 //* for The ALICE HLT Project. *
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 //**************************************************************************
19 /** @file AliHLTCTPData.cxx
20 @author Matthias Richter
22 @brief Container for CTP trigger classes and counters
25 #include "AliHLTCTPData.h"
26 #include "AliHLTReadoutList.h"
28 #include "TObjString.h"
31 /** ROOT macro for the implementation of ROOT specific class methods */
32 ClassImp(AliHLTCTPData)
34 AliHLTCTPData::AliHLTCTPData()
35 : TNamed("AliHLTCTPData", "HLT counters for the CTP")
39 , fClassIds(AliHLTReadoutList::Class(), gkNCTPTriggerClasses)
40 , fCounters(gkNCTPTriggerClasses)
42 // see header file for class documentation
44 // refer to README to build package
46 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
49 AliHLTCTPData::AliHLTCTPData(const char* parameter)
50 : TNamed("AliHLTCTPData", "HLT counters for the CTP")
54 , fClassIds(AliHLTReadoutList::Class(), gkNCTPTriggerClasses)
55 , fCounters(gkNCTPTriggerClasses)
57 // see header file for class documentation
58 InitCTPTriggerClasses(parameter);
61 AliHLTCTPData::~AliHLTCTPData()
63 // see header file for class documentation
67 AliHLTCTPData::AliHLTCTPData(const AliHLTCTPData& src)
68 : TNamed(src.GetName(), src.GetTitle())
71 , fTriggers(src.fTriggers)
72 , fClassIds(src.fClassIds)
73 , fCounters(src.Counters())
75 // see header file for class documentation
78 AliHLTCTPData& AliHLTCTPData::operator=(const AliHLTCTPData& src)
80 // see header file for class documentation
82 SetName(src.GetName());
83 SetTitle(src.GetTitle());
86 fClassIds.ExpandCreate(gkNCTPTriggerClasses);
87 for (int i=0; i<gkNCTPTriggerClasses; i++) {
88 if (i>src.fClassIds.GetLast()) break;
89 ((TNamed*)fClassIds.At(i))->SetName(src.fClassIds.At(i)->GetName());
90 ((TNamed*)fClassIds.At(i))->SetTitle(src.fClassIds.At(i)->GetTitle());
92 fCounters=src.Counters();
98 int AliHLTCTPData::Add(const AliHLTCTPData& src, int factor, int &skipped)
100 // see header file for class documentation
103 for (int i=0; i<gkNCTPTriggerClasses; i++) {
105 c=fClassIds.At(i)->GetName();
106 if (c.IsNull()) continue;
107 if (c.CompareTo(src.fClassIds.At(i)->GetName())==0) {
108 fCounters[i]+=factor*src.Counter(i);
116 AliHLTCTPData& AliHLTCTPData::operator += (const AliHLTCTPData& src)
118 // see header file for class documentation
120 int nofInconsistencies=0;
121 Add(src, 1, nofInconsistencies);
122 if (nofInconsistencies>0) {
123 HLTError("Inconsistent operants: skipping %d of %d CTP classes for operation", nofInconsistencies, gkNCTPTriggerClasses);
128 AliHLTCTPData& AliHLTCTPData::operator -= (const AliHLTCTPData& src)
130 // see header file for class documentation
132 int nofInconsistencies=0;
133 Add(src, -1, nofInconsistencies);
134 if (nofInconsistencies>0) {
135 HLTError("Inconsistent operants: skipping %d of %d CTP classes for operation", nofInconsistencies, gkNCTPTriggerClasses);
140 AliHLTCTPData AliHLTCTPData::operator + (const AliHLTCTPData& src) const
142 // see header file for class documentation
144 AliHLTCTPData result(*this);
149 AliHLTCTPData AliHLTCTPData::operator - (const AliHLTCTPData& src) const
151 // see header file for class documentation
153 AliHLTCTPData result(*this);
158 int AliHLTCTPData::InitCTPTriggerClasses(const char* ctpString)
160 // see header file for function documentation
161 if (!ctpString) return -EINVAL;
163 HLTImportant("Parameter: %s", ctpString);
167 fClassIds.ExpandCreate(gkNCTPTriggerClasses);
169 // general format of the CTP_TRIGGER_CLASS parameter
170 // <bit position>:<Trigger class identifier string>:<detector-id-nr>-<detector-id-nr>-...,<bit position>:<Trigger class identifier string>:<detector-id-nr>-<detector-id-nr>-...,...
171 HLTDebug(": %s", ctpString);
172 TString string=ctpString;
173 if (string.BeginsWith("CTP_TRIGGER_CLASS=")) string.ReplaceAll("CTP_TRIGGER_CLASS=", "");
174 TObjArray* classEntries=string.Tokenize(",");
176 enum {kBit=0, kName, kDetectors};
177 for (int i=0; i<classEntries->GetEntriesFast(); i++) {
178 TString entry=((TObjString*)classEntries->At(i))->GetString();
179 TObjArray* entryParams=entry.Tokenize(":");
181 if (entryParams->GetEntriesFast()==3 &&
182 (((TObjString*)entryParams->At(kBit))->GetString()).IsDigit()) {
183 int index=(((TObjString*)entryParams->At(kBit))->GetString()).Atoi();
184 if (index<gkNCTPTriggerClasses) {
185 AliHLTReadoutList* pCTPClass=dynamic_cast<AliHLTReadoutList*>(fClassIds.At(index));
187 fMask|=(AliHLTUInt64_t)0x1 << index;
188 pCTPClass->SetTitle("CTP Class");
189 pCTPClass->SetName((((TObjString*)entryParams->At(kName))->GetString()).Data());
190 TObjArray* detectors=(((TObjString*)entryParams->At(kDetectors))->GetString()).Tokenize("-");
192 for (int dix=0; dix<detectors->GetEntriesFast(); dix++) {
193 if (!(((TObjString*)detectors->At(dix))->GetString()).IsDigit()) {
194 HLTError("invalid detector list format: trigger class entry %s", entry.Data());
197 // see AliHLTReadoutList::EDetectorId for defines of detectors
198 pCTPClass->Enable(0x1<<(((TObjString*)detectors->At(dix))->GetString()).Atoi());
205 // the trigger bitfield is fixed to 50 bits (gkNCTPTriggerClasses)
206 HLTError("invalid trigger class entry %s, index width of trigger bitfield exceeded (%d)", entry.Data(), gkNCTPTriggerClasses);
209 HLTError("invalid trigger class entry %s", entry.Data());
222 AliHLTUInt64_t AliHLTCTPData::ActiveTriggers(const AliHLTComponentTriggerData& trigData)
224 // extract active triggers from the trigger data
226 if (trigData.fDataSize != sizeof(AliHLTEventTriggerData)) return (AliHLTUInt64_t)0;
228 // trigger mask is 50 bit wide and is stored in word 5 and 6 of the CDH
229 AliHLTEventTriggerData* evtData=reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
230 AliHLTUInt64_t triggerMask=evtData->fCommonHeader[6]&0x3ffff;
232 triggerMask|=evtData->fCommonHeader[5];
236 bool AliHLTCTPData::EvaluateCTPTriggerClass(const char* expression, const AliHLTComponentTriggerData& trigData) const
238 // see header file for function documentation
239 if (trigData.fDataSize != sizeof(AliHLTEventTriggerData)) {
240 HLTError("invalid trigger data size: %d expected %d", trigData.fDataSize, sizeof(AliHLTEventTriggerData));
244 // trigger mask is 50 bit wide and is stored in word 5 and 6 of the CDH
245 AliHLTEventTriggerData* evtData=reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
246 AliHLTUInt64_t triggerMask=evtData->fCommonHeader[6]&0x3ffff;
248 triggerMask|=evtData->fCommonHeader[5];
250 if (fMask!=0 && (triggerMask & fMask)==0) {
251 HLTWarning("invalid trigger mask 0x%llx, unknown CTP trigger, initialized 0x%llx", triggerMask, fMask);
252 for (int i=0; i<8; i++) HLTWarning("\t CDH[%d]=0x%lx", i, evtData->fCommonHeader[i]);
256 return EvaluateCTPTriggerClass(expression, triggerMask);
259 bool AliHLTCTPData::EvaluateCTPTriggerClass(const char* expression, AliHLTUInt64_t triggerMask) const
261 // see header file for function documentation
263 // use a TFormula to interprete the expression
264 // all classname are replaced by '[n]' which means the n'th parameter in the formula
265 // the parameters are set to 0 or 1 depending on the bit in the trigger mask
267 // TODO: this will most likely fail for class names like 'base', 'baseA', 'baseB'
268 // the class names must be fully unique, none must be contained as substring in
269 // another class name. Probably not needed for the moment but needs to be extended.
270 vector<Double_t> par;
271 TString condition=expression;
272 for (int i=0; i<gkNCTPTriggerClasses; i++) {
273 const char* className=Name(i);
274 if (className && strlen(className)>0) {
275 //HLTDebug("checking trigger class %s", className.Data());
276 if (condition.Contains(className)) {
277 TString replace; replace.Form("[%d]", par.size());
278 //HLTDebug("replacing %s with %s in \"%s\"", className.Data(), replace.Data(), condition.Data());
279 condition.ReplaceAll(className, replace);
280 if (triggerMask&((AliHLTUInt64_t)0x1<<i)) par.push_back(1.0);
281 else par.push_back(0.0);
286 TFormula form("trigger expression", condition);
287 if (form.Compile()!=0) {
288 HLTError("invalid expression %s", expression);
291 if (form.EvalPar(&par[0], &par[0])>0.5) return true;
295 void AliHLTCTPData::ResetCounters()
297 // see header file for function documentation
298 fCounters.Set(gkNCTPTriggerClasses);
302 int AliHLTCTPData::Index(const char* name) const
304 // see header file for function documentation
305 TObject* obj=fClassIds.FindObject(name);
306 return obj!=NULL?fClassIds.IndexOf(obj):-1;
309 void AliHLTCTPData::Increment(const char* classIds)
311 // see header file for function documentation
312 TString string=classIds;
313 TObjArray* classEntries=string.Tokenize(",");
315 for (int i=0; i<classEntries->GetEntriesFast(); i++) {
316 int index=Index(((TObjString*)classEntries->At(i))->GetString().Data());
317 if (index>=0 && index<fCounters.GetSize()) fCounters[index]++;
323 void AliHLTCTPData::Increment(AliHLTUInt64_t triggerPattern)
325 // see header file for function documentation
326 AliHLTUInt64_t pattern=triggerPattern&fMask;
327 for (int i=0; i<fCounters.GetSize(); i++) {
328 if ((pattern&((AliHLTUInt64_t)0x1<<i))==0) continue;
333 void AliHLTCTPData::Increment(int classIdx)
335 // see header file for function documentation
336 if (classIdx<fCounters.GetSize() &&
337 (fMask&((AliHLTUInt64_t)0x1<<classIdx))) {
338 fCounters[classIdx]++;
343 int AliHLTCTPData::Increment(AliHLTComponentTriggerData& trigData)
345 // see header file for function documentation
346 if (trigData.fDataSize != sizeof(AliHLTEventTriggerData)) {
347 HLTError("invalid trigger data size: %d expected %d", trigData.fDataSize, sizeof(AliHLTEventTriggerData));
351 // trigger mask is 50 bit wide and is stored in word 5 and 6 of the CDH
352 AliHLTEventTriggerData* evtData=reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
353 AliHLTUInt64_t triggerMask=evtData->fCommonHeader[6]&0x3ffff;
355 triggerMask|=evtData->fCommonHeader[5];
357 if (fMask!=0 && (triggerMask & fMask)==0) {
358 HLTWarning("invalid trigger mask 0x%llx, unknown CTP trigger, initialized 0x%llx", triggerMask, fMask);
359 for (int i=0; i<8; i++) HLTWarning("\t CDH[%d]=0x%lx", i, evtData->fCommonHeader[i]);
361 Increment(triggerMask);
365 AliHLTUInt64_t AliHLTCTPData::Counter(int index) const
367 // see header file for function documentation
368 if (index>=0 && index<Counters().GetSize()) return Counters()[index];
372 AliHLTUInt64_t AliHLTCTPData::Counter(const char* classId) const
374 // see header file for function documentation
375 return Counter(Index(classId));
378 const char* AliHLTCTPData::Name(int index) const
380 // see header file for function documentation
381 if (index>fClassIds.GetLast()) return NULL;
382 return fClassIds.At(index)->GetName();
385 AliHLTEventDDL AliHLTCTPData::ReadoutList(const AliHLTComponentTriggerData& trigData) const
387 // see header file for function documentation
388 if (trigData.fDataSize != sizeof(AliHLTEventTriggerData)) {
389 HLTError("invalid trigger data size: %d expected %d", trigData.fDataSize, sizeof(AliHLTEventTriggerData));
390 AliHLTEventDDL dummy;
391 memset(&dummy, 0, sizeof(AliHLTEventDDL));
395 // trigger mask is 50 bit wide and is stored in word 5 and 6 of the CDH
396 AliHLTEventTriggerData* evtData=reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
397 AliHLTUInt64_t triggerMask=evtData->fCommonHeader[6]&0x3ffff;
399 triggerMask|=evtData->fCommonHeader[5];
401 if (fMask!=0 && (triggerMask & fMask)==0) {
402 HLTWarning("invalid trigger mask 0x%llx, unknown CTP trigger, initialized 0x%llx", triggerMask, fMask);
403 for (int i=0; i<8; i++) HLTWarning("\t CDH[%d]=0x%lx", i, evtData->fCommonHeader[i]);
406 return ReadoutList(triggerMask);
409 AliHLTEventDDL AliHLTCTPData::ReadoutList(AliHLTUInt64_t triggerMask) const
411 // take an 'OR' of all active trigger classes
412 AliHLTReadoutList list;
413 for (int i=0; i<gkNCTPTriggerClasses; i++) {
414 if (i>fClassIds.GetLast()) break;
415 if ((triggerMask&((AliHLTUInt64_t)0x1<<i))==0) continue;
416 AliHLTReadoutList* tcrl=(AliHLTReadoutList*)fClassIds.At(i);
424 void AliHLTCTPData::Print(Option_t* /*option*/) const
426 // see header file for function documentation
427 cout << GetTitle() << endl;
428 cout << "\tactive trigger mask: 0x" << hex << fTriggers << dec << endl;
430 for (int i=0; i<gkNCTPTriggerClasses; i++) {
431 if (i>=Counters().GetSize()) break;
432 if (i>fClassIds.GetLast()) break;
433 if ((fMask&((AliHLTUInt64_t)0x1<<i))==0) continue;
435 cout << "\t" << i << "\t" << Name(i) << "\t" << Counter(i) << endl;
437 if (count==0) cout << "\t(none)" << endl;