//--------------------------------------- #include #include "ITripTPedSingleton.hxx" #include "ITripTParam.hxx" #include "IDPTPedStore.hxx" // For the stat() call below #include #include #include #include /// Singleton for pedestal storage. This grabs pedestal data from the data /// stream or optionally (via ReadFile()) from a pedestal file. This allows /// the oma-xxxx.cxx main program to preload only the pedestals relevant for /// the histograms which will be made. /// The static member pointer to the singleton. COMET::ITripTPedSingleton* COMET::ITripTPedSingleton::fTTripTPedSingleton = NULL; COMET::ITripTPedSingleton::ITripTPedSingleton(){ for (int det=0;det0, tries to locate pedestal files /// (in path) and read them in. If readfiles is =2, if the file is present /// it is loaded and then locked (so that banks will not replace it). If readfiles /// is =2 and the file is not found, the banks will get loaded anyway. int det = aP->GetDetCode(); int maxrmm = aP->GetMaxRmm(); if (det<0 || det >=kMaxDetectorIndex || maxrmm<0 || maxrmm>kMaxRmm) { printf("COMET::ITripTPedSingleton:: Error, bad parameters DetCode=%d MaxRmm=%d\n",det,maxrmm); return; } for (int rmm=0; rmmGetDChar(),rmm); snprintf(filename,200,"%s/Ped_%s.dat",path,name); if (!fStoreH[det][rmm]) { unsigned int uname = 0; // Convert from char to a byte packed integer a la MIDAS bankname char *un8 = (char *) &uname; un8[0] = name[0]; un8[1] = name[1]; un8[2] = name[2]; un8[3] = name[3]; fStoreH[det][rmm] = new COMET::IDPTPedStore(uname); fStoreL[det][rmm] = new COMET::IDPTPedStore(uname); } if (readfiles < 0) continue; // Don't need to read the files struct stat buf; // Temporary, for stat() to fill int s = stat(filename, &buf); if ( s < 0 ) { printf("COMET::ITripTPedSingleton:: Cannot find pedestal file: %s\n",filename); } else { // Good, it exists, read it printf("COMET::ITripTPedSingleton:: Read pedestal file: %s\n",filename); fStoreH[det][rmm]->ReadTextFile(filename,fStoreL[det][rmm]); fStoreStat[det][rmm] = 1; if (readfiles == 2) fStoreStat[det][rmm] = 2; // Flags to not allow updates from banks } } } void COMET::ITripTPedSingleton::HavePedestalBank(const unsigned char *p, size_t psize, int det, int rmm) { if (det<0 || det >=kMaxDetectorIndex || rmm<0 || rmm>=kMaxRmm) { printf("COMET::ITripTPedSingleton::HavePedestalBank called with bad DetCode=%d or rmm=%d\n",det,rmm); return; } if (fStoreStat[det][rmm] == 2) { printf("COMET::ITripTPedSingleton::HavePedestalBank bankreading explicitly disabled DetCode=%d, rmm=%d\n",det,rmm); return; } if(!fStoreH[det][rmm]){ printf("COMET::ITripTPedSingleton: Tried to read pedestal bank for non-enabled channel DetCode=%d, rmm=%d. Call EnablePedestals first!",det,rmm); return; } fStoreH[det][rmm]->ReadBank(p, psize, fStoreL[det][rmm]); if (fStoreStat[det][rmm] < 3) { fStoreStat[det][rmm] = 3; } else { fStoreStat[det][rmm]++; } } COMET::IDPTPedStore* COMET::ITripTPedSingleton::GetPedStoreH(int det, int rmm) { if (det<0 || det >=kMaxDetectorIndex || rmm<0 || rmm>=kMaxRmm) return 0; if(fStoreStat[det][rmm]==0){ printf("COMET::ITripTPedSingleton: Attempt to return pedestals before loading!"); return 0; } return fStoreH[det][rmm]; // Will be 0 if it is not loaded succesfully } COMET::IDPTPedStore* COMET::ITripTPedSingleton::GetPedStoreL(int det, int rmm) { if (det<0 || det >=kMaxDetectorIndex || rmm<0 || rmm>=kMaxRmm) return 0; if(fStoreStat[det][rmm]==0){ printf("COMET::ITripTPedSingleton: Attempt to return pedestals before loading!"); return 0; } return fStoreL[det][rmm]; // Will be 0 if it is not loaded succesfully } //---------------------------- COMET::ITripTPedSingleton& COMET::ITripTPedSingleton::Instance(void){ if (!fTTripTPedSingleton) { printf("Creating COMET::ITripTPedSingleton\n"); fTTripTPedSingleton = new COMET::ITripTPedSingleton(); } return *fTTripTPedSingleton; }