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

DemoCandNtpModule.cxx

Go to the documentation of this file.
00001 
00002 //
00003 // DemoCandNtpModule.cc
00004 //
00005 // A JobControl Module for demonstrating ntuple construction.
00006 //
00008 #include <map>
00009 #include <iostream>
00010 #include <cassert>
00011 using std::endl;
00012 
00013 #include "TClonesArray.h"
00014 
00015 #include "CandData/CandRecord.h"
00016 #include "CandData/CandHeader.h"
00017 #include "MessageService/MsgService.h"
00018 #include "JobControl/JobCModuleRegistry.h"
00019 #include "JobControl/JobCommand.h"
00020 #include "MinosObjectMap/MomNavigator.h"
00021 #include "RawData/RawRecord.h"
00022 #include "RawData/RawHeader.h"
00023 #include "RawData/RawDaqSnarlHeader.h"
00024 #include "RecoBase/CandSliceHandle.h"
00025 #include "RecoBase/CandStripHandle.h"
00026 #include "RecoBase/CandTrackHandle.h"
00027 #include "CandTrackSR/CandTrackSRHandle.h"
00028 #include "RecoBase/CandShowerHandle.h"
00029 #include "RecoBase/CandEventHandle.h"
00030 #include "RecoBase/CandSliceListHandle.h"
00031 #include "RecoBase/CandStripListHandle.h"
00032 #include "RecoBase/CandTrackListHandle.h"
00033 #include "CandTrackSR/CandTrackSRListHandle.h"
00034 #include "RecoBase/CandShowerListHandle.h"
00035 #include "RecoBase/CandEventListHandle.h"
00036 #include "NtupleBase/test/DemoCandNtpModule.h"
00037 #include "NtupleBase/test/CandRecordSRNtuple.h"
00038 #include "NtupleBase/test/CandTrackSRNtuple.h"
00039 #include "NtupleBase/NtpCandEvent.h"
00040 #include "NtupleBase/NtpCandTrack.h"
00041 #include "NtupleBase/NtpCandShower.h"
00042 #include "NtupleBase/NtpCandSlice.h"
00043 #include "NtupleBase/NtpCandStrip.h"
00044 #include "Record/RecCandHeader.h"
00045 
00046 ClassImp(DemoCandNtpModule)
00047 
00048 //   Definition of static data members
00049 //   *********************************
00050 
00051 CVSID("$Id: DemoCandNtpModule.cxx,v 1.4 2005/05/18 06:18:13 west Exp $");
00052 JOBMODULE(DemoCandNtpModule, "DemoCandNtpModule",
00053          "A module for demonstrating ntuple construction.");
00054 
00055 
00056 // Definition of methods (alphabetical order)
00057 // ***************************************************
00058 
00059 JobCResult DemoCandNtpModule::Reco(MomNavigator *mom) {
00060   //
00061   //  Purpose:  Create ntuple record if not present on input
00062   //            stream.
00063   //
00064   //  Arguments: none.
00065   //  
00066   //  Return: none.
00067   //
00068   //  Contact:   S. Kasahara
00069   // 
00070 
00071 
00072   JobCResult result(JobCResult::kPassed);  
00073   MSG("DemoNtuple",Msg::kVerbose) << "DemoCandNtpModule::Get" << endl;
00074 
00075   // Check that mom exists.
00076   assert(mom);
00077     
00078   // Check for existing NtpCand fragment in MOM.
00079   CandRecordSRNtuple *candNtp = dynamic_cast<CandRecordSRNtuple*>
00080      (mom->GetFragment("CandRecordSRNtuple","PrimaryCandidateRecord"));
00081 
00082   if ( candNtp ) return result;
00083 
00084   // Otherwise, create a new one 
00085   CandRecord *candRec = dynamic_cast<CandRecord*>
00086     (mom->GetFragment("CandRecord","PrimaryCandidateRecord"));
00087   if ( !candRec ) {
00088     MSG("DemoNtuple",Msg::kWarning) << "No PrimaryCandidateRecord in MOM"<<endl;
00089     result.SetWarning().SetFailed();
00090     return result;
00091   }
00092 
00093   // Need to convert from old CandHeader format to new.
00094   // This ugliness will go away if the CandRecord adopts the new header class.
00095   // Need rawrecord to properly construct new header
00096   RawRecord *rawRec = dynamic_cast<RawRecord*>
00097     (mom->GetFragment("RawRecord")); // should iterate but this is just a demo
00098   if ( !rawRec ) {
00099     MSG("DemoNtuple",Msg::kWarning) << "No RawRecord in MOM"<<endl;
00100     result.SetWarning().SetFailed();
00101     return result;
00102   }
00103   const CandHeader* cndHdr = candRec -> GetCandHeader();
00104   const RawDaqSnarlHeader* rawHdr = dynamic_cast<const RawDaqSnarlHeader*>
00105                               (rawRec -> GetHeader());
00106   rawHdr->GetVldContext().Print();
00107   RecCandHeader* newHdr = new RecCandHeader(rawHdr->GetVldContext(),
00108         cndHdr->GetRun(),rawHdr->GetSubRun(),rawHdr->GetRunType(),
00109         rawHdr->GetErrorCode(),cndHdr->GetSnarl(),rawHdr->GetTrigSrc(),
00110         rawHdr->GetTimeFrameNum(),rawHdr->GetRemoteSpillType(),cndHdr->GetEvent());
00111 
00112   // Create new record
00113   CandRecordSRNtuple* ntpRec = new CandRecordSRNtuple(*newHdr);
00114 
00115   ntpRec->SetName("PrimaryCandidateRecord"); //associate with parent CandRecord
00116   // And pass it to Mom, mom now has memory management responsibility
00117   mom->AdoptFragment(ntpRec);
00118   
00119   // An option will be provided to not write out strip data as in 
00120   // EventSRListModule
00121   std::map<Int_t,Int_t> stripmap; // uid, stripindex
00122   CandStripListHandle* strips = dynamic_cast<CandStripListHandle*>
00123     (candRec -> FindCandHandle("CandStripListHandle"));
00124   if ( !strips ) return result;  // but warn first
00125   TIter stItr(strips->GetDaughterIterator());
00126   Int_t nstrip=0;
00127   while ( CandStripHandle *strip = dynamic_cast<CandStripHandle*>(stItr()) ) {
00128     // For each new strip, an ntuple object is created and added to the TClones
00129     Int_t uid = strip->GetUidInt();
00130     stripmap.insert(std::make_pair(uid,nstrip));
00131     new((ntpRec->GetStrips())[nstrip++]) NtpCandStrip(*strip);
00132   }
00133 
00134   // Slices
00135   CandSliceListHandle* slices = dynamic_cast<CandSliceListHandle*>
00136     (candRec -> FindCandHandle("CandSliceListHandle"));
00137   if ( slices ) {
00138     TIter slitr(slices->GetDaughterIterator());
00139     Int_t nslice=0;
00140     while (CandSliceHandle *slice = dynamic_cast<CandSliceHandle*>(slitr())) {
00141       // For each new slice, an ntp object is created and added to the TClones
00142       NtpCandSlice* slicentp = 
00143           new((ntpRec->GetSlices())[nslice++]) NtpCandSlice(*slice);
00144       TIter stripitr(slice->GetDaughterIterator());
00145       Int_t nslicestrip=0;
00146       while (CandStripHandle* strip
00147                             = dynamic_cast<CandStripHandle*>(stripitr())) {
00148         Int_t uid = strip->GetUidInt();
00149         Int_t stripindex = stripmap[uid];
00150         slicentp->AddStripAt(stripindex,nslicestrip); // add index to strip
00151         nslicestrip++;
00152       } 
00153     }
00154   }
00155 
00156   CandTrackListHandle* tracks = dynamic_cast<CandTrackListHandle*>
00157     (candRec -> FindCandHandle("CandTrackListHandle"));
00158   Int_t ntrack=0;
00159   std::map<Int_t,Int_t> trackmap; // uid,index
00160   if ( tracks ) {
00161     TIter tritr(tracks->GetDaughterIterator());
00162     while (CandTrackSRHandle *track=dynamic_cast<CandTrackSRHandle*>(tritr()))
00163     {
00164       trackmap.insert(std::make_pair(track->GetUidInt(),ntrack));
00165       // For each new track, an ntp object is created and added to the TClones
00166       CandTrackSRNtuple* trackntp = 
00167            new((ntpRec->GetTracks())[ntrack++]) CandTrackSRNtuple(*track);
00168       TIter stripitr(track->GetDaughterIterator());
00169       Int_t ntrackstrip = 0;
00170       while (CandStripHandle* strip
00171              =dynamic_cast<CandStripHandle*>(stripitr())) {
00172         Int_t stripindex = stripmap[strip->GetUidInt()];
00173         trackntp->AddStripAt(stripindex,ntrackstrip); // add reference to strip
00174         ntrackstrip++;
00175       } 
00176     }
00177   }
00178 
00179   CandShowerListHandle* showers = dynamic_cast<CandShowerListHandle*>
00180     (candRec -> FindCandHandle("CandShowerListHandle"));
00181   Int_t nshower=0;
00182   std::map<Int_t,Int_t> showermap;
00183   if ( showers ) {
00184     TIter shitr(showers->GetDaughterIterator());
00185     while (CandShowerHandle *shower 
00186            = dynamic_cast<CandShowerHandle*>(shitr())) {
00187       showermap.insert(std::make_pair(shower->GetUidInt(),nshower));
00188       // For each new shower,an ntp object is created and added to the TClones
00189       NtpCandShower* showerntp = 
00190            new((ntpRec->GetShowers())[nshower++]) NtpCandShower(*shower);
00191       Int_t nshowerstrip=0;
00192       TIter stripitr(shower->GetDaughterIterator());
00193       while(CandStripHandle* strip=dynamic_cast<CandStripHandle*>(stripitr())){
00194         Int_t stripindex = stripmap[strip->GetUidInt()];
00195         showerntp->AddStripAt(stripindex,nshowerstrip); // add ref to strip
00196         nshowerstrip++;
00197       } 
00198     }
00199   }
00200 
00201   CandEventListHandle* events = dynamic_cast<CandEventListHandle*>
00202     (candRec -> FindCandHandle("CandEventListHandle"));
00203   if ( events ) {
00204     TIter evitr(events->GetDaughterIterator());
00205     Int_t nevent=0;
00206     while (CandEventHandle *event = dynamic_cast<CandEventHandle*>(evitr())) {
00207       // For each new strip, an ntp object is created and added to the TClones
00208       NtpCandEvent* eventntp = 
00209            new((ntpRec->GetEvents())[nevent++]) NtpCandEvent(*event);
00210       // An iterator over the tracks&showers is not provided, why?
00211       for ( Int_t i = 0; i <= event->GetLastTrack(); i++ ) {
00212         CandTrackHandle* track 
00213                        = const_cast<CandTrackHandle*>(event->GetTrack(i));
00214         Int_t trackindex = trackmap[track->GetUidInt()];
00215         eventntp->AddTrackAt(trackindex,i);
00216       }
00217       for ( Int_t i = 0; i <= event->GetLastShower(); i++ ) {
00218         CandShowerHandle* shower 
00219                       = const_cast<CandShowerHandle*>(event->GetShower(i));
00220         Int_t showerindex = showermap[shower->GetUidInt()];
00221         eventntp->AddShowerAt(showerindex,i);
00222       }
00223     }
00224   }
00225 
00226   return result;
00227 
00228 }
00229 
00230 void DemoCandNtpModule::BeginJob() {
00231   //
00232   //  Purpose:  Configure module at beginning of job.
00233   //
00234   //  Arguments: none.
00235   //  
00236   //  Return: none.
00237   //
00238   //  Contact:   S. Kasahara
00239   // 
00240 
00241   MSG("DemoNtuple", Msg::kVerbose) << "DemoCandNtpModule::BeginJob" << endl;
00242 
00243   // Configure module
00244  
00245 }
00246 
00247 void DemoCandNtpModule::Config(const Registry& r) {
00248   //
00249   //  Purpose:  Configure the module based on the contents of the registry.
00250   //
00251   //  Arguments: none.
00252   //  
00253   //  Return: none.
00254   //
00255   //  Contact:   S. Kasahara
00256   // 
00257 
00258   MSG("DemoNtuple",Msg::kDebug) << "Config DemoCandNtpModule with r=" << r << endl;
00259 
00260 }
00261 
00262 const Registry& DemoCandNtpModule::DefaultConfig() const {
00263   //
00264   //  Purpose:  Load default values into configuration registry.
00265   //
00266   //  Arguments: none.
00267   //  
00268   //  Return: registry of default configuration values.
00269   //
00270   //  Contact:   S. Kasahara
00271   // 
00272 
00273   static Registry r;
00274   r.SetName("DemoNtuple.config");
00275 
00276   r.UnLockValues();
00277 
00278   MSG("DemoNtuple",Msg::kDebug) << "Loading default config.\n" << endl;
00279 
00280   // r.Set("variable","argument");
00281 
00282   r.LockValues();
00283   return r;
00284 
00285 }
00286 
00287 DemoCandNtpModule::DemoCandNtpModule() { 
00288   //
00289   //  Purpose:  Default constructor.
00290   //
00291   //  Arguments: none.
00292   //
00293   //  Return:    n/a.
00294   //
00295   //  Contact:   S. Kasahara
00296   // 
00297   //  Notes: none.
00298   // 
00299 
00300   MSG("DemoNtuple", Msg::kVerbose) << "DemoCandNtpModule::Constructor" << endl;
00301 
00302 }
00303 
00304 DemoCandNtpModule::~DemoCandNtpModule() {
00305   //
00306   //  Purpose:  Destructor.  
00307   //
00308   //  Contact:   S. Kasahara
00309   // 
00310 
00311   MSG("DemoNtuple", Msg::kVerbose) << "DemoCandNtpModule::Destructor" << endl;
00312 
00313 }
00314 
00315 
00316 
00317 
00318 

Generated on Mon Feb 15 11:06:36 2010 for loon by  doxygen 1.3.9.1