]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/util/AliHLTMonitoringRelay.cxx
adding the MonitoringRelay component
[u/mrichter/AliRoot.git] / HLT / BASE / util / AliHLTMonitoringRelay.cxx
1 // $Id$
2
3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project        * 
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
32 /** ROOT macro for the implementation of ROOT specific class methods */
33 ClassImp(AliHLTMonitoringRelay)
34
35 AliHLTMonitoringRelay::AliHLTMonitoringRelay()
36   : AliHLTProcessor()
37   , fItems()
38   , fOutputSize()
39 {
40   // see header file for class documentation
41   // or
42   // refer to README to build package
43   // or
44   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
45 }
46
47 AliHLTMonitoringRelay::~AliHLTMonitoringRelay()
48 {
49   // see header file for class documentation
50 }
51
52 void AliHLTMonitoringRelay::GetInputDataTypes(AliHLTComponentDataTypeList& list)
53 {
54   // see header file for class documentation
55   list.clear();
56   list.push_back(kAliHLTAnyDataType);
57 }
58
59 AliHLTComponentDataType AliHLTMonitoringRelay::GetOutputDataType()
60 {
61   // see header file for class documentation
62   return kAliHLTAnyDataType;
63 }
64
65 void AliHLTMonitoringRelay::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
66 {
67   // see header file for class documentation
68   constBase=fOutputSize;
69   inputMultiplier=1.0;
70 }
71
72 int AliHLTMonitoringRelay::DoInit( int argc, const char** argv )
73 {
74   // see header file for class documentation
75   int iResult=0;
76   fOutputSize=0;
77
78   iResult=ConfigureFromArgumentString(argc, argv);
79
80   return iResult;
81 }
82
83 int AliHLTMonitoringRelay::ScanConfigurationArgument(int argc, const char** argv)
84 {
85   // see header file for class documentation
86   if (argc<=0) return 0;
87   int i=0;
88   TString argument=argv[i];
89
90   // -verbose
91   if (argument.CompareTo("-verbose")==0) {
92     // 
93     return 1;
94   }    
95
96   return 0;
97 }
98
99 int AliHLTMonitoringRelay::DoDeinit()
100 {
101   // see header file for class documentation
102   int iResult=0;
103   AliHLTMonitoringItemPList::iterator element=fItems.begin();
104   while (element!=fItems.end()) {
105     AliHLTMonitoringItem* pItem=*element;
106     element=fItems.erase(element);
107     if (pItem) {
108       delete pItem;
109     }
110   }
111   return iResult;
112 }
113
114 int AliHLTMonitoringRelay::DoEvent(const AliHLTComponentEventData& /*evtData*/,
115                                    AliHLTComponentTriggerData& /*trigData*/)
116 {
117   // see header file for class documentation
118   int iResult=0;
119   for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock();
120        pBlock!=NULL; 
121        pBlock=GetNextInputBlock()) {
122     TObject* pObject=AliHLTMessage::Extract(pBlock->fPtr, pBlock->fSize);
123     if (!pObject) continue; // consider only TObjects
124     
125     AliHLTMonitoringItem* pItem=FindItem(pBlock, pObject);
126     if (pItem) {
127       HLTInfo("found block %s 0x%0lx %s %s", DataType2Text(pItem->GetDataType()).c_str(), pItem->GetSpecification(), pObject->GetName(), pObject->GetName());
128       if (pItem->GetSize()<pBlock->fSize) {
129         // update with the new maximum
130         assert(fOutputSize>=pItem->GetSize());
131         fOutputSize-=pItem->GetSize();
132         fOutputSize+=pBlock->fSize;
133       }
134       pItem->SetData(pBlock->fPtr, pBlock->fSize);
135       HLTInfo("setting item size %d, total size %d", pItem->GetSize(), fOutputSize);
136     } else {
137       pItem=new AliHLTMonitoringItem(pBlock, pObject);
138       fItems.push_back(pItem);
139       fOutputSize+=pBlock->fSize;
140       HLTInfo("new item size %d (%d),  %s 0x%0lx %s %s", pItem->GetSize(), fOutputSize, DataType2Text(pItem->GetDataType()).c_str(), pItem->GetSpecification(), pObject->GetName(), pObject->GetName());
141     }
142     delete pObject;
143   }
144
145   for (AliHLTMonitoringItemPList::iterator element=fItems.begin();
146        element!=fItems.end(); element++) {
147     AliHLTMonitoringItem* pItem=*element;
148     if (pItem) {
149       HLTInfo("push back item size %d (%d),  %s 0x%0lx", pItem->GetSize(), fOutputSize, DataType2Text(pItem->GetDataType()).c_str(), pItem->GetSpecification());
150       PushBack(pItem->GetBuffer(), pItem->GetSize(), pItem->GetDataType(), pItem->GetSpecification());
151     }
152   }
153
154   return iResult;
155 }
156
157 AliHLTMonitoringRelay::AliHLTMonitoringItem* AliHLTMonitoringRelay::FindItem(const AliHLTComponentBlockData* pBlock, const TObject* pObject) const
158 {
159   // find an item by data type, specification, name and title
160   for (unsigned i=0; i<fItems.size(); i++) {
161     AliHLTMonitoringItem* pItem=fItems[i];
162     if (pItem &&
163         (*pItem)==(*pBlock) &&
164         (pObject==NULL || (*pItem)==(*pObject))) {
165       return pItem;
166     }
167   }
168   return NULL;  
169 }
170
171 AliHLTMonitoringRelay::AliHLTMonitoringItem::AliHLTMonitoringItem()
172   : fDt(kAliHLTVoidDataType)
173   , fSpecification(kAliHLTVoidDataSpec)
174   , fName()
175   , fTitle()
176   , fData(new TArrayC)
177   , fDataSize(0)
178 {
179   // standard constructor
180 }
181
182 AliHLTMonitoringRelay::AliHLTMonitoringItem::AliHLTMonitoringItem(const AliHLTComponentBlockData* pBlock, const TObject* pObject)
183   : fDt(kAliHLTVoidDataType)
184   , fSpecification(kAliHLTVoidDataSpec)
185   , fName()
186   , fTitle()
187   , fData(new TArrayC)
188   , fDataSize(0)
189 {
190   // constructor
191   if (pBlock) {
192     fDt=pBlock->fDataType;
193     fSpecification=pBlock->fSpecification;
194     if (fData) {
195       fData->Set(pBlock->fSize, reinterpret_cast<const Char_t*>(pBlock->fPtr));
196       fDataSize=pBlock->fSize;
197     }
198   }
199   if (pObject) {
200     fName=pObject->GetName();
201     fTitle=pObject->GetTitle();
202   }
203 }
204
205 AliHLTMonitoringRelay::AliHLTMonitoringItem::~AliHLTMonitoringItem()
206 {
207   // desstructor
208   if (fData) delete fData;
209 }
210
211 int AliHLTMonitoringRelay::AliHLTMonitoringItem::SetData(void* pBuffer, int size)
212 {
213   // copy the data buffer
214   if (!fData) {
215     fData=new TArrayC(size, reinterpret_cast<const Char_t*>(pBuffer));
216   }
217   if (fData->GetSize()<size) {
218     fData->Set(size, reinterpret_cast<const Char_t*>(pBuffer));
219   } else {
220     memcpy(fData->GetArray(), pBuffer, size);
221   }
222
223   if (fData) {
224     fDataSize=size;
225     return 0;
226   }
227   return -ENOMEM;
228
229 }
230
231
232 void* AliHLTMonitoringRelay::AliHLTMonitoringItem::GetBuffer() const
233 {
234   // get buffer pointer of the current data
235   return fData!=NULL?fData->GetArray():NULL;
236 }
237
238 unsigned AliHLTMonitoringRelay::AliHLTMonitoringItem::GetSize() const
239 {
240   // get size of the current data
241   return fDataSize;
242 }
243
244 const AliHLTComponentDataType& AliHLTMonitoringRelay::AliHLTMonitoringItem::GetDataType() const
245 {
246   // get data type
247   return fDt;
248 }
249
250 AliHLTUInt32_t AliHLTMonitoringRelay::AliHLTMonitoringItem::GetSpecification() const
251 {
252   // get specification
253   return fSpecification;
254 }
255
256 bool AliHLTMonitoringRelay::AliHLTMonitoringItem::operator==(const AliHLTComponentBlockData& bd) const
257 {
258   // equal to data type and specification
259   if (bd.fDataType!=fDt) return false;
260   if (bd.fSpecification!=fSpecification) return false;
261   return true;
262 }
263
264 bool AliHLTMonitoringRelay::AliHLTMonitoringItem::operator!=(const AliHLTComponentBlockData& bd) const
265 {
266   // not equal to data type and specification
267   return not operator==(bd);
268 }
269
270 bool AliHLTMonitoringRelay::AliHLTMonitoringItem::operator==(const TObject& object) const
271 {
272   // equal to name and title
273   if (fName.CompareTo(object.GetName())!=0) return false;
274   if (!fTitle.IsNull() && fTitle.CompareTo(object.GetTitle())!=0) return false;
275   return true;
276 }
277
278 bool AliHLTMonitoringRelay::AliHLTMonitoringItem::operator!=(const TObject& object) const
279 {
280   // not equal to name and title
281   return not operator==(object);
282 }