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