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