]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/util/AliHLTMonitoringRelay.cxx
bugfix AliHLTCompStatCollector: filling entry 'Level' of the component statistics...
[u/mrichter/AliRoot.git] / HLT / BASE / util / AliHLTMonitoringRelay.cxx
1 // $Id$
2
3 //**************************************************************************
4 //* This file is property of and copyright by the                          * 
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   AliHLTMonitoringRelay.cxx
20 /// @author Matthias Richter
21 /// @date   2009-11-11
22 /// @brief  Relay components for monitoring objects.
23 ///
24
25 #include <cstdlib>
26 #include <cassert>
27 #include "AliHLTMonitoringRelay.h"
28 #include "AliHLTMessage.h"
29 #include "TArrayC.h"
30 #include "TObject.h"
31 #include "TDatime.h"
32
33 /** ROOT macro for the implementation of ROOT specific class methods */
34 ClassImp(AliHLTMonitoringRelay)
35
36 AliHLTMonitoringRelay::AliHLTMonitoringRelay()
37   : AliHLTProcessor()
38   , fItems()
39   , fOutputSize()
40   , fFlags(0)
41 {
42   // A relay component for monitoring data objects.
43   // It keeps a copy of the last block of every parent and forwards all
44   // the blocks together. By that, the output of histograms (rarely to
45   // be published but for every event filled.
46   //
47   // Component ID: \b MonitoringRelay
48   // Library: \b libAliHLTUtil.so
49   // Input Data Types: kAliHLTAnyDataType
50   // Output Data Types: according to input blocks
51 }
52
53 AliHLTMonitoringRelay::~AliHLTMonitoringRelay()
54 {
55   // destructor
56 }
57
58 void AliHLTMonitoringRelay::GetInputDataTypes(AliHLTComponentDataTypeList& list)
59 {
60   // overloaded from AliHLTComponent
61   list.clear();
62   list.push_back(kAliHLTAnyDataType);
63 }
64
65 AliHLTComponentDataType AliHLTMonitoringRelay::GetOutputDataType()
66 {
67   // overloaded from AliHLTComponent
68   return kAliHLTAnyDataType;
69 }
70
71 void AliHLTMonitoringRelay::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
72 {
73   // overloaded from AliHLTComponent
74   constBase=fOutputSize;
75   inputMultiplier=1.0;
76 }
77
78 int AliHLTMonitoringRelay::DoInit( int argc, const char** argv )
79 {
80   // overloaded from AliHLTComponent: initialization
81   int iResult=0;
82   fOutputSize=0;
83
84   iResult=ConfigureFromArgumentString(argc, argv);
85
86   return iResult;
87 }
88
89 int AliHLTMonitoringRelay::ScanConfigurationArgument(int argc, const char** argv)
90 {
91   // overloaded from AliHLTComponent: argument scan
92   if (argc<=0) return 0;
93   int i=0;
94   TString argument=argv[i];
95
96   // -verbose
97   if (argument.CompareTo("-verbose")==0) {
98     // 
99     return 1;
100   } else if (argument.CompareTo("-check-object")==0) { // check the objects in the blocks
101     SetFlag(kCheckObject);
102     return 1;
103   }
104
105   return 0;
106 }
107
108 int AliHLTMonitoringRelay::DoDeinit()
109 {
110   // overloaded from AliHLTComponent: cleanup
111   int iResult=0;
112   AliHLTMonitoringItemPList::iterator element=fItems.begin();
113   while (element!=fItems.end()) {
114     AliHLTMonitoringItem* pItem=*element;
115     element=fItems.erase(element);
116     if (pItem) {
117       delete pItem;
118     }
119   }
120   return iResult;
121 }
122
123 int AliHLTMonitoringRelay::DoEvent(const AliHLTComponentEventData& /*evtData*/,
124                                    AliHLTComponentTriggerData& /*trigData*/)
125 {
126   // overloaded from AliHLTProcessor: event processing
127   int iResult=0;
128   for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock();
129        pBlock!=NULL; 
130        pBlock=GetNextInputBlock()) {
131     // ignore private blocks
132     if (pBlock->fDataType==(kAliHLTAnyDataType|kAliHLTDataOriginPrivate)) continue;
133     TObject* pObject=NULL;
134     if (CheckFlag(kCheckObject)) pObject=AliHLTMessage::Extract(pBlock->fPtr, pBlock->fSize);
135     
136     AliHLTMonitoringItem* pItem=FindItem(pBlock, pObject);
137     if (pItem) {
138       HLTInfo("found block %s 0x%0lx %s %s", DataType2Text(pItem->GetDataType()).c_str(), pItem->GetSpecification(), pObject?pObject->GetName():"", pObject?pObject->GetName():"");
139       if (pItem->GetSize()<pBlock->fSize) {
140         // update with the new maximum
141         assert(fOutputSize>=pItem->GetSize());
142         fOutputSize-=pItem->GetSize();
143         fOutputSize+=pBlock->fSize;
144       }
145       pItem->SetData(pBlock->fPtr, pBlock->fSize);
146       HLTInfo("setting item size %d, total size %d", pItem->GetSize(), fOutputSize);
147     } else {
148       pItem=new AliHLTMonitoringItem(pBlock, pObject);
149       fItems.push_back(pItem);
150       fOutputSize+=pBlock->fSize;
151       HLTInfo("new item size %d (%d),  %s 0x%0lx %s %s", pItem->GetSize(), fOutputSize, DataType2Text(pItem->GetDataType()).c_str(), pItem->GetSpecification(), pObject?pObject->GetName():"", pObject?pObject->GetName():"");
152     }
153     if (pObject) delete pObject;
154   }
155
156   int nofObjects=0;
157   for (AliHLTMonitoringItemPList::iterator element=fItems.begin();
158        element!=fItems.end(); element++) {
159     AliHLTMonitoringItem* pItem=*element;
160     if (pItem) {
161       HLTInfo("push back item size %d (%d),  %s 0x%0lx", pItem->GetSize(), fOutputSize, DataType2Text(pItem->GetDataType()).c_str(), pItem->GetSpecification());
162       PushBack(pItem->GetBuffer(), pItem->GetSize(), pItem->GetDataType(), pItem->GetSpecification());
163       if (!pItem->GetObjectName().IsNull()) nofObjects++;
164     }
165   }
166   // info output once every 5 seconds
167   const TDatime time;
168   static UInt_t lastTime=0;
169   if (time.Get()-lastTime>5) {
170       lastTime=time.Get();
171       HLTBenchmark("accumulated %d items containing %d TObjects", fItems.size(), nofObjects);
172   }
173
174   return iResult;
175 }
176
177 AliHLTMonitoringRelay::AliHLTMonitoringItem* AliHLTMonitoringRelay::FindItem(const AliHLTComponentBlockData* pBlock, const TObject* pObject) const
178 {
179   // find an item by data type, specification, name and title
180   for (unsigned i=0; i<fItems.size(); i++) {
181     AliHLTMonitoringItem* pItem=fItems[i];
182     if (pItem &&
183         (*pItem)==(*pBlock) &&
184         (pObject==NULL || (*pItem)==(*pObject))) {
185       return pItem;
186     }
187   }
188   return NULL;  
189 }
190
191 AliHLTMonitoringRelay::AliHLTMonitoringItem::AliHLTMonitoringItem()
192   : fDt(kAliHLTVoidDataType)
193   , fSpecification(kAliHLTVoidDataSpec)
194   , fName()
195   , fTitle()
196   , fData(new TArrayC)
197   , fDataSize(0)
198 {
199   // standard constructor
200 }
201
202 AliHLTMonitoringRelay::AliHLTMonitoringItem::AliHLTMonitoringItem(const AliHLTComponentBlockData* pBlock, const TObject* pObject)
203   : fDt(kAliHLTVoidDataType)
204   , fSpecification(kAliHLTVoidDataSpec)
205   , fName()
206   , fTitle()
207   , fData(new TArrayC)
208   , fDataSize(0)
209 {
210   // constructor
211   if (pBlock) {
212     fDt=pBlock->fDataType;
213     fSpecification=pBlock->fSpecification;
214     if (fData) {
215       fData->Set(pBlock->fSize, reinterpret_cast<const Char_t*>(pBlock->fPtr));
216       fDataSize=pBlock->fSize;
217     }
218   }
219   if (pObject) {
220     fName=pObject->GetName();
221     fTitle=pObject->GetTitle();
222   }
223 }
224
225 AliHLTMonitoringRelay::AliHLTMonitoringItem::~AliHLTMonitoringItem()
226 {
227   // desstructor
228   if (fData) delete fData;
229 }
230
231 int AliHLTMonitoringRelay::AliHLTMonitoringItem::SetData(void* pBuffer, int size)
232 {
233   // copy the data buffer
234   if (!fData) {
235     fData=new TArrayC(size, reinterpret_cast<const Char_t*>(pBuffer));
236   }
237   if (!fData) {
238     return -ENOMEM;
239   }
240
241   if (fData->GetSize()<size) {
242     fData->Set(size, reinterpret_cast<const Char_t*>(pBuffer));
243   } else {
244     memcpy(fData->GetArray(), pBuffer, size);
245   }
246
247   fDataSize=size;
248   return 0;
249 }
250
251
252 void* AliHLTMonitoringRelay::AliHLTMonitoringItem::GetBuffer() const
253 {
254   // get buffer pointer of the current data
255   return fData!=NULL?fData->GetArray():NULL;
256 }
257
258 unsigned AliHLTMonitoringRelay::AliHLTMonitoringItem::GetSize() const
259 {
260   // get size of the current data
261   return fDataSize;
262 }
263
264 const AliHLTComponentDataType& AliHLTMonitoringRelay::AliHLTMonitoringItem::GetDataType() const
265 {
266   // get data type
267   return fDt;
268 }
269
270 AliHLTUInt32_t AliHLTMonitoringRelay::AliHLTMonitoringItem::GetSpecification() const
271 {
272   // get specification
273   return fSpecification;
274 }
275
276 bool AliHLTMonitoringRelay::AliHLTMonitoringItem::operator==(const AliHLTComponentBlockData& bd) const
277 {
278   // equal to data type and specification
279   if (bd.fDataType!=fDt) return false;
280   if (bd.fSpecification!=fSpecification) return false;
281   return true;
282 }
283
284 bool AliHLTMonitoringRelay::AliHLTMonitoringItem::operator!=(const AliHLTComponentBlockData& bd) const
285 {
286   // not equal to data type and specification
287   return not operator==(bd);
288 }
289
290 bool AliHLTMonitoringRelay::AliHLTMonitoringItem::operator==(const TObject& object) const
291 {
292   // equal to name and title
293   if (fName.CompareTo(object.GetName())!=0) return false;
294   if (!fTitle.IsNull() && fTitle.CompareTo(object.GetTitle())!=0) return false;
295   return true;
296 }
297
298 bool AliHLTMonitoringRelay::AliHLTMonitoringItem::operator!=(const TObject& object) const
299 {
300   // not equal to name and title
301   return not operator==(object);
302 }