00001 #include "SavePulses.h"
00002 #include "RegisterModule.inc"
00003 #include "TGlobalData.h"
00004 #include "TSetupData.h"
00005 #include "ModulesOptions.h"
00006 #include "ModulesNavigator.h"
00007 #include "ModulesParser.h"
00008 #include "definitions.h"
00009 #include "IdSource.h"
00010 #include "TAnalysedPulse.h"
00011 #include "TAPGeneratorFactory.h"
00012
00013 #include "TTree.h"
00014 #include "TClonesArray.h"
00015
00016 #include <iostream>
00017 using std::cout;
00018 using std::endl;
00019
00020 extern SourceAnalPulseMap gAnalysedPulseMap;
00021
00022 SavePulses::SavePulses(modules::options* opts):
00023 BaseModule("SavePulses",opts,false){
00024 fTree=new TTree("TAP_tree","Tree storing all TAPs made in rootana");
00025 }
00026
00027 SavePulses::~SavePulses(){
00028 }
00029
00030 int SavePulses::BeforeFirstEntry(TGlobalData* gData,const TSetupData *setup){
00031
00032
00033 if(!modules::navigator::Instance()->Before("MakeAnalysedPulses",GetName())){
00034 cout<<"SavePulses: Error: I need to be run after MakeAnalysedPulses"<<endl;
00035 return 1;
00036 }
00037
00038
00039 TClonesArray* array;
00040 std::string name;
00041 for (SourceAnalPulseMap::const_iterator i_source = gAnalysedPulseMap.begin();
00042 i_source != gAnalysedPulseMap.end(); ++i_source) {
00043 std::string tap_type=TAPGeneratorFactory::Instance()->GetTAPType(i_source->first);
00044 array=new TClonesArray(tap_type.c_str());
00045 fArrays[i_source->first]=array;
00046 name=i_source->first.str();
00047 modules::parser::ToCppValid(name);
00048 fTree->Branch(name.c_str(), array);
00049 }
00050
00051 return 0;
00052 }
00053
00054 int SavePulses::ProcessEntry(TGlobalData* gData,const TSetupData *setup){
00055 const AnalysedPulseList* pulseList;
00056 TClonesArray* array;
00057 TObject* tap;
00058 for (SourceAnalPulseMap::const_iterator i_source = gAnalysedPulseMap.begin();
00059 i_source != gAnalysedPulseMap.end(); ++i_source) {
00060 pulseList=&i_source->second;
00061 array=fArrays[i_source->first];
00062 for (AnalysedPulseList::const_iterator i_pulse = pulseList->begin();
00063 i_pulse != pulseList->end(); ++i_pulse) {
00064 tap= array->ConstructedAt(i_pulse-pulseList->begin());
00065 (*i_pulse)->Copy(*tap);
00066 }
00067 }
00068 fTree->Fill();
00069 for(SourceToClonesArrayMap::iterator i_array=fArrays.begin();
00070 i_array!=fArrays.end(); ++i_array){
00071 i_array->second->Clear("C");
00072 }
00073 return 0;
00074 }
00075
00076 int SavePulses::AfterLastEntry(TGlobalData* gData,const TSetupData *setup){
00077 FlyWeight<IDs::source,TAnalysedPulse::Tag>::SaveProxyList(GetDirectory(),"TAP_sources");
00078 return 0;
00079 }
00080
00081 ALCAP_REGISTER_MODULE(SavePulses);