]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/rec/AliHLTEsdManagerImplementation.h
1a79ff621fc2970bbf66c6cee2eff8be44be404d
[u/mrichter/AliRoot.git] / HLT / rec / AliHLTEsdManagerImplementation.h
1 //-*- Mode: C++ -*-
2 // $Id$
3
4 #ifndef ALIHLTESDMANAGERIMPLEMENTATION_H
5 #define ALIHLTESDMANAGERIMPLEMENTATION_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   AliHLTEsdManagerImplementation.h
11     @author Matthias Richter
12     @date   
13     @brief  Implementation of the AliHLTEsdManager
14 */
15
16 #include "AliHLTEsdManager.h"
17 #include "TString.h"
18 #include <vector>
19
20 class AliESDEvent;
21 class TTree;
22 class TFile;
23
24 /**
25  * @class AliHLTEsdManagerImplementation
26  * Implementation of the AliHLTEsdManager.
27  *
28  * For the sake of library (in)dependencies, the concrete implementation of
29  * the AliHLTEsdManager is separated from the libHLTbase class as this would
30  * introduce dependencies to AliRoot libraries. See AliHLTEsdManager for
31  * usage.
32  *
33  * @ingroup alihlt_aliroot_reconstruction
34  */
35 class AliHLTEsdManagerImplementation : public AliHLTEsdManager {
36  public:
37   /** constructor */
38   AliHLTEsdManagerImplementation();
39   /** destructor */
40   virtual ~AliHLTEsdManagerImplementation();
41
42   /**
43    * Inherited from base class, see AliHLTEsdManager::SetOption() for
44    * documentation.
45    */
46   virtual int SetOption(const char* option);
47
48   /**
49    * Convert data buffer to ESD.
50    * The buffer is supposed to describe a streamed AliESDEvent object.
51    * If no target object is specified, the ESD is written to a file AliHLTdetESDs.root,
52    * where 'det' is derived from the data type origin. Each time the function is invoked
53    * a new event is created. Dummy events are added if the previous events did not contain
54    *
55    * @param pBuffer  [in] the data buffer
56    * @param size     [in] data buffer size
57    * @param dt       [in] data type of the block
58    * @param tgtesd   [out] optional target
59    * @param eventno  [in] optional event no
60    */
61   int WriteESD(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size, AliHLTComponentDataType dt,
62                AliESDEvent* tgtesd=NULL, int eventno=-1);
63
64   /**
65    * Merge content of source ESD into the target ESD.
66    * Merging is done on the level of objects in the ESD and for the
67    * moment it's only implemented for the TClonesArrays. In that case it's
68    * easy to detect whether the object is empty or not.
69    *
70    * \b Note: The function can not match entries of the same type, like e.g.
71    * tracks from the 'Tracks' member.
72    */
73   int Merge(AliESDEvent* pTgt, AliESDEvent* pSrc) const;
74
75   /**
76    * Align all ESD to the same number of events.
77    * The function adds empty events to all ESD files if their event number
78    * does not match the specified one.
79    * @param eventno     the desired event no
80    * @return neg. error code if failed
81    */
82   int PadESDs(int eventno);
83
84   /**
85    * Set the target directory for the ESD files.
86    */
87   void SetDirectory(const char* directory);
88
89   /**
90    * Get the list of the internally created files.
91    * Returns a blank separated list of the file names.
92    */
93   TString GetFileNames(AliHLTComponentDataType dt=kAliHLTAnyDataType) const;
94
95   /**
96    * Embed an ESD into a TTree object.
97    * The tree object needs to be deleted by the caller.
98    */
99   static TTree* EmbedIntoTree(AliESDEvent* pESD, const char* name="esdTree", const char* title="Tree with HLT ESD objects");
100
101  protected:
102
103  private:
104   /** copy constructor prohibited */
105   AliHLTEsdManagerImplementation(const AliHLTEsdManagerImplementation&);
106   /** assignment operator prohibited */
107   AliHLTEsdManagerImplementation& operator=(const AliHLTEsdManagerImplementation&);
108
109   class AliHLTEsdListEntry : public AliHLTLogging {
110   public:
111     /** constructor */
112     AliHLTEsdListEntry(AliHLTComponentDataType dt);
113     /** destructor */
114     ~AliHLTEsdListEntry();
115
116     /**
117      * Write the ESD to the corresponding file.
118      * The tree is first synchronized with the eventno and additional empty
119      * events might be inserted if there was a gap. Since we are writing
120      * several files in parallel, we have to make sure that those files contain
121      * the same number of events.
122      * @param pESD        ESD to write
123      * @param eventno     optional event no for tree synchronization
124      */
125     int WriteESD(AliESDEvent* pESD, int eventno=-1);
126
127     /**
128      * Set the target directory for the ESD file.
129      */
130     void SetDirectory(const char* directory);
131
132     /**
133      * Delete the ESD file.
134      */
135     void Delete();
136
137     /**
138      * Get name of the ESD file.
139      */
140     const char* GetFileName() const;
141
142     /**
143      * Get the object name prefix generated from the data origin
144      * The prefix is added to the names of the ESD objects when copied to the
145      * master ESD.
146      */
147     const char* GetPrefix();
148
149     bool operator==(AliHLTComponentDataType dt) const;
150
151   private:
152     /** copy constructor prohibited */
153     AliHLTEsdListEntry(const AliHLTEsdListEntry& src);
154     /** assignment operator prohibited */
155     AliHLTEsdListEntry& operator=(const AliHLTEsdListEntry& src);
156
157     /**
158      * Write ESD to temporary file.
159      * The ESD is embedded into a tree and saved to a temporary file.
160      * The file name is retrieved by TSystem::GetTempFileName and returned
161      * on success.
162      * @return file name, empty on failure
163      */
164     TString WriteTempFile(AliESDEvent* pESD) const;
165
166     /** root file name */
167     TString fName; //!transient
168     /** target directory */
169     TString fDirectory; //!transient
170     /** data type of the corresponding block */
171     AliHLTComponentDataType fDt; //!transient
172     /** the root file for this esd */
173     TFile* fpFile; //!transient
174     /** the tree for this esd */
175     TTree* fpTree; //!transient
176     /** the esd to fill into the tree */
177     AliESDEvent* fpEsd; //!transient
178     /** Prefix for generated ESD objects in the master ESD */
179     TString fPrefix; //!transient
180   };
181
182   typedef vector<AliHLTEsdListEntry*> AliHLTEsdPList;
183
184   /**
185    * Find list entry for given data type
186    */
187   AliHLTEsdListEntry* Find(AliHLTComponentDataType dt) const;
188
189   /** the list of the ESDs */
190   AliHLTEsdPList fESDs; //!transient
191
192   /** target directory */
193   TString fDirectory; //!transient
194   /** write local files */
195   bool fWriteLocal; //!transient
196
197   ClassDef(AliHLTEsdManagerImplementation, 2)
198 };
199
200 #endif