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 /** ROOT macro for the implementation of ROOT specific class methods */
34 ClassImp(AliHLTFileWriter)
36 AliHLTFileWriter::AliHLTFileWriter()
45 // see header file for class documentation
47 // refer to README to build package
49 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
52 AliHLTFileWriter::AliHLTFileWriter(const AliHLTFileWriter&)
61 // see header file for class documentation
62 HLTFatal("copy constructor untested");
65 AliHLTFileWriter& AliHLTFileWriter::operator=(const AliHLTFileWriter&)
67 // see header file for class documentation
68 HLTFatal("assignment operator untested");
72 AliHLTFileWriter::~AliHLTFileWriter()
74 // see header file for class documentation
76 // file list and file name list are owner of their objects and
77 // delete all the objects
80 const char* AliHLTFileWriter::GetComponentID()
82 // see header file for class documentation
86 void AliHLTFileWriter::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
88 // see header file for class documentation
90 list.push_back(kAliHLTAnyDataType);
93 AliHLTComponent* AliHLTFileWriter::Spawn()
95 // see header file for class documentation
96 return new AliHLTFileWriter;
99 int AliHLTFileWriter::DoInit( int argc, const char** argv )
101 // see header file for class documentation
105 for (int i=0; i<argc && iResult>=0; i++) {
107 if (argument.IsNull()) continue;
110 if (argument.CompareTo("-datafile")==0) {
111 if ((bMissingParam=(++i>=argc))) break;
113 TObjArray* pTokens=fBaseName.Tokenize(".");
115 int iEntries=pTokens->GetEntries();
118 fBaseName=((TObjString*)pTokens->At(i++))->GetString();
119 while (i<iEntries-1) {
120 fBaseName+="." + ((TObjString*)pTokens->At(i++))->GetString();
122 fExtension=((TObjString*)pTokens->At(i))->GetString();
128 } else if (argument.CompareTo("-directory")==0) {
129 if ((bMissingParam=(++i>=argc))) break;
133 } else if (argument.CompareTo("-enumerate")==0) {
136 // -concatenate-blocks
137 } else if (argument.CompareTo("-concatenate-blocks")==0) {
138 SetMode(kConcatenateBlocks);
140 // -concatenate-events
141 } else if (argument.CompareTo("-concatenate-events")==0) {
142 SetMode(kConcatenateEvents);
145 if ((iResult=ScanArgument(argc-i, &argv[i]))==-EINVAL) {
146 HLTError("unknown argument %s", argument.Data());
148 } else if (iResult==-EPROTO) {
151 } else if (iResult>=0) {
158 HLTError("missing parameter for argument %s", argument.Data());
162 iResult=InitWriter();
168 int AliHLTFileWriter::InitWriter()
170 // see header file for class documentation
171 return 0; // note: this doesn't mean 'error'
174 int AliHLTFileWriter::ScanArgument(int argc, const char** argv)
176 // see header file for class documentation
178 // there are no other arguments than the standard ones
179 if (argc==0 && argv==NULL) {
180 // this is just to get rid of the warning "unused parameter"
185 int AliHLTFileWriter::DoDeinit()
187 // see header file for class documentation
188 int iResult=CloseWriter();
189 ClearMode(kEnumerate);
193 int AliHLTFileWriter::CloseWriter()
195 // see header file for class documentation
196 return 0; // note: this doesn't mean 'error'
199 int AliHLTFileWriter::DumpEvent( const AliHLTComponentEventData& evtData,
200 const AliHLTComponentBlockData* blocks,
201 AliHLTComponentTriggerData& trigData )
203 // see header file for class documentation
205 if (CheckMode(kConcatenateEvents)==0) {
206 // reset the current file name in order to open a new file
207 // for the first block. If events are concatenated, the current
208 // file name stays in order to be opended in append mode.
211 for (int n=0; n<(int)evtData.fBlockCnt; n++ ) {
212 //HLTDebug("block %d out of %d", n, evtData.fBlockCnt);
214 HLTDebug("dataspec 0x%x", blocks[n].fSpecification);
215 iResult=BuildFileName(evtData.fEventID, n, blocks[n].fDataType, filename);
216 ios::openmode filemode=(ios::openmode)0;
217 if (fCurrentFileName.CompareTo(filename)==0) {
218 // append to the file
221 // store the file for the next block
222 fCurrentFileName=filename;
225 ofstream dump(filename.Data(), filemode);
227 dump.write((const char*)blocks[n].fPtr, blocks[n].fSize);
228 HLTDebug("wrote %d byte(s) to file %s", blocks[n].fSize, filename.Data());
230 HLTError("can not open file %s for writing", filename.Data());
236 if (trigData.fStructSize==0) {
237 // this is just to get rid of the warning "unused parameter"
242 int AliHLTFileWriter::BuildFileName(const AliHLTEventID_t eventID, const int blockID, const AliHLTComponentDataType& dataType, TString& filename)
244 // see header file for class documentation
246 //HLTDebug("build file name for event %d block %d", eventID, blockID);
248 if (!fDirectory.IsNull()) {
249 filename+=fDirectory;
250 if (!fDirectory.EndsWith("/"))
253 if (!fBaseName.IsNull())
257 if (!CheckMode(kConcatenateEvents)) {
258 if (!CheckMode(kEnumerate)) {
259 if (eventID!=kAliHLTVoidEventID) {
260 filename+=Form("_0x%08x", eventID);
263 filename+=Form("_%d", GetEventCount());
266 if (blockID>=0 && !CheckMode(kConcatenateBlocks)) {
267 filename+=Form("_0x%x", blockID);
268 if (dataType!=kAliHLTVoidDataType) {
270 filename+=AliHLTComponent::DataType2Text(dataType).data();
273 if (!fExtension.IsNull())
274 filename+="." + fExtension;
275 filename.ReplaceAll(" ", "");
279 int AliHLTFileWriter::SetMode(Short_t mode)
281 // see header file for class documentation
283 //HLTDebug("mode set to 0x%x", fMode);
287 int AliHLTFileWriter::ClearMode(Short_t mode)
289 // see header file for class documentation
291 //HLTDebug("mode set to 0x%x", fMode);
295 int AliHLTFileWriter::CheckMode(Short_t mode)
297 // see header file for class documentation
299 //HLTDebug("check mode 0x%x for flag 0x%x: %d", fMode, mode, (fMode&mode)!=0);
300 return (fMode&mode)!=0;