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