Index: /fact/tools/rootmacros/PulseTemplates/FCalcPulseTemplate.C
===================================================================
--- /fact/tools/rootmacros/PulseTemplates/FCalcPulseTemplate.C	(revision 13850)
+++ /fact/tools/rootmacros/PulseTemplates/FCalcPulseTemplate.C	(revision 13851)
@@ -42,4 +42,5 @@
 #include "pixelsum.h"
 #include "templateextractors.h"
+#include "configfile.h"
 
 //----------------------------------------------------------------------------
@@ -88,14 +89,16 @@
     TString     OutputRootFileName     = "test.root",
     TString     OutPutPath          = "analysis/FPulseTemplate/20120309_018/",
+    int         firstpixel          = 0,
+    int         npixel              = -1,
+    int         pixelSetSize        = 200,
+    int         maxPulseOrder       = 3,
+    TString     histoOptions        = "SRM",
     bool        ProduceGraphic      = true,
+    bool        stats               = true,
+    bool        saveResults         = true,
 //    bool        fitdata             = false,
-    bool        stats               = false,
     bool        debugPixel          = false,
-    int         pixelSetSize        = 40,
-    int         maxPulseOrder       = 3,
 //    int         refresh_rate        = 500,      //refresh rate for canvases
-    int         verbosityLevel      = 5,        // different verbosity levels can be implemented here
-    int         firstpixel          = 0,
-    int         npixel              = 2
+    int         verbosityLevel      = 2        // different verbosity levels can be implemented here
         )
 {
@@ -104,4 +107,7 @@
     OutPutPath      = SetHostsPaths(true, OutPutPath );
 
+    TString outFile  = OutPutPath;
+    outFile         += OutputRootFileName;
+
 //----------------------------------------------------------------------------
 //	Open-Root-File Settings
@@ -113,5 +119,15 @@
 
     TFile * inputRootFile
-            = OpenRootFile( InputPath, InRootFileName, verbosityLevel );
+            = LoadRootFile( InputPath, InRootFileName, verbosityLevel );
+
+    if (inputRootFile == NULL)
+    {
+        cerr << "input file not readable, check file path!!!" << endl;
+        return(0);
+    }
+    if (saveResults)
+    {
+        CreateRootFile( outFile, true, verbosityLevel );
+    }
 
     TFile * outputRootFile
@@ -266,5 +282,13 @@
               pixelID++ )
         {
-
+            if (verbosityLevel >= 0)
+            {
+                cout << "------------------------------------------------"
+                     << endl
+                     << "...processing Pixel: "
+                     << pixelID << "/"
+                     << firstPixelOfSet + pixelSetSize - 1
+                     << endl;
+            }
             if (verbosityLevel > 1)
             {
@@ -298,5 +322,6 @@
                        -1,   ///TODO: get it from the root file
                        9,    ///TODO: get it from the root file
-                       inputRootFile
+                       inputRootFile,
+                       outputRootFile
                     );
 
@@ -379,21 +404,24 @@
                             );
 
-                WritePixelTemplateToCsv(
-                            pixel[pixelID],
-                            OutPutPath,
-                            "Maximum",
-                            pulse_order,
-                            verbosityLevel
-                            );
-
-                WritePixelTemplateToCsv(
-                            pixel[pixelID],
-                            OutPutPath,
-                            "Edge",
-                            pulse_order,
-                            verbosityLevel
-                            );
-
-                if (ProduceGraphic)
+                if ( saveResults )
+                {
+                    WritePixelTemplateToCsv(
+                                pixel[pixelID],
+                                OutPutPath,
+                                "Maximum",
+                                pulse_order,
+                                verbosityLevel
+                                );
+
+                    WritePixelTemplateToCsv(
+                                pixel[pixelID],
+                                OutPutPath,
+                                "Edge",
+                                pulse_order,
+                                verbosityLevel
+                                );
+                }
+
+                if (ProduceGraphic && debugPixel)
                 {
                     pixel[pixelID]->DrawTemplateHistograms(
@@ -439,5 +467,5 @@
             // End of Loop over pulsorder of current Pixel
 
-            if (ProduceGraphic)
+            if (ProduceGraphic && debugPixel)
             {
                 UpdateCanvases(
@@ -461,6 +489,11 @@
                 }
             }
-
-
+            if ( saveResults )
+            {
+                pixel[pixelID]->SavePixelHistograms(
+                            outFile,
+                            saveResults
+                            );
+            }
 
             //deleteCurrent Pixel from Heap
@@ -528,11 +561,14 @@
                     verbosityLevel
                     );
-        WritePixelTemplateToCsv(
-                    wholeCamera,
-                    OutPutPath,
-                    "Maximum",
-                    pulse_order,
-                    verbosityLevel
-                    );
+        if ( saveResults )
+        {
+            WritePixelTemplateToCsv(
+                        wholeCamera,
+                        OutPutPath,
+                        "Maximum",
+                        pulse_order,
+                        verbosityLevel
+                        );
+        }
 
         //from Edge Overlay
@@ -543,21 +579,27 @@
                     verbosityLevel
                     );
-        WritePixelTemplateToCsv(
-                    wholeCamera,
-                    OutPutPath,
-                    "Edge",
-                    pulse_order,
-                    verbosityLevel
-                    );
-
-//        wholeCamera->DrawTemplateHistograms(
-//                    cgpPixelPulses,
-//                    PixelCanvasFrameNrs
-//                    );
-
-//        wholeCamera->DrawEdgeTemplateHistograms(
-//                    cgpPixelPulses,
-//                    PixelCanvasFrameNrs
-//                    );
+        if ( saveResults )
+        {
+            WritePixelTemplateToCsv(
+                        wholeCamera,
+                        OutPutPath,
+                        "Edge",
+                        pulse_order,
+                        verbosityLevel
+                        );
+        }
+
+        if (ProduceGraphic)
+        {
+            wholeCamera->DrawTemplateHistograms(
+                        cgpPixelPulses,
+                        AllpixelCanvasFrameNrs
+                        );
+
+            wholeCamera->DrawEdgeTemplateHistograms(
+                        cgpPixelPulses,
+                        AllpixelCanvasFrameNrs
+                        );
+        }
     } //EOF: Draw All Pixel Histograms
 
@@ -566,27 +608,31 @@
 // Save All Pixel Histograms
 //-------------------------------------
-
-//    SaveHistograms(     //save histograms of all pixel into output root file
-//                OutInRootFileName,
-//                CreateSubDirName("All"),
-//                hAllPixelList,
-//                verbosityLevel
-//                );
-
-//    SaveHistograms(     //save histograms of generell results into output root file
-//                OutInRootFileName,
-//                "root",
-//                hRootList,
-//                verbosityLevel
-//                );
-
-//    if (ProduceGraphic)
-//    {
-//        UpdateCanvases(
-//                    verbosityLevel,
-//                    MAX_PULS_ORDER,
-//                    false
-//                    );
-//    }
+    if ( saveResults )
+    {
+        wholeCamera->SavePixelHistograms(
+                    outFile,
+                    saveResults
+                    );
+    }
+
+    if (ProduceGraphic)
+    {
+        UpdateCanvases(
+                    verbosityLevel,
+                    MAX_PULS_ORDER,
+                    false
+                    );
+
+        //Process gui events asynchronously during input
+        cout << endl;
+        TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
+        timer.TurnOn();
+        TString input = Getline("press <return> to exit: ");
+        timer.TurnOff();
+        if (input=="q\n")
+        {
+               break;
+        }
+    }
 
 //-------------------------------------
@@ -671,7 +717,112 @@
 //-----------------------------------------------------------------------------
 
-int main()
+int main(int argc,char *argv[])
 {
-    FCalcPulseTemplate();
+//    Int_t   index;
+    TString     test;
+    TString     rcFileName;
+    TString     processType             = "template";
+    bool        rcFileNameCmdSet        = false;
+    int         verbLevel               = 0; // different verbosity levels can be implemented here
+    bool        verbLevelCmdSet         = false;
+    bool        save                    = false;
+    bool        produceGraphic          = false;
+
+//    TString     inputRootFile       = "test.root";
+//    TString     inputPath           = "";
+//    TString     outputRootFile      = "test.root";
+//    TString     outPutPath          = "";
+//    int         firstPixel          = 0;
+//    int         nPixel              = -1;
+//    int         pixelSetSize        = 40;
+//    int         maxOrder            = 3;
+//    bool        dbgPixel            = false;
+//    bool        fitdata             = false;
+//    bool        printStats          = false;
+
+    // decode arguments
+    if(argc < 2)
+    {
+        printf("no arguements given, using standard arguments\n");
+    }
+
+    // set conditions for functions arguments
+    for (int i=1;i<argc;i++)
+    {
+        test = argv[i];
+
+        if (test.Contains("--config-file") || test.Contains("-c"))
+        {
+            cout << "RC-File: \"" << argv[i + 1] << "\"" << endl;
+            rcFileName = argv[i + 1];
+            rcFileNameCmdSet = true;
+            continue;
+        }
+
+        if (test.Contains("--verbosity") || test.Contains("-v"))
+        {
+            cout << "Verbosity Level: \"" << argv[i + 1] << "\"" << endl;
+            verbLevel = atoi(argv[i + 1]);
+            continue;
+        }
+
+        if (test.Contains("--save") || test.Contains("-s"))
+        {
+            cout << "will save results" << endl;
+            save = true;
+            continue;
+        }
+
+        if (test.Contains("--graphics") || test.Contains("-g"))
+        {
+            cout << "will produce graphics" << endl;
+            produceGraphic = true;
+            continue;
+        }
+    }
+
+    // reading rc-File:
+    if (rcFileNameCmdSet)
+    {
+            configfile rcfile( rcFileName, processType );
+
+        if (save)
+        {
+            rcfile.mSave = save;
+        }
+
+        if (verbLevelCmdSet)
+        {
+            rcfile.mVerbLevel = verbLevel;
+        }
+
+        if (produceGraphic)
+        {
+            rcfile.mProduceGraphic = produceGraphic;
+        }
+
+    //
+        FCalcPulseTemplate(
+                    rcfile.mInputFile,
+                    rcfile.mInputPath,
+                    rcfile.mOutputFile,
+                    rcfile.mOutputPath,
+                    rcfile.mFirstPixel,
+                    rcfile.mNumPixel,
+                    rcfile.mPixelSetSize,
+                    rcfile.mMaxOrder,
+                    rcfile.mHistoOptions,
+                    rcfile.mProduceGraphic,
+                    rcfile.mPrintStats,
+                    rcfile.mSave,
+                    rcfile.mDbgPixel,
+                    rcfile.mVerbLevel
+                    );
+    }
+    else
+    {
+        cout << "user: check if configfile is set correctly in cmd" << endl;
+    }
+
     return 0;
 }
