3 /**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * for The ALICE Off-line Project. *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
18 /** @file AliHLTFileWriter.cxx
19 @author Matthias Richter
21 @brief HLT file writer component implementation. */
27 #include "AliHLTFileWriter.h"
28 #include <TObjArray.h>
29 #include <TObjString.h>
33 /** the global object for component registration */
34 AliHLTFileWriter gAliHLTFileWriter;
36 /** ROOT macro for the implementation of ROOT specific class methods */
37 ClassImp(AliHLTFileWriter)
39 AliHLTFileWriter::AliHLTFileWriter()
48 // see header file for class documentation
50 // refer to README to build package
52 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
55 AliHLTFileWriter::AliHLTFileWriter(const AliHLTFileWriter&)
64 // see header file for class documentation
65 HLTFatal("copy constructor untested");
68 AliHLTFileWriter& AliHLTFileWriter::operator=(const AliHLTFileWriter&)
70 // see header file for class documentation
71 HLTFatal("assignment operator untested");
75 AliHLTFileWriter::~AliHLTFileWriter()
77 // see header file for class documentation
79 // file list and file name list are owner of their objects and
80 // delete all the objects
83 const char* AliHLTFileWriter::GetComponentID()
85 // see header file for class documentation
89 void AliHLTFileWriter::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
91 // see header file for class documentation
93 list.push_back(kAliHLTAnyDataType);
96 AliHLTComponent* AliHLTFileWriter::Spawn()
98 // see header file for class documentation
99 return new AliHLTFileWriter;
102 int AliHLTFileWriter::DoInit( int argc, const char** argv )
104 // see header file for class documentation
108 for (int i=0; i<argc && iResult>=0; i++) {
110 if (argument.IsNull()) continue;
113 if (argument.CompareTo("-datafile")==0) {
114 if ((bMissingParam=(++i>=argc))) break;
116 TObjArray* pTokens=fBaseName.Tokenize(".");
118 int iEntries=pTokens->GetEntries();
121 fBaseName=((TObjString*)pTokens->At(i++))->GetString();
122 while (i<iEntries-1) {
123 fBaseName+="." + ((TObjString*)pTokens->At(i++))->GetString();
125 fExtension=((TObjString*)pTokens->At(i))->GetString();
131 } else if (argument.CompareTo("-directory")==0) {
132 if ((bMissingParam=(++i>=argc))) break;
136 } else if (argument.CompareTo("-enumerate")==0) {
139 // -concatenate-blocks
140 } else if (argument.CompareTo("-concatenate-blocks")==0) {
141 SetMode(kConcatenateBlocks);
143 // -concatenate-events
144 } else if (argument.CompareTo("-concatenate-events")==0) {
145 SetMode(kConcatenateEvents);
148 if ((iResult=ScanArgument(argc-i, &argv[i]))==-EINVAL) {
149 HLTError("unknown argument %s", argument.Data());
151 } else if (iResult==-EPROTO) {
154 } else if (iResult>=0) {
161 HLTError("missing parameter for argument %s", argument.Data());
165 iResult=InitWriter();
171 int AliHLTFileWriter::InitWriter()
173 // see header file for class documentation
175 // fCurrentFileName is used in dump event, just touched her to avoid
176 // coding convention violation RC11. The function can not be declared
177 // const since it is just the default implementation, overloaded
178 // virtual function might not be const
180 return 0; // note: this doesn't mean 'error'
183 int AliHLTFileWriter::ScanArgument(int argc, const char** argv)
185 // see header file for class documentation
187 // there are no other arguments than the standard ones
188 if (argc==0 && argv==NULL) {
189 // this is just to get rid of the warning "unused parameter"
191 // fCurrentFileName is used in dump event, just touched her to avoid
192 // coding convention violation RC11. The function can not be declared
193 // const since it is just the default implementation, overloaded
194 // virtual function might not be const
199 int AliHLTFileWriter::DoDeinit()
201 // see header file for class documentation
202 int iResult=CloseWriter();
203 ClearMode(kEnumerate);
207 int AliHLTFileWriter::CloseWriter()
209 // see header file for class documentation
211 // fCurrentFileName is used in dump event, just touched her to avoid
212 // coding convention violation RC11. The function can not be declared
213 // const since it is just the default implementation, overloaded
214 // virtual function might not be const
216 return 0; // note: this doesn't mean 'error'
219 int AliHLTFileWriter::DumpEvent( const AliHLTComponentEventData& evtData,
220 const AliHLTComponentBlockData* blocks,
221 AliHLTComponentTriggerData& trigData )
223 // see header file for class documentation
225 if (CheckMode(kConcatenateEvents)==0) {
226 // reset the current file name in order to open a new file
227 // for the first block. If events are concatenated, the current
228 // file name stays in order to be opended in append mode.
231 for (int n=0; n<(int)evtData.fBlockCnt; n++ ) {
232 //HLTDebug("block %d out of %d", n, evtData.fBlockCnt);
234 HLTDebug("dataspec 0x%x", blocks[n].fSpecification);
235 iResult=BuildFileName(evtData.fEventID, n, blocks[n].fDataType, filename);
236 ios::openmode filemode=(ios::openmode)0;
237 if (fCurrentFileName.CompareTo(filename)==0) {
238 // append to the file
241 // store the file for the next block
242 fCurrentFileName=filename;
245 ofstream dump(filename.Data(), filemode);
247 dump.write((const char*)blocks[n].fPtr, blocks[n].fSize);
248 HLTDebug("wrote %d byte(s) to file %s", blocks[n].fSize, filename.Data());
250 HLTError("can not open file %s for writing", filename.Data());
256 if (trigData.fStructSize==0) {
257 // this is just to get rid of the warning "unused parameter"
262 int AliHLTFileWriter::BuildFileName(const AliHLTEventID_t eventID, const int blockID, const AliHLTComponentDataType& dataType, TString& filename)
264 // see header file for class documentation
266 //HLTDebug("build file name for event %d block %d", eventID, blockID);
268 if (!fDirectory.IsNull()) {
269 filename+=fDirectory;
270 if (!fDirectory.EndsWith("/"))
273 if (!fBaseName.IsNull())
277 if (!CheckMode(kConcatenateEvents)) {
278 if (!CheckMode(kEnumerate)) {
279 if (eventID!=kAliHLTVoidEventID) {
280 filename+=Form("_0x%08x", eventID);
283 filename+=Form("_%d", GetEventCount());
286 if (blockID>=0 && !CheckMode(kConcatenateBlocks)) {
287 filename+=Form("_0x%x", blockID);
288 if (dataType!=kAliHLTVoidDataType) {
290 filename+=AliHLTComponent::DataType2Text(dataType).data();
293 if (!fExtension.IsNull())
294 filename+="." + fExtension;
295 filename.ReplaceAll(" ", "");
299 int AliHLTFileWriter::SetMode(Short_t mode)
301 // see header file for class documentation
303 //HLTDebug("mode set to 0x%x", fMode);
307 int AliHLTFileWriter::ClearMode(Short_t mode)
309 // see header file for class documentation
311 //HLTDebug("mode set to 0x%x", fMode);
315 int AliHLTFileWriter::CheckMode(Short_t mode) const
317 // see header file for class documentation
319 //HLTDebug("check mode 0x%x for flag 0x%x: %d", fMode, mode, (fMode&mode)!=0);
320 return (fMode&mode)!=0;