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 //* Timm Steinbeck <timm@kip.uni-heidelberg.de> *
9 //* for The ALICE HLT Project. *
11 //* Permission to use, copy, modify and distribute this software and its *
12 //* documentation strictly for non-commercial purposes is hereby granted *
13 //* without fee, provided that the above copyright notice appears in all *
14 //* copies and that both the copyright notice and this permission notice *
15 //* appear in the supporting documentation. The authors make no claims *
16 //* about the suitability of this software for any purpose. It is *
17 //* provided "as is" without express or implied warranty. *
18 //**************************************************************************
20 /** @file AliHLTCTPData.cxx
21 @author Matthias Richter
23 @brief Container for CTP trigger classes and counters
26 #include "AliHLTCTPData.h"
29 #include "TObjString.h"
32 /** ROOT macro for the implementation of ROOT specific class methods */
33 ClassImp(AliHLTCTPData)
35 AliHLTCTPData::AliHLTCTPData()
36 : TNamed("AliHLTCTPData", "HLT counters for the CTP")
39 , fClassIds(TNamed::Class(), 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")
53 , fClassIds(TNamed::Class(), gkNCTPTriggerClasses)
56 // see header file for class documentation
57 InitCTPTriggerClasses(parameter);
60 AliHLTCTPData::~AliHLTCTPData()
62 // see header file for class documentation
66 int AliHLTCTPData::InitCTPTriggerClasses(const char* ctpString)
68 // see header file for function documentation
69 if (!ctpString) return -EINVAL;
73 fClassIds.ExpandCreate(gkNCTPTriggerClasses);
75 // general format of the CTP_TRIGGER_CLASS parameter
76 // <bit position>:<Trigger class identifier string>:<detector-id-nr>-<detector-id-nr>-...,<bit position>:<Trigger class identifier string>:<detector-id-nr>-<detector-id-nr>-...,...
77 // the detector ids are ignored for the moment
78 HLTDebug(": %s", ctpString);
79 TString string=ctpString;
80 TObjArray* classEntries=string.Tokenize(",");
82 for (int i=0; i<classEntries->GetEntries(); i++) {
83 TString entry=((TObjString*)classEntries->At(i))->GetString();
84 TObjArray* entryParams=entry.Tokenize(":");
86 if (entryParams->GetEntries()==3 &&
87 (((TObjString*)entryParams->At(0))->GetString()).IsDigit()) {
88 int index=(((TObjString*)entryParams->At(0))->GetString()).Atoi();
89 if (index<gkNCTPTriggerClasses) {
90 fMask|=(AliHLTUInt64_t)0x1 << index;
91 ((TNamed*)fClassIds.At(index))->SetTitle("TriggerClass");
92 ((TNamed*)fClassIds.At(index))->SetName((((TObjString*)entryParams->At(1))->GetString()).Data());
94 // the trigger bitfield is fixed to 50 bits (gkNCTPTriggerClasses)
95 HLTError("invalid trigger class entry %s, index width of trigger bitfield", entry.Data());
98 HLTError("invalid trigger class entry %s", entry.Data());
111 bool AliHLTCTPData::EvaluateCTPTriggerClass(const char* expression, AliHLTComponentTriggerData& trigData) const
113 // see header file for function documentation
114 if (trigData.fDataSize != sizeof(AliHLTEventTriggerData)) {
115 HLTError("invalid trigger data size: %d expected %d", trigData.fDataSize, sizeof(AliHLTEventTriggerData));
119 // trigger mask is 50 bit wide and is stored in word 5 and 6 of the CDH
120 AliHLTEventTriggerData* evtData=reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
121 AliHLTUInt64_t triggerMask=evtData->fCommonHeader[6];
123 triggerMask|=evtData->fCommonHeader[5];
125 if (fMask!=0 && (triggerMask & fMask)==0) {
126 HLTWarning("invalid trigger mask 0x%llx, unknown CTP trigger", triggerMask);
130 // use a TFormula to interprete the expression
131 // all classname are replaced by '[n]' which means the n'th parameter in the formula
132 // the parameters are set to 0 or 1 depending on the bit in the trigger mask
134 // TODO: this will most likely fail for class names like 'base', 'baseA', 'baseB'
135 // the class names must be fully unique, none must be contained as substring in
136 // another class name. Probably not needed for the moment but needs to be extended.
137 vector<Double_t> par;
138 TString condition=expression;
139 for (int i=0; i<gkNCTPTriggerClasses; i++) {
140 const char* className=Name(i);
141 if (className && strlen(className)>0) {
142 //HLTDebug("checking trigger class %s", className.Data());
143 if (condition.Contains(className)) {
144 TString replace; replace.Form("[%d]", par.size());
145 //HLTDebug("replacing %s with %s in \"%s\"", className.Data(), replace.Data(), condition.Data());
146 condition.ReplaceAll(className, replace);
147 if (triggerMask&((AliHLTUInt64_t)0x1<<i)) par.push_back(1.0);
148 else par.push_back(0.0);
153 TFormula form("trigger expression", condition);
154 if (form.Compile()!=0) {
155 HLTError("invalid expression %s", expression);
158 if (form.EvalPar(&par[0], &par[0])>0.5) return true;
162 void AliHLTCTPData::ResetCounters()
164 // see header file for function documentation
165 fCounters.Set(gkNCTPTriggerClasses);
169 int AliHLTCTPData::Index(const char* name) const
171 // see header file for function documentation
172 TObject* obj=fClassIds.FindObject(name);
173 return obj!=NULL?fClassIds.IndexOf(obj):-1;
176 void AliHLTCTPData::Increment(const char* classIds)
178 // see header file for function documentation
179 TString string=classIds;
180 TObjArray* classEntries=string.Tokenize(",");
182 for (int i=0; i<classEntries->GetEntries(); i++) {
183 int index=Index(((TObjString*)classEntries->At(i))->GetString().Data());
184 if (index>=0 && index<fCounters.GetSize()) fCounters[index]++;
190 void AliHLTCTPData::Increment(AliHLTUInt64_t triggerPattern)
192 // see header file for function documentation
193 AliHLTUInt64_t pattern=triggerPattern&fMask;
194 for (int i=0; i<fCounters.GetSize(); i++) {
195 if ((pattern&((AliHLTUInt64_t)0x1<<i))==0) continue;
200 void AliHLTCTPData::Increment(int classIdx)
202 // see header file for function documentation
203 if (classIdx<fCounters.GetSize() &&
204 (fMask&((AliHLTUInt64_t)0x1<<classIdx))) {
205 fCounters[classIdx]++;
210 int AliHLTCTPData::Increment(AliHLTComponentTriggerData& trigData)
212 // see header file for function documentation
213 if (trigData.fDataSize != sizeof(AliHLTEventTriggerData)) {
214 HLTError("invalid trigger data size: %d expected %d", trigData.fDataSize, sizeof(AliHLTEventTriggerData));
218 // trigger mask is 50 bit wide and is stored in word 5 and 6 of the CDH
219 AliHLTEventTriggerData* evtData=reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
220 AliHLTUInt64_t triggerMask=evtData->fCommonHeader[6];
222 triggerMask|=evtData->fCommonHeader[5];
224 if (fMask!=0 && (triggerMask & fMask)==0) {
225 HLTWarning("invalid trigger mask 0x%llx, unknown CTP trigger, initialized 0x%llx", triggerMask, fMask);
227 Increment(triggerMask);
231 AliHLTUInt64_t AliHLTCTPData::Counter(int index) const
233 // see header file for function documentation
234 if (index>=0 && index<Counters().GetSize()) return Counters()[index];
238 AliHLTUInt64_t AliHLTCTPData::Counter(const char* classId) const
240 // see header file for function documentation
241 return Counter(Index(classId));
244 const char* AliHLTCTPData::Name(int index) const
246 // see header file for function documentation
247 if (index>fClassIds.GetLast()) return NULL;
248 return fClassIds.At(index)->GetName();
251 void AliHLTCTPData::Print(Option_t* /*option*/) const
253 // see header file for function documentation
254 cout << "CTP counters:" << endl;
256 for (int i=0; i<gkNCTPTriggerClasses; i++) {
257 if (i>=Counters().GetSize()) break;
258 if (i>fClassIds.GetLast()) break;
259 if ((fMask&((AliHLTUInt64_t)0x1<<i))==0) continue;
261 cout << "\t" << i << "\t" << Name(i) << "\t" << Counter(i) << endl;
263 if (count==0) cout << "\t(none)" << endl;