00001 #include <cassert>
00002
00003 #include "TROOT.h"
00004 #include "TRint.h"
00005 #include "TString.h"
00006 #include "TSystem.h"
00007 #include "TStyle.h"
00008
00009 #include "sigc++/sigc++.h"
00010 #include "sigc++/class_slot.h"
00011 #include "sigc++/slot.h"
00012
00013 #include "Calibrator/Calibrator.h"
00014 #include "MessageService/MsgService.h"
00015 #include "JobControl/JobC.h"
00016 #include "JobControl/JobCModule.h"
00017 #include "JobControl/JobCModuleRegistry.h"
00018 #include "Algorithm/AlgFactory.h"
00019 #include "Algorithm/AlgConfig.h"
00020
00021 #include "Midad/Base/Mint.h"
00022 #include "Midad/Base/PageDisplay.h"
00023
00024 #include "TriD/TridControl.h"
00025 #include "TriD/TridPageDisplay.h"
00026 #include "TriD/TridSetup.h"
00027 #include "TriD/stat/ReadDispatcherModule.h"
00028
00029 #include "Plex/PlexLoanPool.h"
00030 #include "DatabaseInterface/DbiTableProxyRegistry.h"
00031
00032 extern void InitGui();
00033 VoidFuncPtr_t initfuncs[] = { InitGui, 0 };
00034 CVSID("$Id: trid.cxx,v 1.16 2007/03/01 16:59:43 rhatcher Exp $");
00035
00036 TROOT root("trid", "TriD Static Viewer Program",initfuncs);
00037
00038
00039 int SetupInput();
00040 int SetupAuto();
00041 int SetupAnimation();
00042 void setup_paths(void) ;
00043 int main(int argc, char **argv);
00044
00045 void DoNext(void);
00046 void DoPrev(void);
00047
00048 typedef enum EInputMode {
00049 kFromFile = 0,
00050 kFromDispatcher = 1
00051 } InputMode_t;
00052
00053
00054
00055 InputMode_t gInputMode = kFromFile;
00056 JobC* jc;
00057 SigC::Ptr<TridControl> tc;
00058
00059 string hostname = "localhost";
00060 int port = 9090;
00061 float timeout = 1;
00062 bool autoNext = false;
00063 float autoNextDelay = 30.0;
00064 vector<string> filenames;
00065 bool animate = false;
00066 float animateSpeed = 0.1;
00067 int nhitThresh = 30;
00068 int nhitMax = 2000;
00069 string plexfile = "~/cache/plex_cache.dat";
00070
00071 int SetupInput()
00072 {
00073 assert(jc);
00074
00075 if(gInputMode==kFromDispatcher) {
00076 cout << "Setting up dispatcher client connected to "
00077 << hostname << " :" << port << endl;
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 jc->Input.Use("DummyInput");
00096
00097
00098 jc->Path.Add("default","ReadDispatcherModule::Get ");
00099 JobCModule& mod = jc->Path("default").Mod("ReadDispatcherModule");
00100 mod.Set(Form("DDSServer=%s",hostname.c_str()));
00101 mod.Set(Form("DDSPort=%d",port));
00102 mod.Set("Streams=DaqSnarl");
00103 mod.Set("DDSKeepUpMode=RecordKeepUp");
00104 mod.Set("DDSDataSource=Daq");
00105 mod.Set(Form("DDSTimeOut=%d",(int)timeout));
00106 mod.Set("DDSMaxSyncDelay=1");
00107 mod.Set(Form("SelectRule=(((RawDaqSnarlHeader*)fHeader)->GetNumRawDigits()>%d)"
00108 "&&(((RawDaqSnarlHeader*)fHeader)->GetNumRawDigits()<%d)",
00109 nhitThresh,nhitMax));
00110
00111
00112 } else {
00113 jc->Input.Set("Streams=DaqSnarl,Cand");
00114
00115 MSG("TriD",Msg::kDebug) << "Adding files..\n";
00116 for(UInt_t i=0;i<filenames.size();i++) {
00117 jc->Input.AddFile(filenames[i].c_str());
00118 MSG("TriD",Msg::kDebug) << " Adding file " << filenames[i] << endl;
00119 }
00120
00121 }
00122
00123 return 1;
00124 }
00125
00126
00127 class AutoEventTimer : public TTimer
00128 {
00129 Bool_t Notify() {
00130 cout << "Auto-advancing..." << endl;
00131 gMint->Next();
00132 Start((Long_t)(autoNextDelay*1000.),true);
00133 return true;
00134 };
00135 };
00136
00137 int SetupAuto(void)
00138 {
00139 AutoEventTimer* timer = new AutoEventTimer();
00140 timer->Start((Long_t)(autoNextDelay*1000.),true);
00141 timer->TurnOn();
00142 return 0;
00143 }
00144
00145
00146 int SetupAnimation(void)
00147 {
00148 assert(tc);
00149 tc->GetAnimator().SetAnimateViews(true);
00150 tc->GetAnimator().SetAnimateModels(false);
00151 tc->GetAnimator().SetViewAnimSpeed( animateSpeed );
00152 tc->GetAnimator().StartAnimation();
00153 return 0;
00154 }
00155
00156
00157 void DoNext(void)
00158 {
00159
00160 cout << "DoNext()" << endl;
00161
00162
00163 if(gInputMode==kFromDispatcher) {
00164
00165 ReadDispatcherModule* rdm = dynamic_cast<ReadDispatcherModule*>
00166 (&(jc->Path("default").Mod("ReadDispatcherModule")));
00167
00168 assert(rdm);
00169
00170 if(rdm->IsNewEventReady()) gMint->Next();
00171 else {
00172 MSG("TriD",Msg::kInfo) << "No event ready from dispatcher." << endl;
00173 }
00174 } else
00175
00176 {
00177
00178 gMint->Next();
00179 }
00180 }
00181
00182 void DoPrev(void)
00183 {
00184 cout << "DoPrev()" << endl;
00185 if(gInputMode==kFromDispatcher) {
00186 } else {
00187 gMint->Prev();
00188 }
00189 }
00190
00191 void setup_paths(void)
00192 {
00193
00194 MSG("TriD",Msg::kDebug) << "Setting up macro paths.\n"; cout.flush();
00195
00196 TString mp = gROOT->GetMacroPath();
00197 TString ip;
00198 const char* p = gSystem->Getenv("SRT_PRIVATE_CONTEXT");
00199 if (p) {
00200 mp += ":";
00201 mp += p;
00202 mp += ":";
00203 mp += p;
00204 mp += "/macros";
00205 ip += " -I";
00206 ip += p;
00207 }
00208
00209 const char* p2 = gSystem->Getenv("SRT_PUBLIC_CONTEXT");
00210 if (p2) {
00211 mp += ":";
00212 mp += p2;
00213 mp += ":";
00214 mp += p2;
00215 mp += "/macros";
00216 ip += " -I";
00217 ip += p2;
00218 }
00219
00220 gROOT->SetMacroPath(mp.Data());
00221 gSystem->SetIncludePath(ip);
00222
00223 MSG("TriD",Msg::kDebug) << "Setting up include paths.\n"; cout.flush();
00224
00225 if(p) {
00226 TString dip = ".include ";
00227 dip += p;
00228 gROOT->ProcessLine(dip.Data());
00229 }
00230
00231 if(p2) {
00232 TString dip = ".include ";
00233 dip += p2;
00234 gROOT->ProcessLine(dip.Data());
00235 }
00236 }
00237
00238
00239
00240 int main(int argc, char **argv)
00241 {
00242
00243
00244
00245 MsgService::Instance()->GetStream("TriD")->SetLogLevel(Msg::kInfo);
00246
00248
00249
00250 int iarg = 0;
00251 while(++iarg<argc) {
00252
00253 if(argv[iarg][0] == '-') {
00254
00255 if((strcmp(argv[iarg],"-d")==0) || (strncmp(argv[iarg],"--disp",6)==0) ) {
00256 gInputMode = kFromDispatcher;
00257
00258 if( (iarg+1<argc) && (argv[iarg+1][0]!='-')) hostname = argv[++iarg];
00259 if( (iarg+1<argc) && (argv[iarg+1][0]!='-')) {
00260 int tmp = 0;
00261 if(sscanf(argv[++iarg],"%d",&tmp)>0) port = tmp;
00262 }
00263 if( (iarg+1<argc) && (argv[iarg+1][0]!='-')) {
00264 float tmp = 0;
00265 if(sscanf(argv[++iarg],"%f",&tmp)>0) timeout = tmp;
00266 }
00267 cout << "Config: Using dispatcher: " << hostname << ":" << port
00268 << " timeout: " << timeout << endl;
00269 continue;
00270 }
00271
00272
00273 if( (strcmp(argv[iarg],"-a")==0) || (strncmp(argv[iarg],"--auto",6)==0)) {
00274 autoNext = true;
00275 if( (iarg+1<argc) && (argv[iarg+1][0]!='-')) {
00276 float tmp;
00277 if(sscanf(argv[++iarg],"%f",&tmp)>0) autoNextDelay = tmp;
00278 }
00279 cout << "Config: Using Auto Timer: " << autoNextDelay << " s" << endl;
00280 continue;
00281 }
00282
00283 if( (strcmp(argv[iarg],"-n")==0) || (strncmp(argv[iarg],"--nhits",6)==0)) {
00284
00285 if( (iarg+1<argc) && (argv[iarg+1][0]!='-'))
00286 sscanf(argv[++iarg],"%d",&nhitThresh);
00287
00288 if( (iarg+1<argc) && (argv[iarg+1][0]!='-'))
00289 sscanf(argv[++iarg],"%d",&nhitMax);
00290 cout << "Using NHIT threshold of : " << nhitThresh
00291 << " maximum NHIT " << nhitMax << endl;
00292 continue;
00293 }
00294
00295 if( (strcmp(argv[iarg],"-r")==0) || (strncmp(argv[iarg],"--rot",5)==0)) {
00296 animate = true;
00297 if( (iarg+1<argc) && (argv[iarg+1][0]!='-')) {
00298 float tmp;
00299 if(sscanf(argv[++iarg],"%f",&tmp)>0) animateSpeed = tmp;
00300 }
00301 cout << "Config: Turning on animation " << animateSpeed << " s" << endl;
00302 continue;
00303 }
00304
00305 if( (strcmp(argv[iarg],"-D")==0) || (strncmp(argv[iarg],"--debug",7)==0)) {
00306 cout << "Config: Turning on debugging output." << endl;
00307 MsgService::Instance()->GetStream("TriD")->SetLogLevel(Msg::kDebug);
00308 continue;
00309 }
00310
00311 if( (strcmp(argv[iarg],"-h")==0) || (strncmp(argv[iarg],"--help",6)==0)) {
00312 cout << "--- TriD Help ----- " << endl;
00313 cout << "Options: " << endl;
00314 cout << " -d <host> <port> Open dispatcher for input from host:port" << endl;
00315 cout << " -n <nhits> NHit threshold for dispatcher." << endl;
00316 cout << " -a <time> Auto-next-event every <time> seconds" << endl;
00317 cout << " -r <speed> Rotate view at <speed> rotations/second" << endl;
00318 cout << " -D --debug Turn on debugging output." << endl;
00319
00320 }
00321
00322 }
00323
00324 filenames.push_back(argv[iarg]);
00325 }
00326
00327
00328
00329 int dummy =1;
00330
00331 TApplication* theApp = new TApplication("PMT App",&dummy,argv);
00332
00333 setup_paths();
00334
00335
00336 MSG("TriD",Msg::kDebug) << "Creating job path.\n";
00337
00338 jc = new JobC;
00339
00340 MSG("TriD",Msg::kDebug) << "Loading plex cache from filename: " << plexfile << "\n";
00341 PlexLoanPool::ReadFromFile(plexfile.c_str());
00342
00343 MSG("TriD",Msg::kDebug) << "Setting up DBI cache:\n";
00344 CfgConfigurable& dbiCfg = DbiTableProxyRegistry::Instance();
00345 dbiCfg.Set("Level2Cache = '~/cache/'");
00346 dbiCfg.Update();
00347
00348
00349 MSG("TriD",Msg::kDebug) << "Setting up job path\n";
00350
00351
00352
00353
00354
00355
00356
00357
00358 jc->Path.Create("default","");
00359
00360 SetupInput();
00361 jc->Path.Add("default","FilterEvent::Ana ");
00362
00363 jc->Path.Create("getdigits",
00364 "TestDigitsModule::Ana "
00365 "DigitListModule::Get "
00366 "DigitListModule::Reco "
00367 "DumpMomModule::Ana "
00368 );
00369 jc->Path("getdigits").Node("TestDigitsModule::Ana ").ReverseFilter();
00370
00371
00372 jc->Path.Create("demux",
00373 "TestDemuxModule::Ana "
00374 "DeMuxDigitListModule::Reco "
00375
00376 "DumpMomModule::Ana "
00377 );
00378 jc->Path("demux").Node("TestDemuxModule::Ana ").ReverseFilter();
00379
00380 jc->Msg.SetLevel("AltDeMuxModule","Error");
00381 jc->Msg.SetLevel("AlgAltDeMux","Error");
00382 jc->Msg.SetLevel("AlgAltDeMuxDevel","Error");
00383
00384
00385
00386 Calibrator::Instance().Set("TimeCalibrator=SimpleCalScheme "
00387 "PeCalibrator=SimpleCalScheme "
00388 "DriftCalibrator=SimpleCalScheme "
00389 "LinCalibrator=SimpleCalScheme "
00390 "StripCalibrator=SimpleCalScheme "
00391 "AttenCalibrator=SimpleCalScheme "
00392 "MIPCalibrator=SimpleCalScheme "
00393 "Thermometer=SimpleCalScheme " );
00394
00395
00396 jc->Path.Attach("default","getdigits");
00397 jc->Path.Attach("getdigits","demux");
00398
00399
00400
00401 gStyle->SetPalette(1,0);
00402
00403 TridSetup(*jc);
00404
00405
00406
00407
00408 dynamic_cast<TridPageDisplay*>(gPageDisplay)->fNextSignal.clear();
00409 dynamic_cast<TridPageDisplay*>(gPageDisplay)->fPrevSignal.clear();
00410 dynamic_cast<TridPageDisplay*>(gPageDisplay)->fNextSignal.connect(SigC::slot(&DoNext));
00411 dynamic_cast<TridPageDisplay*>(gPageDisplay)->fPrevSignal.connect(SigC::slot(&DoPrev));
00412
00413
00414 tc = TridControl::Instance(gPageDisplay);
00415
00416 MSG("TriD",Msg::kDebug) << "Running job.\n";
00417
00418
00419 jc->Path("default").Report();
00420
00421
00422 if(autoNext) {
00423 MSG("TriD",Msg::kDebug) << "Starting Auto-timer\n";
00424 SetupAuto();
00425 }
00426
00427 if(animate) {
00428 MSG("TriD",Msg::kDebug) << "Starting Animation\n";
00429 SetupAnimation();
00430 }
00431 gMint->Next();
00432
00433
00434 gPageDisplay->AutoZoom();
00435
00436
00437 theApp->Run();
00438
00439 return 0;
00440
00441 }