1 #include "CSMBuildRunMap.h"
35 CSMBuildRunMap::buildRunMap(
const Char_t *directory,
const Char_t* filter) {
37 cout <<
"CSMBuilRunMap::buildRunMap" << endl;
39 std::map<Int_t,std::set<std::string> > runFileMap;
40 if (!directory || !filter)
return 0;
42 if ((dir = gSystem->OpenDirectory(directory)) != NULL) {
43 const Char_t *dirEntry;
44 while ((dirEntry = gSystem->GetDirEntry(dir)) != NULL) {
46 strcpy(buffer,directory);
47 if (buffer[strlen(buffer)-1] !=
'/') strcat(buffer,
"/");
48 strcat(buffer,dirEntry);
49 if (!strstr(buffer,filter))
continue;
50 TFile *file =
new TFile(buffer,
"READ");
52 cout <<
"Read File buffer Initiatiated" << endl;
53 TList *keys = file->GetListOfKeys();
55 TIterator* iter = keys->MakeIterator();
57 while ((key = static_cast<TKey*>(iter->Next())) != NULL) {
58 if (strstr(key->GetName(),
"bemcStatusAdc") != NULL) {
61 file->DecodeNameCycle(key->GetName(),name,keyCycle);
62 Char_t *runNumberString = name+14;
63 cout << runNumberString << endl;
65 Int_t runNumber = atoi(runNumberString);
66 runFileMap[runNumber].insert(
string(buffer));
76 cout <<
"found histograms for " << runFileMap.size() <<
" runs" << endl;
77 cout <<
"dumping run->file map" << endl;
78 for (std::map<Int_t,std::set<std::string> >::const_iterator iter = runFileMap.begin();
79 iter != runFileMap.end(); ++iter) {
80 cout <<
"run number " << iter->first << endl;
81 for (set<string>::const_iterator files = iter->second.begin();
82 files != iter->second.end(); ++files) {
83 cout << *files << endl;
87 Int_t runDate, runTime, minirunDate, minirunTime;
88 Float_t runFillNumber, minirunFillNumber;
89 for (std::map<Int_t,set<string> >::const_iterator iter = runFileMap.begin();
90 iter != runFileMap.end(); ++iter) {
91 cout <<
"Creating status histogram for run " << iter->first << endl;
94 strcpy(buffer,directory);
95 sprintf(tempola,
"/run%d.cal.total.hist.root",iter->first);
96 strcat(buffer,tempola);
97 TFile* outFile =
new TFile(buffer,
"RECREATE");
98 if (outFile) cout <<
"outFile buffer initiated" << endl;
99 TTree* runTree =
new TTree(
"calinfo",
"Extraneous Information");
100 runTree->Branch(
"fillnum",&runFillNumber,
"fillnum/F");
101 runTree->Branch(
"thedate",&runDate,
"thedate/I");
102 runTree->Branch(
"thetime",&runTime,
"thetime/I");
106 sprintf(buffer,
"bemcStatusAdc_%d",iter->first);
107 string BEMChistName(buffer);
108 sprintf(buffer,
"bemcStatusEnergy_%d",iter->first);
109 string BEMCenergyHistName(buffer);
110 sprintf(buffer,
"eemcStatusAdc_%d",iter->first);
111 string EEMChistName(buffer);
112 sprintf(buffer,
"eemcStatusEnergy_%d",iter->first);
113 string EEMCenergyHistName(buffer);
117 TH2F* myBEMCRunHist = NULL;
119 for (set<string>::const_iterator filenames = iter->second.begin();
120 filenames != iter->second.end(); ++filenames) {
121 TFile *file =
new TFile(filenames->c_str(),
"READ");
122 if (file->IsOpen()) {
123 TTree* minirunTree =
dynamic_cast<TTree*
>(file->Get(
"calinfo"));
125 minirunTree->SetBranchAddress(
"thedate",&minirunDate);
126 minirunTree->SetBranchAddress(
"thetime",&minirunTime);
127 minirunTree->SetBranchAddress(
"fillnum",&minirunFillNumber);
128 minirunTree->GetEvent(0);
132 if(runDate > minirunDate) {
133 runDate = minirunDate;
134 runTime = minirunTime;
135 }
else if(runDate == minirunDate && runTime > minirunTime) {
136 runTime = minirunTime;
138 runFillNumber = minirunFillNumber;
139 TH2F* BEMChist =
dynamic_cast<TH2F*
>(file->Get(BEMChistName.c_str()));
141 if (BEMChist->Integral(3,BEMChist->GetXaxis()->GetNbins(),1,2) >1e5) cout <<
"File " << filenames->c_str() <<
" has a ton of 0's" << endl;
142 if (!myBEMCRunHist) {
144 myBEMCRunHist =
new TH2F(BEMChistName.c_str(),BEMChistName.c_str(),
145 BEMChist->GetXaxis()->GetNbins(),
146 BEMChist->GetXaxis()->GetXmin(),
147 BEMChist->GetXaxis()->GetXmax(),
148 BEMChist->GetYaxis()->GetNbins(),
149 BEMChist->GetYaxis()->GetXmin(),
150 BEMChist->GetYaxis()->GetXmax());
152 myBEMCRunHist->Add(BEMChist);
154 cerr <<
"Didn't find histogram " << BEMChistName <<
" ???" << endl;
155 cerr <<
"in file " << filenames->c_str() <<
" ???" << endl;
196 cout <<
"Writing myBEMCRunHist" << endl;
197 myBEMCRunHist->Write();
200 cout <<
"Writing outFile" << endl;