10 |
#include "SaveEventsAction.h" |
#include "SaveEventsAction.h" |
11 |
|
|
12 |
SaveEventsAction::SaveEventsAction(const char *actionName, TString outFileName, TString outOptions) : |
SaveEventsAction::SaveEventsAction(const char *actionName, TString outFileName, TString outOptions) : |
13 |
CollectionAction(actionName), _outTreeFile(NULL), _events(NULL), _outOptions(outOptions) { |
CollectionAction(actionName), _outTreeFile(NULL), _events(NULL), _outOptions(outOptions), _outFileName(outFileName) { |
14 |
|
|
15 |
|
} |
16 |
|
|
17 |
|
void SaveEventsAction::Setup(PamLevel2 *events) { |
18 |
|
|
19 |
// Open output file |
// Open output file |
20 |
/* Due to the combined weirdness of PamLevel2 and ROOT, this pointer must NOT |
/* Due to the combined weirdness of PamLevel2 and ROOT, this pointer must NOT |
22 |
* deletion in the destructors chain. This mechanism is not completely clear |
* deletion in the destructors chain. This mechanism is not completely clear |
23 |
* but it indeed happens... |
* but it indeed happens... |
24 |
*/ |
*/ |
25 |
_outTreeFile = new TFile(outFileName, "RECREATE"); |
|
26 |
|
_outTreeFile = new TFile(_outFileName, "RECREATE"); |
27 |
|
|
28 |
if (_outTreeFile->IsZombie()) { |
if (_outTreeFile->IsZombie()) { |
29 |
cout << "Output file could not be created\n"; |
cout << "Output file could not be created\n"; |
31 |
//TODO Gestire con un'eccezione |
//TODO Gestire con un'eccezione |
32 |
return; |
return; |
33 |
} |
} |
|
} |
|
34 |
|
|
|
void SaveEventsAction::Setup(PamLevel2 *events){ |
|
35 |
_events = events; |
_events = events; |
|
_events->CreateCloneTrees(_outTreeFile); |
|
36 |
if (_outOptions.Length() > 0) |
if (_outOptions.Length() > 0) |
37 |
_events->SetWhichTrees(_outOptions); |
_events->SetWhichTrees(_outOptions); |
38 |
|
_events->CreateCloneTrees(_outTreeFile); |
39 |
} |
} |
40 |
|
|
41 |
void SaveEventsAction::OnGood(PamLevel2 *event){ |
void SaveEventsAction::OnGood(PamLevel2 *event) { |
42 |
// Fill the tree |
// Fill the tree |
43 |
event->FillCloneTrees(); |
event->FillCloneTrees(); |
44 |
} |
} |
45 |
|
|
46 |
void SaveEventsAction::Finalize(){ |
void SaveEventsAction::Finalize() { |
47 |
_outTreeFile->cd(); |
_outTreeFile->cd(); |
48 |
_events->WriteCloneTrees(); |
_events->WriteCloneTrees(); |
49 |
|
|