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 ((TNamed*)fClassIds.At(i))->SetName(src.fClassIds.At(i)->GetName());
89 ((TNamed*)fClassIds.At(i))->SetTitle(src.fClassIds.At(i)->GetTitle());
91 fCounters=src.Counters();
97 int AliHLTCTPData::Add(const AliHLTCTPData& src, int factor, int &skipped)
99 // see header file for class documentation
102 for (int i=0; i<gkNCTPTriggerClasses; i++) {
104 c=fClassIds.At(i)->GetName();
105 if (c.IsNull()) continue;
106 if (c.CompareTo(src.fClassIds.At(i)->GetName())==0) {
107 fCounters[i]+=factor*src.Counter(i);
115 AliHLTCTPData& AliHLTCTPData::operator += (const AliHLTCTPData& src)
117 // see header file for class documentation
119 int nofInconsistencies=0;
120 Add(src, 1, nofInconsistencies);
121 if (nofInconsistencies>0) {
122 HLTError("Inconsistent operants: skipping %d of %d CTP classes for operation", nofInconsistencies, gkNCTPTriggerClasses);
127 AliHLTCTPData& AliHLTCTPData::operator -= (const AliHLTCTPData& src)
129 // see header file for class documentation
131 int nofInconsistencies=0;
132 Add(src, -1, nofInconsistencies);
133 if (nofInconsistencies>0) {
134 HLTError("Inconsistent operants: skipping %d of %d CTP classes for operation", nofInconsistencies, gkNCTPTriggerClasses);
139 AliHLTCTPData AliHLTCTPData::operator + (const AliHLTCTPData& src) const
141 // see header file for class documentation
143 AliHLTCTPData result(*this);
148 AliHLTCTPData AliHLTCTPData::operator - (const AliHLTCTPData& src) const
150 // see header file for class documentation
152 AliHLTCTPData result(*this);
157 int AliHLTCTPData::InitCTPTriggerClasses(const char* ctpString)
159 // see header file for function documentation
160 if (!ctpString) return -EINVAL;
162 HLTImportant("Parameter: %s", ctpString);
166 fClassIds.ExpandCreate(gkNCTPTriggerClasses);
168 // general format of the CTP_TRIGGER_CLASS parameter
169 // <bit position>:<Trigger class identifier string>:<detector-id-nr>-<detector-id-nr>-...,<bit position>:<Trigger class identifier string>:<detector-id-nr>-<detector-id-nr>-...,...
170 HLTDebug(": %s", ctpString);
171 TString string=ctpString;
172 if (string.BeginsWith("CTP_TRIGGER_CLASS=")) string.ReplaceAll("CTP_TRIGGER_CLASS=", "");
173 TObjArray* classEntries=string.Tokenize(",");
175 enum {kBit=0, kName, kDetectors};
176 for (int i=0; i<classEntries->GetEntriesFast(); i++) {
177 TString entry=((TObjString*)classEntries->At(i))->GetString();
178 TObjArray* entryParams=entry.Tokenize(":");
180 if (entryParams->GetEntriesFast()==3 &&
181 (((TObjString*)entryParams->At(kBit))->GetString()).IsDigit()) {
182 int index=(((TObjString*)entryParams->At(kBit))->GetString()).Atoi();
183 if (index<gkNCTPTriggerClasses) {
184 AliHLTReadoutList* pCTPClass=dynamic_cast<AliHLTReadoutList*>(fClassIds.At(index));
186 fMask|=(AliHLTUInt64_t)0x1 << index;
187 pCTPClass->SetTitle("CTP Class");
188 pCTPClass->SetName((((TObjString*)entryParams->At(kName))->GetString()).Data());
189 TObjArray* detectors=(((TObjString*)entryParams->At(kDetectors))->GetString()).Tokenize("-");
191 for (int dix=0; dix<detectors->GetEntriesFast(); dix++) {
192 if (!(((TObjString*)detectors->At(dix))->GetString()).IsDigit()) {
193 HLTError("invalid detector list format: trigger class entry %s", entry.Data());
196 // see AliHLTReadoutList::EDetectorId for defines of detectors
197 pCTPClass->Enable(0x1<<(((TObjString*)detectors->At(dix))->GetString()).Atoi());
204 // the trigger bitfield is fixed to 50 bits (gkNCTPTriggerClasses)
205 HLTError("invalid trigger class entry %s, index width of trigger bitfield exceeded (%d)", entry.Data(), gkNCTPTriggerClasses);
208 HLTError("invalid trigger class entry %s", entry.Data());
221 AliHLTUInt64_t AliHLTCTPData::ActiveTriggers(const AliHLTComponentTriggerData& trigData)
223 // extract active triggers from the trigger data
225 if (trigData.fDataSize != sizeof(AliHLTEventTriggerData)) return (AliHLTUInt64_t)0;
227 // trigger mask is 50 bit wide and is stored in word 5 and 6 of the CDH
228 AliHLTEventTriggerData* evtData=reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
229 AliHLTUInt64_t triggerMask=evtData->fCommonHeader[6]&0x3ffff;
231 triggerMask|=evtData->fCommonHeader[5];
235 bool AliHLTCTPData::EvaluateCTPTriggerClass(const char* expression, const AliHLTComponentTriggerData& trigData) const
237 // see header file for function documentation
238 if (trigData.fDataSize != sizeof(AliHLTEventTriggerData)) {
239 HLTError("invalid trigger data size: %d expected %d", trigData.fDataSize, sizeof(AliHLTEventTriggerData));
243 // trigger mask is 50 bit wide and is stored in word 5 and 6 of the CDH
244 AliHLTEventTriggerData* evtData=reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
245 AliHLTUInt64_t triggerMask=evtData->fCommonHeader[6]&0x3ffff;
247 triggerMask|=evtData->fCommonHeader[5];
249 if (fMask!=0 && (triggerMask & fMask)==0) {
250 HLTWarning("invalid trigger mask 0x%llx, unknown CTP trigger, initialized 0x%llx", triggerMask, fMask);
251 for (int i=0; i<8; i++) HLTWarning("\t CDH[%d]=0x%lx", i, evtData->fCommonHeader[i]);
255 return EvaluateCTPTriggerClass(expression, triggerMask);
258 bool AliHLTCTPData::EvaluateCTPTriggerClass(const char* expression, AliHLTUInt64_t triggerMask) const
260 // see header file for function documentation
262 // use a TFormula to interprete the expression
263 // all classname are replaced by '[n]' which means the n'th parameter in the formula
264 // the parameters are set to 0 or 1 depending on the bit in the trigger mask
266 // TODO: this will most likely fail for class names like 'base', 'baseA', 'baseB'
267 // the class names must be fully unique, none must be contained as substring in
268 // another class name. Probably not needed for the moment but needs to be extended.
269 vector<Double_t> par;
270 TString condition=expression;
271 for (int i=0; i<gkNCTPTriggerClasses; i++) {
272 const char* className=Name(i);
273 if (className && strlen(className)>0) {
274 //HLTDebug("checking trigger class %s", className.Data());
275 if (condition.Contains(className)) {
276 TString replace; replace.Form("[%d]", par.size());
277 //HLTDebug("replacing %s with %s in \"%s\"", className.Data(), replace.Data(), condition.Data());
278 condition.ReplaceAll(className, replace);
279 if (triggerMask&((AliHLTUInt64_t)0x1<<i)) par.push_back(1.0);
280 else par.push_back(0.0);
285 TFormula form("trigger expression", condition);
286 if (form.Compile()!=0) {
287 HLTError("invalid expression %s", expression);
290 if (form.EvalPar(&par[0], &par[0])>0.5) return true;
294 void AliHLTCTPData::ResetCounters()
296 // see header file for function documentation
297 fCounters.Set(gkNCTPTriggerClasses);
301 int AliHLTCTPData::Index(const char* name) const
303 // see header file for function documentation
304 TObject* obj=fClassIds.FindObject(name);
305 return obj!=NULL?fClassIds.IndexOf(obj):-1;
308 void AliHLTCTPData::Increment(const char* classIds)
310 // see header file for function documentation
311 TString string=classIds;
312 TObjArray* classEntries=string.Tokenize(",");
314 for (int i=0; i<classEntries->GetEntriesFast(); i++) {
315 int index=Index(((TObjString*)classEntries->At(i))->GetString().Data());
316 if (index>=0 && index<fCounters.GetSize()) fCounters[index]++;
322 void AliHLTCTPData::Increment(AliHLTUInt64_t triggerPattern)
324 // see header file for function documentation
325 AliHLTUInt64_t pattern=triggerPattern&fMask;
326 for (int i=0; i<fCounters.GetSize(); i++) {
327 if ((pattern&((AliHLTUInt64_t)0x1<<i))==0) continue;
332 void AliHLTCTPData::Increment(int classIdx)
334 // see header file for function documentation
335 if (classIdx<fCounters.GetSize() &&
336 (fMask&((AliHLTUInt64_t)0x1<<classIdx))) {
337 fCounters[classIdx]++;
342 int AliHLTCTPData::Increment(AliHLTComponentTriggerData& trigData)
344 // see header file for function documentation
345 if (trigData.fDataSize != sizeof(AliHLTEventTriggerData)) {
346 HLTError("invalid trigger data size: %d expected %d", trigData.fDataSize, sizeof(AliHLTEventTriggerData));
350 // trigger mask is 50 bit wide and is stored in word 5 and 6 of the CDH
351 AliHLTEventTriggerData* evtData=reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
352 AliHLTUInt64_t triggerMask=evtData->fCommonHeader[6]&0x3ffff;
354 triggerMask|=evtData->fCommonHeader[5];
356 if (fMask!=0 && (triggerMask & fMask)==0) {
357 HLTWarning("invalid trigger mask 0x%llx, unknown CTP trigger, initialized 0x%llx", triggerMask, fMask);
358 for (int i=0; i<8; i++) HLTWarning("\t CDH[%d]=0x%lx", i, evtData->fCommonHeader[i]);
360 Increment(triggerMask);
364 AliHLTUInt64_t AliHLTCTPData::Counter(int index) const
366 // see header file for function documentation
367 if (index>=0 && index<Counters().GetSize()) return Counters()[index];
371 AliHLTUInt64_t AliHLTCTPData::Counter(const char* classId) const
373 // see header file for function documentation
374 return Counter(Index(classId));
377 const char* AliHLTCTPData::Name(int index) const
379 // see header file for function documentation
380 if (index>fClassIds.GetLast()) return NULL;
381 return fClassIds.At(index)->GetName();
384 AliHLTEventDDL AliHLTCTPData::ReadoutList(const AliHLTComponentTriggerData& trigData) const
386 // see header file for function documentation
387 if (trigData.fDataSize != sizeof(AliHLTEventTriggerData)) {
388 HLTError("invalid trigger data size: %d expected %d", trigData.fDataSize, sizeof(AliHLTEventTriggerData));
389 AliHLTEventDDL dummy;
390 memset(&dummy, 0, sizeof(AliHLTEventDDL));
394 // trigger mask is 50 bit wide and is stored in word 5 and 6 of the CDH
395 AliHLTEventTriggerData* evtData=reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
396 AliHLTUInt64_t triggerMask=evtData->fCommonHeader[6]&0x3ffff;
398 triggerMask|=evtData->fCommonHeader[5];
400 if (fMask!=0 && (triggerMask & fMask)==0) {
401 HLTWarning("invalid trigger mask 0x%llx, unknown CTP trigger, initialized 0x%llx", triggerMask, fMask);
402 for (int i=0; i<8; i++) HLTWarning("\t CDH[%d]=0x%lx", i, evtData->fCommonHeader[i]);
405 return ReadoutList(triggerMask);
408 AliHLTEventDDL AliHLTCTPData::ReadoutList(AliHLTUInt64_t triggerMask) const
410 // take an 'OR' of all active trigger classes
411 AliHLTReadoutList list;
412 for (int i=0; i<gkNCTPTriggerClasses; i++) {
413 if (i>fClassIds.GetLast()) break;
414 if ((triggerMask&((AliHLTUInt64_t)0x1<<i))==0) continue;
415 AliHLTReadoutList* tcrl=(AliHLTReadoutList*)fClassIds.At(i);
423 void AliHLTCTPData::Print(Option_t* /*option*/) const
425 // see header file for function documentation
426 cout << GetTitle() << endl;
427 cout << "\tactive trigger mask: 0x" << hex << fTriggers << dec << endl;
429 for (int i=0; i<gkNCTPTriggerClasses; i++) {
430 if (i>=Counters().GetSize()) break;
431 if (i>fClassIds.GetLast()) break;
432 if ((fMask&((AliHLTUInt64_t)0x1<<i))==0) continue;
434 cout << "\t" << i << "\t" << Name(i) << "\t" << Counter(i) << endl;
436 if (count==0) cout << "\t(none)" << endl;