c5123824 |
1 | //-*- Mode: C++ -*- |
2 | // $Id$ |
3 | |
4 | #ifndef ALIHLTESDMANAGER_H |
5 | #define ALIHLTESDMANAGER_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 AliHLTEsdManager.h |
11 | @author Matthias Richter |
12 | @date |
13 | @brief Manager for merging and writing of HLT ESDs |
14 | */ |
15 | |
16 | #include "AliHLTDataTypes.h" |
17 | #include "AliHLTLogging.h" |
90c37647 |
18 | #include "TString.h" |
c5123824 |
19 | #include <vector> |
20 | |
21 | class AliESDEvent; |
22 | class TTree; |
23 | class TFile; |
24 | |
25 | /** |
26 | * @class AliHLTEsdManager |
83cb7e1d |
27 | * Tool to write and merge HLT ESD objects. |
28 | * |
29 | * HLT components can produce ESD output. The ESD objects are sent via |
30 | * a TMessage like mechanism as part of the HLTOUT data. This class retrieves |
31 | * streamed AliESDEvent objects from an HLT output block. An ESD object can be |
32 | * copied to a global ESD provided by the caller or to files. The name of the |
33 | * ROOT files follows the scheme AliHLTDETESDs.root where DET denotes a detector. |
34 | * E.g. the ESD from a data block of type {ESD_TREE,TPC} will be added to the |
35 | * file AliHLTTPCESDs.root. |
36 | * |
9d4cf2ab |
37 | * @ingroup alihlt_aliroot_reconstruction |
c5123824 |
38 | */ |
39 | class AliHLTEsdManager : public AliHLTLogging { |
40 | public: |
41 | /** constructor */ |
42 | AliHLTEsdManager(); |
43 | /** destructor */ |
44 | virtual ~AliHLTEsdManager(); |
45 | |
46 | /** |
47 | * Convert data buffer to ESD. |
48 | * The buffer is supposed to describe a streamed AliESDEvent object. |
49 | * If no target object is specified, the ESD is written to a file AliHLTdetESDs.root, |
50 | * where 'det' is derived from the data type origin. Each time the function is invoked |
51 | * a new event is created. Dummy events are added if the previous events did not contain |
52 | * |
53 | * @param pBuffer [in] the data buffer |
54 | * @param size [in] data buffer size |
55 | * @param dt [in] data type of the block |
56 | * @param tgtesd [out] optional target |
57 | * @param eventno [in] optional event no |
58 | */ |
59 | int WriteESD(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size, AliHLTComponentDataType dt, |
60 | AliESDEvent* tgtesd=NULL, int eventno=-1); |
61 | |
90c37647 |
62 | /** |
63 | * Align all ESD to the same number of events. |
64 | * The function adds empty events to all ESD files if their event number |
65 | * does not match the specified one. |
66 | * @param eventno the desired event no |
67 | * @return neg. error code if failed |
68 | */ |
69 | int PadESDs(int eventno); |
70 | |
71 | /** |
72 | * Set the target directory for the ESD files. |
73 | */ |
74 | void SetDirectory(const char* directory); |
75 | |
76 | /** |
77 | * Get the list of the internally created files. |
78 | * Returns a blank separated list of the file names. |
79 | */ |
80 | TString GetFileNames(AliHLTComponentDataType dt=kAliHLTAnyDataType) const; |
81 | |
82 | /** |
83 | * Embed an ESD into a TTree object. |
84 | * The tree object needs to be deleted by the caller. |
85 | */ |
86 | static TTree* EmbedIntoTree(AliESDEvent* pESD, const char* name="esdTree", const char* title="Tree with HLT ESD objects"); |
87 | |
c5123824 |
88 | protected: |
89 | |
90 | private: |
91 | /** copy constructor prohibited */ |
92 | AliHLTEsdManager(const AliHLTEsdManager&); |
93 | /** assignment operator prohibited */ |
94 | AliHLTEsdManager& operator=(const AliHLTEsdManager&); |
95 | |
96 | class AliHLTEsdListEntry : public AliHLTLogging { |
97 | public: |
98 | /** constructor */ |
99 | AliHLTEsdListEntry(AliHLTComponentDataType dt); |
c5123824 |
100 | /** destructor */ |
101 | ~AliHLTEsdListEntry(); |
102 | |
103 | /** |
104 | * Write the ESD to the corresponding file. |
105 | * The tree is first synchronized with the eventno and additional empty |
106 | * events might be inserted if there was a gap. Since we are writing |
107 | * several files in parallel, we have to make sure that those files contain |
108 | * the same number of events. |
109 | * @param pESD ESD to write |
110 | * @param eventno optional event no for tree synchronization |
111 | */ |
112 | int WriteESD(AliESDEvent* pESD, int eventno=-1); |
113 | |
90c37647 |
114 | /** |
115 | * Set the target directory for the ESD file. |
116 | */ |
117 | void SetDirectory(const char* directory); |
118 | |
119 | /** |
120 | * Delete the ESD file. |
121 | */ |
122 | void Delete(); |
123 | |
124 | /** |
125 | * Get name of the ESD file. |
126 | */ |
127 | const char* GetFileName() const; |
128 | |
c5123824 |
129 | bool operator==(AliHLTComponentDataType dt) const; |
130 | |
131 | private: |
62ff1e23 |
132 | /** copy constructor prohibited */ |
133 | AliHLTEsdListEntry(const AliHLTEsdListEntry& src); |
134 | /** assignment operator prohibited */ |
135 | AliHLTEsdListEntry& operator=(const AliHLTEsdListEntry& src); |
c5123824 |
136 | |
90c37647 |
137 | /** |
138 | * Write ESD to temporary file. |
139 | * The ESD is embedded into a tree and saved to a temporary file. |
140 | * The file name is retrieved by TSystem::GetTempFileName and returned |
141 | * on success. |
142 | * @return file name, empty on failure |
143 | */ |
144 | TString WriteTempFile(AliESDEvent* pESD) const; |
145 | |
c5123824 |
146 | /** root file name */ |
147 | TString fName; //!transient |
90c37647 |
148 | /** target directory */ |
149 | TString fDirectory; //!transient |
c5123824 |
150 | /** data type of the corresponding block */ |
151 | AliHLTComponentDataType fDt; //!transient |
83cb7e1d |
152 | /** the root file for this esd */ |
153 | TFile* fpFile; //!transient |
154 | /** the tree for this esd */ |
155 | TTree* fpTree; //!transient |
156 | /** the esd to fill into the tree */ |
157 | AliESDEvent* fpEsd; //!transient |
c5123824 |
158 | }; |
159 | |
62ff1e23 |
160 | typedef vector<AliHLTEsdListEntry*> AliHLTEsdPList; |
c5123824 |
161 | |
162 | /** |
163 | * Find list entry for given data type |
164 | */ |
165 | AliHLTEsdListEntry* Find(AliHLTComponentDataType dt) const; |
166 | |
167 | /** the list of the ESDs */ |
62ff1e23 |
168 | AliHLTEsdPList fESDs; //!transient |
c5123824 |
169 | |
90c37647 |
170 | /** target directory */ |
171 | TString fDirectory; //!transient |
172 | |
83cb7e1d |
173 | ClassDef(AliHLTEsdManager, 1) |
c5123824 |
174 | }; |
90c37647 |
175 | |
c5123824 |
176 | #endif |