redirecting sub detector stdout, stderr to sub detector log file
authorjgrosseo <jgrosseo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 10 Apr 2007 16:53:14 +0000 (16:53 +0000)
committerjgrosseo <jgrosseo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 10 Apr 2007 16:53:14 +0000 (16:53 +0000)
SHUTTLE/AliShuttle.cxx
SHUTTLE/AliShuttle.h

index 73c3379baa326ef3c5a63371943b7d23744850b4..f822bccbea3ff44611d31f63e1fb3b2a07182ad1 100644 (file)
@@ -234,7 +234,8 @@ fLastActionTime(0),
 fLastAction(),
 fMonaLisa(0),
 fTestMode(kNone),
-fReadTestMode(kFALSE)
+fReadTestMode(kFALSE),
+fOutputRedirected(kFALSE)
 {
        //
        // config: AliShuttleConfig used
@@ -1190,6 +1191,20 @@ Bool_t AliShuttle::Process(AliShuttleLogbookEntry* entry)
                        // client
                        AliInfo(Form("In client process of %d - %s", GetCurrentRun(), aDetector->GetName()));
 
+                       AliInfo("Redirecting output...");
+
+                       if ((freopen(GetLogFileName(fCurrentDetector), "w", stdout)) == 0)
+                       {
+                               Log("SHUTTLE", "Could not freopen stdout");
+                       }
+                       else
+                       {
+                               fOutputRedirected = kTRUE;
+                               if ((dup2(fileno(stdout), fileno(stderr))) < 0)
+                                       Log("SHUTTLE", "Could not redirect stderr");
+                               
+                       }
+                       
                        Bool_t success = ProcessCurrentDetector();
                        if (success) // Preprocessor finished successfully!
                        { 
@@ -2162,12 +2177,12 @@ void AliShuttle::Log(const char* detector, const char* message)
        toLog += Form("%s", message);
 
        AliInfo(toLog.Data());
+       
+       // if we redirect the log output already to the file, leave here
+       if (fOutputRedirected && strcmp(detector, "SHUTTLE") != 0)
+               return;
 
-       TString fileName;
-       if (GetCurrentRun() >= 0) 
-               fileName.Form("%s/%s_%d.log", GetShuttleLogDir(), detector, GetCurrentRun());
-       else
-               fileName.Form("%s/%s.log", GetShuttleLogDir(), detector);
+       TString fileName = GetLogFileName(detector);
        
        gSystem->ExpandPathName(fileName);
 
@@ -2184,6 +2199,23 @@ void AliShuttle::Log(const char* detector, const char* message)
        logFile.close();
 }
 
+//______________________________________________________________________________________________
+TString AliShuttle::GetLogFileName(const char* detector) const
+{
+       // 
+       // returns the name of the log file for a given sub detector
+       //
+       
+       TString fileName;
+       
+       if (GetCurrentRun() >= 0) 
+               fileName.Form("%s/%s_%d.log", GetShuttleLogDir(), detector, GetCurrentRun());
+       else
+               fileName.Form("%s/%s.log", GetShuttleLogDir(), detector);
+
+       return fileName;
+}
+
 //______________________________________________________________________________________________
 Bool_t AliShuttle::Collect(Int_t run)
 {
index 30a0edf3864babbf36d0bc468702004cdb4b8b86..7c3921441cb0988087c60ec93587e19de795d760 100644 (file)
@@ -112,6 +112,8 @@ private:
        void UpdateShuttleStatus(AliShuttleStatus::Status newStatus, Bool_t increaseCount = kFALSE);
        Bool_t UpdateShuttleLogbook(const char* detector, const char* status=0);
        Bool_t SendMail();
+       
+       TString GetLogFileName(const char* detector) const;
 
        void SetLastAction(const char* action);
        
@@ -143,6 +145,8 @@ private:
 
        TestMode fTestMode;          // sets test mode flags, that e.g. simulate a dcs error etc.
        Bool_t fReadTestMode;        // Reads the test mode from the log entry of the given run (only for test)
+       
+       Bool_t fOutputRedirected;    // is the output redirected to a file
 
        ClassDef(AliShuttle, 0);
 };