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 |
27 | */ |
28 | class AliHLTEsdManager : public AliHLTLogging { |
29 | public: |
30 | /** constructor */ |
31 | AliHLTEsdManager(); |
32 | /** destructor */ |
33 | virtual ~AliHLTEsdManager(); |
34 | |
35 | /** |
36 | * Convert data buffer to ESD. |
37 | * The buffer is supposed to describe a streamed AliESDEvent object. |
38 | * If no target object is specified, the ESD is written to a file AliHLTdetESDs.root, |
39 | * where 'det' is derived from the data type origin. Each time the function is invoked |
40 | * a new event is created. Dummy events are added if the previous events did not contain |
41 | * |
42 | * @param pBuffer [in] the data buffer |
43 | * @param size [in] data buffer size |
44 | * @param dt [in] data type of the block |
45 | * @param tgtesd [out] optional target |
46 | * @param eventno [in] optional event no |
47 | */ |
48 | int WriteESD(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size, AliHLTComponentDataType dt, |
49 | AliESDEvent* tgtesd=NULL, int eventno=-1); |
50 | |
90c37647 |
51 | /** |
52 | * Align all ESD to the same number of events. |
53 | * The function adds empty events to all ESD files if their event number |
54 | * does not match the specified one. |
55 | * @param eventno the desired event no |
56 | * @return neg. error code if failed |
57 | */ |
58 | int PadESDs(int eventno); |
59 | |
60 | /** |
61 | * Set the target directory for the ESD files. |
62 | */ |
63 | void SetDirectory(const char* directory); |
64 | |
65 | /** |
66 | * Get the list of the internally created files. |
67 | * Returns a blank separated list of the file names. |
68 | */ |
69 | TString GetFileNames(AliHLTComponentDataType dt=kAliHLTAnyDataType) const; |
70 | |
71 | /** |
72 | * Embed an ESD into a TTree object. |
73 | * The tree object needs to be deleted by the caller. |
74 | */ |
75 | static TTree* EmbedIntoTree(AliESDEvent* pESD, const char* name="esdTree", const char* title="Tree with HLT ESD objects"); |
76 | |
c5123824 |
77 | protected: |
78 | |
79 | private: |
80 | /** copy constructor prohibited */ |
81 | AliHLTEsdManager(const AliHLTEsdManager&); |
82 | /** assignment operator prohibited */ |
83 | AliHLTEsdManager& operator=(const AliHLTEsdManager&); |
84 | |
85 | class AliHLTEsdListEntry : public AliHLTLogging { |
86 | public: |
87 | /** constructor */ |
88 | AliHLTEsdListEntry(AliHLTComponentDataType dt); |
c5123824 |
89 | /** destructor */ |
90 | ~AliHLTEsdListEntry(); |
91 | |
92 | /** |
93 | * Write the ESD to the corresponding file. |
94 | * The tree is first synchronized with the eventno and additional empty |
95 | * events might be inserted if there was a gap. Since we are writing |
96 | * several files in parallel, we have to make sure that those files contain |
97 | * the same number of events. |
98 | * @param pESD ESD to write |
99 | * @param eventno optional event no for tree synchronization |
100 | */ |
101 | int WriteESD(AliESDEvent* pESD, int eventno=-1); |
102 | |
90c37647 |
103 | /** |
104 | * Set the target directory for the ESD file. |
105 | */ |
106 | void SetDirectory(const char* directory); |
107 | |
108 | /** |
109 | * Delete the ESD file. |
110 | */ |
111 | void Delete(); |
112 | |
113 | /** |
114 | * Get name of the ESD file. |
115 | */ |
116 | const char* GetFileName() const; |
117 | |
c5123824 |
118 | bool operator==(AliHLTComponentDataType dt) const; |
119 | |
120 | private: |
62ff1e23 |
121 | /** copy constructor prohibited */ |
122 | AliHLTEsdListEntry(const AliHLTEsdListEntry& src); |
123 | /** assignment operator prohibited */ |
124 | AliHLTEsdListEntry& operator=(const AliHLTEsdListEntry& src); |
c5123824 |
125 | |
90c37647 |
126 | /** |
127 | * Write ESD to temporary file. |
128 | * The ESD is embedded into a tree and saved to a temporary file. |
129 | * The file name is retrieved by TSystem::GetTempFileName and returned |
130 | * on success. |
131 | * @return file name, empty on failure |
132 | */ |
133 | TString WriteTempFile(AliESDEvent* pESD) const; |
134 | |
c5123824 |
135 | /** root file name */ |
136 | TString fName; //!transient |
90c37647 |
137 | /** target directory */ |
138 | TString fDirectory; //!transient |
c5123824 |
139 | /** data type of the corresponding block */ |
140 | AliHLTComponentDataType fDt; //!transient |
141 | }; |
142 | |
62ff1e23 |
143 | typedef vector<AliHLTEsdListEntry*> AliHLTEsdPList; |
c5123824 |
144 | |
145 | /** |
146 | * Find list entry for given data type |
147 | */ |
148 | AliHLTEsdListEntry* Find(AliHLTComponentDataType dt) const; |
149 | |
150 | /** the list of the ESDs */ |
62ff1e23 |
151 | AliHLTEsdPList fESDs; //!transient |
c5123824 |
152 | |
90c37647 |
153 | /** target directory */ |
154 | TString fDirectory; //!transient |
155 | |
c5123824 |
156 | ClassDef(AliHLTEsdManager, 0) |
157 | }; |
90c37647 |
158 | |
c5123824 |
159 | #endif |