#define MAIN #include #include "nodestuff.h" #include "recoConsts.h" #include "preco.h" #include "pisaReco.h" #include "nodestuff.h" #include "timestampstuff.h" #include "precoSelect.h" #include "bbcfuncs.h" #include "cglfuncs.h" #include "crkfuncs.h" #include "dchfuncs.h" #include "dispfuncs.h" #include "emcfuncs.h" #include "ertfuncs.h" #include "headerfuncs.h" #include "lvl2funcs.h" #include "mvdfuncs.h" #include "momfuncs.h" #include "muifuncs.h" #include "ntcfuncs.h" #include "padfuncs.h" #include "tecfuncs.h" #include "toffuncs.h" #include "triggerfuncs.h" #include "tzrfuncs.h" #include "t0funcs.h" #include "vtxfuncs.h" #include "zdcfuncs.h" #include "spinfuncs.h" #include "EventTypes.h" #include "good_vtx.h" #include "PdbObjyApplication.hh" #include "RunToTimeObjy.hh" #include "PHRunConfig.h" #include "PHRunConfigV1.h" #include "PHFile.h" #include "PHFileV1.h" #include "PHRun.h" #include "PHRunV1.h" #include "PHRunV2.h" #include "PHProcess.h" #include "PHProcessV1.h" #include "PHCalibration.h" #include "VtxOut.h" static int init_done = 0; static int pdbobjy_done = 0; PHNodeIOManager *dstOut = 0; PHString *saveDstOutFile = NULL; typedef PHIODataNode VtxOutNode_t; void setProcessFlag(char * cvs, char * desc, char * inFile, char * outFile) { processFlag = 1; // set values to be enterned in Process Database cvsTag = cvs; description = desc; inputFile = inFile; outputFile = outFile; } void fillProcessObject() { // start application with processJob flag NOT set in order NOT to // update calibration object in run database // PHBoolean pJob = False; PdbObjyApplication *poa = PdbObjyApplication::instance(); if (poa->startUpdate()) { ooRef(ooDBObj) runDBH; ooRef(ooDBObj) processDBH; ooRef(ooDBObj) fileDBH; ooRef(PHRunConfig) runC; runC = PHRunConfig::findRunConfig(oovTopFD); runDBH = runC->getRunH(); processDBH = runC->getProcessH(); fileDBH = runC->getDataFileH(); if (runDBH.open(oocUpdate) != oocSuccess) { cout << "Error opening database " << runDBH.fileName() << endl; poa->abort(); return ; } if (runDBH.lock(oocLockUpdate) != oocSuccess) { cout << "Error locking database " << runDBH.fileName() << endl; poa->abort(); return ; } if (processDBH.open(oocUpdate) != oocSuccess) { cout << "Error opening database " << processDBH.fileName() << endl; poa->abort(); return ; } if (processDBH.lock(oocLockUpdate) != oocSuccess) { cout << "Error locking database " << processDBH.fileName() << endl; poa->abort(); return ; } if (fileDBH.open(oocUpdate) != oocSuccess) { cout << "Error opening database " << fileDBH.fileName() << endl; poa->abort(); return ; } if (fileDBH.lock(oocLockUpdate) != oocSuccess) { cout << "Error locking database " << fileDBH.fileName() << endl; poa->abort(); return ; } ooItr(PHRun) runIter; int foundRun = 0; runIter.scan(runDBH); ooRef(PHRun) runHandle; ooRef(PHFile) inputFileH; ooRef(PHFile) outputFileH; // // Search the complete database for a run with matching run-number. // while (runIter.next() && !foundRun) { runHandle = runIter; if (runHandle->getRunNumber() == runNumber) { foundRun = 1; } } if (foundRun) { ooVArray(ooRef(PHProcess)) processObjects; ooHandle(PHProcess) processObject; // Get process object (or create new one) processObjects = runHandle->getProcessObjects(description); int nObjects = processObjects.size(); if ( nObjects == 0) { processObject = runHandle->createAndAddProcessObject(runC); processObject->setProcessDate(); processObject->setCVSTag(cvsTag); processObject->setDescription(description); } else { processObject = processObjects[0]; } // processObject->print(); inputFileH = processObject->addInputFile(inputFile, runC); outputFileH = processObject->addOutputFile(outputFile, runC); } // Commit transaction poa->commit(); } } void setSimulationFlag(int simFlag = 1) { simulationFlag = simFlag; cout << "\n setSimulationFlag : simulationFlag = " << simulationFlag << endl; } void setEvaluationFlag() { if (!simulationFlag) { simulationFlag = 1; } evaluationFlag = 1; } void setppFlag(int temp = 1) { ppFlag = temp; cout << "\n setppFlag : ppFlag = " << ppFlag << endl; } void setTofCalibrator(int triggerSelect) { tofTriggerSelect = triggerSelect; } void setMvdCalib(int temp) { pass_mvd = temp; } int setup_all() { int i; if (runNumber > 0 && recoDataset == -1) { for (i = 0; i < ndataset; i++) { if (runNumber >= minrun[i] && runNumber <= maxrun[i]) { recoDataset = i; } } bFieldFlag = -1; // part of hack work for run number being too large if (runNumber > maxrun[ndataset - 1]) { cout << "\n setup_all : run number " << runNumber; cout << ", exceeds last maximum run number " << maxrun[ndataset - 1]; cout << "\n Resetting run number to " << maxrun[ndataset - 1] << endl; recoDataset = ndataset - 1; // set to the largest dataset number for this hack bFieldFlag = 1; // force magnetic field to be on in this hack geomFlag = 1; // force normal geometry in this hack recoDataset = ndataset - 1; runNumber = maxrun[ndataset - 1] ; } // hack work for run number being too large if (recoDataset == -1) { cerr << "ERROR(preco.C): No dataset corresponds to your input run number. Quitting." << endl; return -1; } cout << "DATASET = " << recoDataset << endl; if (bFieldFlag == -1) { // Set the magnetic field and geometry flags based on the dataset # bFieldFlag = bFieldArray[recoDataset]; geomFlag = geomFlagArray[recoDataset]; } // check to see that the run number too large condition did not occur cout << "\n setup_all : For this run bFieldFlag = " << bFieldFlag; cout << ", and geomFlag = " << geomFlag << endl; } if (runNumber <= 0 && recoDataset == -1) { if (simulationFlag == 0) { cerr << "\n setup_all : Found simulationFlag = 0"; cerr << ", with runNumber = " << runNumber << endl; return -1; } // consistency check of simulationFlag and presumed negative run number recoDataset = 0; // assign a value anyway switch (runNumber) { case 0: // field on, normal arms, obsolete zero run number on PRDF bFieldFlag = 1; geomFlag = 1; cout << "\n setup_all : Simulation files with 0 run number are obsolete." << endl; cout << " Program assumes that this is a field on, normal geometry simulation run." << endl; break; case - 1: // field on, normal arms bFieldFlag = 1; geomFlag = 1; cout << "\n setup_all : This is a field on, normal geometry simulation run." << endl; break; case - 2: // field off, normal arms bFieldFlag = 0; geomFlag = 1; cout << "\n setup_all : This is a field off, normal geometry simulation run." << endl; break; case - 3: // field on, retracted arms bFieldFlag = 1; geomFlag = 0; cout << "\n setup_all : This is a field on, retracted geometry simulation run." << endl; break; case - 4: // field off, retracted arms bFieldFlag = 0; geomFlag = 0; cout << "\n setup_all : This is a field off, retracted geometry simulation run." << endl; break; default: // error condition cerr << "\n unrecognized negative run number choice " << runNumber << endl; return -1; } // check on negative runNumber value } // found a negative or zero runNumber topNode = new PHCompositeNode("TOP"); parNode = new PHCompositeNode("PAR"); topNode->addNode(parNode); dcmNode = new PHCompositeNode("DCM"); topNode->addNode(dcmNode); dstNode = new PHCompositeNode("DST"); topNode->addNode(dstNode); runNode = new PHCompositeNode("RUN"); topNode->addNode(runNode); evaNode = new PHCompositeNode("EVA"); topNode->addNode(evaNode); if (simulationFlag == 2 || simulationFlag == 3) { prdfNode = new PHCompositeNode("PRDF"); topNode->addNode(prdfNode); } // check for simulation OUTPUT prdf condition (BBC wants prdfNode for PISA-to-DST) PHNodeIterator mainIter(topNode); PHCompositeNode* headerNode = new PHCompositeNode("HEADER"); topNode->addNode(headerNode); geaNode = new PHCompositeNode("GEA"); topNode->addNode(geaNode); rawDataCheck = new RawDataCheck(); Gl1Unp = new mGl1Unp; Gl1GetDCM = new mGl1GetDCM; GlpEvent = new mGlpEvent; size_t mr = 1; dGl1DCMWrapper* dGl1DCM = new dGl1DCMWrapper("dGl1DCM", mr); PHIODataNode* dGl1DCMNode = new PHIODataNode(dGl1DCM, "dGl1DCM"); dcmNode->addNode(dGl1DCMNode); mr = 1; dGl1AcptEvtDCMWrapper* dGl1AcptEvtDCM = new dGl1AcptEvtDCMWrapper("dGl1AcptEvtDCM", mr); PHIODataNode* dGl1AcptEvtDCMNode = new PHIODataNode(dGl1AcptEvtDCM, "dGl1AcptEvtDCM"); dstNode->addNode(dGl1AcptEvtDCMNode); mr = 1; dRunHeaderWrapper* dRunHeader = new dRunHeaderWrapper("dRunHeader", mr); PHIODataNode* dRunHeaderNode = new PHIODataNode(dRunHeader, "dRunHeader"); headerNode->addNode(dRunHeaderNode); mr = 1; dEventHeaderWrapper* dEventHeader = new dEventHeaderWrapper("dEventHeader", mr); PHIODataNode* dEventHeaderNode = new PHIODataNode(dEventHeader, "dEventHeader"); headerNode->addNode(dEventHeaderNode); // Get the time stamp to use in Objectivity calls runHeaderRoot = new PHRunHeaderRoot(); runHeaderRoot->set_run(runNumber); if (processFlag) { fillProcessObject(); } if (runNumber > 0) { if (year1Flag) { runHeaderRoot->lookup_timeStamp("runtotime.txt"); //comment out for Year2 TimeStamp = runHeaderRoot->get_timeStamp(); //comment out for Year2 } else { auto_ptr runTime(new RunToTimeObjy); auto_ptr ts(runTime->getBeginTime(runNumber)) ; if (ts.get() != 0) { PHTimeStamp startTime = *ts ; cout << "Found TimeStamp: "; startTime.print(); cout << endl; TimeStamp = startTime + 30; } else { cerr << "ERROR: Can NOT get Time Stamp !!!" << endl; return -1; } } } else { // // Simulation run // TimeStamp = PHTimeStamp(2000, 4, 5, 0, 0, 0); // taken from camrecini.C file } // check on positive run number // Go ahead and put the event on the node tree so that setup_modules can // access run information. // //thisEvent = 0; if (simulationFlag == 0 || simulationFlag == 1) { mainIter.addNode(new PHDataNode(thisEvent, "PRDF")); } // this is the input PRDF node; the output PRDF node for simulations is added in the setup_all module // If detector response chain, extract MutPISAPara object from PISA file and put on // par node for use in MuTr geometry initialization. Write par node out to par file // if parOut is not null: if (simulationFlag == 2 || simulationFlag == 3) { if (precoSelect::isMUTR()) { mumpara = MutPISAPara::GetMutParaEvt(); if (!mumpara) { cout << "\n Invalid mumpara value from MutPISAPara::GetMutParaEvt()"; cout << "\n PISA hits file does not contain Muon Arm information" << endl; exit(9); } else { PHIODataNode* mumparaNode = new PHIODataNode(mumpara, "mumpara"); parNode->addNode(mumparaNode); } if (parOut) { parOut->write(parNode); cout << "MutPISAPara written to parOutFile " << endl; delete parOut; } else { cout << "No geometry file mupar.root written for this run. " << endl; } } } if (precoSelect::isTRIG()) { cout << "SETUP TRIG" << endl; setup_trigger(); } if (precoSelect::isNTC()) { cout << "SETUP NTC" << endl; setup_ntc(); } if (precoSelect::isTZR()) { cout << "SETUP TZR" << endl; setup_tzr(); } if (precoSelect::isBBC()) { cout << "SETUP BBC" << endl; setup_bbc(precoSelect::getBBCCalibVersion()); } if (precoSelect::isMVD()) { cout << "SETUP MVD" << endl; setup_mvd(); } if (precoSelect::isZDC()) { cout << "SETUP ZDC" << endl; setup_zdc(); } if (precoSelect::isT0()) { cout << "SETUP T0" << endl; setup_t0(); } if (precoSelect::isPAD()) { cout << "SETUP PAD" << endl; setup_pad(); } if (precoSelect::isVTX()) { cout << "SETUP VTX" << endl; setup_vtx(); } if (precoSelect::isTEC()) { cout << "SETUP TEC" << endl; setup_tec(); } if (precoSelect::isTOF()) { cout << "SETUP TOF" << endl; setup_tof(); } if (precoSelect::isDCH()) { cout << "SETUP DCH" << endl; setup_dch(); } if (precoSelect::isCRK()) { cout << "SETUP CRK" << endl; setup_crk(); } if (precoSelect::isEMC()) { cout << "SETUP EMC" << endl; setup_emc(); } if (precoSelect::isCGL()) { cout << "SETUP CGL" << endl; setup_cgl(); } if (precoSelect::isMOM()) { cout << "SETUP MOM" << endl; setup_mom(); } if (precoSelect::isMUID()) { cout << "SETUP MUI" << endl; setup_mui(); } if (precoSelect::isLVL2()) { cout << "SETUP LVL2" << endl; setup_lvl2(); } if (precoSelect::isERT()) { cout << "SETUP ERT" << endl; setup_ert(); } if (precoSelect::isHEAD()) { cout << "SETUP HEAD" << endl; setup_header(); } if (precoSelect::isDISP()) { cout << endl << "SETUP PHENIX EVENT DISPLAY" << endl; setup_disp(); } if (ppFlag) { if (precoSelect::isSPIN()) { cout << "SETUP SPIN" << endl; setup_spin(); } } return (0); } int pinit() { cout << "Initializing" << endl; runNumber = 0; processFlag = 0; simulationFlag = 0; evaluationFlag = 0; year1Flag = 0; ppFlag = 0; tofTriggerSelect = 0; pass_mvd = 2; eventHeaderRoot = new PHEventHeaderRoot(); return 0; } int process_event (Event *evt) { static int satisfySetup; // cout << "process_event" << endl; if (!init_done) { runNumber = evt->getRunNumber(); cout << "Run Number = " << runNumber << endl; cout << "SIMULATION FLAG = " << simulationFlag << endl; if (runNumber <= 0 && simulationFlag == 0) { cerr << "\n process_event : "; cerr << " trying to process simulated PRDF as a real PRDF\n"; satisfySetup = -1; return 0; } cout << "EVALUATION FLAG = " << evaluationFlag << endl; cout << "PROCESS FLAG = " << processFlag << endl; if (runNumber > -1 && runNumber < 20000) year1Flag = 1; cout << "YEAR1 FLAG = " << year1Flag << endl; thisEvent = evt; satisfySetup = setup_all(); init_done = 1; } if (satisfySetup == -1) { return 0; } PHNodeIterator mainIter(topNode); PHNodeReset reset; if ( (evt->getEvtType() == BEGRUNEVENT) || (evt->getEvtType() == ENDRUNEVENT) || (evt->getEvtType() == SCALEREVENT) ) { if (ppFlag) { if (precoSelect::isSPIN()) { cout << "SPIN Scal" << endl; anaScal_spin(evt); } } } if ( (evt->getEvtType() != DATAEVENT) && (evt->getEvtType() != REJECTEDEVENT) ) { cout << " no data event" << endl; return 0; } // Identify the event evt->identify(); if (evt->getErrorCode()) { cout << "Event is corrupted, skip it" << endl; return 0; } ((PHDataNode*)(mainIter.findFirst("PHDataNode", "PRDF")))->setData(evt); thisEvent = evt; static int checkFlag = 1; Int_t iRDCheck; if (!rawDataCheck->eventCheck(thisEvent)) { printf("EVENT ERROR DETECTED\n"); for (iRDCheck = 0; iRDCheck < 32; iRDCheck++) { if (!rawDataCheck->GranOK(iRDCheck)) { printf("GRANULE %d ERROR\n", iRDCheck); } } if (!rawDataCheck->EventAlignOK()) { printf("GLOBAL EVENT ALIGNMENT ERROR - MUST STOP!\n"); checkFlag = 0; // stop processing data! } } if (checkFlag) { // Initialize header information eventHeaderRoot->InitHeader(); eventHeaderRoot->fetchBefore(topNode, thisEvent); eventHeaderRoot->set_run(runNumber); eventHeaderRoot->set_timeStamp(TimeStamp); Gl1GetDCM->event(topNode); Gl1Unp->event(topNode); GlpEvent->event(topNode); if (precoSelect::isTRIG()) { cout << "TRIG" << endl; ana_trigger(); } if (precoSelect::isERT()) { cout << "ERT" << endl; ana_ert(); } if (precoSelect::isLVL2()) { cout << "LVL2" << endl; ana_lvl2(); } // done, if rejected event, since there should be no packets // of any other kind in the PRDF for those events. if (evt->getEvtType() == REJECTEDEVENT) { cout << "rejected event, only ran TRIG and LVL2" << endl; return 0; } cout << "\n simulationFlag = " << simulationFlag; cout << ", simVertexFlag = " << simVertexFlag << endl; if (simulationFlag == 1 && simVertexFlag != 0) { simSetBbcOut(); // set the BBC Z0 to simVertex value, BBC T0 to 0.0 } else { if (precoSelect::isBBC()) { cout << "BBC" << endl; ana_bbc(); } if (precoSelect::isZDC()) { cout << "ZDC" << endl; ana_zdc(); } } // check on using simulated PRDF and forced Z0 into BBC if (precoSelect::isHEAD()) { cout << "HEAD" << endl; ana_header(); } if (!good_vtx(thisEvent)) { cout << "\n The good_vtx condition for this event was FALSE"; cout << "\n Skipping the processing of all subsystems except ZDC, BBC, and LVL2" << endl; if (pass_mvd < 2) { // process mvd if calibration mode if (precoSelect::isMVD()) { cout << "Processing MVD for calibration" << endl; ana_mvd(); } } } // issue warning message when good_vtx says false if ( good_vtx(thisEvent) || simulationFlag || ppFlag) // // NOTE: the simulationFlag will be either 0 (real PRDF) or 1 (simulated PRDF) // { //analyze only good vertex event and physics trigger if (precoSelect::isMVD()) { cout << "MVD" << endl; ana_mvd(); } if (precoSelect::isNTC()) { cout << "NTC" << endl; ana_ntc(); } if (precoSelect::isTZR()) { cout << "TZR" << endl; ana_tzr(); } if (precoSelect::isT0()) { cout << "T0" << endl; ana_t0(); } if (precoSelect::isPAD()) { cout << "PAD" << endl; ana_pad(); } if (precoSelect::isVTX()) { cout << "VTX" << endl; ana_vtx(); } if (precoSelect::isTEC()) { cout << "TEC" << endl; ana_tec(); } if (precoSelect::isTOF()) { cout << "TOF" << endl; ana_tof(); } if (precoSelect::isDCH()) { cout << "DCH" << endl; ana_dch(); // for run2_v01 with DCH ascii files } if (precoSelect::isCRK()) { cout << "CRK" << endl; ana_crk(); } if (precoSelect::isEMC()) { cout << "EMC" << endl; ana_emc(); } // delete of pdbcal to clean out if (!pdbobjy_done) { #ifdef DEBUG cout << "PdbObjyApplication *poa = PdbObjyApplication::instance();"; cout << "delete poa;" << endl; #endif PdbObjyApplication *poa = PdbObjyApplication::instance(); delete poa; pdbobjy_done = 1; } if (precoSelect::isCGL()) { cout << "CGL" << endl; ana_cgl(); } if (precoSelect::isMOM()) { cout << "MOM" << endl; ana_mom(); } if (precoSelect::isTEC()) { ana_tec_pid(); } if (precoSelect::isTOF() && precoSelect::isCGL()) { ana_tof_pid(); } if (precoSelect::isMUID()) { cout << "MUON" << endl; ana_mui(); // MUONS reserve the right to use another vertex sometimes // so the VtxOut object has to be resetted and refilled if (precoSelect::isVTX()) { cout << "VTX (refill after MUON analysis)" << endl; VtxOut* vtxout = NULL; PHTypedNodeIterator vtxiter(topNode); VtxOutNode_t *VtxOutNode = vtxiter.find("VtxOut"); if (VtxOutNode) { vtxout = VtxOutNode->getData(); if (vtxout) { vtxout->Reset(); // Otherwise the forced vtx // will stay on the dst } } ana_vtx(); // refill VtxOut object } } if (precoSelect::isDISP()) { cout << endl << "DISP" << endl; ana_disp(); } if (precoSelect::isDCH()) { cout << endl << "" << endl; filter_dch(); } if (ppFlag) { if (precoSelect::isSPIN()) { cout << "SPIN Data" << endl; anaData_spin(evt); } } } //only good vertex and physics trig event is processed if (dstOut) { dstOut->write(dstNode); } // mainIter.print(); if (mainIter.cd("DST")) { mainIter.forEach(reset); mainIter.cd(); } if (mainIter.cd("DCM")) { mainIter.forEach(reset); mainIter.cd(); } if (mainIter.cd("GEA")) { mainIter.forEach(reset); mainIter.cd(); } if (mainIter.cd("EVA")) { mainIter.forEach(reset); mainIter.cd(); } if (mainIter.cd("BBC")) { mainIter.forEach(reset); mainIter.cd(); } if (mainIter.cd("MVD")) { mainIter.forEach(reset); mainIter.cd(); } if (mainIter.cd("PAD")) { mainIter.forEach(reset); mainIter.cd(); } if (mainIter.cd("CRK")) { mainIter.forEach(reset); mainIter.cd(); } if (mainIter.cd("TEC")) { mainIter.forEach(reset); mainIter.cd(); } if (mainIter.cd("EMC")) { mainIter.forEach(reset); mainIter.cd(); } if (mainIter.cd("TOF")) { mainIter.forEach(reset); mainIter.cd(); } if (mainIter.cd("CGL")) { mainIter.forEach(reset); mainIter.cd(); } if (mainIter.cd("DCH")) { mainIter.forEach(reset); mainIter.cd(); } if (mainIter.cd("MOM")) { mainIter.forEach(reset); mainIter.cd(); } } return 0; } void pexit() { delete dstOut; dstOut = new PHNodeIOManager(*saveDstOutFile, PHUpdate, PHRunTree); dstOut->write(runNode); delete dstOut; cout << "Completed reconstruction and exiting" << endl; } int poutfileopen(PHString dstOutFile) { saveDstOutFile = new PHString(dstOutFile); dstOut = new PHNodeIOManager(dstOutFile, PHWrite); dstOut->SetCompressionLevel(3); return 0; } void pend() { cout << "In pend()" << endl; if (precoSelect::isTOF()) { end_tof(); } if (precoSelect::isMUID() && precoSelect::isMUTR()) { end_mui(); } if (precoSelect::isMVD()) { end_mvd(); } if (precoSelect::isDCH()) { end_dch(); } if (ppFlag) { if (precoSelect::isSPIN()) { end_spin(); } } }