1 |
paus |
1.5 |
// $Id: TreeService.cc,v 1.4 2008/06/17 08:24:09 loizides Exp $
|
2 |
loizides |
1.1 |
|
3 |
|
|
#include "MitProd/TreeService/interface/TreeService.h"
|
4 |
|
|
#include "DataFormats/Provenance/interface/ModuleDescription.h"
|
5 |
|
|
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
6 |
|
|
#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
|
7 |
|
|
#include "FWCore/ServiceRegistry/interface/Service.h"
|
8 |
|
|
#include "FWCore/MessageLogger/interface/JobReport.h"
|
9 |
|
|
#include "MitAna/DataUtil/interface/TreeWriter.h"
|
10 |
|
|
|
11 |
|
|
using namespace edm;
|
12 |
|
|
using namespace std;
|
13 |
|
|
using namespace mithep;
|
14 |
|
|
|
15 |
paus |
1.2 |
//--------------------------------------------------------------------------------------------------
|
16 |
loizides |
1.3 |
TreeService::TreeService(const ParameterSet &cfg, ActivityRegistry &r) :
|
17 |
paus |
1.5 |
tws_ (0),
|
18 |
loizides |
1.3 |
treeNames_ (cfg.getUntrackedParameter<vector<string> >("treeNames")),
|
19 |
|
|
fileNames_ (cfg.getUntrackedParameter<vector<string> >("fileNames")),
|
20 |
|
|
pathNames_ (cfg.getUntrackedParameter<vector<string> >("pathNames")),
|
21 |
|
|
maxSizes_ (cfg.getUntrackedParameter<vector<unsigned> >("maxSizes")),
|
22 |
|
|
compLevels_ (cfg.getUntrackedParameter<vector<unsigned> >("compLevels")),
|
23 |
|
|
splitLevels_(cfg.getUntrackedParameter<vector<unsigned> >("splitLevels")),
|
24 |
|
|
brSizes_ (cfg.getUntrackedParameter<vector<unsigned> >("brSizes"))
|
25 |
|
|
{
|
26 |
|
|
if (treeNames_.size()!=fileNames_.size()) {
|
27 |
|
|
throw edm::Exception(edm::errors::Configuration, "TreeService::TreeService()\n")
|
28 |
|
|
<< "Number of main trees should match number of files " << treeNames_.size()
|
29 |
|
|
<< " " << fileNames_.size() << "\n";
|
30 |
|
|
return;
|
31 |
loizides |
1.1 |
}
|
32 |
|
|
|
33 |
|
|
// setup tw array
|
34 |
|
|
tws_.SetOwner(kTRUE);
|
35 |
|
|
tws_.Expand(treeNames_.size());
|
36 |
|
|
|
37 |
|
|
// init tree writers
|
38 |
paus |
1.2 |
for (unsigned int i=0; i<treeNames_.size(); ++i) {
|
39 |
loizides |
1.1 |
|
40 |
|
|
TreeWriter *t = new TreeWriter(treeNames_.at(i).c_str(),1);
|
41 |
|
|
|
42 |
|
|
t->SetPrefix(fileNames_.at(i).c_str());
|
43 |
paus |
1.2 |
|
44 |
|
|
if (i<pathNames_.size())
|
45 |
|
|
t->SetBaseURL(pathNames_.at(i).c_str());
|
46 |
|
|
else if (pathNames_.size()>0)
|
47 |
|
|
t->SetBaseURL(pathNames_.at(0).c_str());
|
48 |
|
|
|
49 |
|
|
if (i<maxSizes_.size())
|
50 |
loizides |
1.4 |
t->SetMaxSize((Long64_t)maxSizes_.at(i)*1024*1024);
|
51 |
paus |
1.2 |
else if (maxSizes_.size()>0)
|
52 |
loizides |
1.4 |
t->SetMaxSize((Long64_t)maxSizes_.at(0)*1024*1024);
|
53 |
paus |
1.2 |
|
54 |
|
|
if (i<compLevels_.size())
|
55 |
|
|
t->SetCompressLevel(compLevels_.at(i));
|
56 |
|
|
else if (compLevels_.size()>0)
|
57 |
|
|
t->SetCompressLevel(compLevels_.at(0));
|
58 |
|
|
|
59 |
|
|
if (i<splitLevels_.size())
|
60 |
|
|
t->SetDefaultSL(splitLevels_.at(i));
|
61 |
|
|
else if (splitLevels_.size()>0)
|
62 |
|
|
t->SetDefaultSL(splitLevels_.at(0));
|
63 |
|
|
|
64 |
|
|
if (i<brSizes_.size())
|
65 |
|
|
t->SetDefaultBrSize(brSizes_.at(i));
|
66 |
|
|
else if (brSizes_.size()>0)
|
67 |
|
|
t->SetDefaultBrSize(brSizes_.at(0));
|
68 |
loizides |
1.1 |
|
69 |
|
|
//t->Print();
|
70 |
|
|
tws_.Add(t);
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
// set watchers
|
74 |
paus |
1.2 |
r.watchPreProcessEvent (this,&TreeService::preEventProcessing);
|
75 |
loizides |
1.1 |
r.watchPostProcessEvent(this,&TreeService::postEventProcessing);
|
76 |
paus |
1.2 |
r.watchPostBeginJob (this,&TreeService::postBeginJob);
|
77 |
|
|
r.watchPostEndJob (this,&TreeService::postEndJob);
|
78 |
loizides |
1.1 |
}
|
79 |
|
|
|
80 |
paus |
1.2 |
//--------------------------------------------------------------------------------------------------
|
81 |
loizides |
1.1 |
TreeService::~TreeService()
|
82 |
|
|
{
|
83 |
|
|
}
|
84 |
|
|
|
85 |
paus |
1.2 |
//--------------------------------------------------------------------------------------------------
|
86 |
loizides |
1.1 |
TreeWriter* TreeService::get(const char *name)
|
87 |
|
|
{
|
88 |
paus |
1.2 |
if (tws_.GetEntries()<=0)
|
89 |
|
|
return 0;
|
90 |
loizides |
1.1 |
|
91 |
paus |
1.2 |
if (name==0)
|
92 |
loizides |
1.1 |
return dynamic_cast<TreeWriter*>(tws_.At(0));
|
93 |
|
|
|
94 |
|
|
TObject *ret = tws_.FindObject(name);
|
95 |
paus |
1.2 |
|
96 |
loizides |
1.1 |
return dynamic_cast<TreeWriter*>(ret);
|
97 |
|
|
}
|
98 |
|
|
|
99 |
paus |
1.2 |
//--------------------------------------------------------------------------------------------------
|
100 |
loizides |
1.1 |
void TreeService::postBeginJob()
|
101 |
|
|
{
|
102 |
|
|
// nothing to be done for now
|
103 |
|
|
}
|
104 |
|
|
|
105 |
paus |
1.2 |
//--------------------------------------------------------------------------------------------------
|
106 |
loizides |
1.1 |
void TreeService::postEndJob()
|
107 |
|
|
{
|
108 |
|
|
tws_.Clear();
|
109 |
|
|
}
|
110 |
|
|
|
111 |
paus |
1.2 |
//--------------------------------------------------------------------------------------------------
|
112 |
loizides |
1.1 |
void TreeService::postEventProcessing(const Event&, const EventSetup&)
|
113 |
|
|
{
|
114 |
paus |
1.2 |
for (int i=0; i<tws_.GetEntries(); ++i) {
|
115 |
loizides |
1.1 |
TreeWriter *tw=dynamic_cast<TreeWriter*>(tws_.At(i));
|
116 |
paus |
1.2 |
if (tw)
|
117 |
loizides |
1.1 |
tw->EndEvent();
|
118 |
|
|
}
|
119 |
|
|
}
|
120 |
|
|
|
121 |
paus |
1.2 |
//--------------------------------------------------------------------------------------------------
|
122 |
loizides |
1.1 |
void TreeService::preEventProcessing(const EventID&, const Timestamp&)
|
123 |
|
|
{
|
124 |
paus |
1.2 |
for (int i=0; i<tws_.GetEntries(); ++i) {
|
125 |
loizides |
1.1 |
TreeWriter *tw=dynamic_cast<TreeWriter*>(tws_.At(i));
|
126 |
paus |
1.2 |
if (tw)
|
127 |
loizides |
1.1 |
tw->BeginEvent();
|
128 |
|
|
}
|
129 |
|
|
}
|