00001 /* 00002 * SaveEventsAction.cpp 00003 * 00004 * Created on: 16-mag-2009 00005 * Author: Nicola Mori 00006 */ 00007 00010 #include "SaveEventsAction.h" 00011 00012 SaveEventsAction::SaveEventsAction(const char *actionName, TString outFileName, TString outOptions) : 00013 CollectionAction(actionName), _outTreeFile(NULL), _events(NULL), _outOptions(outOptions) { 00014 00015 // Open output file 00016 /* Due to the combined weirdness of PamLevel2 and ROOT, this pointer must NOT 00017 * be explicitly deleted, nor the file closed. This would generate a double 00018 * deletion in the destructors chain. This mechanism is not completely clear 00019 * but it indeed happens... 00020 */ 00021 _outTreeFile = new TFile(outFileName, "RECREATE"); 00022 00023 if (_outTreeFile->IsZombie()) { 00024 cout << "Output file could not be created\n"; 00025 _outTreeFile->Delete(); 00026 //TODO Gestire con un'eccezione 00027 return; 00028 } 00029 } 00030 00031 void SaveEventsAction::Setup(PamLevel2 *events){ 00032 _events = events; 00033 _events->CreateCloneTrees(_outTreeFile); 00034 if (_outOptions.Length() > 0) 00035 _events->SetWhichTrees(_outOptions); 00036 } 00037 00038 void SaveEventsAction::OnGood(PamLevel2 *event){ 00039 // Fill the tree 00040 event->FillCloneTrees(); 00041 } 00042 00043 void SaveEventsAction::Finalize(){ 00044 _outTreeFile->cd(); 00045 _events->WriteCloneTrees(); 00046 00047 }