]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
- adding FileWriter option to write a configuration file for FilePublisher
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 25 Aug 2010 23:23:59 +0000 (23:23 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 25 Aug 2010 23:23:59 +0000 (23:23 +0000)
- enhanced argument scan in FilePublisher, option '-datafilelist' implemented

HLT/BASE/util/AliHLTFilePublisher.cxx
HLT/BASE/util/AliHLTFilePublisher.h
HLT/BASE/util/AliHLTFileWriter.cxx
HLT/BASE/util/AliHLTFileWriter.h

index 8ada91edff35d21346f76167c78c7a51c1de250e..8457872d82d70f778440f390a7f6b8bf8d2fa273 100644 (file)
@@ -108,7 +108,23 @@ AliHLTComponent* AliHLTFilePublisher::Spawn()
 int AliHLTFilePublisher::DoInit( int argc, const char** argv )
 {
   // see header file for class documentation
+  int iResult=0;
+  if ((iResult=ConfigureFromArgumentString(argc, argv))<0) return iResult;
 
+  if (iResult>=0 && fEvents.GetSize()==0) {
+    HLTError("the publisher needs at least one file argument");
+    iResult=-EINVAL;
+  }
+  if (iResult>=0) iResult=OpenFiles(fOpenFilesAtStart);
+  if (iResult<0) {
+    fEvents.Clear();
+  }
+  return iResult;
+}
+
+int AliHLTFilePublisher::ScanConfigurationArgument(int argc, const char** argv)
+{
+  // argument scan
   //HLTDebug("%d %s", argc, argv[0]);
   int iResult=0;
   TString argument="";
@@ -119,7 +135,8 @@ int AliHLTFilePublisher::DoInit( int argc, const char** argv )
   AliHLTComponentDataType currDataType=kAliHLTVoidDataType;
   AliHLTUInt32_t          currSpecification=kAliHLTVoidDataSpec;
   EventFiles*             pCurrEvent=NULL;
-  for (int i=0; i<argc && iResult>=0; i++) {
+  int i=0;
+  for (; i<argc && iResult>=0; i++) {
     argument=argv[i];
     if (argument.IsNull()) continue;
 
@@ -139,7 +156,26 @@ int AliHLTFilePublisher::DoInit( int argc, const char** argv )
       // -datafilelist
     } else if (argument.CompareTo("-datafilelist")==0) {
       if ((bMissingParam=(++i>=argc))) break;
-      HLTWarning("-datafilelist option not yet implemented");
+      TString input=argv[i];
+      input+="?filetype=raw";
+      TFile* pFile=new TFile(input);
+      if (pFile && !pFile->IsZombie()) {
+       pFile->Seek(0);
+       TArrayC buffer;
+       buffer.Set(pFile->GetSize());
+       if (pFile->ReadBuffer(buffer.GetArray(), buffer.GetSize())==0) {
+         const char* argbuffer=buffer.GetArray();
+         if ((iResult=ConfigureFromArgumentString(1, &argbuffer))<0) {
+           iResult=-EPROTO;
+         }
+       } else {
+         HLTError("failed to read configuration from file %s", argv[i]);
+         iResult=-EIO;
+       }
+      } else {
+       HLTError("can not open configuration file %s", argv[i]);
+       iResult=-ENOENT;
+      }
 
       // -datatype
     } else if (argument.CompareTo("-datatype")==0) {
@@ -221,14 +257,8 @@ int AliHLTFilePublisher::DoInit( int argc, const char** argv )
     HLTError("missing parameter for argument %s", argument.Data());
     iResult=-EINVAL;
   }
-  if (fEvents.GetSize()==0) {
-    HLTError("the publisher needs at least one file argument");
-    iResult=-EINVAL;
-  }
-  if (iResult>=0) iResult=OpenFiles(fOpenFilesAtStart);
-  if (iResult<0) {
-    fEvents.Clear();
-  }
+
+  if (iResult>=0) return i;
   return iResult;
 }
 
index 0ff0a5b4977221f890ec476d878249fbb0275c2b..fe38ba3d2b534e34c9234664159c4f99249796a4 100644 (file)
@@ -1,5 +1,5 @@
 // -*- Mode: C++ -*-
-// @(#) $Id$
+// $Id$
 
 #ifndef ALIHLTFILEPUBLISHER_H
 #define ALIHLTFILEPUBLISHER_H
@@ -7,12 +7,12 @@
 //* ALICE Experiment at CERN, All rights reserved.                         *
 //* See cxx source for full Copyright notice                               *
 
-/** @file   AliHLTFilePublisher.h
-    @author Matthias Richter
-    @date   
-    @brief  An HLT file publishing (data source) component.
-    @note   The class is used in Offline (AliRoot) context
-*/
+/ @file   AliHLTFilePublisher.h
+//  @author Matthias Richter
+//  @date   
+//  @brief  An HLT file publishing (data source) component.
+//  @note   The class is used in Offline (AliRoot) context
+// 
 
 #include "AliHLTDataSource.h"
 #include <TList.h>
@@ -33,21 +33,21 @@ class TFile;
  * <h2>Mandatory arguments:</h2>
  * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
  * \li -datafile     <i> filename      </i>
- * \li -datafilelist <i> file pattern  </i> <br>
- *      not yet implemented
+ * \li -datafilelist <i> configfile  </i> <br>
+ *      read arguments from a configfile
  * \li -datatype     <i> datatype   dataorigin </i> <br>
  *      data type ID and origin, e.g. <tt>-datatype 'CLUSTERS' 'TPC ' </tt>
  * \li -dataspec     <i> specification </i> <br>
  *      data specification treated as decimal number or hex number if
  *      prepended by '0x'
- * \li -nextevent
- *      indicate files published by the next event
  *
  * <h2>Optional arguments:</h2>
  * \li -open_files_at_start
  *      Opens all files during component initialisation rather than as needed
  *      during event processing. Note: this feature may result in the system
  *      running out of file handles if a large number of files was specified.
+ * \li -nextevent
+ *      indicate files published by the next event
  *
  * <h2>Configuration:</h2>
  * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
@@ -113,6 +113,9 @@ class AliHLTFilePublisher : public AliHLTDataSource  {
    */
   virtual int DoInit( int argc, const char** argv );
 
+  /// inherited from AliHLTComponent: argument scan
+  int ScanConfigurationArgument(int argc, const char** argv);
+
   /**
    * Deinit method.
    */
@@ -288,6 +291,6 @@ class AliHLTFilePublisher : public AliHLTDataSource  {
   /** Is raw file (kTRUE) [default] or root file (kFALSE). */
   Bool_t fIsRaw;                                                   //! transient     
 
-  ClassDef(AliHLTFilePublisher, 3)
+  ClassDef(AliHLTFilePublisher, 0)
 };
 #endif
index 320b7362ddf07d9783ec2a4315e11fdfd924b50a..617a4f5fc36e2fec606674e67d98bbb5dccf5f6e 100644 (file)
@@ -54,6 +54,8 @@ AliHLTFileWriter::AliHLTFileWriter()
   , fBurstBufferSize(0)
   , fBurstBlocks()
   , fBurstBlockEvents()
+  , fPublisherConfName()
+  , fPublisherConfEvent(-1)
 {
   // see header file for class documentation
   // or
@@ -86,6 +88,7 @@ int AliHLTFileWriter::SetDefaults()
   fBurstBufferSize=0;
   fBurstBlocks.clear();
   fBurstBlockEvents.clear();
+  fPublisherConfEvent=-1;
   return 0;
 }
 
@@ -201,6 +204,11 @@ int AliHLTFileWriter::DoInit( int argc, const char** argv )
     } else if (argument.CompareTo("-concatenate-events")==0) {
       SetMode(kConcatenateEvents);
 
+      // -publisher-conf
+    } else if (argument.CompareTo("-publisher-conf")==0) {
+      if ((bMissingParam=(++i>=argc))) break;
+      fPublisherConfName=argv[i];
+
       // -write-all-events
     } else if (argument.CompareTo("-write-all-events")==0) {
       SetMode(kWriteAllEvents);
@@ -268,6 +276,13 @@ int AliHLTFileWriter::DoInit( int argc, const char** argv )
     }
   }
 
+  if (!fPublisherConfName.IsNull()) {
+    if (CheckMode(kConcatenateBlocks) || CheckMode(kConcatenateEvents)) {
+      fPublisherConfName="";
+      HLTWarning("option 'concatenate blocks/events' collides with writing of FilePublisher configuration, ignoring option '-publisher-conf'");
+    }
+  }
+
   if (iResult>=0) {
     iResult=InitWriter();
     if (!fDirectory.IsNull()) {
@@ -557,5 +572,33 @@ int AliHLTFileWriter::WriteBlock(int blockno, const AliHLTEventID_t& eventID,
     }
     dump.close();
   }
+  if (iResult>=0 && !fPublisherConfName.IsNull()) {
+    if (!CheckMode(kConcatenateBlocks) &&
+       !CheckMode(kConcatenateEvents)) {
+      // append if not the first entry
+      if (fPublisherConfEvent>=0) filemode=ios::app;
+      else filemode=(ios::openmode)0;
+      ofstream conf(fPublisherConfName.Data(), filemode);
+      if (conf.good()) {
+       if (fPublisherConfEvent>=0 &&
+           fPublisherConfEvent!=GetEventCount()) {
+         conf << "-nextevent " << endl;
+       }
+       fPublisherConfEvent=GetEventCount();
+       conf << "-datatype ";
+       conf << DataType2Text(pDesc->fDataType, 3);
+       conf << " -datafile ";
+       conf << filename;
+       conf << endl;
+      } else {
+       fPublisherConfName="";
+       HLTError("can not open file %s for writing of configuration commands", fPublisherConfName.Data());
+      }
+      conf.close();
+    } else {
+       fPublisherConfName="";
+       HLTWarning("option 'concatenate blocks/events' collides with writing of FilePublisher configuration, disable ...");
+    }
+  }
   return iResult;
 }
index 9046a59b678ee62bbacf06ae043855c6ed2d048c..cd582bd70d670f158fa793f1e93e6a66e7d384df 100644 (file)
@@ -1,3 +1,4 @@
+// -*- Mode: C++ -*-
 // $Id$
 
 #ifndef ALIHLTFILEWRITER_H
@@ -67,6 +68,10 @@ class AliHLTBlockDataCollection;
  *      concatenate all events into one file, this skips the event no,
  *      the block no, and the block data type in the file name. Currently,
  *      this implies the -concatenate-blocks option.
+ * \li -publisher-conf <i>filename</i> <br>
+ *      write configuration file for FilePublisher component (AliHLTFilePublisher) <br>
+ *      one line per file: -datatype id origin -datafile filename           <br>
+ *      events separated by -nextevent
  * \li -write-all-events <br>
  *      by default, the file writer ignores all steering events like the
  *      the SOR/EOR events, with this option, all events will be considered
@@ -346,7 +351,12 @@ class AliHLTFileWriter : public AliHLTDataSink  {
 
   /** event ids for the burst blocks */
   vector<AliHLTEventID_t> fBurstBlockEvents;                       //!transient
+
+  /// configuration file of FilePublisher component
+  TString fPublisherConfName;                                      // see above
+  /// current event for FilePublisher configuration
+  int fPublisherConfEvent;                                         // see above
   
-  ClassDef(AliHLTFileWriter, 3)
+  ClassDef(AliHLTFileWriter, 0)
 };
 #endif