]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Add WriteFile
authorcholm <cholm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 26 Apr 2011 20:23:14 +0000 (20:23 +0000)
committercholm <cholm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 26 Apr 2011 20:23:14 +0000 (20:23 +0000)
PWG2/FORWARD/analysis2/AliForwardCorrectionManager.cxx
PWG2/FORWARD/analysis2/AliForwardCorrectionManager.h

index b359c5a2b9cd04165dabff840c4404e552b10d71..a4cd2a52fbceae0bbd540e53ddf6b2c82864fc24 100644 (file)
@@ -909,6 +909,78 @@ AliForwardCorrectionManager::Browse(TBrowser* b)
   if (fAcceptance)       b->Add(fAcceptance,        "Acceptance corr");
 }
 
+//____________________________________________________________________
+Bool_t
+AliForwardCorrectionManager::WriteFile(ECorrection what, 
+                                      UShort_t    sys, 
+                                      UShort_t    sNN, 
+                                      Short_t     fld, 
+                                      Bool_t      mc,
+                                      TObject*    obj, 
+                                      Bool_t      full) const
+{
+  // 
+  // Write correction output to (a temporary) file 
+  // 
+  // Parameters: 
+  //   What     What to write 
+  //   sys      Collision system (1: pp, 2: PbPb)
+  //   sNN      Center of mass energy per nucleon (GeV)
+  //   fld      Field (kG)
+  //   mc       MC-only flag 
+  //   obj      Object to write 
+  //   full     if true, write to full path, otherwise locally
+  // 
+  // Return: 
+  //   true on success. 
+  TString ofName;
+  if (!full)
+    ofName = GetFileName(what, sys, sNN, fld, mc);
+  else 
+    ofName = GetFilePath(what, sys, sNN, fld, mc);
+  if (ofName.IsNull()) { 
+    AliError(Form("Unknown object type %d", what));
+    return false;
+  }
+  TFile* output = TFile::Open(ofName, "RECREATE");
+  if (!output) { 
+    AliError(Form("Failed to open file %s", ofName.Data()));
+    return false;
+  }
+
+  TString oName(GetObjectName(what));
+  Int_t ret = obj->Write(oName);
+  if (ret <= 0) { 
+    AliError(Form("Failed to write %p to %s/%s (%d)", 
+                 obj, ofName.Data(), oName.Data(), ret));
+    return false;
+  }
+
+  ret = output->Write();
+  if (ret < 0) { 
+    AliError(Form("Failed to write %s to disk (%d)", ofName.Data(), ret));
+    return false;
+  }
+  output->ls();
+  output->Close();
+  
+  TString cName(obj->IsA()->GetName());
+  AliInfo(Form("Wrote %s object %s to %s",
+              cName.Data(), oName.Data(), ofName.Data()));
+  if (!full) { 
+    TString dName(GetFileDir(what));
+    AliInfo(Form("%s should be copied to %s"
+                "Do for example\n\n\t"
+                "aliroot $ALICE_ROOT/PWG2/FORWARD/analysis2/scripts/"
+                "MoveCorrections.C\\(%d\\)\nor\n\t"
+                "cp %s %s/\n", 
+                ofName.Data(),dName.Data(),
+                what, ofName.Data(), 
+                gSystem->ExpandPathName(dName.Data())));
+  }
+  return true;
+}
+
 #ifndef DOXY_INPUT
 //______________________________________________________________________________
 void AliForwardCorrectionManager::Streamer(TBuffer &R__b)
index 9beea99ff6dfea80882f067968d930fc7a1856a4..cc5c2c6be0393b356bf0abb2809549625dc30a98 100644 (file)
@@ -326,6 +326,22 @@ public:
   /* 
    * @}
    */
+  /** 
+   * Write a correction object to (a temporary) file.  
+   *    
+   * @param what   What kind of correction
+   * @param sys    Collision system
+   * @param cms    Center of mass energy
+   * @param field  Field 
+   * @param mc     Whether this is for MC only
+   * @param o      Object to write
+   * @param full   If true, write to full path
+   * 
+   * @return True on success 
+   */
+  Bool_t WriteFile(ECorrection what, 
+                  UShort_t sys, UShort_t cms, Short_t field, Bool_t mc,
+                  TObject* o, Bool_t full) const;
 private:
   /** 
    * Copy constructor