ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeService/src/TreeService.cc
Revision: 1.3
Committed: Wed Jun 11 13:10:27 2008 UTC (16 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.2: +16 -15 lines
Log Message:
Throw if input is not consistent, cleanup.

File Contents

# Content
1 // $Id: TreeService.cc,v 1.2 2008/06/03 07:21:45 paus Exp $
2
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 //--------------------------------------------------------------------------------------------------
16 TreeService::TreeService(const ParameterSet &cfg, ActivityRegistry &r) :
17 tws_(0),
18 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 }
32
33 // setup tw array
34 tws_.SetOwner(kTRUE);
35 tws_.Expand(treeNames_.size());
36
37 // init tree writers
38 for (unsigned int i=0; i<treeNames_.size(); ++i) {
39
40 TreeWriter *t = new TreeWriter(treeNames_.at(i).c_str(),1);
41
42 t->SetPrefix(fileNames_.at(i).c_str());
43
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 t->SetMaxSize(maxSizes_.at(i)*1024*1024);
51 else if (maxSizes_.size()>0)
52 t->SetMaxSize(maxSizes_.at(0)*1024*1024);
53
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
69 //t->Print();
70 tws_.Add(t);
71 }
72
73 // set watchers
74 r.watchPreProcessEvent (this,&TreeService::preEventProcessing);
75 r.watchPostProcessEvent(this,&TreeService::postEventProcessing);
76 r.watchPostBeginJob (this,&TreeService::postBeginJob);
77 r.watchPostEndJob (this,&TreeService::postEndJob);
78 }
79
80 //--------------------------------------------------------------------------------------------------
81 TreeService::~TreeService()
82 {
83 }
84
85 //--------------------------------------------------------------------------------------------------
86 TreeWriter* TreeService::get(const char *name)
87 {
88 if (tws_.GetEntries()<=0)
89 return 0;
90
91 if (name==0)
92 return dynamic_cast<TreeWriter*>(tws_.At(0));
93
94 TObject *ret = tws_.FindObject(name);
95
96 return dynamic_cast<TreeWriter*>(ret);
97 }
98
99 //--------------------------------------------------------------------------------------------------
100 void TreeService::postBeginJob()
101 {
102 // nothing to be done for now
103 }
104
105 //--------------------------------------------------------------------------------------------------
106 void TreeService::postEndJob()
107 {
108 tws_.Clear();
109 }
110
111 //--------------------------------------------------------------------------------------------------
112 void TreeService::postEventProcessing(const Event&, const EventSetup&)
113 {
114 for (int i=0; i<tws_.GetEntries(); ++i) {
115 TreeWriter *tw=dynamic_cast<TreeWriter*>(tws_.At(i));
116 if (tw)
117 tw->EndEvent();
118 }
119 }
120
121 //--------------------------------------------------------------------------------------------------
122 void TreeService::preEventProcessing(const EventID&, const Timestamp&)
123 {
124 for (int i=0; i<tws_.GetEntries(); ++i) {
125 TreeWriter *tw=dynamic_cast<TreeWriter*>(tws_.At(i));
126 if (tw)
127 tw->BeginEvent();
128 }
129 }