Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

TrackCamListModule.cxx

Go to the documentation of this file.
00001 
00002 // Package: CandTrackCam
00003 //
00004 // marshall@hep.phy.cam.ac.uk
00006 #include <cassert>
00007 
00008 // For measuring CPU time
00009 extern "C" {
00010 #include <unistd.h>    // sysconf
00011 #include <sys/times.h> // times()
00012 }
00013 
00014 // Job Control includes
00015 #include "MessageService/MsgService.h"
00016 #include "MinosObjectMap/MomNavigator.h"
00017 #include "JobControl/JobCModuleRegistry.h" // For JOBMODULE macro
00018 
00019 // Algorithm includes
00020 #include "Algorithm/AlgFactory.h"
00021 #include "Algorithm/AlgHandle.h"
00022 #include "Algorithm/AlgConfig.h"
00023 
00024 // Candidate includes
00025 #include "CandData/CandRecord.h"
00026 #include "Candidate/CandContext.h"
00027 
00028 #include "RecoBase/CandSliceHandle.h"
00029 #include "RecoBase/CandSliceListHandle.h"
00030 #include "RecoBase/CandTrack.h"
00031 #include "RecoBase/CandTrackHandle.h"
00032 #include "RecoBase/CandTrackListHandle.h"
00033 
00034 #include "RawData/RawRecord.h"
00035 #include "RawData/RawDaqSnarlHeader.h"
00036 
00037 // This package includes
00038 #include "CandTrackCam/TrackCamListModule.h"
00039 #include "CandTrackCam/CandTrackCamListHandle.h"
00040 #include "CandTrackCam/CandTrackCamList.h"
00041 
00042 JOBMODULE(TrackCamListModule, "TrackCamListModule", "Track finder");
00043 CVSID("$Id: TrackCamListModule.cxx,v 1.7 2010/01/06 18:55:29 rhatcher Exp $");
00044 
00046 TrackCamListModule::TrackCamListModule()
00047 {
00048   fAlgName="AlgTrackCamList";
00049   fAlgConfig="default";
00050 
00051   fListIn="CandSliceList";
00052 }
00054 
00055 
00057 TrackCamListModule::~TrackCamListModule()
00058 {
00059 }
00061 
00062 
00064 void TrackCamListModule::BeginJob()
00065 {
00066   MSG("TrackCamListModule", Msg::kDebug) << " Track Finder startup complete " << endl;
00067 }
00069 
00070 
00072 void TrackCamListModule::EndJob()
00073 {
00074 }
00076 
00077 
00079 JobCResult TrackCamListModule::Reco(MomNavigator* mom)
00080 {
00081   JobCResult result(JobCResult::kPassed);
00082   
00083   const char* alg_name = 0;
00084   const char* alg_config_name = 0;
00085   
00086   // Get CandRecord
00087   CandRecord *candrec = dynamic_cast<CandRecord *> (mom->GetFragment("CandRecord", "PrimaryCandidateRecord"));
00088   if(!candrec)
00089     {
00090       MSG("TrackCamListModule", Msg::kWarning) << " Failed to Find CandRecord " << endl;
00091       return result.SetFailed();
00092     }
00093 
00094   // Get RawRecord, in particular from the DaqSnarl stream
00095   RawRecord *rr = dynamic_cast<RawRecord *>(mom->GetFragment("RawRecord",0,"DaqSnarl"));
00096   if(rr==0){
00097     MSG("TrackCamListModule", Msg::kWarning) << " Failed to Find RawRecord " << endl;
00098     return result.SetFailed();
00099   }
00100   
00101   // Get RawHeader
00102   else {
00103     const RawDaqSnarlHeader* hdr = dynamic_cast<const RawDaqSnarlHeader*>(rr->GetRawHeader());
00104     if(hdr){
00105       MSG("TrackCamListModule", Msg::kDebug) << "TrackCamListModule:Reco Run:Snarl "<<hdr->GetRun()<<":"<< hdr->GetSnarl()<<endl; 
00106     }
00107   }
00108 
00109 
00110   // Get CandSliceListHandle
00111   CandSliceListHandle* slice_list = dynamic_cast<CandSliceListHandle*>(candrec->FindCandHandle("CandSliceListHandle",fListIn.Data()));
00112   if( !slice_list || (slice_list && slice_list->GetNDaughters()<1) )
00113     {
00114       // Require number of CandSlices to be non-zero.
00115       if(!slice_list) {
00116         MSG("TrackCamListModule", Msg::kWarning) << " Failed to Find " << fListIn.Data() << endl;}
00117       else if(slice_list && slice_list->GetNDaughters()<1) {
00118         MSG("TrackCamListModule", Msg::kDebug) << " No slices found. Empty " << fListIn.Data() << endl;}
00119 
00120       //return JobCResult::kPassed;
00121       return JobCResult::kAOK;     // Otherwise no further processing of record
00122     }
00123 
00124 
00125   AlgFactory &af = AlgFactory::GetInstance();
00126   alg_name=fAlgName.Data(); alg_config_name=fAlgConfig.Data();
00127   AlgHandle adlh = af.GetAlgHandle(alg_name,alg_config_name);
00128   
00129   CandContext cx(this, mom);
00130   cx.SetCandRecord(candrec);
00131   cx.SetDataIn(slice_list);
00132 
00133   clock_t dummyt;
00134   struct tms t1;
00135   struct tms t2;
00136   static double ticksPerSecond = sysconf(_SC_CLK_TCK);
00137   
00138   dummyt = times(&t1);
00139   CandTrackCamListHandle ctlh = CandTrackCamList::MakeCandidate(adlh, cx);
00140   dummyt = times(&t2);
00141   ctlh.SetCPUTime((Double_t)(t2.tms_utime+t2.tms_stime-t1.tms_utime-t1.tms_stime)/ticksPerSecond);
00142 
00143   MSG("TrackCamListModule", Msg::kVerbose) << "CandTrackCam CPUTime " << ctlh.GetCPUTime() << endl;
00144 
00145   ctlh.SetName(fListOut.Data());
00146   ctlh.SetTitle(TString("Created by TrackCamListModule"));
00147   candrec->SecureCandHandle(ctlh);
00148    
00149   return JobCResult::kPassed; // kNoDecision, kFailed, etc.
00150 }
00152 
00153 
00155 const char* TrackCamListModule::GetName() const
00156 {
00157   const char* tmps = "TrackCamListModule";
00158   return tmps;
00159 }
00161 
00162 
00164 const Registry& TrackCamListModule::DefaultConfig() const
00165 {
00166 //======================================================================
00167 // Supply the default configuration for the module
00168 //======================================================================
00169   static Registry r; // Default configuration for module
00170 
00171   // Set name of config
00172   std::string name = this->GetName();
00173   name += ".config.default";
00174   r.SetName(name.c_str());
00175 
00176   // Set values in configuration
00177   r.UnLockValues();
00178   r.Set("NameListIn","CandSliceList");
00179   r.Set("NameListOut","CandTrackCamList");
00180   r.Set("TrackCamAlgorithm","AlgTrackCamList");
00181   r.Set("TrackListAlgConfig","default");
00182   r.LockValues();
00183 
00184   return r;
00185 }
00187 
00188 
00190 void TrackCamListModule::Config(const Registry& r)
00191 {
00192 //======================================================================
00193 // Configure the module given the Registry r
00194 //======================================================================
00195   const char* tmps;
00196   if (r.Get("NameListIn",tmps)) { fListIn = tmps; }
00197   if (r.Get("NameListOut",tmps)) { fListOut = tmps; }
00198   if (r.Get("TrackCamAlgorithm",tmps)) { fAlgName = tmps; }
00199   if (r.Get("TrackListAlgConfig",tmps)) { fAlgConfig = tmps; }
00200 }

Generated on Mon Feb 15 11:07:42 2010 for loon by  doxygen 1.3.9.1