using common function for merging of streamer info
[u/mrichter/AliRoot.git] / HLT / BASE / util / AliHLTRootSchemaEvolutionComponent.h
CommitLineData
65106d07 1// -*- Mode: C++ -*-
2// $Id$
3
4#ifndef ALIHLTROOTSCHEMAEVOLUTIONCOMPONENT_H
5#define ALIHLTROOTSCHEMAEVOLUTIONCOMPONENT_H
4e8187d8 6//* This file is property of and copyright by the *
65106d07 7//* ALICE Experiment at CERN, All rights reserved. *
8//* See cxx source for full Copyright notice *
9
94d06b79 10/// @file AliHLTRootSchemaEvolutionComponent.h
11/// @author Matthias Richter
12/// @date 2009-10-18
13/// @brief Handler component for ROOT schema evolution of streamed objects
14///
65106d07 15
b64e4d93 16#include "AliHLTCalibrationProcessor.h"
05948425 17#include "TString.h"
a22cde70 18#include <vector>
65106d07 19
20class TObjArray;
a22cde70 21class TObject;
22class TStopwatch;
23class AliHLTMessage;
65106d07 24
4e8187d8 25using std::vector;
26
65106d07 27/**
28 * @class AliHLTRootSchemaEvolutionComponent
a22cde70 29 * Collects streamer info for all input objects and produces the corresponding
30 * calibration object for reconstruction of HLT. The component runs with a
31 * configurable rate constraint and skips the processing of known data blocks
32 * for the sake of performance. New data blocks are always processed and added
33 * to the list.
65106d07 34 *
35 * <h2>General properties:</h2>
36 *
878f7b64 37 * Component ID: \b ROOTSchemaEvolutionComponent <br>
65106d07 38 * Library: \b libAliHLTUtil.so <br>
39 * Input Data Types: ::kAliHLTAnyDataType <br>
40 * Output Data Types: none <br>
41 *
42 * <h2>Mandatory arguments:</h2>
43 * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
44 *
45 * <h2>Optional arguments:</h2>
46 * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
b64e4d93 47 * \li -fxs<=[n,off]> <br>
65106d07 48 * push streamer info to FXS, fetched by Shuttle and store in the entry
b64e4d93 49 * HLT/Calib/StreamerInfo <br>
50 * if a scalar greather then 0 is specified the calibration object is
51 * pushed during the event processing with the specified scale down<br>
52 * always pushed on EOR, default on
65106d07 53 * \li -hltout<=[all,first,eor,off]> <br>
54 * push streamer info to output, the streamer info is stored in the
55 * events in all, the first, and/or the EOR.
a22cde70 56 * \li -file=filename <br>
05948425 57 * write to file at EOR
a22cde70 58 * \li -rate=hz <br>
59 * required processing rate in Hz, default 2000Hz
65106d07 60 *
61 * <h2>Configuration:</h2>
62 * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
63 * Configuration by component arguments.
64 *
65 * <h2>Default CDB entries:</h2>
66 * The component loads no CDB entries.
67 *
68 * <h2>Performance:</h2>
878f7b64 69 * TODO: update performance requirements for unpacking ESDs and creating the
70 * streamer info
65106d07 71 *
72 * <h2>Memory consumption:</h2>
73 * The component does not process any event data.
74 *
75 * <h2>Output size:</h2>
76 * Depending on the mode.
77 *
78 * @ingroup alihlt_util_components
79 */
b64e4d93 80class AliHLTRootSchemaEvolutionComponent : public AliHLTCalibrationProcessor
65106d07 81{
82 public:
83 /// standard constructor
84 AliHLTRootSchemaEvolutionComponent();
85 /// destructor
86 virtual ~AliHLTRootSchemaEvolutionComponent();
87
88 /// inherited from AliHLTComponent: return id of the component.
89 virtual const char* GetComponentID() {return "ROOTSchemaEvolutionComponent";};
90 /// inherited from AliHLTComponent: input data types
94d06b79 91 virtual void GetInputDataTypes(AliHLTComponentDataTypeList& list);
65106d07 92 /// inherited from AliHLTComponent: output data types
93 virtual AliHLTComponentDataType GetOutputDataType();
94 /// inherited from AliHLTComponent: output data size
95 virtual void GetOutputDataSize(unsigned long&, double&);
96
97 /// inherited from AliHLTComponent: spawn function, create an instance.
98 virtual AliHLTComponent* Spawn() {return new AliHLTRootSchemaEvolutionComponent;}
99
100 enum {
101 /// push streamer info to the HLTOUT for the first event
102 kHLTOUTatFirstEvent = 0x1,
103 /// push streamer info to the HLTOUT for all events
104 kHLTOUTatAllEvents = 0x2,
105 /// push streamer info to the HLTOUT at EOR, this has no relevance
106 /// for reconstruction as it is too late and just in one raw file,
107 /// but it allows archival at the end of the run
108 kHLTOUTatEOR = 0x4,
109 /// push streamer info to FXS
110 kFXS = 0x100,
111 };
112
113 /// Update the array of known streamer infos from a list of infos
114 /// Checks whether the provided infos are already there in the present version
115 /// and adds if it is a new info.
116 int UpdateStreamerInfos(const TList* list, TObjArray* infos) const;
117
a22cde70 118 class AliHLTDataBlockItem
119 {
120 public:
121 AliHLTDataBlockItem(AliHLTComponentDataType dt=kAliHLTVoidDataType,
122 AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
123 ~AliHLTDataBlockItem();
124
125 /// extract data block to root object, and update performance parameters
126 /// object needs to be deleted externally
127 TObject* Extract(const AliHLTComponentBlockData* bd);
128
129 /// stream object and update performance parameters
94d06b79 130 int Stream(const TObject* obj, AliHLTMessage& msg);
a22cde70 131
132 bool IsObject() const {return fIsObject;}
94d06b79 133 bool operator==(const AliHLTDataBlockItem& i) const {return fDt==i.fDt && fSpecification==i.fSpecification;}
a22cde70 134 bool operator==(AliHLTComponentDataType dt) const {return fDt==dt;}
135 bool operator==(AliHLTUInt32_t spec) const {return fSpecification==spec;}
a22cde70 136 operator const AliHLTComponentDataType&() const {return fDt;}
137 AliHLTUInt32_t GetSpecification() const {return fSpecification;}
138
139 /// average extraction time in usec
140 AliHLTUInt32_t GetExtractionTime() const {return fNofExtractions>0?fExtractionTimeUsec/fNofExtractions:0;}
141 /// average streaming time in usec
142 AliHLTUInt32_t GetStreamingTime() const {return fNofStreamings>0?fStreamingTimeUsec/fNofStreamings:0;}
143 /// average total time in usec
144 AliHLTUInt32_t GetTotalTime() const {return GetExtractionTime() + GetStreamingTime();}
145
146 /// print status
147 void Print(const char* option) const;
148
a22cde70 149 private:
150 /// data type of the block
151 AliHLTComponentDataType fDt; //! transient
152 /// specification of the block
153 AliHLTUInt32_t fSpecification; //! transient
154 /// flag for TObject
155 bool fIsObject; //! transient
156
157 /// number of extractions
158 AliHLTUInt32_t fNofExtractions; //! transient
159 /// object extraction time in usec
160 AliHLTUInt32_t fExtractionTimeUsec; //! transient
161 /// timestamp of last extraction in usec
162 AliHLTUInt32_t fLastExtraction; //! transient
163 /// number of streamings
164 AliHLTUInt32_t fNofStreamings; //! transient
165 /// object streaming time in usec
166 AliHLTUInt32_t fStreamingTimeUsec; //! transient
167 /// timestamp of last streaming in usec
168 AliHLTUInt32_t fLastStreaming; // !transient
169 };
170
171 /// find item in the list
172 AliHLTDataBlockItem* FindItem(AliHLTComponentDataType dt,
173 AliHLTUInt32_t spec);
174
65106d07 175 protected:
b64e4d93 176 /// inherited from AliHLTCalibrationProcessor: custom initialization
177 int InitCalibration();
178 /// inherited from AliHLTCalibrationProcessor: custom argument scan
179 /// the AliHLTCalibrationProcessor so far does not use the base class
180 /// methods for argument scan.
181 int ScanArgument( int argc, const char** argv ) {
182 int result=ScanConfigurationArgument(argc, argv); return result>0?result-1:result;
183 }
184 /// inherited from AliHLTCalibrationProcessor: cleanup
185 int DeinitCalibration();
186
187 /// inherited from AliHLTCalibrationProcessor processing
188 virtual int ProcessCalibration( const AliHLTComponentEventData& evtData,
189 AliHLTComponentTriggerData& trigData );
65106d07 190
b64e4d93 191 using AliHLTCalibrationProcessor::ProcessCalibration;
192
193 /// inherited from AliHLTCalibrationProcessor processing
194 int ShipDataToFXS( const AliHLTComponentEventData& evtData,
195 AliHLTComponentTriggerData& trigData);
196
197 using AliHLTCalibrationProcessor::ShipDataToFXS;
65106d07 198
199 /**
200 * Inherited from AliHLTComponent
201 * Scan one argument and adjacent parameters.
202 * @return number of scanned parameters, neg. error code if failed
203 */
204 virtual int ScanConfigurationArgument(int argc, const char** argv);
205
94d06b79 206 void SetBits(AliHLTUInt32_t b) {fPropertyFlags|=b;}
207 void ClearBits(AliHLTUInt32_t b) {fPropertyFlags&=~b;}
208 bool TestBits(AliHLTUInt32_t b) const {return (fPropertyFlags&b) != 0;}
05948425 209 int WriteToFile(const char* filename, const TObjArray* infos) const;
65106d07 210
211private:
212 /** copy constructor prohibited */
213 AliHLTRootSchemaEvolutionComponent(const AliHLTRootSchemaEvolutionComponent&);
214 /** assignment operator prohibited */
215 AliHLTRootSchemaEvolutionComponent& operator=(const AliHLTRootSchemaEvolutionComponent&);
216
a22cde70 217 vector<AliHLTDataBlockItem> fList; //! list of block properties
218
94d06b79 219 AliHLTUInt32_t fPropertyFlags; //! property flags
65106d07 220
221 TObjArray* fpStreamerInfos; //! array of streamer infos
a22cde70 222 TStopwatch* fpEventTimer; //! stopwatch for event processing
223 TStopwatch* fpCycleTimer; //! stopwatch for event cycle
224 AliHLTUInt32_t fMaxEventTime; //! required maximum processing time in usec
65106d07 225
226 AliHLTUInt32_t fFXSPrescaler; //! prescalar for the publishing to FXS
227
05948425 228 TString fFileName; //! file name for dump at EOR
229
65106d07 230 static const char* fgkConfigurationObject; //! configuration object
a22cde70 231 static const AliHLTUInt32_t fgkTimeScale; //! timescale base
65106d07 232
a22cde70 233 ClassDef(AliHLTRootSchemaEvolutionComponent, 0) // ROOT schema evolution component
65106d07 234};
235#endif