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

LIRawNt.cxx

Go to the documentation of this file.
00001 #include <cstdio>
00002 #include <fstream>
00003 #include "LIRawNt.h"
00004 // ROOT includes
00005 #include "TFile.h"
00006 // MINOS includes
00007 #include "MessageService/MsgService.h"     // MSG text output
00008 #include "MinosObjectMap/MomNavigator.h"   // Data access
00009 #include "RawData/RawDigit.h"
00010 #include "JobControl/JobCommand.h"         // JobCommand handling
00011 #include "JobControl/JobCModuleRegistry.h" // JOBMODULE registration macro
00012 #include "RawData/RawChannelId.h"
00013 #include "RawData/RawDaqSnarlHeader.h"
00014 #include "RawData/RawRecord.h"
00015 #include "RawData/RawDaqHeaderBlock.h"
00016 #include "RawData/RawSnarlHeaderBlock.h"
00017 #include "RawData/RawDigitDataBlock.h"
00018 #include "RawData/RawDigit.h"
00019 
00020 
00021 CVSID("$Id: LIRawNt.cxx,v 1.3 2008/11/04 11:45:35 dja25 Exp $");
00022 JOBMODULE(LIRawNt,"LIRawNt","Create Ntuple for list of raw LI hits\n");
00023 
00024 //......................................................................
00025 
00026 //......................................................................
00027 
00028 LIRawNt::LIRawNt() 
00029   : fPlex(0)
00030 {
00031   outFile=0;
00032   string sBase = "liraw";
00033   string sFileName=sBase+".root";
00034   ifstream test(sFileName.c_str());
00035   if(!test){
00036   outFile = new TFile(sFileName.c_str(),"RECREATE");
00037   }
00038   else{
00039     Int_t count=1;
00040     while(test){
00041       test.close();
00042       string sAppen=Form("%d",count);
00043       sFileName=sBase+"_"+sAppen+".root";
00044       test.open(sFileName.c_str());
00045       ++count;
00046     }
00047     outFile=new TFile(sFileName.c_str(),"NEW");
00048   }
00049 
00050   fLIRawNt = new TTree("liraw", "liraw");
00051   fLIRawNt -> Branch("run", &nt_run, "run/I");
00052   fLIRawNt -> Branch("snarl", &nt_snarl, "snarl/I");
00053   fLIRawNt -> Branch("timesec", &nt_timesec, "timesec/I");
00054   fLIRawNt -> Branch("timenanosec", &nt_timenanosec, "timenanosec/I");
00055   fLIRawNt -> Branch("errcode", &nt_errcode, "errcode/I");
00056   fLIRawNt -> Branch("crate", &nt_crate, "crate/I1");
00057   fLIRawNt -> Branch("varc", &nt_varc, "varc/I1");
00058   fLIRawNt -> Branch("vmm", &nt_vmm, "vmm/I1");
00059   fLIRawNt -> Branch("vaadc", &nt_vaadc, "vaadc/I1");
00060   fLIRawNt -> Branch("vachip", &nt_vachip, "vachip/I1");
00061   fLIRawNt -> Branch("vachannel", &nt_vachannel, "vachannel/I1");
00062   fLIRawNt -> Branch("pixel", &nt_pixel, "pixel/I1");
00063   fLIRawNt -> Branch("adc", &nt_adc, "adc/I2");
00064   fLIRawNt -> Branch("tdc", &nt_tdc, "tdc/I");
00065   fLIRawNt -> Branch("readouttype", &nt_readouttype, "readouttype/I");
00066   fLIRawNt -> Branch("pbox", &nt_pbox, "pbox/S");
00067   fLIRawNt -> Branch("pboxopp", &nt_pboxopp, "pboxopp/S");
00068   fLIRawNt -> Branch("led", nt_led, "led[8]/S");
00069   fLIRawNt -> Branch("ledopp", nt_ledopp, "led[8]/S");
00070 
00071 }
00073 JobCResult LIRawNt::Ana(const MomNavigator *mom) {
00074 
00075   const RawRecord *rawrec = 
00076     dynamic_cast<const RawRecord *>(mom -> GetFragment("RawRecord"));
00077   if (!rawrec) { 
00078     MSG("LIRawNt", Msg::kWarning) << "No RawRecord in MOM." << endl; 
00079     return JobCResult::kFailed;
00080   }
00082  static Int_t count =0;
00084   const VldContext *vldC = rawrec -> GetVldContext();
00085   if (!(vldC -> IsValid())) {
00086     MSG("LIRawNt", Msg::kWarning) << "Invalid context for RawRecord." << endl;
00087     return JobCResult::kFailed;
00088   }
00089  // if(count<10000){
00090         ++count;
00091   const Detector::Detector_t detector = vldC -> GetDetector();
00092   if (fPlex && !(fPlex -> GetVldRange().IsCompatible(vldC))) {
00093     delete fPlex;
00094   }
00095   if (!fPlex) {
00096     fPlex = new PlexHandle(*vldC);
00097     MSG("LIRawNt", Msg::kVerbose)
00098       << "New plex handle; validity"
00099       << " from " << fPlex -> GetVldRange().GetTimeStart().AsString()
00100       << " to " << fPlex -> GetVldRange().GetTimeEnd().AsString()
00101       << endl; 
00102   }
00103 
00104   const RawDaqSnarlHeader *snarlHdr = 
00105      dynamic_cast<const RawDaqSnarlHeader*>(rawrec -> GetRawHeader());
00106   if (!snarlHdr) {
00107     return JobCResult::kFailed;
00108   }
00109 
00110   nt_run   = snarlHdr -> GetRun();
00111   nt_snarl = snarlHdr -> GetSnarl();
00112 
00113   const RawSnarlHeaderBlock *rawsnarlHdrBlock = 
00114      dynamic_cast<const RawSnarlHeaderBlock *>
00115      (rawrec -> FindRawBlock("RawSnarlHeaderBlock"));
00116 
00117   nt_timesec     = -1;
00118   nt_timenanosec = -1;
00119   if (rawsnarlHdrBlock) {
00120     nt_timesec     = rawsnarlHdrBlock -> GetTriggerTime().GetSec();
00121     nt_timenanosec = rawsnarlHdrBlock -> GetTriggerTime().GetNanoSec();
00122   }
00123 
00124   // Remove this?
00125   const RawRecord *rr = 
00126     dynamic_cast<RawRecord *>(mom -> GetFragment("RawRecord"));
00127   if (!rr) {
00128     MSG("LIRawNt", Msg::kWarning) << "No RawRecord in MOM." << endl;
00129     return JobCResult::kFailed;
00130   }
00131 
00132   // Can this be pulled out from the plex?
00133   const Int_t vach2pixel[18] = 
00134     {0, 0, 15, 1, 16, 2, 11, 5, 12, 6, 7, 9, 8, 10, 3, 14, 4, 13};
00135 
00136   TIter rdbit = rr -> GetRawBlockIter();
00137   TObject *tob;
00138   while ((tob = rdbit())) {
00139     //          ++count;//
00140 //      cout<<count<<endl;
00141         if(count>10)break;//
00142     if (tob -> InheritsFrom("RawDigitDataBlock")) {
00143       const RawDigitDataBlock *rdb = 
00144         dynamic_cast<const RawDigitDataBlock *>(tob);
00145       TIter rdit = rdb -> GetDatumIter();
00146       const RawDigit *rd = dynamic_cast<const RawDigit *>(rdit());
00147       while (rd) {
00148         nt_pbox = -1;
00149         nt_pboxopp = -1;
00150         for (Int_t i = 0; i < nStripPerPixel; ++i) {
00151           nt_led[i] = -1; nt_ledopp[i] = -1;
00152         }
00153         const RawChannelId rawid = rd -> GetChannel();
00154         if (rawid.GetElecType() == ElecType::kVA/*&&count%10==0*/) {
00155           nt_crate       = rawid.GetCrate();
00156           nt_varc        = rawid.GetVarcId();
00157           nt_vmm         = rawid.GetVmm();
00158           nt_vaadc       = rawid.GetVaAdcSel();
00159           nt_vachip      = rawid.GetVaChip();
00160           nt_vachannel   = rawid.GetVaChannel();
00161           nt_pixel       = -1;
00162           if ((nt_vachannel >= 2) && (nt_vachannel <= 17)) {
00163             nt_pixel     = vach2pixel[nt_vachannel];
00164           }
00165           nt_errcode     = rd -> GetErrorCode();
00166           nt_adc         = rd -> GetADC();
00167           nt_tdc         = rd -> GetTDC();
00168           nt_readouttype = static_cast<Int_t>(fPlex -> GetReadoutType(rawid));
00169           if (nt_readouttype == ReadoutType::kScintStrip) {
00170             PlexSEIdAltL stripEndList = fPlex -> GetSEIdAltL(rawid);
00171             Int_t plane = stripEndList.GetPlane();
00172             if (plane > 485) {} // Ignore shield "planes"
00173             else if (detector == Detector::kCalDet &&
00174                      plane > 59) {} // Ignore CalDet muon counter
00175             else {
00176               Int_t i = 0;
00177               for (PlexSEIdAltL::iterator it = stripEndList.begin(); 
00178                    it != stripEndList.end();
00179                    it++) {
00180                 PlexStripEndId stripEndId    = (*it).GetSEId();
00181                 PlexStripEndId stripEndIdOpp = stripEndId.GetOppositeSEId();
00182                 PlexLedId ledId    = fPlex -> GetLedId(stripEndId);
00183                 PlexLedId ledIdOpp = fPlex -> GetLedId(stripEndIdOpp);
00184                 if (it == stripEndList.begin()) {
00185                   nt_pbox = ledId.GetPulserBox();
00186                   nt_pboxopp = ledIdOpp.GetPulserBox();
00187                 }
00188                 if (i < nStripPerPixel) {
00189                   nt_led[i] = ledId.GetLedInBox();
00190                   nt_ledopp[i] = ledIdOpp.GetLedInBox();
00191                 }
00192                 i++;
00193               }
00194             }
00195           }
00196           else {}
00197          //       if(count<100000){
00198           //        ++count;
00199             fLIRawNt -> Fill();
00200           //  }
00201           //      else{return false;}
00202         }
00203         rd = dynamic_cast<const RawDigit *>(rdit());
00204 //      }//
00205       }
00206     }
00207   }
00208 
00209   return JobCResult::kPassed;
00210 }
00211 
00212 
00213 //......................................................................
00214 
00215 void LIRawNt::HandleCommand(JobCommand* cmd)
00216 {
00217 //======================================================================
00218 // Handle a command send from the job controller
00219 // 
00220 // Inputs: cmd - The parsed job command
00221 //======================================================================
00222   if (cmd->HaveCmd()) {                      // If we have a command...
00223     string sc = cmd->PopCmd();               // Get the command
00224     MSG("LIRawNt",Msg::kWarning) << "Don't understand '" << sc.c_str() << "'\n";
00225   }
00226 }
00227 
00228 
00229 void LIRawNt::EndJob() 
00230 {
00231 //======================================================================
00232 // At the end of the job print some stuff out and save the histogram
00233 // to a file
00234 //======================================================================
00235   // fFile->Write();
00236   outFile->Close();
00237 }

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