1 |
pam-fi |
1.1 |
/* |
2 |
|
|
* SaveEventsAction.cpp |
3 |
|
|
* |
4 |
|
|
* Created on: 16-mag-2009 |
5 |
|
|
* Author: Nicola Mori |
6 |
|
|
*/ |
7 |
|
|
|
8 |
|
|
/*! @file SaveEventsAction.cpp The SaveEventsAction class implementation file */ |
9 |
|
|
|
10 |
|
|
#include "SaveEventsAction.h" |
11 |
|
|
|
12 |
pam-fi |
1.3 |
SaveEventsAction::SaveEventsAction(const char *actionName, TString outFileName, TString outOptions) : |
13 |
|
|
CollectionAction(actionName), _outTreeFile(NULL), _events(NULL), _outOptions(outOptions), _outFileName(outFileName) { |
14 |
pam-fi |
1.1 |
|
15 |
|
|
} |
16 |
|
|
|
17 |
pam-fi |
1.2 |
void SaveEventsAction::Setup(PamLevel2 *events) { |
18 |
|
|
|
19 |
pam-fi |
1.3 |
// Open output file |
20 |
|
|
/* Due to the combined weirdness of PamLevel2 and ROOT, this pointer must NOT |
21 |
|
|
* be explicitly deleted, nor the file closed. This would generate a double |
22 |
|
|
* deletion in the destructors chain. This mechanism is not completely clear |
23 |
|
|
* but it indeed happens... |
24 |
|
|
*/ |
25 |
|
|
|
26 |
|
|
_outTreeFile = new TFile(_outFileName, "RECREATE"); |
27 |
|
|
|
28 |
|
|
if (_outTreeFile->IsZombie()) { |
29 |
|
|
cout << "Output file could not be created\n"; |
30 |
|
|
_outTreeFile->Delete(); |
31 |
|
|
//TODO Gestire con un'eccezione |
32 |
|
|
return; |
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
_events = events; |
36 |
|
|
if (_outOptions.Length() > 0) |
37 |
|
|
_events->SetWhichTrees(_outOptions); |
38 |
|
|
_events->CreateCloneTrees(_outTreeFile); |
39 |
pam-fi |
1.1 |
} |
40 |
|
|
|
41 |
pam-fi |
1.2 |
void SaveEventsAction::OnGood(PamLevel2 *event) { |
42 |
pam-fi |
1.3 |
// Fill the tree |
43 |
|
|
event->FillCloneTrees(); |
44 |
pam-fi |
1.1 |
} |
45 |
|
|
|
46 |
pam-fi |
1.2 |
void SaveEventsAction::Finalize() { |
47 |
pam-fi |
1.3 |
_outTreeFile->cd(); |
48 |
|
|
_events->WriteCloneTrees(); |
49 |
pam-fi |
1.1 |
|
50 |
|
|
} |