]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
code cleanup
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 29 Nov 2010 10:59:18 +0000 (10:59 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 29 Nov 2010 10:59:18 +0000 (10:59 +0000)
- declaring member functions const
- adding Print function
- require explicite call to AliHLTConfiguration::ExtractSources instead of indirect call from status function SourcesResolved()
- disable copy constructor and assignment operator of logging helper class AliHLTKeyword

HLT/BASE/AliHLTConfiguration.cxx
HLT/BASE/AliHLTConfiguration.h
HLT/BASE/AliHLTLogging.h
HLT/BASE/AliHLTSystem.cxx

index f0e1c96a9fa8d3a01dc91c2affd21ecde2c35f41..4ec0f5d82c7c986b919b8aad54c3ebfcd07c7056 100644 (file)
@@ -52,7 +52,7 @@ AliHLTConfiguration::AliHLTConfiguration()
   fStringSources(""),
   fNofSources(-1),
   fListSources(),
-  fListSrcElement(),
+  fListSrcElementIdx(-1),
   fArguments(""),
   fArgc(-1),
   fArgv(NULL),
@@ -63,8 +63,6 @@ AliHLTConfiguration::AliHLTConfiguration()
   // refer to README to build package
   // or
   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
-
-  fListSrcElement=fListSources.begin();
 }
 
 AliHLTConfiguration::AliHLTConfiguration(const char* id, const char* component, const char* sources,
@@ -75,7 +73,7 @@ AliHLTConfiguration::AliHLTConfiguration(const char* id, const char* component,
   fStringSources(sources),
   fNofSources(-1),
   fListSources(),
-  fListSrcElement(),
+  fListSrcElementIdx(-1),
   fArguments(arguments),
   fArgc(-1),
   fArgv(NULL),
@@ -83,12 +81,11 @@ AliHLTConfiguration::AliHLTConfiguration(const char* id, const char* component,
 {
   // see header file for function documentation
   if (bufsize) fBufferSize=ConvertSizeString(bufsize);
-  fListSrcElement=fListSources.begin();
   if (id && component) {
     if (fgConfigurationHandler) {
       fgConfigurationHandler->RegisterConfiguration(this);
     } else {
-      HLTError("no configuration handler set, abort registration");
+      HLTWarning("no configuration handler set, skip registration");
     }
   }
 }
@@ -102,19 +99,20 @@ AliHLTConfiguration::AliHLTConfiguration(const AliHLTConfiguration& src)
   fStringSources(src.fStringSources),
   fNofSources(-1),
   fListSources(),
-  fListSrcElement(),
+  fListSrcElementIdx(-1),
   fArguments(src.fArguments),
   fArgc(-1),
   fArgv(NULL),
   fBufferSize(src.fBufferSize)
 { 
   // see header file for function documentation
-  fListSrcElement=fListSources.begin();
 }
 
 AliHLTConfiguration& AliHLTConfiguration::operator=(const AliHLTConfiguration& src)
 { 
   // see header file for function documentation
+  if (this==&src) return *this;
+
   fID=src.fID;
   fComponent=src.fComponent;
   fStringSources=src.fStringSources;
@@ -194,8 +192,9 @@ AliHLTConfiguration* AliHLTConfiguration::GetSource(const char* id)
   AliHLTConfiguration* pSrc=NULL;
   if (id) {
     // first check the current element
-    if (fListSrcElement!=fListSources.end() && strcmp(id, (*fListSrcElement)->GetName())==0) {
-      pSrc=*fListSrcElement;
+    if (fListSrcElementIdx>=0 && fListSrcElementIdx<(int)fListSources.size() &&
+       strcmp(id, (fListSources[fListSrcElementIdx])->GetName())==0) {
+      pSrc=fListSources[fListSrcElementIdx];
       } else {
       // check the list
 
@@ -210,35 +209,35 @@ AliHLTConfiguration* AliHLTConfiguration::GetSource(const char* id)
   return pSrc;
 }
 
-AliHLTConfiguration* AliHLTConfiguration::GetFirstSource()
+AliHLTConfiguration* AliHLTConfiguration::GetFirstSource() const
 {
   // see header file for function documentation
   AliHLTConfiguration* pSrc=NULL;
-  if (fNofSources>=0 || ExtractSources()>=0) {
-    fListSrcElement=fListSources.begin();
-    if (fListSrcElement!=fListSources.end()) pSrc=*fListSrcElement;
+  if (fNofSources>0) {
+    const_cast<AliHLTConfiguration*>(this)->fListSrcElementIdx=-1;
+    pSrc=GetNextSource();
   } 
   return pSrc;
 }
 
-AliHLTConfiguration* AliHLTConfiguration::GetNextSource()
+AliHLTConfiguration* AliHLTConfiguration::GetNextSource() const
 {
   // see header file for function documentation
   AliHLTConfiguration* pSrc=NULL;
   if (fNofSources>0) {
-    if (fListSrcElement!=fListSources.end() && (++fListSrcElement)!=fListSources.end()) 
-      pSrc=*fListSrcElement;
+    if (fListSrcElementIdx+1<(int)fListSources.size()) {
+      const_cast<AliHLTConfiguration*>(this)->fListSrcElementIdx++;
+      pSrc=fListSources[fListSrcElementIdx];
+    }
   } 
   return pSrc;
 }
 
-int AliHLTConfiguration::SourcesResolved(int bAuto) 
+int AliHLTConfiguration::SourcesResolved() const
 {
   // see header file for function documentation
   int iResult=0;
-  if (fNofSources>=0 || (bAuto && (iResult=ExtractSources()))>=0) {
-    //HLTDebug("fNofSources=%d", fNofSources);
-    //HLTDebug("list size = %d", fListSources.size());
+  if (fNofSources>=0) {
     iResult=fNofSources==(int)fListSources.size();
   }
   return iResult;
@@ -253,7 +252,7 @@ int AliHLTConfiguration::InvalidateSource(AliHLTConfiguration* pConf)
     while (element!=fListSources.end()) {
       if (*element==pConf) {
        fListSources.erase(element);
-       fListSrcElement=fListSources.end();
+       fListSrcElementIdx=fListSources.size();
        // there is no need to re-evaluate until there was a new configuration registered
        // -> postpone the invalidation, its done in AliHLTConfigurationHandler::RegisterConfiguration
        //InvalidateSources();
@@ -267,7 +266,7 @@ int AliHLTConfiguration::InvalidateSource(AliHLTConfiguration* pConf)
   return iResult;
 }
 
-void AliHLTConfiguration::PrintStatus()
+void AliHLTConfiguration::PrintStatus() const
 {
   // see header file for function documentation
   HLTLogKeyword("configuration status");
@@ -276,7 +275,7 @@ void AliHLTConfiguration::PrintStatus()
   else HLTMessage("  - component string invalid");
   if (!fStringSources.IsNull()) HLTMessage("  - sources: \"%s\"", fStringSources.Data());
   else HLTMessage("  - no sources");
-  if (SourcesResolved(1)<=0)
+  if (SourcesResolved()!=1)
     HLTMessage("    there are unresolved sources");
   AliHLTConfiguration* pSrc=GetFirstSource();
   while (pSrc) {
@@ -285,6 +284,22 @@ void AliHLTConfiguration::PrintStatus()
   }
 }
 
+void AliHLTConfiguration::Print(const char* option) const
+{
+  // print information
+  if (option && strcmp(option, "status")==0) {
+    PrintStatus();
+    return;
+  }
+  HLTLogKeyword("configuration");
+  HLTMessage("configuration %s: component %s, sources %s, arguments %s",
+            GetName(),
+            GetComponentID(),
+            GetSourceSettings(),
+            GetArgumentSettings()
+            );
+}
+
 int AliHLTConfiguration::GetArguments(const char*** pArgv) const
 {
   // see header file for function documentation
@@ -312,15 +327,18 @@ int AliHLTConfiguration::ExtractSources()
 {
   // see header file for function documentation
   int iResult=0;
-  fNofSources=0;
+  fNofSources=0; // indicates that the function was called, there are either n or 0 sources
+  fListSources.clear();
+  if (!fgConfigurationHandler) {
+    HLTError("global configuration handler not initialized, can not resolve sources");
+    return -EFAULT;
+  }
   if (!fStringSources.IsNull()) {
     vector<char*> tgtList;
-    fListSources.clear();
     if ((iResult=InterpreteString(fStringSources.Data(), tgtList))>=0) {
       fNofSources=tgtList.size();
       vector<char*>::iterator element=tgtList.begin();
       while ((element=tgtList.begin())!=tgtList.end()) {
-       if (fgConfigurationHandler) {
          AliHLTConfiguration* pConf=fgConfigurationHandler->FindConfiguration(*element);
          if (pConf) {
            //HLTDebug("configuration %s (%p): source \"%s\" (%p) inserted", GetName(), this, pConf->GetName(), pConf);
@@ -329,17 +347,13 @@ int AliHLTConfiguration::ExtractSources()
            HLTError("can not find source \"%s\"", (*element));
            iResult=-ENOENT;
          }
-       } else if (iResult>=0) {
-         iResult=-EFAULT;
-         HLTFatal("global configuration handler not initialized, can not resolve sources");
-       }
        delete[] (*element);
        tgtList.erase(element);
       }
-      fListSrcElement=fListSources.begin();
     }
   }
-  return iResult;
+  fListSrcElementIdx=-1;
+  return iResult<0?iResult:SourcesResolved();
 }
 
 int AliHLTConfiguration::ExtractArguments()
index bf9055b0e7a1a5f411fe9a52ad5696cb7f740dd5..7139c9ca220cc7202981ed3aaba8539daf545055 100644 (file)
@@ -7,17 +7,11 @@
 //* ALICE Experiment at CERN, All rights reserved.                         *
 //* See cxx source for full Copyright notice                               *
 
-//  @file   AliHLTConfiguration.h
-//  @author Matthias Richter
-//  @date   
-//  @brief  HLT configuration description for a single component.
-//  @note   The class is used in Offline (AliRoot) context
-
-// see below for class documentation
-// or
-// refer to README to build package
-// or
-// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt   
+/// @file   AliHLTConfiguration.h
+/// @author Matthias Richter
+/// @date   
+/// @brief  HLT configuration description for a single component.
+/// @note   The class is used in Offline (AliRoot) context
 
 #include <vector>
 #include <TObject.h>
@@ -56,8 +50,8 @@ class AliHLTConfigurationHandler;
  * The registration mechanism requires the HLT system to be available. The
  * global instance of AliHLTSystem is created and retrieved by
  * <pre>
- * // setup the HLT system
- * AliHLTSystem* pHLT=AliHLTPluginBase::GetInstance();
+ *   // setup the HLT system
+ *   AliHLTSystem* pHLT=AliHLTPluginBase::GetInstance();
  * </pre>
  *
  * A configuration is transformed into a list of AliHLTTask objects by the
@@ -142,7 +136,14 @@ class AliHLTConfiguration : public TObject, public AliHLTLogging {
    * Print status info.
    * Short summary on id, component, sources and unresolved sources.
    */
-  void PrintStatus();
+  void PrintStatus() const;
+
+  /**
+   * overloaded from TObject
+   * options:
+   *   status  - print status including the resolved sources
+   */
+  virtual void Print(const char* option="") const;
 
   /**
    * Get a certain source.
@@ -170,22 +171,28 @@ class AliHLTConfiguration : public TObject, public AliHLTLogging {
 
   /**
    * Check resolving status.
-   * @param bAuto resolve if ==1 
-   * @return 1 if all sources resolved
+   * @return 1 if all sources resolved, 0 if not yet extracted or not resolved
+   */
+  int SourcesResolved() const;
+
+  /**
+   * extract the source configurations from the sources string
+   * builds up the internal list of source configurations
+   * @result 1 if sources resolved, 0 if not
    */
-  int SourcesResolved(int bAuto=0);
+  int ExtractSources();
 
   /**
    * Start iteration and get the first source.
    * @result pointer to the first configuration descriptor
    */
-  AliHLTConfiguration* GetFirstSource();
+  AliHLTConfiguration* GetFirstSource() const;
 
   /**
    * Continue iteration and get the next source.
    * @result pointer to the next configuration descriptor in the list
    */
-  AliHLTConfiguration* GetNextSource();
+  AliHLTConfiguration* GetNextSource() const;
 
   /**
    * Invalidate a dependency and mark the configuration to be re-evaluted. 
@@ -234,10 +241,6 @@ class AliHLTConfiguration : public TObject, public AliHLTLogging {
   
 
  private:
-  /* extract the source configurations from the sources string
-   */
-  int ExtractSources();
-
   /* extract arguments from the argument string
    */
   int ExtractArguments();
@@ -255,11 +258,11 @@ class AliHLTConfiguration : public TObject, public AliHLTLogging {
   /** the <i>sources</i> string as passed to the constructor */
   TString fStringSources;                                          // see above
   /** number of resolved sources, -1 indicates re-evaluation */
-  int fNofSources;                                                 // see above
+  int fNofSources;                                                 //! transient
   /** list of sources */
-  vector<AliHLTConfiguration*> fListSources;                       // see above
-  /** iterator for the above list */
-  vector<AliHLTConfiguration*>::iterator fListSrcElement;          // see above
+  vector<AliHLTConfiguration*> fListSources;                       //! transient
+  /** index of the current element in the list of sources */
+  int fListSrcElementIdx;                                          //! transient
 
   /**
    * The argument string as passed to the constructor.
@@ -269,9 +272,9 @@ class AliHLTConfiguration : public TObject, public AliHLTLogging {
    */
   TString fArguments;                                              // see above
   /** number of arguments */
-  int fArgc;                                                       // see above
+  int fArgc;                                                       //! transient
   /** argument array */
-  char** fArgv;                                                    // see above
+  char** fArgv;                                                    //! transient
 
   /** size of the output buffer */
   int fBufferSize;                                                 // see above
@@ -279,7 +282,7 @@ class AliHLTConfiguration : public TObject, public AliHLTLogging {
   /** the instance of the global configuration handler */
   static AliHLTConfigurationHandler* fgConfigurationHandler;       //! transient
 
-  ClassDef(AliHLTConfiguration, 0);
+  ClassDef(AliHLTConfiguration, 1);
 };
 
 #endif
index ba93efdcac4cd7230ee0b380911186157130d74a..b7f2c75f05e95b1bc548c4e84cf42dd95d7241b5 100644 (file)
@@ -131,6 +131,8 @@ public:
 
   /**
    * Set a temporary keyword
+   * Keywords need to be static const strings, the class handles only
+   * pointers and assumes the strings to be persistent.
    * returns the old key value
    */
   const char* SetKeyword(const char* keyword) 
@@ -355,7 +357,8 @@ private:
 /* the class AliHLTKeyword is a simple helper class used by the HLTLogKeyword macro
  * HLTLogKeyword("a keyword") creates an object of AliHLTKeyword which sets the keyword for the logging class
  * the object is destroyed automatically when the current scope is left and so the keyword is set
- * to the original value
+ * to the original value. Please note that all keywords need to be static strings, only pointyers
+ * are handled and the strings required to ber persistent.
  */
 class AliHLTKeyword {
  public:
@@ -366,30 +369,18 @@ class AliHLTKeyword {
     {
     }
 
-  AliHLTKeyword(AliHLTLogging* parent, const char* keyword)
+  AliHLTKeyword(const AliHLTLogging* parent, const char* keyword)
     :
-    fpParent(parent),
+    fpParent(const_cast<AliHLTLogging*>(parent)),
     fpOriginal(NULL)
     {
-      if (parent) {
+      // the const cast is on purpose in order to be allowed to use
+      // HLTLogKeyword from const member functions
+      if (fpParent) {
        fpOriginal=fpParent->SetKeyword(keyword);
       }
     }
 
-  AliHLTKeyword(const AliHLTKeyword& kw)
-    :
-    fpParent(kw.fpParent),
-    fpOriginal(kw.fpOriginal)
-    {
-    }
-
-  AliHLTKeyword& operator=(const AliHLTKeyword& kw)
-    { 
-      fpParent=kw.fpParent;
-      fpOriginal=kw.fpOriginal;
-      return *this;
-    }
-
   ~AliHLTKeyword()
     {
       if (fpParent) {
@@ -398,6 +389,11 @@ class AliHLTKeyword {
     }
 
  private:
+  /// copy constructor prohibited
+  AliHLTKeyword(const AliHLTKeyword& kw);
+  /// assignment operator prohibited
+  AliHLTKeyword& operator=(const AliHLTKeyword& kw);
+
   AliHLTLogging* fpParent;                                         //! transient
   const char* fpOriginal;                                          //! transient
 };
index b62f5fe106d85cea1d2974fe2e8716a515ff55e7..ed0de420f0d62b76b95d26793595e77b065b50dd 100644 (file)
@@ -183,7 +183,8 @@ int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
       }
       // task for this configuration exists, terminate
       pTask=NULL;
-    } else if (pConf->SourcesResolved(1)!=1) {
+    // check first if the configuration has all sources resolved, try to extract otherwise
+    } else if (pConf->SourcesResolved()!=1 && pConf->ExtractSources()!=1) {
        HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
        iResult=-ENOLINK;
     } else {