]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTTriggerMenu.cxx
bugfix: correct range of DDL for specified detector
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTTriggerMenu.cxx
1 // $Id$
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: Artur Szostak <artursz@iafrica.com>                   *
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   AliHLTTriggerMenu.cxx
19 /// @author Artur Szostak <artursz@iafrica.com>
20 /// @date   19 Dec 2008
21 /// @brief  Implementation of the AliHLTTriggerMenu base class.
22 ///
23 /// The AliHLTTriggerMenu class implements the HLT global trigger menu,
24 /// which defines how and on what events the HLT triggers.
25
26 #include "AliHLTTriggerMenu.h"
27 #include "Riostream.h"
28 #include <sstream>
29
30 ClassImp(AliHLTTriggerMenu)
31
32
33 AliHLTTriggerMenu::AliHLTTriggerMenu() :
34   TObject(),
35   fName("Unknown"),
36   fSymbols(AliHLTTriggerMenuSymbol::Class(), 100),
37   fItems(AliHLTTriggerMenuItem::Class(), 100),
38   fDefaultDescription(),
39   fDefaultDomain(),
40   fDefaultConditionOperator("||"),
41   fDefaultDomainOperator("|")
42 {
43   // Default constructor.
44 }
45
46
47 AliHLTTriggerMenu::~AliHLTTriggerMenu()
48 {
49   // Default destructor.
50 }
51
52
53 AliHLTTriggerMenu::AliHLTTriggerMenu(const AliHLTTriggerMenu& obj) :
54   TObject(obj),
55   fName(obj.fName),
56   fSymbols(AliHLTTriggerMenuSymbol::Class(), obj.fSymbols.GetEntriesFast()),
57   fItems(AliHLTTriggerMenuItem::Class(), obj.fItems.GetEntriesFast()),
58   fDefaultDescription(obj.fDefaultDescription),
59   fDefaultDomain(obj.fDefaultDomain),
60   fDefaultConditionOperator(obj.fDefaultConditionOperator),
61   fDefaultDomainOperator(obj.fDefaultDomainOperator)
62 {
63   // Copy constructor performs a deep copy.
64   
65   for (UInt_t i = 0; i < obj.NumberOfSymbols(); i++)
66   {
67     AddSymbol(*obj.Symbol(i));
68   }
69   for (UInt_t i = 0; i < obj.NumberOfItems(); i++)
70   {
71     AddItem(*obj.Item(i));
72   }
73 }
74
75
76 AliHLTTriggerMenu& AliHLTTriggerMenu::operator = (const AliHLTTriggerMenu& obj)
77 {
78   // Assignment operator performs a deep copy.
79   
80   if (this != &obj)
81   {
82     TObject::operator = (obj);
83     fName = obj.fName;
84     fSymbols.Clear();
85     for (UInt_t i = 0; i < obj.NumberOfSymbols(); i++)
86     {
87       AddSymbol(*obj.Symbol(i));
88     }
89     fItems.Clear();
90     for (UInt_t i = 0; i < obj.NumberOfItems(); i++)
91     {
92       AddItem(*obj.Item(i));
93     }
94     fDefaultDescription = obj.fDefaultDescription;
95     fDefaultDomain = obj.fDefaultDomain;
96     fDefaultConditionOperator = obj.fDefaultConditionOperator;
97     fDefaultDomainOperator = obj.fDefaultDomainOperator;
98   }
99   return *this;
100 }
101
102
103 void AliHLTTriggerMenu::Print(Option_t* option) const
104 {
105   // Prints the contents of the trigger menu.
106   
107   cout << "HLT Trigger Menu: " << fName.Data();
108   TString opt = option;
109   if (opt.Contains("short"))
110   {
111     cout << ", contains " << NumberOfItems() << " entries." << endl;
112     return;
113   }
114   cout << endl;
115   
116   size_t prescalarColWidth = 9;
117   size_t scaledownColWidth = 9;
118   size_t priorityColWidth = 8;
119   size_t resultColWidth = 6;
120   size_t conditionColWidth = 17;
121   size_t mergexprColWidth = 23;
122   size_t descColWidth = 11;
123   // Find out the required widths of the columns:
124   for (UInt_t i = 0; i < NumberOfItems(); i++)
125   {
126     std::stringstream buf;
127     buf.copyfmt(cout);
128     buf << Item(i)->PreScalar();
129     if (buf.str().length() > prescalarColWidth) prescalarColWidth = buf.str().length();
130     buf.str("");
131     buf << Item(i)->ScaleDown();
132     if (buf.str().length()+1 > scaledownColWidth) scaledownColWidth = buf.str().length()+1;
133     buf.str("");
134     buf << Item(i)->Priority();
135     if (buf.str().length() > priorityColWidth) priorityColWidth = buf.str().length();
136     size_t len = strlen(Item(i)->TriggerCondition());
137     if (len > conditionColWidth and len < 128) conditionColWidth = len;
138     len = strlen(Item(i)->MergeExpression());
139     if (len > mergexprColWidth and len < 128) mergexprColWidth = len;
140     len = strlen(Item(i)->Description());
141     if (len > descColWidth and len < 128) descColWidth = len;
142   }
143   cout << setw(prescalarColWidth) << "Prescalar" << " | "
144        << setw(scaledownColWidth) << "Scaledown" << " | "
145        << setw(priorityColWidth) << "Priority" << " | "
146        << setw(resultColWidth) << "Result" << " | "
147        << setw(conditionColWidth) << "Trigger condition" << " | "
148        << setw(mergexprColWidth) << "Domain merge expression" << " | "
149        << setw(descColWidth) << "Description" << setw(0) << endl;
150   cout << setfill('-') << setw(prescalarColWidth) << "-" << "-+-"
151        << setw(scaledownColWidth) << "-" << "-+-"
152        << setw(priorityColWidth) << "-" << "-+-"
153        << setw(resultColWidth) << "-" << "-+-"
154        << setw(conditionColWidth) << "-" << "-+-"
155        << setw(mergexprColWidth) << "-" << "-+-"
156        << setw(descColWidth) << "-" << setw(0) << setfill(' ') << endl;
157   for (UInt_t i = 0; i < NumberOfItems(); i++)
158   {
159     if (Item(i)->PreScalar() == 0)
160       cout << setw(prescalarColWidth) << "off" << " | ";
161     else
162       cout << setw(prescalarColWidth) << Item(i)->PreScalar() << " | ";
163     if (Item(i)->ScaleDown() == 1)
164       cout << setw(scaledownColWidth) << "none" << " | ";
165     else
166       cout << setw(scaledownColWidth-1) << Item(i)->ScaleDown()*100 << "% | ";
167     cout << setw(priorityColWidth) << Item(i)->Priority() << " | "
168          << setw(resultColWidth) << (Item(i)->DefaultResult() ? "true" : "false") << " | "
169          << setw(conditionColWidth) << Item(i)->TriggerCondition() << " | "
170          << setw(mergexprColWidth) << Item(i)->MergeExpression() << " | "
171          << setw(descColWidth) << Item(i)->Description() << setw(0) << endl;
172   }
173   if (NumberOfItems() == 0) cout << "(none)" << endl;
174   
175   cout << "Symbol list:" << endl;
176   size_t nameColWidth = 4;
177   size_t typeColWidth = 9;
178   size_t classColWidth = 10;
179   size_t assignColWidth = 14;
180   size_t valueColWidth = 13;
181   // Find out the required widths of the columns:
182   for (UInt_t i = 0; i < NumberOfSymbols(); i++)
183   {
184     size_t len = strlen(Symbol(i)->RealName());
185     if (len > nameColWidth and len < 128) nameColWidth = len;
186     len = strlen(Symbol(i)->Type());
187     if (len > typeColWidth and len < 128) typeColWidth = len;
188     len = strlen(Symbol(i)->ObjectClass());
189     if (len > classColWidth and len < 128) classColWidth = len;
190     len = strlen(Symbol(i)->AssignExpression());
191     if (len > assignColWidth and len < 128) assignColWidth = len;
192     len = strlen(Symbol(i)->DefaultValue());
193     if (len > valueColWidth and len < 128) valueColWidth = len;
194   }
195   cout << setw(nameColWidth) << "Name"
196        << " | " << setw(typeColWidth) << "Data type"
197        << " | " << setw(24) << "Block type & spec"
198        << " | " << setw(classColWidth) << "Class name"
199        << " | " << setw(assignColWidth) << "Assigned value"
200        << " | " << setw(valueColWidth) << "Default value"
201        << setw(0) << endl;
202   cout << setw(nameColWidth) << setfill('-') << "-"
203        << "-+-" << setw(typeColWidth) << "-"
204        << "-+-" << setw(24) << "-"
205        << "-+-" << setw(classColWidth) << "-"
206        << "-+-" << setw(assignColWidth) << "-"
207        << "-+-" << setw(valueColWidth) << "-"
208        << setw(0) << setfill(' ') << endl;
209   for (UInt_t i = 0; i < NumberOfSymbols(); i++)
210   {
211     cout << setw(nameColWidth) << Symbol(i)->RealName() << " | "
212          << setw(typeColWidth) << Symbol(i)->Type() << " | ";
213     Symbol(i)->BlockType().Print("noendl");
214     cout << " | " << setw(classColWidth) << Symbol(i)->ObjectClass()
215          << " | " << setw(assignColWidth) << Symbol(i)->AssignExpression()
216          << " | " << setw(valueColWidth) << Symbol(i)->DefaultValue()
217          << setw(0) << endl;
218   }
219   if (NumberOfSymbols() == 0) cout << "(none)" << endl;
220   
221   cout << "Default trigger condition operator: " << fDefaultConditionOperator << endl;
222   cout << "   Default trigger domain operator: " << fDefaultDomainOperator << endl;
223   cout << "       Default trigger description: \"" << fDefaultDescription << "\"" << endl;
224   cout << "     Default global trigger result: " << (DefaultResult() ? "true" : "false") << "" << endl;
225   cout << "Default "; fDefaultDomain.Print();
226 }
227
228
229 void AliHLTTriggerMenu::Clear(Option_t* option)
230 {
231   // Clears the internal symbol and items arrays.
232   
233   fSymbols.Clear(option);
234   fItems.Clear(option);
235 }
236
237
238 void AliHLTTriggerMenu::AddSymbol(const AliHLTTriggerMenuSymbol& entry)
239 {
240   // Adds a new symbol to the trigger menu.
241   
242   for (Int_t i = 0; i < fSymbols.GetEntriesFast(); i++)
243   {
244     const char* symbolname = static_cast<AliHLTTriggerMenuSymbol*>(fSymbols.UncheckedAt(i))->Name();
245     if ( strcmp(symbolname, entry.Name()) == 0 )
246     {
247       Warning("AliHLTTriggerMenu::AddSymbol",
248               "The symbol '%s' already exists in the trigger menu. Will not add the new entry.",
249               entry.RealName()
250              );
251       return;
252     }
253   }
254   new (fSymbols[fSymbols.GetEntriesFast()]) AliHLTTriggerMenuSymbol(entry);
255 }
256